?

Average Error: 0.1 → 0.0
Time: 5.8s
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.1

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

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

    [Start]0.1

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

    +-commutative [=>]0.1

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

    +-commutative [=>]0.1

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

    associate-+l+ [=>]0.1

    \[ 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.1

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

    count-2 [=>]0.1

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

    distribute-rgt1-in [=>]0.1

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

    *-commutative [=>]0.1

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

    fma-def [=>]0.0

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

    metadata-eval [=>]0.0

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

    count-2 [=>]0.0

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

    *-commutative [=>]0.0

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

    fma-def [=>]0.0

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

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

Alternatives

Alternative 1
Error9.4
Cost1240
\[\begin{array}{l} t_0 := z + y \cdot 2\\ t_1 := x + 2 \cdot \left(x + y\right)\\ \mathbf{if}\;y \leq -4.5 \cdot 10^{+162}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.9 \cdot 10^{+65}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -7.8 \cdot 10^{+33}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.6 \cdot 10^{+40}:\\ \;\;\;\;x \cdot 2 + \left(x + z\right)\\ \mathbf{elif}\;y \leq 3.1 \cdot 10^{+100}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.45 \cdot 10^{+117}:\\ \;\;\;\;z + x \cdot 3\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error29.8
Cost852
\[\begin{array}{l} \mathbf{if}\;z \leq -1.32 \cdot 10^{+67}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq -5.2 \cdot 10^{-57}:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;z \leq -1.32 \cdot 10^{-154}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;z \leq 1.38 \cdot 10^{-307}:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;z \leq 7.2 \cdot 10^{+50}:\\ \;\;\;\;x \cdot 3\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 3
Error14.4
Cost849
\[\begin{array}{l} \mathbf{if}\;x \leq -4.5 \cdot 10^{+100}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;x \leq 8 \cdot 10^{+36} \lor \neg \left(x \leq 1.32 \cdot 10^{+70}\right) \land x \leq 3 \cdot 10^{+203}:\\ \;\;\;\;z + y \cdot 2\\ \mathbf{else}:\\ \;\;\;\;x \cdot 3\\ \end{array} \]
Alternative 4
Error9.5
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -1.56 \cdot 10^{+35} \lor \neg \left(y \leq 2.1 \cdot 10^{+42}\right):\\ \;\;\;\;z + y \cdot 2\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + \left(x + z\right)\\ \end{array} \]
Alternative 5
Error9.5
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -4.7 \cdot 10^{+34} \lor \neg \left(y \leq 6.4 \cdot 10^{+41}\right):\\ \;\;\;\;z + y \cdot 2\\ \mathbf{else}:\\ \;\;\;\;z + x \cdot 3\\ \end{array} \]
Alternative 6
Error0.1
Cost576
\[x + \left(z + 2 \cdot \left(x + y\right)\right) \]
Alternative 7
Error30.3
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -6.1 \cdot 10^{+66}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 7.6 \cdot 10^{+90}:\\ \;\;\;\;y \cdot 2\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 8
Error41.7
Cost64
\[z \]

Error

Reproduce?

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