| Alternative 1 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 7232 |
\[\cos^{-1} \left(\frac{1 - \left(v \cdot v\right) \cdot 5}{v \cdot v + -1}\right)
\]

(FPCore (v) :precision binary64 (acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))
(FPCore (v) :precision binary64 (expm1 (log1p (acos (/ (fma (* v v) -5.0 1.0) (fma v v -1.0))))))
double code(double v) {
return acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
}
double code(double v) {
return expm1(log1p(acos((fma((v * v), -5.0, 1.0) / fma(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 code(v) return expm1(log1p(acos(Float64(fma(Float64(v * v), -5.0, 1.0) / fma(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]
code[v_] := N[(Exp[N[Log[1 + N[ArcCos[N[(N[(N[(v * v), $MachinePrecision] * -5.0 + 1.0), $MachinePrecision] / N[(v * v + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]
\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right)
\mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, -1\right)}\right)\right)\right)
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Initial program 99.4%
Applied egg-rr99.4%
[Start]99.4 | \[ \cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right)
\] |
|---|---|
expm1-log1p-u [=>]99.4 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right)\right)\right)}
\] |
sub-neg [=>]99.4 | \[ \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\color{blue}{1 + \left(-5 \cdot \left(v \cdot v\right)\right)}}{v \cdot v - 1}\right)\right)\right)
\] |
+-commutative [=>]99.4 | \[ \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\color{blue}{\left(-5 \cdot \left(v \cdot v\right)\right) + 1}}{v \cdot v - 1}\right)\right)\right)
\] |
*-commutative [=>]99.4 | \[ \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\left(-\color{blue}{\left(v \cdot v\right) \cdot 5}\right) + 1}{v \cdot v - 1}\right)\right)\right)
\] |
distribute-rgt-neg-in [=>]99.4 | \[ \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\color{blue}{\left(v \cdot v\right) \cdot \left(-5\right)} + 1}{v \cdot v - 1}\right)\right)\right)
\] |
fma-def [=>]99.4 | \[ \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\color{blue}{\mathsf{fma}\left(v \cdot v, -5, 1\right)}}{v \cdot v - 1}\right)\right)\right)
\] |
metadata-eval [=>]99.4 | \[ \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, \color{blue}{-5}, 1\right)}{v \cdot v - 1}\right)\right)\right)
\] |
fma-neg [=>]99.4 | \[ \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\color{blue}{\mathsf{fma}\left(v, v, -1\right)}}\right)\right)\right)
\] |
metadata-eval [=>]99.4 | \[ \mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\frac{\mathsf{fma}\left(v \cdot v, -5, 1\right)}{\mathsf{fma}\left(v, v, \color{blue}{-1}\right)}\right)\right)\right)
\] |
Final simplification99.4%
| Alternative 1 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 7232 |
| Alternative 2 | |
|---|---|
| Accuracy | 97.9% |
| Cost | 6464 |
herbie shell --seed 2023160
(FPCore (v)
:name "Falkner and Boettcher, Appendix B, 1"
:precision binary64
(acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))