How to get a reduced solution?



On Nov. 12, Jaime Villate wrote:
-------------
I think that linwaytin still wants some further simplification to get
the solution as he wants:
--------------
Thanks for showing that solve can make
the implicit solution explicit.

An alternative route to an explicit solution, which
provides more insight into what the sign choices 
imply, is to
1. use:
(%i27) exp(log(A));
(%o27) A
and
(%i28) log(exp(A));
(%o28) A

and 2.  simplify the equation before using solve.

I created a small batch file ex1.mac, and the run looks
like:

(%i1) batch(ex1)$
read and interpret file: #pc:/work5/ex1.mac

(%i2) de:'diff(y,x,2) = exp(y)
(%i3) assume(%k1 > 0)
(%i4) solns:ode2(de,y,x)

(%o4) [-log((sqrt(%e^y+%k1)-sqrt(%k1))/(sqrt(%e^y+%k1)+sqrt(%k1)))
        /(sqrt(2)*sqrt(%k1))
         = x+%k2,
       log((sqrt(%e^y+%k1)-sqrt(%k1))/(sqrt(%e^y+%k1)+sqrt(%k1)))
        /(sqrt(2)*sqrt(%k1))
         = x+%k2]

(%i5) s2:solns[2]

(%o5) log((sqrt(%e^y+%k1)-sqrt(%k1))/(sqrt(%e^y+%k1)+sqrt(%k1)))
       /(sqrt(2)*sqrt(%k1))
        = x+%k2
(%i6) s2:denom(lhs(s2))*s2
(%o6) log((sqrt(%e^y+%k1)-sqrt(%k1))/(sqrt(%e^y+%k1)+sqrt(%k1)))
        = sqrt(2)*sqrt(%k1)*(x+%k2)
(%i7) s2:rootscontract(s2)

(%o7) log((sqrt(%e^y+%k1)-sqrt(%k1))/(sqrt(%e^y+%k1)+sqrt(%k1)))
        = sqrt(2*%k1)*(x+%k2)

/* here is where we use A = exp(log(A))  */

(%i8) s3:map('exp,s2)
(%o8) (sqrt(%e^y+%k1)-sqrt(%k1))/(sqrt(%e^y+%k1)+sqrt(%k1))
        = %e^(sqrt(2*%k1)*(x+%k2))

/* simplify equation to be solved */

(%i9) hrule:h = part(s3,1,1,1,1)
(%o9) h = %e^y+%k1
(%i10) arule:a = -part(s3,1,1,2)
(%o10) a = sqrt(%k1)
(%i11) grule:g = rhs(s3)
(%o11) g = %e^(sqrt(2*%k1)*(x+%k2))

(%i12) s4 : (sqrt(h) - a)/(sqrt(h) + a)  =  g

(%i13) assume(a > 0,h > 0,g > 0,g < 1)

(%i14) s4soln:solve(s4,h)[1]
(%o14) h = (a^2*g^2+2*a^2*g+a^2)/(g^2-2*g+1)
(%i15) s4soln:factor(s4soln)
(%o15) h = a^2*(g+1)^2/(g-1)^2

/* restore h,a,g meanings and get f(y)
   by itself on the lhs */

(%i16) s5:ev(s4soln,hrule)
(%o16) %e^y+%k1 = a^2*(g+1)^2/(g-1)^2

(%i17) s5 : s5 - %k1
(%o17) %e^y = a^2*(g+1)^2/(g-1)^2-%k1

(%i18) s5:ev(s5,arule)
(%o18) %e^y = %k1*(g+1)^2/(g-1)^2-%k1

/* here we use log(exp(A)) = A */

(%i19) s5:map('log,s5)
(%o19) y = log(%k1*(g+1)^2/(g-1)^2-%k1)

(%i20) s5:ev(s5,grule)
(%o20) y = log(%k1*(%e^(sqrt(2)*sqrt(%k1)*(x+%k2))+1)^2
                /(%e^(sqrt(2)*sqrt(%k1)*(x+%k2))-1)^2
                -%k1)
(%i21) ysoln1:rootscontract(s5)

(%o21) y = log(%k1*(%e^(sqrt(2*%k1)*(x+%k2))+1)^2
                /(%e^(sqrt(2*%k1)*(x+%k2))-1)^2
                -%k1)
-----------------------
Of course, this is a lot more work than your solution,
but one is left with more understanding of what
parameter ranges the solution is good for.

I also avoided, in my initial work,
 using part(e,...) by just making a note
of what h, g, and a stood for,
but at least this shows how you might use part
to remember more complicated pieces of a solution.

Ted Woollett