| Alternative 1 | |
|---|---|
| Error | 1.8 |
| Cost | 585 |
\[\begin{array}{l}
\mathbf{if}\;x \leq -2 \lor \neg \left(x \leq 2\right):\\
\;\;\;\;x \cdot \left(x \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\]
(FPCore (x) :precision binary64 (* x (- 1.0 (* x 0.5))))
(FPCore (x) :precision binary64 (fma x (* x -0.5) x))
double code(double x) {
return x * (1.0 - (x * 0.5));
}
double code(double x) {
return fma(x, (x * -0.5), x);
}
function code(x) return Float64(x * Float64(1.0 - Float64(x * 0.5))) end
function code(x) return fma(x, Float64(x * -0.5), x) end
code[x_] := N[(x * N[(1.0 - N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(x * N[(x * -0.5), $MachinePrecision] + x), $MachinePrecision]
x \cdot \left(1 - x \cdot 0.5\right)
\mathsf{fma}\left(x, x \cdot -0.5, x\right)
Initial program 0.0
Simplified0
[Start]0.0 | \[ x \cdot \left(1 - x \cdot 0.5\right)
\] |
|---|---|
sub-neg [=>]0.0 | \[ x \cdot \color{blue}{\left(1 + \left(-x \cdot 0.5\right)\right)}
\] |
distribute-lft-in [=>]0.0 | \[ \color{blue}{x \cdot 1 + x \cdot \left(-x \cdot 0.5\right)}
\] |
+-commutative [=>]0.0 | \[ \color{blue}{x \cdot \left(-x \cdot 0.5\right) + x \cdot 1}
\] |
*-rgt-identity [=>]0.0 | \[ x \cdot \left(-x \cdot 0.5\right) + \color{blue}{x}
\] |
fma-def [=>]0 | \[ \color{blue}{\mathsf{fma}\left(x, -x \cdot 0.5, x\right)}
\] |
distribute-rgt-neg-in [=>]0 | \[ \mathsf{fma}\left(x, \color{blue}{x \cdot \left(-0.5\right)}, x\right)
\] |
metadata-eval [=>]0 | \[ \mathsf{fma}\left(x, x \cdot \color{blue}{-0.5}, x\right)
\] |
Final simplification0
| Alternative 1 | |
|---|---|
| Error | 1.8 |
| Cost | 585 |
| Alternative 2 | |
|---|---|
| Error | 0.0 |
| Cost | 448 |
| Alternative 3 | |
|---|---|
| Error | 21.5 |
| Cost | 64 |
herbie shell --seed 2023125
(FPCore (x)
:name "Numeric.SpecFunctions:log1p from math-functions-0.1.5.2, B"
:precision binary64
(* x (- 1.0 (* x 0.5))))