?

Average Accuracy: 99.8% → 99.9%
Time: 5.5s
Precision: binary64
Cost: 6848

?

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

Error?

Bogosity?

Bogosity

Target

Original99.8%
Target99.9%
Herbie99.9%
\[3 + \left(\left(9 \cdot x\right) \cdot x - 12 \cdot x\right) \]

Derivation?

  1. Initial program 99.8%

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

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

    [Start]99.8

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

    *-commutative [=>]99.8

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

    distribute-lft1-in [<=]99.9

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

    *-commutative [=>]99.9

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

    distribute-lft-out-- [=>]99.9

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

    associate-*l* [=>]99.9

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

    fma-def [=>]99.9

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

    *-commutative [=>]99.9

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

    sub-neg [=>]99.9

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

    distribute-lft-in [=>]99.9

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

    *-commutative [<=]99.9

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

    associate-*l* [=>]99.9

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

    fma-def [=>]99.9

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

    metadata-eval [=>]99.9

    \[ \mathsf{fma}\left(x, \mathsf{fma}\left(x, \color{blue}{9}, 3 \cdot \left(-4\right)\right), 3\right) \]

    metadata-eval [=>]99.9

    \[ \mathsf{fma}\left(x, \mathsf{fma}\left(x, 9, 3 \cdot \color{blue}{-4}\right), 3\right) \]

    metadata-eval [=>]99.9

    \[ \mathsf{fma}\left(x, \mathsf{fma}\left(x, 9, \color{blue}{-12}\right), 3\right) \]
  3. Applied egg-rr99.9%

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

    [Start]99.9

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

    fma-udef [=>]99.9

    \[ \color{blue}{x \cdot \mathsf{fma}\left(x, 9, -12\right) + 3} \]
  4. Final simplification99.9%

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

Alternatives

Alternative 1
Accuracy99.8%
Cost832
\[3 \cdot \left(\left(x \cdot \left(x \cdot 3\right) - x \cdot 4\right) + 1\right) \]
Alternative 2
Accuracy98.9%
Cost713
\[\begin{array}{l} \mathbf{if}\;x \leq -0.58 \lor \neg \left(x \leq 0.58\right):\\ \;\;\;\;x \cdot \left(-12 + x \cdot 9\right)\\ \mathbf{else}:\\ \;\;\;\;3 + x \cdot -12\\ \end{array} \]
Alternative 3
Accuracy99.9%
Cost704
\[3 + \left(x \cdot -12 + x \cdot \left(x \cdot 9\right)\right) \]
Alternative 4
Accuracy97.7%
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -0.58 \lor \neg \left(x \leq 0.2\right):\\ \;\;\;\;9 \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;3\\ \end{array} \]
Alternative 5
Accuracy97.7%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -0.58:\\ \;\;\;\;x \cdot \left(x \cdot 9\right)\\ \mathbf{elif}\;x \leq 0.2:\\ \;\;\;\;3\\ \mathbf{else}:\\ \;\;\;\;9 \cdot \left(x \cdot x\right)\\ \end{array} \]
Alternative 6
Accuracy98.3%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.55:\\ \;\;\;\;x \cdot \left(x \cdot 9\right)\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;3 + x \cdot -12\\ \mathbf{else}:\\ \;\;\;\;9 \cdot \left(x \cdot x\right)\\ \end{array} \]
Alternative 7
Accuracy50.6%
Cost64
\[3 \]

Error

Reproduce?

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