Average Error: 0.1 → 0.0
Time: 5.4s
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
    (fma.f64 x 3 (fma.f64 y 2 z)): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (Rewrite<= metadata-eval (+.f64 2 1)) (fma.f64 y 2 z)): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (+.f64 2 1) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y 2) z))): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (+.f64 2 1) (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 2 y)) z)): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (+.f64 2 1) (+.f64 (Rewrite<= count-2_binary64 (+.f64 y y)) z)): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x (+.f64 2 1)) (+.f64 (+.f64 y y) z))): 17 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (+.f64 2 1) x)) (+.f64 (+.f64 y y) z)): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= distribute-rgt1-in_binary64 (+.f64 x (*.f64 2 x))) (+.f64 (+.f64 y y) z)): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+r+_binary64 (+.f64 x (+.f64 (*.f64 2 x) (+.f64 (+.f64 y y) z)))): 1 points increase in error, 0 points decrease in error
    (+.f64 x (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (*.f64 2 x) (+.f64 y y)) z))): 0 points increase in error, 0 points decrease in error
    (+.f64 x (+.f64 (+.f64 (Rewrite<= count-2_binary64 (+.f64 x x)) (+.f64 y y)) z)): 0 points increase in error, 0 points decrease in error
    (+.f64 x (+.f64 (Rewrite<= associate-+r+_binary64 (+.f64 x (+.f64 x (+.f64 y y)))) z)): 2 points increase in error, 0 points decrease in error
    (+.f64 x (+.f64 (+.f64 x (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 x y) y))) z)): 0 points increase in error, 1 points decrease in error
    (+.f64 x (+.f64 (Rewrite<= +-commutative_binary64 (+.f64 (+.f64 (+.f64 x y) y) x)) z)): 0 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 (+.f64 (+.f64 (+.f64 (+.f64 x y) y) x) z) x)): 0 points increase in error, 0 points decrease in error
  3. Final simplification0.0

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

Alternatives

Alternative 1
Error31.7
Cost1512
\[\begin{array}{l} \mathbf{if}\;x \leq -1.0467538617436061 \cdot 10^{+129}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;x \leq -0.010980063189511583:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;x \leq -8.705482660495711 \cdot 10^{-40}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;x \leq -5.730454642523982 \cdot 10^{-75}:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;x \leq -1.5697335560110443 \cdot 10^{-188}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq -7.841576584979235 \cdot 10^{-276}:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;x \leq -2.071649384062286 \cdot 10^{-292}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 8.135627211281429 \cdot 10^{-225}:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;x \leq 3.170724592141651 \cdot 10^{-157}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 2.3400185397719987 \cdot 10^{+119}:\\ \;\;\;\;y \cdot 2\\ \mathbf{else}:\\ \;\;\;\;x \cdot 3\\ \end{array} \]
Alternative 2
Error14.8
Cost848
\[\begin{array}{l} t_0 := z + x \cdot 3\\ \mathbf{if}\;y \leq -2.3210420635289466 \cdot 10^{+212}:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;y \leq -4.3346927148533094 \cdot 10^{+120}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.265353894823474 \cdot 10^{+44}:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;y \leq 5.716805253351331 \cdot 10^{+149}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot 2\\ \end{array} \]
Alternative 3
Error10.7
Cost848
\[\begin{array}{l} t_0 := z + x \cdot 3\\ t_1 := z + y \cdot 2\\ \mathbf{if}\;x \leq -1.0467538617436061 \cdot 10^{+129}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -0.010980063189511583:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -8.705482660495711 \cdot 10^{-40}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 6.112907165769802 \cdot 10^{+116}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error10.1
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -8.705482660495711 \cdot 10^{-40}:\\ \;\;\;\;y \cdot 2 + x \cdot 3\\ \mathbf{elif}\;x \leq 6.112907165769802 \cdot 10^{+116}:\\ \;\;\;\;z + y \cdot 2\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + \left(x + z\right)\\ \end{array} \]
Alternative 5
Error0.1
Cost704
\[x + \left(z + \left(x + \left(y + \left(x + y\right)\right)\right)\right) \]
Alternative 6
Error10.1
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -8.705482660495711 \cdot 10^{-40}:\\ \;\;\;\;y \cdot 2 + x \cdot 3\\ \mathbf{elif}\;x \leq 6.112907165769802 \cdot 10^{+116}:\\ \;\;\;\;z + y \cdot 2\\ \mathbf{else}:\\ \;\;\;\;z + x \cdot 3\\ \end{array} \]
Alternative 7
Error30.1
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -7.579531565352611 \cdot 10^{+48}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 6.16539763804 \cdot 10^{+70}:\\ \;\;\;\;x \cdot 3\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 8
Error41.9
Cost64
\[z \]

Error

Reproduce

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