Ask Your Question
0

Exception in sage-fricas interface

asked 2018-06-20 05:06:00 -0600

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)
    494 
    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)
    507 
    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         dummy_error_message.name = 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)
False
sage:

No error.

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

>fricas
Checking for foreign routines
AXIOM="/usr/lib/fricas/target/x86_64-linux-gnu"
spad-lib="/usr/lib/fricas/target/x86_64-linux-gnu/lib/libspad.so"
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

--Nasser

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2018-07-02 14:08:34 -0600

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

Stats

Asked: 2018-06-20 05:06:00 -0600

Seen: 48 times

Last updated: Jul 02