?

Average Error: 0.28% → 0.26%
Time: 8.2s
Precision: binary64
Cost: 7104

?

\[\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right) \]
\[\mathsf{fma}\left(x \cdot x, x \cdot -2, x \cdot \left(x \cdot 3\right)\right) \]
(FPCore (x) :precision binary64 (* (* x x) (- 3.0 (* x 2.0))))
(FPCore (x) :precision binary64 (fma (* x x) (* x -2.0) (* x (* x 3.0))))
double code(double x) {
	return (x * x) * (3.0 - (x * 2.0));
}
double code(double x) {
	return fma((x * x), (x * -2.0), (x * (x * 3.0)));
}
function code(x)
	return Float64(Float64(x * x) * Float64(3.0 - Float64(x * 2.0)))
end
function code(x)
	return fma(Float64(x * x), Float64(x * -2.0), Float64(x * Float64(x * 3.0)))
end
code[x_] := N[(N[(x * x), $MachinePrecision] * N[(3.0 - N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(N[(x * x), $MachinePrecision] * N[(x * -2.0), $MachinePrecision] + N[(x * N[(x * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right)
\mathsf{fma}\left(x \cdot x, x \cdot -2, x \cdot \left(x \cdot 3\right)\right)

Error?

Target

Original0.28%
Target0.25%
Herbie0.26%
\[x \cdot \left(x \cdot \left(3 - x \cdot 2\right)\right) \]

Derivation?

  1. Initial program 0.28

    \[\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right) \]
  2. Simplified0.25

    \[\leadsto \color{blue}{x \cdot \left(x \cdot \left(3 - x \cdot 2\right)\right)} \]
    Proof

    [Start]0.28

    \[ \left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right) \]

    associate-*l* [=>]0.25

    \[ \color{blue}{x \cdot \left(x \cdot \left(3 - x \cdot 2\right)\right)} \]
  3. Applied egg-rr0.29

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot x, x \cdot -2, x \cdot \left(x \cdot 3\right)\right)} \]
  5. Final simplification0.26

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

Alternatives

Alternative 1
Error0.29%
Cost832
\[\left(x \cdot x\right) \cdot 3 + \left(x \cdot x\right) \cdot \left(x \cdot -2\right) \]
Alternative 2
Error3.19%
Cost713
\[\begin{array}{l} \mathbf{if}\;x \leq -1.5 \lor \neg \left(x \leq 1.5\right):\\ \;\;\;\;x \cdot \left(x \cdot \left(x \cdot -2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(x \cdot 3\right)\\ \end{array} \]
Alternative 3
Error0.26%
Cost704
\[x \cdot \left(x \cdot 3 + x \cdot \left(x \cdot -2\right)\right) \]
Alternative 4
Error0.25%
Cost576
\[x \cdot \left(x \cdot \left(x \cdot -2 + 3\right)\right) \]
Alternative 5
Error25.64%
Cost320
\[\left(x \cdot x\right) \cdot 3 \]
Alternative 6
Error25.61%
Cost320
\[x \cdot \left(x \cdot 3\right) \]
Alternative 7
Error95.37%
Cost192
\[x \cdot 4.5 \]

Error

Reproduce?

herbie shell --seed 2023121 
(FPCore (x)
  :name "Data.Spline.Key:interpolateKeys from smoothie-0.4.0.2"
  :precision binary64

  :herbie-target
  (* x (* x (- 3.0 (* x 2.0))))

  (* (* x x) (- 3.0 (* x 2.0))))