
(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 3 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
(exp
(*
(log
(pow (acos (/ (fma (* v v) -5.0 1.0) (fma v v -1.0))) 0.16666666666666666))
6.0)))
double code(double v) {
return exp((log(pow(acos((fma((v * v), -5.0, 1.0) / fma(v, v, -1.0))), 0.16666666666666666)) * 6.0));
}
function code(v) return exp(Float64(log((acos(Float64(fma(Float64(v * v), -5.0, 1.0) / fma(v, v, -1.0))) ^ 0.16666666666666666)) * 6.0)) end
code[v_] := N[Exp[N[(N[Log[N[Power[N[ArcCos[N[(N[(N[(v * v), $MachinePrecision] * -5.0 + 1.0), $MachinePrecision] / N[(v * v + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 0.16666666666666666], $MachinePrecision]], $MachinePrecision] * 6.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\log \left({\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)}^{0.16666666666666666}\right) \cdot 6}
\end{array}
Initial program 99.4%
acos-asin99.4%
add-cube-cbrt97.0%
fma-neg97.0%
div-inv97.0%
metadata-eval97.0%
div-inv97.0%
metadata-eval97.0%
div-inv97.0%
metadata-eval97.0%
Applied egg-rr97.0%
pow1/397.9%
pow1/399.4%
pow-prod-up97.9%
metadata-eval97.9%
Applied egg-rr97.9%
metadata-eval97.9%
pow-sqr99.4%
unpow1/397.9%
unpow1/397.0%
unpow297.0%
Simplified97.0%
fma-neg97.0%
unpow297.0%
add-cube-cbrt99.4%
metadata-eval99.4%
div-inv99.4%
acos-asin99.4%
add-sqr-sqrt97.9%
unpow297.9%
add-cube-cbrt94.6%
unpow395.2%
pow-pow94.9%
Applied egg-rr99.4%
Final simplification99.4%
(FPCore (v) :precision binary64 (- PI (acos (/ (fma (* v v) -5.0 1.0) (- (fma v v -1.0))))))
double code(double v) {
return ((double) M_PI) - acos((fma((v * v), -5.0, 1.0) / -fma(v, v, -1.0)));
}
function code(v) return Float64(pi - acos(Float64(fma(Float64(v * v), -5.0, 1.0) / Float64(-fma(v, v, -1.0))))) end
code[v_] := N[(Pi - N[ArcCos[N[(N[(N[(v * v), $MachinePrecision] * -5.0 + 1.0), $MachinePrecision] / (-N[(v * v + -1.0), $MachinePrecision])), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\pi - \cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{-\mathsf{fma}\left(v, v, -1\right)}\right)
\end{array}
Initial program 99.4%
frac-2neg99.4%
distribute-frac-neg99.4%
acos-neg99.4%
sub-neg99.4%
+-commutative99.4%
*-commutative99.4%
distribute-rgt-neg-in99.4%
fma-def99.4%
metadata-eval99.4%
fma-neg99.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%
herbie shell --seed 2023213
(FPCore (v)
:name "Falkner and Boettcher, Appendix B, 1"
:precision binary64
(acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))