
(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 13 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 (asin (- 1.0 x))) (t_1 (cbrt t_0)))
(+
(fma PI 0.5 (* t_1 (- (pow (cbrt (- (* PI 0.5) (acos (- 1.0 x)))) 2.0))))
(fma (- (cbrt (pow (sqrt t_0) 2.0))) (pow t_1 2.0) (pow t_1 3.0)))))
double code(double x) {
double t_0 = asin((1.0 - x));
double t_1 = cbrt(t_0);
return fma(((double) M_PI), 0.5, (t_1 * -pow(cbrt(((((double) M_PI) * 0.5) - acos((1.0 - x)))), 2.0))) + fma(-cbrt(pow(sqrt(t_0), 2.0)), pow(t_1, 2.0), pow(t_1, 3.0));
}
function code(x) t_0 = asin(Float64(1.0 - x)) t_1 = cbrt(t_0) return Float64(fma(pi, 0.5, Float64(t_1 * Float64(-(cbrt(Float64(Float64(pi * 0.5) - acos(Float64(1.0 - x)))) ^ 2.0)))) + fma(Float64(-cbrt((sqrt(t_0) ^ 2.0))), (t_1 ^ 2.0), (t_1 ^ 3.0))) end
code[x_] := Block[{t$95$0 = N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Power[t$95$0, 1/3], $MachinePrecision]}, N[(N[(Pi * 0.5 + N[(t$95$1 * (-N[Power[N[Power[N[(N[(Pi * 0.5), $MachinePrecision] - N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], 2.0], $MachinePrecision])), $MachinePrecision]), $MachinePrecision] + N[((-N[Power[N[Power[N[Sqrt[t$95$0], $MachinePrecision], 2.0], $MachinePrecision], 1/3], $MachinePrecision]) * N[Power[t$95$1, 2.0], $MachinePrecision] + N[Power[t$95$1, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
t_1 := \sqrt[3]{t\_0}\\
\mathsf{fma}\left(\pi, 0.5, t\_1 \cdot \left(-{\left(\sqrt[3]{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right)\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{t\_0}\right)}^{2}}, {t\_1}^{2}, {t\_1}^{3}\right)
\end{array}
\end{array}
Initial program 7.4%
acos-asin7.4%
div-inv7.4%
metadata-eval7.4%
add-cube-cbrt10.9%
prod-diff10.9%
pow210.9%
pow210.9%
Applied egg-rr10.9%
add-sqr-sqrt10.9%
pow210.9%
Applied egg-rr10.9%
asin-acos10.9%
div-inv10.9%
metadata-eval10.9%
Applied egg-rr10.9%
unpow210.9%
cube-unmult10.9%
Applied egg-rr10.9%
Final simplification10.9%
(FPCore (x)
:precision binary64
(let* ((t_0 (acos (- 1.0 x))) (t_1 (asin (- 1.0 x))) (t_2 (cbrt t_1)))
(+
(fma PI 0.5 (* t_2 (- (pow (cbrt (- (* PI 0.5) t_0)) 2.0))))
(fma (- (cbrt (pow (sqrt t_1) 2.0))) (pow t_2 2.0) (- (/ PI 2.0) t_0)))))
double code(double x) {
double t_0 = acos((1.0 - x));
double t_1 = asin((1.0 - x));
double t_2 = cbrt(t_1);
return fma(((double) M_PI), 0.5, (t_2 * -pow(cbrt(((((double) M_PI) * 0.5) - t_0)), 2.0))) + fma(-cbrt(pow(sqrt(t_1), 2.0)), pow(t_2, 2.0), ((((double) M_PI) / 2.0) - t_0));
}
function code(x) t_0 = acos(Float64(1.0 - x)) t_1 = asin(Float64(1.0 - x)) t_2 = cbrt(t_1) return Float64(fma(pi, 0.5, Float64(t_2 * Float64(-(cbrt(Float64(Float64(pi * 0.5) - t_0)) ^ 2.0)))) + fma(Float64(-cbrt((sqrt(t_1) ^ 2.0))), (t_2 ^ 2.0), Float64(Float64(pi / 2.0) - t_0))) end
code[x_] := Block[{t$95$0 = N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Power[t$95$1, 1/3], $MachinePrecision]}, N[(N[(Pi * 0.5 + N[(t$95$2 * (-N[Power[N[Power[N[(N[(Pi * 0.5), $MachinePrecision] - t$95$0), $MachinePrecision], 1/3], $MachinePrecision], 2.0], $MachinePrecision])), $MachinePrecision]), $MachinePrecision] + N[((-N[Power[N[Power[N[Sqrt[t$95$1], $MachinePrecision], 2.0], $MachinePrecision], 1/3], $MachinePrecision]) * N[Power[t$95$2, 2.0], $MachinePrecision] + N[(N[(Pi / 2.0), $MachinePrecision] - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos^{-1} \left(1 - x\right)\\
t_1 := \sin^{-1} \left(1 - x\right)\\
t_2 := \sqrt[3]{t\_1}\\
\mathsf{fma}\left(\pi, 0.5, t\_2 \cdot \left(-{\left(\sqrt[3]{\pi \cdot 0.5 - t\_0}\right)}^{2}\right)\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{t\_1}\right)}^{2}}, {t\_2}^{2}, \frac{\pi}{2} - t\_0\right)
\end{array}
\end{array}
Initial program 7.4%
acos-asin7.4%
div-inv7.4%
metadata-eval7.4%
add-cube-cbrt10.9%
prod-diff10.9%
pow210.9%
pow210.9%
Applied egg-rr10.9%
add-sqr-sqrt10.9%
pow210.9%
Applied egg-rr10.9%
asin-acos10.9%
div-inv10.9%
metadata-eval10.9%
Applied egg-rr10.9%
unpow210.9%
rem-3cbrt-rft10.9%
asin-acos10.9%
Applied egg-rr10.9%
Final simplification10.9%
(FPCore (x)
:precision binary64
(let* ((t_0 (asin (- 1.0 x))) (t_1 (cbrt t_0)))
(+
(fma PI 0.5 (* t_1 (- (pow (cbrt (- (* PI 0.5) (acos (- 1.0 x)))) 2.0))))
(fma (- (cbrt (pow (sqrt t_0) 2.0))) (pow t_1 2.0) t_0))))
double code(double x) {
double t_0 = asin((1.0 - x));
double t_1 = cbrt(t_0);
return fma(((double) M_PI), 0.5, (t_1 * -pow(cbrt(((((double) M_PI) * 0.5) - acos((1.0 - x)))), 2.0))) + fma(-cbrt(pow(sqrt(t_0), 2.0)), pow(t_1, 2.0), t_0);
}
function code(x) t_0 = asin(Float64(1.0 - x)) t_1 = cbrt(t_0) return Float64(fma(pi, 0.5, Float64(t_1 * Float64(-(cbrt(Float64(Float64(pi * 0.5) - acos(Float64(1.0 - x)))) ^ 2.0)))) + fma(Float64(-cbrt((sqrt(t_0) ^ 2.0))), (t_1 ^ 2.0), t_0)) end
code[x_] := Block[{t$95$0 = N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Power[t$95$0, 1/3], $MachinePrecision]}, N[(N[(Pi * 0.5 + N[(t$95$1 * (-N[Power[N[Power[N[(N[(Pi * 0.5), $MachinePrecision] - N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], 2.0], $MachinePrecision])), $MachinePrecision]), $MachinePrecision] + N[((-N[Power[N[Power[N[Sqrt[t$95$0], $MachinePrecision], 2.0], $MachinePrecision], 1/3], $MachinePrecision]) * N[Power[t$95$1, 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[3]{t\_0}\\
\mathsf{fma}\left(\pi, 0.5, t\_1 \cdot \left(-{\left(\sqrt[3]{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right)\right) + \mathsf{fma}\left(-\sqrt[3]{{\left(\sqrt{t\_0}\right)}^{2}}, {t\_1}^{2}, t\_0\right)
\end{array}
\end{array}
Initial program 7.4%
acos-asin7.4%
div-inv7.4%
metadata-eval7.4%
add-cube-cbrt10.9%
prod-diff10.9%
pow210.9%
pow210.9%
Applied egg-rr10.9%
add-sqr-sqrt10.9%
pow210.9%
Applied egg-rr10.9%
asin-acos10.9%
div-inv10.9%
metadata-eval10.9%
Applied egg-rr10.9%
Taylor expanded in x around 0 10.9%
Final simplification10.9%
(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 (cbrt (pow t_0 3.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, cbrt(pow(t_0, 3.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, cbrt((t_0 ^ 3.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 + N[Power[N[Power[t$95$0, 3.0], $MachinePrecision], 1/3], $MachinePrecision]), $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, \sqrt[3]{{t\_0}^{3}}\right)
\end{array}
\end{array}
Initial program 7.4%
acos-asin7.4%
*-un-lft-identity7.4%
add-sqr-sqrt10.8%
prod-diff10.8%
add-sqr-sqrt10.9%
fma-neg10.9%
*-un-lft-identity10.9%
acos-asin10.9%
add-sqr-sqrt10.8%
Applied egg-rr10.8%
add-cbrt-cube10.9%
pow310.9%
Applied egg-rr10.9%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (* PI 0.5))))
(+
(*
(pow (cbrt (+ 1.0 (fma t_0 t_0 (- (asin (- 1.0 x)))))) 2.0)
(cbrt (+ 1.0 (acos (- 1.0 x)))))
-1.0)))
double code(double x) {
double t_0 = sqrt((((double) M_PI) * 0.5));
return (pow(cbrt((1.0 + fma(t_0, t_0, -asin((1.0 - x))))), 2.0) * cbrt((1.0 + acos((1.0 - x))))) + -1.0;
}
function code(x) t_0 = sqrt(Float64(pi * 0.5)) return Float64(Float64((cbrt(Float64(1.0 + fma(t_0, t_0, Float64(-asin(Float64(1.0 - x)))))) ^ 2.0) * cbrt(Float64(1.0 + acos(Float64(1.0 - x))))) + -1.0) end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(Pi * 0.5), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[Power[N[Power[N[(1.0 + N[(t$95$0 * t$95$0 + (-N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], 2.0], $MachinePrecision] * N[Power[N[(1.0 + N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\pi \cdot 0.5}\\
{\left(\sqrt[3]{1 + \mathsf{fma}\left(t\_0, t\_0, -\sin^{-1} \left(1 - x\right)\right)}\right)}^{2} \cdot \sqrt[3]{1 + \cos^{-1} \left(1 - x\right)} + -1
\end{array}
\end{array}
Initial program 7.4%
expm1-log1p-u7.4%
expm1-undefine7.4%
log1p-undefine7.4%
rem-exp-log7.4%
Applied egg-rr7.4%
add-cube-cbrt7.4%
pow27.4%
Applied egg-rr7.4%
acos-asin7.4%
add-sqr-sqrt10.9%
fma-neg10.9%
div-inv10.9%
metadata-eval10.9%
div-inv10.9%
metadata-eval10.9%
Applied egg-rr10.9%
Final simplification10.9%
(FPCore (x) :precision binary64 (fma PI 0.5 (* (cbrt (asin (- 1.0 x))) (- (pow (cbrt (- (* PI 0.5) (acos (- 1.0 x)))) 2.0)))))
double code(double x) {
return fma(((double) M_PI), 0.5, (cbrt(asin((1.0 - x))) * -pow(cbrt(((((double) M_PI) * 0.5) - acos((1.0 - x)))), 2.0)));
}
function code(x) return fma(pi, 0.5, Float64(cbrt(asin(Float64(1.0 - x))) * Float64(-(cbrt(Float64(Float64(pi * 0.5) - acos(Float64(1.0 - x)))) ^ 2.0)))) end
code[x_] := N[(Pi * 0.5 + N[(N[Power[N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision] * (-N[Power[N[Power[N[(N[(Pi * 0.5), $MachinePrecision] - N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], 2.0], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\pi, 0.5, \sqrt[3]{\sin^{-1} \left(1 - x\right)} \cdot \left(-{\left(\sqrt[3]{\pi \cdot 0.5 - \cos^{-1} \left(1 - x\right)}\right)}^{2}\right)\right)
\end{array}
Initial program 7.4%
acos-asin7.4%
div-inv7.4%
metadata-eval7.4%
add-cube-cbrt10.9%
prod-diff10.9%
pow210.9%
pow210.9%
Applied egg-rr10.9%
add-sqr-sqrt10.9%
pow210.9%
Applied egg-rr10.9%
asin-acos10.9%
div-inv10.9%
metadata-eval10.9%
Applied egg-rr10.9%
Taylor expanded in x around 0 10.9%
distribute-rgt1-in10.9%
metadata-eval10.9%
sub-neg10.9%
mul-1-neg10.9%
mul0-lft10.9%
Simplified10.9%
Final simplification10.9%
(FPCore (x) :precision binary64 (let* ((t_0 (cbrt (asin (- 1.0 x))))) (fma PI 0.5 (* t_0 (- (pow t_0 2.0))))))
double code(double x) {
double t_0 = cbrt(asin((1.0 - x)));
return fma(((double) M_PI), 0.5, (t_0 * -pow(t_0, 2.0)));
}
function code(x) t_0 = cbrt(asin(Float64(1.0 - x))) return fma(pi, 0.5, Float64(t_0 * Float64(-(t_0 ^ 2.0)))) end
code[x_] := Block[{t$95$0 = N[Power[N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision]}, N[(Pi * 0.5 + N[(t$95$0 * (-N[Power[t$95$0, 2.0], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{\sin^{-1} \left(1 - x\right)}\\
\mathsf{fma}\left(\pi, 0.5, t\_0 \cdot \left(-{t\_0}^{2}\right)\right)
\end{array}
\end{array}
Initial program 7.4%
acos-asin7.4%
div-inv7.4%
metadata-eval7.4%
add-cube-cbrt10.9%
prod-diff10.9%
pow210.9%
pow210.9%
Applied egg-rr10.9%
Taylor expanded in x around 0 10.9%
Simplified10.9%
Final simplification10.9%
(FPCore (x) :precision binary64 (let* ((t_0 (acos (- 1.0 x)))) (if (<= t_0 0.0) (acos x) (+ (pow (hypot 1.0 (sqrt t_0)) 2.0) -1.0))))
double code(double x) {
double t_0 = acos((1.0 - x));
double tmp;
if (t_0 <= 0.0) {
tmp = acos(x);
} else {
tmp = pow(hypot(1.0, sqrt(t_0)), 2.0) + -1.0;
}
return tmp;
}
public static double code(double x) {
double t_0 = Math.acos((1.0 - x));
double tmp;
if (t_0 <= 0.0) {
tmp = Math.acos(x);
} else {
tmp = Math.pow(Math.hypot(1.0, Math.sqrt(t_0)), 2.0) + -1.0;
}
return tmp;
}
def code(x): t_0 = math.acos((1.0 - x)) tmp = 0 if t_0 <= 0.0: tmp = math.acos(x) else: tmp = math.pow(math.hypot(1.0, math.sqrt(t_0)), 2.0) + -1.0 return tmp
function code(x) t_0 = acos(Float64(1.0 - x)) tmp = 0.0 if (t_0 <= 0.0) tmp = acos(x); else tmp = Float64((hypot(1.0, sqrt(t_0)) ^ 2.0) + -1.0); end return tmp end
function tmp_2 = code(x) t_0 = acos((1.0 - x)); tmp = 0.0; if (t_0 <= 0.0) tmp = acos(x); else tmp = (hypot(1.0, sqrt(t_0)) ^ 2.0) + -1.0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], N[ArcCos[x], $MachinePrecision], N[(N[Power[N[Sqrt[1.0 ^ 2 + N[Sqrt[t$95$0], $MachinePrecision] ^ 2], $MachinePrecision], 2.0], $MachinePrecision] + -1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos^{-1} \left(1 - x\right)\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;\cos^{-1} x\\
\mathbf{else}:\\
\;\;\;\;{\left(\mathsf{hypot}\left(1, \sqrt{t\_0}\right)\right)}^{2} + -1\\
\end{array}
\end{array}
if (acos.f64 (-.f64 #s(literal 1 binary64) x)) < 0.0Initial program 3.9%
Taylor expanded in x around inf 6.5%
neg-mul-16.5%
Simplified6.5%
*-un-lft-identity6.5%
add-sqr-sqrt0.0%
sqrt-unprod6.5%
sqr-neg6.5%
sqrt-unprod6.5%
add-sqr-sqrt6.5%
Applied egg-rr6.5%
*-lft-identity6.5%
Simplified6.5%
if 0.0 < (acos.f64 (-.f64 #s(literal 1 binary64) x)) Initial program 69.2%
expm1-log1p-u69.2%
expm1-undefine69.2%
log1p-undefine69.2%
rem-exp-log69.2%
Applied egg-rr69.2%
add-sqr-sqrt69.1%
pow269.1%
rem-cbrt-cube69.1%
unpow1/369.3%
add-sqr-sqrt69.3%
hypot-1-def69.4%
unpow1/369.4%
rem-cbrt-cube69.4%
Applied egg-rr69.4%
Final simplification10.0%
(FPCore (x) :precision binary64 (let* ((t_0 (acos (- 1.0 x)))) (if (<= t_0 0.0) (acos x) (+ (+ 1.0 (log (exp t_0))) -1.0))))
double code(double x) {
double t_0 = acos((1.0 - x));
double tmp;
if (t_0 <= 0.0) {
tmp = acos(x);
} else {
tmp = (1.0 + log(exp(t_0))) + -1.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = acos((1.0d0 - x))
if (t_0 <= 0.0d0) then
tmp = acos(x)
else
tmp = (1.0d0 + log(exp(t_0))) + (-1.0d0)
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.acos((1.0 - x));
double tmp;
if (t_0 <= 0.0) {
tmp = Math.acos(x);
} else {
tmp = (1.0 + Math.log(Math.exp(t_0))) + -1.0;
}
return tmp;
}
def code(x): t_0 = math.acos((1.0 - x)) tmp = 0 if t_0 <= 0.0: tmp = math.acos(x) else: tmp = (1.0 + math.log(math.exp(t_0))) + -1.0 return tmp
function code(x) t_0 = acos(Float64(1.0 - x)) tmp = 0.0 if (t_0 <= 0.0) tmp = acos(x); else tmp = Float64(Float64(1.0 + log(exp(t_0))) + -1.0); end return tmp end
function tmp_2 = code(x) t_0 = acos((1.0 - x)); tmp = 0.0; if (t_0 <= 0.0) tmp = acos(x); else tmp = (1.0 + log(exp(t_0))) + -1.0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], N[ArcCos[x], $MachinePrecision], N[(N[(1.0 + N[Log[N[Exp[t$95$0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos^{-1} \left(1 - x\right)\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;\cos^{-1} x\\
\mathbf{else}:\\
\;\;\;\;\left(1 + \log \left(e^{t\_0}\right)\right) + -1\\
\end{array}
\end{array}
if (acos.f64 (-.f64 #s(literal 1 binary64) x)) < 0.0Initial program 3.9%
Taylor expanded in x around inf 6.5%
neg-mul-16.5%
Simplified6.5%
*-un-lft-identity6.5%
add-sqr-sqrt0.0%
sqrt-unprod6.5%
sqr-neg6.5%
sqrt-unprod6.5%
add-sqr-sqrt6.5%
Applied egg-rr6.5%
*-lft-identity6.5%
Simplified6.5%
if 0.0 < (acos.f64 (-.f64 #s(literal 1 binary64) x)) Initial program 69.2%
expm1-log1p-u69.2%
expm1-undefine69.2%
log1p-undefine69.2%
rem-exp-log69.2%
Applied egg-rr69.2%
add-log-exp69.4%
Applied egg-rr69.4%
Final simplification10.0%
(FPCore (x) :precision binary64 (if (<= (- 1.0 x) 1.0) (acos (exp (log1p (- x)))) (acos x)))
double code(double x) {
double tmp;
if ((1.0 - x) <= 1.0) {
tmp = acos(exp(log1p(-x)));
} else {
tmp = acos(x);
}
return tmp;
}
public static double code(double x) {
double tmp;
if ((1.0 - x) <= 1.0) {
tmp = Math.acos(Math.exp(Math.log1p(-x)));
} else {
tmp = Math.acos(x);
}
return tmp;
}
def code(x): tmp = 0 if (1.0 - x) <= 1.0: tmp = math.acos(math.exp(math.log1p(-x))) else: tmp = math.acos(x) return tmp
function code(x) tmp = 0.0 if (Float64(1.0 - x) <= 1.0) tmp = acos(exp(log1p(Float64(-x)))); else tmp = acos(x); end return tmp end
code[x_] := If[LessEqual[N[(1.0 - x), $MachinePrecision], 1.0], N[ArcCos[N[Exp[N[Log[1 + (-x)], $MachinePrecision]], $MachinePrecision]], $MachinePrecision], N[ArcCos[x], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - x \leq 1:\\
\;\;\;\;\cos^{-1} \left(e^{\mathsf{log1p}\left(-x\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\cos^{-1} x\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) x) < 1Initial program 7.4%
add-exp-log7.4%
sub-neg7.4%
log1p-define7.4%
Applied egg-rr7.4%
if 1 < (-.f64 #s(literal 1 binary64) x) Initial program 7.4%
Taylor expanded in x around inf 6.9%
neg-mul-16.9%
Simplified6.9%
*-un-lft-identity6.9%
add-sqr-sqrt0.0%
sqrt-unprod6.9%
sqr-neg6.9%
sqrt-unprod6.9%
add-sqr-sqrt6.9%
Applied egg-rr6.9%
*-lft-identity6.9%
Simplified6.9%
(FPCore (x) :precision binary64 (if (<= (- 1.0 x) 1.0) (acos (- 1.0 x)) (acos x)))
double code(double x) {
double tmp;
if ((1.0 - x) <= 1.0) {
tmp = acos((1.0 - x));
} else {
tmp = acos(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((1.0d0 - x) <= 1.0d0) then
tmp = acos((1.0d0 - x))
else
tmp = acos(x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((1.0 - x) <= 1.0) {
tmp = Math.acos((1.0 - x));
} else {
tmp = Math.acos(x);
}
return tmp;
}
def code(x): tmp = 0 if (1.0 - x) <= 1.0: tmp = math.acos((1.0 - x)) else: tmp = math.acos(x) return tmp
function code(x) tmp = 0.0 if (Float64(1.0 - x) <= 1.0) tmp = acos(Float64(1.0 - x)); else tmp = acos(x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((1.0 - x) <= 1.0) tmp = acos((1.0 - x)); else tmp = acos(x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(1.0 - x), $MachinePrecision], 1.0], N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision], N[ArcCos[x], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - x \leq 1:\\
\;\;\;\;\cos^{-1} \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;\cos^{-1} x\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) x) < 1Initial program 7.4%
if 1 < (-.f64 #s(literal 1 binary64) x) Initial program 7.4%
Taylor expanded in x around inf 6.9%
neg-mul-16.9%
Simplified6.9%
*-un-lft-identity6.9%
add-sqr-sqrt0.0%
sqrt-unprod6.9%
sqr-neg6.9%
sqrt-unprod6.9%
add-sqr-sqrt6.9%
Applied egg-rr6.9%
*-lft-identity6.9%
Simplified6.9%
(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 7.4%
Taylor expanded in x around inf 6.9%
neg-mul-16.9%
Simplified6.9%
*-un-lft-identity6.9%
add-sqr-sqrt0.0%
sqrt-unprod6.9%
sqr-neg6.9%
sqrt-unprod6.9%
add-sqr-sqrt6.9%
Applied egg-rr6.9%
*-lft-identity6.9%
Simplified6.9%
(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 7.4%
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 2024135
(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)))