Importing variables non-deterministic?

S

Steven D'Aprano

Op 19-08-13 19:05, Steven D'Aprano schreef:



Why should you expect math.sin and friends be dependant on math.pi?
AfAIR the numerical algorithms for calulating sin and friends don't
depend on (the value of) pi. So there is no reason to suspect that
altering math.pi would have any effect on the results of these
functions.


Of course they depend on pi. Or rather, they depend on the geometric
properties of circles, which are related to pi. If the ratio of the
circumference of a circle to its diameter was exactly 3, instead of
3.1415..., then sine and cosine functions would be periodic with period 6
rather than Ï„ = 2Ï€.

If you consider the implementation of sin and cos functions, they usually
reduce the argument modulo π to something in the first quadrant, and then
use symmetry to adjust the value. So changing the value of pi could, in
principle, change the implementation of sin, cos and tan.
 
W

wxjmfauth

Le mardi 20 août 2013 07:48:37 UTC+2, Steven D'Aprano a écrit :
Of course they depend on pi. Or rather, they depend on the geometric

properties of circles, which are related to pi. If the ratio of the

circumference of a circle to its diameter was exactly 3, instead of

3.1415..., then sine and cosine functions would be periodic with period 6

rather than Ï„ = 2Ï€.



If you consider the implementation of sin and cos functions, they usually

reduce the argument modulo π to something in the first quadrant, andthen

use symmetry to adjust the value. So changing the value of pi could, in

principle, change the implementation of sin, cos and tan.

---------


Never heard about series, Taylor, Maclaurin, ... ?


jmf
 
A

Antoon Pardon

Op 20-08-13 07:48, Steven D'Aprano schreef:
Of course they depend on pi. Or rather, they depend on the geometric
properties of circles, which are related to pi. If the ratio of the
circumference of a circle to its diameter was exactly 3, instead of
3.1415..., then sine and cosine functions would be periodic with period 6
rather than Ï„ = 2Ï€.

Which is beside the point. The fact that nπ are the zeropoints of the
sin function doesn't imply in any way that you somehow need to work with
the value of π in order to calculate any result of the function.

Just as the function x^2 - 2 has -√2 and √2 as zeropoints, yet when
given a numerical value, you dont need (the value of) √2 in order to
get the result. So setting a variable like sqrt2 to whatever value
shouldn't lead us to suspect it would influence the zeropoints of
that function. Likewise with π and the calculation of sin.

If you consider the implementation of sin and cos functions, they usually
reduce the argument modulo π to something in the first quadrant, and then
use symmetry to adjust the value. So changing the value of pi could, in
principle, change the implementation of sin, cos and tan.

Yes there is this aspect, which is a fair point.
 
W

wxjmfauth

Le mardi 20 août 2013 08:55:18 UTC+2, Antoon Pardon a écrit :
Yes there is this aspect, which is a fair point.

-----

Not really, see my previous post. This is only a geometric
interpretation, useless for calculation.

Consequence of an implementation: common trick to use
and/or define pi:
3.141592653589793

jmf
 
A

Antoon Pardon

Op 20-08-13 09:31, (e-mail address removed) schreef:
Le mardi 20 août 2013 08:55:18 UTC+2, Antoon Pardon a écrit :
Yes there is this aspect, which is a fair point.

No it is not. Steven is correct that if for example you
want the value of sin(10), that in a typical implementation
this will be reduced to calculating -sin(10 - 3Ï€).

This for two reasons. It is faster to first reduce the argument
within the first kwadrant, do the series expansion and then
correct for sign than to expand the series with the original
argument and it is more acurate because first reducing asures
that all terms will stay relatively small while using the
original arguments can intrduce some large terms that will
have to cancel each other but that will reduce acuracy.
 
W

wxjmfauth

Le mardi 20 août 2013 09:55:44 UTC+2, Antoon Pardon a écrit :
Op 20-08-13 09:31, (e-mail address removed) schreef:





No it is not. Steven is correct that if for example you

want the value of sin(10), that in a typical implementation

this will be reduced to calculating -sin(10 - 3Ï€).



This for two reasons. It is faster to first reduce the argument

within the first kwadrant, do the series expansion and then

correct for sign than to expand the series with the original

argument and it is more acurate because first reducing asures

that all terms will stay relatively small while using the

original arguments can intrduce some large terms that will

have to cancel each other but that will reduce acuracy.

Ok. Fine. I was aware of the serie expansion, not
about the reduction.

jmf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,218
Latest member
JolieDenha

Latest Threads

Top