
(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 5 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 (fma v (* v 4.0) -1.0)) 0.3333333333333333))) 3.0))
double code(double v) {
return expm1(log1p((acos(fma(v, (v * 4.0), -1.0)) * 0.3333333333333333))) * 3.0;
}
function code(v) return Float64(expm1(log1p(Float64(acos(fma(v, Float64(v * 4.0), -1.0)) * 0.3333333333333333))) * 3.0) end
code[v_] := N[(N[(Exp[N[Log[1 + N[(N[ArcCos[N[(v * N[(v * 4.0), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision] * 0.3333333333333333), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision] * 3.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\mathsf{fma}\left(v, v \cdot 4, -1\right)\right) \cdot 0.3333333333333333\right)\right) \cdot 3
\end{array}
Initial program 99.3%
add-exp-log99.3%
sub-neg99.3%
+-commutative99.3%
*-commutative99.3%
distribute-rgt-neg-in99.3%
fma-def99.3%
metadata-eval99.3%
fma-neg99.3%
metadata-eval99.3%
Applied egg-rr99.3%
Taylor expanded in v around 0 99.3%
*-commutative99.3%
unpow299.3%
associate-*r*99.3%
fma-neg99.3%
metadata-eval99.3%
Simplified99.3%
add-exp-log99.3%
add-log-exp99.3%
add-cube-cbrt99.3%
pow399.3%
exp-to-pow99.3%
*-commutative99.3%
add-log-exp99.3%
*-commutative99.3%
pow1/399.3%
log-pow99.3%
add-log-exp99.3%
Applied egg-rr99.3%
expm1-log1p-u99.3%
*-commutative99.3%
Applied egg-rr99.3%
Final simplification99.3%
(FPCore (v) :precision binary64 (exp (log (acos (fma v (* v 4.0) -1.0)))))
double code(double v) {
return exp(log(acos(fma(v, (v * 4.0), -1.0))));
}
function code(v) return exp(log(acos(fma(v, Float64(v * 4.0), -1.0)))) end
code[v_] := N[Exp[N[Log[N[ArcCos[N[(v * N[(v * 4.0), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\log \cos^{-1} \left(\mathsf{fma}\left(v, v \cdot 4, -1\right)\right)}
\end{array}
Initial program 99.3%
add-exp-log99.3%
sub-neg99.3%
+-commutative99.3%
*-commutative99.3%
distribute-rgt-neg-in99.3%
fma-def99.3%
metadata-eval99.3%
fma-neg99.3%
metadata-eval99.3%
Applied egg-rr99.3%
Taylor expanded in v around 0 99.3%
*-commutative99.3%
unpow299.3%
associate-*r*99.3%
fma-neg99.3%
metadata-eval99.3%
Simplified99.3%
Final simplification99.3%
(FPCore (v) :precision binary64 (acos (fma v (* v 4.0) -1.0)))
double code(double v) {
return acos(fma(v, (v * 4.0), -1.0));
}
function code(v) return acos(fma(v, Float64(v * 4.0), -1.0)) end
code[v_] := N[ArcCos[N[(v * N[(v * 4.0), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\mathsf{fma}\left(v, v \cdot 4, -1\right)\right)
\end{array}
Initial program 99.3%
Taylor expanded in v around 0 99.3%
unpow299.3%
*-commutative99.3%
associate-*l*99.3%
fma-neg99.3%
metadata-eval99.3%
Simplified99.3%
Final simplification99.3%
(FPCore (v) :precision binary64 (acos (/ (- 1.0 (* 5.0 (* v v))) (+ -1.0 (* v v)))))
double code(double v) {
return acos(((1.0 - (5.0 * (v * v))) / (-1.0 + (v * v))));
}
real(8) function code(v)
real(8), intent (in) :: v
code = acos(((1.0d0 - (5.0d0 * (v * v))) / ((-1.0d0) + (v * v))))
end function
public static double code(double v) {
return Math.acos(((1.0 - (5.0 * (v * v))) / (-1.0 + (v * v))));
}
def code(v): return math.acos(((1.0 - (5.0 * (v * v))) / (-1.0 + (v * v))))
function code(v) return acos(Float64(Float64(1.0 - Float64(5.0 * Float64(v * v))) / Float64(-1.0 + Float64(v * v)))) end
function tmp = code(v) tmp = acos(((1.0 - (5.0 * (v * v))) / (-1.0 + (v * v)))); end
code[v_] := N[ArcCos[N[(N[(1.0 - N[(5.0 * N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(-1.0 + N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{-1 + v \cdot v}\right)
\end{array}
Initial program 99.3%
Final simplification99.3%
(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.3%
Taylor expanded in v around 0 98.8%
Final simplification98.8%
herbie shell --seed 2023175
(FPCore (v)
:name "Falkner and Boettcher, Appendix B, 1"
:precision binary64
(acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))