rtoy / maxima

A Clone of Maxima's repo
Other
0 stars 0 forks source link

Multiple evaluation of logical expressions #1144

Open rtoy opened 3 months ago

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-04 00:48:44 Created by macrakis on 2016-02-07 22:53:15 Original: https://sourceforge.net/p/maxima/bugs/3087


s: not s$ is(s) => stack overflow not s => stack overflow s or s => stack overflow s and true => stack overflow if s then 3 => stack overflow

Compare this to the completely unproblematic:

x: -x$ -x => x x * 1 => -x

This is presumably all because of the perverse way logical operators are evaluated.

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-04 00:48:44 Created by macrakis on 2016-02-15 02:00:22 Original: https://sourceforge.net/p/maxima/bugs/3087/#d6f6


To elaborate a bit on: "the perverse way logical operators are evaluated."

Arithmetic operators are simplifying functions. They have no attached "function body". Logical operators on the other hand are MFEXPR (), that is, they are functions whose arguments are passed in without evaluation. It is up to them to evaluate the argments, which they do with mevalp.

Mevalp is a special kind of evaluation which checks whether equalities/inequalities are true.

Equalities/inequalities are normally not "evaluated", just like arithmetic operators. Just as (a+1) evaluates to (a+1), (a<0) evaluates to (a<0).

But in several special contexts, in/equalities are evaluated. Those special contexts are: as arguments to and/or/not, in is/maybe, and as the conditional part of an "if".

Thus:

assume(a<0)$
a<0 => a<0

But:

a<0 and a<0 => true

It is perversely the "and" that causes the truth-value of "a<0" to be checked.

I suspect we can fairly straightforwardly make and/or/not into regular simplifying functions and in fact share the logic used to evaluate them in acall.lisp (mevalp_tr and friends).