| Alternative 1 | |
|---|---|
| Accuracy | 98.8% |
| Cost | 32704 |
\[\mathsf{expm1}\left(\mathsf{log1p}\left(\cos^{-1} \left(\left(4 \cdot {v}^{2} + 4 \cdot {v}^{4}\right) + -1\right)\right)\right)
\]

(FPCore (v) :precision binary64 (acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))
(FPCore (v) :precision binary64 (expm1 (log1p (acos (+ (+ (* 4.0 (pow v 2.0)) (* 4.0 (pow v 4.0))) -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((((4.0 * pow(v, 2.0)) + (4.0 * pow(v, 4.0))) + -1.0))));
}
public static double code(double v) {
return Math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
}
public static double code(double v) {
return Math.expm1(Math.log1p(Math.acos((((4.0 * Math.pow(v, 2.0)) + (4.0 * Math.pow(v, 4.0))) + -1.0))));
}
def code(v): return math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)))
def code(v): return math.expm1(math.log1p(math.acos((((4.0 * math.pow(v, 2.0)) + (4.0 * math.pow(v, 4.0))) + -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(Float64(Float64(4.0 * (v ^ 2.0)) + Float64(4.0 * (v ^ 4.0))) + -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[(4.0 * N[Power[v, 2.0], $MachinePrecision]), $MachinePrecision] + N[(4.0 * N[Power[v, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $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(\left(4 \cdot {v}^{2} + 4 \cdot {v}^{4}\right) + -1\right)\right)\right)
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
Initial program 99.3%
Applied egg-rr99.3%
[Start]99.3% | \[ \cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right)
\] |
|---|---|
expm1-log1p-u [=>]99.3% | \[ \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.3% | \[ \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.3% | \[ \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.3% | \[ \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.3% | \[ \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.3% | \[ \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.3% | \[ \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.3% | \[ \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.3% | \[ \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)
\] |
Taylor expanded in v around 0 99.3%
Final simplification99.3%
| Alternative 1 | |
|---|---|
| Accuracy | 98.8% |
| Cost | 32704 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.8% |
| Cost | 13440 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 7232 |
| Alternative 4 | |
|---|---|
| Accuracy | 98.5% |
| Cost | 6848 |
| Alternative 5 | |
|---|---|
| Accuracy | 97.8% |
| Cost | 6464 |
herbie shell --seed 2023263
(FPCore (v)
:name "Falkner and Boettcher, Appendix B, 1"
:precision binary64
(acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))