Cube root [HP-35]
|
03-06-2020, 01:53 AM
(This post was last modified: 03-06-2020 02:01 AM by Gerson W. Barbosa.)
Post: #1
|
|||
|
|||
Cube root [HP-35]
27
√ √ ENTER √ √ √ √ × ENTER √ √ √ √ √ √ √ √ × ENTER √ √ × -> 2.999949713 https://youtu.be/gU_gty53GfU PS: On the 35 we can use logs, but we can still use the algorithm on the HP-16C, which lacks them. |
|||
03-06-2020, 09:50 AM
Post: #2
|
|||
|
|||
RE: Cube root [HP-35]
I've a feeling we're using a truncated binary approximation to a third. Clever!
|
|||
03-06-2020, 10:23 AM
(This post was last modified: 03-06-2020 10:24 AM by Gerson W. Barbosa.)
Post: #3
|
|||
|
|||
RE: Cube root [HP-35]
(03-06-2020 09:50 AM)EdS2 Wrote: I've a feeling we're using a truncated binary approximation to a third. Clever! I only converted the method in the YouTube video to RPN. It took me a while to figure out what he meant by "ten cross", though :-) Algorithms using square roots to approximate non-available functions might have been interesting when scientific calculators were not affordable. There was one for ln(x) which I managed to improve a bit. See here. |
|||
03-06-2020, 11:57 AM
Post: #4
|
|||
|
|||
RE: Cube root [HP-35]
Clever yes.
Is there a need to use it however? :-) 3 1/x 27 X^y ? |
|||
03-06-2020, 01:41 PM
Post: #5
|
|||
|
|||
RE: Cube root [HP-35]
This is a rare case which CHAIN take less keystrokes than RPN
I would swap the order of the keys though, so successive iterations improve the cube root Code: ; CHAIN calculator, N^(1/3) = N^(5/15) |
|||
03-06-2020, 04:12 PM
Post: #6
|
|||
|
|||
RE: Cube root [HP-35]
(03-06-2020 11:57 AM)Gene Wrote: Is there a need to use it however? :-) No, there is not, hence the PS in post #1. I chose the HP-35 because it’s my oldest RPN calculator with square root as a primary function key. Is there an HP calculator other than the HP-16C this might be useful to? |
|||
03-06-2020, 09:57 PM
Post: #7
|
|||
|
|||
RE: Cube root [HP-35]
ah, I saw that but it didn't hit me early this morning about the implementation of X^y. :-)
|
|||
03-06-2020, 11:35 PM
(This post was last modified: 03-06-2020 11:50 PM by Gerson W. Barbosa.)
Post: #8
|
|||
|
|||
RE: Cube root [HP-35]
(03-06-2020 01:41 PM)Albert Chan Wrote: I would swap the order of the keys though, so successive iterations improve the cube root Nice change! Another method, but more keystrokes, at least on the 8-digit Canon LC-37: 27 √ √ √ √ √ √ √ √ √ √ √ - 1 / 3 + 1 = × = × = × = × = × = × = × = × = × = × = × = -> 3.000989 Replace 3 with 5 and you’ll get the 5th root: 1.9338459 From https://www.quora.com/Using-a-simple-cal...root-n-odd PS: Again, it looks like they have trouble with /th/ – “...den press √ (12 times)” :-) |
|||
03-08-2020, 03:23 PM
Post: #9
|
|||
|
|||
RE: Cube root [HP-35]
Fixed point iteration:
From x^3 – A = 0 we have: x^2 = A/x and x = √(A/x), we can use the last equation for the fixed point iteration method. For example for A=27 and (with x0 = 27) we load the stack with 27. 27 ENTER ENTER ENTER for the first steep we press √ √ then for each iteration we press / √ after 10 iterations we have: x = 2.99919546023 |
|||
03-08-2020, 04:05 PM
Post: #10
|
|||
|
|||
RE: Cube root [HP-35]
(03-08-2020 03:23 PM)Juan14 Wrote: 27 ENTER ENTER ENTER Slight improvement to above cube roots fixed point iteration, by replacing "/ √" as "× √ √" This cut down iteration counts in half. |
|||
03-08-2020, 05:31 PM
(This post was last modified: 03-08-2020 05:35 PM by Gerson W. Barbosa.)
Post: #11
|
|||
|
|||
RE: Cube root [HP-35]
(03-08-2020 03:23 PM)Juan14 Wrote: 27 ENTER ENTER ENTER Great! After 9 iterations we have 3.001609727 Now we store that result and do a final iteration STO / √ then ENTER + RCL + 3 / and we get 3.000000216 (on the HP-35) |
|||
03-11-2020, 03:05 AM
(This post was last modified: 03-11-2020 03:07 AM by Gerson W. Barbosa.)
Post: #12
|
|||
|
|||
RE: Cube root [HP-35]
just a proof of concept on the hp 33s to reduce the number of iterations in this variation of Juan’s algorithm. Line D0013 should be replaced by a short routine to compute ln(x) on the HP-16C, where this might make some sense.
Code:
27 XEQ C -> 3 1E50 XEQ C -> 4.64158883316E16 1E50 ³√x -> 4.64158883316E16 Algorithm: r₀ = √x r₁ = √(x/r₀) r₂ = √(x/r₁) ... rn = √(x/rn-1) a = rn b = rn-1 ³√x ~ {a[2 - 1/(2ⁿ⁺¹/lnx + 5/18)] + b}/[3 - 1/(2ⁿ⁺¹/lnx + 5/18)] |
|||
03-16-2020, 02:42 PM
(This post was last modified: 03-16-2020 03:43 PM by Albert Chan.)
Post: #13
|
|||
|
|||
RE: Cube root [HP-35]
We can use Pade approximation to speedup convergence.
Example, simple Pade[1,1] gives cubic convergence. Pade[(1+z)^(1/n), {z,0,1,1}] = \(\large{2n + (n+1)z \over 2n + (n-1)z}\) \(\large\sqrt[n]k = x \left(\sqrt[n] {1 + ({k \over x^n} - 1)}\right) ≈ x \left({k(n+1)\;+\; (n-1)x^n \over k(n-1)\;+\;(n+1)x^n } \right) \) For cube roots, we have: \(\large\sqrt[3]k ≈ x \left({2k\;+\; x^3 \over k\;+\;2x^3 } \right) \) Example, cube root of 0.1 (guess x=0.5): 0.5 0.46428 57142 85714 28571 0.46415 88833 67588 52147 0.46415 88833 61277 88924 10076 35091 94543 0.46415 88833 61277 88924 10076 35091 94465 76551 34912 50112 ... (98 correct digits) Above formula is *exactly* the same as Halley's method, Hf(x), with f(x) = x^n - k see Method of obtaining Third Order Iterative Formulas |
|||
03-16-2020, 07:49 PM
Post: #14
|
|||
|
|||
RE: Cube root [HP-35] | |||
03-16-2020, 10:54 PM
(This post was last modified: 03-17-2020 02:06 AM by Albert Chan.)
Post: #15
|
|||
|
|||
RE: Cube root [HP-35]
(03-16-2020 07:49 PM)Gerson W. Barbosa Wrote:(03-16-2020 02:42 PM)Albert Chan Wrote: We can use Pade approximation to speedup convergence. One issue is optimal range of k, to maximize convergence rate. In other words, with guess = k^y, y≠1/3, should we convert \(\sqrt[3]{27} = 10 \sqrt[3]{0.027}\) ? At the break-even point, errors should match, but with opposite sign: \(\sqrt[3]k - k^y = 10(k/1000)^y - \sqrt[3]k\) \(2 \sqrt[3]k = (1 + 10/1000^y) k^y \) At break-even, \(\large k = (1/2 + 5/1000^y)^{1 \over 1/3\;-\;y}\) With guess, x₀ = √√k = k^(1/4), break-even k ≈ 51.636 → optimal k in range [0.051636, 51.636) Example, try \(\;\sqrt[3]{100}\) = 4.64158 88336 12728 89241 00763 ... x₀ = √√(100) → x3 = 4.64158 88336 12724 68166 58655 x₀ = 10√√0.1 → x3 = 4.64158 88336 12728 89241 08943 Keeping k inside optimal range, \(\sqrt[3]{100} = 10\;\sqrt[3]{0.1}\), x3 gained 7 digits accuracy. --- OP, we estimate k^(1/3) as k^0x0.5555, break-even k ≈ 31.624 → optimal k in range [0.031624, 31.624) 100^0x0.5555 = 4.641480114, error ≈ +0.000109 10 * 0.1^0x0.5555 = 4.641643194, error ≈ −0.000054, better, as expected |
|||
03-17-2020, 04:17 PM
(This post was last modified: 03-18-2020 01:59 AM by Albert Chan.)
Post: #16
|
|||
|
|||
RE: Cube root [HP-35]
(03-16-2020 10:54 PM)Albert Chan Wrote: One issue is optimal range of k, to maximize convergence rate. I made an error assuming better guess speedup Pade convergence. Plotting the errors suggest my pade setup prefer over-estimated guess. For guess x₀ = √√k = k^(1/4), optimal k is before break-even point, at k ≈ √1000 Thus, optimal k should be in range [0.031623, 31.623) \(\large\sqrt[3]k ≈ x \left({2k\;+\; x^3 \over k\;+\;2x^3 } \right) \) Example, try \(\quad\sqrt[3]{27} =\; 3\) x₀ = √√(27) → x3 = 2.9999 99999 99999 99934 // error = +66 ULP x₀ = 10√√.027 → x3 = 3.0000 00000 00000 00709 // error = -709 ULP Example, try \(\quad\sqrt[3]{32}\) = 3.1748 02103 93639 89495 ... x₀ = √√(32) → x3 = 3.1748 02103 93639 89237 // error = +258 ULP x₀ = 10√√.032 → x3 = 3.1748 02103 93639 89710 // error = -215 ULP Edit: rough estimate, with k in range [0.031623, 31.623), x₀ = √√k : \(\large\sqrt[3]k ≈ x_1 = {½\;+\; x_0 \over ½\;+\; 1/x_0}\) // relative error < 1.5% |
|||
03-20-2020, 02:10 PM
Post: #17
|
|||
|
|||
RE: Cube root [HP-35]
(03-17-2020 04:17 PM)Albert Chan Wrote: Edit: rough estimate, with k in range [0.031623, 31.623), x₀ = √√k : My particular HP-16C application requires the evaluation of cubic roots in a very narrow range around 17/4, so I use \(1+\sqrt{\frac{{x}-2}{6}}\), exact at k = 8 (Taken from http://ajmonline.org/2008/5.pdf) Code:
4.1 GSB 3 -> 1.600520664 |
|||
03-20-2020, 05:36 PM
Post: #18
|
|||
|
|||
RE: Cube root [HP-35]
(03-20-2020 02:10 PM)Gerson W. Barbosa Wrote: (Taken from http://ajmonline.org/2008/5.pdf) Thanks for the link. Setup as interation formula, this also have cubic convergence, slightly better than Pade[1,1] \(\large \sqrt[3]k ≈\left(x + \sqrt{4k\;-\; x^3 \over 3x}\right) ÷ 2\) Note: guess x can be at most 4^(1/3)-1 ≈ 58% above true value of \(\sqrt[3]k\) Code: STO 0 ; HP-12C code for cube root 4.1 Enter 2 R/S → 1.591607979 R/S → 1.600520756 R/S → 1.600520664 100 Enter 5 R/S → 4.640872096 R/S → 4.641588834 |
|||
03-20-2020, 10:47 PM
(This post was last modified: 03-21-2020 09:31 PM by Gerson W. Barbosa.)
Post: #19
|
|||
|
|||
RE: Cube root [HP-35]
(03-20-2020 05:36 PM)Albert Chan Wrote: Setup as interation formula, this also have cubic convergence, slightly better than Pade[1,1] It’s just perfect for my purpose. Thanks! Now I can get logs to 7 places on the 16C, like I used to do on my old logarithm tables book :-) 2 GSB A -> 0.6931471(360) GSB B -> 2.0000(13165) 12345 GSB A -> 9.421006(848) GSB B -> 12345.0(1957) 6.789 EEX 79 GSB A -> 183.8195(343) GSB B -> 6.(686887E79) 0.12345 GSB A -> -2.091919(104) GSB B -> 0.123450(119) 230 GSB B -> 7.496895E99 GSB A -> 229.97041(15) 1 GSB A -> 0.000000000 GSB B -> 1.000000000 GSB B -> 2.7182(92170) GSB B -> 15.1544(4181) GSB A -> 2.71829(4016) GSB A -> 1.000004(736) GSB A -> 0.000004736 0.693147181 CHS GSB B -> 0.500000(16) 10 GSB A -> 2.302585(344) STO 2 2 GSB A RCL 2 / -> 0.3010299(435) 0 GSB A -> Error 0 2 CHS GSB A -> Error 0 Code:
Edited to fix errors in line 019 and 045 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 3 Guest(s)