
(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 4 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
(let* ((t_0
(log (cbrt (exp (acos (/ (fma (* v v) -5.0 1.0) (fma v v -1.0))))))))
(+ t_0 (* 2.0 t_0))))
double code(double v) {
double t_0 = log(cbrt(exp(acos((fma((v * v), -5.0, 1.0) / fma(v, v, -1.0))))));
return t_0 + (2.0 * t_0);
}
function code(v) t_0 = log(cbrt(exp(acos(Float64(fma(Float64(v * v), -5.0, 1.0) / fma(v, v, -1.0)))))) return Float64(t_0 + Float64(2.0 * t_0)) end
code[v_] := Block[{t$95$0 = N[Log[N[Power[N[Exp[N[ArcCos[N[(N[(N[(v * v), $MachinePrecision] * -5.0 + 1.0), $MachinePrecision] / N[(v * v + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision]], $MachinePrecision]}, N[(t$95$0 + N[(2.0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \log \left(\sqrt[3]{e^{\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)}}\right)\\
t_0 + 2 \cdot t_0
\end{array}
\end{array}
Initial program 99.4%
add-log-exp99.4%
add-cube-cbrt99.4%
log-prod99.5%
Applied egg-rr99.5%
log-prod99.5%
count-299.5%
Simplified99.5%
Final simplification99.5%
(FPCore (v) :precision binary64 (* (* (acos (/ (fma (* v v) -5.0 1.0) (fma v v -1.0))) 0.3333333333333333) 3.0))
double code(double v) {
return (acos((fma((v * v), -5.0, 1.0) / fma(v, v, -1.0))) * 0.3333333333333333) * 3.0;
}
function code(v) return Float64(Float64(acos(Float64(fma(Float64(v * v), -5.0, 1.0) / fma(v, v, -1.0))) * 0.3333333333333333) * 3.0) end
code[v_] := N[(N[(N[ArcCos[N[(N[(N[(v * v), $MachinePrecision] * -5.0 + 1.0), $MachinePrecision] / N[(v * v + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 0.3333333333333333), $MachinePrecision] * 3.0), $MachinePrecision]
\begin{array}{l}
\\
\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right) \cdot 0.3333333333333333\right) \cdot 3
\end{array}
Initial program 99.4%
add-log-exp99.4%
add-cube-cbrt99.4%
log-prod99.5%
Applied egg-rr99.5%
log-prod99.5%
count-299.5%
Simplified99.5%
*-un-lft-identity99.5%
distribute-rgt-out99.5%
pow1/399.4%
log-pow99.4%
add-log-exp99.4%
metadata-eval99.4%
Applied egg-rr99.4%
Final simplification99.4%
(FPCore (v) :precision binary64 (acos (/ (- 1.0 (* (* v v) 5.0)) (+ (* v v) -1.0))))
double code(double v) {
return acos(((1.0 - ((v * v) * 5.0)) / ((v * v) + -1.0)));
}
real(8) function code(v)
real(8), intent (in) :: v
code = acos(((1.0d0 - ((v * v) * 5.0d0)) / ((v * v) + (-1.0d0))))
end function
public static double code(double v) {
return Math.acos(((1.0 - ((v * v) * 5.0)) / ((v * v) + -1.0)));
}
def code(v): return math.acos(((1.0 - ((v * v) * 5.0)) / ((v * v) + -1.0)))
function code(v) return acos(Float64(Float64(1.0 - Float64(Float64(v * v) * 5.0)) / Float64(Float64(v * v) + -1.0))) end
function tmp = code(v) tmp = acos(((1.0 - ((v * v) * 5.0)) / ((v * v) + -1.0))); end
code[v_] := N[ArcCos[N[(N[(1.0 - N[(N[(v * v), $MachinePrecision] * 5.0), $MachinePrecision]), $MachinePrecision] / N[(N[(v * v), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\frac{1 - \left(v \cdot v\right) \cdot 5}{v \cdot v + -1}\right)
\end{array}
Initial program 99.4%
Final simplification99.4%
(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 99.4%
Taylor expanded in v around 0 98.1%
Final simplification98.1%
herbie shell --seed 2023222
(FPCore (v)
:name "Falkner and Boettcher, Appendix B, 1"
:precision binary64
(acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))