
(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}
Herbie found 3 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 (fma (acos (sqrt (fma x -0.5 0.5))) 2.0 (* -0.5 PI)))
double code(double x) {
return fma(acos(sqrt(fma(x, -0.5, 0.5))), 2.0, (-0.5 * ((double) M_PI)));
}
function code(x) return fma(acos(sqrt(fma(x, -0.5, 0.5))), 2.0, Float64(-0.5 * pi)) end
code[x_] := N[(N[ArcCos[N[Sqrt[N[(x * -0.5 + 0.5), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 2.0 + N[(-0.5 * Pi), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos^{-1} \left(\sqrt{\mathsf{fma}\left(x, -0.5, 0.5\right)}\right), 2, -0.5 \cdot \pi\right)
\end{array}
Initial program 6.9%
Applied rewrites8.4%
(FPCore (x) :precision binary64 (fma (acos (fma x -0.5 (sqrt 0.5))) 2.0 (* -0.5 PI)))
double code(double x) {
return fma(acos(fma(x, -0.5, sqrt(0.5))), 2.0, (-0.5 * ((double) M_PI)));
}
function code(x) return fma(acos(fma(x, -0.5, sqrt(0.5))), 2.0, Float64(-0.5 * pi)) end
code[x_] := N[(N[ArcCos[N[(x * -0.5 + N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 2.0 + N[(-0.5 * Pi), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos^{-1} \left(\mathsf{fma}\left(x, -0.5, \sqrt{0.5}\right)\right), 2, -0.5 \cdot \pi\right)
\end{array}
Initial program 6.9%
Applied rewrites8.4%
Taylor expanded in x around 0
Applied rewrites7.4%
Applied rewrites3.8%
Applied rewrites6.3%
(FPCore (x) :precision binary64 (fma (acos (sqrt 0.5)) 2.0 (* -0.5 PI)))
double code(double x) {
return fma(acos(sqrt(0.5)), 2.0, (-0.5 * ((double) M_PI)));
}
function code(x) return fma(acos(sqrt(0.5)), 2.0, Float64(-0.5 * pi)) end
code[x_] := N[(N[ArcCos[N[Sqrt[0.5], $MachinePrecision]], $MachinePrecision] * 2.0 + N[(-0.5 * Pi), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos^{-1} \left(\sqrt{0.5}\right), 2, -0.5 \cdot \pi\right)
\end{array}
Initial program 6.9%
Applied rewrites8.4%
Taylor expanded in x around 0
Applied rewrites5.4%
herbie shell --seed 2025161
(FPCore (x)
:name "Ian Simplification"
:precision binary64
(- (/ PI 2.0) (* 2.0 (asin (sqrt (/ (- 1.0 x) 2.0))))))