
(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 11 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))))
(/
(fma (* (pow PI 2.0) 0.25) (* PI 0.5) (- (pow t_0 3.0)))
(+ (* (* PI 0.5) (* PI 0.5)) (+ (pow t_0 2.0) (* (* PI 0.5) t_0))))))
double code(double x) {
double t_0 = asin((1.0 - x));
return fma((pow(((double) M_PI), 2.0) * 0.25), (((double) M_PI) * 0.5), -pow(t_0, 3.0)) / (((((double) M_PI) * 0.5) * (((double) M_PI) * 0.5)) + (pow(t_0, 2.0) + ((((double) M_PI) * 0.5) * t_0)));
}
function code(x) t_0 = asin(Float64(1.0 - x)) return Float64(fma(Float64((pi ^ 2.0) * 0.25), Float64(pi * 0.5), Float64(-(t_0 ^ 3.0))) / Float64(Float64(Float64(pi * 0.5) * Float64(pi * 0.5)) + Float64((t_0 ^ 2.0) + Float64(Float64(pi * 0.5) * t_0)))) end
code[x_] := Block[{t$95$0 = N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[(N[Power[Pi, 2.0], $MachinePrecision] * 0.25), $MachinePrecision] * N[(Pi * 0.5), $MachinePrecision] + (-N[Power[t$95$0, 3.0], $MachinePrecision])), $MachinePrecision] / N[(N[(N[(Pi * 0.5), $MachinePrecision] * N[(Pi * 0.5), $MachinePrecision]), $MachinePrecision] + N[(N[Power[t$95$0, 2.0], $MachinePrecision] + N[(N[(Pi * 0.5), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
\frac{\mathsf{fma}\left({\pi}^{2} \cdot 0.25, \pi \cdot 0.5, -{t\_0}^{3}\right)}{\left(\pi \cdot 0.5\right) \cdot \left(\pi \cdot 0.5\right) + \left({t\_0}^{2} + \left(\pi \cdot 0.5\right) \cdot t\_0\right)}
\end{array}
\end{array}
Initial program 5.9%
expm1-log1p-u5.9%
expm1-undefine5.9%
log1p-undefine5.9%
rem-exp-log5.9%
Applied egg-rr5.9%
add-exp-log5.9%
expm1-define5.9%
log1p-define5.9%
expm1-log1p-u5.9%
acos-asin5.9%
flip3--5.9%
div-inv5.9%
metadata-eval5.9%
div-inv5.9%
metadata-eval5.9%
div-inv5.9%
metadata-eval5.9%
pow25.9%
Applied egg-rr5.9%
unpow35.9%
fma-neg9.2%
pow29.2%
unpow-prod-down9.2%
metadata-eval9.2%
Applied egg-rr9.2%
(FPCore (x) :precision binary64 (let* ((t_0 (acos (- 1.0 x))) (t_1 (sqrt (asin (- 1.0 x))))) (+ t_0 (fma (- t_1) t_1 (- (* PI 0.5) t_0)))))
double code(double x) {
double t_0 = acos((1.0 - x));
double t_1 = sqrt(asin((1.0 - x)));
return t_0 + fma(-t_1, t_1, ((((double) M_PI) * 0.5) - t_0));
}
function code(x) t_0 = acos(Float64(1.0 - x)) t_1 = sqrt(asin(Float64(1.0 - x))) return Float64(t_0 + fma(Float64(-t_1), t_1, Float64(Float64(pi * 0.5) - t_0))) end
code[x_] := Block[{t$95$0 = N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]}, N[(t$95$0 + N[((-t$95$1) * t$95$1 + N[(N[(Pi * 0.5), $MachinePrecision] - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos^{-1} \left(1 - x\right)\\
t_1 := \sqrt{\sin^{-1} \left(1 - x\right)}\\
t\_0 + \mathsf{fma}\left(-t\_1, t\_1, \pi \cdot 0.5 - t\_0\right)
\end{array}
\end{array}
Initial program 5.9%
acos-asin5.9%
*-un-lft-identity5.9%
add-sqr-sqrt9.1%
prod-diff9.1%
add-sqr-sqrt9.1%
fma-neg9.1%
*-un-lft-identity9.1%
acos-asin9.1%
add-sqr-sqrt9.1%
Applied egg-rr9.1%
asin-acos9.1%
div-inv9.1%
metadata-eval9.1%
Applied egg-rr9.1%
(FPCore (x) :precision binary64 (* 2.0 (log (sqrt (exp (- (* PI (pow (sqrt 0.5) 2.0)) (asin (- 1.0 x))))))))
double code(double x) {
return 2.0 * log(sqrt(exp(((((double) M_PI) * pow(sqrt(0.5), 2.0)) - asin((1.0 - x))))));
}
public static double code(double x) {
return 2.0 * Math.log(Math.sqrt(Math.exp(((Math.PI * Math.pow(Math.sqrt(0.5), 2.0)) - Math.asin((1.0 - x))))));
}
def code(x): return 2.0 * math.log(math.sqrt(math.exp(((math.pi * math.pow(math.sqrt(0.5), 2.0)) - math.asin((1.0 - x))))))
function code(x) return Float64(2.0 * log(sqrt(exp(Float64(Float64(pi * (sqrt(0.5) ^ 2.0)) - asin(Float64(1.0 - x))))))) end
function tmp = code(x) tmp = 2.0 * log(sqrt(exp(((pi * (sqrt(0.5) ^ 2.0)) - asin((1.0 - x)))))); end
code[x_] := N[(2.0 * N[Log[N[Sqrt[N[Exp[N[(N[(Pi * N[Power[N[Sqrt[0.5], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] - N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \log \left(\sqrt{e^{\pi \cdot {\left(\sqrt{0.5}\right)}^{2} - \sin^{-1} \left(1 - x\right)}}\right)
\end{array}
Initial program 5.9%
add-log-exp5.9%
add-sqr-sqrt5.9%
log-prod5.9%
Applied egg-rr5.9%
count-25.9%
Simplified5.9%
acos-asin5.9%
add-sqr-sqrt4.0%
fma-neg4.0%
div-inv4.0%
metadata-eval4.0%
div-inv4.0%
metadata-eval4.0%
Applied egg-rr4.0%
Taylor expanded in x around 0 9.1%
(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 5.9%
expm1-log1p-u5.9%
expm1-undefine5.9%
log1p-undefine5.9%
rem-exp-log5.9%
Applied egg-rr5.9%
add-exp-log5.9%
expm1-define5.9%
log1p-define5.9%
expm1-log1p-u5.9%
acos-asin5.9%
add-cube-cbrt9.1%
cancel-sign-sub-inv9.1%
div-inv9.1%
metadata-eval9.1%
pow29.1%
Applied egg-rr9.1%
Final simplification9.1%
(FPCore (x)
:precision binary64
(let* ((t_0 (acos (- 1.0 x))))
(if (<= x 5.6e-17)
(+ (* (sqrt (+ 1.0 t_0)) (sqrt (+ 1.0 (acos (- x))))) -1.0)
(+ (+ 1.0 (* 2.0 (log (exp (* 0.5 t_0))))) -1.0))))
double code(double x) {
double t_0 = acos((1.0 - x));
double tmp;
if (x <= 5.6e-17) {
tmp = (sqrt((1.0 + t_0)) * sqrt((1.0 + acos(-x)))) + -1.0;
} else {
tmp = (1.0 + (2.0 * log(exp((0.5 * 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 (x <= 5.6d-17) then
tmp = (sqrt((1.0d0 + t_0)) * sqrt((1.0d0 + acos(-x)))) + (-1.0d0)
else
tmp = (1.0d0 + (2.0d0 * log(exp((0.5d0 * 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 (x <= 5.6e-17) {
tmp = (Math.sqrt((1.0 + t_0)) * Math.sqrt((1.0 + Math.acos(-x)))) + -1.0;
} else {
tmp = (1.0 + (2.0 * Math.log(Math.exp((0.5 * t_0))))) + -1.0;
}
return tmp;
}
def code(x): t_0 = math.acos((1.0 - x)) tmp = 0 if x <= 5.6e-17: tmp = (math.sqrt((1.0 + t_0)) * math.sqrt((1.0 + math.acos(-x)))) + -1.0 else: tmp = (1.0 + (2.0 * math.log(math.exp((0.5 * t_0))))) + -1.0 return tmp
function code(x) t_0 = acos(Float64(1.0 - x)) tmp = 0.0 if (x <= 5.6e-17) tmp = Float64(Float64(sqrt(Float64(1.0 + t_0)) * sqrt(Float64(1.0 + acos(Float64(-x))))) + -1.0); else tmp = Float64(Float64(1.0 + Float64(2.0 * log(exp(Float64(0.5 * t_0))))) + -1.0); end return tmp end
function tmp_2 = code(x) t_0 = acos((1.0 - x)); tmp = 0.0; if (x <= 5.6e-17) tmp = (sqrt((1.0 + t_0)) * sqrt((1.0 + acos(-x)))) + -1.0; else tmp = (1.0 + (2.0 * log(exp((0.5 * 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[x, 5.6e-17], N[(N[(N[Sqrt[N[(1.0 + t$95$0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(1.0 + N[ArcCos[(-x)], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(1.0 + N[(2.0 * N[Log[N[Exp[N[(0.5 * t$95$0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos^{-1} \left(1 - x\right)\\
\mathbf{if}\;x \leq 5.6 \cdot 10^{-17}:\\
\;\;\;\;\sqrt{1 + t\_0} \cdot \sqrt{1 + \cos^{-1} \left(-x\right)} + -1\\
\mathbf{else}:\\
\;\;\;\;\left(1 + 2 \cdot \log \left(e^{0.5 \cdot t\_0}\right)\right) + -1\\
\end{array}
\end{array}
if x < 5.5999999999999998e-17Initial program 3.9%
expm1-log1p-u3.9%
expm1-undefine3.9%
log1p-undefine3.9%
rem-exp-log3.9%
Applied egg-rr3.9%
add-sqr-sqrt3.9%
Applied egg-rr3.9%
Taylor expanded in x around inf 6.4%
neg-mul-16.4%
Simplified6.4%
if 5.5999999999999998e-17 < x Initial program 59.9%
expm1-log1p-u59.9%
expm1-undefine59.8%
log1p-undefine59.8%
rem-exp-log59.8%
Applied egg-rr59.8%
add-log-exp59.8%
add-sqr-sqrt60.1%
log-prod60.1%
Applied egg-rr60.2%
count-260.1%
Simplified60.2%
pow1/260.2%
pow-exp60.2%
Applied egg-rr60.2%
Final simplification8.3%
(FPCore (x) :precision binary64 (if (<= x 5.6e-17) (acos (- x)) (+ (+ 1.0 (* 2.0 (log (exp (* 0.5 (acos (- 1.0 x))))))) -1.0)))
double code(double x) {
double tmp;
if (x <= 5.6e-17) {
tmp = acos(-x);
} else {
tmp = (1.0 + (2.0 * log(exp((0.5 * acos((1.0 - x))))))) + -1.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 5.6d-17) then
tmp = acos(-x)
else
tmp = (1.0d0 + (2.0d0 * log(exp((0.5d0 * acos((1.0d0 - x))))))) + (-1.0d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 5.6e-17) {
tmp = Math.acos(-x);
} else {
tmp = (1.0 + (2.0 * Math.log(Math.exp((0.5 * Math.acos((1.0 - x))))))) + -1.0;
}
return tmp;
}
def code(x): tmp = 0 if x <= 5.6e-17: tmp = math.acos(-x) else: tmp = (1.0 + (2.0 * math.log(math.exp((0.5 * math.acos((1.0 - x))))))) + -1.0 return tmp
function code(x) tmp = 0.0 if (x <= 5.6e-17) tmp = acos(Float64(-x)); else tmp = Float64(Float64(1.0 + Float64(2.0 * log(exp(Float64(0.5 * acos(Float64(1.0 - x))))))) + -1.0); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 5.6e-17) tmp = acos(-x); else tmp = (1.0 + (2.0 * log(exp((0.5 * acos((1.0 - x))))))) + -1.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 5.6e-17], N[ArcCos[(-x)], $MachinePrecision], N[(N[(1.0 + N[(2.0 * N[Log[N[Exp[N[(0.5 * N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.6 \cdot 10^{-17}:\\
\;\;\;\;\cos^{-1} \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 + 2 \cdot \log \left(e^{0.5 \cdot \cos^{-1} \left(1 - x\right)}\right)\right) + -1\\
\end{array}
\end{array}
if x < 5.5999999999999998e-17Initial program 3.9%
Taylor expanded in x around inf 6.4%
neg-mul-16.4%
Simplified6.4%
if 5.5999999999999998e-17 < x Initial program 59.9%
expm1-log1p-u59.9%
expm1-undefine59.8%
log1p-undefine59.8%
rem-exp-log59.8%
Applied egg-rr59.8%
add-log-exp59.8%
add-sqr-sqrt60.1%
log-prod60.1%
Applied egg-rr60.2%
count-260.1%
Simplified60.2%
pow1/260.2%
pow-exp60.2%
Applied egg-rr60.2%
Final simplification8.3%
(FPCore (x) :precision binary64 (if (<= (- 1.0 x) 1.0) (- (* PI 0.5) (asin (- 1.0 x))) (acos (- x))))
double code(double x) {
double tmp;
if ((1.0 - x) <= 1.0) {
tmp = (((double) M_PI) * 0.5) - asin((1.0 - x));
} else {
tmp = acos(-x);
}
return tmp;
}
public static double code(double x) {
double tmp;
if ((1.0 - x) <= 1.0) {
tmp = (Math.PI * 0.5) - Math.asin((1.0 - x));
} else {
tmp = Math.acos(-x);
}
return tmp;
}
def code(x): tmp = 0 if (1.0 - x) <= 1.0: tmp = (math.pi * 0.5) - math.asin((1.0 - x)) else: tmp = math.acos(-x) return tmp
function code(x) tmp = 0.0 if (Float64(1.0 - x) <= 1.0) tmp = Float64(Float64(pi * 0.5) - asin(Float64(1.0 - x))); else tmp = acos(Float64(-x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((1.0 - x) <= 1.0) tmp = (pi * 0.5) - asin((1.0 - x)); else tmp = acos(-x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(1.0 - x), $MachinePrecision], 1.0], N[(N[(Pi * 0.5), $MachinePrecision] - N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[ArcCos[(-x)], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - x \leq 1:\\
\;\;\;\;\pi \cdot 0.5 - \sin^{-1} \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;\cos^{-1} \left(-x\right)\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) x) < 1Initial program 5.9%
acos-asin5.9%
sub-neg5.9%
div-inv5.9%
metadata-eval5.9%
Applied egg-rr5.9%
sub-neg5.9%
Simplified5.9%
if 1 < (-.f64 #s(literal 1 binary64) x) Initial program 5.9%
Taylor expanded in x around inf 6.6%
neg-mul-16.6%
Simplified6.6%
(FPCore (x) :precision binary64 (if (<= x 5.6e-17) (acos (- x)) (+ 1.0 (+ (acos (- 1.0 x)) -1.0))))
double code(double x) {
double tmp;
if (x <= 5.6e-17) {
tmp = acos(-x);
} else {
tmp = 1.0 + (acos((1.0 - x)) + -1.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 5.6d-17) then
tmp = acos(-x)
else
tmp = 1.0d0 + (acos((1.0d0 - x)) + (-1.0d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 5.6e-17) {
tmp = Math.acos(-x);
} else {
tmp = 1.0 + (Math.acos((1.0 - x)) + -1.0);
}
return tmp;
}
def code(x): tmp = 0 if x <= 5.6e-17: tmp = math.acos(-x) else: tmp = 1.0 + (math.acos((1.0 - x)) + -1.0) return tmp
function code(x) tmp = 0.0 if (x <= 5.6e-17) tmp = acos(Float64(-x)); 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.6e-17) tmp = acos(-x); else tmp = 1.0 + (acos((1.0 - x)) + -1.0); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 5.6e-17], N[ArcCos[(-x)], $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.6 \cdot 10^{-17}:\\
\;\;\;\;\cos^{-1} \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;1 + \left(\cos^{-1} \left(1 - x\right) + -1\right)\\
\end{array}
\end{array}
if x < 5.5999999999999998e-17Initial program 3.9%
Taylor expanded in x around inf 6.4%
neg-mul-16.4%
Simplified6.4%
if 5.5999999999999998e-17 < x Initial program 59.9%
expm1-log1p-u59.9%
expm1-undefine59.8%
log1p-undefine59.8%
rem-exp-log59.8%
Applied egg-rr59.8%
associate--l+59.9%
+-commutative59.9%
sub-neg59.9%
metadata-eval59.9%
Applied egg-rr59.9%
Final simplification8.3%
(FPCore (x) :precision binary64 (if (<= x 5.6e-17) (acos (- x)) (acos (- 1.0 x))))
double code(double x) {
double tmp;
if (x <= 5.6e-17) {
tmp = acos(-x);
} else {
tmp = acos((1.0 - x));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 5.6d-17) then
tmp = acos(-x)
else
tmp = acos((1.0d0 - x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 5.6e-17) {
tmp = Math.acos(-x);
} else {
tmp = Math.acos((1.0 - x));
}
return tmp;
}
def code(x): tmp = 0 if x <= 5.6e-17: tmp = math.acos(-x) else: tmp = math.acos((1.0 - x)) return tmp
function code(x) tmp = 0.0 if (x <= 5.6e-17) tmp = acos(Float64(-x)); else tmp = acos(Float64(1.0 - x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 5.6e-17) tmp = acos(-x); else tmp = acos((1.0 - x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 5.6e-17], N[ArcCos[(-x)], $MachinePrecision], N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.6 \cdot 10^{-17}:\\
\;\;\;\;\cos^{-1} \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;\cos^{-1} \left(1 - x\right)\\
\end{array}
\end{array}
if x < 5.5999999999999998e-17Initial program 3.9%
Taylor expanded in x around inf 6.4%
neg-mul-16.4%
Simplified6.4%
if 5.5999999999999998e-17 < x Initial program 59.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(Float64(-x)) end
function tmp = code(x) tmp = acos(-x); end
code[x_] := N[ArcCos[(-x)], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(-x\right)
\end{array}
Initial program 5.9%
Taylor expanded in x around inf 6.6%
neg-mul-16.6%
Simplified6.6%
(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 5.9%
Taylor expanded in x around 0 3.9%
(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 2024118
(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)))