Ask Your Question
1

Unable to parse Giac output error

asked 2019-12-25 06:19:43 +0200

Nasser gravatar image

Sagemath 8.9

Why does sagemath return this error here?

sage: var('x')
x
sage: integrate((1-2*x^(1/3))^(3/4)/x,x, algorithm="giac")
NotImplementedError                       Traceback (most recent call last)
<ipython-input-16-987ddabbc645> in <module>()
----> 1 integrate((Integer(1)-Integer(2)*x**(Integer(1)/Integer(3)))**(Integer(3)/Integer(4))/x,x, algorithm="giac")

/usr/lib/python2.7/site-packages/sage/misc/functional.pyc in integral(x, *args, **kwds)
    751     """
    752     if hasattr(x, 'integral'):
--> 753         return x.integral(*args, **kwds)
    754     else:
    755         from sage.symbolic.ring import SR

/usr/lib/python2.7/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.integral (build/cythonized/sage/symbolic/expression.cpp:64032)()
  12360                     R = ring.SR
  12361             return R(integral(f, v, a, b, **kwds))
> 12362         return integral(self, *args, **kwds)
  12363 
  12364     integrate = integral

/usr/lib/python2.7/site-packages/sage/symbolic/integration/integral.pyc in integrate(expression, v, a, b, algorithm, hold)
    910         if not integrator:
    911             raise ValueError("Unknown algorithm: %s" % algorithm)
--> 912         return integrator(expression, v, a, b)
    913     if a is None:
    914         return indefinite_integral(expression, v, hold=hold)

/usr/lib/python2.7/site-packages/sage/symbolic/integration/external.pyc in giac_integrator(expression, v, a, b)
    430         return expression.integrate(v, a, b, hold=True)
    431     else:
--> 432         return result._sage_()

/usr/lib/python2.7/site-packages/sage/interfaces/giac.pyc in _sage_(self, locals)
   1096 
   1097             except Exception:
-> 1098                 raise NotImplementedError("Unable to parse Giac output: %s" % result)
   1099         else:
   1100             return [entry.sage() for entry in self]

NotImplementedError: Unable to parse Giac output: Evaluation time: 1.76
12*(1/4*ln(abs((-2*x^(1/3)+1)^(1/4)-1))-1/4*ln((-2*x^(1/3)+1)^(1/4)+1)+1/2*atan((-2*x^(1/3)+1)^(1/4))+1/3*((-2*x^(1/3)+1)^(1/4))^3)
sage:

The error is similar to one in this bug report from 3 years ago https://trac.sagemath.org/ticket/22997 but that is for unresolved integral while here Giac is able to solve it.

Here is the same thing using giac directly on same computer

>giac
// Using locale /usr/share/locale/
// en_US.utf8
// /usr/share/locale/
// giac
// UTF-8
// Maximum number of parallel threads 4
Help file /usr/share/giac/doc/en/aide_cas not found
Added 26 synonyms
Welcome to giac readline interface
(c) 2001,2018 B. Parisse & others
Homepage http://www-fourier.ujf-grenoble.fr/~parisse/giac.html
Released under the GPL license 3.0 or above
See http://www.gnu.org for license details
May contain BSD licensed software parts (lapack, atlas, tinymt)
-------------------------------------------------
Press CTRL and D simultaneously to finish session
Type ?commandname for help
0>> integrate((1-2*x^(1/3))^(3/4)/x,x)

Evaluation time: 1.66
12*(1/4*ln(abs((-2*x^(1/3)+1)^(1/4)-1))-1/4*ln((-2*x^(1/3)+1)^(1/4)+1)+1/2*atan((-2*x^(1/3)+1)^(1/4))+1/3*((-2*x^(1/3)+1)^(1/4))^3)
// Time 1.66
1>>

Version

>giac --version
// Using locale /usr/share/locale/
// en_US.utf8
// /usr/share/locale/
// giac
// UTF-8
// Maximum number of parallel threads 4
// (c) 2001, 2018 B. Parisse & others
1.5.0
>

Any suggestions what is going on?

Thanks --Nasser

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2019-12-25 21:45:17 +0200

dsejas gravatar image

Hello, @Nasser! I may have an idea of what is going on, and I think you found a bug! (Although I am not 100% sure.) Here is what I can deduce from reading lots of line of Sage code.

If you want to do some integration using Giac, what really happens at a low level is the following:

ex = (x+1)._giac_()
result = ex.integrate(x._giac_())
result._sage_()

The result is obviously x^2/2+x. The first line converts the x+1 from Sage representation to Giac representation, and stores it in ex. The second line calls the Giac integrate method (since the expression is now converted), which asks to integrate with respect to x; but, once again, you have to do it converting x to Giac representation (that's the x._giac_()). Finally, the third line converts the result back to Sage representation, so you can work with that within Sage itself

Now, let's go to your example. The same process is performed:

ex = ((1-2*x^(1/3))^(3/4)/x)._giac_()
result = ex.integrate(x._giac_())

If you could print result in this stage, you would see the answer

Evaluation time: 1.28
12*(1/4*ln(abs((-2*x^(1/3)+1)^(1/4)-1))-1/4*ln((-2*x^(1/3)+1)^(1/4)+1)+1/2*atan((-2*x^(1/3)+1)^(1/4))+1/3*((-2*x^(1/3)+1)^(1/4))^3)

The difference with the previous example is that there is this Evaluation time: 1.28, which Giac seems to add as part of the result when the computation takes a little longer than usual (like 1.28 seconds). That is when Sage fails, because the line

result._sage_()

is executed, but Sage is expecting a function, not the new string of evaluation time.

My suggestion: Use Giac to integrate simple functions until the bug is fixed (I will report it right now). But, if you really want to use it to integrate a function like this, execute the two previous steps (without result._sage_()), ten redefine x with x = var('x'), and copy what result shows in your screen, without the "Evaluation time" part. You have to be careful to replace every ln with log, which is one of the things that the _sage_() method should do automatically.

I hope this helps!

edit flag offensive delete link more

Comments

Hello, @Nasser! I have reported this here. Let us hope a bug fix is soon proposed.

dsejas gravatar imagedsejas ( 2019-12-25 22:05:27 +0200 )edit

Hello, @Nasser! Please, check the answer to this question. There is a proposed workaround that will help you. Also, the bug has been confirmed and a bug report has been file.

dsejas gravatar imagedsejas ( 2019-12-27 00:26:25 +0200 )edit
1

answered 2021-01-03 19:51:57 +0200

Emmanuel Charpentier gravatar image

updated 2021-01-03 19:53:09 +0200

This is now fixed thanks to Trac#28913.

edit flag offensive delete link more

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: 2019-12-25 06:19:43 +0200

Seen: 371 times

Last updated: Jan 03 '21