Importing variables non-deterministic?

wxjmfauth at gmail.com wxjmfauth at gmail.com
Tue Aug 20 02:40:40 EDT 2013


Le mardi 20 août 2013 07:48:37 UTC+2, Steven D'Aprano a écrit :
> On Mon, 19 Aug 2013 22:34:00 +0200, Antoon Pardon wrote:
> 
> 
> 
> > Op 19-08-13 19:05, Steven D'Aprano schreef:
> 
> > 
> 
> > 
> 
> >> I wish Python had stronger support for enforcing constantness, to whit,
> 
> >> some way to say "you can't rebind or delete this name once it is
> 
> >> bound". You can do it with attributes, by use of property, or in C
> 
> >> extensions, but you cannot do it with top-level name bindings. It makes
> 
> >> me terribly sad that you can do this:
> 
> >>
> 
> >> import math
> 
> >> math.pi = 3.0
> 
> >>
> 
> >>
> 
> >> although I can't decide whether I am less sad or more sad to see that
> 
> >> the behaviour of math.sin and friends doesn't depend on math.pi.
> 
> > 
> 
> > 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.
> 
> 
> 
> 
> 
> -- 
> 
> Steven

---------


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


jmf



More information about the Python-list mailing list