?

Average Accuracy: 99.9% → 100.0%
Time: 8.8s
Precision: binary64
Cost: 6848

?

\[\left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right) + x \]
\[\mathsf{fma}\left(3, x, z\right) + y \cdot 2 \]
(FPCore (x y z) :precision binary64 (+ (+ (+ (+ (+ x y) y) x) z) x))
(FPCore (x y z) :precision binary64 (+ (fma 3.0 x z) (* y 2.0)))
double code(double x, double y, double z) {
	return ((((x + y) + y) + x) + z) + x;
}
double code(double x, double y, double z) {
	return fma(3.0, x, z) + (y * 2.0);
}
function code(x, y, z)
	return Float64(Float64(Float64(Float64(Float64(x + y) + y) + x) + z) + x)
end
function code(x, y, z)
	return Float64(fma(3.0, x, z) + Float64(y * 2.0))
end
code[x_, y_, z_] := N[(N[(N[(N[(N[(x + y), $MachinePrecision] + y), $MachinePrecision] + x), $MachinePrecision] + z), $MachinePrecision] + x), $MachinePrecision]
code[x_, y_, z_] := N[(N[(3.0 * x + z), $MachinePrecision] + N[(y * 2.0), $MachinePrecision]), $MachinePrecision]
\left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right) + x
\mathsf{fma}\left(3, x, z\right) + y \cdot 2

Error?

Derivation?

  1. Initial program 99.9%

    \[\left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right) + x \]
  2. Simplified100.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(y, 2, \mathsf{fma}\left(3, x, z\right)\right)} \]
    Proof

    [Start]99.9

    \[ \left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right) + x \]

    associate-+l+ [=>]99.9

    \[ \color{blue}{\left(\left(\left(x + y\right) + y\right) + \left(x + z\right)\right)} + x \]

    associate-+l+ [=>]99.9

    \[ \left(\color{blue}{\left(x + \left(y + y\right)\right)} + \left(x + z\right)\right) + x \]

    +-commutative [=>]99.9

    \[ \left(\color{blue}{\left(\left(y + y\right) + x\right)} + \left(x + z\right)\right) + x \]

    associate-+l+ [=>]99.9

    \[ \color{blue}{\left(\left(y + y\right) + \left(x + \left(x + z\right)\right)\right)} + x \]

    associate-+l+ [=>]99.9

    \[ \color{blue}{\left(y + y\right) + \left(\left(x + \left(x + z\right)\right) + x\right)} \]

    count-2 [=>]99.9

    \[ \color{blue}{2 \cdot y} + \left(\left(x + \left(x + z\right)\right) + x\right) \]

    *-commutative [=>]99.9

    \[ \color{blue}{y \cdot 2} + \left(\left(x + \left(x + z\right)\right) + x\right) \]

    +-commutative [=>]99.9

    \[ y \cdot 2 + \left(\color{blue}{\left(\left(x + z\right) + x\right)} + x\right) \]

    associate-+r+ [<=]99.9

    \[ y \cdot 2 + \color{blue}{\left(\left(x + z\right) + \left(x + x\right)\right)} \]

    fma-def [=>]99.9

    \[ \color{blue}{\mathsf{fma}\left(y, 2, \left(x + z\right) + \left(x + x\right)\right)} \]

    +-commutative [=>]99.9

    \[ \mathsf{fma}\left(y, 2, \color{blue}{\left(x + x\right) + \left(x + z\right)}\right) \]

    associate-+r+ [=>]99.9

    \[ \mathsf{fma}\left(y, 2, \color{blue}{\left(\left(x + x\right) + x\right) + z}\right) \]

    +-commutative [<=]99.9

    \[ \mathsf{fma}\left(y, 2, \color{blue}{\left(x + \left(x + x\right)\right)} + z\right) \]

    count-2 [=>]99.9

    \[ \mathsf{fma}\left(y, 2, \left(x + \color{blue}{2 \cdot x}\right) + z\right) \]

    distribute-rgt1-in [=>]99.9

    \[ \mathsf{fma}\left(y, 2, \color{blue}{\left(2 + 1\right) \cdot x} + z\right) \]

    fma-def [=>]100.0

    \[ \mathsf{fma}\left(y, 2, \color{blue}{\mathsf{fma}\left(2 + 1, x, z\right)}\right) \]

    metadata-eval [=>]100.0

    \[ \mathsf{fma}\left(y, 2, \mathsf{fma}\left(\color{blue}{3}, x, z\right)\right) \]
  3. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(3, x, z\right) + y \cdot 2} \]
    Proof

    [Start]100.0

    \[ \mathsf{fma}\left(y, 2, \mathsf{fma}\left(3, x, z\right)\right) \]

    fma-udef [=>]100.0

    \[ \color{blue}{y \cdot 2 + \mathsf{fma}\left(3, x, z\right)} \]

    +-commutative [=>]100.0

    \[ \color{blue}{\mathsf{fma}\left(3, x, z\right) + y \cdot 2} \]
  4. Final simplification100.0%

    \[\leadsto \mathsf{fma}\left(3, x, z\right) + y \cdot 2 \]

Alternatives

Alternative 1
Accuracy52.4%
Cost1777
\[\begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{+131}:\\ \;\;\;\;3 \cdot x\\ \mathbf{elif}\;x \leq -1.4 \cdot 10^{+37}:\\ \;\;\;\;x + z\\ \mathbf{elif}\;x \leq -4.8 \cdot 10^{-74}:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;x \leq -2.4 \cdot 10^{-129}:\\ \;\;\;\;x + z\\ \mathbf{elif}\;x \leq -1.75 \cdot 10^{-280}:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;x \leq 3.8 \cdot 10^{-289}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{-249}:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;x \leq 7 \cdot 10^{-170}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 7.5 \cdot 10^{-40}:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;x \leq 0.00062 \lor \neg \left(x \leq 1.05 \cdot 10^{+64}\right) \land x \leq 1.05 \cdot 10^{+95}:\\ \;\;\;\;x + z\\ \mathbf{else}:\\ \;\;\;\;3 \cdot x\\ \end{array} \]
Alternative 2
Accuracy50.9%
Cost1512
\[\begin{array}{l} \mathbf{if}\;x \leq -2.1 \cdot 10^{+129}:\\ \;\;\;\;3 \cdot x\\ \mathbf{elif}\;x \leq -7 \cdot 10^{+37}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq -0.026:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;x \leq 4 \cdot 10^{-288}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 4.9 \cdot 10^{-250}:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;x \leq 6 \cdot 10^{-172}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 1.76 \cdot 10^{-37}:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;x \leq 1.06 \cdot 10^{-18}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 8.8 \cdot 10^{+56}:\\ \;\;\;\;3 \cdot x\\ \mathbf{elif}\;x \leq 2.4 \cdot 10^{+98}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;3 \cdot x\\ \end{array} \]
Alternative 3
Accuracy52.8%
Cost1508
\[\begin{array}{l} t_0 := x + \left(y + y\right)\\ \mathbf{if}\;x \leq -2.3 \cdot 10^{+123}:\\ \;\;\;\;3 \cdot x\\ \mathbf{elif}\;x \leq -6 \cdot 10^{+39}:\\ \;\;\;\;x + z\\ \mathbf{elif}\;x \leq -2.8 \cdot 10^{-68}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-129}:\\ \;\;\;\;x + z\\ \mathbf{elif}\;x \leq -4.5 \cdot 10^{-279}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4.5 \cdot 10^{-288}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 1.8 \cdot 10^{-248}:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;x \leq 10^{-171}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{+87}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;3 \cdot x\\ \end{array} \]
Alternative 4
Accuracy77.0%
Cost1115
\[\begin{array}{l} \mathbf{if}\;y \leq -7.6 \cdot 10^{+240} \lor \neg \left(y \leq -6.6 \cdot 10^{+182}\right) \land \left(y \leq -2.65 \cdot 10^{+65} \lor \neg \left(y \leq 1.9 \cdot 10^{+101}\right) \land \left(y \leq 2 \cdot 10^{+134} \lor \neg \left(y \leq 4.7 \cdot 10^{+176}\right)\right)\right):\\ \;\;\;\;x + \left(y + y\right)\\ \mathbf{else}:\\ \;\;\;\;z + 3 \cdot x\\ \end{array} \]
Alternative 5
Accuracy84.7%
Cost976
\[\begin{array}{l} t_0 := x \cdot 2 + \left(x + z\right)\\ t_1 := z + y \cdot 2\\ \mathbf{if}\;x \leq -1550000000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 10^{-18}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{+64}:\\ \;\;\;\;x + 2 \cdot \left(x + y\right)\\ \mathbf{elif}\;x \leq 7.4 \cdot 10^{+87}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Accuracy85.8%
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -3000000000000 \lor \neg \left(x \leq 1.25 \cdot 10^{-7}\right):\\ \;\;\;\;z + 3 \cdot x\\ \mathbf{else}:\\ \;\;\;\;z + y \cdot 2\\ \end{array} \]
Alternative 7
Accuracy85.8%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.25 \cdot 10^{+16}:\\ \;\;\;\;x \cdot 2 + \left(x + z\right)\\ \mathbf{elif}\;x \leq 0.00062:\\ \;\;\;\;z + y \cdot 2\\ \mathbf{else}:\\ \;\;\;\;z + 3 \cdot x\\ \end{array} \]
Alternative 8
Accuracy99.9%
Cost576
\[x + \left(z + 2 \cdot \left(x + y\right)\right) \]
Alternative 9
Accuracy53.1%
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -1.8 \cdot 10^{+64}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{+94}:\\ \;\;\;\;y \cdot 2\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 10
Accuracy33.7%
Cost64
\[z \]

Error

Reproduce?

herbie shell --seed 2023133 
(FPCore (x y z)
  :name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendInside from plot-0.2.3.4"
  :precision binary64
  (+ (+ (+ (+ (+ x y) y) x) z) x))