
(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 5 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))))) (+ (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 5.4%
acos-asin5.4%
*-un-lft-identity5.4%
add-sqr-sqrt8.8%
prod-diff8.8%
add-sqr-sqrt8.8%
fma-neg8.8%
*-un-lft-identity8.8%
acos-asin8.8%
add-sqr-sqrt8.8%
Applied egg-rr8.8%
add-sqr-sqrt8.8%
pow28.8%
Applied egg-rr8.8%
Final simplification8.8%
(FPCore (x) :precision binary64 (fma (* (sqrt PI) (sqrt 0.5)) (sqrt (* PI 0.5)) (- (asin (- 1.0 x)))))
double code(double x) {
return fma((sqrt(((double) M_PI)) * sqrt(0.5)), sqrt((((double) M_PI) * 0.5)), -asin((1.0 - x)));
}
function code(x) return fma(Float64(sqrt(pi) * sqrt(0.5)), sqrt(Float64(pi * 0.5)), Float64(-asin(Float64(1.0 - x)))) end
code[x_] := N[(N[(N[Sqrt[Pi], $MachinePrecision] * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(Pi * 0.5), $MachinePrecision]], $MachinePrecision] + (-N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sqrt{\pi} \cdot \sqrt{0.5}, \sqrt{\pi \cdot 0.5}, -\sin^{-1} \left(1 - x\right)\right)
\end{array}
Initial program 5.4%
acos-asin5.4%
add-sqr-sqrt3.6%
fma-neg3.5%
div-inv3.5%
metadata-eval3.5%
div-inv3.5%
metadata-eval3.5%
Applied egg-rr3.5%
sqrt-prod8.8%
Applied egg-rr8.8%
Final simplification8.8%
(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 5.4%
acos-asin5.4%
add-sqr-sqrt3.6%
fma-neg3.5%
div-inv3.5%
metadata-eval3.5%
div-inv3.5%
metadata-eval3.5%
Applied egg-rr3.5%
Taylor expanded in x around 0 8.8%
Final simplification8.8%
(FPCore (x) :precision binary64 (+ (asin (- 1.0 x)) (* PI 0.5)))
double code(double x) {
return asin((1.0 - x)) + (((double) M_PI) * 0.5);
}
public static double code(double x) {
return Math.asin((1.0 - x)) + (Math.PI * 0.5);
}
def code(x): return math.asin((1.0 - x)) + (math.pi * 0.5)
function code(x) return Float64(asin(Float64(1.0 - x)) + Float64(pi * 0.5)) end
function tmp = code(x) tmp = asin((1.0 - x)) + (pi * 0.5); end
code[x_] := N[(N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision] + N[(Pi * 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin^{-1} \left(1 - x\right) + \pi \cdot 0.5
\end{array}
Initial program 5.4%
expm1-log1p-u5.4%
expm1-undefine5.4%
log1p-undefine5.4%
rem-exp-log5.4%
Applied egg-rr5.4%
add-exp-log5.4%
expm1-define5.4%
log1p-define5.4%
expm1-log1p-u5.4%
acos-asin5.4%
div-inv5.4%
metadata-eval5.4%
add-sqr-sqrt8.8%
cancel-sign-sub-inv8.8%
add-sqr-sqrt0.0%
sqrt-unprod6.6%
sqr-neg6.6%
add-sqr-sqrt6.6%
add-sqr-sqrt6.6%
Applied egg-rr6.6%
Final simplification6.6%
(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 5.4%
Final simplification5.4%
(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 2024071
(FPCore (x)
:name "bug323 (missed optimization)"
:precision binary64
:pre (and (<= 0.0 x) (<= x 0.5))
:alt
(* 2.0 (asin (sqrt (/ x 2.0))))
(acos (- 1.0 x)))