Alternative 1 | |
---|---|
Error | 0.3 |
Cost | 6980 |
\[\begin{array}{l}
\mathbf{if}\;b \leq 5 \cdot 10^{-21}:\\
\;\;\;\;\left(x + y\right) + a \cdot \left(b \cdot c\right)\\
\mathbf{else}:\\
\;\;\;\;y + \mathsf{fma}\left(b, a \cdot c, x\right)\\
\end{array}
\]
(FPCore (x y a b c) :precision binary64 (+ (+ x y) (* (* a b) c)))
(FPCore (x y a b c) :precision binary64 (if (<= b 1e-21) (fma a (* b c) (+ x y)) (+ y (fma b (* a c) x))))
double code(double x, double y, double a, double b, double c) { return (x + y) + ((a * b) * c); }
double code(double x, double y, double a, double b, double c) { double tmp; if (b <= 1e-21) { tmp = fma(a, (b * c), (x + y)); } else { tmp = y + fma(b, (a * c), x); } return tmp; }
function code(x, y, a, b, c) return Float64(Float64(x + y) + Float64(Float64(a * b) * c)) end
function code(x, y, a, b, c) tmp = 0.0 if (b <= 1e-21) tmp = fma(a, Float64(b * c), Float64(x + y)); else tmp = Float64(y + fma(b, Float64(a * c), x)); end return tmp end
code[x_, y_, a_, b_, c_] := N[(N[(x + y), $MachinePrecision] + N[(N[(a * b), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]
code[x_, y_, a_, b_, c_] := If[LessEqual[b, 1e-21], N[(a * N[(b * c), $MachinePrecision] + N[(x + y), $MachinePrecision]), $MachinePrecision], N[(y + N[(b * N[(a * c), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]]
\left(x + y\right) + \left(a \cdot b\right) \cdot c
\begin{array}{l} \mathbf{if}\;b \leq 10^{-21}:\\ \;\;\;\;\mathsf{fma}\left(a, b \cdot c, x + y\right)\\ \mathbf{else}:\\ \;\;\;\;y + \mathsf{fma}\left(b, a \cdot c, x\right)\\ \end{array}
if b < 9.99999999999999908e-22
Initial program 1.9
Simplified0.3
[Start]1.9 | \[ \left(x + y\right) + \left(a \cdot b\right) \cdot c
\] |
---|---|
+-commutative [=>]1.9 | \[ \color{blue}{\left(a \cdot b\right) \cdot c + \left(x + y\right)}
\] |
associate-*l* [=>]0.3 | \[ \color{blue}{a \cdot \left(b \cdot c\right)} + \left(x + y\right)
\] |
fma-def [=>]0.3 | \[ \color{blue}{\mathsf{fma}\left(a, b \cdot c, x + y\right)}
\] |
if 9.99999999999999908e-22 < b
Initial program 0.1
Simplified0.3
[Start]0.1 | \[ \left(x + y\right) + \left(a \cdot b\right) \cdot c
\] |
---|---|
+-commutative [=>]0.1 | \[ \color{blue}{\left(a \cdot b\right) \cdot c + \left(x + y\right)}
\] |
associate-+r+ [=>]0.1 | \[ \color{blue}{\left(\left(a \cdot b\right) \cdot c + x\right) + y}
\] |
+-commutative [=>]0.1 | \[ \color{blue}{y + \left(\left(a \cdot b\right) \cdot c + x\right)}
\] |
*-commutative [=>]0.1 | \[ y + \left(\color{blue}{c \cdot \left(a \cdot b\right)} + x\right)
\] |
associate-*r* [=>]0.3 | \[ y + \left(\color{blue}{\left(c \cdot a\right) \cdot b} + x\right)
\] |
*-commutative [=>]0.3 | \[ y + \left(\color{blue}{b \cdot \left(c \cdot a\right)} + x\right)
\] |
fma-def [=>]0.3 | \[ y + \color{blue}{\mathsf{fma}\left(b, c \cdot a, x\right)}
\] |
*-commutative [=>]0.3 | \[ y + \mathsf{fma}\left(b, \color{blue}{a \cdot c}, x\right)
\] |
Final simplification0.3
Alternative 1 | |
---|---|
Error | 0.3 |
Cost | 6980 |
Alternative 2 | |
---|---|
Error | 0.8 |
Cost | 708 |
Alternative 3 | |
---|---|
Error | 12.1 |
Cost | 452 |
Alternative 4 | |
---|---|
Error | 11.3 |
Cost | 452 |
Alternative 5 | |
---|---|
Error | 26.9 |
Cost | 448 |
Alternative 6 | |
---|---|
Error | 11.1 |
Cost | 192 |
Alternative 7 | |
---|---|
Error | 37.0 |
Cost | 64 |
Alternative 8 | |
---|---|
Error | 36.2 |
Cost | 64 |
herbie shell --seed 1
(FPCore (x y a b c)
:name "x + y + a * b * c"
:precision binary64
:pre (and (and (and (and (and (<= 0.0 x) (<= x 1.79e+308)) (and (<= 0.0 y) (<= y 1.79e+308))) (and (<= -1.0 a) (<= a 1.0))) (and (<= -1.79e+308 b) (<= b 1.79e+308))) (and (<= -1.79e+308 c) (<= c 1.79e+308)))
(+ (+ x y) (* (* a b) c)))