Discussion:
Simplification of a trigonometric or exponentialized term
(too old to reply)
Roland Salz
2017-07-18 11:04:44 UTC
Permalink
Raw Message
The following term I don't manage to simplify, neither in trigonometric nor in exponentialized form nor with ntrig:



a:(-1-cos(4*%pi/5)+%i*sin(4*%pi/5))/(1-cos(4*%pi/5)+%i*sin(4*%pi/5));

rectform(a);

float(%);



By exponentialization I get

b:exponentialize(a);

radcan(b);



I'm pretty sure the term is identical with

c:sqrt(5-2*sqrt(5))*%i/sqrt(5);

float(c);



Using load(ntrig); gives from a:

a:(-1-cos(4*%pi/5)+%i*sin(4*%pi/5))/(1-cos(4*%pi/5)+%i*sin(4*%pi/5));

rectform(%);

radcan(%);

-> d:(sqrt(sqrt(5)+5)*(sqrt(2)*sqrt(5)-sqrt(2))*%i)/(2*sqrt(5)+10);

which again I cannot simplify to c.



How can simplification a -> c or b -> c or d -> c be achieved? A wxmx file is annexed.



Thanks for any help. Best regards,

Roland
Barton Willis
2017-07-18 13:04:35 UTC
Permalink
Raw Message
Maybe something like:

(%i2) load(ntrig)$
(%i3) a:(-1-cos(4*%pi/5)+%i*sin(4*%pi/5))/(1-cos(4*%pi/5)+%i*sin(4*%pi/5))$

(%i4) trigrat(a);
(%o4) (sqrt(sqrt(5)+5)*(3*sqrt(2)*sqrt(5)-5*sqrt(2))*%i)/20


--Barton
________________________________
From: Roland Salz <***@gmail.com>
Sent: Tuesday, July 18, 2017 6:04:44 AM
To: maxima-***@lists.sourceforge.net
Subject: [Maxima-discuss] Simplification of a trigonometric or exponentialized term

The following term I don’t manage to simplify, neither in trigonometric nor in exponentialized form nor with ntrig:

a:(-1-cos(4*%pi/5)+%i*sin(4*%pi/5))/(1-cos(4*%pi/5)+%i*sin(4*%pi/5));
rectform(a);
float(%);

By exponentialization I get
b:exponentialize(a);
radcan(b);

I’m pretty sure the term is identical with
c:sqrt(5-2*sqrt(5))*%i/sqrt(5);
float(c);

Using load(ntrig); gives from a:
a:(-1-cos(4*%pi/5)+%i*sin(4*%pi/5))/(1-cos(4*%pi/5)+%i*sin(4*%pi/5));
rectform(%);
radcan(%);
-> d:(sqrt(sqrt(5)+5)*(sqrt(2)*sqrt(5)-sqrt(2))*%i)/(2*sqrt(5)+10);
which again I cannot simplify to c.

How can simplification a -> c or b -> c or d -> c be achieved? A wxmx file is annexed.

Thanks for any help. Best regards,
Roland
Roland Salz
2017-07-18 15:38:50 UTC
Permalink
Raw Message
Thanks, Barton. That's little better than what I had achieved in (%o20). I did not have the idea to use trigrat, because
the expression resulting from your (%i3) does not have any trigonometric functions left, only square roots.



But your result is still far away from the simple expression c. I assume Maxima does not have any guideline regarding to
which is the simplest version of this expression of nested square roots. And in order to verify identity of your (%o4)
with my c, I would have to do it manually. Maxima does not simplfy, if I build the difference of the two, and I don't
see any way how to simplify this difference to zero. But the floats indicate clearly that the terms should be identical.



Roland







From: Barton Willis [mailto:***@unk.edu]
Sent: Tuesday, July 18, 2017 3:05 PM
To: Roland Salz; maxima-***@lists.sourceforge.net
Subject: Re: [Maxima-discuss] Simplification of a trigonometric or exponentialized term




Maybe something like:

(%i2) load(ntrig)$
(%i3) a:(-1-cos(4*%pi/5)+%i*sin(4*%pi/5))/(1-cos(4*%pi/5)+%i*sin(4*%pi/5))$

(%i4) trigrat(a);
(%o4) (sqrt(sqrt(5)+5)*(3*sqrt(2)*sqrt(5)-5*sqrt(2))*%i)/20



--Barton
Raymond Toy
2017-07-18 19:20:58 UTC
Permalink
Raw Message
Roland> Thanks, Barton. That’s little better than what I had
Roland> achieved in (%o20). I did not have the idea to use
Roland> trigrat, because the expression resulting from your (%i3)
Roland> does not have any trigonometric functions left, only
Roland> square roots.

Roland>  

Roland> But your result is still far away from the simple
Roland> expression c. I assume Maxima does not have any guideline
Roland> regarding to which is the simplest version of this
Roland> expression of nested square roots. And in order to verify
Roland> identity of your (%o4) with my c, I would have to do it
Roland> manually. Maxima does not simplfy, if I build the
Roland> difference of the two, and I don’t see any way how to
Roland> simplify this difference to zero. But the floats indicate
Roland> clearly that the terms should be identical.

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.

--
Ray
Roland Salz
2017-07-18 19:55:09 UTC
Permalink
Raw Message
-----Original Message-----
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
Richard Fateman
2017-07-18 20:52:25 UTC
Permalink
Raw Message
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
Post by Roland Salz
-----Original Message-----
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
https://lists.sourceforge.net/lists/listinfo/maxima-discuss
Stavros Macrakis (Σταῦρος Μακράκης)
2017-07-18 23:17:52 UTC
Permalink
Raw Message
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
Post by Richard Fateman
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
-----Original Message-----
Post by Raymond Toy
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
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
https://lists.sourceforge.net/lists/listinfo/maxima-discuss
Roland Salz
2017-07-19 22:10:55 UTC
Permalink
Raw Message
-----Original Message-----
Sent: Tuesday, July 18, 2017 9:21 PM
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.
True. Unfortunately, my problem consists of 4 such expressions, and two of them are negative imaginary numbers. Take for example the expression -c. The sign is lost. Is there another hack to simplify the general case? Or would I have to write my own routine that memorizes the sign and adjusts it at the end accordingly?

PS: Stavros' general algorithm I did not dare to ask about this new situation yet ...

Best regards,
Roland

Loading...