Average Error: 0.3 → 0.2
Time: 7.1s
Precision: binary64
Cost: 6720
\[\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x \]
\[x \cdot \mathsf{fma}\left(x, -9, 6\right) \]
(FPCore (x) :precision binary64 (* (* 3.0 (- 2.0 (* x 3.0))) x))
(FPCore (x) :precision binary64 (* x (fma x -9.0 6.0)))
double code(double x) {
	return (3.0 * (2.0 - (x * 3.0))) * x;
}
double code(double x) {
	return x * fma(x, -9.0, 6.0);
}
function code(x)
	return Float64(Float64(3.0 * Float64(2.0 - Float64(x * 3.0))) * x)
end
function code(x)
	return Float64(x * fma(x, -9.0, 6.0))
end
code[x_] := N[(N[(3.0 * N[(2.0 - N[(x * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]
code[x_] := N[(x * N[(x * -9.0 + 6.0), $MachinePrecision]), $MachinePrecision]
\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x
x \cdot \mathsf{fma}\left(x, -9, 6\right)

Error

Target

Original0.3
Target0.2
Herbie0.2
\[6 \cdot x - 9 \cdot \left(x \cdot x\right) \]

Derivation

  1. Initial program 0.3

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

    \[\leadsto \color{blue}{x \cdot \mathsf{fma}\left(x, -9, 6\right)} \]
    Proof
    (*.f64 x (fma.f64 x -9 6)): 0 points increase in error, 0 points decrease in error
    (*.f64 x (fma.f64 x (Rewrite<= metadata-eval (*.f64 3 -3)) 6)): 0 points increase in error, 0 points decrease in error
    (*.f64 x (fma.f64 x (*.f64 3 (Rewrite<= metadata-eval (neg.f64 3))) 6)): 0 points increase in error, 0 points decrease in error
    (*.f64 x (fma.f64 x (*.f64 3 (neg.f64 3)) (Rewrite<= metadata-eval (*.f64 3 2)))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x (*.f64 3 (neg.f64 3))) (*.f64 3 2)))): 8 points increase in error, 0 points decrease in error
    (*.f64 x (+.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 x 3) (neg.f64 3))) (*.f64 3 2))): 0 points increase in error, 8 points decrease in error
    (*.f64 x (+.f64 (Rewrite=> *-commutative_binary64 (*.f64 (neg.f64 3) (*.f64 x 3))) (*.f64 3 2))): 0 points increase in error, 0 points decrease in error
    (*.f64 x (+.f64 (Rewrite<= distribute-lft-neg-in_binary64 (neg.f64 (*.f64 3 (*.f64 x 3)))) (*.f64 3 2))): 13 points increase in error, 0 points decrease in error
    (*.f64 x (+.f64 (Rewrite<= distribute-rgt-neg-out_binary64 (*.f64 3 (neg.f64 (*.f64 x 3)))) (*.f64 3 2))): 0 points increase in error, 5 points decrease in error
    (*.f64 x (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 3 2) (*.f64 3 (neg.f64 (*.f64 x 3)))))): 5 points increase in error, 0 points decrease in error
    (*.f64 x (Rewrite<= distribute-lft-in_binary64 (*.f64 3 (+.f64 2 (neg.f64 (*.f64 x 3)))))): 0 points increase in error, 13 points decrease in error
    (*.f64 x (*.f64 3 (Rewrite<= sub-neg_binary64 (-.f64 2 (*.f64 x 3))))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= *-commutative_binary64 (*.f64 (*.f64 3 (-.f64 2 (*.f64 x 3))) x)): 0 points increase in error, 0 points decrease in error
  3. Final simplification0.2

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

Alternatives

Alternative 1
Error2.0
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -0.65 \lor \neg \left(x \leq 0.66\right):\\ \;\;\;\;-9 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 6\\ \end{array} \]
Alternative 2
Error2.0
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -0.65 \lor \neg \left(x \leq 0.66\right):\\ \;\;\;\;x \cdot \left(x \cdot -9\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 6\\ \end{array} \]
Alternative 3
Error0.2
Cost448
\[x \cdot \left(6 + x \cdot -9\right) \]
Alternative 4
Error21.9
Cost192
\[x \cdot 6 \]
Alternative 5
Error62.2
Cost64
\[4 \]

Error

Reproduce

herbie shell --seed 2022340 
(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))