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