| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 32832 |
\[\mathsf{fma}\left(b + -0.5, \log c, a\right) + \mathsf{fma}\left(y, i, z + \mathsf{fma}\left(x, \log y, t\right)\right)
\]

(FPCore (x y z t a b c i) :precision binary64 (+ (+ (+ (+ (+ (* x (log y)) z) t) a) (* (- b 0.5) (log c))) (* y i)))
(FPCore (x y z t a b c i) :precision binary64 (+ (fma (+ b -0.5) (log c) a) (fma y i (+ z (fma x (log y) t)))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return (((((x * log(y)) + z) + t) + a) + ((b - 0.5) * log(c))) + (y * i);
}
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return fma((b + -0.5), log(c), a) + fma(y, i, (z + fma(x, log(y), t)));
}
function code(x, y, z, t, a, b, c, i) return Float64(Float64(Float64(Float64(Float64(Float64(x * log(y)) + z) + t) + a) + Float64(Float64(b - 0.5) * log(c))) + Float64(y * i)) end
function code(x, y, z, t, a, b, c, i) return Float64(fma(Float64(b + -0.5), log(c), a) + fma(y, i, Float64(z + fma(x, log(y), t)))) end
code[x_, y_, z_, t_, a_, b_, c_, i_] := N[(N[(N[(N[(N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision] + t), $MachinePrecision] + a), $MachinePrecision] + N[(N[(b - 0.5), $MachinePrecision] * N[Log[c], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(y * i), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_, c_, i_] := N[(N[(N[(b + -0.5), $MachinePrecision] * N[Log[c], $MachinePrecision] + a), $MachinePrecision] + N[(y * i + N[(z + N[(x * N[Log[y], $MachinePrecision] + t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(\left(\left(\left(x \cdot \log y + z\right) + t\right) + a\right) + \left(b - 0.5\right) \cdot \log c\right) + y \cdot i
\mathsf{fma}\left(b + -0.5, \log c, a\right) + \mathsf{fma}\left(y, i, z + \mathsf{fma}\left(x, \log y, t\right)\right)
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Initial program 99.9%
Simplified99.9%
[Start]99.9% | \[ \left(\left(\left(\left(x \cdot \log y + z\right) + t\right) + a\right) + \left(b - 0.5\right) \cdot \log c\right) + y \cdot i
\] |
|---|---|
associate-+l+ [=>]99.9% | \[ \color{blue}{\left(\left(\left(x \cdot \log y + z\right) + t\right) + \left(a + \left(b - 0.5\right) \cdot \log c\right)\right)} + y \cdot i
\] |
+-commutative [=>]99.9% | \[ \color{blue}{\left(\left(a + \left(b - 0.5\right) \cdot \log c\right) + \left(\left(x \cdot \log y + z\right) + t\right)\right)} + y \cdot i
\] |
associate-+l+ [=>]99.9% | \[ \color{blue}{\left(a + \left(b - 0.5\right) \cdot \log c\right) + \left(\left(\left(x \cdot \log y + z\right) + t\right) + y \cdot i\right)}
\] |
+-commutative [=>]99.9% | \[ \color{blue}{\left(\left(b - 0.5\right) \cdot \log c + a\right)} + \left(\left(\left(x \cdot \log y + z\right) + t\right) + y \cdot i\right)
\] |
fma-def [=>]99.9% | \[ \color{blue}{\mathsf{fma}\left(b - 0.5, \log c, a\right)} + \left(\left(\left(x \cdot \log y + z\right) + t\right) + y \cdot i\right)
\] |
sub-neg [=>]99.9% | \[ \mathsf{fma}\left(\color{blue}{b + \left(-0.5\right)}, \log c, a\right) + \left(\left(\left(x \cdot \log y + z\right) + t\right) + y \cdot i\right)
\] |
metadata-eval [=>]99.9% | \[ \mathsf{fma}\left(b + \color{blue}{-0.5}, \log c, a\right) + \left(\left(\left(x \cdot \log y + z\right) + t\right) + y \cdot i\right)
\] |
+-commutative [<=]99.9% | \[ \mathsf{fma}\left(b + -0.5, \log c, a\right) + \color{blue}{\left(y \cdot i + \left(\left(x \cdot \log y + z\right) + t\right)\right)}
\] |
fma-def [=>]99.9% | \[ \mathsf{fma}\left(b + -0.5, \log c, a\right) + \color{blue}{\mathsf{fma}\left(y, i, \left(x \cdot \log y + z\right) + t\right)}
\] |
+-commutative [=>]99.9% | \[ \mathsf{fma}\left(b + -0.5, \log c, a\right) + \mathsf{fma}\left(y, i, \color{blue}{\left(z + x \cdot \log y\right)} + t\right)
\] |
associate-+l+ [=>]99.9% | \[ \mathsf{fma}\left(b + -0.5, \log c, a\right) + \mathsf{fma}\left(y, i, \color{blue}{z + \left(x \cdot \log y + t\right)}\right)
\] |
fma-def [=>]99.9% | \[ \mathsf{fma}\left(b + -0.5, \log c, a\right) + \mathsf{fma}\left(y, i, z + \color{blue}{\mathsf{fma}\left(x, \log y, t\right)}\right)
\] |
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 32832 |
| Alternative 2 | |
|---|---|
| Accuracy | 92.5% |
| Cost | 20809 |
| Alternative 3 | |
|---|---|
| Accuracy | 75.2% |
| Cost | 20681 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 14016 |
| Alternative 5 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 13888 |
| Alternative 6 | |
|---|---|
| Accuracy | 94.8% |
| Cost | 7625 |
| Alternative 7 | |
|---|---|
| Accuracy | 88.3% |
| Cost | 7496 |
| Alternative 8 | |
|---|---|
| Accuracy | 72.8% |
| Cost | 7112 |
| Alternative 9 | |
|---|---|
| Accuracy | 71.4% |
| Cost | 6857 |
| Alternative 10 | |
|---|---|
| Accuracy | 66.9% |
| Cost | 576 |
| Alternative 11 | |
|---|---|
| Accuracy | 59.0% |
| Cost | 452 |
| Alternative 12 | |
|---|---|
| Accuracy | 44.5% |
| Cost | 320 |
| Alternative 13 | |
|---|---|
| Accuracy | 23.5% |
| Cost | 192 |
herbie shell --seed 2023167
(FPCore (x y z t a b c i)
:name "Numeric.SpecFunctions:logBeta from math-functions-0.1.5.2, B"
:precision binary64
(+ (+ (+ (+ (+ (* x (log y)) z) t) a) (* (- b 0.5) (log c))) (* y i)))