Menu

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

None
closed
nobody
5
2022-02-11
2021-07-02
No

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.

Related

Bugs: #3807

Discussion

  • Gunter Königsmann

    ...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...

     
    • Robert Dodier

      Robert Dodier - 2021-07-02

      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.

       
      • Stavros Macrakis

        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

         

        Related

        Bugs: #3807

  • Gunter Königsmann

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

     
  • Jaime E. Villate

    It is possible to relax the requirement on the number of variables, leaving it to the user to make user the expression leads to numbers (as someone has suggested in another ticket). But in that case I would rather give a warning and let plot2d end with an error if the expression does not give numbers, rather than trying to use some heuristics.

     
  • Robert Dodier

    Robert Dodier - 2021-10-09

    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.
    
     
  • Jaime E. Villate

    • status: open --> closed
     
  • Jaime E. Villate

    Fixed by commit [558ba7].

     

    Related

    Commit: [558ba7]


Log in to post a comment.