Ask Your Question
0

Simplification of atan

asked 2014-08-21 03:13:28 +0100

Rafael gravatar image

updated 2014-08-21 19:35:26 +0100

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

2 Answers

Sort by ยป oldest newest most voted
2

answered 2014-08-21 13:37:20 +0100

tmonteil gravatar image

updated 2014-08-21 13:44:11 +0100

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

Comments

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 19:39:11 +0100 )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 20:09:42 +0100 )edit
1

answered 2014-08-21 08:57:59 +0100

rws gravatar image

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

edit flag offensive delete link more

Comments

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 15:57:15 +0100 )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 19:45:25 +0100 )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

Stats

Asked: 2014-08-21 03:13:28 +0100

Seen: 539 times

Last updated: Aug 21 '14