| Alternative 1 | |
|---|---|
| Error | 17.7 |
| Cost | 456 |
\[\begin{array}{l}
\mathbf{if}\;y \leq -6.5 \cdot 10^{+73}:\\
\;\;\;\;y \cdot -0.5\\
\mathbf{elif}\;y \leq 10^{+120}:\\
\;\;\;\;x \cdot 1.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot -0.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 | 0.1 |
|---|---|
| Target | 0.1 |
| Herbie | 0 |
Initial program 0.1
Simplified0
[Start]0.1 | \[ x + \frac{x - y}{2}
\] |
|---|---|
+-commutative [=>]0.1 | \[ \color{blue}{\frac{x - y}{2} + x}
\] |
div-sub [=>]0.1 | \[ \color{blue}{\left(\frac{x}{2} - \frac{y}{2}\right)} + x
\] |
associate-+l- [=>]0.1 | \[ \color{blue}{\frac{x}{2} - \left(\frac{y}{2} - x\right)}
\] |
sub-neg [=>]0.1 | \[ \frac{x}{2} - \color{blue}{\left(\frac{y}{2} + \left(-x\right)\right)}
\] |
+-commutative [=>]0.1 | \[ \frac{x}{2} - \color{blue}{\left(\left(-x\right) + \frac{y}{2}\right)}
\] |
associate--r+ [=>]0.1 | \[ \color{blue}{\left(\frac{x}{2} - \left(-x\right)\right) - \frac{y}{2}}
\] |
sub-neg [=>]0.1 | \[ \color{blue}{\left(\frac{x}{2} + \left(-\left(-x\right)\right)\right)} - \frac{y}{2}
\] |
remove-double-neg [=>]0.1 | \[ \left(\frac{x}{2} + \color{blue}{x}\right) - \frac{y}{2}
\] |
+-commutative [<=]0.1 | \[ \color{blue}{\left(x + \frac{x}{2}\right)} - \frac{y}{2}
\] |
*-lft-identity [<=]0.1 | \[ \left(\color{blue}{1 \cdot x} + \frac{x}{2}\right) - \frac{y}{2}
\] |
metadata-eval [<=]0.1 | \[ \left(\color{blue}{\left(--1\right)} \cdot x + \frac{x}{2}\right) - \frac{y}{2}
\] |
*-lft-identity [<=]0.1 | \[ \left(\left(--1\right) \cdot x + \frac{\color{blue}{1 \cdot x}}{2}\right) - \frac{y}{2}
\] |
metadata-eval [<=]0.1 | \[ \left(\left(--1\right) \cdot x + \frac{\color{blue}{\left(--1\right)} \cdot x}{2}\right) - \frac{y}{2}
\] |
associate-/l* [=>]0.1 | \[ \left(\left(--1\right) \cdot x + \color{blue}{\frac{--1}{\frac{2}{x}}}\right) - \frac{y}{2}
\] |
associate-/r/ [=>]0.1 | \[ \left(\left(--1\right) \cdot x + \color{blue}{\frac{--1}{2} \cdot x}\right) - \frac{y}{2}
\] |
distribute-rgt-out [=>]0.1 | \[ \color{blue}{x \cdot \left(\left(--1\right) + \frac{--1}{2}\right)} - \frac{y}{2}
\] |
fma-neg [=>]0 | \[ \color{blue}{\mathsf{fma}\left(x, \left(--1\right) + \frac{--1}{2}, -\frac{y}{2}\right)}
\] |
metadata-eval [=>]0 | \[ \mathsf{fma}\left(x, \color{blue}{1} + \frac{--1}{2}, -\frac{y}{2}\right)
\] |
metadata-eval [=>]0 | \[ \mathsf{fma}\left(x, 1 + \frac{\color{blue}{1}}{2}, -\frac{y}{2}\right)
\] |
metadata-eval [=>]0 | \[ \mathsf{fma}\left(x, 1 + \color{blue}{0.5}, -\frac{y}{2}\right)
\] |
metadata-eval [=>]0 | \[ \mathsf{fma}\left(x, \color{blue}{1.5}, -\frac{y}{2}\right)
\] |
distribute-neg-frac [=>]0 | \[ \mathsf{fma}\left(x, 1.5, \color{blue}{\frac{-y}{2}}\right)
\] |
neg-mul-1 [=>]0 | \[ \mathsf{fma}\left(x, 1.5, \frac{\color{blue}{-1 \cdot y}}{2}\right)
\] |
associate-/l* [=>]0.1 | \[ \mathsf{fma}\left(x, 1.5, \color{blue}{\frac{-1}{\frac{2}{y}}}\right)
\] |
associate-/r/ [=>]0 | \[ \mathsf{fma}\left(x, 1.5, \color{blue}{\frac{-1}{2} \cdot y}\right)
\] |
*-commutative [=>]0 | \[ \mathsf{fma}\left(x, 1.5, \color{blue}{y \cdot \frac{-1}{2}}\right)
\] |
metadata-eval [=>]0 | \[ \mathsf{fma}\left(x, 1.5, y \cdot \color{blue}{-0.5}\right)
\] |
Final simplification0
| Alternative 1 | |
|---|---|
| Error | 17.7 |
| Cost | 456 |
| Alternative 2 | |
|---|---|
| Error | 0.1 |
| Cost | 448 |
| Alternative 3 | |
|---|---|
| Error | 32.1 |
| Cost | 192 |
herbie shell --seed 2023016
(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)))