Trig algorithms on HP RPN?
|
11-30-2024, 01:39 PM
Post: #1
|
|||
|
|||
Trig algorithms on HP RPN?
Can someone tell me if the trig algorithms for HP (and other RPN calculators) are all done in radians (behind the scenes). The reason I ask is I've been trying out the Mike Sebastian Forensic test.
It is of course meant to find the underlying chip used, regardless of brand name. But it gives a (very) rough estimation of accuracy, and the results I get using 0.15707 radians are startlingly better than with 9 degrees. HP-25 degrees 9.0040 error 0.05% HP-25 radians 8.9999 error 0.00003% Any Soviet Elektronika programmable RPN (eg B3-34) degrees 9.0881 error 1% Any Soviet Elektronika programmable RPN (eg B3-34) radians 9.0000 error 0.0003% Sinclair Scientific radians 8.9381 error 0.7% (no degree mode) Thanks. |
|||
11-30-2024, 02:09 PM
(This post was last modified: 11-30-2024 02:11 PM by Idnarn.)
Post: #2
|
|||
|
|||
RE: Trig algorithms on HP RPN?
(11-30-2024 01:39 PM)MinkLib Wrote: Can someone tell me if the trig algorithms for HP (and other RPN calculators) are all done in radians (behind the scenes). While the answer cannot be generalized as it may depend on the particular calculator, if you want an example, see the paper "Algorithms and Accuracy in the HP-35" by David S. Cochran (example, here: https://www.keesvandersanden.nl/calculat..._HP-35.pdf) which describes trigonometry function calculation on the HP-35. I read somewhere (was it an interview with William Kahan?) that the HP 15C code derived from it. You can also browse Jacques Laporte's excellent reverse engineering of the HP-35 here: https://archived.hpcalc.org/laporte/index.html https://archived.hpcalc.org/laporte/Trigonometry.htm |
|||
11-30-2024, 03:15 PM
Post: #3
|
|||
|
|||
RE: Trig algorithms on HP RPN?
See this thread where I asked the same seven weeks ago:
https://www.hpmuseum.org/forum/thread-22486.html The best calculator is the one you actually use. |
|||
11-30-2024, 03:49 PM
Post: #4
|
|||
|
|||
RE: Trig algorithms on HP RPN?
(11-30-2024 01:39 PM)MinkLib Wrote: Can someone tell me if the trig algorithms for HP (and other RPN calculators) are all done in radians (behind the scenes). Although the HP-35 only uses degrees for trigonometric functions, it still seems to use the \(\tan^{-1}\) values in radians: Code: 0-0716 0730 load constant 7 reg['C'] = 0x00700000000000 And then a bit later: Code: 0-0617 1030 load constant 8 reg['C'] = 0x00099668666666 This is output from running x11-calc-35 with the -t option: Code: -t, trace Compare this to (using RAD): 1 ATAN 0.78539816340 0.1 ATAN 0.09966865249 From my understanding of CORDIC we might as well use angles in degrees. Honestly, I don't know why that wasn't used instead. |
|||
12-01-2024, 05:17 PM
Post: #5
|
|||
|
|||
RE: Trig algorithms on HP RPN?
(11-30-2024 03:49 PM)Thomas Klemm Wrote: Honestly, I don't know why that wasn't used instead. Probably to take advantage of the fact that arctan(x) ~ ln(1 + x) for small values of x, which allows part of the arctangent table to be used in the computation of the natural logarithm. For example, arctan(0.00001) ~ ln (1.00001). That’s the fifth element in the arctangent table starting at register 1, generated by the HP-15C program B below, when in RAD mode. Program A computes tan(x) using the CORDIC algorithm. Code:
I cannot find a reference to the original TI program this one is based upon. |
|||
12-01-2024, 07:27 PM
(This post was last modified: 12-01-2024 08:46 PM by Albert Chan.)
Post: #6
|
|||
|
|||
RE: Trig algorithms on HP RPN?
(11-30-2024 03:49 PM)Thomas Klemm Wrote: Should last digit for pi/4 a 4? lua> pi/4 0.7853981633974483 (11-30-2024 03:49 PM)Thomas Klemm Wrote: Honestly, I don't know why that wasn't used instead. Just a guess, if angles are in radian, we can just use tan code to get atan tan sum formula: tan(x+y) = (tan(x) + tan(y)) / (1 - tan(x)*tan(y)) Flip for atan: atan(x) = atan( y + (x-y) ) atan(x) = atan(y) + atan(z), where z = (x-y)/(1+x*y) if y = tan(x), (x-y) ≈ x^3/3 --> z shrink fast, cubic convergence! But we can do better! y can be set to anything. As long as y is close to x, z will shrink fast. Below, y = tan(x2 = x/(1+x*x/3)), to get convergence rate of O(x^5) Code: function myatan(x, s) lua> myatan(0.1) 0 + atan( 0.1 ) 0.09966777408637874 + atan( 8.784047832967151e-07 ) 0.09966865249116204 + atan( -1.0587911840670585e-22 ) 0.09966865249116204 lua> myatan(1) 0 + atan( 1 ) 0.75 + atan( 0.03541295579818369 ) 0.7853981584542247 + atan( 4.943223638603625e-09 ) 0.7853981633974483 |
|||
12-01-2024, 07:30 PM
Post: #7
|
|||
|
|||
RE: Trig algorithms on HP RPN?
(12-01-2024 05:17 PM)Gerson W. Barbosa Wrote: For example, arctan(0.00001) ~ ln (1.00001). That’s the fifth element in the arctangent table starting at register 1, generated by the HP-15C program B below, when in RAD mode. Program A computes tan(x) using the CORDIC algorithm. Can you explain in words (better, example) how tan and log1p is used to get atan? |
|||
12-01-2024, 07:47 PM
Post: #8
|
|||
|
|||
RE: Trig algorithms on HP RPN?
Your program illustrates my point very nicely: Run program B in DEG mode to use program A to calculate \(\tan(x)\) in degrees.
But then we end up with constants like these: 45.00000000 5.710593137 0.572938698 0.057295760 0.005729578 0.000572958 … And ROM was a scarce resource. (12-01-2024 05:17 PM)Gerson W. Barbosa Wrote: I cannot find a reference to the original TI program this one is based upon. Initially I considered the HP-15C for this article: Exploring the CORDIC algorithm with the WP-34S But I'm not sure if that would have worked as well because you can't store complex numbers in registers. And the WP-34C provides INC and decimal shift which turned out to be useful. But you can still follow the example on the HP-15C manually: 1 ENTER 0.1 I ENTER ENTER 3 ENTER 4 I 3.000000000 × 2.600000000 × 2.170000000 × 1.714000000 × 1.236300000 × 0.741460000 × 0.234257000 × -0.280360600 |
|||
12-01-2024, 08:13 PM
Post: #9
|
|||
|
|||
RE: Trig algorithms on HP RPN?
(12-01-2024 07:27 PM)Albert Chan Wrote: Just a guess, if angles are in radian, we can just use tan code to get atan. This is already the case. From A Unified Algorithm for Elementary Functions: J. S. WALTHER Wrote:This paper describes a single unified algorithm for the calculation of elementary functions including multiplication, division, sin, cos, tan, arctan, sinh, cosh, tanh, arctanh, ln, exp and square-root. |
|||
Yesterday, 08:59 PM
Post: #10
|
|||
|
|||
RE: Trig algorithms on HP RPN?
(12-01-2024 07:30 PM)Albert Chan Wrote:(12-01-2024 05:17 PM)Gerson W. Barbosa Wrote: For example, arctan(0.00001) ~ ln (1.00001). That’s the fifth element in the arctangent table starting at register 1, generated by the HP-15C program B below, when in RAD mode. Program A computes tan(x) using the CORDIC algorithm. Actually, atan and log1p lookup tables are used to get tan and log (and exp) functions (please see https://archived.hpcalc.org/laporte/TheS...rithms.htm). Sorry if my text was not clear enough. .x arctan(1/10^x) ln(1+1/10^x) 00 0.785398163397 0.693147180560 01 0.099668652491 0.095310179804 02 0.009999666687 0.009950330853 03 0.000999999667 0.000999500333 04 0.000100000000 0.000099995000 05 0.000010000000 0.000009999950 06 0.000001000000 0.000000999999 07 0.000000100000 0.000000100000 08 0.000000010000 0.000000010000 09 0.000000001000 0.000000001000 10 0.000000000100 0.000000000100 11 0.000000000010 0.000000000010 12 0.000000000001 0.000000000001 As Thomas Klemm has correctly pointed out, tan(x) would accept arguments in degrees if the atan table elements were in degrees rather than radians. It appears they chose radians in order do save memory, as thus the second half of the elements would be common to both tables. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: Namir, 7 Guest(s)