Average Error: 0.0 → 0
Time: 1.5s
Precision: binary64
Cost: 6720
\[x \cdot \left(1 - x \cdot 0.5\right) \]
\[\mathsf{fma}\left(x \cdot -0.5, x, x\right) \]
(FPCore (x) :precision binary64 (* x (- 1.0 (* x 0.5))))
(FPCore (x) :precision binary64 (fma (* x -0.5) x x))
double code(double x) {
	return x * (1.0 - (x * 0.5));
}
double code(double x) {
	return fma((x * -0.5), x, x);
}
function code(x)
	return Float64(x * Float64(1.0 - Float64(x * 0.5)))
end
function code(x)
	return fma(Float64(x * -0.5), x, x)
end
code[x_] := N[(x * N[(1.0 - N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(N[(x * -0.5), $MachinePrecision] * x + x), $MachinePrecision]
x \cdot \left(1 - x \cdot 0.5\right)
\mathsf{fma}\left(x \cdot -0.5, x, x\right)

Error

Derivation

  1. Initial program 0.0

    \[x \cdot \left(1 - x \cdot 0.5\right) \]
  2. Applied egg-rr0.0

    \[\leadsto \color{blue}{x + \left(x \cdot -0.5\right) \cdot x} \]
  3. Applied egg-rr0

    \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot -0.5, x, x\right)} \]
  4. Final simplification0

    \[\leadsto \mathsf{fma}\left(x \cdot -0.5, x, x\right) \]

Alternatives

Alternative 1
Error1.8
Cost584
\[\begin{array}{l} t_0 := x \cdot \left(x \cdot -0.5\right)\\ \mathbf{if}\;x \leq -2:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.0
Cost448
\[x \cdot \left(x \cdot -0.5 + 1\right) \]
Alternative 3
Error21.7
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022330 
(FPCore (x)
  :name "Numeric.SpecFunctions:log1p from math-functions-0.1.5.2, B"
  :precision binary64
  (* x (- 1.0 (* x 0.5))))