Average Error: 0.0 → 0.0
Time: 3.4s
Precision: binary64
Cost: 6720
\[x + y \cdot \left(z + x\right) \]
\[\mathsf{fma}\left(y, x + z, x\right) \]
(FPCore (x y z) :precision binary64 (+ x (* y (+ z x))))
(FPCore (x y z) :precision binary64 (fma y (+ x z) x))
double code(double x, double y, double z) {
	return x + (y * (z + x));
}
double code(double x, double y, double z) {
	return fma(y, (x + z), x);
}
function code(x, y, z)
	return Float64(x + Float64(y * Float64(z + x)))
end
function code(x, y, z)
	return fma(y, Float64(x + z), x)
end
code[x_, y_, z_] := N[(x + N[(y * N[(z + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := N[(y * N[(x + z), $MachinePrecision] + x), $MachinePrecision]
x + y \cdot \left(z + x\right)
\mathsf{fma}\left(y, x + z, x\right)

Error

Derivation

  1. Initial program 0.0

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(y, x + z, x\right)} \]
    Proof
    (fma.f64 y (+.f64 x z) x): 0 points increase in error, 0 points decrease in error
    (fma.f64 y (Rewrite<= +-commutative_binary64 (+.f64 z x)) x): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y (+.f64 z x)) x)): 5 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 x (*.f64 y (+.f64 z x)))): 0 points increase in error, 0 points decrease in error
  3. Final simplification0.0

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

Alternatives

Alternative 1
Error24.0
Cost1116
\[\begin{array}{l} \mathbf{if}\;y \leq -2.655558862252027 \cdot 10^{+21}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -1.37150999400213 \cdot 10^{-27}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq -4.826276484937989 \cdot 10^{-99}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -2.8616239359329024 \cdot 10^{-129}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 4.714813121874414 \cdot 10^{-31}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.05 \cdot 10^{+54}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{+153}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 2
Error11.9
Cost716
\[\begin{array}{l} t_0 := x + y \cdot z\\ \mathbf{if}\;y \leq -2.655558862252027 \cdot 10^{+21}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 1.05 \cdot 10^{+54}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.45 \cdot 10^{+133}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error7.1
Cost584
\[\begin{array}{l} t_0 := x + y \cdot z\\ \mathbf{if}\;z \leq -1.1912780477687877 \cdot 10^{-98}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 9.050232470255792 \cdot 10^{-66}:\\ \;\;\;\;x \cdot \left(y + 1\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error0.8
Cost584
\[\begin{array}{l} t_0 := y \cdot \left(x + z\right)\\ \mathbf{if}\;y \leq -7.095618448588677:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 0.05060558891981524:\\ \;\;\;\;x + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error0.8
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -7.095618448588677:\\ \;\;\;\;y \cdot z + y \cdot x\\ \mathbf{elif}\;y \leq 0.05060558891981524:\\ \;\;\;\;x + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x + z\right)\\ \end{array} \]
Alternative 6
Error0.0
Cost576
\[y \cdot z + \left(x + y \cdot x\right) \]
Alternative 7
Error24.8
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -0.0283923311559037:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 0.05060558891981524:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 8
Error0.0
Cost448
\[x + y \cdot \left(x + z\right) \]
Alternative 9
Error35.2
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022300 
(FPCore (x y z)
  :name "Main:bigenough2 from A"
  :precision binary64
  (+ x (* y (+ z x))))