rtoy / maxima

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

plot2d heuristic to detect unbound variables excludes some valid cases #2866

Closed rtoy closed 2 months ago

rtoy commented 2 months ago

Imported from SourceForge on 2024-07-07 00:07:27 Created by robert_dodier on 2021-07-02 05:04:47 Original: https://sourceforge.net/p/maxima/bugs/3807


plot2d has a bit of code to figure out if the expression to be plotted has variables that are unbound, which would lead to many or all values being nonnumeric and therefore unplottable. The heuristic is that if listofvars(f(x)) returns something other than x (where f is the function constructed by COERCE-FLOAT-FUN and x is the plotting variable) then those other variables are unbound and therefore the function is rejected.

This excludes some classes of valid functions, e.g. expressions containing calls to quadpack functions or find_root; there may be others, anything with a dummy variable has the potential to tickle the bug.

(%i1) plot2d (quad_qags (sin(u), u, 0, x)[1], [x, 0, 1]);
plot2d: expression quad_qags(sin(u),u,0,x,epsrel = 1.0E-8,epsabs = 0.0,
                             limit = 200)[
                    1]
    should  depend only on x, or be an expression of 2 variables
    equal another expression of the same variables.
 -- an error. To debug this try: debugmode(true);
(%i2) plot2d (find_root (sin(u) - x, u, 0, %pi/2), [x, 0, 1]);
plot2d: expression find_root(sin(u)-x,u,0.0,1.570796326794897)
    should  depend only on x, or be an expression of 2 variables
    equal another expression of the same variables.
 -- an error. To debug this try: debugmode(true);

These examples worked as expected with Maxima 5.44.

Trying to see what the function does with a trial value is susceptible to mistakes, since the function can do something different when there's a numerical value. I think a preferable solution is to remove the listofvars check, and go ahead with adaptive plotting, and go to a small depth (adapt_depth = 1, 2, or 3, let's say) for a trial run, and if that yields only nonnumeric values, then give up, otherwise keep going.

rtoy commented 2 months ago

Imported from SourceForge on 2024-07-07 00:07:29 Created by peterpall on 2021-07-02 08:05:26 Original: https://sourceforge.net/p/maxima/bugs/3807/#84bd


...or is there a way of making listofvars stronger? I rather like the fact that the plotting functions no more only say that the function that is to be plotted evaluates to a non-number in all points that were tested initially, but can tell which variable one failed to eliminate before plotting. Also one could argue we detect the list of variables in quad_qag expressions wrong...

rtoy commented 2 months ago

Imported from SourceForge on 2024-07-07 00:07:33 Created by robert_dodier on 2021-07-02 18:35:15 Original: https://sourceforge.net/p/maxima/bugs/3807/#84bd/4267


I'm inclined to agree with figuring out how to tell listofvars about dummy variables for quadpack functions, find_root, and maybe others, and that would fix the examples I gave.

However, there are other cases which used to work and now they don't, involving functions that don't work for symbolic arguments. For example, length, makelist, for, etc. As it stands, the unbound-variable heuristic requires that expressions be evaluated for symbolic argument; I don't think this restriction is necessary.

Maybe instead of an error, plot2d can just give a warning.

@villate I would be interested to hear what you think about all this.

rtoy commented 2 months ago

Imported from SourceForge on 2024-07-07 00:07:36 Created by macrakis on 2021-07-02 19:27:27 Original: https://sourceforge.net/p/maxima/bugs/3807/#84bd/4267/641d


I agree that a warning is much more appropriate than an error when we're using an unreliable heuristic.

         -s

On Fri, Jul 2, 2021 at 2:35 PM Robert Dodier via Maxima-bugs < maxima-bugs@lists.sourceforge.net> wrote:

I'm inclined to agree with figuring out how to tell listofvars about dummy variables for quadpack functions, find_root, and maybe others, and that would fix the examples I gave.

However, there are other cases which used to work and now they don't, involving functions that don't work for symbolic arguments. For example, length, makelist, for, etc. As it stands, the unbound-variable heuristic requires that expressions be evaluated for symbolic argument; I don't think this restriction is necessary.

Maybe instead of an error, plot2d can just give a warning.

@villate https://sourceforge.net/u/villate/ I would be interested to hear what you think about all this.

Status: open Group: None Labels: plot2d plotting Created: Fri Jul 02, 2021 05:04 AM UTC by Robert Dodier Last Updated: Fri Jul 02, 2021 08:05 AM UTC Owner: nobody

plot2d has a bit of code to figure out if the expression to be plotted has variables that are unbound, which would lead to many or all values being nonnumeric and therefore unplottable. The heuristic is that if listofvars(f(x)) returns something other than x (where f is the function constructed by COERCE-FLOAT-FUN and x is the plotting variable) then those other variables are unbound and therefore the function is rejected.

This excludes some classes of valid functions, e.g. expressions containing calls to quadpack functions or find_root; there may be others, anything with a dummy variable has the potential to tickle the bug.

(%i1) plot2d (quad_qags (sin(u), u, 0, x)[1], [x, 0, 1]);plot2d: expression quad_qags(sin(u),u,0,x,epsrel = 1.0E-8,epsabs = 0.0, limit = 200)[ 1] should depend only on x, or be an expression of 2 variables equal another expression of the same variables. -- an error. To debug this try: debugmode(true);(%i2) plot2d (find_root (sin(u) - x, u, 0, %pi/2), [x, 0, 1]);plot2d: expression find_root(sin(u)-x,u,0.0,1.570796326794897) should depend only on x, or be an expression of 2 variables equal another expression of the same variables. -- an error. To debug this try: debugmode(true);

These examples worked as expected with Maxima 5.44.

Trying to see what the function does with a trial value is susceptible to mistakes, since the function can do something different when there's a numerical value. I think a preferable solution is to remove the listofvars check, and go ahead with adaptive plotting, and go to a small depth (adapt_depth = 1, 2, or 3, let's say) for a trial run, and if that yields only nonnumeric values, then give up, otherwise keep going.

Sent from sourceforge.net because maxima-bugs@lists.sourceforge.net is subscribed to https://sourceforge.net/p/maxima/bugs/

To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/maxima/admin/bugs/options. Or, if this is a mailing list, you can unsubscribe from the mailing list.


Maxima-bugs mailing list Maxima-bugs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/maxima-bugs

Attachments:

rtoy commented 2 months ago

Imported from SourceForge on 2024-07-07 00:07:40 Created by peterpall on 2021-07-03 07:15:26 Original: https://sourceforge.net/p/maxima/bugs/3807/#5526


A warning would be great: it helps the user debugging the problem and tells where listofvars still isn't perfect.

rtoy commented 2 months ago

Imported from SourceForge on 2024-07-07 00:07:43 Created by robert_dodier on 2021-10-09 07:16:41 Original: https://sourceforge.net/p/maxima/bugs/3807/#b0fa


Another example, collected from the mailing list 2021-10-08:


(%i1) plot2d(sum(w, w, 1, abs(x)), [x, 1, 10]);
plot2d: expression 'sum(w,w,1,abs(x))
    should  depend only on x, or be an expression of 2 variables
    equal another expression of the same variables.
rtoy commented 2 months ago

Imported from SourceForge on 2024-07-07 00:07:47 Created by villate on 2022-02-11 16:05:55 Original: https://sourceforge.net/p/maxima/bugs/3807/#a924


rtoy commented 2 months ago

Imported from SourceForge on 2024-07-07 00:07:50 Created by villate on 2022-02-11 16:05:55 Original: https://sourceforge.net/p/maxima/bugs/3807/#ff94


Fixed by commit [558ba7].