
(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 2 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 -0.5 x 0.5))) 2.0 (* -0.5 PI)))
double code(double x) {
return fma(acos(sqrt(fma(-0.5, x, 0.5))), 2.0, (-0.5 * ((double) M_PI)));
}
function code(x) return fma(acos(sqrt(fma(-0.5, x, 0.5))), 2.0, Float64(-0.5 * pi)) end
code[x_] := N[(N[ArcCos[N[Sqrt[N[(-0.5 * x + 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(-0.5, x, 0.5\right)}\right), 2, -0.5 \cdot \pi\right)
\end{array}
Initial program 7.0%
Applied rewrites8.5%
lift--.f64N/A
lift-+.f64N/A
associate--r+N/A
sub-flipN/A
+-commutativeN/A
lift-*.f64N/A
lift-neg.f64N/A
distribute-lft-neg-outN/A
remove-double-negN/A
sub-flipN/A
lift-/.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lift-PI.f64N/A
add-log-expN/A
log-pow-revN/A
lift-PI.f64N/A
add-log-expN/A
Applied rewrites8.5%
(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 7.0%
Applied rewrites8.5%
lift--.f64N/A
lift-+.f64N/A
associate--r+N/A
sub-flipN/A
+-commutativeN/A
lift-*.f64N/A
lift-neg.f64N/A
distribute-lft-neg-outN/A
remove-double-negN/A
sub-flipN/A
lift-/.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lift-PI.f64N/A
add-log-expN/A
log-pow-revN/A
lift-PI.f64N/A
add-log-expN/A
Applied rewrites8.5%
Taylor expanded in x around 0
Applied rewrites5.3%
herbie shell --seed 2025156
(FPCore (x)
:name "Ian Simplification"
:precision binary64
(- (/ PI 2.0) (* 2.0 (asin (sqrt (/ (- 1.0 x) 2.0))))))