Opened 4 years ago

Last modified 17 months ago

#17892 needs_work defect

Doctest handling of Maxima's one-sided symbolic limits

Reported by: rws Owned by:
Priority: major Milestone: sage-8.2
Component: calculus Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by nbruin)

Maxima gives back limit expressions in some integral computation but Sage has no idea what that is. Consequently, working with the expression leads to failure:

sage: var('a,b,t,s,k');
sage: u(t) = exp(-(t-a)^2/(2*s^2)) + exp(-(t-b)^2/(2*s^2)) ;
sage: I=integral(u(t)*exp(-I*k*t), t, -infinity, +infinity); I
-limit(1/2*sqrt(2)*sqrt(pi)*s*erf(1/2*(I*sqrt(2)*k*s^2 - sqrt(2)*a + sqrt(2)*t)/s)*e^(-1/2*k^2*s^2 - I*a*k) + 1/2*sqrt(2)*sqrt(pi)*s*erf(1/2*(I*sqrt(2)*k*s^2 - sqrt(2)*b + sqrt(2)*t)/s)*e^(-1/2*k^2*s^2 - I*b*k), t, -Infinity, plus) + limit(1/2*sqrt(2)*sqrt(pi)*s*erf(1/2*(I*sqrt(2)*k*s^2 - sqrt(2)*a + sqrt(2)*t)/s)*e^(-1/2*k^2*s^2 - I*a*k) + 1/2*sqrt(2)*sqrt(pi)*s*erf(1/2*(I*sqrt(2)*k*s^2 - sqrt(2)*b + sqrt(2)*t)/s)*e^(-1/2*k^2*s^2 - I*b*k), t, +Infinity, minus)
sage: I.simplify_full()
...
TypeError: ECL says: Error executing code in Maxima: 

Presumably a symbolic limit function would be necessary, and to connect it with what Maxima gives back.

Is there a smaller example?

This is from http://ask.sagemath.org/question/26004/sage-65-maxima-simplify_full-error/

Change History (6)

comment:1 Changed 4 years ago by rws

  • Description modified (diff)

comment:2 Changed 4 years ago by nbruin

  • Description modified (diff)

Funnily enough it's not the limit placeholder that seems to be the primary issue. For the most part, the generic stuff just works for that. It's the "plus" or "minus" keyword that confuses things.

sage: L=I.operands()[0].operands()[0]
limit(1/2*sqrt(2)*sqrt(pi)*s*erf(1/2*(I*sqrt(2)*k*s^2 - sqrt(2)*a + sqrt(2)*t)/s)*e^(-1/2*k^2*s^2 - I*a*k) + 1/2*sqrt(2)*sqrt(pi)*s*erf(1/2*(I*sqrt(2)*k*s^2 - sqrt(2)*b + sqrt(2)*t)/s)*e^(-1/2*k^2*s^2 - I*b*k), t, -Infinity, plus)
sage: Ls=L.operator()(*L.operands()[:-1]); Ls
limit(1/2*sqrt(2)*sqrt(pi)*s*erf(1/2*(I*sqrt(2)*k*s^2 - sqrt(2)*a + sqrt(2)*t)/s)*e^(-1/2*k^2*s^2 - I*a*k) + 1/2*sqrt(2)*sqrt(pi)*s*erf(1/2*(I*sqrt(2)*k*s^2 - sqrt(2)*b + sqrt(2)*t)/s)*e^(-1/2*k^2*s^2 - I*b*k), t, -Infinity)
sage: Ls.simplify_full()
1/2*sqrt(pi)*e^(-1/2*k^2*s^2 - I*a*k - I*b*k)*limit(sqrt(2)*s*erf(1/2*(I*sqrt(2)*k*s^2 - sqrt(2)*b + sqrt(2)*t)/s)*e^(I*a*k) + sqrt(2)*s*erf(1/2*(I*sqrt(2)*k*s^2 - sqrt(2)*a + sqrt(2)*t)/s)*e^(I*b*k), t, -Infinity)

i.e., the direct problem is that the keyword "plus" does not get translated appropriately. In fact:

sage: L.operands()[-1].is_symbol()
True
sage: L.operands()[-1]._maxima_()
_SAGE_VAR_plus

as you can see, the maxima symbol "plus" got translated to a symbolic variable, which doesn't round-trip properly. It would have been nice to recognize "plus" on the maxima side not into a variable.

For the rest:

sage: limit(L.operands()[0],t=-oo,dir='+')
limit(1/2*sqrt(2)*sqrt(pi)*s*erf(1/2*(I*sqrt(2)*k*s^2 - sqrt(2)*a + sqrt(2)*t)/s)*e^(-1/2*k^2*s^2 - I*a*k) + 1/2*sqrt(2)*sqrt(pi)*s*erf(1/2*(I*sqrt(2)*k*s^2 - sqrt(2)*b + sqrt(2)*t)/s)*e^(-1/2*k^2*s^2 - I*b*k), t, -Infinity, plus)

which gives a bit of a pointer to the sage user interface (we shouldn't use that as "placeholder", though: it punts to maxima by default, so it shouldn't be called for interpreting the result that comes back).

comment:3 Changed 4 years ago by kcrisman

Conceivably related: #19203

comment:4 Changed 2 years ago by rws

  • Milestone changed from sage-6.6 to sage-duplicate/invalid/wontfix
  • Status changed from new to needs_review

The limit part appears to work now, i.e. the limit is evaluated and gives sqrt(2)*sqrt(pi)*s*e^(-1/2*k^2*s^2 - I*a*k) + sqrt(2)*sqrt(pi)*s*e^(-1/2*k^2*s^2 - I*b*k). This means the simplify part is no longer in a code path. I propose to close the original issue. Is there something left?

comment:5 follow-up: Changed 17 months ago by rws

  • Milestone changed from sage-duplicate/invalid/wontfix to sage-8.2
  • Status changed from needs_review to needs_work
  • Summary changed from Sage cannot work with Maxima's symbolic limit to Doctest handling of Maxima's one-sided symbolic limits

No, rather this ticket should add an example calling Maxima's integral that is guaranteed to return a one-sided limit.

comment:6 in reply to: ↑ 5 Changed 17 months ago by rws

Replying to rws:

No, rather this ticket should add an example calling Maxima's integral that is guaranteed to return a one-sided limit.

Also, the interface to Maxima wrt plus/minus is broken with the placeholder function as well:

sage: from sage.functions.other import symbolic_limit as slimit
sage: _ = var('plus')
sage: slimit(1/x, x, 0, plus)
limit(1/x, x, 0, plus)
sage: maxima(_)
...
TypeError: Error executing code in Maxima
CODE:
	sage4 : limit((_SAGE_VAR_x)^(-1),_SAGE_VAR_x,0,_SAGE_VAR_plus)$
Maxima ERROR:
	
limit: direction must be either 'plus' or 'minus'; found: _SAGE_VAR_plus
 -- an error. To debug this try: debugmode(true);
Note: See TracTickets for help on using tickets.