Post Reply 
Π day
03-27-2022, 01:44 PM (This post was last modified: 03-30-2022 01:20 AM by Albert Chan.)
Post: #52
RE: Π day
If arugment for asin is big, taylor series take a long time to converge.

Ratio of coefficient = (2k+1)^2 / ((2k+2)*(2k+3)), approach 1 when k is huge.
For asin(1), this implied dropped term is almost same size as the last kept term.

We can use the "half-angle" formula for asin()
(05-31-2021 07:30 PM)Albert Chan Wrote:  \(\displaystyle\arcsin(x) = 2\arcsin\left( {x \over \sqrt{2\sqrt{1-x^2}+2}} \right)\)

Code:
function asinq(x) -- = asin(sqrt(x))
    if x > 4e-4 then return 2 * asinq(0.5*x/(sqrt(1-x)+1)) end
    return sqrt(x) * (1+x/6*(1+x*9/20/(1-x*25/42)))
end

lua> asinq(1/4), pi/6
0.5235987755982989      0.5235987755982988
lua> asinq(2/4), pi/4
0.7853981633974483      0.7853981633974483
lua> asinq(3/4), pi/3
1.0471975511965979      1.0471975511965976
lua> asinq(4/4), pi/2
1.5707963267948966      1.5707963267948966

Another way is to use Carlson Elliptic Integrals: RC(1-x,1) = asin(√x)/(√x)

Code:
function RC(x,y, verbose) -- RC(1-x,1) = asin(sqrt(x))/sqrt(x)
    local k = y + 2*sqrt(x*y)
    if k==x+2*y then return sqrt(3/k) end
    if verbose then print(sqrt(3/k)) end
    return RC((x+k)*0.25, (y+k)*0.25, verbose)
end

This is a simplified version of RF, RC(x,y) = RF(x,y,y)
see https://www.hpmuseum.org/forum/thread-17...#pid148498

It has no problem getting asin(1)/1 = pi/2, 1 sqrt per iteration

lua> RC(1-1, 1, true)
1.7320508075688772
1.5764775210064272
1.5711174700143078
1.5708159330462599
1.5707975451380392
1.570796402832061
1.5707963315455151
1.5707963270917837
1.5707963268134517
1.5707963267960565
1.5707963267949692
1.5707963267949012
1.570796326794897
1.5707963267948968
1.5707963267948968

Another example, from area of inscribed and circumsribed square, for pi

lua> A, B = 2, 4
lua> r = (B-A)/B -- = 1/2
lua> c = RC(1-r, 1, true) -- = asin(sqrt(1/2)) / sqrt(1/2) = pi/4 * sqrt(2)
1.1147379454918027
1.1109478170877694
1.1107345982528842
1.1107215960382895
1.1107207883059862
1.110720737898786
1.1107207347495225
1.110720734552712
1.1107207345404118
1.1107207345396428
1.1107207345395949
1.1107207345395917
1.1107207345395915

lua> A * c/sqrt(1-r)
3.141592653589793

lua> A * asinq(r)/sqrt(r-r*r)
3.141592653589793
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Π day - robve - 03-14-2022, 03:35 AM
RE: Π day - Dave Britten - 03-14-2022, 11:44 AM
RE: Π day - Gerson W. Barbosa - 03-14-2022, 12:25 PM
RE: Π day - robve - 03-14-2022, 05:52 PM
RE: Π day - Dave Britten - 03-14-2022, 06:15 PM
RE: Π day - Gerson W. Barbosa - 03-14-2022, 11:53 AM
RE: Π day - EdS2 - 03-14-2022, 01:55 PM
RE: Π day - Gerson W. Barbosa - 03-14-2022, 06:06 PM
RE: Π day - EdS2 - 03-15-2022, 12:05 PM
RE: Π day - robve - 03-14-2022, 09:35 PM
RE: Π day - Gerson W. Barbosa - 03-14-2022, 10:30 PM
RE: Π day - robve - 03-14-2022, 02:10 PM
RE: Π day - Gerson W. Barbosa - 03-14-2022, 08:29 PM
RE: π day - Thomas Klemm - 03-14-2022, 09:17 PM
RE: Π day - robve - 03-15-2022, 04:56 PM
RE: Π day - ttw - 03-14-2022, 11:06 PM
RE: Π day - robve - 03-15-2022, 12:35 AM
RE: Π day - floppy - 04-02-2022, 11:12 AM
RE: Π day - Eddie W. Shore - 03-15-2022, 01:09 AM
RE: Π day - rprosperi - 03-15-2022, 12:25 PM
RE: Π day - Ren - 03-15-2022, 01:16 AM
RE: π day - Thomas Klemm - 03-15-2022, 07:55 PM
RE: Π day - robve - 03-15-2022, 08:49 PM
RE: Π day - Thomas Klemm - 03-17-2022, 03:40 AM
RE: Π day - robve - 03-18-2022, 01:04 AM
RE: Π day - Thomas Klemm - 03-17-2022, 03:54 AM
RE: Π day - Gerson W. Barbosa - 03-17-2022, 11:39 AM
RE: Π day - Thomas Klemm - 03-17-2022, 12:29 PM
RE: Π day - Gerson W. Barbosa - 03-17-2022, 02:10 PM
RE: Π day - Ángel Martin - 03-18-2022, 09:07 AM
RE: Π day - Frido Bohn - 03-19-2022, 09:45 AM
RE: Π day - Ángel Martin - 03-19-2022, 11:17 AM
RE: Π day - Frido Bohn - 03-19-2022, 01:01 PM
RE: Π day - Frido Bohn - 03-19-2022, 03:13 PM
RE: Π day - DavidM - 03-17-2022, 08:25 PM
RE: Π day - Xorand - 03-18-2022, 03:06 AM
RE: Π day - Steve Simpkin - 03-18-2022, 04:31 AM
RE: Π day - MeindertKuipers - 03-18-2022, 10:48 AM
RE: Π day - Ángel Martin - 03-18-2022, 11:04 AM
RE: Π day - Ángel Martin - 03-19-2022, 11:18 AM
RE: Π day - Ren - 04-02-2022, 03:14 AM
RE: Π day - Ángel Martin - 03-20-2022, 07:39 AM
RE: Π day - Frido Bohn - 03-20-2022, 07:28 PM
RE: π day - Thomas Klemm - 03-21-2022, 07:24 AM
RE: Π day - Frido Bohn - 03-21-2022, 04:03 PM
RE: Π day - Albert Chan - 03-21-2022, 10:45 PM
RE: Π day - Gerson W. Barbosa - 03-24-2022, 01:36 AM
RE: Π day - Albert Chan - 03-26-2022, 03:59 PM
RE: Π day - Gerson W. Barbosa - 03-26-2022, 05:37 PM
RE: Π day - Thomas Klemm - 03-21-2022, 05:27 PM
RE: π day - Thomas Klemm - 03-21-2022, 05:54 PM
RE: π day - Thomas Klemm - 03-21-2022, 06:33 PM
RE: Π day - Albert Chan - 03-26-2022, 11:24 PM
RE: Π day - Albert Chan - 03-27-2022 01:44 PM
RE: Π day - Albert Chan - 03-27-2022, 04:00 PM
RE: Π day - ttw - 03-31-2022, 02:04 AM



User(s) browsing this thread: 1 Guest(s)