Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

A couple of answer elements :

  • Sage per se has not (yet) symbolic logical operators (but see Trac#31911).

  • Your (Mathematica ?) syntax is not Python : there is no such operators as && or ||...

With these limitations in mind, you can do :

sage: var("A, B, C, D")
(A, B, C, D)
sage: import sympy
sage: sympy.sympify('((A <= B) & (B <= C)) | ((A <= D) & (D <= C)) | ((B <= A) & (A <= D) & (D <= C)) | ((D >= C) & (A <= B) & (B <= C) ) | ((B <= A) & (D >= C))').simplify()
((A >= B) & (C <= D)) | ((C >= D) & (A <= D)) | ((A <= B) & (B <= C))

but this result cannot (yet) be translated in Sage.

There is some support for propositional logic in Sage, but these tools use string representation of the formulæ ; the translation to Sage symbolic expressions would require the addition of some support for symbolic logical functions (see the Trac cicket...).

FWIW :

sage: mathematica("FullSimplify[(A <= B && B <= C) || (A <= D && D <= C) || (B <= A && A <= D && D <= C) || (D >= C && A <= B && B <= C ) || (B <= A && D >= C)]")
(D >= C && B <= A) || (A <= B && B <= C) || (A <= D && D <= C)

sage: maxima_console()
;;; Loading #P"/usr/local/sage-9/local/lib/ecl-21.2.1/sb-bsd-sockets.fas"
;;; Loading #P"/usr/local/sage-9/local/lib/ecl-21.2.1/sockets.fas"
Maxima 5.45.0 https://maxima.sourceforge.io
using Lisp ECL 21.2.1
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) simplify((A <= B and B <= C) or (A <= D and D <= C) or (B <= A and A <= D and D <= C) or (D >= C and A <= B and B <= C ) or (B <= A and D >= C));
(%o1) simplify(((A <= B) and (B <= C)) or ((A <= D) and (D <= C))
 or ((B <= A) and (A <= D) and (D <= C))
 or ((D >= C) and (A <= B) and (B <= C)) or ((B <= A) and (D >= C)))

HTH,