Bug report ID:635627 - subst([...] is order-dependent



The functions subst and sublis differ in the order of substitution and 
simplification. 
The function sublis does the substitutions followed by simplification; the 
function
subst does simplifications along the way. This gives rise to subtle 
(almost magical)
differences.

 (%i1) timer(?simplifya)$

Using subst results in 69 calls to simplifya:

 (%i2) subst([x=5,y=9,z=42], x+y+(x+z)^2);
 (%o2) 2223

 (%i3) timer_info();
 (%o3) 
matrix([function,time//call,calls,runtime,gctime],[simplifya,0,69,0,0],[total,0,69,0,0])

 (%i4) (untimer(?simplifya), timer(?simplifya))$

But using sublis results in 48 calls to simplifya:

 (%i5) sublis([x=5,y=9,z=42], x+y+(x+z)^2);
 (%o5) 2223

 (%i6) timer_info();
 (%o6) 
matrix([function,time//call,calls,runtime,gctime],[simplifya,0,48,0,0],[total,0,48,0,0])

The to_poly_solve exploits the slight differ to avoid division by zero in 
conditionals:

 (%i7) load(to_poly_solver)$
 (%i8) subst(x=0, %if(x < 10, 0,1/x));
 Division by 0 -- an error. To debug this try: debugmode(true);

 (%i10) sublis([x=0], %if(x < 10, 0,1/x));
 (%o10) 0

Maybe that was a poor choice, but every alternative I thought of would 
break stuff.

> We can modify to_poly_solve or any other functions which
> expect serial substitution.

I hope that the to_poly_solve regression test is sturdy...

--Barton