Ask Your Question

Simplification of atan

asked 2014-08-20 20:13:28 -0500

Rafael gravatar image

updated 2014-08-21 12:35:26 -0500

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:



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 flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2014-08-21 06:37:20 -0500

tmonteil gravatar image

updated 2014-08-21 06:44:11 -0500

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)
sage: f(f(x))
sage: f(f(f(x)))

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)
sage: f(0.8)
sage: f(5/4)
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
sage: for i in range(60):
....:     x = f(x)
....:     print(x)
edit flag offensive delete link 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)`.

Rafael gravatar imageRafael ( 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)

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

answered 2014-08-21 01:57:59 -0500

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()

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).

edit flag offensive delete link 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?

kcrisman gravatar imagekcrisman ( 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.

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-08-20 20:13:28 -0500

Seen: 171 times

Last updated: Aug 21 '14