Menu

#54 Add local declarations in share/numeric/interpol.mac

None
closed
nobody
interpol (1)
5
2023-09-14
2014-04-02
No

Add local declarations in share/numeric/interpol.mac

It prevents errors like

(%i1) load("interpol")$
(%i2) tab[any]:=error();
(%o2)                          tab    := error()
                                  any
(%i3) linearinterpol(dat1), dat1: matrix([6.5,3],[1.8,-8],[9,2],[-2,4],[1/8,1][9/12,3],[10,%pi]);
#0: lambda([any],error())(any=2)
#1: linearinterpol(tab=matrix([6.5,3],[1.8,-8],[9,2],[-2,4],[1/8,1],[3/4,3],[10,%pi]),select=[])(interpol.mac line 148)
 -- an error. To debug this try: debugmode(true);

Related

Patches: #54

Discussion

  • Raymond Toy

    Raymond Toy - 2023-09-12

    This doesn't happen in the latest version of maxima. First, there's a typo in the definition of dat1. There's a missing comma before the list [9/12,3]. When that is fixed, I get:

    (%i10) linearinterpol(dat1), dat1:matrix([6.5,3],[1.8,-8],[9,2],[-2,4],[1/8,1],[9/12,3],[10,%pi]);
            20   24 x              1
    (%o10) (-- - ----) charfun(x < -) + charfun(9 <= x) (%pi x - 2 x - 9 %pi + 20)
            17    17               8
                1                3    16 x   3
     + charfun((- <= x) and (x < -)) (---- + -)
                8                4     5     5
     + charfun((1.8 <= x) and (x < 6.5)) (2.3404255319148937 x
     - 12.212765957446809) + charfun((6.5 <= x) and (x < 9)) (5.6 - 0.4 x)
                3
     + charfun((- <= x) and (x < 1.8)) (10.857142857142858 - 10.476190476190476 x)
                4
    (%i11) 
    

    I didn't check to see if this is correct or not, but the error is gone.

     
  • Raymond Toy

    Raymond Toy - 2023-09-12
    • status: open --> closed
    • Group: -->
     
  • Raymond Toy

    Raymond Toy - 2023-09-12

    Closing since the error no longer happens.

     
  • Robert Dodier

    Robert Dodier - 2023-09-14

    The problem is still there. Other examples exist in the bug list; e.g. https://sourceforge.net/p/maxima/bugs/2519/ . Although this behavior is "broken as designed", that doesn't rule out trying to work around it, so I guess we might apply this patch; I'm undecided.

    Any function which has a function argument or block variable which is subscripted has the potential for showing the bug, if there exists a global symbol which has the same name. For example, I see in the interpol source code that there is a symbol data which is subscripted. So here's a way to tickle the bug:

    data[x] := error();
    load ("interpol");
    linearinterpol (matrix ([6.5, 3], [1.8, -8], [9, 2], [-2, 4], [1/8, 1], [9/12, 3], [10, %pi]));
    

    which provokes

    #0: lambda([x],error())(x=1)
    #1: interpol_check_input(data=matrix([6.5,3],[1.8,-8],[9,2],[-2,4],[1/8,1],[3/4,3],[10,%pi]),funame=linearinterpol) (interpol.mac line 49)
    #2: linearinterpol(tab=matrix([6.5,3],[1.8,-8],[9,2],[-2,4],[1/8,1],[3/4,3],[10,%pi]),select=[]) (interpol.mac line 130)
     -- an error. To debug this try: debugmode(true);
    

    This is an example of a whole class of global-local name collision bugs which go away when symbols have lexical scope, something I've worked on from time to time; I guess I should get it together and finish it. Anyone who wants to help is welcome to do so.

     
    • Stavros Macrakis

      I agree that lexical scope will fix this, but in the meantime, a
      local statement
      fixes the particular case in interpol.
      You can blindly add local(...) for all the function parameters and local
      variables -- being careful to exclude global variables like ratprint --
      and it will work. Of course, better if you only use local for the symbols
      that need it.
      This is much less efficient than a good lexical scope solution, because it
      saves and restores properties of the symbols, but at least it is correct.

              -s
      

      On Thu, Sep 14, 2023 at 3:45 PM Robert Dodier robert_dodier@users.sourceforge.net wrote:

      The problem is still there. Other examples exist in the bug list; e.g.
      https://sourceforge.net/p/maxima/bugs/2519/ . Although this behavior is
      "broken as designed", that doesn't rule out trying to work around it, so I
      guess we might apply this patch; I'm undecided.

      Any function which has a function argument or block variable which is
      subscripted has the potential for showing the bug, if there exists a global
      symbol which has the same name. For example, I see in the interpol source
      code that there is a symbol data which is subscripted. So here's a way to
      tickle the bug:

      data[x] := error();load ("interpol");linearinterpol (matrix ([6.5, 3], [1.8, -8], [9, 2], [-2, 4], [1/8, 1], [9/12, 3], [10, %pi]));

      which provokes

      0: lambda([x],error())(x=1)#1: interpol_check_input(data=matrix([6.5,3],[1.8,-8],[9,2],[-2,4],[1/8,1],[3/4,3],[10,%pi]),funame=linearinterpol) (interpol.mac line 49)#2: linearinterpol(tab=matrix([6.5,3],[1.8,-8],[9,2],[-2,4],[1/8,1],[3/4,3],[10,%pi]),select=[]) (interpol.mac line 130) -- an error. To debug this try: debugmode(true);

      This is an example of a whole class of global-local name collision bugs
      which go away when symbols have lexical scope, something I've worked on
      from time to time; I guess I should get it together and finish it. Anyone
      who wants to help is welcome to do so.


      [patches:#54] https://sourceforge.net/p/maxima/patches/54/ Add local
      declarations in share/numeric/interpol.mac

      Status: closed
      Group:
      Labels: interpol
      Created: Wed Apr 02, 2014 04:59 PM UTC by Sergey Litvinov
      Last Updated: Tue Sep 12, 2023 08:57 PM UTC
      Owner: nobody

      Add local declarations in share/numeric/interpol.mac

      It prevents errors like

      (%i1) load("interpol")$(%i2) tab[any]:=error();(%o2) tab := error() any(%i3) linearinterpol(dat1), dat1: matrix([6.5,3],[1.8,-8],[9,2],[-2,4],[1/8,1][9/12,3],[10,%pi]);#0: lambda([any],error())(any=2)#1: linearinterpol(tab=matrix([6.5,3],[1.8,-8],[9,2],[-2,4],[1/8,1],[3/4,3],[10,%pi]),select=[])(interpol.mac line 148) -- an error. To debug this try: debugmode(true);


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/maxima/patches/54/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       

      Related

      Patches: #54


Log in to post a comment.