Ask Your Question
2

result that comes with warning from giac integrator

asked 2021-05-28 05:55:19 +0200

Nasser gravatar image

Using Giac/Xcas 1.7 on Linux. (via sagemath 9.3)

giac sometimes results an actual antiderivative from a call to int but because it issues warnings, sagemath is not able to parse what giac returned back, it throws an exception.

Is it possible to handle such cases, so that one can get the anti derivative returned, but have the warning message be separated and may be just printed on the screen in addition, as separate output? Here are two examples.

Example 1

   var('x')
   anti=integrate(1/(2*x^(1/2)+(1+x)^(1/2))^2,x, algorithm="giac")
/usr/lib/python3.9/site-packages/sage/interfaces/giac.py in _sage_(self, locals)
   1134 
   1135             except Exception:
-> 1136                 raise NotImplementedError("Unable to parse Giac output: %s" % result)
   1137         else:
   1138             return [entry.sage() for entry in self]

NotImplementedError: Unable to parse Giac output: Warning, ....

And because an exception is thrown, this is counted as failed.

Example 2

 var('a x')
 integrate(sec(2*a*x),x, algorithm="giac")

usr/lib/python3.9/site-packages/sage/interfaces/giac.py in _sage_(self, locals)
   1134 
   1135             except Exception:
-> 1136                 raise NotImplementedError("Unable to parse Giac output: %s" % result)
   1137         else:
   1138             return [entry.sage() for entry in self]

NotImplementedError: Unable to parse Giac output: Unable to check sign:...

Here are the examples done inside giac directly

0>> integrate(sec(2*a*x),x)
Unable to check sign: (pi/x/2)>(-pi/x/2)
Unable to check sign: (pi/x/2)>(-pi/x/2)
2/(2*a)*(-1/8*ln(abs(sin(2*a*x)+1/sin(2*a*x)-2))+1/8*ln(abs(sin(2*a*x)+1/sin(2*a*x)+2)))
// Time 0.02

And

2>> integrate(1/(2*x^(1/2)+(1+x)^(1/2))^2,x)
Warning, choosing root of [1,0,%%%{-4,[1]%%%}+%%%{-2,[0]%%%},0,1] at parameters values [-27]
Warning, choosing root of [1,0,%%%{-4,[1]%%%}+%%%{-2,[0]%%%},0,1] at parameters values [26]
2*((-5*x-1)/6/(3*x-1)+5/18*ln(abs(3*x-1))+2*(2/9*ln(sqrt(x+1)-sqrt(x))+5/36*ln(abs((sqrt(x+1)-sqrt(x))^2-3))-5/36*ln(abs(3*(sqrt(x+1)-sqrt(x))^2-1))-(10*(sqrt(x+1)-sqrt(x))^2-6)/9/(3*(sqrt(x+1)-sqrt(x))^4-10*(sqrt(x+1)-sqrt(x))^2+3)))
// Time 0.06
3>>

The above output from giac shows it does gives a result for the integrate command, but it follows some warning messages. Even if the result might not be correct, it is still a result. But now it is not possible to capture this returned result, since sagemath throws an exception and this is taken right away as failed call.

May be if these warning lines could be filtered out or handled somehow differently, this will allow one to see giac result?

There are many such examples.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-05-28 19:51:12 +0200

mwageringel gravatar image

updated 2021-05-28 22:42:35 +0200

These issues with the text-based interfaces are known. See for example #28913 for a very similar problem.

Instead of the text-based interface to Giac, you can use the C-interface libgiac. This is a recent addition, so you need at least Sage 9.2.

sage: var('a x')
sage: from sage.libs.giac import libgiac
sage: anti = libgiac.integrate(1/(2*x^(1/2)+(1+x)^(1/2))^2, x).sage()
Warning, choosing root of [1,0,%%%{-4,[1]%%%}+%%%{-2,[0]%%%},0,1] at parameters values [86]
Warning, choosing root of [1,0,%%%{-4,[1]%%%}+%%%{-2,[0]%%%},0,1] at parameters values [-97]
sage: anti
-8/9*(5*(sqrt(x + 1) - sqrt(x))^2 - 3)/(3*(sqrt(x + 1) - sqrt(x))^4 - 10*(sqrt(x + 1) - sqrt(x))^2 + 3) - 1/3*(5*x + 1)/(3*x - 1) + 4/9*log((sqrt(x + 1) - sqrt(x))^2) - 5/9*log(abs(3*(sqrt(x + 1) - sqrt(x))^2 - 1)) + 5/9*log(abs((sqrt(x + 1) - sqrt(x))^2 - 3)) + 5/9*log(abs(3*x - 1))

sage: libgiac.integrate(sec(2*a*x), x).sage()
Unable to check sign: (pi/x/2)>(-pi/x/2)
Unable to check sign: (pi/x/2)>(-pi/x/2)
1/8*(log(abs(1/sin(2*a*x) + sin(2*a*x) + 2)) - log(abs(1/sin(2*a*x) + sin(2*a*x) - 2)))/a

Probably, this will become the default behind the scenes, in a future version of Sage. (Edit: I have opened #31873 for this.)

edit flag offensive delete link more

Comments

thanks. But I found a problem using libgiac directly, I posted separate question https://ask.sagemath.org/question/573... on this issue.

Nasser gravatar imageNasser ( 2021-05-28 22:23:35 +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

Stats

Asked: 2021-05-28 05:55:19 +0200

Seen: 479 times

Last updated: May 28 '21