From: Stavros M. (Σ. Μ. <mac...@al...> - 2017-07-18 23:18:01
|
It's easy enough to try *all* sequences of simplification you want to explore: multif_fixedpoint(new,funs) := block([done:new], while new#{} do ( new: setdifference(setify(create_list(apply(func,[i]),func,funs,i,listify(new))), done), done: union(new,done), if length(new)>30 or length(done)>50 /* catch over-expansion */ then (global_new: new, global_done: done, error("overflow")) /* assign to global_x for debugging */ ), done); ratsimp_alg(ex) := block([algebraic:true],ratsimp(ex))$ squaresimp(ex) := ratsimp_alg(sqrt(expand(ex^2)))$ squaresimpf(ex) := ratsimp_alg(sqrt(factor(ex^2)))$ partfracx(ex) := partfrac(ex,'x)$ load(ntrig)$ testx : expand( (-1-cos(4*%pi/5)+%i*sin(4*%pi/5))/(1-cos(4*%pi/5)+%i*sin(4*%pi/5)), 0 , 0)$ test1() := multif_fixedpoint( { testx }, '[ratsimp,ratsimp_alg,squaresimp,squaresimpf,partfracx,radcan,rectform])$ ... you might want to add, say, factor or factorsum or any other value-preserving transformation ... Now tt: test1() => { (sqrt(5-2*sqrt(5))*%i)/sqrt(5), (sqrt(5-2*sqrt(5))*%i)/sqrt(5), (sqrt(sqrt(5)+5)*(sqrt(2)*sqrt(5)-sqrt(2))*%i)/(2*sqrt(5)+10), (sqrt(sqrt(5)+5)*(3*sqrt(2)*sqrt(5)-5*sqrt(2))*%i)/20, ((((1-((-sqrt(5))-1)/4)*(sqrt(5)-1)*sqrt(sqrt(5)+5))/2^(5/2)-(((-((-sqrt(5))-1)/4)-1)*(sqrt(5)-1)*sqrt(sqrt(5)+5))/2^(5/2))*%i)/(((sqrt(5)-1)^2*(sqrt(5)+5))/32+(1-((-sqrt(5))-1)/4)^2)+(((sqrt(5)-1)^2*(sqrt(5)+5))/32+((-((-sqrt(5))-1)/4)-1)*(1-((-sqrt(5))-1)/4))/(((sqrt(5)-1)^2*(sqrt(5)+5))/32+(1-((-sqrt(5))-1)/4)^2), ((sqrt(sqrt(5)+5)*(2*sqrt(5)+10)*(sqrt(2)*sqrt(5)-sqrt(2))-sqrt(sqrt(5)+5)*(2*sqrt(5)-6)*(sqrt(2)*sqrt(5)-sqrt(2)))*%i)/((sqrt(5)+5)*(sqrt(2)*sqrt(5)-sqrt(2))^2+(2*sqrt(5)+10)^2)+((sqrt(5)+5)*(sqrt(2)*sqrt(5)-sqrt(2))^2+(2*sqrt(5)-6)*(2*sqrt(5)+10))/((sqrt(5)+5)*(sqrt(2)*sqrt(5)-sqrt(2))^2+(2*sqrt(5)+10)^2), (sqrt(sqrt(5)+5)*(sqrt(2)*sqrt(5)-sqrt(2))*%i+2*sqrt(5)-6)/(sqrt(sqrt(5)+5)*(sqrt(2)*sqrt(5)-sqrt(2))*%i+2*sqrt(5)+10), (((sqrt(5)-1)*sqrt(sqrt(5)+5)*%i)/2^(5/2)-((-sqrt(5))-1)/4-1)/(((sqrt(5)-1)*sqrt(sqrt(5)+5)*%i)/2^(5/2)-((-sqrt(5))-1)/4+1) } Let's sort those by length (as a proxy for simplicity): sort(listify(tt),lambda([a,b],slength(string(a))<slength(string(b)))) => [ (sqrt(5-2*sqrt(5))*%i)/sqrt(5), (sqrt(5-2*sqrt(5))*%i)/sqrt(5), <<< see below (sqrt(sqrt(5)+5)*(3*sqrt(2)*sqrt(5)-5*sqrt(2))*%i)/20, (sqrt(sqrt(5)+5)*(sqrt(2)*sqrt(5)-sqrt(2))*%i)/(2*sqrt(5)+10), (sqrt(sqrt(5)+5)*(sqrt(2)*sqrt(5)-sqrt(2))*%i+2*sqrt(5)-6)/(sqrt(sqrt(5)+5)*(sqrt(2)*sqrt(5)-sqrt(2))*%i+2*sqrt(5)+10), (((sqrt(5)-1)*sqrt(sqrt(5)+5)*%i)/2^(5/2)-((-sqrt(5))-1)/4-1)/(((sqrt(5)-1)*sqrt(sqrt(5)+5)*%i)/2^(5/2)-((-sqrt(5))-1)/4+1), ((sqrt(sqrt(5)+5)*(2*sqrt(5)+10)*(sqrt(2)*sqrt(5)-sqrt(2))-sqrt(sqrt(5)+5)*(2*sqrt(5)-6)*(sqrt(2)*sqrt(5)-sqrt(2)))*%i)/((sqrt(5)+5)*(sqrt(2)*sqrt(5)-sqrt(2))^2+(2*sqrt(5)+10)^2)+((sqrt(5)+5)*(sqrt(2)*sqrt(5)-sqrt(2))^2+(2*sqrt(5)-6)*(2*sqrt(5)+10))/((sqrt(5)+5)*(sqrt(2)*sqrt(5)-sqrt(2))^2+(2*sqrt(5)+10)^2), ((((1-((-sqrt(5))-1)/4)*(sqrt(5)-1)*sqrt(sqrt(5)+5))/2^(5/2)-(((-((-sqrt(5))-1)/4)-1)*(sqrt(5)-1)*sqrt(sqrt(5)+5))/2^(5/2))*%i)/(((sqrt(5)-1)^2*(sqrt(5)+5))/32+(1-((-sqrt(5))-1)/4)^2)+(((sqrt(5)-1)^2*(sqrt(5)+5))/32+((-((-sqrt(5))-1)/4)-1)*(1-((-sqrt(5))-1)/4))/(((sqrt(5)-1)^2*(sqrt(5)+5))/32+(1-((-sqrt(5))-1)/4)^2) ] Let's evaluate numerically to check that they are equivalent: map(lambda([ex],rectform(float(ex))),tt) => {0.3249196962329062*%i+3.068580969878509e-17,0.3249196962329063*%i+3.068580969878509e-17,0.3249196962329063*%i-2.775557561562891e-17,0.3249196962329063*%i+6.938893903907228e-17,0.3249196962329063*%i,0.3249196962329063*%i,0.3249196962329066*%i} which looks good, I guess, especially if you look at the cabs: map(cabs,%o148); => {0.3249196962329062,0.3249196962329063,0.3249196962329063,0.3249196962329066} You might have noticed something funny about the first two expressions in tt, though: they print identically, but they are not equal, because they are not the same internally. This is a bug. In fact, there are multiple ways of getting the wrong version of that expression (wrong means that resimplifying with expand(ex,0,0) doesn't give the same result as ex). My guess is that they are all being generated by ratdisrep, but I'm not going to investigate right now.... The procedure can also go wrong if you add a function to the list which makes bigger and bigger expressions. An example? rootscontract.... Have fun, -s On Tue, Jul 18, 2017 at 4:52 PM, Richard Fateman <fa...@be...> wrote: > in general those nested roots are ambiguous > because there are 2 sqrts. The fact that float() > gets the "right" result is partly concidence. > > On the other hand, it is a useful (if theoretically > dubious) technique to evaluate expressions to > floating-point numbers to see if they are the same, > just as originally posted. > > RJF > > On 7/18/2017 12:55 PM, Roland Salz wrote: > >> -----Original Message----- >>> From: Raymond Toy [mailto:toy...@gm...] >>> >>> Here is one way. Take Barton's result: >>> >>> c: (sqrt(sqrt(5)+5)*(3*sqrt(2)*sqrt(5)-5*sqrt(2))*%i)/20 >>> c^2; >>> ratsimp(sqrt(expand(%))),algebraic; >>> >>> => sqrt(5-2*sqrt(5))*%i/sqrt(5) >>> >>> The c^2 and expand is a hack to get maxima to multiply the contents of >>> the sqrt together. This really only works >>> because the imagpart is positive. Otherwise, we probably would have >>> gotten the wrong sign. >>> >>> Great! There seems to be a magic word for everything in Maxima. Thanks a >> lot to both of you! >> >> Roland >> >> >> >> ------------------------------------------------------------ >> ------------------ >> Check out the vibrant tech community on one of the world's most >> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >> _______________________________________________ >> Maxima-discuss mailing list >> Max...@li... >> https://lists.sourceforge.net/lists/listinfo/maxima-discuss >> > > > ------------------------------------------------------------ > ------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > Maxima-discuss mailing list > Max...@li... > https://lists.sourceforge.net/lists/listinfo/maxima-discuss > |