Average Error: 0.1 → 0.1
Time: 9.0s
Precision: binary64
Cost: 6976
\[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
\[\mathsf{fma}\left(9, x \cdot x, x \cdot -12\right) + 3 \]
(FPCore (x) :precision binary64 (* 3.0 (+ (- (* (* x 3.0) x) (* x 4.0)) 1.0)))
(FPCore (x) :precision binary64 (+ (fma 9.0 (* x x) (* x -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(9.0, (x * x), (x * -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 Float64(fma(9.0, Float64(x * x), Float64(x * -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[(N[(9.0 * N[(x * x), $MachinePrecision] + N[(x * -12.0), $MachinePrecision]), $MachinePrecision] + 3.0), $MachinePrecision]
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
\mathsf{fma}\left(9, x \cdot x, x \cdot -12\right) + 3

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. Applied egg-rr0.1

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(9, x \cdot x, x \cdot -12\right)} + 3 \]
  5. Final simplification0.1

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

Alternatives

Alternative 1
Error1.2
Cost840
\[\begin{array}{l} t_0 := x \cdot -12 + 9 \cdot \left(x \cdot x\right)\\ \mathbf{if}\;x \leq -41.09187112638979:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 7.135383061402566 \cdot 10^{-9}:\\ \;\;\;\;x \cdot -12 + 3\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error1.2
Cost712
\[\begin{array}{l} t_0 := x \cdot \left(-12 + 9 \cdot x\right)\\ \mathbf{if}\;x \leq -41.09187112638979:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 7.135383061402566 \cdot 10^{-9}:\\ \;\;\;\;x \cdot -12 + 3\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error0.1
Cost704
\[3 + \left(x \cdot -12 + 9 \cdot \left(x \cdot x\right)\right) \]
Alternative 4
Error1.7
Cost584
\[\begin{array}{l} t_0 := x \cdot \left(9 \cdot x\right)\\ \mathbf{if}\;x \leq -41.09187112638979:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 7.135383061402566 \cdot 10^{-9}:\\ \;\;\;\;x \cdot -12 + 3\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error2.0
Cost576
\[3 + 3 \cdot \left(x \cdot \left(x \cdot 3\right)\right) \]
Alternative 6
Error21.5
Cost64
\[3 \]

Error

Reproduce

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