Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-23 Thread Chris Barker - NOAA Federal via Python-ideas
>> However -- if this is really such a good idea -- wouldn't someone have make >> a C lib that does it? Or has someone? Anyone looked? > > No, there's nothing magical about C. You can do it in pure Python. Sure, but there are a number of FP subtleties around the edge cases. So wrapping (or

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-19 Thread Steven D'Aprano
On Mon, Jun 18, 2018 at 07:23:50PM -0700, Chris Barker wrote: > Though if someone really wants to implement trig in native degrees -- more > power to 'em. > > However -- if this is really such a good idea -- wouldn't someone have make > a C lib that does it? Or has someone? Anyone looked? No,

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-19 Thread Robert Kern
On 6/18/18 19:23, Chris Barker via Python-ideas wrote: On Sat, Jun 16, 2018 at 10:57 PM, Tim Peters > wrote: Ya, decimal fp doesn't really solve anything except the shallow surprise that decimal fractions generally aren't exactly representable as binary

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-18 Thread Matt Arcidy
On Mon, Jun 18, 2018, 19:25 Chris Barker via Python-ideas < python-ideas@python.org> wrote: > On Sat, Jun 16, 2018 at 10:57 PM, Tim Peters wrote: > > Ya, decimal fp doesn't really solve anything except the shallow surprise >> that decimal fractions generally aren't exactly representable as

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-18 Thread Chris Barker via Python-ideas
On Sat, Jun 16, 2018 at 10:57 PM, Tim Peters wrote: Ya, decimal fp doesn't really solve anything except the shallow surprise > that decimal fractions generally aren't exactly representable as binary > fractions. Which is worth a whole lot for casual users, but doesn't > address any of the deep

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-16 Thread Tim Peters
[Steven D'Aprano ] > Thanks Tim! > You're welcome ;-) > Reading your digressions on the minutia of floating point maths is > certainly an education. It makes algebra and real-valued mathematics > seem easy in comparison. > Hard to say, really. The problem with floating point is that it's so

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-16 Thread Steven D'Aprano
On Thu, Jun 14, 2018 at 01:44:34PM -0500, Tim Peters wrote: > I should note that numeric code "that works" is often much subtler than it > appears at first glance. So, for educational purposes, I'll point out some > of what _wasn't_ said about this crucial function: [...] Thanks Tim! Reading

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-15 Thread Richard Damon
On 6/13/18 7:21 AM, Stephan Houben wrote: > > > Op wo 13 jun. 2018 13:12 schreef Richard Damon > mailto:rich...@damon-family.org>>: > > My first comment is that special casing values like this can lead to > some very undesirable properties when you use the function for > numerical >

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-14 Thread Tim Peters
I should note that numeric code "that works" is often much subtler than it appears at first glance. So, for educational purposes, I'll point out some of what _wasn't_ said about this crucial function: [Tim] > import mpmath > from math import fmod > # Return (n, x) such that: > #

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-13 Thread Greg Ewing
Stephan Houben wrote: Yes that is what my code does. It reduces degrees to [0,90]. Only for the special angles, though. Richard's point is that you need to do tha for *all* angles to avoid discontinuities with large angles. This is not how sine functions are calculated. They are calculated

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-13 Thread Tim Peters
[Richard Damon] > My first comment is that special casing values like this can lead to > some very undesirable properties when you use the function for numerical > analysis. Suddenly your sind is no longer continuous (sind(x) is no > longer the limit of sind(x+d) as d goes to 0). > > As I stated

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-13 Thread Stephan Houben
Op wo 13 jun. 2018 13:12 schreef Richard Damon : > My first comment is that special casing values like this can lead to > some very undesirable properties when you use the function for numerical > analysis. Suddenly your sind is no longer continuous (sind(x) is no > longer the limit of sind(x+d)

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-13 Thread Richard Damon
My first comment is that special casing values like this can lead to some very undesirable properties when you use the function for numerical analysis. Suddenly your sind is no longer continuous (sind(x) is no longer the limit of sind(x+d) as d goes to 0). As I stated in my initial comment on

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-13 Thread Stephan Houben
2018-06-13 12:08 GMT+02:00 Robert Vanden Eynde : > Then of you also want 45, you could do % 15 ? :D > Sure, but how the lookup is done in the Python reference code is ultimately not so important, since it will need to be rewritten in C if it is to be included in the math package (math is

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-13 Thread Robert Vanden Eynde
Then of you also want 45, you could do % 15 ? :D Le mer. 13 juin 2018 à 12:07, Stephan Houben a écrit : > 2018-06-13 12:00 GMT+02:00 Robert Vanden Eynde : > >> What was wrong with my initial implementation with a lookup table ? :D >> >> def sind(x): >> if x % 90 == 0: >> return (0,

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-13 Thread Stephan Houben
2018-06-13 12:00 GMT+02:00 Robert Vanden Eynde : > What was wrong with my initial implementation with a lookup table ? :D > > def sind(x): > if x % 90 == 0: > return (0, 1, 0, -1)[int(x // 90) % 4] > else: > return sin(radians(x)) > I kinda missed it, but now you ask: 1.

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-13 Thread Robert Vanden Eynde
What was wrong with my initial implementation with a lookup table ? :D def sind(x): if x % 90 == 0: return (0, 1, 0, -1)[int(x // 90) % 4] else: return sin(radians(x)) If you want to support multiples of 30, you can do % 30 and // 30. Le mer. 13 juin 2018 à 09:51,

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-13 Thread Stephan Houben
Op di 12 jun. 2018 12:41 schreef Nathaniel Smith : > On Tue, Jun 12, 2018, 00:03 Stephan Houben wrote: > >> Hi all, >> >> I wrote a possible implementation of sindg: >> >> https://gist.github.com/stephanh42/336d54a53b31104b97e46156c7deacdd >> >> This code first reduces the angle to the [0,90]

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-12 Thread Robert Vanden Eynde
As mentioned, with complex numbers the radians make more sense and of course cmath.sind(x) + 1j * cmath.sind(x) != cmath.exp(1j * x). However, adding degrees version for cmath (import cmath) is still useful, cmath.rectd, cmath.phased, cmath.polard etc. 2018-06-11 19:24 GMT+02:00 Michael Selik

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-12 Thread Tim Peters
> > > [Tim] >> 1. Python's float "%" is unsuitable for argument reduction; e.g., > >> > >> >>> -1e-14 % 360.0 > >> 360.0 > >> > >> `math.fmod` is suitable, because it's exact: > >> > >> >>> math.fmod(-1e-14, 360.0) > >> -1e-14 > > [Greg Ewing] > So why doesn't float % use math.fmod? >

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-12 Thread Nathaniel Smith
On Tue, Jun 12, 2018, 00:03 Stephan Houben wrote: > Hi all, > > I wrote a possible implementation of sindg: > > https://gist.github.com/stephanh42/336d54a53b31104b97e46156c7deacdd > > This code first reduces the angle to the [0,90] interval. > After doing so, it can be observed that the simple

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-12 Thread Stephan Houben
Hi all, I wrote a possible implementation of sindg: https://gist.github.com/stephanh42/336d54a53b31104b97e46156c7deacdd This code first reduces the angle to the [0,90] interval. After doing so, it can be observed that the simple implementation math.sin(math.radians(angle)) produces exact

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-12 Thread Chris Angelico
On Tue, Jun 12, 2018 at 4:40 PM, Greg Ewing wrote: > Tim Peters wrote: > >> 1. Python's float "%" is unsuitable for argument reduction; e.g., >> >> >>> -1e-14 % 360.0 >> 360.0 >> >> `math.fmod` is suitable, because it's exact: >> >> >>> math.fmod(-1e-14, 360.0) >> -1e-14 > > > So why doesn't

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-12 Thread Matt Arcidy
Sorry for top posting, but these aren't really opinions for the debate, just information. I haven't seen them mentioned, and none grouped nicely under someone's reply. Number representation:: IEEE-754 doubles cannot represent pi correctly at any bit-depth (i mean, obviously, but more seriously).

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-12 Thread Greg Ewing
Tim Peters wrote: 1. Python's float "%" is unsuitable for argument reduction; e.g., >>> -1e-14 % 360.0 360.0 `math.fmod` is suitable, because it's exact: >>> math.fmod(-1e-14, 360.0) -1e-14 So why doesn't float % use math.fmod? -- Greg ___

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-11 Thread Tim Peters
[Steven D'Aprano] > ... The initial proposal is fine: a separate set of trig functions that take > their arguments in degrees would have no unexpected surprises (only the > expected ones). With a decent implementation i.e. not this one: > > # don't do this > def sind(angle): >

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-11 Thread Steven D'Aprano
On Mon, Jun 11, 2018 at 02:12:06PM -0700, Chris Barker wrote: > no, but you can say "y is as close to zero as I care about" Of course you can. But we (the std lib) should not make that decision for everybody. For some people 0.001 is "close enough to zero". For others, 1e-16 is not. We're not

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-11 Thread Steven D'Aprano
On Mon, Jun 11, 2018 at 01:18:10PM -0700, Chris Barker via Python-ideas wrote: > On Mon, Jun 11, 2018 at 10:24 AM, Michael Selik wrote: > > > Would sind and cosd make Euler's formula work correctly? > > > Not trying to pick on you, but this question shows a key misunderstanding: > > There is

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-11 Thread Steven D'Aprano
On Tue, Jun 12, 2018 at 10:57:18AM +1200, Greg Ewing wrote: > Steven D'Aprano wrote: > >sin(3°) is: > > > >-1/2 (-1)^(29/60) ((-1)^(1/60) - 1) (1 + (-1)^(1/60)) > > > >This proposal was supposed to *simplify* the trig functions for > >non-mathematicians, not make them mind-bogglingly complicated.

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-11 Thread Greg Ewing
Steven D'Aprano wrote: sin(3°) is: -1/2 (-1)^(29/60) ((-1)^(1/60) - 1) (1 + (-1)^(1/60)) This proposal was supposed to *simplify* the trig functions for non-mathematicians, not make them mind-bogglingly complicated. I don't think anyone is going to complain about sin(3°) not being exact,

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-11 Thread Greg Ewing
Michael Selik wrote: Whoops, it turns out Euler's formula does work! I expected imprecision, but at least one test matched. That might be because the implememtation of e ** x where x is complex is using Euler's formula... -- Greg ___ Python-ideas

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-11 Thread Chris Barker via Python-ideas
On Sun, Jun 10, 2018 at 10:48 PM, Steven D'Aprano wrote: > > > In regard to the "special values", and exact results -- a good math lib > > should return results that are "exact" in all but maybe the last digit > > stored. So you could check inputs and outputs with, e.g. math.isclose() > to > >

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-11 Thread Michael Selik
On Mon, Jun 11, 2018, 1:18 PM Chris Barker wrote: > On Mon, Jun 11, 2018 at 10:24 AM, Michael Selik wrote: > >> Would sind and cosd make Euler's formula work correctly? > > > There is nothing inherently more accurate in using degrees rather than > radians for trigonometry. > That's actually

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-11 Thread Chris Barker via Python-ideas
On Mon, Jun 11, 2018 at 10:24 AM, Michael Selik wrote: > Would sind and cosd make Euler's formula work correctly? Not trying to pick on you, but this question shows a key misunderstanding: There is nothing inherently more accurate in using degrees rather than radians for trigonometry. IT's

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-11 Thread Clément Pit-Claudel
On 2018-06-11 14:04, Stephan Houben wrote: > 2018-06-11 19:33 GMT+02:00 Michael Selik >: > > Whoops, it turns out Euler's formula does work! I expected imprecision, > but at least one test matched. > > x = 42 > cos(x) + 1j * sin(x) == e ** (1j * x) > > > I

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-11 Thread Steven D'Aprano
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:

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-11 Thread Stephan Houben
2018-06-11 19:33 GMT+02:00 Michael Selik : > Whoops, it turns out Euler's formula does work! I expected imprecision, > but at least one test matched. > > x = 42 > cos(x) + 1j * sin(x) == e ** (1j * x) > I think you will find it holds for any x (except inf, -inf and nan). The boat is less leaky

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-11 Thread Michael Selik
Whoops, it turns out Euler's formula does work! I expected imprecision, but at least one test matched. x = 42 cos(x) + 1j * sin(x) == e ** (1j * x) I suppose that's because it's radians. On Mon, Jun 11, 2018, 10:24 AM Michael Selik wrote: > Would sind and cosd make Euler's formula work

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-11 Thread Michael Selik
Would sind and cosd make Euler's formula work correctly? sind(x) + i * sind(x) == math.e ** (i * x) I suspect that adding these functions is kind of like those cartoons where the boat is springing leaks and the character tried to plug them with their fingers. Floating point is a leaky

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-11 Thread Chris Barker via Python-ideas
On Mon, Jun 11, 2018 at 1:00 AM, Ronald Oussoren wrote: > > What is the real world advantage of such a class? So far I’ve only seen > examples where the current behavior is said to be confusing for students. EXACTLY! In [*49*]: math.sin(math.pi) Out[*49*]: 1.2246467991473532e-16 If the

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-11 Thread Steven D'Aprano
On Mon, Jun 11, 2018 at 12:08:07PM +0200, Jacco van Dorp wrote: > >>> asin(1) > "0.5π" # Currently: 1.5707963267948966 I think that if you expect the stdlib math library to change to symbolic maths for trig functions, you are going to be extremely disappointed. Aside from everything else,

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-11 Thread Steven D'Aprano
On Mon, Jun 11, 2018 at 09:18:22AM +0200, Jacco van Dorp wrote: > > Remember, because π is irrational, we cannot actually call sin or cos on > > any rational multiple of π. We can only operate on multiples of pi, > > which is *close to* but not the same as π. That's why it is okay that > >

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-11 Thread Jacco van Dorp
2018-06-11 10:00 GMT+02:00 Ronald Oussoren : >> [me suggestion PiMultiple class] > > What is the real world advantage of such a class? So far I’ve only seen > examples where the current behavior is said to be confusing for students. In > most cases where I have used math.sin the angle wasn’t a

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-11 Thread Ronald Oussoren
Op 11 jun. 2018 om 09:18 heeft Jacco van Dorp het volgende geschreven: >> Remember, because π is irrational, we cannot actually call sin or cos on >> any rational multiple of π. We can only operate on multiples of pi, >> which is *close to* but not the same as π. That's why it is okay that >>

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-11 Thread Jacco van Dorp
> Remember, because π is irrational, we cannot actually call sin or cos on > any rational multiple of π. We can only operate on multiples of pi, > which is *close to* but not the same as π. That's why it is okay that > tan(pi/2) returns a huge number instead of infinity or NAN. That's > because

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-10 Thread Steven D'Aprano
On Sun, Jun 10, 2018 at 10:01:09PM -0700, Chris Barker via Python-ideas wrote: > In regard to the "special values", and exact results -- a good math lib > should return results that are "exact" in all but maybe the last digit > stored. So you could check inputs and outputs with, e.g.

Re: [Python-ideas] Fwd: Trigonometry in degrees

2018-06-10 Thread Chris Barker via Python-ideas
On Sun, Jun 10, 2018 at 11:26 AM, Robert Vanden Eynde < robertvandeney...@hotmail.com> wrote: > I agree that a big python library is more close to the standard python lib > than matlab. However, helping transition from matlab is a great concern in > the python scientific community, because matlab

[Python-ideas] Fwd: Trigonometry in degrees

2018-06-10 Thread Robert Vanden Eynde
I agree that a big python library is more close to the standard python lib than matlab. However, helping transition from matlab is a great concern in the python scientific community, because matlab is used is a lot of engineering classes at University. That's a tough call hmmm. I'll look at