Fix for bug [ 1370433 ] trigsimp(sqrt(%i2))!=sqrt(trigsimp(%i2))?




> -----Original Message-----
> From: maxima-bounces at math.utexas.edu [mailto:maxima-
> bounces at math.utexas.edu] On Behalf Of Jaime E. Villate
> Sent: Friday, November 10, 2006 7:15 AM
> To: Raymond Toy
> Cc: fateman at cs.berkeley.edu; maxima at math.utexas.edu
> Subject: Re: [Maxima] Fix for bug [ 1370433 ]
> trigsimp(sqrt(%i2))!=sqrt(trigsimp(%i2))?
> 
> On Thu, 2006-11-09, Raymond Toy wrote:
> > expr:2*(cos(x)^2-sin(x)^2)+2;
> > sqrt(trigsimp(expr))
> > trigsimp(sqrt(expr))
> 
> > Richard Fateman wrote:
> > > There are two square roots. Which do you mean?
> > > either 2*abs(cos(x))  or -2*abs(cos(x))
> > > Since you have not specified which one, how is Maxima to know?
> > >
> > Doesn't sqrt(x) mean the principal square root?
> That was what I thought too. When Maxima gives me the results:
> 
> (%i2) sqrt(x^2);
> (%o2) abs(x)
> (%i3) solve(a*x^2+b*x+c, x);
> (%o3) [x = -(sqrt(b^2-4*a*c)+b)/(2*a),x = (sqrt(b^2-4*a*c)-b)/(2*a)]
> 
> I understand that sqrt() refers to the square root with either real or
> imaginary part positive. Otherwise, if sqrt() referred to the two roots,
> the results above should be:
> (%o2) [abs(x), -abs(x)]
> (%o3) x = (sqrt(b^2-4*a*c)+b)/(2*a)
> 
> ( or x = -(sqrt(b^2-4*a*c)+b)/(2*a) which would be equivalent)

I disagree on both.
The result of the first would be  {x, -x}.  Each of the elements in this set
would be a continuous differentiable function of x such that when squared
gives x.  Neither abs(x) nor -abs(x) is necessary here, and these functions
have singularities at x=0, usually considered a bad thing.

For the second answer we would have
  X = {(-b+D)/(2*a) |  D=RootOf(z^2-b^2-4*a*c=0,z)}. What do we know about
D={D[1],D[2]}?  There are two elements, and for any d in D,
   d^2=4*a*c  and also D[1]+D[2]=0.

Pro: This is mathematically "more correct". It doesn't say WHICH root is
(say) positive, because it doesn't matter and can't know without values for
a,b,c.
Con:  Maxima is not outfitted to handle this. People do not expect to see
this.

Perhaps this correct answer can be downgraded for human consumption, in a
way similar to downgrading the correct answer log(h)  to log(abs(h)) for
people who have not yet learned of I = sqrt(-1). Maybe the setting of
radexpand should be the deciding flag.  

Most of this is irrelevant if the item inside sqrt() is a positive real
number.  The problem is:  Trying to make the rules for sqrt of positive real
numbers work for everything else, especially expressions like sqrt(x^2) and
1^(1/8) lead to paradoxes.

> 
> Thus, I would expect both sqrt(trigsimp(expr)) and trigsimp(sqrt(expr))
> to return 2*abs(cos(x))

The correct answer by my reasoning would be something like {2*D |
D=RootOf(z^2= cos(x),z) }  A set of two expressions.  Or perhaps
2*sqrt(cos(x)^2).  Which may be what radexpand: false gets.

> 
> On the same subject, following a question recently answered in this
> list, I would expect plot2d(sqrt(x^2),[x,-3,3]) to show the plot of
> abs(x)

If you view "^2" and "sqrt" or "^(1/2)" as a mapping from real numbers to
real numbers, and you (artificially) impose on sqrt that it means only the
non-negative value, this is OK for simple cases. But Maxima is not doing
just numerical real calculation. Generalizing the rule to (say)
(x^5+1)^(1/8) does not work. There are 8 different roots. Which do you
choose?  Abs() is not helpful.

RJF