Faking arcsin.....

Andy Long, Spring 2024

Now that we have a good fake for sine, it seems like we might have a good fake for arcsin:

Plot[{Sin[x],ArcSin[x],x},{x,-Pi/2,Pi/2},PlotRange->All,AspectRatio->1,PlotStyle->{Black,Blue,Dashed}]

p1=Plot[{Sin[x],ArcSin[x],x},{x,0,Pi/2},PlotRange->All,AspectRatio->1,PlotStyle->{Black,Blue,Dashed}]

Arcsine is the inverse of sine...

x0=0.99
(* *)
arcSinner[x_]:=Solve[Sin[y]==x,y] 
y0=y/.arcSinner[x0][[1]]
p2=ListPlot[{{x0,y0},{y0,x0}}];
Show[p1,p2]

Maclaurin sins:

We wanted an error less than 10^{-6}; if we take the error term to 11, it works (while 10 is not quite enough):

errTerm[n_]:=(Pi/2)^(n+1)/Factorial[n+1]
N[errTerm[11]]
N[errTerm[10]]

So we’ll use the 11 degree Taylor polynomial to fake sine:

T11[x_]=Normal[Series[Sin[x],{x,0,11}]]

And then redefine sinner, incorporating this fake, plot it, and plot its error -- is it less than 10^{-6} everywhere?

sinner[x_]:=
If[x<0,-sinner[-x], 
If[x>2Pi,sinner[x-Floor[x/(2Pi)]*2Pi],
If[x>Pi,-sinner[2Pi-x],
If[x>Pi/2,sinner[Pi-x],
T11[x]
]
]
]
]
Plot[sinner[x],{x,-Pi,3Pi}]
Plot[(sinner[x]-Sin[x]),{x,-Pi,3Pi},PlotRange->All]

Now we need to fake for Mathematica’s “Solve” routine: we’ll start with bisection.

arcSinner[y_]:=Module[{f},
If[y<0,
-arcSinner[-y],
(* Because ArcSin[x] is always > x, *)
f[x_]:=sinner[x]-y;
Bisection[f,y,Pi/2,epsilon->10^(-9),maxits->1000,verbose->False]
]
]
xx=0.9
yy=arcSinner[xx]
p2=ListPlot[{{xx,yy},{yy,xx}}];
Show[p1,p2]

Plot[{ArcSin[x],arcSinner[x]},{x,-1,1}]
Plot[{ArcSin[x]-arcSinner[x]},{x,-1,1}]
Plot[{ArcSin[x]-arcSinner[x]},{x,-1,1},PlotRange->All]

Plot[{ArcSin[x]-arcSinner[x]},{x,0.99,1},PlotRange->All]

NumberForm[N[arcSinner[.9999999]],20]
NumberForm[N[ArcSin[.9999999]],20]
NumberForm[N[arcSinner[.999999]],20]
NumberForm[N[ArcSin[.999999]],20]
NumberForm[N[arcSinner[.99999]],20]
NumberForm[N[ArcSin[.99999]],20]
NumberForm[N[arcSinner[.99998]],20]
NumberForm[N[ArcSin[.99998]],20]
N[Pi/2]

arcSinner2[y_]:=Module[{f},
If[y<0,
-arcSinner2[-y],
(* Because ArcSin[x] is always > x, *)
f[x_]:=sinner[x]-y;
Bisection[f,y,Pi/2,epsilon->10^(-11),tolerance->10^(-12),maxits->1000,verbose->False]
]
]
N[arcSinner2[0.9999999],20]

Plot[{ArcSin[x]-arcSinner2[x]},{x,0.999999,1},PlotRange->All]
Plot[{ArcSin[x],arcSinner2[x]},{x,0.999999,1},PlotRange->All]