?

Average Error: 0.39% → 0.22%
Time: 7.2s
Precision: binary64
Cost: 6848

?

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

Error?

Target

Original0.39%
Target0.32%
Herbie0.22%
\[6 \cdot x - 9 \cdot \left(x \cdot x\right) \]

Derivation?

  1. Initial program 0.39

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

    \[\leadsto \color{blue}{x \cdot \left(6 + x \cdot -9\right)} \]
    Proof

    [Start]0.39

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

    *-commutative [=>]0.39

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

    cancel-sign-sub-inv [=>]0.39

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

    distribute-rgt-in [=>]0.39

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

    metadata-eval [=>]0.39

    \[ x \cdot \left(\color{blue}{6} + \left(\left(-x\right) \cdot 3\right) \cdot 3\right) \]

    distribute-lft-neg-in [<=]0.39

    \[ x \cdot \left(6 + \color{blue}{\left(-x \cdot 3\right)} \cdot 3\right) \]

    distribute-rgt-neg-in [=>]0.39

    \[ x \cdot \left(6 + \color{blue}{\left(x \cdot \left(-3\right)\right)} \cdot 3\right) \]

    associate-*l* [=>]0.32

    \[ x \cdot \left(6 + \color{blue}{x \cdot \left(\left(-3\right) \cdot 3\right)}\right) \]

    metadata-eval [=>]0.32

    \[ x \cdot \left(6 + x \cdot \left(\color{blue}{-3} \cdot 3\right)\right) \]

    metadata-eval [=>]0.32

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

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

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

Alternatives

Alternative 1
Error0.31%
Cost6848
\[\mathsf{fma}\left(-9, x \cdot x, x \cdot 6\right) \]
Alternative 2
Error0.31%
Cost6720
\[x \cdot \mathsf{fma}\left(x, -9, 6\right) \]
Alternative 3
Error2.99%
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -0.65 \lor \neg \left(x \leq 0.68\right):\\ \;\;\;\;-9 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 6\\ \end{array} \]
Alternative 4
Error2.99%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -0.65:\\ \;\;\;\;x \cdot \left(x \cdot -9\right)\\ \mathbf{elif}\;x \leq 0.68:\\ \;\;\;\;x \cdot 6\\ \mathbf{else}:\\ \;\;\;\;-9 \cdot \left(x \cdot x\right)\\ \end{array} \]
Alternative 5
Error0.32%
Cost448
\[x \cdot \left(6 + x \cdot -9\right) \]
Alternative 6
Error33.55%
Cost192
\[x \cdot 6 \]
Alternative 7
Error97.1%
Cost64
\[4 \]

Error

Reproduce?

herbie shell --seed 2023115 
(FPCore (x)
  :name "Diagrams.Tangent:$catParam from diagrams-lib-1.3.0.3, E"
  :precision binary64

  :herbie-target
  (- (* 6.0 x) (* 9.0 (* x x)))

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