8.12 changevar bug? (12.11.99)

8.12.1 Francis Sergeraert
8.12.2 Helmut Kahovec

8.12.1 Francis Sergeraert

I’ve observed a strange sign bug in student[changevar] ; look at this small session with Maple output:

> integral := Int(1, x=1..2) ; 
                     integral := Int(1,x = 1 .. 2) 
> value(%) ; 
                                    1 
> with(student, changevar) ; 
                              [changevar] 
> changevar(t=1-1/sqrt(x), integral, t) ; 
               Int(2/(-1+t)^3,t = 0 .. 1/2*(2^(1/2)-1)*2^(1/2)) 
> value(%) ; 
                                  -1
 

Computing by hand, it is clear the right integrand after changevar should be -2/(-1+t)^3 :

> solve(t=1-1/sqrt(x), x) ; 
                                 1/(-1+t)^2 
> diff(%,t); 
                                 -2/(-1+t)^3
 

Probably this type of error had already been noted ? Is there some "philosophical" idea which could alert the user about such a possible error ? In the above changevar, the traditional difficulty where the variable change reverses the orientation does not occur, so that I don’t understand what the origin of this sign bug could be.

It’s not a bug, there are two possible branches. If you substitute \(x = 1/(t-1)^2\) the other branch is used.

The reason for the result is the solution of the equation \(x = 1/(t-1)^2\) for \(t\) to calculate the limits of integration. (U. Klein)

8.12.2 Helmut Kahovec

That’s an interesting bug. The culprit is the square root function. A possible solution is that you don’t use an equation like t=1-1/sqrt(x) but solve it for x yourself before changing variables:

> restart; 
> with(student): 
> integral:=Int(1,x=1..2); 
> x=solve(t=1-1/sqrt(x),x); 
> changevar(%,integral,t); 
> value(%); 
                                  1
 
If we follow ‘student/changevar‘() executing your example then we get something like:
> restart; 
> j:=1; 
> substitut:=1-1/(sqrt(x))=t; 
> r:=x=solve(substitut,x);
 

Although ‘student/changevar‘() at some point solves the equation ’substitut’ for x it does not use that result when computing the new integrand.

If there is a square root in ’substitut’ then this is a difficult approach:

> subs(x=x(t),substitut); 
> map(diff,%,t); 
> solve(%,diff(x(t),t)); 
> subs(x(t)=x,%); 
> jj:=eval(subs(r,%)); 
                               /    1    \(3/2) 
                       jj := 2 |---------| 
                               |        2| 
                               \(-1 + t) /
 

Now ‘student/changevar‘() uses ‘expand/radical‘, which simplifies jj incorrectly:

> expand(radical(jj)); 
> jnew:=subs(r,j)*%; 
                                       1 
                         jnew := 2 --------- 
                                           3 
                                   (-1 + t)
 

‘student/changevar‘() should analyze the value of t for x=1..2 and notice that t would always be less than 1:

> t=solve(eval(substitut,x=1),t); 
> t=solve(eval(substitut,x=2),t);
 

Then jj could be simplified correctly:

> simplify(jj,assume=real); 
> applyop( 
>   u->simplify(subs(t=1-tau,u),assume=positive), 2, % 
> ); 
> jnew:=subs(r,j)*%; 
                                        1 
                         jnew := -2 --------- 
                                            3 
                                    (-1 + t)
 

IMO the following would be much easier for ‘student/changevar‘() to execute:

> r; 
> subs(x=x(t),%); 
> map(diff,%,t); 
> subs(x(t)=x,%); 
> jnew:=subs(r,j)*rhs(%);