Average Error: 0.1 → 0.1
Time: 6.9s
Precision: binary64
Cost: 6976
\[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
\[3 + \left(3 \cdot x\right) \cdot \mathsf{fma}\left(3, x, -4\right) \]
(FPCore (x) :precision binary64 (* 3.0 (+ (- (* (* x 3.0) x) (* x 4.0)) 1.0)))
(FPCore (x) :precision binary64 (+ 3.0 (* (* 3.0 x) (fma 3.0 x -4.0))))
double code(double x) {
	return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0);
}
double code(double x) {
	return 3.0 + ((3.0 * x) * fma(3.0, x, -4.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(3.0 + Float64(Float64(3.0 * x) * fma(3.0, x, -4.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[(3.0 + N[(N[(3.0 * x), $MachinePrecision] * N[(3.0 * x + -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
3 + \left(3 \cdot x\right) \cdot \mathsf{fma}\left(3, x, -4\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. Applied egg-rr0.2

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

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

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

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

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

Alternatives

Alternative 1
Error0.1
Cost6848
\[\mathsf{fma}\left(x, x \cdot 9 + -12, 3\right) \]
Alternative 2
Error0.1
Cost704
\[3 + 3 \cdot \left(x \cdot \left(3 \cdot x + -4\right)\right) \]
Alternative 3
Error1.9
Cost584
\[\begin{array}{l} t_0 := 9 \cdot \left(x \cdot x\right)\\ \mathbf{if}\;x \leq -16.758399484866253:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.011197212236638863:\\ \;\;\;\;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 -16.758399484866253:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.011197212236638863:\\ \;\;\;\;3 + x \cdot -12\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error1.9
Cost448
\[3 + x \cdot \left(x \cdot 9\right) \]
Alternative 6
Error21.2
Cost64
\[3 \]

Error

Reproduce

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