Average Error: 0.1 → 0.0
Time: 9.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
    (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))): 19 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, 1 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)): 3 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, 2 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.4
Cost1248
\[\begin{array}{l} \mathbf{if}\;y \leq -1.1311109916546304 \cdot 10^{-35}:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;y \leq -4.046521193678837 \cdot 10^{-279}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;y \leq 8.26725517696767 \cdot 10^{-303}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 9.122207740855013 \cdot 10^{-155}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;y \leq 1.7230702809447793 \cdot 10^{-93}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 2.8895009647207565 \cdot 10^{-56}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;y \leq 17500:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 1.0475514476749794 \cdot 10^{+158}:\\ \;\;\;\;x \cdot 3\\ \mathbf{else}:\\ \;\;\;\;y \cdot 2\\ \end{array} \]
Alternative 2
Error31.4
Cost1248
\[\begin{array}{l} \mathbf{if}\;y \leq -1.1311109916546304 \cdot 10^{-35}:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;y \leq -4.046521193678837 \cdot 10^{-279}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;y \leq 8.26725517696767 \cdot 10^{-303}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 9.122207740855013 \cdot 10^{-155}:\\ \;\;\;\;\frac{1}{\frac{0.3333333333333333}{x}}\\ \mathbf{elif}\;y \leq 1.7230702809447793 \cdot 10^{-93}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 2.8895009647207565 \cdot 10^{-56}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;y \leq 17500:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 1.0475514476749794 \cdot 10^{+158}:\\ \;\;\;\;x \cdot 3\\ \mathbf{else}:\\ \;\;\;\;y \cdot 2\\ \end{array} \]
Alternative 3
Error9.3
Cost976
\[\begin{array}{l} t_0 := z + x \cdot 3\\ t_1 := y \cdot 2 + x \cdot 3\\ \mathbf{if}\;x \leq -2.4077341653516396 \cdot 10^{+169}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -3.119011484679137 \cdot 10^{+80}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -8.56354277697843 \cdot 10^{-29}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 8.042269311778185 \cdot 10^{+29}:\\ \;\;\;\;z + y \cdot 2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error13.0
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -8.521754491384424 \cdot 10^{+111}:\\ \;\;\;\;y \cdot 2\\ \mathbf{elif}\;y \leq 1.0475514476749794 \cdot 10^{+158}:\\ \;\;\;\;z + x \cdot 3\\ \mathbf{else}:\\ \;\;\;\;y \cdot 2\\ \end{array} \]
Alternative 5
Error10.7
Cost584
\[\begin{array}{l} t_0 := z + y \cdot 2\\ \mathbf{if}\;y \leq -4.5092686212459793 \cdot 10^{-20}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.0475514476749794 \cdot 10^{+158}:\\ \;\;\;\;z + x \cdot 3\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error0.1
Cost576
\[x + \left(z + 2 \cdot \left(x + y\right)\right) \]
Alternative 7
Error30.7
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -5.619386082582822 \cdot 10^{+67}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 2.0846725357758262 \cdot 10^{+58}:\\ \;\;\;\;y \cdot 2\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 8
Error42.8
Cost64
\[z \]

Error

Reproduce

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