| Alternative 1 | |
|---|---|
| Accuracy | 74.8% |
| Cost | 456 |
\[\begin{array}{l}
\mathbf{if}\;x \leq -2.75 \cdot 10^{+44}:\\
\;\;\;\;x \cdot 1.5\\
\mathbf{elif}\;x \leq 1.4 \cdot 10^{-40}:\\
\;\;\;\;y \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1.5\\
\end{array}
\]
(FPCore (x y) :precision binary64 (+ x (/ (- x y) 2.0)))
(FPCore (x y) :precision binary64 (fma x 1.5 (* y -0.5)))
double code(double x, double y) {
return x + ((x - y) / 2.0);
}
double code(double x, double y) {
return fma(x, 1.5, (y * -0.5));
}
function code(x, y) return Float64(x + Float64(Float64(x - y) / 2.0)) end
function code(x, y) return fma(x, 1.5, Float64(y * -0.5)) end
code[x_, y_] := N[(x + N[(N[(x - y), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := N[(x * 1.5 + N[(y * -0.5), $MachinePrecision]), $MachinePrecision]
x + \frac{x - y}{2}
\mathsf{fma}\left(x, 1.5, y \cdot -0.5\right)
| Original | 99.9% |
|---|---|
| Target | 99.9% |
| Herbie | 100.0% |
Initial program 99.9%
Simplified100.0%
[Start]99.9 | \[ x + \frac{x - y}{2}
\] |
|---|---|
+-commutative [=>]99.9 | \[ \color{blue}{\frac{x - y}{2} + x}
\] |
div-sub [=>]99.9 | \[ \color{blue}{\left(\frac{x}{2} - \frac{y}{2}\right)} + x
\] |
associate-+l- [=>]99.8 | \[ \color{blue}{\frac{x}{2} - \left(\frac{y}{2} - x\right)}
\] |
sub-neg [=>]99.8 | \[ \frac{x}{2} - \color{blue}{\left(\frac{y}{2} + \left(-x\right)\right)}
\] |
+-commutative [=>]99.8 | \[ \frac{x}{2} - \color{blue}{\left(\left(-x\right) + \frac{y}{2}\right)}
\] |
associate--r+ [=>]99.9 | \[ \color{blue}{\left(\frac{x}{2} - \left(-x\right)\right) - \frac{y}{2}}
\] |
sub-neg [=>]99.9 | \[ \color{blue}{\left(\frac{x}{2} + \left(-\left(-x\right)\right)\right)} - \frac{y}{2}
\] |
remove-double-neg [=>]99.9 | \[ \left(\frac{x}{2} + \color{blue}{x}\right) - \frac{y}{2}
\] |
+-commutative [<=]99.9 | \[ \color{blue}{\left(x + \frac{x}{2}\right)} - \frac{y}{2}
\] |
*-lft-identity [<=]99.9 | \[ \left(\color{blue}{1 \cdot x} + \frac{x}{2}\right) - \frac{y}{2}
\] |
metadata-eval [<=]99.9 | \[ \left(\color{blue}{\left(--1\right)} \cdot x + \frac{x}{2}\right) - \frac{y}{2}
\] |
*-lft-identity [<=]99.9 | \[ \left(\left(--1\right) \cdot x + \frac{\color{blue}{1 \cdot x}}{2}\right) - \frac{y}{2}
\] |
metadata-eval [<=]99.9 | \[ \left(\left(--1\right) \cdot x + \frac{\color{blue}{\left(--1\right)} \cdot x}{2}\right) - \frac{y}{2}
\] |
associate-/l* [=>]99.8 | \[ \left(\left(--1\right) \cdot x + \color{blue}{\frac{--1}{\frac{2}{x}}}\right) - \frac{y}{2}
\] |
associate-/r/ [=>]99.9 | \[ \left(\left(--1\right) \cdot x + \color{blue}{\frac{--1}{2} \cdot x}\right) - \frac{y}{2}
\] |
distribute-rgt-out [=>]99.9 | \[ \color{blue}{x \cdot \left(\left(--1\right) + \frac{--1}{2}\right)} - \frac{y}{2}
\] |
fma-neg [=>]100.0 | \[ \color{blue}{\mathsf{fma}\left(x, \left(--1\right) + \frac{--1}{2}, -\frac{y}{2}\right)}
\] |
metadata-eval [=>]100.0 | \[ \mathsf{fma}\left(x, \color{blue}{1} + \frac{--1}{2}, -\frac{y}{2}\right)
\] |
metadata-eval [=>]100.0 | \[ \mathsf{fma}\left(x, 1 + \frac{\color{blue}{1}}{2}, -\frac{y}{2}\right)
\] |
metadata-eval [=>]100.0 | \[ \mathsf{fma}\left(x, 1 + \color{blue}{0.5}, -\frac{y}{2}\right)
\] |
metadata-eval [=>]100.0 | \[ \mathsf{fma}\left(x, \color{blue}{1.5}, -\frac{y}{2}\right)
\] |
distribute-neg-frac [=>]100.0 | \[ \mathsf{fma}\left(x, 1.5, \color{blue}{\frac{-y}{2}}\right)
\] |
neg-mul-1 [=>]100.0 | \[ \mathsf{fma}\left(x, 1.5, \frac{\color{blue}{-1 \cdot y}}{2}\right)
\] |
associate-/l* [=>]99.9 | \[ \mathsf{fma}\left(x, 1.5, \color{blue}{\frac{-1}{\frac{2}{y}}}\right)
\] |
associate-/r/ [=>]100.0 | \[ \mathsf{fma}\left(x, 1.5, \color{blue}{\frac{-1}{2} \cdot y}\right)
\] |
*-commutative [=>]100.0 | \[ \mathsf{fma}\left(x, 1.5, \color{blue}{y \cdot \frac{-1}{2}}\right)
\] |
metadata-eval [=>]100.0 | \[ \mathsf{fma}\left(x, 1.5, y \cdot \color{blue}{-0.5}\right)
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 74.8% |
| Cost | 456 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 448 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 448 |
| Alternative 4 | |
|---|---|
| Accuracy | 50.5% |
| Cost | 192 |
herbie shell --seed 2023137
(FPCore (x y)
:name "Graphics.Rendering.Chart.Axis.Types:hBufferRect from Chart-1.5.3"
:precision binary64
:herbie-target
(- (* 1.5 x) (* 0.5 y))
(+ x (/ (- x y) 2.0)))