
(FPCore (x) :precision binary64 (- (/ PI 2.0) (* 2.0 (asin (sqrt (/ (- 1.0 x) 2.0))))))
double code(double x) {
return (((double) M_PI) / 2.0) - (2.0 * asin(sqrt(((1.0 - x) / 2.0))));
}
public static double code(double x) {
return (Math.PI / 2.0) - (2.0 * Math.asin(Math.sqrt(((1.0 - x) / 2.0))));
}
def code(x): return (math.pi / 2.0) - (2.0 * math.asin(math.sqrt(((1.0 - x) / 2.0))))
function code(x) return Float64(Float64(pi / 2.0) - Float64(2.0 * asin(sqrt(Float64(Float64(1.0 - x) / 2.0))))) end
function tmp = code(x) tmp = (pi / 2.0) - (2.0 * asin(sqrt(((1.0 - x) / 2.0)))); end
code[x_] := N[(N[(Pi / 2.0), $MachinePrecision] - N[(2.0 * N[ArcSin[N[Sqrt[N[(N[(1.0 - x), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (/ PI 2.0) (* 2.0 (asin (sqrt (/ (- 1.0 x) 2.0))))))
double code(double x) {
return (((double) M_PI) / 2.0) - (2.0 * asin(sqrt(((1.0 - x) / 2.0))));
}
public static double code(double x) {
return (Math.PI / 2.0) - (2.0 * Math.asin(Math.sqrt(((1.0 - x) / 2.0))));
}
def code(x): return (math.pi / 2.0) - (2.0 * math.asin(math.sqrt(((1.0 - x) / 2.0))))
function code(x) return Float64(Float64(pi / 2.0) - Float64(2.0 * asin(sqrt(Float64(Float64(1.0 - x) / 2.0))))) end
function tmp = code(x) tmp = (pi / 2.0) - (2.0 * asin(sqrt(((1.0 - x) / 2.0)))); end
code[x_] := N[(N[(Pi / 2.0), $MachinePrecision] - N[(2.0 * N[ArcSin[N[Sqrt[N[(N[(1.0 - x), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)
\end{array}
(FPCore (x)
:precision binary64
(let* ((t_0 (asin (sqrt (- 0.5 (* 0.5 x))))))
(/
(- (pow (* (cbrt (pow PI 3.0)) 0.5) 2.0) (pow (* 2.0 t_0) 2.0))
(fma 2.0 t_0 (* PI 0.5)))))
double code(double x) {
double t_0 = asin(sqrt((0.5 - (0.5 * x))));
return (pow((cbrt(pow(((double) M_PI), 3.0)) * 0.5), 2.0) - pow((2.0 * t_0), 2.0)) / fma(2.0, t_0, (((double) M_PI) * 0.5));
}
function code(x) t_0 = asin(sqrt(Float64(0.5 - Float64(0.5 * x)))) return Float64(Float64((Float64(cbrt((pi ^ 3.0)) * 0.5) ^ 2.0) - (Float64(2.0 * t_0) ^ 2.0)) / fma(2.0, t_0, Float64(pi * 0.5))) end
code[x_] := Block[{t$95$0 = N[ArcSin[N[Sqrt[N[(0.5 - N[(0.5 * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]}, N[(N[(N[Power[N[(N[Power[N[Power[Pi, 3.0], $MachinePrecision], 1/3], $MachinePrecision] * 0.5), $MachinePrecision], 2.0], $MachinePrecision] - N[Power[N[(2.0 * t$95$0), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / N[(2.0 * t$95$0 + N[(Pi * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(\sqrt{0.5 - 0.5 \cdot x}\right)\\
\frac{{\left(\sqrt[3]{{\pi}^{3}} \cdot 0.5\right)}^{2} - {\left(2 \cdot t\_0\right)}^{2}}{\mathsf{fma}\left(2, t\_0, \pi \cdot 0.5\right)}
\end{array}
\end{array}
Initial program 6.9%
flip--7.0%
pow27.0%
div-inv7.0%
metadata-eval7.0%
pow27.0%
div-sub7.0%
metadata-eval7.0%
div-inv7.0%
metadata-eval7.0%
+-commutative7.0%
Applied egg-rr7.0%
add-cbrt-cube8.0%
pow38.0%
Applied egg-rr8.0%
Final simplification8.0%
(FPCore (x) :precision binary64 (+ (/ PI 2.0) (* 2.0 (- (acos (pow (/ 2.0 (- 1.0 x)) -0.5)) (* PI 0.5)))))
double code(double x) {
return (((double) M_PI) / 2.0) + (2.0 * (acos(pow((2.0 / (1.0 - x)), -0.5)) - (((double) M_PI) * 0.5)));
}
public static double code(double x) {
return (Math.PI / 2.0) + (2.0 * (Math.acos(Math.pow((2.0 / (1.0 - x)), -0.5)) - (Math.PI * 0.5)));
}
def code(x): return (math.pi / 2.0) + (2.0 * (math.acos(math.pow((2.0 / (1.0 - x)), -0.5)) - (math.pi * 0.5)))
function code(x) return Float64(Float64(pi / 2.0) + Float64(2.0 * Float64(acos((Float64(2.0 / Float64(1.0 - x)) ^ -0.5)) - Float64(pi * 0.5)))) end
function tmp = code(x) tmp = (pi / 2.0) + (2.0 * (acos(((2.0 / (1.0 - x)) ^ -0.5)) - (pi * 0.5))); end
code[x_] := N[(N[(Pi / 2.0), $MachinePrecision] + N[(2.0 * N[(N[ArcCos[N[Power[N[(2.0 / N[(1.0 - x), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision]], $MachinePrecision] - N[(Pi * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\pi}{2} + 2 \cdot \left(\cos^{-1} \left({\left(\frac{2}{1 - x}\right)}^{-0.5}\right) - \pi \cdot 0.5\right)
\end{array}
Initial program 6.9%
clear-num6.9%
sqrt-div7.2%
metadata-eval7.2%
Applied egg-rr7.2%
asin-acos7.1%
div-inv7.1%
metadata-eval7.1%
*-commutative7.1%
pow1/27.1%
pow-flip8.0%
metadata-eval8.0%
Applied egg-rr8.0%
Final simplification8.0%
(FPCore (x) :precision binary64 (+ (/ PI 2.0) (* 2.0 (- (acos (sqrt (+ 0.5 (* x -0.5)))) (/ PI 2.0)))))
double code(double x) {
return (((double) M_PI) / 2.0) + (2.0 * (acos(sqrt((0.5 + (x * -0.5)))) - (((double) M_PI) / 2.0)));
}
public static double code(double x) {
return (Math.PI / 2.0) + (2.0 * (Math.acos(Math.sqrt((0.5 + (x * -0.5)))) - (Math.PI / 2.0)));
}
def code(x): return (math.pi / 2.0) + (2.0 * (math.acos(math.sqrt((0.5 + (x * -0.5)))) - (math.pi / 2.0)))
function code(x) return Float64(Float64(pi / 2.0) + Float64(2.0 * Float64(acos(sqrt(Float64(0.5 + Float64(x * -0.5)))) - Float64(pi / 2.0)))) end
function tmp = code(x) tmp = (pi / 2.0) + (2.0 * (acos(sqrt((0.5 + (x * -0.5)))) - (pi / 2.0))); end
code[x_] := N[(N[(Pi / 2.0), $MachinePrecision] + N[(2.0 * N[(N[ArcCos[N[Sqrt[N[(0.5 + N[(x * -0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] - N[(Pi / 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\pi}{2} + 2 \cdot \left(\cos^{-1} \left(\sqrt{0.5 + x \cdot -0.5}\right) - \frac{\pi}{2}\right)
\end{array}
Initial program 6.9%
asin-acos8.0%
add-cube-cbrt6.9%
associate-/l*6.9%
fma-neg6.9%
pow26.9%
div-sub6.9%
metadata-eval6.9%
div-inv6.9%
metadata-eval6.9%
Applied egg-rr6.9%
fma-neg6.9%
associate-*r/6.9%
unpow26.9%
rem-3cbrt-lft8.0%
sub-neg8.0%
distribute-rgt-neg-in8.0%
metadata-eval8.0%
Simplified8.0%
Final simplification8.0%
(FPCore (x) :precision binary64 (if (<= x -5e-310) (- (/ PI 2.0) (* 2.0 (asin (sqrt 0.5)))) (- (/ PI 2.0) (* 2.0 (asin (/ 1.0 (sqrt 2.0)))))))
double code(double x) {
double tmp;
if (x <= -5e-310) {
tmp = (((double) M_PI) / 2.0) - (2.0 * asin(sqrt(0.5)));
} else {
tmp = (((double) M_PI) / 2.0) - (2.0 * asin((1.0 / sqrt(2.0))));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= -5e-310) {
tmp = (Math.PI / 2.0) - (2.0 * Math.asin(Math.sqrt(0.5)));
} else {
tmp = (Math.PI / 2.0) - (2.0 * Math.asin((1.0 / Math.sqrt(2.0))));
}
return tmp;
}
def code(x): tmp = 0 if x <= -5e-310: tmp = (math.pi / 2.0) - (2.0 * math.asin(math.sqrt(0.5))) else: tmp = (math.pi / 2.0) - (2.0 * math.asin((1.0 / math.sqrt(2.0)))) return tmp
function code(x) tmp = 0.0 if (x <= -5e-310) tmp = Float64(Float64(pi / 2.0) - Float64(2.0 * asin(sqrt(0.5)))); else tmp = Float64(Float64(pi / 2.0) - Float64(2.0 * asin(Float64(1.0 / sqrt(2.0))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -5e-310) tmp = (pi / 2.0) - (2.0 * asin(sqrt(0.5))); else tmp = (pi / 2.0) - (2.0 * asin((1.0 / sqrt(2.0)))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -5e-310], N[(N[(Pi / 2.0), $MachinePrecision] - N[(2.0 * N[ArcSin[N[Sqrt[0.5], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(Pi / 2.0), $MachinePrecision] - N[(2.0 * N[ArcSin[N[(1.0 / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{0.5}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\frac{1}{\sqrt{2}}\right)\\
\end{array}
\end{array}
if x < -4.999999999999985e-310Initial program 8.9%
Taylor expanded in x around 0 5.9%
if -4.999999999999985e-310 < x Initial program 5.1%
clear-num5.1%
sqrt-div8.5%
metadata-eval8.5%
Applied egg-rr8.5%
Taylor expanded in x around 0 6.3%
Final simplification6.1%
(FPCore (x) :precision binary64 (- (/ PI 2.0) (* 2.0 (asin (/ 1.0 (sqrt (/ 2.0 (- 1.0 x))))))))
double code(double x) {
return (((double) M_PI) / 2.0) - (2.0 * asin((1.0 / sqrt((2.0 / (1.0 - x))))));
}
public static double code(double x) {
return (Math.PI / 2.0) - (2.0 * Math.asin((1.0 / Math.sqrt((2.0 / (1.0 - x))))));
}
def code(x): return (math.pi / 2.0) - (2.0 * math.asin((1.0 / math.sqrt((2.0 / (1.0 - x))))))
function code(x) return Float64(Float64(pi / 2.0) - Float64(2.0 * asin(Float64(1.0 / sqrt(Float64(2.0 / Float64(1.0 - x))))))) end
function tmp = code(x) tmp = (pi / 2.0) - (2.0 * asin((1.0 / sqrt((2.0 / (1.0 - x)))))); end
code[x_] := N[(N[(Pi / 2.0), $MachinePrecision] - N[(2.0 * N[ArcSin[N[(1.0 / N[Sqrt[N[(2.0 / N[(1.0 - x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\frac{1}{\sqrt{\frac{2}{1 - x}}}\right)
\end{array}
Initial program 6.9%
clear-num6.9%
sqrt-div7.2%
metadata-eval7.2%
Applied egg-rr7.2%
Final simplification7.2%
(FPCore (x) :precision binary64 (- (/ PI 2.0) (* 2.0 (asin (sqrt (/ (- 1.0 x) 2.0))))))
double code(double x) {
return (((double) M_PI) / 2.0) - (2.0 * asin(sqrt(((1.0 - x) / 2.0))));
}
public static double code(double x) {
return (Math.PI / 2.0) - (2.0 * Math.asin(Math.sqrt(((1.0 - x) / 2.0))));
}
def code(x): return (math.pi / 2.0) - (2.0 * math.asin(math.sqrt(((1.0 - x) / 2.0))))
function code(x) return Float64(Float64(pi / 2.0) - Float64(2.0 * asin(sqrt(Float64(Float64(1.0 - x) / 2.0))))) end
function tmp = code(x) tmp = (pi / 2.0) - (2.0 * asin(sqrt(((1.0 - x) / 2.0)))); end
code[x_] := N[(N[(Pi / 2.0), $MachinePrecision] - N[(2.0 * N[ArcSin[N[Sqrt[N[(N[(1.0 - x), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)
\end{array}
Initial program 6.9%
Final simplification6.9%
(FPCore (x) :precision binary64 (- (/ PI 2.0) (* 2.0 (asin (sqrt 0.5)))))
double code(double x) {
return (((double) M_PI) / 2.0) - (2.0 * asin(sqrt(0.5)));
}
public static double code(double x) {
return (Math.PI / 2.0) - (2.0 * Math.asin(Math.sqrt(0.5)));
}
def code(x): return (math.pi / 2.0) - (2.0 * math.asin(math.sqrt(0.5)))
function code(x) return Float64(Float64(pi / 2.0) - Float64(2.0 * asin(sqrt(0.5)))) end
function tmp = code(x) tmp = (pi / 2.0) - (2.0 * asin(sqrt(0.5))); end
code[x_] := N[(N[(Pi / 2.0), $MachinePrecision] - N[(2.0 * N[ArcSin[N[Sqrt[0.5], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{0.5}\right)
\end{array}
Initial program 6.9%
Taylor expanded in x around 0 4.0%
Final simplification4.0%
(FPCore (x) :precision binary64 (asin x))
double code(double x) {
return asin(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = asin(x)
end function
public static double code(double x) {
return Math.asin(x);
}
def code(x): return math.asin(x)
function code(x) return asin(x) end
function tmp = code(x) tmp = asin(x); end
code[x_] := N[ArcSin[x], $MachinePrecision]
\begin{array}{l}
\\
\sin^{-1} x
\end{array}
herbie shell --seed 2024043
(FPCore (x)
:name "Ian Simplification"
:precision binary64
:alt
(asin x)
(- (/ PI 2.0) (* 2.0 (asin (sqrt (/ (- 1.0 x) 2.0))))))