
(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]
\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)
Herbie found 6 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]
\frac{\pi}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)
(FPCore (x)
:precision binary64
(*
(*
(*
(fma 2.0 (acos (sqrt (fma x -0.5 0.5))) (- 1.5707963267948966 PI))
0.4052847345693511)
1.5707963267948966)
1.5707963267948966))double code(double x) {
return ((fma(2.0, acos(sqrt(fma(x, -0.5, 0.5))), (1.5707963267948966 - ((double) M_PI))) * 0.4052847345693511) * 1.5707963267948966) * 1.5707963267948966;
}
function code(x) return Float64(Float64(Float64(fma(2.0, acos(sqrt(fma(x, -0.5, 0.5))), Float64(1.5707963267948966 - pi)) * 0.4052847345693511) * 1.5707963267948966) * 1.5707963267948966) end
code[x_] := N[(N[(N[(N[(2.0 * N[ArcCos[N[Sqrt[N[(x * -0.5 + 0.5), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] + N[(1.5707963267948966 - Pi), $MachinePrecision]), $MachinePrecision] * 0.4052847345693511), $MachinePrecision] * 1.5707963267948966), $MachinePrecision] * 1.5707963267948966), $MachinePrecision]
\left(\left(\mathsf{fma}\left(2, \cos^{-1} \left(\sqrt{\mathsf{fma}\left(x, -0.5, 0.5\right)}\right), 1.5707963267948966 - \pi\right) \cdot 0.4052847345693511\right) \cdot 1.5707963267948966\right) \cdot 1.5707963267948966
Initial program 6.9%
Applied rewrites8.3%
Evaluated real constant8.3%
lift--.f64N/A
sub-to-multN/A
lower-unsound-*.f64N/A
Applied rewrites8.3%
Applied rewrites8.3%
(FPCore (x) :precision binary64 (fma (acos (sqrt (fma -0.5 x 0.5))) 2.0 (- 1.5707963267948966 PI)))
double code(double x) {
return fma(acos(sqrt(fma(-0.5, x, 0.5))), 2.0, (1.5707963267948966 - ((double) M_PI)));
}
function code(x) return fma(acos(sqrt(fma(-0.5, x, 0.5))), 2.0, Float64(1.5707963267948966 - pi)) end
code[x_] := N[(N[ArcCos[N[Sqrt[N[(-0.5 * x + 0.5), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 2.0 + N[(1.5707963267948966 - Pi), $MachinePrecision]), $MachinePrecision]
\mathsf{fma}\left(\cos^{-1} \left(\sqrt{\mathsf{fma}\left(-0.5, x, 0.5\right)}\right), 2, 1.5707963267948966 - \pi\right)
Initial program 6.9%
Applied rewrites8.3%
Evaluated real constant8.3%
lift--.f64N/A
lift-+.f64N/A
associate--r+N/A
sub-negate-revN/A
sub-negate-revN/A
add-flip-revN/A
distribute-neg-inN/A
lift-*.f64N/A
lift-neg.f64N/A
distribute-lft-neg-outN/A
remove-double-negN/A
sub-negate-revN/A
lower-fma.f64N/A
Applied rewrites8.3%
(FPCore (x) :precision binary64 (fma (asin (sqrt (* 0.5 (- 1.0 x)))) -2.0 1.5707963267948966))
double code(double x) {
return fma(asin(sqrt((0.5 * (1.0 - x)))), -2.0, 1.5707963267948966);
}
function code(x) return fma(asin(sqrt(Float64(0.5 * Float64(1.0 - x)))), -2.0, 1.5707963267948966) end
code[x_] := N[(N[ArcSin[N[Sqrt[N[(0.5 * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * -2.0 + 1.5707963267948966), $MachinePrecision]
\mathsf{fma}\left(\sin^{-1} \left(\sqrt{0.5 \cdot \left(1 - x\right)}\right), -2, 1.5707963267948966\right)
Initial program 6.9%
Taylor expanded in x around 0
Applied rewrites4.1%
Evaluated real constant4.1%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
metadata-evalN/A
*-commutativeN/A
lower-fma.f644.1%
Applied rewrites4.1%
Taylor expanded in x around 0
lower-asin.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower--.f646.9%
Applied rewrites6.9%
(FPCore (x) :precision binary64 (fma (acos (sqrt (fma -0.5 x 0.5))) 2.0 -1.5707963267948968))
double code(double x) {
return fma(acos(sqrt(fma(-0.5, x, 0.5))), 2.0, -1.5707963267948968);
}
function code(x) return fma(acos(sqrt(fma(-0.5, x, 0.5))), 2.0, -1.5707963267948968) end
code[x_] := N[(N[ArcCos[N[Sqrt[N[(-0.5 * x + 0.5), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 2.0 + -1.5707963267948968), $MachinePrecision]
\mathsf{fma}\left(\cos^{-1} \left(\sqrt{\mathsf{fma}\left(-0.5, x, 0.5\right)}\right), 2, -1.5707963267948968\right)
Initial program 6.9%
Applied rewrites8.3%
Evaluated real constant8.3%
lift--.f64N/A
lift-+.f64N/A
associate--r+N/A
sub-negate-revN/A
sub-negate-revN/A
add-flip-revN/A
distribute-neg-inN/A
lift-*.f64N/A
lift-neg.f64N/A
distribute-lft-neg-outN/A
remove-double-negN/A
sub-negate-revN/A
lower-fma.f64N/A
Applied rewrites8.3%
Evaluated real constant6.8%
(FPCore (x) :precision binary64 (fma (acos (sqrt 0.5)) 2.0 (- 1.5707963267948966 PI)))
double code(double x) {
return fma(acos(sqrt(0.5)), 2.0, (1.5707963267948966 - ((double) M_PI)));
}
function code(x) return fma(acos(sqrt(0.5)), 2.0, Float64(1.5707963267948966 - pi)) end
code[x_] := N[(N[ArcCos[N[Sqrt[0.5], $MachinePrecision]], $MachinePrecision] * 2.0 + N[(1.5707963267948966 - Pi), $MachinePrecision]), $MachinePrecision]
\mathsf{fma}\left(\cos^{-1} \left(\sqrt{0.5}\right), 2, 1.5707963267948966 - \pi\right)
Initial program 6.9%
Applied rewrites8.3%
Evaluated real constant8.3%
lift--.f64N/A
lift-+.f64N/A
associate--r+N/A
sub-negate-revN/A
sub-negate-revN/A
add-flip-revN/A
distribute-neg-inN/A
lift-*.f64N/A
lift-neg.f64N/A
distribute-lft-neg-outN/A
remove-double-negN/A
sub-negate-revN/A
lower-fma.f64N/A
Applied rewrites8.3%
Taylor expanded in x around 0
Applied rewrites5.4%
(FPCore (x) :precision binary64 (fma (asin (sqrt 0.5)) -2.0 1.5707963267948966))
double code(double x) {
return fma(asin(sqrt(0.5)), -2.0, 1.5707963267948966);
}
function code(x) return fma(asin(sqrt(0.5)), -2.0, 1.5707963267948966) end
code[x_] := N[(N[ArcSin[N[Sqrt[0.5], $MachinePrecision]], $MachinePrecision] * -2.0 + 1.5707963267948966), $MachinePrecision]
\mathsf{fma}\left(\sin^{-1} \left(\sqrt{0.5}\right), -2, 1.5707963267948966\right)
Initial program 6.9%
Taylor expanded in x around 0
Applied rewrites4.1%
Evaluated real constant4.1%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
metadata-evalN/A
*-commutativeN/A
lower-fma.f644.1%
Applied rewrites4.1%
herbie shell --seed 2025183
(FPCore (x)
:name "Ian Simplification"
:precision binary64
(- (/ PI 2.0) (* 2.0 (asin (sqrt (/ (- 1.0 x) 2.0))))))