Loading [MathJax]/jax/output/HTML-CSS/jax.js

First time here? Check out the FAQ!

Ask Your Question
0

Simplification of atan

asked 10 years ago

Rafael gravatar image

updated 10 years ago

I'm teaching a course on dynamical systems based on the book by Devaney. Today I tried to show the map f(θ)=2θ on the circle using Sage, where θ is given in radians. I could not find functions already defined to perform addition in R modulo 2π, 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.)

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
2

answered 10 years ago

tmonteil gravatar image

updated 10 years ago

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π, 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)
Preview: (hide)
link

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 ( 10 years ago )

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

tmonteil gravatar imagetmonteil ( 10 years ago )
1

answered 10 years ago

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

Preview: (hide)
link

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 ( 10 years ago )

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 ( 10 years ago )

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: 10 years ago

Seen: 567 times

Last updated: Aug 21 '14