
(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 12 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 (asin (- 1.0 x)))) (t_1 (acos (- 1.0 x))))
(+
(log (pow (cbrt (exp t_1)) 2.0))
(* 0.3333333333333333 (+ t_1 (fma (- t_0) t_0 (pow t_0 2.0)))))))
double code(double x) {
double t_0 = sqrt(asin((1.0 - x)));
double t_1 = acos((1.0 - x));
return log(pow(cbrt(exp(t_1)), 2.0)) + (0.3333333333333333 * (t_1 + fma(-t_0, t_0, pow(t_0, 2.0))));
}
function code(x) t_0 = sqrt(asin(Float64(1.0 - x))) t_1 = acos(Float64(1.0 - x)) return Float64(log((cbrt(exp(t_1)) ^ 2.0)) + Float64(0.3333333333333333 * Float64(t_1 + 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]}, Block[{t$95$1 = N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, N[(N[Log[N[Power[N[Power[N[Exp[t$95$1], $MachinePrecision], 1/3], $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision] + N[(0.3333333333333333 * N[(t$95$1 + N[((-t$95$0) * t$95$0 + N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\sin^{-1} \left(1 - x\right)}\\
t_1 := \cos^{-1} \left(1 - x\right)\\
\log \left({\left(\sqrt[3]{e^{t_1}}\right)}^{2}\right) + 0.3333333333333333 \cdot \left(t_1 + \mathsf{fma}\left(-t_0, t_0, {t_0}^{2}\right)\right)
\end{array}
\end{array}
Initial program 6.7%
expm1-log1p-u6.7%
expm1-udef6.7%
log1p-udef6.7%
rem-exp-log6.7%
Applied egg-rr6.7%
add-exp-log6.7%
log1p-udef6.7%
expm1-udef6.7%
add-log-exp6.7%
expm1-log1p-u6.7%
add-cube-cbrt6.7%
log-prod6.7%
pow26.7%
pow1/36.7%
log-pow6.7%
rem-log-exp6.7%
Applied egg-rr6.7%
acos-asin6.7%
*-un-lft-identity6.7%
add-sqr-sqrt10.5%
prod-diff10.5%
add-sqr-sqrt10.5%
fma-neg10.5%
*-un-lft-identity10.5%
acos-asin10.5%
add-sqr-sqrt10.5%
Applied egg-rr10.5%
add-sqr-sqrt10.5%
pow210.5%
Applied egg-rr10.5%
Final simplification10.5%
(FPCore (x)
:precision binary64
(let* ((t_0 (asin (- 1.0 x))) (t_1 (sqrt t_0)) (t_2 (acos (- 1.0 x))))
(+
(log (pow (cbrt (exp t_2)) 2.0))
(* 0.3333333333333333 (+ t_2 (fma (- t_1) t_1 t_0))))))
double code(double x) {
double t_0 = asin((1.0 - x));
double t_1 = sqrt(t_0);
double t_2 = acos((1.0 - x));
return log(pow(cbrt(exp(t_2)), 2.0)) + (0.3333333333333333 * (t_2 + fma(-t_1, t_1, t_0)));
}
function code(x) t_0 = asin(Float64(1.0 - x)) t_1 = sqrt(t_0) t_2 = acos(Float64(1.0 - x)) return Float64(log((cbrt(exp(t_2)) ^ 2.0)) + Float64(0.3333333333333333 * Float64(t_2 + 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]}, Block[{t$95$2 = N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, N[(N[Log[N[Power[N[Power[N[Exp[t$95$2], $MachinePrecision], 1/3], $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision] + N[(0.3333333333333333 * N[(t$95$2 + N[((-t$95$1) * t$95$1 + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
t_1 := \sqrt{t_0}\\
t_2 := \cos^{-1} \left(1 - x\right)\\
\log \left({\left(\sqrt[3]{e^{t_2}}\right)}^{2}\right) + 0.3333333333333333 \cdot \left(t_2 + \mathsf{fma}\left(-t_1, t_1, t_0\right)\right)
\end{array}
\end{array}
Initial program 6.7%
expm1-log1p-u6.7%
expm1-udef6.7%
log1p-udef6.7%
rem-exp-log6.7%
Applied egg-rr6.7%
add-exp-log6.7%
log1p-udef6.7%
expm1-udef6.7%
add-log-exp6.7%
expm1-log1p-u6.7%
add-cube-cbrt6.7%
log-prod6.7%
pow26.7%
pow1/36.7%
log-pow6.7%
rem-log-exp6.7%
Applied egg-rr6.7%
acos-asin6.7%
*-un-lft-identity6.7%
add-sqr-sqrt10.5%
prod-diff10.5%
add-sqr-sqrt10.5%
fma-neg10.5%
*-un-lft-identity10.5%
acos-asin10.5%
add-sqr-sqrt10.5%
Applied egg-rr10.5%
Final simplification10.5%
(FPCore (x)
:precision binary64
(let* ((t_0 (acos (- 1.0 x))) (t_1 (asin (- 1.0 x))) (t_2 (sqrt t_1)))
(+
(* 0.3333333333333333 (+ t_0 (fma (- t_2) t_2 t_1)))
(* 2.0 (* t_0 0.3333333333333333)))))
double code(double x) {
double t_0 = acos((1.0 - x));
double t_1 = asin((1.0 - x));
double t_2 = sqrt(t_1);
return (0.3333333333333333 * (t_0 + fma(-t_2, t_2, t_1))) + (2.0 * (t_0 * 0.3333333333333333));
}
function code(x) t_0 = acos(Float64(1.0 - x)) t_1 = asin(Float64(1.0 - x)) t_2 = sqrt(t_1) return Float64(Float64(0.3333333333333333 * Float64(t_0 + fma(Float64(-t_2), t_2, t_1))) + Float64(2.0 * Float64(t_0 * 0.3333333333333333))) 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[Sqrt[t$95$1], $MachinePrecision]}, N[(N[(0.3333333333333333 * N[(t$95$0 + N[((-t$95$2) * t$95$2 + t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(t$95$0 * 0.3333333333333333), $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{t_1}\\
0.3333333333333333 \cdot \left(t_0 + \mathsf{fma}\left(-t_2, t_2, t_1\right)\right) + 2 \cdot \left(t_0 \cdot 0.3333333333333333\right)
\end{array}
\end{array}
Initial program 6.7%
expm1-log1p-u6.7%
expm1-udef6.7%
log1p-udef6.7%
rem-exp-log6.7%
Applied egg-rr6.7%
add-exp-log6.7%
log1p-udef6.7%
expm1-udef6.7%
add-log-exp6.7%
expm1-log1p-u6.7%
add-cube-cbrt6.7%
log-prod6.7%
pow26.7%
pow1/36.7%
log-pow6.7%
rem-log-exp6.7%
Applied egg-rr6.7%
acos-asin6.7%
*-un-lft-identity6.7%
add-sqr-sqrt10.5%
prod-diff10.5%
add-sqr-sqrt10.5%
fma-neg10.5%
*-un-lft-identity10.5%
acos-asin10.5%
add-sqr-sqrt10.5%
Applied egg-rr10.5%
pow-to-exp10.5%
rem-log-exp10.5%
pow1/310.5%
pow-exp10.5%
add-log-exp10.5%
Applied egg-rr10.5%
Final simplification10.5%
(FPCore (x) :precision binary64 (let* ((t_0 (asin (- 1.0 x))) (t_1 (sqrt t_0))) (+ (+ 1.0 (+ (acos (- 1.0 x)) (fma (- t_1) t_1 t_0))) -1.0)))
double code(double x) {
double t_0 = asin((1.0 - x));
double t_1 = sqrt(t_0);
return (1.0 + (acos((1.0 - x)) + fma(-t_1, t_1, t_0))) + -1.0;
}
function code(x) t_0 = asin(Float64(1.0 - x)) t_1 = sqrt(t_0) return Float64(Float64(1.0 + Float64(acos(Float64(1.0 - x)) + fma(Float64(-t_1), t_1, t_0))) + -1.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[(1.0 + N[(N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision] + N[((-t$95$1) * t$95$1 + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
t_1 := \sqrt{t_0}\\
\left(1 + \left(\cos^{-1} \left(1 - x\right) + \mathsf{fma}\left(-t_1, t_1, t_0\right)\right)\right) + -1
\end{array}
\end{array}
Initial program 6.7%
expm1-log1p-u6.7%
expm1-udef6.7%
log1p-udef6.7%
rem-exp-log6.7%
Applied egg-rr6.7%
acos-asin6.7%
*-un-lft-identity6.7%
add-sqr-sqrt10.5%
prod-diff10.5%
add-sqr-sqrt10.5%
fma-neg10.5%
*-un-lft-identity10.5%
acos-asin10.5%
add-sqr-sqrt10.5%
Applied egg-rr10.4%
Final simplification10.4%
(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 6.7%
acos-asin6.7%
*-un-lft-identity6.7%
add-sqr-sqrt10.5%
prod-diff10.5%
add-sqr-sqrt10.5%
fma-neg10.5%
*-un-lft-identity10.5%
acos-asin10.5%
add-sqr-sqrt10.5%
Applied egg-rr10.4%
Final simplification10.4%
(FPCore (x) :precision binary64 (let* ((t_0 (cbrt (asin (- 1.0 x))))) (- (* PI 0.5) (* t_0 (pow t_0 2.0)))))
double code(double x) {
double t_0 = cbrt(asin((1.0 - x)));
return (((double) M_PI) * 0.5) - (t_0 * pow(t_0, 2.0));
}
public static double code(double x) {
double t_0 = Math.cbrt(Math.asin((1.0 - x)));
return (Math.PI * 0.5) - (t_0 * Math.pow(t_0, 2.0));
}
function code(x) t_0 = cbrt(asin(Float64(1.0 - x))) return Float64(Float64(pi * 0.5) - Float64(t_0 * (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[(N[(Pi * 0.5), $MachinePrecision] - 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)}\\
\pi \cdot 0.5 - t_0 \cdot {t_0}^{2}
\end{array}
\end{array}
Initial program 6.7%
expm1-log1p-u6.7%
expm1-udef6.7%
log1p-udef6.7%
rem-exp-log6.7%
Applied egg-rr6.7%
add-exp-log6.7%
log1p-udef6.7%
expm1-udef6.7%
expm1-log1p-u6.7%
acos-asin6.7%
div-inv6.7%
metadata-eval6.7%
add-cbrt-cube4.9%
unpow24.9%
cbrt-prod10.5%
cancel-sign-sub-inv10.5%
unpow210.5%
cbrt-prod10.4%
pow210.4%
Applied egg-rr10.4%
Final simplification10.4%
(FPCore (x) :precision binary64 (fma PI 0.5 (- (pow (cbrt (asin (- 1.0 x))) 3.0))))
double code(double x) {
return fma(((double) M_PI), 0.5, -pow(cbrt(asin((1.0 - x))), 3.0));
}
function code(x) return fma(pi, 0.5, Float64(-(cbrt(asin(Float64(1.0 - x))) ^ 3.0))) end
code[x_] := N[(Pi * 0.5 + (-N[Power[N[Power[N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision], 3.0], $MachinePrecision])), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\pi, 0.5, -{\left(\sqrt[3]{\sin^{-1} \left(1 - x\right)}\right)}^{3}\right)
\end{array}
Initial program 6.7%
expm1-log1p-u6.7%
expm1-udef6.7%
log1p-udef6.7%
rem-exp-log6.7%
Applied egg-rr6.7%
add-exp-log6.7%
log1p-udef6.7%
expm1-udef6.7%
expm1-log1p-u6.7%
acos-asin6.7%
div-inv6.7%
metadata-eval6.7%
flip--6.7%
unpow26.7%
unpow26.7%
fma-udef6.7%
clear-num6.7%
clear-num6.7%
Applied egg-rr6.7%
remove-double-div6.7%
acos-asin6.7%
div-inv6.7%
metadata-eval6.7%
add-cbrt-cube4.9%
pow24.9%
add-cube-cbrt10.4%
unpow310.4%
cbrt-prod10.4%
expm1-log1p-u10.4%
expm1-def10.4%
*-commutative10.4%
Applied egg-rr10.4%
fma-def10.4%
distribute-lft-neg-out10.4%
unpow210.4%
cube-unmult10.4%
Simplified10.4%
Final simplification10.4%
(FPCore (x) :precision binary64 (if (<= x 5.5e-17) (+ (asin (- 1.0 x)) (* PI 0.5)) (* 3.0 (log (cbrt (exp (acos (- 1.0 x))))))))
double code(double x) {
double tmp;
if (x <= 5.5e-17) {
tmp = asin((1.0 - x)) + (((double) M_PI) * 0.5);
} else {
tmp = 3.0 * log(cbrt(exp(acos((1.0 - x)))));
}
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 = 3.0 * Math.log(Math.cbrt(Math.exp(Math.acos((1.0 - x)))));
}
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(3.0 * log(cbrt(exp(acos(Float64(1.0 - x)))))); end return 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[(3.0 * N[Log[N[Power[N[Exp[N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision]], $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}:\\
\;\;\;\;3 \cdot \log \left(\sqrt[3]{e^{\cos^{-1} \left(1 - x\right)}}\right)\\
\end{array}
\end{array}
if x < 5.50000000000000001e-17Initial program 3.8%
expm1-log1p-u3.8%
expm1-udef3.8%
log1p-udef3.8%
rem-exp-log3.8%
Applied egg-rr3.8%
add-exp-log3.8%
log1p-udef3.8%
expm1-udef3.8%
expm1-log1p-u3.8%
acos-asin3.8%
div-inv3.8%
metadata-eval3.8%
add-sqr-sqrt7.8%
cancel-sign-sub-inv7.8%
add-sqr-sqrt0.0%
sqrt-unprod6.7%
sqr-neg6.7%
add-sqr-sqrt6.7%
add-sqr-sqrt6.7%
Applied egg-rr6.7%
if 5.50000000000000001e-17 < x Initial program 60.7%
add-log-exp60.6%
add-cube-cbrt60.7%
log-prod60.9%
pow260.9%
Applied egg-rr60.9%
log-pow60.9%
distribute-lft1-in60.9%
metadata-eval60.9%
*-commutative60.9%
Simplified60.9%
Final simplification9.5%
(FPCore (x) :precision binary64 (if (<= x 5.5e-17) (+ (asin (- 1.0 x)) (* PI 0.5)) (pow (pow (acos (- 1.0 x)) 3.0) 0.3333333333333333)))
double code(double x) {
double tmp;
if (x <= 5.5e-17) {
tmp = asin((1.0 - x)) + (((double) M_PI) * 0.5);
} else {
tmp = pow(pow(acos((1.0 - x)), 3.0), 0.3333333333333333);
}
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 = Math.pow(Math.pow(Math.acos((1.0 - x)), 3.0), 0.3333333333333333);
}
return tmp;
}
def code(x): tmp = 0 if x <= 5.5e-17: tmp = math.asin((1.0 - x)) + (math.pi * 0.5) else: tmp = math.pow(math.pow(math.acos((1.0 - x)), 3.0), 0.3333333333333333) 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 = (acos(Float64(1.0 - x)) ^ 3.0) ^ 0.3333333333333333; 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 = (acos((1.0 - x)) ^ 3.0) ^ 0.3333333333333333; 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[Power[N[Power[N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision], 3.0], $MachinePrecision], 0.3333333333333333], $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}:\\
\;\;\;\;{\left({\cos^{-1} \left(1 - x\right)}^{3}\right)}^{0.3333333333333333}\\
\end{array}
\end{array}
if x < 5.50000000000000001e-17Initial program 3.8%
expm1-log1p-u3.8%
expm1-udef3.8%
log1p-udef3.8%
rem-exp-log3.8%
Applied egg-rr3.8%
add-exp-log3.8%
log1p-udef3.8%
expm1-udef3.8%
expm1-log1p-u3.8%
acos-asin3.8%
div-inv3.8%
metadata-eval3.8%
add-sqr-sqrt7.8%
cancel-sign-sub-inv7.8%
add-sqr-sqrt0.0%
sqrt-unprod6.7%
sqr-neg6.7%
add-sqr-sqrt6.7%
add-sqr-sqrt6.7%
Applied egg-rr6.7%
if 5.50000000000000001e-17 < x Initial program 60.7%
add-cbrt-cube60.7%
pow1/360.8%
pow360.8%
Applied egg-rr60.8%
Final simplification9.4%
(FPCore (x) :precision binary64 (if (<= x 5.5e-17) (+ (asin (- 1.0 x)) (* PI 0.5)) (/ 1.0 (/ 1.0 (acos (- 1.0 x))))))
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 / (1.0 / acos((1.0 - x)));
}
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 / (1.0 / Math.acos((1.0 - x)));
}
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 / (1.0 / math.acos((1.0 - x))) 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(1.0 / acos(Float64(1.0 - x)))); 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 / (1.0 / acos((1.0 - x))); 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[(1.0 / N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]), $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}:\\
\;\;\;\;\frac{1}{\frac{1}{\cos^{-1} \left(1 - x\right)}}\\
\end{array}
\end{array}
if x < 5.50000000000000001e-17Initial program 3.8%
expm1-log1p-u3.8%
expm1-udef3.8%
log1p-udef3.8%
rem-exp-log3.8%
Applied egg-rr3.8%
add-exp-log3.8%
log1p-udef3.8%
expm1-udef3.8%
expm1-log1p-u3.8%
acos-asin3.8%
div-inv3.8%
metadata-eval3.8%
add-sqr-sqrt7.8%
cancel-sign-sub-inv7.8%
add-sqr-sqrt0.0%
sqrt-unprod6.7%
sqr-neg6.7%
add-sqr-sqrt6.7%
add-sqr-sqrt6.7%
Applied egg-rr6.7%
if 5.50000000000000001e-17 < x Initial program 60.7%
expm1-log1p-u60.7%
expm1-udef60.7%
log1p-udef60.7%
rem-exp-log60.7%
Applied egg-rr60.7%
add-exp-log60.7%
log1p-udef60.7%
expm1-udef60.7%
expm1-log1p-u60.7%
acos-asin60.6%
div-inv60.6%
metadata-eval60.6%
flip--60.6%
unpow260.6%
unpow260.6%
fma-udef60.6%
clear-num60.6%
clear-num60.6%
Applied egg-rr60.8%
Final simplification9.4%
(FPCore (x) :precision binary64 (/ 1.0 (/ 1.0 (acos (- 1.0 x)))))
double code(double x) {
return 1.0 / (1.0 / acos((1.0 - x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (1.0d0 / acos((1.0d0 - x)))
end function
public static double code(double x) {
return 1.0 / (1.0 / Math.acos((1.0 - x)));
}
def code(x): return 1.0 / (1.0 / math.acos((1.0 - x)))
function code(x) return Float64(1.0 / Float64(1.0 / acos(Float64(1.0 - x)))) end
function tmp = code(x) tmp = 1.0 / (1.0 / acos((1.0 - x))); end
code[x_] := N[(1.0 / N[(1.0 / N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{1}{\cos^{-1} \left(1 - x\right)}}
\end{array}
Initial program 6.7%
expm1-log1p-u6.7%
expm1-udef6.7%
log1p-udef6.7%
rem-exp-log6.7%
Applied egg-rr6.7%
add-exp-log6.7%
log1p-udef6.7%
expm1-udef6.7%
expm1-log1p-u6.7%
acos-asin6.7%
div-inv6.7%
metadata-eval6.7%
flip--6.7%
unpow26.7%
unpow26.7%
fma-udef6.7%
clear-num6.7%
clear-num6.7%
Applied egg-rr6.7%
Final simplification6.7%
(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 6.7%
Final simplification6.7%
(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 2024019
(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)))