?

Average Error: 0.11% → 0%
Time: 7.3s
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 0.11

    \[\left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right) + x \]
  2. Simplified0

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

    [Start]0.11

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

    +-commutative [=>]0.11

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

    +-commutative [=>]0.11

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

    associate-+l+ [=>]0.11

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

    associate-+r+ [=>]0.1

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

    associate-+l+ [=>]0.1

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

    associate-+r+ [=>]0.09

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

    count-2 [=>]0.09

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

    distribute-rgt1-in [=>]0.09

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

    *-commutative [=>]0.09

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

    fma-def [=>]0

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

    metadata-eval [=>]0

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

    count-2 [=>]0

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

    *-commutative [=>]0

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

    fma-def [=>]0

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

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

Alternatives

Alternative 1
Error49.98%
Cost1644
\[\begin{array}{l} \mathbf{if}\;x \leq -6.8 \cdot 10^{+113}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;x \leq -1.05 \cdot 10^{-9}:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;x \leq -1.05 \cdot 10^{-170}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq -1.3 \cdot 10^{-221}:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{-300}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 4.4 \cdot 10^{-224}:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;x \leq 1.2 \cdot 10^{-147}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 3.65 \cdot 10^{-124}:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;x \leq 2.3 \cdot 10^{-35}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 2 \cdot 10^{+60}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;x \leq 4.6 \cdot 10^{+166}:\\ \;\;\;\;y \cdot 2\\ \mathbf{else}:\\ \;\;\;\;x \cdot 3\\ \end{array} \]
Alternative 2
Error43.69%
Cost1112
\[\begin{array}{l} t_0 := x + \left(y + y\right)\\ \mathbf{if}\;z \leq -2.05 \cdot 10^{+76}:\\ \;\;\;\;x + z\\ \mathbf{elif}\;z \leq -1.04 \cdot 10^{-255}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.1 \cdot 10^{-291}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;z \leq 5.8 \cdot 10^{-192}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.25 \cdot 10^{-114}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;z \leq 2.05 \cdot 10^{+20}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x + z\\ \end{array} \]
Alternative 3
Error46.65%
Cost984
\[\begin{array}{l} \mathbf{if}\;z \leq -9.5 \cdot 10^{+50}:\\ \;\;\;\;x + z\\ \mathbf{elif}\;z \leq -4.8 \cdot 10^{-250}:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;z \leq -1 \cdot 10^{-292}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;z \leq 4.5 \cdot 10^{-194}:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;z \leq 1.56 \cdot 10^{-114}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;z \leq 1.46 \cdot 10^{+20}:\\ \;\;\;\;y \cdot 2\\ \mathbf{else}:\\ \;\;\;\;x + z\\ \end{array} \]
Alternative 4
Error16.16%
Cost978
\[\begin{array}{l} \mathbf{if}\;x \leq -1.26 \cdot 10^{+114} \lor \neg \left(x \leq 6.2 \cdot 10^{-54} \lor \neg \left(x \leq 4.8 \cdot 10^{+46}\right) \land x \leq 3.6 \cdot 10^{+164}\right):\\ \;\;\;\;z + x \cdot 3\\ \mathbf{else}:\\ \;\;\;\;x + \left(z + y \cdot 2\right)\\ \end{array} \]
Alternative 5
Error14.14%
Cost977
\[\begin{array}{l} \mathbf{if}\;x \leq -1.08 \cdot 10^{+114}:\\ \;\;\;\;z + x \cdot 3\\ \mathbf{elif}\;x \leq -2.75 \cdot 10^{+63} \lor \neg \left(x \leq -2 \cdot 10^{-6}\right) \land x \leq 7.8 \cdot 10^{+31}:\\ \;\;\;\;x + \left(z + y \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;x + 2 \cdot \left(x + y\right)\\ \end{array} \]
Alternative 6
Error17.69%
Cost850
\[\begin{array}{l} \mathbf{if}\;x \leq -4.9 \cdot 10^{+113} \lor \neg \left(x \leq 6.2 \cdot 10^{-54}\right) \land \left(x \leq 2.3 \cdot 10^{+46} \lor \neg \left(x \leq 1.55 \cdot 10^{+165}\right)\right):\\ \;\;\;\;z + x \cdot 3\\ \mathbf{else}:\\ \;\;\;\;z + y \cdot 2\\ \end{array} \]
Alternative 7
Error19.72%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.85 \cdot 10^{+138}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{+167}:\\ \;\;\;\;z + y \cdot 2\\ \mathbf{else}:\\ \;\;\;\;x \cdot 3\\ \end{array} \]
Alternative 8
Error0.1%
Cost576
\[x + \left(z + 2 \cdot \left(x + y\right)\right) \]
Alternative 9
Error48.07%
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -2 \cdot 10^{+64}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 1.65 \cdot 10^{+20}:\\ \;\;\;\;y \cdot 2\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 10
Error66.15%
Cost64
\[z \]

Error

Reproduce?

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