Average Error: 0.0 → 0.0
Time: 2.5s
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)): 2 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
Error13.8
Cost848
\[\begin{array}{l} t_0 := x \cdot \left(y + 1\right)\\ t_1 := y \cdot \left(x + z\right)\\ \mathbf{if}\;x \leq -4.5 \cdot 10^{+19}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -6.8 \cdot 10^{-72}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.3 \cdot 10^{-118}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.45 \cdot 10^{-44}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error13.9
Cost848
\[\begin{array}{l} t_0 := x \cdot \left(y + 1\right)\\ t_1 := y \cdot \left(x + z\right)\\ \mathbf{if}\;x \leq -1.52 \cdot 10^{+19}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -6.8 \cdot 10^{-71}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.4 \cdot 10^{-119}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.45 \cdot 10^{-47}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot x\\ \end{array} \]
Alternative 3
Error25.7
Cost720
\[\begin{array}{l} \mathbf{if}\;x \leq -1.15 \cdot 10^{+21}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.3 \cdot 10^{-73}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq -3 \cdot 10^{-118}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.8 \cdot 10^{-48}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error13.1
Cost584
\[\begin{array}{l} t_0 := y \cdot \left(x + z\right)\\ \mathbf{if}\;y \leq -1.95 \cdot 10^{-19}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.35 \cdot 10^{-98}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error24.3
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -8.6 \cdot 10^{-11}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 6
Error0.0
Cost448
\[x + y \cdot \left(x + z\right) \]
Alternative 7
Error34.9
Cost64
\[x \]

Error

Reproduce

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