?

Average Error: 0.1% → 0.05%
Time: 4.6s
Precision: binary64
Cost: 13120

?

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

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

    [Start]0.1

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

    associate-+l+ [=>]0.11

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

    associate-+l+ [=>]0.12

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

    +-commutative [=>]0.12

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

    associate-+l+ [=>]0.11

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

    associate-+l+ [=>]0.11

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

    count-2 [=>]0.11

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

    *-commutative [=>]0.11

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

    +-commutative [=>]0.11

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

    associate-+r+ [<=]0.1

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

    fma-def [=>]0.1

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

    +-commutative [=>]0.1

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

    associate-+r+ [=>]0.1

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

    +-commutative [<=]0.1

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

    count-2 [=>]0.1

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

    distribute-rgt1-in [=>]0.1

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

    fma-def [=>]0.05

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

    metadata-eval [=>]0.05

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

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

Alternatives

Alternative 1
Error47.26%
Cost852
\[\begin{array}{l} \mathbf{if}\;y \leq -0.36:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;y \leq -3.2 \cdot 10^{-247}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 2.45 \cdot 10^{-190}:\\ \;\;\;\;3 \cdot x\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{-63}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 1.5 \cdot 10^{+70}:\\ \;\;\;\;3 \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot 2\\ \end{array} \]
Alternative 2
Error14.38%
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -1.15 \cdot 10^{+17} \lor \neg \left(y \leq 3.6 \cdot 10^{+33}\right):\\ \;\;\;\;x + 2 \cdot \left(y + x\right)\\ \mathbf{else}:\\ \;\;\;\;z + 3 \cdot x\\ \end{array} \]
Alternative 3
Error14.25%
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -3.8 \cdot 10^{+14} \lor \neg \left(y \leq 1.35 \cdot 10^{+68}\right):\\ \;\;\;\;z + y \cdot 2\\ \mathbf{else}:\\ \;\;\;\;z + 3 \cdot x\\ \end{array} \]
Alternative 4
Error22.18%
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -5.3 \cdot 10^{+23}:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{+69}:\\ \;\;\;\;z + 3 \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot 2\\ \end{array} \]
Alternative 5
Error0.1%
Cost576
\[x + \left(z + 2 \cdot \left(y + x\right)\right) \]
Alternative 6
Error46.86%
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -16:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;y \leq 1.85 \cdot 10^{+38}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;y \cdot 2\\ \end{array} \]
Alternative 7
Error64.61%
Cost64
\[z \]

Error

Reproduce?

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