Menu

#4257 Incorrect change of variable in integral involving diff

None
closed
5
2024-01-31
2024-01-29
No
(%i2) integrate (cos(2*x) * 'diff (f(x), x, 1), x);
                                                new-var-16771
diff: second argument must be a variable; found ─────────────
                                                      2

Observed in current version (be9074f).

debugmode(true) and then trying again, and then control-C at the debugger prompt, and then looking at a Lisp stack trace shows the error is coming out of the Risch code, but I think the actual error is earlier -- looks like some function, maybe MONSTERTRIG, not sure, has tried to make a change of variable but the diff is handled incorrectly.

Related

Bugs: #4258
Commit: [1ad835]
Commit: [4d8e30]

Discussion

  • Raymond Toy

    Raymond Toy - 2024-01-29

    This is probably something I did while trying to remove/reduce the number of special variables.

     
  • Raymond Toy

    Raymond Toy - 2024-01-29

    Oh, wait. This might be older than that. Maxima 5.45.1 produces the same thing.

     
  • Raymond Toy

    Raymond Toy - 2024-01-29

    Probably caused by [4c9c1efb86] from me from 2007-01-19 where we have this bit fo code that does the substitution in monstertrig:

        (let ((arg (simple-trig-arg trigarg var2)))
          (cond (arg
             ;; We have trig(c*x+b).  Use the substitution y=c*x+b to
             ;; try to compute the integral.  Why?  Because x*sin(n*x)
             ;; takes longer and longer as n gets larger and larger.
             ;; This is caused by the Risch integrator.  This is a
             ;; work-around for this issue.
             (let* ((c (cdras 'c arg))
                (b (cdras 'b arg))
                (new-var (gensym "NEW-VAR-"))
                (new-exp (maxima-substitute (div (sub new-var b) c)
                            var2 expr)))
    

    I notice that changevar has a similar problem:

    (%i17) changevar('integrate(cos(2*x)*'diff(f(x),x,1),x), 2*x=y,y,x);
    
                                
                                  d     y
                                 (── (f())) cos(y) dy
                                   y    2
                                  d
                                    2
    (%o17)                      ───────────────────────
                                           2
    
     
  • Raymond Toy

    Raymond Toy - 2024-01-30

    If I comment out the when block at the beginning of monstertrig, this integral now just returns the nounform. And the comment about integrals of x*sin(n*x) taking longer and longer doesn't seem to be true anymore. The commit log for [4c9c1e] says

    [ 1631094 ] integrate(sin(n*x)*x, x) => linear time when n is an integer
    

    Add a special case to MONSTERTRIG to match n*x+b where n is a number
    and b is free of x. We use the substitution y = n*x+b to evaluate the
    integral.

    I tried with n=10 and100, which take 0 time. n=1000 takes 0.02 sec. n=10000 takes 0.01 sec. I guess this is all in the noise.

    Too bad SF changed bug trackers because I have no idea what bug 1631094 really says.

     

    Related

    Commit: [4c9c1e]


    Last edit: Robert Dodier 2024-01-30
  • Robert Dodier

    Robert Dodier - 2024-01-30

    Ray, thanks for looking into it. SF still recognizes old bug numbers if you paste it into a suitable URL, e.g. http://sourceforge.net/tracker/?func=detail&atid=104933&aid=1631094&group_id=4933 which redirects to bug #1053, the bug number itself being the aid= part.

    OK by me to revert the previous fix -- looks like sin(<literal integer>*x) is being handled by some different path now; PCOEFADD and PEXPT (mentioned in bug #1053) aren't called, and even for fairly large integers, e.g.,

    integrate (sin (93932923323999393493499349392399239239393392392999595*x), x);
    

    it returns immediately, so it seems unlikely there is any iteration going on.

    I guess changevar has its own change of variable bug related to diff -- probably it needs its own bug report.

     
    • Raymond Toy

      Raymond Toy - 2024-01-31

      Oh, I didn't know you could still get the old bug number. There are quite a few places in the code (and tests) that reference the old bug numbers. These should be fixed. And maybe a link instead of just listing a bug number.

       
  • Raymond Toy

    Raymond Toy - 2024-01-31
    • status: open --> closed
    • assigned_to: Raymond Toy
     
  • Raymond Toy

    Raymond Toy - 2024-01-31

    Fixed in [63b1b1d7124cb5d5441023d7417fcc351f88bc24]

    We basically removed the old substitution code that doesn't seem to be needed anymore. And added a simple test for this.

     

    Related

    Commit: [63b1b1]


Log in to post a comment.

MongoDB Logo MongoDB