
(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 (exp (log (acos (/ (fma (pow v 2.0) -5.0 1.0) (fma v v -1.0))))))
double code(double v) {
return exp(log(acos((fma(pow(v, 2.0), -5.0, 1.0) / fma(v, v, -1.0)))));
}
function code(v) return exp(log(acos(Float64(fma((v ^ 2.0), -5.0, 1.0) / fma(v, v, -1.0))))) end
code[v_] := N[Exp[N[Log[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]
\begin{array}{l}
\\
e^{\log \cos^{-1} \left(\frac{\mathsf{fma}\left({v}^{2}, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)}
\end{array}
Initial program 99.2%
sub-neg99.2%
sqr-neg99.2%
*-commutative99.2%
distribute-rgt-neg-in99.2%
sqr-neg99.2%
metadata-eval99.2%
fma-neg99.2%
metadata-eval99.2%
Simplified99.2%
+-commutative99.2%
fma-undefine99.2%
add-exp-log99.2%
pow299.2%
Applied egg-rr99.2%
Final simplification99.2%
(FPCore (v) :precision binary64 (+ (+ 1.0 (acos (/ (fma (pow v 2.0) -5.0 1.0) (fma v v -1.0)))) -1.0))
double code(double v) {
return (1.0 + acos((fma(pow(v, 2.0), -5.0, 1.0) / fma(v, v, -1.0)))) + -1.0;
}
function code(v) return Float64(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[(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] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(1 + \cos^{-1} \left(\frac{\mathsf{fma}\left({v}^{2}, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right) + -1
\end{array}
Initial program 99.2%
sub-neg99.2%
sqr-neg99.2%
*-commutative99.2%
distribute-rgt-neg-in99.2%
sqr-neg99.2%
metadata-eval99.2%
fma-neg99.2%
metadata-eval99.2%
Simplified99.2%
+-commutative99.2%
fma-undefine99.2%
expm1-log1p-u99.2%
pow299.2%
Applied egg-rr99.2%
expm1-undefine99.2%
log1p-undefine99.2%
rem-exp-log99.2%
Applied egg-rr99.2%
Final simplification99.2%
(FPCore (v) :precision binary64 (acos (/ (fma (* v v) -5.0 1.0) (fma v v -1.0))))
double code(double v) {
return acos((fma((v * v), -5.0, 1.0) / fma(v, v, -1.0)));
}
function code(v) return acos(Float64(fma(Float64(v * v), -5.0, 1.0) / fma(v, v, -1.0))) end
code[v_] := N[ArcCos[N[(N[(N[(v * v), $MachinePrecision] * -5.0 + 1.0), $MachinePrecision] / N[(v * v + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\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.2%
sub-neg99.2%
sqr-neg99.2%
+-commutative99.2%
*-commutative99.2%
distribute-rgt-neg-in99.2%
fma-define99.2%
sqr-neg99.2%
metadata-eval99.2%
fma-neg99.2%
metadata-eval99.2%
Simplified99.2%
Final simplification99.2%
(FPCore (v) :precision binary64 (acos (/ (+ 1.0 (* -5.0 (* v v))) (fma v v -1.0))))
double code(double v) {
return acos(((1.0 + (-5.0 * (v * v))) / fma(v, v, -1.0)));
}
function code(v) return acos(Float64(Float64(1.0 + Float64(-5.0 * Float64(v * v))) / fma(v, v, -1.0))) end
code[v_] := N[ArcCos[N[(N[(1.0 + N[(-5.0 * N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(v * v + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\frac{1 + -5 \cdot \left(v \cdot v\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)
\end{array}
Initial program 99.2%
sub-neg99.2%
sqr-neg99.2%
*-commutative99.2%
distribute-rgt-neg-in99.2%
sqr-neg99.2%
metadata-eval99.2%
fma-neg99.2%
metadata-eval99.2%
Simplified99.2%
Final simplification99.2%
(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.2%
Final simplification99.2%
(FPCore (v) :precision binary64 (acos (* (+ 1.0 (* v 2.0)) (+ (* v 2.0) -1.0))))
double code(double v) {
return acos(((1.0 + (v * 2.0)) * ((v * 2.0) + -1.0)));
}
real(8) function code(v)
real(8), intent (in) :: v
code = acos(((1.0d0 + (v * 2.0d0)) * ((v * 2.0d0) + (-1.0d0))))
end function
public static double code(double v) {
return Math.acos(((1.0 + (v * 2.0)) * ((v * 2.0) + -1.0)));
}
def code(v): return math.acos(((1.0 + (v * 2.0)) * ((v * 2.0) + -1.0)))
function code(v) return acos(Float64(Float64(1.0 + Float64(v * 2.0)) * Float64(Float64(v * 2.0) + -1.0))) end
function tmp = code(v) tmp = acos(((1.0 + (v * 2.0)) * ((v * 2.0) + -1.0))); end
code[v_] := N[ArcCos[N[(N[(1.0 + N[(v * 2.0), $MachinePrecision]), $MachinePrecision] * N[(N[(v * 2.0), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\left(1 + v \cdot 2\right) \cdot \left(v \cdot 2 + -1\right)\right)
\end{array}
Initial program 99.2%
sub-neg99.2%
sqr-neg99.2%
*-commutative99.2%
distribute-rgt-neg-in99.2%
sqr-neg99.2%
metadata-eval99.2%
fma-neg99.2%
metadata-eval99.2%
Simplified99.2%
Taylor expanded in v around 0 97.9%
add-sqr-sqrt97.9%
difference-of-sqr-197.8%
*-commutative97.8%
sqrt-prod97.8%
sqrt-pow196.6%
metadata-eval96.6%
pow196.6%
metadata-eval96.6%
*-commutative96.6%
sqrt-prod96.6%
sqrt-pow197.8%
metadata-eval97.8%
pow197.8%
metadata-eval97.8%
Applied egg-rr97.8%
Final simplification97.8%
(FPCore (v) :precision binary64 (acos (/ (- 1.0 (* (* v v) 5.0)) -1.0)))
double code(double v) {
return acos(((1.0 - ((v * v) * 5.0)) / -1.0));
}
real(8) function code(v)
real(8), intent (in) :: v
code = acos(((1.0d0 - ((v * v) * 5.0d0)) / (-1.0d0)))
end function
public static double code(double v) {
return Math.acos(((1.0 - ((v * v) * 5.0)) / -1.0));
}
def code(v): return math.acos(((1.0 - ((v * v) * 5.0)) / -1.0))
function code(v) return acos(Float64(Float64(1.0 - Float64(Float64(v * v) * 5.0)) / -1.0)) end
function tmp = code(v) tmp = acos(((1.0 - ((v * v) * 5.0)) / -1.0)); end
code[v_] := N[ArcCos[N[(N[(1.0 - N[(N[(v * v), $MachinePrecision] * 5.0), $MachinePrecision]), $MachinePrecision] / -1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\frac{1 - \left(v \cdot v\right) \cdot 5}{-1}\right)
\end{array}
Initial program 99.2%
difference-of-sqr-198.5%
*-commutative98.5%
sub-neg98.5%
metadata-eval98.5%
+-commutative98.5%
Applied egg-rr98.5%
Taylor expanded in v around 0 97.0%
Final simplification97.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 99.2%
sub-neg99.2%
sqr-neg99.2%
*-commutative99.2%
distribute-rgt-neg-in99.2%
sqr-neg99.2%
metadata-eval99.2%
fma-neg99.2%
metadata-eval99.2%
Simplified99.2%
Taylor expanded in v around 0 96.8%
Final simplification96.8%
herbie shell --seed 2024077
(FPCore (v)
:name "Falkner and Boettcher, Appendix B, 1"
:precision binary64
(acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))