Opened 4 years ago

Closed 3 years ago

#25817 closed defect (fixed)

RuntimeError: Encountered operator mismatch in maxima-to-sr translation, integrate

Reported by: gh-nasser1 Owned by:
Priority: minor Milestone: sage-8.9
Component: interfaces Keywords: integrate, maxima
Cc: tscrim, vklein, jhpalmieri Merged in:
Authors: Nils Bruin, Frédéric Chapoton Reviewers: Travis Scrimshaw
Report Upstream: N/A Work issues:
Branch: 3bf6cd7 (Commits, GitHub, GitLab) Commit: 3bf6cd76f9a97787841fa8b113a39b6411cbb0a4
Dependencies: Stopgaps:

Status badges

Description

I do not know if this is known or not. If it is, feel free to close.

>sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 8.3.rc0, Release Date: 2018-07-08                 │
│ Type "notebook()" for the browser-based notebook interface.        │
│ Type "help()" for help.                                            │
└────────────────────────────────────────────────────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Warning: this is a prerelease version, and it may be unstable.     ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sage: var('x')
x
sage: integrate(log(e^x*log(x)*sin(x))/x^2, x)
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-2-ee0ac2fd3190> in <module>()
----> 1 integrate(log(e**x*log(x)*sin(x))/x**Integer(2), x)

/usr/lib/python2.7/site-packages/sage/misc/functional.py in integral(x, *args, **kwds)
    751     """
    752     if hasattr(x, 'integral'):
--> 753         return x.integral(*args, **kwds)
    754     else:
    755         from sage.symbolic.ring import SR

/usr/lib/python2.7/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.integral (build/cythonized/sage/symbolic/expression.cpp:69761)()
  12364                     R = ring.SR
  12365             return R(integral(f, v, a, b, **kwds))
> 12366         return integral(self, *args, **kwds)
  12367 
  12368     integrate = integral

/usr/lib/python2.7/site-packages/sage/symbolic/integration/integral.py in integrate(expression, v, a, b, algorithm, hold)
    816         return integrator(expression, v, a, b)
    817     if a is None:
--> 818         return indefinite_integral(expression, v, hold=hold)
    819     else:
    820         return definite_integral(expression, v, a, b, hold=hold)

/usr/lib/python2.7/site-packages/sage/symbolic/function.pyx in sage.symbolic.function.BuiltinFunction.__call__ (build/cythonized/sage/symbolic/function.cpp:11921)()
    996             res = self._evalf_try_(*args)
    997             if res is None:
--> 998                 res = super(BuiltinFunction, self).__call__(
    999                         *args, coerce=coerce, hold=hold)
   1000 

/usr/lib/python2.7/site-packages/sage/symbolic/function.pyx in sage.symbolic.function.Function.__call__ (build/cythonized/sage/symbolic/function.cpp:6948)()
    490                     (<Expression>args[0])._gobj, hold)
    491         elif self._nargs == 2:
--> 492             res = g_function_eval2(self._serial, (<Expression>args[0])._gobj,
    493                     (<Expression>args[1])._gobj, hold)
    494         elif self._nargs == 3:

/usr/lib/python2.7/site-packages/sage/symbolic/integration/integral.py in _eval_(self, f, x)
     88         for integrator in self.integrators:
     89             try:
---> 90                 return integrator(f, x)
     91             except NotImplementedError:
     92                 pass

/usr/lib/python2.7/site-packages/sage/symbolic/integration/external.py in maxima_integrator(expression, v, a, b)
     30         expression = SR(expression)
     31     if a is None:
---> 32         result = maxima.sr_integral(expression,v)
     33     else:
     34         result = maxima.sr_integral(expression, v, a, b)

/usr/lib/python2.7/site-packages/sage/interfaces/maxima_lib.py in sr_integral(self, *args)
    803         """
    804         try:
--> 805             return max_to_sr(maxima_eval(([max_integrate],[sr_to_max(SR(a)) for a in args])))
    806         except RuntimeError as error:
    807             s = str(error)

/usr/lib/python2.7/site-packages/sage/interfaces/maxima_lib.py in max_to_sr(expr)
   1697             op=max_op_dict[op_max]
   1698         max_args=cdr(expr)
-> 1699         args=[max_to_sr(a) for a in max_args]
   1700         return op(*args)
   1701     elif expr.symbolp():

/usr/lib/python2.7/site-packages/sage/interfaces/maxima_lib.py in max_to_sr(expr)
   1697             op=max_op_dict[op_max]
   1698         max_args=cdr(expr)
-> 1699         args=[max_to_sr(a) for a in max_args]
   1700         return op(*args)
   1701     elif expr.symbolp():

/usr/lib/python2.7/site-packages/sage/interfaces/maxima_lib.py in max_to_sr(expr)
   1697             op=max_op_dict[op_max]
   1698         max_args=cdr(expr)
-> 1699         args=[max_to_sr(a) for a in max_args]
   1700         return op(*args)
   1701     elif expr.symbolp():

/usr/lib/python2.7/site-packages/sage/interfaces/maxima_lib.py in max_to_sr(expr)
   1697             op=max_op_dict[op_max]
   1698         max_args=cdr(expr)
-> 1699         args=[max_to_sr(a) for a in max_args]
   1700         return op(*args)
   1701     elif expr.symbolp():

/usr/lib/python2.7/site-packages/sage/interfaces/maxima_lib.py in max_to_sr(expr)
   1691                 op=sage_expr.operator()
   1692             if op in sage_op_dict:
-> 1693                 raise RuntimeError("Encountered operator mismatch in maxima-to-sr translation")
   1694             max_op_dict[op_max]=op
   1695             sage_op_dict[op]=op_max

RuntimeError: Encountered operator mismatch in maxima-to-sr translation

Running on Linux Manjaro 17.1

Change History (10)

comment:1 Changed 4 years ago by nbruin

Thanks! good catch. That's been a long while since that one was triggered. The code has a warning (line 1689 in maxima_lib.py):

            else:
                # This could be unsafe if the conversion to SR
                # changes the structure of expr

The fix is straightforward: add the appropriate translation to the dictionary. A bit of debugging shows that this diff does the trick:

diff --git a/src/sage/interfaces/maxima_lib.py b/src/sage/interfaces/maxima_lib.py
index 874ea23..6d142c2 100644
--- a/src/sage/interfaces/maxima_lib.py
+++ b/src/sage/interfaces/maxima_lib.py
@@ -1236,6 +1236,7 @@ sage_op_dict = {
     sage.functions.other.factorial : "MFACTORIAL",
     sage.functions.error.erf : "%ERF",
     sage.functions.gamma.gamma_inc : "%GAMMA_INCOMPLETE",
+    sage.functions.other.conjugate : "$CONJUGATE",
 }
 #we compile the dictionary
 sage_op_dict = dict([(k,EclObject(sage_op_dict[k])) for k in sage_op_dict])

I don't have a sage build ready from which I can push this change, so for now I just document the fix this way.

comment:2 Changed 4 years ago by nbruin

  • Branch set to u/nbruin/runtimeerror__encountered_operator_mismatch_in_maxima_to_sr_translation__integrate

comment:3 Changed 4 years ago by nbruin

  • Authors set to Nils Bruin
  • Commit set to b0b5de2ea9c79e6c80017fbedbfa4d0b0a54c2e3
  • Status changed from new to needs_review
  • Type changed from PLEASE CHANGE to defect

One line fix. If someone feels the need, please add a doctest. The error check in the code performed exactly as intended, and raised at a point where a little debug inspection immediately indicated what entry should be added.


New commits:

b0b5de2trac 25817: add "conjugate" explicitly to maxima_lib translation dictionary, since automatic discovery doesn't always work.

comment:4 Changed 4 years ago by git

  • Commit changed from b0b5de2ea9c79e6c80017fbedbfa4d0b0a54c2e3 to 2a5d00c3894fd9eeeb14c970fd6e89f7b77d059d

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

2a5d00ctrac 25817: add "conjugate" explicitly to maxima_lib translation dictionary, since automatic discovery doesn't always work.

comment:5 Changed 4 years ago by slelievre

With the fix from commit 2a5d00c:

sage: x = SR.var('x')
sage: integrate(log(e^x*log(x)*sin(x))/x^2, x)
1/2*(x*(Ei(-log(x)) + conjugate(Ei(-log(x))))
- 2*x*integrate(sin(x)/(x*cos(x)^2 + x*sin(x)^2
+ 2*x*cos(x) + x), x) + 2*x*integrate(sin(x)/(x*cos(x)^2
+ x*sin(x)^2 - 2*x*cos(x) + x), x) + 2*x*log(x) + 2*log(2)
- log(cos(x)^2 + sin(x)^2 + 2*cos(x) + 1) - log(cos(x)^2
+ sin(x)^2 - 2*cos(x) + 1) - 2*log(log(x)))/x

Where would be a good place to put this as a doctest?

comment:6 Changed 3 years ago by chapoton

  • Authors changed from Nils Bruin to Nils Bruin, Frédéric Chapoton
  • Branch changed from u/nbruin/runtimeerror__encountered_operator_mismatch_in_maxima_to_sr_translation__integrate to u/chapoton/25817
  • Commit changed from 2a5d00c3894fd9eeeb14c970fd6e89f7b77d059d to 3bf6cd76f9a97787841fa8b113a39b6411cbb0a4
  • Keywords maxima added
  • Milestone changed from sage-8.3 to sage-8.9

doctest added. I checked that the result is indeed a primitive. Please review


New commits:

5a0a3edMerge branch 'u/nbruin/runtimeerror__encountered_operator_mismatch_in_maxima_to_sr_translation__integrate' of ssh://trac.sagemath.org:22/sage into 8.9.b7
3bf6cd7trac 25817 adding the doctest

comment:7 Changed 3 years ago by chapoton

  • Cc tscrim vklein jhpalmieri added

green bot, please review (easy one)

comment:8 Changed 3 years ago by tscrim

  • Reviewers set to Travis Scrimshaw
  • Status changed from needs_review to positive_review

LGTM.

comment:9 Changed 3 years ago by chapoton

Thanks Travis.

If you have time, please look at

https://ask.sagemath.org/question/47657/virasoro-verma-module-basis/

comment:10 Changed 3 years ago by vbraun

  • Branch changed from u/chapoton/25817 to 3bf6cd76f9a97787841fa8b113a39b6411cbb0a4
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.