Ask Your Question

syntaxError exception using integrate with fricas

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

Nasser gravatar image

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

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

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
                                            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



1 Answer

Sort by » oldest newest most voted

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

tolga gravatar image

Try to replace the term 2^(1/2) by a variable 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


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 +0200 )edit

Can a try-except solve your problem:


    res=integrate(f(x),x, algorithm="fricas")

tolga gravatar imagetolga ( 2021-05-27 13:02:29 +0200 )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


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

Seen: 222 times

Last updated: May 27 '21