Ask Your Question
2

syntaxError exception using integrate with fricas

asked 2021-05-27 08:41:38 +0100

Nasser gravatar image

updated 2021-05-27 08:48:51 +0100

This seems to be another Sagemath<-->Fricas interface issue. I am not sure if it is reported or not.

Using sagemath 9.3 with fricas 1.3.6 on Linux

var('x')
integrate(2*x+x^2*2^(1/2),x, algorithm="fricas")
....
  File "sage/misc/parser.pyx", line 1019, in sage.misc.parser.Parser.parse_error (build/cythonized/sage/misc/parser.c:10208)
    raise SyntaxError(msg, tokens.s, tokens.pos)

  File "<string>", line unknown
SyntaxError: Malformed expression

Using fricas directly

(2) -> ii:=integrate(2*x+x^2*2^(1/2),x)

         +-+
        \|2   3    2
   (2)  ---- x  + x
          3
                                            Type: Polynomial(AlgebraicNumber)
(3) -> unparse(ii::InputForm)  

   (3)  "((2^(1/2))/3)::AlgebraicNumber()*x^3+1::AlgebraicNumber()*x^2"
                                                                 Type: String
(4) ->

Is the syntax error coming due to Fricas using those ::AlgebraicNumber() in there? I looked at my older report for this one using Fricas 1.3.6 on Linux (via sagemath 9.0) and the error then was

   Exception raised: UnboundLocalError

So the exception seem to have changed, but both still fail.

Any idea why the above gives syntax error on the sagemath side? Currently this is flagged as failed, when it should really be valid result.

edit retag flag offensive close merge delete

Comments

1

1 Answer

Sort by » oldest newest most voted
0

answered 2021-05-27 12:41:27 +0100

tolga gravatar image

Try to replace the term 2^(1/2) by a variable a:

var('x,a')
integrate(2*x+x^2*a,x, algorithm="fricas")

to obtain

1/3*x^3*a + x^2

Then you can substitute a=2^(1/2).

edit flag offensive delete link more

Comments

Thanks. But I can't really do this. These integrals come from a large integration test files (over 70,000 integrals) and they are read by a program and processed in batch mode. It is not possible to check each integral and decide what to do for each different algorithm used by integrate to avoid possible problems with the interface.

Nasser gravatar imageNasser ( 2021-05-27 12:44:29 +0100 )edit

Can a try-except solve your problem:

f(x)=2*x+x^2*2^(1/2)

try:
    res=integrate(f(x),x, algorithm="fricas")
except:
    res=integrate(f(x),x)

print(res)
tolga gravatar imagetolga ( 2021-05-27 13:02:29 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-05-27 08:41:38 +0100

Seen: 265 times

Last updated: May 27 '21