Average Error: 0.0 → 0.0
Time: 4.0s
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)): 3 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.9
Cost1116
\[\begin{array}{l} \mathbf{if}\;y \leq -1.0375905147361758 \cdot 10^{-5}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 1.2952789533448019 \cdot 10^{-204}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 2.119768506094311 \cdot 10^{-165}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 9.692060928859593 \cdot 10^{-12}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.12 \cdot 10^{+55}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 2.55 \cdot 10^{+70}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{+94}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 2
Error16.4
Cost848
\[\begin{array}{l} t_0 := x + y \cdot x\\ \mathbf{if}\;x \leq -2.755218003563302 \cdot 10^{-78}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.1379212199527635 \cdot 10^{-115}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq -1.581045283652413 \cdot 10^{-142}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.039703826867275 \cdot 10^{-57}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error14.0
Cost848
\[\begin{array}{l} t_0 := y \cdot \left(x + z\right)\\ t_1 := x + y \cdot x\\ \mathbf{if}\;y \leq -1.5112653547067211 \cdot 10^{+22}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.2952789533448019 \cdot 10^{-204}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.119768506094311 \cdot 10^{-165}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 9.692060928859593 \cdot 10^{-12}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error1.1
Cost584
\[\begin{array}{l} t_0 := y \cdot \left(x + z\right)\\ \mathbf{if}\;y \leq -970.2538576584302:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 3.766590029089347 \cdot 10^{-11}:\\ \;\;\;\;x + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error24.8
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -970.2538576584302:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 1958422320072.9436:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 6
Error0.0
Cost448
\[x + y \cdot \left(x + z\right) \]
Alternative 7
Error35.4
Cost64
\[x \]

Error

Reproduce

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