rtoy / maxima

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

inconsistent treatment of simple and subscripted assignments in ev #3309

Open rtoy opened 2 months ago

rtoy commented 2 months ago

Imported from SourceForge on 2024-07-07 20:49:14 Created by robert_dodier on 2019-02-03 03:01:45 Original: https://sourceforge.net/p/maxima/bugs/3526


ev handles assignments to simple variables differently than assignments to subscripted variables. Assignments to simple variables are handled by binding (via MBIND) the variables. Assignments to subscripted variables are handled by substituting the value for the subscripted variable in the input expression, and then evaluating the expression.

Since the subscripted variables are not bound, any further occurence of the subscripted variables in the evaluation won't make use of the assigned value. Here is an example, take from [1].

(%i1) f(x) := a[0]*x $

(%i2) ev (f(z), a[0]=99);
(%o2)                                a  z
                                      0

But if the variable is a0 instead of a[0] the result is what you'd expect from dynamic binding:

(%i3) g(x) := a0*x $

(%i4) ev (g(z), a0=99);
(%o4)                                99 z

The behavior of ev is actually documented: "If 'V' is a non-atomic expression then a substitution rather than a binding is performed." But I think the current behavior is a bug anyway, since it is counterintuitive at best.

[1] https://stackoverflow.com/questions/54300600/maxima-indexed-variables-assigned-in-evaluation-of-function

rtoy commented 2 months ago

Imported from SourceForge on 2024-07-07 20:49:15 Created by robert_dodier on 2019-02-03 20:22:00 Original: https://sourceforge.net/p/maxima/bugs/3526/#06e6


rtoy commented 2 months ago

Imported from SourceForge on 2024-07-07 20:49:19 Created by robert_dodier on 2019-02-03 20:22:00 Original: https://sourceforge.net/p/maxima/bugs/3526/#fbfb


I'm closing this one as won't-fix since changing ev(..., a[0]=b) to use binding instead of substitution breaks the existing use of temporary assignment in ev to effect substitutions. It turns out there are many instances of that in the test suite -- stuff like ev(..., laplace(expr, u, v) = ...). I don't think there's any comprehensible way to distinguish assignments which can succeed from ones, like the laplace example, which can't, so at this point I think using binding instead of substitution can't work.