Average Error: 0.0 → 0
Time: 1.1s
Precision: binary64
Cost: 6720
\[x \cdot \left(1 - x \cdot 0.5\right) \]
\[\mathsf{fma}\left(x, x \cdot -0.5, x\right) \]
(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)

Error

Derivation

  1. Initial program 0.0

    \[x \cdot \left(1 - x \cdot 0.5\right) \]
  2. Simplified0

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, x \cdot -0.5, x\right)} \]
    Proof
    (fma.f64 x (*.f64 x -1/2) x): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (*.f64 x (Rewrite<= metadata-eval (neg.f64 1/2))) x): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 x 1/2))) x): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x (neg.f64 (*.f64 x 1/2))) x)): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 x (neg.f64 (*.f64 x 1/2))) (Rewrite<= *-rgt-identity_binary64 (*.f64 x 1))): 2 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 x 1) (*.f64 x (neg.f64 (*.f64 x 1/2))))): 0 points increase in error, 2 points decrease in error
    (Rewrite<= distribute-lft-in_binary64 (*.f64 x (+.f64 1 (neg.f64 (*.f64 x 1/2))))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (Rewrite<= sub-neg_binary64 (-.f64 1 (*.f64 x 1/2)))): 0 points increase in error, 0 points decrease in error
  3. Final simplification0

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

Alternatives

Alternative 1
Error1.9
Cost585
\[\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} \]
Alternative 2
Error0.0
Cost448
\[x \cdot \left(1 + x \cdot -0.5\right) \]
Alternative 3
Error0.0
Cost448
\[x + x \cdot \left(x \cdot -0.5\right) \]
Alternative 4
Error20.9
Cost64
\[x \]

Error

Reproduce

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