At least Sympy, Maxima and Mathematica can treat boolean expressions as other expressions. Maxima : :
(%i1) display2d:false; (%o1) false (%i2) foo: a and b; (%o2) a and b (%i3) bar: subst([a=(%pi>3), b=(%pi<4)], foo); (%o3) %pi > 3 and %pi < 4 (%i4) is(bar); (%o4) unknown (%i5) bar, ev; (%o5) true Sympy: >>> a, b, x=symbols("a, b, x") >>> foo.subs({a:pi>3, b:x<4}) x < 4 >>> from sympy import * >>> a, b, x=symbols("a, b, x") >>> foo=And(a, b) ; foo a & b >>> foo.subs({a:pi>3, b:x<4}) x < 4 >>> foo.subs({a:pi>3, b:pi<4}) True Thanks to Sage’s and and or “lazy” operators and the interpretation on anything not zero as True, Sage’s expressions containing logical operators gives surprising results : sage: var("a, b") (a, b) sage: foo = a and b ; foo b sage: (x>3) and (x<4) x > 3 sage: (pi>3) and (x<4) x < 4 sage: (pi>3) and (pi<4) pi < 4 bool((pi>3) and (pi<4)) True As a consequence, we have no way to translate in sage the boolean expressions sometimes returned by Sympy or Maxima (e. g. Piecewise functions returned by Sympy for some integrations. It ois easy to slap _sage_ methods to Sympy’s logical functions in terms of Python expressions, but : - their interpretation won't be what us expected, and - these expressions won't translate to Maxima in a useful way : sage: "print(%s)"%(a and b) 'print(b)' sage: maxima("print(%s)"%(a and b)) b Another (better) solution is to wrap, for example, Sympy’s logical functions in symbolic function, and define suitanle conversion functions. This is easy for Sage<-> sympy translations ; Sage -> maxima translation is also manageable. Where I’m stuck is the Maxima->Sage translation (necessary given the importance of Maxima for a lot of our symbolics) : the current interface isn’”t useable : sage: maxima("a and b") aandb sage: maxima("a and b").sage() aandb sage: maxima("a and b").sage().parent() Symbolic Ring sage: maxima("a and b").sage().variables() (aandb,) sage: maxima("a and b").sage().operator() is None True sage: maxima("a and b").sage().operands() [] or worse : sage: maxima("subst([a=(%pi>3), b=(%pi<4)], a and b)") %pi>3and%pi<4 sage: maxima("subst([a=(%pi>3), b=(%pi<4)], a and b)").sage() --------------------------------------------------------------------------- SyntaxError Traceback (most recent call last) [ Snip... ] TypeError: unable to make sense of Maxima expression 'pi>3andpi<4' in Sage Maxima’s logical operators are not recognized as such and are “pasted” along their arguments. What should be done would be to get them parsed, and translated a Sages logical function calls. An alternative would be to create “symbolic logical operators” at least for the classes relevant asossible Maxima returns, but, as far as I know, this is not possible in Python. In both cases, this requires recognizing and treating specially Maxima logical operators. The code of the current Maxima interfaces stymied me : I have been unable to identify the relevant parts. Traceing test expressions failed, since the cricial parts probably written in Cython, aren’t accessible to pdb. Any hint or criticism well received. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/aaa97b25-2d1a-48aa-9814-cc2f216208ban%40googlegroups.com.