Log-Arcsine Algorithm - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: General Forum (/forum-4.html) +--- Thread: Log-Arcsine Algorithm (/thread-19068.html) |
Log-Arcsine Algorithm - Thomas Klemm - 11-02-2022 10:22 PM Recently I stumbled upon the Log-Arcsine Algorithm in Peter Henrici's book: Computational Analysis with the HP-25 Pocket Calculator. (pp. 207) The following recurrence relation is used: \( \begin{align} s_{n+1} = s_n \sqrt{\frac{2 s_n}{s_n + s_{n-1}}} \end{align} \) This little program can be used with most HP calculators: Code: ENTER Example 0 ENTER 1 R/S R/S R/S … 1.41421356237 1.53073372946 1.56072257613 1.56827424527 1.57016557848 1.57063862547 1.57075690057 1.57078647018 1.57079386264 1.57079571076 1.57079617279 1.57079628829 1.57079631717 1.57079632439 1.57079632619 1.57079632664 1.57079632676 1.57079632679 1.57079632679 1.57079632679 … Let's slap a loop around it and we have yet another program for the next \(\pi\)-day: Code: 00 { 26-Byte Prgm } This allows us to calculate both \(\log\) and \(\arcsin\) on an HP-16C: Code: 001 - 43,22, A LBL A Examples 10 GSB A 2.302585094 0.5 GSB B 0.523598775 Here is the same program for the HP-42S: Code: 00 { 56-Byte Prgm } References
RE: Log-Arcsine Algorithm - Nihotte(lma) - 11-03-2022 06:32 PM (11-02-2022 10:22 PM)Thomas Klemm Wrote: Recently I stumbled upon the Log-Arcsine Algorithm in Peter Henrici's book: Computational Analysis with the HP-25 Pocket Calculator. (pp. 207) Thanks Thomas ! That's fine !! Laurent RE: Log-Arcsine Algorithm - Albert Chan - 11-04-2022 03:29 PM (11-02-2022 10:22 PM)Thomas Klemm Wrote: The following recurrence relation is used: Above initial conditions for θ = asin(x): s-1 = x*√(1-x*x) = sin(θ)*cos(θ) = sin(2θ)/2 s0 = x = sin(θ) The program then iterate for s1 = 2*sin(θ/2), s2 = 4*sin(θ/4), ... --> s∞ = θ = asin(x) Sequence is identical to asin(x) half-angle formula. Note: asinq(x) = asin(√x) (03-31-2022 11:07 PM)Albert Chan Wrote: asinq(x) = 2 * asinq(x/2/(1+sqrt(1-x))) >>> x = 1 # iterate for asin(√1) >>> for k in range(1,20): ... x /= 2*(1+sqrt(1-x)) ... print 2**k * sqrt(x) ... 1.41421356237 1.53073372946 1.56072257613 1.56827424527 1.57016557848 1.57063862547 1.57075690057 1.57078647018 1.57079386264 ... RE: Log-Arcsine Algorithm - Albert Chan - 11-04-2022 04:58 PM (11-02-2022 10:22 PM)Thomas Klemm Wrote: The following recurrence relation is used: If we let y = ln(x), and s-1 = (x² - 1/x²)/4 = sinh(2y)/2 s0 = (x - 1/x)/2 = sinh(y) then s1 = 2*sinh(y/2) s2 = 4*sinh(y/4) ... --> s∞ = y = ln(x), sin(θ) = sinh(θ*i)/i, this explained why Log-Arcsine Algorithm have same recurrence relation. RE: Log-Arcsine Algorithm - Thomas Klemm - 11-05-2022 01:27 AM With a minor change we can also calculate the inverse hyperbolic sine function. We just have to start with: \( x \sqrt{1 + x^2} \) and \( x \) Example 2 SQRT 1 XEQ 00 0.88137358702 To find the recurrence relation we can define the following functions with somewhat suggestive names: \( \begin{align} s(z) &= \frac{z - \frac{1}{z}}{2} \\ \\ c(z) &= \frac{z + \frac{1}{z}}{2} \\ \end{align} \) It's easy to show (see below) that: \( \begin{align} 2 s(z) c(z) &= s(z^2) \\ \\ 2 c(z)^2 &= 1 + c(z^2) \\ \end{align} \) From the latter we conclude: \( \begin{align} c(z) = \sqrt{\frac{1 + c(z^2)}{2}} \end{align} \) Using the substitution \(z \to z^{\tfrac{1}{2}}\) we get: \( \begin{align} c(z^{\frac{1}{2}}) &= \sqrt{\frac{1 + c(z)}{2}} \\ \\ s(z) &= 2 \, s(z^{\frac{1}{2}}) \, c(z^{\frac{1}{2}}) \\ \\ &= 2 \, s(z^{\frac{1}{2}}) \, \sqrt{\frac{1 + c(z)}{2}} \\ \\ &= 2 \, s(z^{\frac{1}{2}}) \, \sqrt{\frac{s(z) + s(z)c(z)}{2s(z)}} \\ \\ &= 2 \, s(z^{\frac{1}{2}}) \, \sqrt{\frac{s(z) + \frac{1}{2}s(z^2)}{2s(z)}} \\ \end{align} \) Or then after rearranging it: \( \begin{align} 2 \, s(z^{\frac{1}{2}}) = s(z) \, \sqrt{\frac{2s(z)}{s(z) + \frac{1}{2}s(z^2)}} \end{align} \) With: \( \begin{align} \ell(h) = \frac{1}{2h}(x^h - x^{-h}) = \frac{s(x^h)}{h} \end{align} \) Or then with \(z = x^h = x^{2^{-n}}\) we have: \( \begin{align} \ell_n = \ell(2^{-n}) = 2^n s(x^{2^{-n}}) = 2^n s(z) = s_n \end{align} \) This leads to the recurrence relation: \( \begin{align} s_{n+1} &= \ell(2^{-n-1}) \\ &= 2^{n+1} s(x^{2^{-n-1}}) \\ &= 2^n \cdot 2 s(z^{\tfrac{1}{2}}) \\ \\ &= 2^n s(z) \sqrt{\frac{2s(z)}{s(z) + \tfrac{1}{2}s(z^2)}} \\ \\ &= 2^n s(z) \sqrt{\frac{2 \cdot 2^n s(z)}{2^n s(z) + \tfrac{1}{2} \cdot 2^n s(z^2)}} \\ \\ &= s_n \sqrt{\frac{2 s_n}{s_n + 2^{n-1} s(z^2)}} \\ \\ &= s_n \sqrt{\frac{2 s_n}{s_n + s_{n-1}}} \\ \end{align} \) We can plug in \(z = e^x\) or \(z = e^{ix}\) to get related formulas for \(\sinh(x)\) and \(\sin(x)\): \( \begin{align} 2 \sinh(\frac{1}{2} z) &= \sinh(z) \sqrt{\frac{2\sinh(z)}{\sinh(z) + \frac{1}{2}\sinh(2z)}} \\ \\ 2 \sin(\frac{1}{2} z) &= \sin(z) \sqrt{\frac{2\sin(z)}{\sin(z) + \frac{1}{2}\sin(2z)}} \\ \end{align} \) That's due to the fact that: \( \begin{align} s(e^x) = \frac{e^x - e^{-x}}{2} = \sinh(x) \\ \\ s(e^{ix}) = \frac{e^{ix} - e^{-ix}}{2} = \sin(x) \\ \end{align} \) \( \begin{align} 2 s(z) c(z) &= 2 \frac{z - \frac{1}{z}}{2} \frac{z + \frac{1}{z}}{2} \\ &= \frac{\left(z - \frac{1}{z} \right) \left(z + \frac{1}{z} \right)}{2} \\ &= \frac{z^2 - \frac{1}{z^2}}{2} \\ &= s(z^2) \\ \\ 2 c(z)^2 &= 2 \left( \frac{z + \frac{1}{z}}{2} \right)^2 \\ &= \frac{\left(z + \frac{1}{z} \right)^2}{2} \\ &= \frac{z^2 + 2 + \frac{1}{z^2}}{2} \\ &= 1 + \frac{z^2 + \frac{1}{z^2}}{2} \\ &= 1 + c(z^2) \\ \end{align} \) RE: Log-Arcsine Algorithm - Albert Chan - 11-05-2022 10:47 AM It may be easier to get recurrence relation, directly from cosines. Let θ = x/2^(n+1), s(n) = 2^n * sin(x/2^n) cos(θ) = sin(2θ)/(2*sin(θ)) = s(n)/s(n+1) cos(2θ) = sin(4θ)/(2*sin(2θ)) = s(n-1)/s(n) cos(θ) = √((1+cos(2θ))/2) s(n)/s(n+1) = √((1+s(n-1)/s(n))/2) --> s(n+1) = s(n) * √(2*s(n) / (s(n) + s(n-1))) RE: Log-Arcsine Algorithm - Thomas Klemm - 11-05-2022 11:18 PM (11-05-2022 10:47 AM)Albert Chan Wrote: It may be easier I find it interesting that the recurrence relation is not dependent on trigonometric formulas. RE: Log-Arcsine Algorithm - Albert Chan - 11-06-2022 12:09 PM Here is a table of initial conditions, for all inverse trigonometric / hyperbolic / log functions s(n+1) = s(n) * √(2*s(n) / (s(n) + s(n-1))) → s(∞) = func(x) Code: asin x*√(1-x²) x RE: Log-Arcsine Algorithm - Thomas Klemm - 11-06-2022 02:43 PM Nice. I like where this is heading. |