
(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 (pow t_0 3.0)))
(/
(/
(- (* (pow PI 6.0) 0.015625) (* t_1 t_1))
(+ (pow (* PI 0.5) 3.0) (pow (cbrt t_1) 3.0)))
(+ (* (* PI PI) 0.25) (* t_0 (fma PI 0.5 t_0))))))
double code(double x) {
double t_0 = asin((1.0 - x));
double t_1 = pow(t_0, 3.0);
return (((pow(((double) M_PI), 6.0) * 0.015625) - (t_1 * t_1)) / (pow((((double) M_PI) * 0.5), 3.0) + pow(cbrt(t_1), 3.0))) / (((((double) M_PI) * ((double) M_PI)) * 0.25) + (t_0 * fma(((double) M_PI), 0.5, t_0)));
}
function code(x) t_0 = asin(Float64(1.0 - x)) t_1 = t_0 ^ 3.0 return Float64(Float64(Float64(Float64((pi ^ 6.0) * 0.015625) - Float64(t_1 * t_1)) / Float64((Float64(pi * 0.5) ^ 3.0) + (cbrt(t_1) ^ 3.0))) / Float64(Float64(Float64(pi * pi) * 0.25) + Float64(t_0 * fma(pi, 0.5, 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, 3.0], $MachinePrecision]}, N[(N[(N[(N[(N[Power[Pi, 6.0], $MachinePrecision] * 0.015625), $MachinePrecision] - N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision] / N[(N[Power[N[(Pi * 0.5), $MachinePrecision], 3.0], $MachinePrecision] + N[Power[N[Power[t$95$1, 1/3], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(N[(Pi * Pi), $MachinePrecision] * 0.25), $MachinePrecision] + N[(t$95$0 * N[(Pi * 0.5 + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
t_1 := {t_0}^{3}\\
\frac{\frac{{\pi}^{6} \cdot 0.015625 - t_1 \cdot t_1}{{\left(\pi \cdot 0.5\right)}^{3} + {\left(\sqrt[3]{t_1}\right)}^{3}}}{\left(\pi \cdot \pi\right) \cdot 0.25 + t_0 \cdot \mathsf{fma}\left(\pi, 0.5, t_0\right)}
\end{array}
\end{array}
Initial program 7.1%
acos-asin7.1%
flip3--7.1%
div-inv7.1%
metadata-eval7.1%
div-inv7.1%
metadata-eval7.1%
div-inv7.1%
metadata-eval7.1%
div-inv7.1%
metadata-eval7.1%
Applied egg-rr7.1%
swap-sqr7.1%
metadata-eval7.1%
distribute-rgt-out7.1%
+-commutative7.1%
fma-def7.1%
Simplified7.1%
sub-neg7.1%
flip-+7.1%
pow-prod-up10.5%
metadata-eval10.5%
Applied egg-rr10.5%
rem-cbrt-cube10.5%
Applied egg-rr10.5%
cancel-sign-sub10.5%
unpow-prod-down10.5%
metadata-eval10.5%
Applied egg-rr10.5%
Final simplification10.5%
(FPCore (x)
:precision binary64
(let* ((t_0 (asin (- 1.0 x))) (t_1 (pow t_0 3.0)))
(/
(/ (- (* (pow PI 6.0) 0.015625) (* t_1 t_1)) (+ t_1 (pow (* PI 0.5) 3.0)))
(+ (* (* PI PI) 0.25) (* t_0 (fma PI 0.5 t_0))))))
double code(double x) {
double t_0 = asin((1.0 - x));
double t_1 = pow(t_0, 3.0);
return (((pow(((double) M_PI), 6.0) * 0.015625) - (t_1 * t_1)) / (t_1 + pow((((double) M_PI) * 0.5), 3.0))) / (((((double) M_PI) * ((double) M_PI)) * 0.25) + (t_0 * fma(((double) M_PI), 0.5, t_0)));
}
function code(x) t_0 = asin(Float64(1.0 - x)) t_1 = t_0 ^ 3.0 return Float64(Float64(Float64(Float64((pi ^ 6.0) * 0.015625) - Float64(t_1 * t_1)) / Float64(t_1 + (Float64(pi * 0.5) ^ 3.0))) / Float64(Float64(Float64(pi * pi) * 0.25) + Float64(t_0 * fma(pi, 0.5, 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, 3.0], $MachinePrecision]}, N[(N[(N[(N[(N[Power[Pi, 6.0], $MachinePrecision] * 0.015625), $MachinePrecision] - N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision] / N[(t$95$1 + N[Power[N[(Pi * 0.5), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(N[(Pi * Pi), $MachinePrecision] * 0.25), $MachinePrecision] + N[(t$95$0 * N[(Pi * 0.5 + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
t_1 := {t_0}^{3}\\
\frac{\frac{{\pi}^{6} \cdot 0.015625 - t_1 \cdot t_1}{t_1 + {\left(\pi \cdot 0.5\right)}^{3}}}{\left(\pi \cdot \pi\right) \cdot 0.25 + t_0 \cdot \mathsf{fma}\left(\pi, 0.5, t_0\right)}
\end{array}
\end{array}
Initial program 7.1%
acos-asin7.1%
flip3--7.1%
div-inv7.1%
metadata-eval7.1%
div-inv7.1%
metadata-eval7.1%
div-inv7.1%
metadata-eval7.1%
div-inv7.1%
metadata-eval7.1%
Applied egg-rr7.1%
swap-sqr7.1%
metadata-eval7.1%
distribute-rgt-out7.1%
+-commutative7.1%
fma-def7.1%
Simplified7.1%
sub-neg7.1%
flip-+7.1%
pow-prod-up10.5%
metadata-eval10.5%
Applied egg-rr10.5%
cancel-sign-sub10.5%
unpow-prod-down10.5%
metadata-eval10.5%
Applied egg-rr10.5%
Final simplification10.5%
(FPCore (x) :precision binary64 (let* ((t_0 (sqrt (asin (- 1.0 x))))) (+ (acos (- 1.0 x)) (fma (- t_0) t_0 (pow t_0 2.0)))))
double code(double x) {
double t_0 = sqrt(asin((1.0 - x)));
return acos((1.0 - x)) + fma(-t_0, t_0, pow(t_0, 2.0));
}
function code(x) t_0 = sqrt(asin(Float64(1.0 - x))) return Float64(acos(Float64(1.0 - x)) + fma(Float64(-t_0), t_0, (t_0 ^ 2.0))) end
code[x_] := Block[{t$95$0 = N[Sqrt[N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]}, N[(N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision] + N[((-t$95$0) * t$95$0 + N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\sin^{-1} \left(1 - x\right)}\\
\cos^{-1} \left(1 - x\right) + \mathsf{fma}\left(-t_0, t_0, {t_0}^{2}\right)
\end{array}
\end{array}
Initial program 7.1%
expm1-log1p-u7.1%
expm1-udef7.1%
log1p-udef7.1%
add-exp-log7.1%
Applied egg-rr7.1%
*-rgt-identity7.1%
add-exp-log7.1%
*-rgt-identity7.1%
log1p-udef7.1%
expm1-udef7.1%
expm1-log1p-u7.1%
acos-asin7.1%
div-inv7.1%
metadata-eval7.1%
add-sqr-sqrt10.4%
prod-diff10.4%
Applied egg-rr10.4%
add-sqr-sqrt10.4%
pow210.4%
Applied egg-rr10.4%
Final simplification10.4%
(FPCore (x) :precision binary64 (let* ((t_0 (sqrt (* PI 0.5)))) (- (/ PI 2.0) (fma t_0 t_0 (- (acos (- 1.0 x)))))))
double code(double x) {
double t_0 = sqrt((((double) M_PI) * 0.5));
return (((double) M_PI) / 2.0) - fma(t_0, t_0, -acos((1.0 - x)));
}
function code(x) t_0 = sqrt(Float64(pi * 0.5)) return Float64(Float64(pi / 2.0) - fma(t_0, t_0, Float64(-acos(Float64(1.0 - x))))) end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(Pi * 0.5), $MachinePrecision]], $MachinePrecision]}, N[(N[(Pi / 2.0), $MachinePrecision] - N[(t$95$0 * t$95$0 + (-N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\pi \cdot 0.5}\\
\frac{\pi}{2} - \mathsf{fma}\left(t_0, t_0, -\cos^{-1} \left(1 - x\right)\right)
\end{array}
\end{array}
Initial program 7.1%
add-cube-cbrt7.1%
pow37.1%
Applied egg-rr7.1%
add-log-exp7.1%
Applied egg-rr7.1%
unpow37.1%
add-log-exp7.1%
add-log-exp7.1%
add-log-exp7.1%
add-cube-cbrt7.1%
acos-asin7.1%
Applied egg-rr7.1%
asin-acos7.1%
div-inv7.1%
metadata-eval7.1%
add-sqr-sqrt10.4%
fma-neg10.4%
Applied egg-rr10.4%
Final simplification10.4%
(FPCore (x) :precision binary64 (exp (log (- (* PI 0.5) (pow (sqrt (asin (- 1.0 x))) 2.0)))))
double code(double x) {
return exp(log(((((double) M_PI) * 0.5) - pow(sqrt(asin((1.0 - x))), 2.0))));
}
public static double code(double x) {
return Math.exp(Math.log(((Math.PI * 0.5) - Math.pow(Math.sqrt(Math.asin((1.0 - x))), 2.0))));
}
def code(x): return math.exp(math.log(((math.pi * 0.5) - math.pow(math.sqrt(math.asin((1.0 - x))), 2.0))))
function code(x) return exp(log(Float64(Float64(pi * 0.5) - (sqrt(asin(Float64(1.0 - x))) ^ 2.0)))) end
function tmp = code(x) tmp = exp(log(((pi * 0.5) - (sqrt(asin((1.0 - x))) ^ 2.0)))); end
code[x_] := N[Exp[N[Log[N[(N[(Pi * 0.5), $MachinePrecision] - N[Power[N[Sqrt[N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\log \left(\pi \cdot 0.5 - {\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}\right)}
\end{array}
Initial program 7.1%
add-exp-log7.1%
Applied egg-rr7.1%
acos-asin7.1%
sub-neg7.1%
div-inv7.1%
metadata-eval7.1%
Applied egg-rr7.1%
sub-neg7.1%
Simplified7.1%
add-sqr-sqrt10.4%
pow210.4%
Applied egg-rr10.4%
Final simplification10.4%
(FPCore (x) :precision binary64 (- (/ PI 2.0) (pow (cbrt (asin (- 1.0 x))) 3.0)))
double code(double x) {
return (((double) M_PI) / 2.0) - pow(cbrt(asin((1.0 - x))), 3.0);
}
public static double code(double x) {
return (Math.PI / 2.0) - Math.pow(Math.cbrt(Math.asin((1.0 - x))), 3.0);
}
function code(x) return Float64(Float64(pi / 2.0) - (cbrt(asin(Float64(1.0 - x))) ^ 3.0)) end
code[x_] := N[(N[(Pi / 2.0), $MachinePrecision] - N[Power[N[Power[N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\pi}{2} - {\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{3}
\end{array}
Initial program 7.1%
add-cube-cbrt7.1%
pow37.1%
Applied egg-rr7.1%
add-log-exp7.1%
Applied egg-rr7.1%
unpow37.1%
add-log-exp7.1%
add-log-exp7.1%
add-log-exp7.1%
add-cube-cbrt7.1%
acos-asin7.1%
Applied egg-rr7.1%
add-cube-cbrt10.3%
pow310.3%
Applied egg-rr10.3%
Final simplification10.3%
(FPCore (x) :precision binary64 (- (/ PI 2.0) (pow (sqrt (asin (- 1.0 x))) 2.0)))
double code(double x) {
return (((double) M_PI) / 2.0) - pow(sqrt(asin((1.0 - x))), 2.0);
}
public static double code(double x) {
return (Math.PI / 2.0) - Math.pow(Math.sqrt(Math.asin((1.0 - x))), 2.0);
}
def code(x): return (math.pi / 2.0) - math.pow(math.sqrt(math.asin((1.0 - x))), 2.0)
function code(x) return Float64(Float64(pi / 2.0) - (sqrt(asin(Float64(1.0 - x))) ^ 2.0)) end
function tmp = code(x) tmp = (pi / 2.0) - (sqrt(asin((1.0 - x))) ^ 2.0); end
code[x_] := N[(N[(Pi / 2.0), $MachinePrecision] - N[Power[N[Sqrt[N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\pi}{2} - {\left(\sqrt{\sin^{-1} \left(1 - x\right)}\right)}^{2}
\end{array}
Initial program 7.1%
add-cube-cbrt7.1%
pow37.1%
Applied egg-rr7.1%
add-log-exp7.1%
Applied egg-rr7.1%
unpow37.1%
add-log-exp7.1%
add-log-exp7.1%
add-log-exp7.1%
add-cube-cbrt7.1%
acos-asin7.1%
Applied egg-rr7.1%
add-sqr-sqrt10.4%
pow210.4%
Applied egg-rr10.4%
Final simplification10.4%
(FPCore (x) :precision binary64 (if (<= (- 1.0 x) 1.0) (+ 1.0 (cbrt (pow (+ (acos (- 1.0 x)) -1.0) 3.0))) (hypot (* PI 0.5) (asin (- 1.0 x)))))
double code(double x) {
double tmp;
if ((1.0 - x) <= 1.0) {
tmp = 1.0 + cbrt(pow((acos((1.0 - x)) + -1.0), 3.0));
} else {
tmp = hypot((((double) M_PI) * 0.5), asin((1.0 - x)));
}
return tmp;
}
public static double code(double x) {
double tmp;
if ((1.0 - x) <= 1.0) {
tmp = 1.0 + Math.cbrt(Math.pow((Math.acos((1.0 - x)) + -1.0), 3.0));
} else {
tmp = Math.hypot((Math.PI * 0.5), Math.asin((1.0 - x)));
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(1.0 - x) <= 1.0) tmp = Float64(1.0 + cbrt((Float64(acos(Float64(1.0 - x)) + -1.0) ^ 3.0))); else tmp = hypot(Float64(pi * 0.5), asin(Float64(1.0 - x))); end return tmp end
code[x_] := If[LessEqual[N[(1.0 - x), $MachinePrecision], 1.0], N[(1.0 + N[Power[N[Power[N[(N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision] + -1.0), $MachinePrecision], 3.0], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(Pi * 0.5), $MachinePrecision] ^ 2 + N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - x \leq 1:\\
\;\;\;\;1 + \sqrt[3]{{\left(\cos^{-1} \left(1 - x\right) + -1\right)}^{3}}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(\pi \cdot 0.5, \sin^{-1} \left(1 - x\right)\right)\\
\end{array}
\end{array}
if (-.f64 1 x) < 1Initial program 7.1%
expm1-log1p-u7.1%
expm1-udef7.1%
log1p-udef7.1%
add-exp-log7.1%
Applied egg-rr7.1%
associate--l+7.1%
+-commutative7.1%
sub-neg7.1%
metadata-eval7.1%
Applied egg-rr7.1%
add-cbrt-cube7.1%
pow37.1%
Applied egg-rr7.1%
if 1 < (-.f64 1 x) Initial program 7.1%
add-cube-cbrt7.1%
pow37.1%
Applied egg-rr7.1%
add-log-exp7.1%
Applied egg-rr7.1%
unpow37.1%
add-log-exp7.1%
add-log-exp7.1%
add-log-exp7.1%
add-cube-cbrt7.1%
acos-asin7.1%
Applied egg-rr7.1%
div-inv7.1%
metadata-eval7.1%
add-sqr-sqrt7.1%
sqrt-unprod7.1%
flip3--7.1%
Applied egg-rr6.8%
Final simplification7.1%
(FPCore (x) :precision binary64 (let* ((t_0 (asin (- 1.0 x)))) (if (<= (- 1.0 x) 1.0) (- (* PI 0.5) t_0) (hypot (* PI 0.5) t_0))))
double code(double x) {
double t_0 = asin((1.0 - x));
double tmp;
if ((1.0 - x) <= 1.0) {
tmp = (((double) M_PI) * 0.5) - t_0;
} else {
tmp = hypot((((double) M_PI) * 0.5), t_0);
}
return tmp;
}
public static double code(double x) {
double t_0 = Math.asin((1.0 - x));
double tmp;
if ((1.0 - x) <= 1.0) {
tmp = (Math.PI * 0.5) - t_0;
} else {
tmp = Math.hypot((Math.PI * 0.5), t_0);
}
return tmp;
}
def code(x): t_0 = math.asin((1.0 - x)) tmp = 0 if (1.0 - x) <= 1.0: tmp = (math.pi * 0.5) - t_0 else: tmp = math.hypot((math.pi * 0.5), t_0) return tmp
function code(x) t_0 = asin(Float64(1.0 - x)) tmp = 0.0 if (Float64(1.0 - x) <= 1.0) tmp = Float64(Float64(pi * 0.5) - t_0); else tmp = hypot(Float64(pi * 0.5), t_0); end return tmp end
function tmp_2 = code(x) t_0 = asin((1.0 - x)); tmp = 0.0; if ((1.0 - x) <= 1.0) tmp = (pi * 0.5) - t_0; else tmp = hypot((pi * 0.5), t_0); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(1.0 - x), $MachinePrecision], 1.0], N[(N[(Pi * 0.5), $MachinePrecision] - t$95$0), $MachinePrecision], N[Sqrt[N[(Pi * 0.5), $MachinePrecision] ^ 2 + t$95$0 ^ 2], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
\mathbf{if}\;1 - x \leq 1:\\
\;\;\;\;\pi \cdot 0.5 - t_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(\pi \cdot 0.5, t_0\right)\\
\end{array}
\end{array}
if (-.f64 1 x) < 1Initial program 7.1%
acos-asin7.1%
sub-neg7.1%
div-inv7.1%
metadata-eval7.1%
Applied egg-rr7.1%
sub-neg7.1%
Simplified7.1%
if 1 < (-.f64 1 x) Initial program 7.1%
add-cube-cbrt7.1%
pow37.1%
Applied egg-rr7.1%
add-log-exp7.1%
Applied egg-rr7.1%
unpow37.1%
add-log-exp7.1%
add-log-exp7.1%
add-log-exp7.1%
add-cube-cbrt7.1%
acos-asin7.1%
Applied egg-rr7.1%
div-inv7.1%
metadata-eval7.1%
add-sqr-sqrt7.1%
sqrt-unprod7.1%
flip3--7.1%
Applied egg-rr6.8%
Final simplification7.1%
(FPCore (x) :precision binary64 (if (<= x 5.5e-17) (+ (asin (- 1.0 x)) (* PI 0.5)) (+ 1.0 (+ (acos (- 1.0 x)) -1.0))))
double code(double x) {
double tmp;
if (x <= 5.5e-17) {
tmp = asin((1.0 - x)) + (((double) M_PI) * 0.5);
} else {
tmp = 1.0 + (acos((1.0 - x)) + -1.0);
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= 5.5e-17) {
tmp = Math.asin((1.0 - x)) + (Math.PI * 0.5);
} else {
tmp = 1.0 + (Math.acos((1.0 - x)) + -1.0);
}
return tmp;
}
def code(x): tmp = 0 if x <= 5.5e-17: tmp = math.asin((1.0 - x)) + (math.pi * 0.5) else: tmp = 1.0 + (math.acos((1.0 - x)) + -1.0) return tmp
function code(x) tmp = 0.0 if (x <= 5.5e-17) tmp = Float64(asin(Float64(1.0 - x)) + Float64(pi * 0.5)); else tmp = Float64(1.0 + Float64(acos(Float64(1.0 - x)) + -1.0)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 5.5e-17) tmp = asin((1.0 - x)) + (pi * 0.5); else tmp = 1.0 + (acos((1.0 - x)) + -1.0); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 5.5e-17], N[(N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision] + N[(Pi * 0.5), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.5 \cdot 10^{-17}:\\
\;\;\;\;\sin^{-1} \left(1 - x\right) + \pi \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;1 + \left(\cos^{-1} \left(1 - x\right) + -1\right)\\
\end{array}
\end{array}
if x < 5.50000000000000001e-17Initial program 3.9%
add-cube-cbrt3.9%
pow33.9%
Applied egg-rr3.9%
add-log-exp3.9%
Applied egg-rr3.9%
unpow33.9%
add-log-exp3.9%
add-log-exp3.9%
add-log-exp3.9%
add-cube-cbrt3.9%
acos-asin3.9%
Applied egg-rr3.9%
div-inv3.9%
metadata-eval3.9%
add-cube-cbrt7.3%
unpow27.3%
cancel-sign-sub-inv7.3%
+-commutative7.3%
fma-def7.3%
add-sqr-sqrt0.0%
sqrt-unprod6.5%
sqr-neg6.5%
sqrt-unprod6.5%
add-sqr-sqrt6.5%
Applied egg-rr6.5%
if 5.50000000000000001e-17 < x Initial program 58.5%
expm1-log1p-u58.5%
expm1-udef58.5%
log1p-udef58.5%
add-exp-log58.5%
Applied egg-rr58.5%
associate--l+58.5%
+-commutative58.5%
sub-neg58.5%
metadata-eval58.5%
Applied egg-rr58.5%
Final simplification9.5%
(FPCore (x) :precision binary64 (let* ((t_0 (asin (- 1.0 x)))) (if (<= x 5.5e-17) (+ t_0 (* PI 0.5)) (- (* PI 0.5) t_0))))
double code(double x) {
double t_0 = asin((1.0 - x));
double tmp;
if (x <= 5.5e-17) {
tmp = t_0 + (((double) M_PI) * 0.5);
} else {
tmp = (((double) M_PI) * 0.5) - t_0;
}
return tmp;
}
public static double code(double x) {
double t_0 = Math.asin((1.0 - x));
double tmp;
if (x <= 5.5e-17) {
tmp = t_0 + (Math.PI * 0.5);
} else {
tmp = (Math.PI * 0.5) - t_0;
}
return tmp;
}
def code(x): t_0 = math.asin((1.0 - x)) tmp = 0 if x <= 5.5e-17: tmp = t_0 + (math.pi * 0.5) else: tmp = (math.pi * 0.5) - t_0 return tmp
function code(x) t_0 = asin(Float64(1.0 - x)) tmp = 0.0 if (x <= 5.5e-17) tmp = Float64(t_0 + Float64(pi * 0.5)); else tmp = Float64(Float64(pi * 0.5) - t_0); end return tmp end
function tmp_2 = code(x) t_0 = asin((1.0 - x)); tmp = 0.0; if (x <= 5.5e-17) tmp = t_0 + (pi * 0.5); else tmp = (pi * 0.5) - t_0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, 5.5e-17], N[(t$95$0 + N[(Pi * 0.5), $MachinePrecision]), $MachinePrecision], N[(N[(Pi * 0.5), $MachinePrecision] - t$95$0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
\mathbf{if}\;x \leq 5.5 \cdot 10^{-17}:\\
\;\;\;\;t_0 + \pi \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\pi \cdot 0.5 - t_0\\
\end{array}
\end{array}
if x < 5.50000000000000001e-17Initial program 3.9%
add-cube-cbrt3.9%
pow33.9%
Applied egg-rr3.9%
add-log-exp3.9%
Applied egg-rr3.9%
unpow33.9%
add-log-exp3.9%
add-log-exp3.9%
add-log-exp3.9%
add-cube-cbrt3.9%
acos-asin3.9%
Applied egg-rr3.9%
div-inv3.9%
metadata-eval3.9%
add-cube-cbrt7.3%
unpow27.3%
cancel-sign-sub-inv7.3%
+-commutative7.3%
fma-def7.3%
add-sqr-sqrt0.0%
sqrt-unprod6.5%
sqr-neg6.5%
sqrt-unprod6.5%
add-sqr-sqrt6.5%
Applied egg-rr6.5%
if 5.50000000000000001e-17 < x Initial program 58.5%
acos-asin58.5%
sub-neg58.5%
div-inv58.5%
metadata-eval58.5%
Applied egg-rr58.5%
sub-neg58.5%
Simplified58.5%
Final simplification9.5%
(FPCore (x) :precision binary64 (+ 1.0 (+ (acos (- 1.0 x)) -1.0)))
double code(double x) {
return 1.0 + (acos((1.0 - x)) + -1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 + (acos((1.0d0 - x)) + (-1.0d0))
end function
public static double code(double x) {
return 1.0 + (Math.acos((1.0 - x)) + -1.0);
}
def code(x): return 1.0 + (math.acos((1.0 - x)) + -1.0)
function code(x) return Float64(1.0 + Float64(acos(Float64(1.0 - x)) + -1.0)) end
function tmp = code(x) tmp = 1.0 + (acos((1.0 - x)) + -1.0); end
code[x_] := N[(1.0 + N[(N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \left(\cos^{-1} \left(1 - x\right) + -1\right)
\end{array}
Initial program 7.1%
expm1-log1p-u7.1%
expm1-udef7.1%
log1p-udef7.1%
add-exp-log7.1%
Applied egg-rr7.1%
associate--l+7.1%
+-commutative7.1%
sub-neg7.1%
metadata-eval7.1%
Applied egg-rr7.1%
Final simplification7.1%
(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}
Initial program 7.1%
Final simplification7.1%
(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 2023271
(FPCore (x)
:name "bug323 (missed optimization)"
:precision binary64
:pre (and (<= 0.0 x) (<= x 0.5))
:herbie-target
(* 2.0 (asin (sqrt (/ x 2.0))))
(acos (- 1.0 x)))