
(FPCore (v) :precision binary64 (acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))
double code(double v) {
return acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
}
real(8) function code(v)
real(8), intent (in) :: v
code = acos(((1.0d0 - (5.0d0 * (v * v))) / ((v * v) - 1.0d0)))
end function
public static double code(double v) {
return Math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
}
def code(v): return math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)))
function code(v) return acos(Float64(Float64(1.0 - Float64(5.0 * Float64(v * v))) / Float64(Float64(v * v) - 1.0))) end
function tmp = code(v) tmp = acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0))); end
code[v_] := N[ArcCos[N[(N[(1.0 - N[(5.0 * N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(v * v), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (v) :precision binary64 (acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))
double code(double v) {
return acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
}
real(8) function code(v)
real(8), intent (in) :: v
code = acos(((1.0d0 - (5.0d0 * (v * v))) / ((v * v) - 1.0d0)))
end function
public static double code(double v) {
return Math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
}
def code(v): return math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)))
function code(v) return acos(Float64(Float64(1.0 - Float64(5.0 * Float64(v * v))) / Float64(Float64(v * v) - 1.0))) end
function tmp = code(v) tmp = acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0))); end
code[v_] := N[ArcCos[N[(N[(1.0 - N[(5.0 * N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(v * v), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right)
\end{array}
(FPCore (v)
:precision binary64
(expm1
(log1p
(acos
(+
(* (pow v 2.0) (+ 4.0 (* (pow v 2.0) (+ 4.0 (* (pow v 2.0) 4.0)))))
-1.0)))))
double code(double v) {
return expm1(log1p(acos(((pow(v, 2.0) * (4.0 + (pow(v, 2.0) * (4.0 + (pow(v, 2.0) * 4.0))))) + -1.0))));
}
public static double code(double v) {
return Math.expm1(Math.log1p(Math.acos(((Math.pow(v, 2.0) * (4.0 + (Math.pow(v, 2.0) * (4.0 + (Math.pow(v, 2.0) * 4.0))))) + -1.0))));
}
def code(v): return math.expm1(math.log1p(math.acos(((math.pow(v, 2.0) * (4.0 + (math.pow(v, 2.0) * (4.0 + (math.pow(v, 2.0) * 4.0))))) + -1.0))))
function code(v) return expm1(log1p(acos(Float64(Float64((v ^ 2.0) * Float64(4.0 + Float64((v ^ 2.0) * Float64(4.0 + Float64((v ^ 2.0) * 4.0))))) + -1.0)))) end
code[v_] := N[(Exp[N[Log[1 + N[ArcCos[N[(N[(N[Power[v, 2.0], $MachinePrecision] * N[(4.0 + N[(N[Power[v, 2.0], $MachinePrecision] * N[(4.0 + N[(N[Power[v, 2.0], $MachinePrecision] * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left({v}^{2} \cdot \left(4 + {v}^{2} \cdot \left(4 + {v}^{2} \cdot 4\right)\right) + -1\right)\right)\right)
\end{array}
Initial program 98.9%
expm1-log1p-u98.9%
sub-neg98.9%
*-commutative98.9%
distribute-rgt-neg-in98.9%
pow298.9%
metadata-eval98.9%
fmm-def98.9%
metadata-eval98.9%
Applied egg-rr98.9%
Taylor expanded in v around 0 98.9%
Final simplification98.9%
(FPCore (v) :precision binary64 (+ (expm1 (log1p (+ 1.0 (acos (/ (fma (pow v 2.0) -5.0 1.0) (fma v v -1.0)))))) -1.0))
double code(double v) {
return expm1(log1p((1.0 + acos((fma(pow(v, 2.0), -5.0, 1.0) / fma(v, v, -1.0)))))) + -1.0;
}
function code(v) return Float64(expm1(log1p(Float64(1.0 + acos(Float64(fma((v ^ 2.0), -5.0, 1.0) / fma(v, v, -1.0)))))) + -1.0) end
code[v_] := N[(N[(Exp[N[Log[1 + N[(1.0 + N[ArcCos[N[(N[(N[Power[v, 2.0], $MachinePrecision] * -5.0 + 1.0), $MachinePrecision] / N[(v * v + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{expm1}\left(\mathsf{log1p}\left(1 + \cos^{-1} \left(\frac{\mathsf{fma}\left({v}^{2}, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right)\right) + -1
\end{array}
Initial program 98.9%
expm1-log1p-u98.9%
sub-neg98.9%
*-commutative98.9%
distribute-rgt-neg-in98.9%
pow298.9%
metadata-eval98.9%
fmm-def98.9%
metadata-eval98.9%
Applied egg-rr98.9%
expm1-undefine98.9%
log1p-undefine98.9%
rem-exp-log98.9%
+-commutative98.9%
pow298.9%
*-commutative98.9%
fma-define98.9%
pow298.9%
Applied egg-rr98.9%
expm1-log1p-u98.9%
log1p-undefine98.9%
+-commutative98.9%
associate-+l+98.9%
+-commutative98.9%
associate-+l+98.9%
fma-undefine98.9%
*-commutative98.9%
fma-define98.9%
metadata-eval98.9%
Applied egg-rr98.9%
log1p-expm1-u98.9%
expm1-undefine98.9%
add-exp-log98.9%
fma-undefine98.9%
*-commutative98.9%
fma-undefine98.9%
associate--l+98.9%
metadata-eval98.9%
+-commutative98.9%
acos-asin98.9%
acos-asin98.9%
Applied egg-rr98.9%
Final simplification98.9%
(FPCore (v) :precision binary64 (+ (expm1 (log (+ 2.0 (acos (/ (- 1.0 (* (pow v 2.0) 5.0)) (+ (pow v 2.0) -1.0)))))) -1.0))
double code(double v) {
return expm1(log((2.0 + acos(((1.0 - (pow(v, 2.0) * 5.0)) / (pow(v, 2.0) + -1.0)))))) + -1.0;
}
public static double code(double v) {
return Math.expm1(Math.log((2.0 + Math.acos(((1.0 - (Math.pow(v, 2.0) * 5.0)) / (Math.pow(v, 2.0) + -1.0)))))) + -1.0;
}
def code(v): return math.expm1(math.log((2.0 + math.acos(((1.0 - (math.pow(v, 2.0) * 5.0)) / (math.pow(v, 2.0) + -1.0)))))) + -1.0
function code(v) return Float64(expm1(log(Float64(2.0 + acos(Float64(Float64(1.0 - Float64((v ^ 2.0) * 5.0)) / Float64((v ^ 2.0) + -1.0)))))) + -1.0) end
code[v_] := N[(N[(Exp[N[Log[N[(2.0 + N[ArcCos[N[(N[(1.0 - N[(N[Power[v, 2.0], $MachinePrecision] * 5.0), $MachinePrecision]), $MachinePrecision] / N[(N[Power[v, 2.0], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{expm1}\left(\log \left(2 + \cos^{-1} \left(\frac{1 - {v}^{2} \cdot 5}{{v}^{2} + -1}\right)\right)\right) + -1
\end{array}
Initial program 98.9%
expm1-log1p-u98.9%
sub-neg98.9%
*-commutative98.9%
distribute-rgt-neg-in98.9%
pow298.9%
metadata-eval98.9%
fmm-def98.9%
metadata-eval98.9%
Applied egg-rr98.9%
expm1-undefine98.9%
log1p-undefine98.9%
rem-exp-log98.9%
+-commutative98.9%
pow298.9%
*-commutative98.9%
fma-define98.9%
pow298.9%
Applied egg-rr98.9%
expm1-log1p-u98.9%
log1p-undefine98.9%
+-commutative98.9%
associate-+l+98.9%
+-commutative98.9%
associate-+l+98.9%
fma-undefine98.9%
*-commutative98.9%
fma-define98.9%
metadata-eval98.9%
Applied egg-rr98.9%
Taylor expanded in v around inf 98.9%
Final simplification98.9%
(FPCore (v) :precision binary64 (expm1 (log1p (acos (/ (+ 1.0 (* (pow v 2.0) -5.0)) (fma v v -1.0))))))
double code(double v) {
return expm1(log1p(acos(((1.0 + (pow(v, 2.0) * -5.0)) / fma(v, v, -1.0)))));
}
function code(v) return expm1(log1p(acos(Float64(Float64(1.0 + Float64((v ^ 2.0) * -5.0)) / fma(v, v, -1.0))))) end
code[v_] := N[(Exp[N[Log[1 + N[ArcCos[N[(N[(1.0 + N[(N[Power[v, 2.0], $MachinePrecision] * -5.0), $MachinePrecision]), $MachinePrecision] / N[(v * v + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{1 + {v}^{2} \cdot -5}{\mathsf{fma}\left(v, v, -1\right)}\right)\right)\right)
\end{array}
Initial program 98.9%
expm1-log1p-u98.9%
sub-neg98.9%
*-commutative98.9%
distribute-rgt-neg-in98.9%
pow298.9%
metadata-eval98.9%
fmm-def98.9%
metadata-eval98.9%
Applied egg-rr98.9%
(FPCore (v) :precision binary64 (acos (/ (- 1.0 (* 5.0 (* v v))) (+ (* v v) -1.0))))
double code(double v) {
return acos(((1.0 - (5.0 * (v * v))) / ((v * v) + -1.0)));
}
real(8) function code(v)
real(8), intent (in) :: v
code = acos(((1.0d0 - (5.0d0 * (v * v))) / ((v * v) + (-1.0d0))))
end function
public static double code(double v) {
return Math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) + -1.0)));
}
def code(v): return math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) + -1.0)))
function code(v) return acos(Float64(Float64(1.0 - Float64(5.0 * Float64(v * v))) / Float64(Float64(v * v) + -1.0))) end
function tmp = code(v) tmp = acos(((1.0 - (5.0 * (v * v))) / ((v * v) + -1.0))); end
code[v_] := N[ArcCos[N[(N[(1.0 - N[(5.0 * N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(v * v), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v + -1}\right)
\end{array}
Initial program 98.9%
Final simplification98.9%
(FPCore (v) :precision binary64 (acos (/ (- 1.0 (* 5.0 (* v v))) -1.0)))
double code(double v) {
return acos(((1.0 - (5.0 * (v * v))) / -1.0));
}
real(8) function code(v)
real(8), intent (in) :: v
code = acos(((1.0d0 - (5.0d0 * (v * v))) / (-1.0d0)))
end function
public static double code(double v) {
return Math.acos(((1.0 - (5.0 * (v * v))) / -1.0));
}
def code(v): return math.acos(((1.0 - (5.0 * (v * v))) / -1.0))
function code(v) return acos(Float64(Float64(1.0 - Float64(5.0 * Float64(v * v))) / -1.0)) end
function tmp = code(v) tmp = acos(((1.0 - (5.0 * (v * v))) / -1.0)); end
code[v_] := N[ArcCos[N[(N[(1.0 - N[(5.0 * N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / -1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{-1}\right)
\end{array}
Initial program 98.9%
Taylor expanded in v around 0 98.0%
(FPCore (v) :precision binary64 (acos -1.0))
double code(double v) {
return acos(-1.0);
}
real(8) function code(v)
real(8), intent (in) :: v
code = acos((-1.0d0))
end function
public static double code(double v) {
return Math.acos(-1.0);
}
def code(v): return math.acos(-1.0)
function code(v) return acos(-1.0) end
function tmp = code(v) tmp = acos(-1.0); end
code[v_] := N[ArcCos[-1.0], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} -1
\end{array}
Initial program 98.9%
Taylor expanded in v around 0 96.6%
Taylor expanded in v around 0 97.8%
(FPCore (v) :precision binary64 (acos -5.0))
double code(double v) {
return acos(-5.0);
}
real(8) function code(v)
real(8), intent (in) :: v
code = acos((-5.0d0))
end function
public static double code(double v) {
return Math.acos(-5.0);
}
def code(v): return math.acos(-5.0)
function code(v) return acos(-5.0) end
function tmp = code(v) tmp = acos(-5.0); end
code[v_] := N[ArcCos[-5.0], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} -5
\end{array}
Initial program 98.9%
Taylor expanded in v around inf 0.0%
herbie shell --seed 2024184
(FPCore (v)
:name "Falkner and Boettcher, Appendix B, 1"
:precision binary64
(acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))