# Simplification of atan

I'm teaching a course on dynamical systems based on the book by Devaney. Today I tried to show the map $f(\theta)=2\theta$ on the circle using Sage, where $\theta$ is given in radians. I could not find functions already defined to perform addition in $\mathbb{R}$ modulo $2\pi$, so I tried to devise my own. I stumbled upon this problem:

atan(sin(1/5*pi)/cos(1/5*pi))


produces

arctan(4*sin(1/5*pi)/(sqrt(5) + 1)).


Is there a way to obtain 1/5*pi?

(By the way, _.simplify() does nothing in this case.)

edit retag close merge delete

Sort by » oldest newest most voted

The unit circle is better handled as a set of complex numbers (and doubling the angle is equivalent to squaring), so you can try to play with:

sage: x = exp(I*pi/5)
sage: f = lambda x : x^2
sage: f(x)
e^(2/5*I*pi)
sage: f(f(x))
e^(4/5*I*pi)
sage: f(f(f(x)))
e^(8/5*I*pi)


You can also stay on the real line by working modulo $1$ (not $2\pi$, this rescaling does not change the nature of the dynamical system), and use the fractional part:

sage: f = lambda x : (2*x) - int(2*x)
sage: f(0.2)
0.400000000000000
sage: f(0.8)
0.600000000000000
sage: f(5/4)
1/2
sage: f(pi)
2*pi - 6


You will enjoy a nice phenomenon : the orbit of every numerical number goes very fast to zero, because of the nature of floating-point numbers, which is also a nice way to explain why we should be very careful about numerical simulations in dynamical systems (note that standard floating points numbers have 53 bits of precision):

sage: x = RDF.random_element() ; x
0.963562235713
sage: for i in range(60):
....:     x = f(x)
....:     print(x)

more

Thanks. Trying to follow your first suggestion, do you know a way to simplify further iterations? Since f(f(f(f(x))) results in e^(16/5*I*pi) and not, say, e^(6/5*I*pi).

( 2014-08-21 12:39:11 -0500 )edit

You can do f(f(f(f(x)))).simplify() which will result in e^(-4/5*I*pi)

( 2014-08-21 13:09:42 -0500 )edit

If you do much symbolic manipulation you should read about Sage's subsystem Maxima. There is however a catch with your case.

sage: ex=atan(sin(1/5*pi)/cos(1/5*pi, hold=True))
sage: m=ex.maxima_methods()
sage: m.trigreduce()
1/5*pi


The problem is that cos(pi/5) gets immediately simplified to (sqrt(5)+1)/4 in Sage before Maxima can be called. This can be prevented by saying cos(pi/5,hold=True).

more

Nice! I suggest adding this to the documentation somewhere. Very interesting, I am surprised Sage/Ginac does that reduction - why not for pi/8?

( 2014-08-21 08:57:15 -0500 )edit

Thanks. Unfortunately, it seems that the solution is not general enough. For example. arctan(sin(2,hold=True)/cos(2,hold=True)).trigreduce() gives an error AttributeError: 'sage.symbolic.expression.Expression' object has no attribute 'trigreduce' instead of returning 2.

( 2014-08-21 12:45:25 -0500 )edit