Ask Your Question

Exception in sage-fricas interface

asked 2018-06-20 12:06:00 +0200

Nasser gravatar image

I get an error in this specific integral. Here is how to reproduce it. I call fricas from sage to do an integral. Convert the result back to sage syntax. Then use

 isinstance(anti.operator(), sage.symbolic.integration.integral.IndefiniteIntegral)

As a way to check if the result has no unevaluated integral in it anywhere, so I would know it actually evaluated and not echoed back.

This works OK for everything I tried so far. It works on all the tests I did on Maxima. Except on this one I found so far using Fricas

sage: fricas.setSimplifyDenomsFlag(fricas.true)
sage: var('x')
sage: theIntegral = fricas(x*(x^2-1)^9)
sage: anti = theIntegral.integrate(x)
sage: anti = anti.sage()

sage: anti
1/20*x^20 - 1/2*x^18 + 9/4*x^16 - 6*x^14 + 21/2*x^12 - 63/5*x^10 + 21/2*x^8 - 6*x^6 + 9/4*x^4 - 1/2*x^2

sage: isinstance(anti.operator(), sage.symbolic.integration.integral.IndefiniteIntegral)

and now

AttributeError                            Traceback (most recent call last)
<ipython-input-16-ebdd05a45434> in <module>()
----> 1 isinstance(anti.operator(), sage.symbolic.integration.integral.IndefiniteIntegral)

/usr/lib/python2.7/site-packages/sage/structure/element.pyx in sage.structure.element.Element.__getattr__ (build/cythonized/sage/structure/element.c:4531)()
    491             AttributeError: 'LeftZeroSemigroup_with_category.element_class' object has no attribute 'blah_blah'
    492         """
--> 493         return self.getattr_from_category(name)
    495     cdef getattr_from_category(self, name):

/usr/lib/python2.7/site-packages/sage/structure/element.pyx in sage.structure.element.Element.getattr_from_category (build/cythonized/sage/structure/element.c:4640)()
    504         else:
    505             cls = P._abstract_element_class
--> 506         return getattr_from_other_class(self, cls, name)
    508     def __dir__(self):

/usr/lib/python2.7/site-packages/sage/cpython/getattr.pyx in sage.cpython.getattr.getattr_from_other_class (build/cythonized/sage/cpython/getattr.c:2536)()
    392         dummy_error_message.cls = type(self)
    393 = name
--> 394         raise AttributeError(dummy_error_message)
    395     attribute = <object>attr
    396     # Check for a descriptor (__get__ in Python)

AttributeError: 'sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint' object has no attribute 'operator'

The above works OK on other integrals. For example

sage: theIntegral = fricas(x*(x^2+1)^(1/2))
sage: anti = theIntegral.integrate(x)
sage: anti = anti.sage()

sage: anti
1/3*(x^2 + 1)^(3/2)

sage: isinstance(anti.operator(), sage.symbolic.integration.integral.IndefiniteIntegral)

No error.

I am using sage: SageMath version 8.3.beta6, Release Date: 2018-06-17 and

Checking for foreign routines
foreign routines found
openServer result 0
                       FriCAS Computer Algebra System 
                            Version: FriCAS 1.3.3
                   Timestamp: Tue Jun 19 19:53:54 CDT 2018

Any idea why this error shows up on this integral? Is it possible to fix it?

Thank you


edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2018-07-02 21:08:34 +0200

vdelecroix gravatar image

At the end of the traceback you get a very explicit error message

AttributeError: 'sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint'
object has no attribute 'operator'

The point is that the result of the .sage() function in your situation was not a symbolic expression but a polynomial. And a polynomial does not have this .operator() function that you are using in

sage: isinstance(anti.operator(), sage.symbolic.integration.integral.IndefiniteIntegral)

You can see the very same error with

sage: anti.operator()

In this situation, if you want to check whether the object anti is an indefinite integral you can do

anti.parent() is SR and isinstance(anti.operator(), sage.symbolic.integration.integral.IndefiniteIntegral)

(Note that your way of checking that no integral remains unevaluated is not very strong.)

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


Asked: 2018-06-20 12:06:00 +0200

Seen: 316 times

Last updated: Jul 02 '18