[Python-ideas] Fwd: Trigonometry in degrees

Steven D'Aprano steve at pearwood.info
Mon Jun 11 14:38:07 EDT 2018


On Mon, Jun 11, 2018 at 10:24:42AM -0700, Michael Selik wrote:
> Would sind and cosd make Euler's formula work correctly?
> 
> sind(x) + i * sind(x) == math.e ** (i * x)

No, using degrees makes Euler's identity *not* work correctly, unless 
you add in a conversion factor from degrees to radians:

https://math.stackexchange.com/questions/1368049/eulers-identity-in-degrees

Euler's Identity works fine in radians:

py> from cmath import exp
py> exp(1j*math.pi)
(-1+1.2246063538223773e-16j)

which is close enough to -1 given the usual rounding issues with floats. 
(Remember, math.pi is not π, but a number close to it. There is no way 
to represent the irrational number π in less than an infinite amount of 
memory without symbolic maths.)


[...]
> Perhaps you'd prefer an enhancement to the fractions module that provides
> real (not float) math?

I should think not. Niven's Theorem tells us that for rational angles 
between 0° and 90° (that is, angles which can be represented as 
fractions), there are only THREE for which sine (and cosine) are 
themselves rational:

https://en.wikipedia.org/wiki/Niven's_theorem

Every value of sin(x) except for those three angles is an irrational 
number, which means they cannot be represented exactly as fractions or 
in a finite number of decimal places.

What that means is that if we tried to implement real (not float) 
trigonometric functions on fractions, we'd need symbolic maths capable 
of returning ever-more complicated expressions involving surds.

For example, the exact value of sin(7/2 °) involves a triple nested 
square root:

1/2 sqrt(2 - sqrt(2 + sqrt(3)))

and that's one of the relatively pretty ones. sin(3°) is:

-1/2 (-1)^(29/60) ((-1)^(1/60) - 1) (1 + (-1)^(1/60))

http://www.wolframalpha.com/input/?i=exact+value+of+sine%2815%2F2+degrees%29
http://www.wolframalpha.com/input/?i=exact+value+of+sine%283+degrees%29

This proposal was supposed to *simplify* the trig functions for 
non-mathematicians, not make them mind-bogglingly complicated.



-- 
Steve


More information about the Python-ideas mailing list