sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.34k stars 460 forks source link

maxima interface integration problem #13071

Open 56048686-9665-4c5e-973e-6c3add3aa805 opened 12 years ago

56048686-9665-4c5e-973e-6c3add3aa805 commented 12 years ago

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.

CC: @kcrisman

Component: symbolics

Keywords: integral

Issue created by migration from https://trac.sagemath.org/ticket/13071

nbruin commented 12 years ago
comment:1

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.

fchapoton commented 4 years ago

Changed keywords from none to integral