?

Average Accuracy: 99.9% → 100.0%
Time: 10.9s
Precision: binary64
Cost: 13120

?

\[\left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right) + x \]
\[\mathsf{fma}\left(x, 3, \mathsf{fma}\left(y, 2, z\right)\right) \]
(FPCore (x y z) :precision binary64 (+ (+ (+ (+ (+ x y) y) x) z) x))
(FPCore (x y z) :precision binary64 (fma x 3.0 (fma y 2.0 z)))
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(x, 3.0, fma(y, 2.0, z));
}
function code(x, y, z)
	return Float64(Float64(Float64(Float64(Float64(x + y) + y) + x) + z) + x)
end
function code(x, y, z)
	return fma(x, 3.0, fma(y, 2.0, z))
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[(x * 3.0 + N[(y * 2.0 + z), $MachinePrecision]), $MachinePrecision]
\left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right) + x
\mathsf{fma}\left(x, 3, \mathsf{fma}\left(y, 2, z\right)\right)

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(x, 3, \mathsf{fma}\left(y, 2, z\right)\right)} \]
    Proof

    [Start]99.9

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

    +-commutative [=>]99.9

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

    +-commutative [=>]99.9

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

    associate-+l+ [=>]99.9

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

    associate-+r+ [=>]99.9

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

    associate-+l+ [=>]99.9

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

    associate-+r+ [=>]99.9

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

    count-2 [=>]99.9

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

    distribute-rgt1-in [=>]99.9

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

    *-commutative [=>]99.9

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

    fma-def [=>]100.0

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

    metadata-eval [=>]100.0

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

    count-2 [=>]100.0

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

    *-commutative [=>]100.0

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

    fma-def [=>]100.0

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

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

Alternatives

Alternative 1
Accuracy52.5%
Cost1116
\[\begin{array}{l} \mathbf{if}\;y \leq -1.05 \cdot 10^{+82}:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;y \leq -2.95 \cdot 10^{-211}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;y \leq 8.2 \cdot 10^{-295}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 4 \cdot 10^{-180}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{-83}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 8.2 \cdot 10^{-13}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;y \leq 8.5 \cdot 10^{+21}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;y \cdot 2\\ \end{array} \]
Alternative 2
Accuracy52.4%
Cost1116
\[\begin{array}{l} t_0 := \frac{x}{3} \cdot 9\\ \mathbf{if}\;y \leq -1.2 \cdot 10^{+86}:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;y \leq -1.2 \cdot 10^{-212}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 3.2 \cdot 10^{-293}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 4 \cdot 10^{-180}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;y \leq 9.5 \cdot 10^{-83}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 6 \cdot 10^{-13}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 5.1 \cdot 10^{+23}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;y \cdot 2\\ \end{array} \]
Alternative 3
Accuracy76.5%
Cost849
\[\begin{array}{l} \mathbf{if}\;x \leq -2.4 \cdot 10^{+144}:\\ \;\;\;\;\frac{x}{3} \cdot 9\\ \mathbf{elif}\;x \leq 85000 \lor \neg \left(x \leq 2.35 \cdot 10^{+120}\right) \land x \leq 4.1 \cdot 10^{+208}:\\ \;\;\;\;z + y \cdot 2\\ \mathbf{else}:\\ \;\;\;\;x \cdot 3\\ \end{array} \]
Alternative 4
Accuracy85.5%
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -6.2 \cdot 10^{+66} \lor \neg \left(z \leq 650\right):\\ \;\;\;\;z + x \cdot 3\\ \mathbf{else}:\\ \;\;\;\;x + 2 \cdot \left(x + y\right)\\ \end{array} \]
Alternative 5
Accuracy85.5%
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -1.4 \cdot 10^{+67} \lor \neg \left(z \leq 45000\right):\\ \;\;\;\;z + x \cdot 3\\ \mathbf{else}:\\ \;\;\;\;x \cdot 3 + y \cdot 2\\ \end{array} \]
Alternative 6
Accuracy85.2%
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -2.9 \cdot 10^{+83} \lor \neg \left(y \leq 2.45 \cdot 10^{+92}\right):\\ \;\;\;\;z + y \cdot 2\\ \mathbf{else}:\\ \;\;\;\;z + x \cdot 3\\ \end{array} \]
Alternative 7
Accuracy99.9%
Cost576
\[x + \left(z + 2 \cdot \left(x + y\right)\right) \]
Alternative 8
Accuracy53.1%
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -4.8 \cdot 10^{+66}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 58000:\\ \;\;\;\;y \cdot 2\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 9
Accuracy34.5%
Cost64
\[z \]

Error

Reproduce?

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