Re: Logical connective "or"

32 views
Skip to first unread message

Volker Braun

unread,
Dec 7, 2012, 9:39:09 AM12/7/12
to sage-s...@googlegroups.com
"or" is just the normal Python boolean operation. 

When you evaluate y == 5 or y == 15, the Python interpreter first checks if the first statement is true:

sage: bool(y==5)
False

Since the first operand is false, the result of "or" is the second operand.

sage: y == 5 or 'second operand'
'second operand'



On Friday, December 7, 2012 1:45:37 PM UTC, charmi panchal wrote:
Hello !
I would like understand how "or" works in sage.
I tried following .
var('y'); (y == 5 or y == 15)

and sage displays.
y
y == 15

While I tried the same in mathematica and it just displays : (y == 5 or y == 15)
In sage "or" works perfect for boolean values, true and false.

But why sage chooses  "y==15" instead of displaying "(y == 5 or y == 15)" like mathematica.  

Best regards
Charmi
 

Simon King

unread,
Dec 7, 2012, 9:43:37 AM12/7/12
to sage-s...@googlegroups.com
Hi Volker,

On 2012-12-07, Volker Braun <vbrau...@gmail.com> wrote:
> ------=_Part_251_18870492.1354891149790
> Content-Type: text/plain; charset=ISO-8859-1
>
> "or" is just the normal Python boolean operation.

But then: How can one combine symbolic expressions without automatic
evaluation?

Best regards,
Simon

Volker Braun

unread,
Dec 7, 2012, 10:17:51 AM12/7/12
to sage-s...@googlegroups.com
Short answer: I don't know. What are you trying to achieve?

Long answer: I'd use the propositional calculus http://www.sagemath.org/doc/reference/sage/logic/propcalc.html to compute the truth table for the statement. Then each row is a system of equations/negated equations that you can feed into maxima. 

Any better options?

Nils Bruin

unread,
Dec 7, 2012, 11:36:21 AM12/7/12
to sage-s...@googlegroups.com
On Friday, December 7, 2012 6:43:37 AM UTC-8, Simon King wrote:
But then: How can one combine symbolic expressions without automatic
evaluation?
 by implementing symbolic 'and' and 'or' functions. You can already do the formal stuff:

sage: function('symbolic_or')
sage: symbolic_or(x==2,x==4)
symbolic_or(x == 2, x == 5)

you'd still need to put the plumbing in to get the semantics (and link that to the `bool` function on symbolics). Maxima has symbolic 'and' and 'or' so there's a pretty good chance one could get it to work in a lot of cases.

You can't reasonably overload python's 'and' and 'or' with this functionality though: they're supposed to be shortcutting and a lot of python code depends on that behaviour to function correctly. There are 'bitwise' operations '&' and '|' that one could overload to be symbolic 'and' and 'or' for symbolic expressions.
Reply all
Reply to author
Forward
0 new messages