
(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)))
(t_1 (fma 0.25 (pow PI 2.0) (pow t_0 2.0)))
(t_2 (fma PI 0.5 t_0))
(t_3 (pow t_2 2.0)))
(fma
(/ (* 0.0625 (pow PI 4.0)) (* (* t_2 t_1) t_3))
t_3
(* (/ (pow t_0 4.0) t_3) (/ (- t_2) t_1)))))
double code(double x) {
double t_0 = asin((1.0 - x));
double t_1 = fma(0.25, pow(((double) M_PI), 2.0), pow(t_0, 2.0));
double t_2 = fma(((double) M_PI), 0.5, t_0);
double t_3 = pow(t_2, 2.0);
return fma(((0.0625 * pow(((double) M_PI), 4.0)) / ((t_2 * t_1) * t_3)), t_3, ((pow(t_0, 4.0) / t_3) * (-t_2 / t_1)));
}
function code(x) t_0 = asin(Float64(1.0 - x)) t_1 = fma(0.25, (pi ^ 2.0), (t_0 ^ 2.0)) t_2 = fma(pi, 0.5, t_0) t_3 = t_2 ^ 2.0 return fma(Float64(Float64(0.0625 * (pi ^ 4.0)) / Float64(Float64(t_2 * t_1) * t_3)), t_3, Float64(Float64((t_0 ^ 4.0) / t_3) * Float64(Float64(-t_2) / t_1))) end
code[x_] := Block[{t$95$0 = N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(0.25 * N[Power[Pi, 2.0], $MachinePrecision] + N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(Pi * 0.5 + t$95$0), $MachinePrecision]}, Block[{t$95$3 = N[Power[t$95$2, 2.0], $MachinePrecision]}, N[(N[(N[(0.0625 * N[Power[Pi, 4.0], $MachinePrecision]), $MachinePrecision] / N[(N[(t$95$2 * t$95$1), $MachinePrecision] * t$95$3), $MachinePrecision]), $MachinePrecision] * t$95$3 + N[(N[(N[Power[t$95$0, 4.0], $MachinePrecision] / t$95$3), $MachinePrecision] * N[((-t$95$2) / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
t_1 := \mathsf{fma}\left(0.25, {\pi}^{2}, {t_0}^{2}\right)\\
t_2 := \mathsf{fma}\left(\pi, 0.5, t_0\right)\\
t_3 := {t_2}^{2}\\
\mathsf{fma}\left(\frac{0.0625 \cdot {\pi}^{4}}{\left(t_2 \cdot t_1\right) \cdot t_3}, t_3, \frac{{t_0}^{4}}{t_3} \cdot \frac{-t_2}{t_1}\right)
\end{array}
\end{array}
Initial program 8.0%
acos-asin8.0%
flip--8.0%
div-sub8.0%
flip--8.0%
Applied egg-rr8.0%
Applied egg-rr11.4%
add-sqr-sqrt_binary6411.4%
Applied rewrite-once11.4%
rem-square-sqrt11.4%
Simplified11.4%
Final simplification11.4%
(FPCore (x)
:precision binary64
(let* ((t_0 (asin (- 1.0 x)))
(t_1 (fma PI 0.5 t_0))
(t_2 (fma 0.25 (pow PI 2.0) (pow t_0 2.0))))
(fma
(pow PI 4.0)
(/ (/ 0.0625 t_1) t_2)
(* (* (pow t_0 4.0) (/ (- t_1) t_2)) (pow t_1 -2.0)))))
double code(double x) {
double t_0 = asin((1.0 - x));
double t_1 = fma(((double) M_PI), 0.5, t_0);
double t_2 = fma(0.25, pow(((double) M_PI), 2.0), pow(t_0, 2.0));
return fma(pow(((double) M_PI), 4.0), ((0.0625 / t_1) / t_2), ((pow(t_0, 4.0) * (-t_1 / t_2)) * pow(t_1, -2.0)));
}
function code(x) t_0 = asin(Float64(1.0 - x)) t_1 = fma(pi, 0.5, t_0) t_2 = fma(0.25, (pi ^ 2.0), (t_0 ^ 2.0)) return fma((pi ^ 4.0), Float64(Float64(0.0625 / t_1) / t_2), Float64(Float64((t_0 ^ 4.0) * Float64(Float64(-t_1) / t_2)) * (t_1 ^ -2.0))) end
code[x_] := Block[{t$95$0 = N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(Pi * 0.5 + t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(0.25 * N[Power[Pi, 2.0], $MachinePrecision] + N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]}, N[(N[Power[Pi, 4.0], $MachinePrecision] * N[(N[(0.0625 / t$95$1), $MachinePrecision] / t$95$2), $MachinePrecision] + N[(N[(N[Power[t$95$0, 4.0], $MachinePrecision] * N[((-t$95$1) / t$95$2), $MachinePrecision]), $MachinePrecision] * N[Power[t$95$1, -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
t_1 := \mathsf{fma}\left(\pi, 0.5, t_0\right)\\
t_2 := \mathsf{fma}\left(0.25, {\pi}^{2}, {t_0}^{2}\right)\\
\mathsf{fma}\left({\pi}^{4}, \frac{\frac{0.0625}{t_1}}{t_2}, \left({t_0}^{4} \cdot \frac{-t_1}{t_2}\right) \cdot {t_1}^{-2}\right)
\end{array}
\end{array}
Initial program 8.0%
acos-asin8.0%
flip--8.0%
div-sub8.0%
flip--8.0%
Applied egg-rr8.0%
Applied egg-rr11.4%
add-sqr-sqrt_binary6411.4%
Applied rewrite-once11.4%
rem-square-sqrt11.4%
Simplified11.4%
fma-udef8.0%
+-commutative8.0%
Applied egg-rr8.0%
+-commutative8.0%
fma-def11.4%
associate-*r*11.4%
Simplified11.4%
Final simplification11.4%
(FPCore (x) :precision binary64 (let* ((t_0 (asin (- 1.0 x)))) (/ (fma t_0 t_0 (* (pow PI 2.0) -0.25)) (- (* PI -0.5) t_0))))
double code(double x) {
double t_0 = asin((1.0 - x));
return fma(t_0, t_0, (pow(((double) M_PI), 2.0) * -0.25)) / ((((double) M_PI) * -0.5) - t_0);
}
function code(x) t_0 = asin(Float64(1.0 - x)) return Float64(fma(t_0, t_0, Float64((pi ^ 2.0) * -0.25)) / Float64(Float64(pi * -0.5) - t_0)) end
code[x_] := Block[{t$95$0 = N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, N[(N[(t$95$0 * t$95$0 + N[(N[Power[Pi, 2.0], $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision] / N[(N[(Pi * -0.5), $MachinePrecision] - t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
\frac{\mathsf{fma}\left(t_0, t_0, {\pi}^{2} \cdot -0.25\right)}{\pi \cdot -0.5 - t_0}
\end{array}
\end{array}
Initial program 8.0%
acos-asin8.0%
sub-neg8.0%
+-commutative8.0%
flip-+8.0%
sqr-neg8.0%
pow28.0%
pow28.0%
div-inv8.0%
metadata-eval8.0%
div-inv8.0%
metadata-eval8.0%
Applied egg-rr8.0%
sub-neg8.0%
distribute-rgt-neg-in8.0%
metadata-eval8.0%
Applied egg-rr8.0%
+-commutative8.0%
sub-neg8.0%
Simplified8.0%
unpow28.0%
fma-neg11.4%
unpow-prod-down11.4%
distribute-rgt-neg-in11.4%
metadata-eval11.4%
metadata-eval11.4%
Applied egg-rr11.4%
Final simplification11.4%
(FPCore (x) :precision binary64 (let* ((t_0 (asin (- 1.0 x)))) (/ 1.0 (/ (/ 2.0 (- t_0)) (fma PI (/ -1.0 t_0) 2.0)))))
double code(double x) {
double t_0 = asin((1.0 - x));
return 1.0 / ((2.0 / -t_0) / fma(((double) M_PI), (-1.0 / t_0), 2.0));
}
function code(x) t_0 = asin(Float64(1.0 - x)) return Float64(1.0 / Float64(Float64(2.0 / Float64(-t_0)) / fma(pi, Float64(-1.0 / t_0), 2.0))) end
code[x_] := Block[{t$95$0 = N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, N[(1.0 / N[(N[(2.0 / (-t$95$0)), $MachinePrecision] / N[(Pi * N[(-1.0 / t$95$0), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
\frac{1}{\frac{\frac{2}{-t_0}}{\mathsf{fma}\left(\pi, \frac{-1}{t_0}, 2\right)}}
\end{array}
\end{array}
Initial program 8.0%
acos-asin8.0%
sub-neg8.0%
div-inv8.0%
metadata-eval8.0%
Applied egg-rr8.0%
sub-neg8.0%
Simplified8.0%
/-rgt-identity8.0%
clear-num8.0%
Applied egg-rr8.0%
metadata-eval8.0%
div-inv8.0%
frac-2neg8.0%
metadata-eval8.0%
frac-sub7.9%
clear-num8.0%
frac-2neg8.0%
metadata-eval8.0%
distribute-neg-frac8.0%
metadata-eval8.0%
un-div-inv8.0%
metadata-eval8.0%
fma-neg11.3%
Applied egg-rr11.3%
Final simplification11.3%
(FPCore (x) :precision binary64 (let* ((t_0 (asin (- 1.0 x)))) (* (fma PI (/ -1.0 t_0) 2.0) (* t_0 -0.5))))
double code(double x) {
double t_0 = asin((1.0 - x));
return fma(((double) M_PI), (-1.0 / t_0), 2.0) * (t_0 * -0.5);
}
function code(x) t_0 = asin(Float64(1.0 - x)) return Float64(fma(pi, Float64(-1.0 / t_0), 2.0) * Float64(t_0 * -0.5)) end
code[x_] := Block[{t$95$0 = N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]}, N[(N[(Pi * N[(-1.0 / t$95$0), $MachinePrecision] + 2.0), $MachinePrecision] * N[(t$95$0 * -0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(1 - x\right)\\
\mathsf{fma}\left(\pi, \frac{-1}{t_0}, 2\right) \cdot \left(t_0 \cdot -0.5\right)
\end{array}
\end{array}
Initial program 8.0%
acos-asin8.0%
sub-neg8.0%
div-inv8.0%
metadata-eval8.0%
Applied egg-rr8.0%
sub-neg8.0%
Simplified8.0%
/-rgt-identity8.0%
clear-num8.0%
Applied egg-rr8.0%
metadata-eval8.0%
div-inv8.0%
frac-2neg8.0%
metadata-eval8.0%
frac-sub7.9%
div-inv7.9%
metadata-eval7.9%
fma-neg11.3%
distribute-neg-frac11.3%
metadata-eval11.3%
metadata-eval11.3%
frac-2neg11.3%
metadata-eval11.3%
distribute-neg-frac11.3%
metadata-eval11.3%
Applied egg-rr11.3%
associate-/r/11.3%
metadata-eval11.3%
mul-1-neg11.3%
associate-*r*11.3%
metadata-eval11.3%
Simplified11.3%
Final simplification11.3%
(FPCore (x) :precision binary64 (/ 1.0 (/ 1.0 (log (exp (acos (- 1.0 x)))))))
double code(double x) {
return 1.0 / (1.0 / log(exp(acos((1.0 - x)))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (1.0d0 / log(exp(acos((1.0d0 - x)))))
end function
public static double code(double x) {
return 1.0 / (1.0 / Math.log(Math.exp(Math.acos((1.0 - x)))));
}
def code(x): return 1.0 / (1.0 / math.log(math.exp(math.acos((1.0 - x)))))
function code(x) return Float64(1.0 / Float64(1.0 / log(exp(acos(Float64(1.0 - x)))))) end
function tmp = code(x) tmp = 1.0 / (1.0 / log(exp(acos((1.0 - x))))); end
code[x_] := N[(1.0 / N[(1.0 / N[Log[N[Exp[N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{1}{\log \left(e^{\cos^{-1} \left(1 - x\right)}\right)}}
\end{array}
Initial program 8.0%
acos-asin8.0%
flip3--8.0%
clear-num8.0%
clear-num8.0%
flip3--8.0%
acos-asin8.0%
Applied egg-rr8.0%
add-log-exp_binary648.0%
Applied rewrite-once8.0%
Final simplification8.0%
(FPCore (x) :precision binary64 (log (exp (acos (- 1.0 x)))))
double code(double x) {
return log(exp(acos((1.0 - x))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = log(exp(acos((1.0d0 - x))))
end function
public static double code(double x) {
return Math.log(Math.exp(Math.acos((1.0 - x))));
}
def code(x): return math.log(math.exp(math.acos((1.0 - x))))
function code(x) return log(exp(acos(Float64(1.0 - x)))) end
function tmp = code(x) tmp = log(exp(acos((1.0 - x)))); end
code[x_] := N[Log[N[Exp[N[ArcCos[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(e^{\cos^{-1} \left(1 - x\right)}\right)
\end{array}
Initial program 8.0%
add-log-exp_binary648.0%
Applied rewrite-once8.0%
Final simplification8.0%
(FPCore (x) :precision binary64 (/ 1.0 (/ 1.0 (- (* PI 0.5) (asin (- 1.0 x))))))
double code(double x) {
return 1.0 / (1.0 / ((((double) M_PI) * 0.5) - asin((1.0 - x))));
}
public static double code(double x) {
return 1.0 / (1.0 / ((Math.PI * 0.5) - Math.asin((1.0 - x))));
}
def code(x): return 1.0 / (1.0 / ((math.pi * 0.5) - math.asin((1.0 - x))))
function code(x) return Float64(1.0 / Float64(1.0 / Float64(Float64(pi * 0.5) - asin(Float64(1.0 - x))))) end
function tmp = code(x) tmp = 1.0 / (1.0 / ((pi * 0.5) - asin((1.0 - x)))); end
code[x_] := N[(1.0 / N[(1.0 / N[(N[(Pi * 0.5), $MachinePrecision] - N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{1}{\pi \cdot 0.5 - \sin^{-1} \left(1 - x\right)}}
\end{array}
Initial program 8.0%
acos-asin8.0%
flip3--8.0%
clear-num8.0%
clear-num8.0%
flip3--8.0%
acos-asin8.0%
Applied egg-rr8.0%
acos-asin8.0%
sub-neg8.0%
div-inv8.0%
metadata-eval8.0%
Applied egg-rr8.0%
sub-neg8.0%
Simplified8.0%
Final simplification8.0%
(FPCore (x) :precision binary64 (- (* PI 0.5) (asin (- 1.0 x))))
double code(double x) {
return (((double) M_PI) * 0.5) - asin((1.0 - x));
}
public static double code(double x) {
return (Math.PI * 0.5) - Math.asin((1.0 - x));
}
def code(x): return (math.pi * 0.5) - math.asin((1.0 - x))
function code(x) return Float64(Float64(pi * 0.5) - asin(Float64(1.0 - x))) end
function tmp = code(x) tmp = (pi * 0.5) - asin((1.0 - x)); end
code[x_] := N[(N[(Pi * 0.5), $MachinePrecision] - N[ArcSin[N[(1.0 - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\pi \cdot 0.5 - \sin^{-1} \left(1 - x\right)
\end{array}
Initial program 8.0%
acos-asin8.0%
sub-neg8.0%
div-inv8.0%
metadata-eval8.0%
Applied egg-rr8.0%
sub-neg8.0%
Simplified8.0%
Final simplification8.0%
(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 8.0%
acos-asin8.0%
flip3--8.0%
clear-num8.0%
clear-num8.0%
flip3--8.0%
acos-asin8.0%
Applied egg-rr8.0%
Final simplification8.0%
(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 8.0%
Final simplification8.0%
(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 2023297
(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)))