Opened 10 years ago

Last modified 2 years ago

#13071 new defect

maxima interface integration problem

Reported by: D.S. McNeil Owned by: Burcin Erocal
Priority: major Milestone: sage-wishlist
Component: symbolics Keywords: integral
Cc: Karl-Dieter Crisman Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

Something seems to be going wrong in maxima_lib:

sage: integrate(sin(x), x)
-cos(x)
sage: integrate(sin(x)*exp(x), x)
1/2*(sin(x) - cos(x))*e^x
sage: integrate(sin(x)*exp(x)/x, x)
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (580, 0))

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/home/mcneil/sagedev/sage-5.1.beta1/devel/sage-hack/sage/<ipython console> in <module>()

/home/mcneil/sagedev/sage-5.0/local/lib/python2.7/site-packages/sage/misc/functional.pyc in integral(x, *args, **kwds)
    726     """
    727     if hasattr(x, 'integral'):
--> 728         return x.integral(*args, **kwds)
    729     else:
    730         from sage.symbolic.ring import SR

/home/mcneil/sagedev/sage-5.0/local/lib/python2.7/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression.integral (sage/symbolic/expression.cpp:33707)()

[...]

/home/mcneil/sagedev/sage-5.0/local/lib/python2.7/site-packages/sage/interfaces/maxima_lib.pyc in max_to_sr(expr)
   1536         op=max_op_dict[op_max]
   1537         max_args=cdr(expr)
-> 1538         args=[max_to_sr(a) for a in max_args]
   1539         return op(*args)
   1540     elif expr.symbolp():

/home/mcneil/sagedev/sage-5.0/local/lib/python2.7/site-packages/sage/interfaces/maxima_lib.pyc in max_to_sr(expr)
   1537         max_args=cdr(expr)
   1538         args=[max_to_sr(a) for a in max_args]
-> 1539         return op(*args)
   1540     elif expr.symbolp():
   1541         if not(expr in max_sym_dict):

TypeError: op_mul expected 2 arguments, got 1

This happens in 5.0 and beyond. Unfortunately I don't have a 4.8 at hand so I can't track it down before that.

Strangely enough, if you do it again, you get a different error:

/home/mcneil/sagedev/sage-5.0/local/lib/python2.7/site-packages/sage/interfaces/maxima_lib.pyc in sr_integral(self, *args)
    745                 raise ValueError, "Computation failed since Maxima requested additional constraints; using the 'assume' command before integral evaluation *may* help (example of legal syntax is 'assume(" + s[4:k] +">0)', see `assume?` for more details)\n" + s
    746             else:
--> 747                 raise error
    748 
    749     def sr_sum(self,*args):

RuntimeError: ECL says: Error executing code in Maxima: conjugate: wrong number of arguments.

So -- and this might be independent -- something's stateful which probably shouldn't be.

Change History (7)

comment:1 Changed 10 years ago by Nils Bruin

Yep, sage is trying to learn how to translate "conjugate" and gets tripped up. The following does work because it primes the dictionary.

sage: integrate(conjugate(Ei((I+1)*x)),x)
integrate(-conjugate(Ei(-(I + 1)*x)), x)
sage: integrate(sin(x)*exp(x)/x, x)
-1/4*I*conjugate(Ei(-(I - 1)*x)) + 1/4*I*conjugate(Ei((I + 1)*x)) + 1/4*I*Ei(-(I - 1)*x) - 1/4*I*Ei((I + 1)*x)

The problem is that sage tries to learn what conjugate is from this expression:

sage: expr=maxima("conjugate(gamma_incomplete(0,(-%i-1)*x))")
conjugate(gamma_incomplete(0,(-%i-1)*x))

but its conversion to SR pulls out a minus sign:

sage: SR(expr)
-conjugate(Ei((I + 1)*x))

so in max_to_sr line 1530 text-based fallback we find that the corresponding operator is:

sage: SR(expr).operator()
<built-in function mul>

Once conversion of multiplication is broken, we of course get all kinds garbage. A warning for exactly this problem is in the source.

Work-around for this particular issue: Prepopulate sage_op_dict with conjugate

A better solution would be to once and for all solve this problem by initializing sage_op_dict from the same source where the text-based interface gets its knowledge from.

Last edited 10 years ago by Nils Bruin (previous) (diff)

comment:2 Changed 9 years ago by Jeroen Demeyer

Milestone: sage-5.11sage-5.12

comment:3 Changed 9 years ago by For batch modifications

Milestone: sage-6.1sage-6.2

comment:4 Changed 9 years ago by For batch modifications

Milestone: sage-6.2sage-6.3

comment:5 Changed 8 years ago by For batch modifications

Milestone: sage-6.3sage-6.4

comment:6 Changed 4 years ago by Erik Bray

Milestone: sage-6.4sage-wishlist

comment:7 Changed 2 years ago by Frédéric Chapoton

Keywords: integral added
Note: See TracTickets for help on using tickets.