Trigonometric/transcendental function accuracy

General discussion about calculators, SwissMicros or otherwise
Post Reply
BigEd
Posts: 71
Joined: Wed May 03, 2017 9:00 am

Re: Trigonometric/transcendental function accuracy

Post by BigEd »

Excellent - thanks! (I'm OK with some inaccuracy on enormous arguments - it's all a question of how enormous they need to be. But pi itself didn't seem enormous to me!)
sca
Posts: 8
Joined: Mon Mar 30, 2020 9:51 pm

Re: Trigonometric/transcendental function accuracy

Post by sca »

Jaymos wrote:
Wed Jun 07, 2023 6:45 pm
Although Pauli did not mention fixing it in his post above, he undertook to increase the accuracy by increasing the internal digits and of the pi stored value for (1) argument reduction and (2) operations from 51 to 75 digits. The good news is, it is now accurate, do see below. The bad news, it will be slower, do see when we release the next version. Of course it has to, if it has to deal with more digits. And further bad news is that rounding will ALWAYS be there at some point unless you use infinite digits (good luck!). So the same thing will happen next time someone needs to calculate sin(𝝿 * × 10^20); of course you will run out of accuracy with the reduction and when you do, ask yourself: "why?" - at some point you have to say enough is enough.
Perhaps BidEd’s original question arises because this is a case of the code and the documentation disagreeing? From page B-4 of the WP43 Reference Manual, in the discussion of range reduction:
WP43 uses 1065 digits for 2π to warrant 34 digits accuracy of respective function results within ±10^999.
Thank you to all of you that spend so much time on these calculators!

Cheers,

Scott
User avatar
Walter
Posts: 3070
Joined: Tue May 02, 2017 11:13 am
Location: On a mission close to DRS, Germany

Re: Trigonometric/transcendental function accuracy

Post by Walter »

The underlying problem is known as radian. Each and every angular unit can be reduced properly modulo 360° (or equivalent) except those f...g radians. Only for them the 1065 digits of pi are required. AFAICS radians are necessary (?) for Taylor. Hence the attempt on pp. B-3f to get rid of them using multiples of pi for the Taylor series. A nice challenge for a proper mathematician IMO. Any takers?
WP43 SN00000, 34S, and 31S for obvious reasons; HP-35, 45, ..., 35S, 15CE, DM16L S/N# 00093, DM42β SN:00041
User avatar
pauli
Posts: 252
Joined: Tue May 02, 2017 10:11 am
Location: Australia

Re: Trigonometric/transcendental function accuracy

Post by pauli »

It's not the modulo reduction that's the issue here -- that's good out to a thousand digits or so I think. sin(𝝿 * 10²⁰) won't lose accuracy.
It was the subsequent octant reduction to get a small angle to improve accuracy in certain cases and also to speed convergence that was at fault.
User avatar
dm319
Posts: 144
Joined: Thu Aug 03, 2017 12:21 pm
Location: Birmingham, UK

Re: Trigonometric/transcendental function accuracy

Post by dm319 »

This was posted on HackerNews last week, and I found this a similarly fascinating article:

https://austinhenley.com/blog/cosine.html
SN:09075
User avatar
Steve Simpkin
Posts: 66
Joined: Thu May 25, 2023 1:35 am
Location: Los Angeles, California
Contact:

Re: Trigonometric/transcendental function accuracy

Post by Steve Simpkin »

dm319 wrote:
Fri Jun 09, 2023 1:28 pm
This was posted on HackerNews last week, and I found this a similarly fascinating article:

https://austinhenley.com/blog/cosine.html
That is a cool article. It reminds me of the BASIC subroutines shown in the Level 1 BASIC User's Manual for the TRS-80 computer in 1977. The Level 1 BASIC in this computer was missing a lot of math functions and these subroutines were provided in the manual for calculating functions such the square root, log and transcendental functions. Here is the routine for calculating the SINE function.
TRS80 BASIC Lvl1 Sine subroutine.jpg
TRS80 BASIC Lvl1 Sine subroutine.jpg (170.48 KiB) Viewed 2502 times
Helix
Posts: 31
Joined: Sat Jun 24, 2017 12:59 am
Location: France

Re: Trigonometric/transcendental function accuracy

Post by Helix »

dm319 wrote:
Fri Jun 09, 2023 1:28 pm
This was posted on HackerNews last week, and I found this a similarly fascinating article:

https://austinhenley.com/blog/cosine.html
Taylor series are inefficient to approximate functions over an interval. The best method is to use a minimax approximation.
Here is a simple introduction:
https://www.youtube.com/watch?v=j29rVHCpRUY
One can also combine a lookup table, and a minimax approximation (instead of interpolation) over the subintervals.

An excellent book on these subjects is "Elementary Functions - Algorithms and Implementation" from Jean-Michel Muller.
Try Google with this title. ;)
User avatar
pauli
Posts: 252
Joined: Tue May 02, 2017 10:11 am
Location: Australia

Re: Trigonometric/transcendental function accuracy

Post by pauli »

Rational approximations seem to be commoner in my experience than polynomial ones.
User avatar
Walter
Posts: 3070
Joined: Tue May 02, 2017 11:13 am
Location: On a mission close to DRS, Germany

Re: Trigonometric/transcendental function accuracy

Post by Walter »

I won't object to rational approximations avoiding radians a suitable way.
WP43 SN00000, 34S, and 31S for obvious reasons; HP-35, 45, ..., 35S, 15CE, DM16L S/N# 00093, DM42β SN:00041
User avatar
pauli
Posts: 252
Joined: Tue May 02, 2017 10:11 am
Location: Australia

Re: Trigonometric/transcendental function accuracy

Post by pauli »

Radians are the natural unit of angle. Your dislike for them is completely irrelevant.
Post Reply