Menu ▾ ▴

#1848 taytorat leaks internal gensyms from multivar expansions

None
closed
None
5
2022-04-01
2009-12-11
Martin
No

taytorat() produces an internal symbol visible at toplevel (%o2). According to the documentation, taytorat(expr) is equivalent to rat(ratdisrep(expr)), which is not the case here (%o3) (Not sure what rat is trying to do here).

(%i1) ft: taylor(f(x,y), [x,y],[a1,a2], [1,1]);
taytorat(ft);
ratdisrep(ft);
rat(%);
(%o1) f(a1,a2)+((at('diff(f(x,y),x,1),x=a1))*(x-a1)+(at('diff(f(a1,y),y,1),y=a2))*(y-a2))+...
(%o2) ((at('diff(f(x,y),x,1),x=a1))*(x-a1)+(at('diff(f(a1,y),y,1),y=a2))*(y-a2))*g36791+f(a1,a2)
(%o3) (at('diff(f(a1,y),y,1),y=a2))*(y-a2)+(x-a1)*(at('diff(f(x,y),x,1),x=a1))+f(a1,a2)
(%o4) (at('diff(f(a1,y),y,1),y=a2))*y+(x-a1)*(at('diff(f(x,y),x,1),x=a1))-(at('diff(f(a1,y),y,1),y=a2))*a2+f(a1,a2)

This is with
-------------------------------------------------------------
Maxima version: 5.19.2
Maxima build date: 8:55 8/31/2009
host type: i686-pc-mingw32
lisp-implementation-type: GNU Common Lisp (GCL)
lisp-implementation-version: GCL 2.6.8
-------------------------------------------------------------

Related

Bugs: #2446
Bugs: #608

Discussion

  • Kris Katterjohn

    Kris Katterjohn - 2022-04-01
    • summary: taytorat() implementation and documentation --> taytorat leaks internal gensyms from multivar expansions
    • assigned_to: Kris Katterjohn
    • Group: --> None
     
  • Kris Katterjohn

    Kris Katterjohn - 2022-04-01

    Thank you for the report. This is a very old bug.

    Here are some other examples:

    (%i1) taytorat(taylor(x,[x],0,1));
    (%o1) x*g472
    
    (%i2) taytorat(taylor(taylor(x+y,[x],0,1),[y],0,1));
    (%o2) y*g479+x*g475
    

    taytorat calls SRRAT to see if that can do the conversion. If SRRAT fails then taytorat falls back to calling ratdisrep followed to RATF. So SRRAT is supposed to be the "fast" version, but if it fails then, basically, rat(ratdisrep(...)) is used instead.

    The problem is that SRRAT doesn't handle multivariate expansions correctly and it also doesn't signal failure in this case either. taytorat thinks SRRAT succeeds and so it returns the bogus result with internal gensyms.

    I see no problems with the test suite when using following patch, which just has SRRAT give up if it sees a multivariate expansion. This will cause taytorat go through the "slow" path which handles this case.

    diff --git a/src/combin.lisp b/src/combin.lisp
    index 5f6dbf545..86b908970 100644
    --- a/src/combin.lisp
    +++ b/src/combin.lisp
    @@ -1400,8 +1400,9 @@
            (t (ratf ($ratdisrep e)))))
    
     (defun srrat (e)
    
    -  (cons (list 'mrat 'simp (caddar e) (cadddr (car e)))
    -       (srrat2 (cdr e))))
    +  (unless (some (lambda (v) (switch 'multivar v)) (mrat-tlist e))
    +    (cons (list 'mrat 'simp (mrat-varlist e) (mrat-genvar e))
    +          (srrat2 (mrat-ps e)))))
    
     (defun srrat2 (e)
       (if (pscoefp e) e (srrat3 (terms e) (gvar e))))
    

    Then we have

    (%i4) taytorat(taylor(x,[x],0,1));
    (%o4) x
    
    (%i5) taytorat(taylor(taylor(x+y,[x],0,1),[y],0,1));
    (%o5) y+x
    
    (%i6) ft: taylor(f(x,y),[x,y],[a1,a2],[1,1])$
    
    (%i7) taytorat(ft);
    (%o7) ('at('diff(f(a1,y),y,1),y = a2))*y
     +(x-a1)*('at('diff(f(x,a2),x,1),x = a1))-('at('diff(f(a1,y),y,1),y = a2))*a2
     +f(a1,a2)
    
    (%i8) rat(ratdisrep(ft));
    (%o8) ('at('diff(f(a1,y),y,1),y = a2))*y
     +(x-a1)*('at('diff(f(x,a2),x,1),x = a1))-('at('diff(f(a1,y),y,1),y = a2))*a2
     +f(a1,a2)
    
    (%i9) %o8 - %o7;
    (%o9) 0
    
     
  • Kris Katterjohn

    Kris Katterjohn - 2022-04-01

    And in case anyone else is interested: taytorat used to be called srrat a long time ago.

     
  • Kris Katterjohn

    Kris Katterjohn - 2022-04-01
    • status: open --> closed
     
  • Kris Katterjohn

    Kris Katterjohn - 2022-04-01

    Fixed by commit [38d4b2].

     

    Related

    Commit: [38d4b2]


Log in to post a comment.