ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 03 Jan 2021 19:51:57 +0100Unable to parse Giac output errorhttps://ask.sagemath.org/question/49176/unable-to-parse-giac-output-error/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](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
Wed, 25 Dec 2019 06:19:43 +0100https://ask.sagemath.org/question/49176/unable-to-parse-giac-output-error/Answer by Emmanuel Charpentier for <p>Sagemath 8.9</p>
<p>Why does sagemath return this error here?</p>
<pre><code>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:
</code></pre>
<p>The error is similar to one in this bug report from 3 years ago <a href="https://trac.sagemath.org/ticket/22997">https://trac.sagemath.org/ticket/22997</a> but that is for unresolved integral while here Giac is able to solve it.</p>
<p>Here is the same thing using giac directly on same computer</p>
<pre><code>>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>>
</code></pre>
<p>Version</p>
<pre><code>>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
>
</code></pre>
<p>Any suggestions what is going on?</p>
<p>Thanks
--Nasser</p>
https://ask.sagemath.org/question/49176/unable-to-parse-giac-output-error/?answer=55083#post-id-55083This is now fixed thanks to [Trac#28913](https://trac.sagemath.org/ticket/28913).Sun, 03 Jan 2021 19:51:57 +0100https://ask.sagemath.org/question/49176/unable-to-parse-giac-output-error/?answer=55083#post-id-55083Answer by dsejas for <p>Sagemath 8.9</p>
<p>Why does sagemath return this error here?</p>
<pre><code>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:
</code></pre>
<p>The error is similar to one in this bug report from 3 years ago <a href="https://trac.sagemath.org/ticket/22997">https://trac.sagemath.org/ticket/22997</a> but that is for unresolved integral while here Giac is able to solve it.</p>
<p>Here is the same thing using giac directly on same computer</p>
<pre><code>>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>>
</code></pre>
<p>Version</p>
<pre><code>>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
>
</code></pre>
<p>Any suggestions what is going on?</p>
<p>Thanks
--Nasser</p>
https://ask.sagemath.org/question/49176/unable-to-parse-giac-output-error/?answer=49191#post-id-49191Hello, @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!Wed, 25 Dec 2019 21:45:17 +0100https://ask.sagemath.org/question/49176/unable-to-parse-giac-output-error/?answer=49191#post-id-49191Comment by dsejas for <p>Hello, <a href="/users/7931/nasser/">@Nasser</a>! 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.</p>
<p>If you want to do some integration using <code>Giac</code>, what really happens at a low level is the following:</p>
<pre><code>ex = (x+1)._giac_()
result = ex.integrate(x._giac_())
result._sage_()
</code></pre>
<p>The result is obviously <code>x^2/2+x</code>. The first line converts the <code>x+1</code> from Sage representation to Giac representation, and stores it in <code>ex</code>. The second line calls the Giac <code>integrate</code> method (since the expression is now converted), which asks to integrate with respect to <code>x</code>; but, once again, you have to do it converting <code>x</code> to Giac representation (that's the <code>x._giac_()</code>). Finally, the third line converts the result back to Sage representation, so you can work with that within Sage itself</p>
<p>Now, let's go to your example. The same process is performed:</p>
<pre><code>ex = ((1-2*x^(1/3))^(3/4)/x)._giac_()
result = ex.integrate(x._giac_())
</code></pre>
<p>If you could print <code>result</code> in this stage, you would see the answer</p>
<pre><code>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)
</code></pre>
<p>The difference with the previous example is that there is this <code>Evaluation time: 1.28</code>, 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</p>
<pre><code>result._sage_()
</code></pre>
<p>is executed, but Sage is expecting a function, not the new string of evaluation time.</p>
<p>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 <code>result._sage_()</code>), ten redefine <code>x</code> with <code>x = var('x')</code>, and copy what <code>result</code> shows in your screen, without the "Evaluation time" part. You have to be careful to replace every <code>ln</code> with <code>log</code>, which is one of the things that the <code>_sage_()</code> method should do automatically.</p>
<p>I hope this helps!</p>
https://ask.sagemath.org/question/49176/unable-to-parse-giac-output-error/?comment=49193#post-id-49193Hello, @Nasser! I have reported this [here](https://ask.sagemath.org/question/49192/possible-bug-in-sage-giac-integration-interface-needs-confirmation/). Let us hope a bug fix is soon proposed.Wed, 25 Dec 2019 22:05:27 +0100https://ask.sagemath.org/question/49176/unable-to-parse-giac-output-error/?comment=49193#post-id-49193Comment by dsejas for <p>Hello, <a href="/users/7931/nasser/">@Nasser</a>! 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.</p>
<p>If you want to do some integration using <code>Giac</code>, what really happens at a low level is the following:</p>
<pre><code>ex = (x+1)._giac_()
result = ex.integrate(x._giac_())
result._sage_()
</code></pre>
<p>The result is obviously <code>x^2/2+x</code>. The first line converts the <code>x+1</code> from Sage representation to Giac representation, and stores it in <code>ex</code>. The second line calls the Giac <code>integrate</code> method (since the expression is now converted), which asks to integrate with respect to <code>x</code>; but, once again, you have to do it converting <code>x</code> to Giac representation (that's the <code>x._giac_()</code>). Finally, the third line converts the result back to Sage representation, so you can work with that within Sage itself</p>
<p>Now, let's go to your example. The same process is performed:</p>
<pre><code>ex = ((1-2*x^(1/3))^(3/4)/x)._giac_()
result = ex.integrate(x._giac_())
</code></pre>
<p>If you could print <code>result</code> in this stage, you would see the answer</p>
<pre><code>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)
</code></pre>
<p>The difference with the previous example is that there is this <code>Evaluation time: 1.28</code>, 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</p>
<pre><code>result._sage_()
</code></pre>
<p>is executed, but Sage is expecting a function, not the new string of evaluation time.</p>
<p>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 <code>result._sage_()</code>), ten redefine <code>x</code> with <code>x = var('x')</code>, and copy what <code>result</code> shows in your screen, without the "Evaluation time" part. You have to be careful to replace every <code>ln</code> with <code>log</code>, which is one of the things that the <code>_sage_()</code> method should do automatically.</p>
<p>I hope this helps!</p>
https://ask.sagemath.org/question/49176/unable-to-parse-giac-output-error/?comment=49214#post-id-49214Hello, @Nasser! Please, check the answer to [this question](https://ask.sagemath.org/question/49192/possible-bug-in-sage-giac-integration-interface-needs-confirmation/). There is a proposed workaround that will help you. Also, the bug has been confirmed and a bug report has been file.Fri, 27 Dec 2019 00:26:25 +0100https://ask.sagemath.org/question/49176/unable-to-parse-giac-output-error/?comment=49214#post-id-49214