Average Error: 0.1 → 0.1
Time: 12.8s
Precision: binary64
Cost: 13120
\[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
\[\mathsf{fma}\left(x, \mathsf{fma}\left(x, 9, -12\right), 3\right) \]
(FPCore (x) :precision binary64 (* 3.0 (+ (- (* (* x 3.0) x) (* x 4.0)) 1.0)))
(FPCore (x) :precision binary64 (fma x (fma x 9.0 -12.0) 3.0))
double code(double x) {
	return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0);
}
double code(double x) {
	return fma(x, fma(x, 9.0, -12.0), 3.0);
}
function code(x)
	return Float64(3.0 * Float64(Float64(Float64(Float64(x * 3.0) * x) - Float64(x * 4.0)) + 1.0))
end
function code(x)
	return fma(x, fma(x, 9.0, -12.0), 3.0)
end
code[x_] := N[(3.0 * N[(N[(N[(N[(x * 3.0), $MachinePrecision] * x), $MachinePrecision] - N[(x * 4.0), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(x * N[(x * 9.0 + -12.0), $MachinePrecision] + 3.0), $MachinePrecision]
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
\mathsf{fma}\left(x, \mathsf{fma}\left(x, 9, -12\right), 3\right)

Error

Target

Original0.1
Target0.1
Herbie0.1
\[3 + \left(\left(9 \cdot x\right) \cdot x - 12 \cdot x\right) \]

Derivation

  1. Initial program 0.1

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, \mathsf{fma}\left(x, 9, -12\right), 3\right)} \]
    Proof
    (fma.f64 x (fma.f64 x 9 -12) 3): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (fma.f64 x (Rewrite<= metadata-eval (*.f64 3 3)) -12) 3): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (fma.f64 x (*.f64 3 3) (Rewrite<= metadata-eval (*.f64 -4 3))) 3): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (fma.f64 x (*.f64 3 3) (*.f64 (Rewrite<= metadata-eval (neg.f64 4)) 3)) 3): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x (*.f64 3 3)) (*.f64 (neg.f64 4) 3))) 3): 2 points increase in error, 3 points decrease in error
    (fma.f64 x (+.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 x 3) 3)) (*.f64 (neg.f64 4) 3)) 3): 15 points increase in error, 0 points decrease in error
    (fma.f64 x (Rewrite<= distribute-rgt-in_binary64 (*.f64 3 (+.f64 (*.f64 x 3) (neg.f64 4)))) 3): 1 points increase in error, 0 points decrease in error
    (fma.f64 x (*.f64 3 (Rewrite<= sub-neg_binary64 (-.f64 (*.f64 x 3) 4))) 3): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (Rewrite<= *-commutative_binary64 (*.f64 (-.f64 (*.f64 x 3) 4) 3)) 3): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x (*.f64 (-.f64 (*.f64 x 3) 4) 3)) 3)): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 x (-.f64 (*.f64 x 3) 4)) 3)) 3): 11 points increase in error, 14 points decrease in error
    (+.f64 (*.f64 (Rewrite<= distribute-rgt-out--_binary64 (-.f64 (*.f64 (*.f64 x 3) x) (*.f64 4 x))) 3) 3): 0 points increase in error, 1 points decrease in error
    (+.f64 (*.f64 (-.f64 (*.f64 (*.f64 x 3) x) (Rewrite<= *-commutative_binary64 (*.f64 x 4))) 3) 3): 0 points increase in error, 0 points decrease in error
    (Rewrite=> distribute-lft1-in_binary64 (*.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 3) x) (*.f64 x 4)) 1) 3)): 4 points increase in error, 0 points decrease in error
    (Rewrite<= *-commutative_binary64 (*.f64 3 (+.f64 (-.f64 (*.f64 (*.f64 x 3) x) (*.f64 x 4)) 1))): 0 points increase in error, 0 points decrease in error
  3. Final simplification0.1

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

Alternatives

Alternative 1
Error0.1
Cost832
\[3 \cdot \left(\left(3 \cdot \left(x \cdot x\right) + x \cdot -4\right) + 1\right) \]
Alternative 2
Error1.0
Cost712
\[\begin{array}{l} t_0 := x \cdot \left(-12 + x \cdot 9\right)\\ \mathbf{if}\;x \leq -2.323917429247241:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.3738252580529614 \cdot 10^{-6}:\\ \;\;\;\;3 + x \cdot -12\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error1.9
Cost584
\[\begin{array}{l} t_0 := 9 \cdot \left(x \cdot x\right)\\ \mathbf{if}\;x \leq -2.323917429247241:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.3738252580529614 \cdot 10^{-6}:\\ \;\;\;\;3\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error1.5
Cost584
\[\begin{array}{l} t_0 := 9 \cdot \left(x \cdot x\right)\\ \mathbf{if}\;x \leq -2.323917429247241:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.3738252580529614 \cdot 10^{-6}:\\ \;\;\;\;3 + x \cdot -12\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error1.5
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -2.323917429247241:\\ \;\;\;\;x \cdot \left(x \cdot 9\right)\\ \mathbf{elif}\;x \leq 1.3738252580529614 \cdot 10^{-6}:\\ \;\;\;\;3 + x \cdot -12\\ \mathbf{else}:\\ \;\;\;\;9 \cdot \left(x \cdot x\right)\\ \end{array} \]
Alternative 6
Error20.5
Cost64
\[3 \]

Error

Reproduce

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

  :herbie-target
  (+ 3.0 (- (* (* 9.0 x) x) (* 12.0 x)))

  (* 3.0 (+ (- (* (* x 3.0) x) (* x 4.0)) 1.0)))