
(FPCore (x) :precision binary64 (acos (- 1.0 x)))
double code(double x) {
return acos((1.0 - x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = acos((1.0d0 - x))
end function
public static double code(double x) {
return Math.acos((1.0 - x));
}
def code(x): return math.acos((1.0 - x))
function code(x) return acos(Float64(1.0 - x)) end
function tmp = code(x) tmp = acos((1.0 - x)); end
code[x_] := N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(1 - x\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (acos (- 1.0 x)))
double code(double x) {
return acos((1.0 - x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = acos((1.0d0 - x))
end function
public static double code(double x) {
return Math.acos((1.0 - x));
}
def code(x): return math.acos((1.0 - x))
function code(x) return acos(Float64(1.0 - x)) end
function tmp = code(x) tmp = acos((1.0 - x)); end
code[x_] := N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(1 - x\right)
\end{array}
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (* PI 0.5)))
(t_1 (asin (- 1.0 x)))
(t_2
(cbrt (cbrt (* (asin (/ (fma x x -1.0) (- -1.0 x))) (pow t_1 2.0)))))
(t_3 (pow t_2 2.0))
(t_4 (* t_2 t_3))
(t_5 (cbrt t_1))
(t_6 (pow t_5 2.0)))
(+
(+ (fma t_0 t_0 (- t_4)) (fma (- t_2) t_3 t_4))
(fma (- t_5) t_6 (* t_5 t_6)))))
double code(double x) {
double t_0 = sqrt((((double) M_PI) * 0.5));
double t_1 = asin((1.0 - x));
double t_2 = cbrt(cbrt((asin((fma(x, x, -1.0) / (-1.0 - x))) * pow(t_1, 2.0))));
double t_3 = pow(t_2, 2.0);
double t_4 = t_2 * t_3;
double t_5 = cbrt(t_1);
double t_6 = pow(t_5, 2.0);
return (fma(t_0, t_0, -t_4) + fma(-t_2, t_3, t_4)) + fma(-t_5, t_6, (t_5 * t_6));
}
function code(x) t_0 = sqrt(Float64(pi * 0.5)) t_1 = asin(Float64(1.0 - x)) t_2 = cbrt(cbrt(Float64(asin(Float64(fma(x, x, -1.0) / Float64(-1.0 - x))) * (t_1 ^ 2.0)))) t_3 = t_2 ^ 2.0 t_4 = Float64(t_2 * t_3) t_5 = cbrt(t_1) t_6 = t_5 ^ 2.0 return Float64(Float64(fma(t_0, t_0, Float64(-t_4)) + fma(Float64(-t_2), t_3, t_4)) + fma(Float64(-t_5), t_6, Float64(t_5 * t_6))) end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(Pi * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Power[N[(N[ArcSin[N[(N[(x * x + -1.0), $MachinePrecision] / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], 1/3], $MachinePrecision]}, Block[{t$95$3 = N[Power[t$95$2, 2.0], $MachinePrecision]}, Block[{t$95$4 = N[(t$95$2 * t$95$3), $MachinePrecision]}, Block[{t$95$5 = N[Power[t$95$1, 1/3], $MachinePrecision]}, Block[{t$95$6 = N[Power[t$95$5, 2.0], $MachinePrecision]}, N[(N[(N[(t$95$0 * t$95$0 + (-t$95$4)), $MachinePrecision] + N[((-t$95$2) * t$95$3 + t$95$4), $MachinePrecision]), $MachinePrecision] + N[((-t$95$5) * t$95$6 + N[(t$95$5 * t$95$6), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\pi \cdot 0.5}\\
t_1 := \sin^{-1} \left(1 - x\right)\\
t_2 := \sqrt[3]{\sqrt[3]{\sin^{-1} \left(\frac{\mathsf{fma}\left(x, x, -1\right)}{-1 - x}\right) \cdot {t\_1}^{2}}}\\
t_3 := {t\_2}^{2}\\
t_4 := t\_2 \cdot t\_3\\
t_5 := \sqrt[3]{t\_1}\\
t_6 := {t\_5}^{2}\\
\left(\mathsf{fma}\left(t\_0, t\_0, -t\_4\right) + \mathsf{fma}\left(-t\_2, t\_3, t\_4\right)\right) + \mathsf{fma}\left(-t\_5, t\_6, t\_5 \cdot t\_6\right)
\end{array}
\end{array}
Initial program 4.9%
acos-asin4.9%
add-sqr-sqrt3.0%
add-cube-cbrt8.7%
prod-diff8.7%
Applied egg-rr8.7%
flip--8.8%
div-inv8.8%
metadata-eval8.8%
pow28.8%
Applied egg-rr8.8%
associate-*r/8.8%
*-rgt-identity8.8%
remove-double-neg8.8%
distribute-frac-neg8.8%
distribute-frac-neg28.8%
sub-neg8.8%
+-commutative8.8%
distribute-neg-in8.8%
unpow28.8%
sqr-neg8.8%
unpow28.8%
remove-double-neg8.8%
sub-neg8.8%
unpow28.8%
sqr-neg8.8%
fmm-def8.8%
metadata-eval8.8%
distribute-neg-in8.8%
metadata-eval8.8%
unsub-neg8.8%
Simplified8.8%
Taylor expanded in x around 0 3.1%
Simplified3.1%
fmm-undef3.1%
add-cube-cbrt8.8%
prod-diff8.8%
Applied egg-rr8.8%
(FPCore (x)
:precision binary64
(let* ((t_0 (cbrt (asin (- 1.0 x))))
(t_1 (pow t_0 2.0))
(t_2 (sqrt (* PI 0.5))))
(+
(fma (- t_0) t_1 (* t_0 t_1))
(fma t_2 t_2 (* t_1 (- (cbrt (asin (/ (fma x x -1.0) (- -1.0 x))))))))))
double code(double x) {
double t_0 = cbrt(asin((1.0 - x)));
double t_1 = pow(t_0, 2.0);
double t_2 = sqrt((((double) M_PI) * 0.5));
return fma(-t_0, t_1, (t_0 * t_1)) + fma(t_2, t_2, (t_1 * -cbrt(asin((fma(x, x, -1.0) / (-1.0 - x))))));
}
function code(x) t_0 = cbrt(asin(Float64(1.0 - x))) t_1 = t_0 ^ 2.0 t_2 = sqrt(Float64(pi * 0.5)) return Float64(fma(Float64(-t_0), t_1, Float64(t_0 * t_1)) + fma(t_2, t_2, Float64(t_1 * Float64(-cbrt(asin(Float64(fma(x, x, -1.0) / Float64(-1.0 - x)))))))) end
code[x_] := Block[{t$95$0 = N[Power[N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision]}, Block[{t$95$1 = N[Power[t$95$0, 2.0], $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(Pi * 0.5), $MachinePrecision]], $MachinePrecision]}, N[(N[((-t$95$0) * t$95$1 + N[(t$95$0 * t$95$1), $MachinePrecision]), $MachinePrecision] + N[(t$95$2 * t$95$2 + N[(t$95$1 * (-N[Power[N[ArcSin[N[(N[(x * x + -1.0), $MachinePrecision] / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{\sin^{-1} \left(1 - x\right)}\\
t_1 := {t\_0}^{2}\\
t_2 := \sqrt{\pi \cdot 0.5}\\
\mathsf{fma}\left(-t\_0, t\_1, t\_0 \cdot t\_1\right) + \mathsf{fma}\left(t\_2, t\_2, t\_1 \cdot \left(-\sqrt[3]{\sin^{-1} \left(\frac{\mathsf{fma}\left(x, x, -1\right)}{-1 - x}\right)}\right)\right)
\end{array}
\end{array}
Initial program 4.9%
acos-asin4.9%
add-sqr-sqrt3.0%
add-cube-cbrt8.7%
prod-diff8.7%
Applied egg-rr8.7%
flip--8.8%
div-inv8.8%
metadata-eval8.8%
pow28.8%
Applied egg-rr8.8%
associate-*r/8.8%
*-rgt-identity8.8%
remove-double-neg8.8%
distribute-frac-neg8.8%
distribute-frac-neg28.8%
sub-neg8.8%
+-commutative8.8%
distribute-neg-in8.8%
unpow28.8%
sqr-neg8.8%
unpow28.8%
remove-double-neg8.8%
sub-neg8.8%
unpow28.8%
sqr-neg8.8%
fmm-def8.8%
metadata-eval8.8%
distribute-neg-in8.8%
metadata-eval8.8%
unsub-neg8.8%
Simplified8.8%
Final simplification8.8%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (* PI 0.5)))
(t_1 (cbrt (asin (- 1.0 x))))
(t_2 (pow t_1 2.0)))
(+
(fma t_0 t_0 (* t_1 (- t_2)))
(fma (- (cbrt (asin (/ (fma x x -1.0) (- -1.0 x))))) t_2 (* t_1 t_2)))))
double code(double x) {
double t_0 = sqrt((((double) M_PI) * 0.5));
double t_1 = cbrt(asin((1.0 - x)));
double t_2 = pow(t_1, 2.0);
return fma(t_0, t_0, (t_1 * -t_2)) + fma(-cbrt(asin((fma(x, x, -1.0) / (-1.0 - x)))), t_2, (t_1 * t_2));
}
function code(x) t_0 = sqrt(Float64(pi * 0.5)) t_1 = cbrt(asin(Float64(1.0 - x))) t_2 = t_1 ^ 2.0 return Float64(fma(t_0, t_0, Float64(t_1 * Float64(-t_2))) + fma(Float64(-cbrt(asin(Float64(fma(x, x, -1.0) / Float64(-1.0 - x))))), t_2, Float64(t_1 * t_2))) end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(Pi * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision]}, Block[{t$95$2 = N[Power[t$95$1, 2.0], $MachinePrecision]}, N[(N[(t$95$0 * t$95$0 + N[(t$95$1 * (-t$95$2)), $MachinePrecision]), $MachinePrecision] + N[((-N[Power[N[ArcSin[N[(N[(x * x + -1.0), $MachinePrecision] / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision]) * t$95$2 + N[(t$95$1 * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\pi \cdot 0.5}\\
t_1 := \sqrt[3]{\sin^{-1} \left(1 - x\right)}\\
t_2 := {t\_1}^{2}\\
\mathsf{fma}\left(t\_0, t\_0, t\_1 \cdot \left(-t\_2\right)\right) + \mathsf{fma}\left(-\sqrt[3]{\sin^{-1} \left(\frac{\mathsf{fma}\left(x, x, -1\right)}{-1 - x}\right)}, t\_2, t\_1 \cdot t\_2\right)
\end{array}
\end{array}
Initial program 4.9%
acos-asin4.9%
add-sqr-sqrt3.0%
add-cube-cbrt8.7%
prod-diff8.7%
Applied egg-rr8.7%
flip--8.8%
div-inv8.8%
metadata-eval8.8%
pow28.8%
Applied egg-rr8.8%
associate-*r/8.8%
*-rgt-identity8.8%
remove-double-neg8.8%
distribute-frac-neg8.8%
distribute-frac-neg28.8%
sub-neg8.8%
+-commutative8.8%
distribute-neg-in8.8%
unpow28.8%
sqr-neg8.8%
unpow28.8%
remove-double-neg8.8%
sub-neg8.8%
unpow28.8%
sqr-neg8.8%
fmm-def8.8%
metadata-eval8.8%
distribute-neg-in8.8%
metadata-eval8.8%
unsub-neg8.8%
Simplified8.8%
Final simplification8.8%
(FPCore (x)
:precision binary64
(let* ((t_0 (asin (- 1.0 x))) (t_1 (sqrt (* PI 0.5))) (t_2 (cbrt t_0)))
(+
(fma
t_1
t_1
(- (cbrt (* (asin (/ (fma x x -1.0) (- -1.0 x))) (pow t_0 2.0)))))
(fma (- t_2) (pow t_2 2.0) t_0))))
double code(double x) {
double t_0 = asin((1.0 - x));
double t_1 = sqrt((((double) M_PI) * 0.5));
double t_2 = cbrt(t_0);
return fma(t_1, t_1, -cbrt((asin((fma(x, x, -1.0) / (-1.0 - x))) * pow(t_0, 2.0)))) + fma(-t_2, pow(t_2, 2.0), t_0);
}
function code(x) t_0 = asin(Float64(1.0 - x)) t_1 = sqrt(Float64(pi * 0.5)) t_2 = cbrt(t_0) return Float64(fma(t_1, t_1, Float64(-cbrt(Float64(asin(Float64(fma(x, x, -1.0) / Float64(-1.0 - x))) * (t_0 ^ 2.0))))) + fma(Float64(-t_2), (t_2 ^ 2.0), t_0)) end
code[x_] := Block[{t$95$0 = N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(Pi * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Power[t$95$0, 1/3], $MachinePrecision]}, N[(N[(t$95$1 * t$95$1 + (-N[Power[N[(N[ArcSin[N[(N[(x * x + -1.0), $MachinePrecision] / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision])), $MachinePrecision] + N[((-t$95$2) * N[Power[t$95$2, 2.0], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
t_1 := \sqrt{\pi \cdot 0.5}\\
t_2 := \sqrt[3]{t\_0}\\
\mathsf{fma}\left(t\_1, t\_1, -\sqrt[3]{\sin^{-1} \left(\frac{\mathsf{fma}\left(x, x, -1\right)}{-1 - x}\right) \cdot {t\_0}^{2}}\right) + \mathsf{fma}\left(-t\_2, {t\_2}^{2}, t\_0\right)
\end{array}
\end{array}
Initial program 4.9%
acos-asin4.9%
add-sqr-sqrt3.0%
add-cube-cbrt8.7%
prod-diff8.7%
Applied egg-rr8.7%
flip--8.8%
div-inv8.8%
metadata-eval8.8%
pow28.8%
Applied egg-rr8.8%
associate-*r/8.8%
*-rgt-identity8.8%
remove-double-neg8.8%
distribute-frac-neg8.8%
distribute-frac-neg28.8%
sub-neg8.8%
+-commutative8.8%
distribute-neg-in8.8%
unpow28.8%
sqr-neg8.8%
unpow28.8%
remove-double-neg8.8%
sub-neg8.8%
unpow28.8%
sqr-neg8.8%
fmm-def8.8%
metadata-eval8.8%
distribute-neg-in8.8%
metadata-eval8.8%
unsub-neg8.8%
Simplified8.8%
Taylor expanded in x around 0 3.1%
Simplified3.1%
Taylor expanded in x around 0 8.8%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (* PI 0.5))) (t_1 (asin (- 1.0 x))))
(+
(fma
t_0
t_0
(* (pow (cbrt t_1) 2.0) (- (cbrt (asin (/ (fma x x -1.0) (- -1.0 x)))))))
(* t_1 0.0))))
double code(double x) {
double t_0 = sqrt((((double) M_PI) * 0.5));
double t_1 = asin((1.0 - x));
return fma(t_0, t_0, (pow(cbrt(t_1), 2.0) * -cbrt(asin((fma(x, x, -1.0) / (-1.0 - x)))))) + (t_1 * 0.0);
}
function code(x) t_0 = sqrt(Float64(pi * 0.5)) t_1 = asin(Float64(1.0 - x)) return Float64(fma(t_0, t_0, Float64((cbrt(t_1) ^ 2.0) * Float64(-cbrt(asin(Float64(fma(x, x, -1.0) / Float64(-1.0 - x))))))) + Float64(t_1 * 0.0)) end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(Pi * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, N[(N[(t$95$0 * t$95$0 + N[(N[Power[N[Power[t$95$1, 1/3], $MachinePrecision], 2.0], $MachinePrecision] * (-N[Power[N[ArcSin[N[(N[(x * x + -1.0), $MachinePrecision] / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision])), $MachinePrecision]), $MachinePrecision] + N[(t$95$1 * 0.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\pi \cdot 0.5}\\
t_1 := \sin^{-1} \left(1 - x\right)\\
\mathsf{fma}\left(t\_0, t\_0, {\left(\sqrt[3]{t\_1}\right)}^{2} \cdot \left(-\sqrt[3]{\sin^{-1} \left(\frac{\mathsf{fma}\left(x, x, -1\right)}{-1 - x}\right)}\right)\right) + t\_1 \cdot 0
\end{array}
\end{array}
Initial program 4.9%
acos-asin4.9%
add-sqr-sqrt3.0%
add-cube-cbrt8.7%
prod-diff8.7%
Applied egg-rr8.7%
flip--8.8%
div-inv8.8%
metadata-eval8.8%
pow28.8%
Applied egg-rr8.8%
associate-*r/8.8%
*-rgt-identity8.8%
remove-double-neg8.8%
distribute-frac-neg8.8%
distribute-frac-neg28.8%
sub-neg8.8%
+-commutative8.8%
distribute-neg-in8.8%
unpow28.8%
sqr-neg8.8%
unpow28.8%
remove-double-neg8.8%
sub-neg8.8%
unpow28.8%
sqr-neg8.8%
fmm-def8.8%
metadata-eval8.8%
distribute-neg-in8.8%
metadata-eval8.8%
unsub-neg8.8%
Simplified8.8%
fma-undefine8.7%
distribute-lft-neg-in8.7%
neg-mul-18.7%
unpow28.7%
rem-3cbrt-rft3.1%
unpow23.1%
rem-3cbrt-rft8.7%
*-un-lft-identity8.7%
distribute-rgt-out8.7%
metadata-eval8.7%
Applied egg-rr8.7%
Final simplification8.7%
(FPCore (x)
:precision binary64
(let* ((t_0 (asin (- 1.0 x))))
(-
(+ (* t_0 0.0) (* PI (pow (sqrt 0.5) 2.0)))
(cbrt (* (asin (/ (fma x x -1.0) (- -1.0 x))) (pow t_0 2.0))))))
double code(double x) {
double t_0 = asin((1.0 - x));
return ((t_0 * 0.0) + (((double) M_PI) * pow(sqrt(0.5), 2.0))) - cbrt((asin((fma(x, x, -1.0) / (-1.0 - x))) * pow(t_0, 2.0)));
}
function code(x) t_0 = asin(Float64(1.0 - x)) return Float64(Float64(Float64(t_0 * 0.0) + Float64(pi * (sqrt(0.5) ^ 2.0))) - cbrt(Float64(asin(Float64(fma(x, x, -1.0) / Float64(-1.0 - x))) * (t_0 ^ 2.0)))) end
code[x_] := Block[{t$95$0 = N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[(t$95$0 * 0.0), $MachinePrecision] + N[(Pi * N[Power[N[Sqrt[0.5], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Power[N[(N[ArcSin[N[(N[(x * x + -1.0), $MachinePrecision] / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
\left(t\_0 \cdot 0 + \pi \cdot {\left(\sqrt{0.5}\right)}^{2}\right) - \sqrt[3]{\sin^{-1} \left(\frac{\mathsf{fma}\left(x, x, -1\right)}{-1 - x}\right) \cdot {t\_0}^{2}}
\end{array}
\end{array}
Initial program 4.9%
acos-asin4.9%
add-sqr-sqrt3.0%
add-cube-cbrt8.7%
prod-diff8.7%
Applied egg-rr8.7%
flip--8.8%
div-inv8.8%
metadata-eval8.8%
pow28.8%
Applied egg-rr8.8%
associate-*r/8.8%
*-rgt-identity8.8%
remove-double-neg8.8%
distribute-frac-neg8.8%
distribute-frac-neg28.8%
sub-neg8.8%
+-commutative8.8%
distribute-neg-in8.8%
unpow28.8%
sqr-neg8.8%
unpow28.8%
remove-double-neg8.8%
sub-neg8.8%
unpow28.8%
sqr-neg8.8%
fmm-def8.8%
metadata-eval8.8%
distribute-neg-in8.8%
metadata-eval8.8%
unsub-neg8.8%
Simplified8.8%
Taylor expanded in x around 0 3.1%
Simplified3.1%
Taylor expanded in x around 0 8.7%
fma-define8.7%
sub-neg8.7%
mul-1-neg8.7%
fma-define8.7%
sub-neg8.7%
mul-1-neg8.7%
Simplified8.7%
Final simplification8.7%
(FPCore (x) :precision binary64 (let* ((t_0 (asin (- 1.0 x))) (t_1 (sqrt t_0))) (+ (acos (- 1.0 x)) (fma (- t_1) t_1 t_0))))
double code(double x) {
double t_0 = asin((1.0 - x));
double t_1 = sqrt(t_0);
return acos((1.0 - x)) + fma(-t_1, t_1, t_0);
}
function code(x) t_0 = asin(Float64(1.0 - x)) t_1 = sqrt(t_0) return Float64(acos(Float64(1.0 - x)) + fma(Float64(-t_1), t_1, t_0)) end
code[x_] := Block[{t$95$0 = N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[t$95$0], $MachinePrecision]}, N[(N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision] + N[((-t$95$1) * t$95$1 + t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
t_1 := \sqrt{t\_0}\\
\cos^{-1} \left(1 - x\right) + \mathsf{fma}\left(-t\_1, t\_1, t\_0\right)
\end{array}
\end{array}
Initial program 4.9%
acos-asin4.9%
*-un-lft-identity4.9%
add-sqr-sqrt8.7%
prod-diff8.7%
add-sqr-sqrt8.7%
fmm-def8.7%
*-un-lft-identity8.7%
acos-asin8.7%
add-sqr-sqrt8.7%
Applied egg-rr8.7%
(FPCore (x) :precision binary64 (- (* PI (pow (sqrt 0.5) 2.0)) (asin (- 1.0 x))))
double code(double x) {
return (((double) M_PI) * pow(sqrt(0.5), 2.0)) - asin((1.0 - x));
}
public static double code(double x) {
return (Math.PI * Math.pow(Math.sqrt(0.5), 2.0)) - Math.asin((1.0 - x));
}
def code(x): return (math.pi * math.pow(math.sqrt(0.5), 2.0)) - math.asin((1.0 - x))
function code(x) return Float64(Float64(pi * (sqrt(0.5) ^ 2.0)) - asin(Float64(1.0 - x))) end
function tmp = code(x) tmp = (pi * (sqrt(0.5) ^ 2.0)) - asin((1.0 - x)); end
code[x_] := N[(N[(Pi * N[Power[N[Sqrt[0.5], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] - N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\pi \cdot {\left(\sqrt{0.5}\right)}^{2} - \sin^{-1} \left(1 - x\right)
\end{array}
Initial program 4.9%
acos-asin4.9%
add-sqr-sqrt3.0%
add-cube-cbrt8.7%
prod-diff8.7%
Applied egg-rr8.7%
Taylor expanded in x around 0 8.7%
Simplified8.7%
(FPCore (x) :precision binary64 (acos x))
double code(double x) {
return acos(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = acos(x)
end function
public static double code(double x) {
return Math.acos(x);
}
def code(x): return math.acos(x)
function code(x) return acos(x) end
function tmp = code(x) tmp = acos(x); end
code[x_] := N[ArcCos[x], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} x
\end{array}
Initial program 4.9%
Taylor expanded in x around inf 6.8%
neg-mul-16.8%
Simplified6.8%
*-un-lft-identity6.8%
add-sqr-sqrt0.0%
sqrt-unprod6.8%
sqr-neg6.8%
sqrt-unprod6.8%
add-sqr-sqrt6.8%
Applied egg-rr6.8%
*-lft-identity6.8%
Simplified6.8%
(FPCore (x) :precision binary64 (acos 1.0))
double code(double x) {
return acos(1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = acos(1.0d0)
end function
public static double code(double x) {
return Math.acos(1.0);
}
def code(x): return math.acos(1.0)
function code(x) return acos(1.0) end
function tmp = code(x) tmp = acos(1.0); end
code[x_] := N[ArcCos[1.0], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} 1
\end{array}
Initial program 4.9%
Taylor expanded in x around 0 3.8%
(FPCore (x) :precision binary64 (* 2.0 (asin (sqrt (/ x 2.0)))))
double code(double x) {
return 2.0 * asin(sqrt((x / 2.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 * asin(sqrt((x / 2.0d0)))
end function
public static double code(double x) {
return 2.0 * Math.asin(Math.sqrt((x / 2.0)));
}
def code(x): return 2.0 * math.asin(math.sqrt((x / 2.0)))
function code(x) return Float64(2.0 * asin(sqrt(Float64(x / 2.0)))) end
function tmp = code(x) tmp = 2.0 * asin(sqrt((x / 2.0))); end
code[x_] := N[(2.0 * N[ArcSin[N[Sqrt[N[(x / 2.0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \sin^{-1} \left(\sqrt{\frac{x}{2}}\right)
\end{array}
herbie shell --seed 2024181
(FPCore (x)
:name "bug323 (missed optimization)"
:precision binary64
:pre (and (<= 0.0 x) (<= x 0.5))
:alt
(! :herbie-platform default (* 2 (asin (sqrt (/ x 2)))))
(acos (- 1.0 x)))