?

Average Error: 0.02% → 0.01%
Time: 1.9s
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.02

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

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

    [Start]0.02

    \[ x + y \cdot \left(z + x\right) \]

    +-commutative [=>]0.02

    \[ \color{blue}{y \cdot \left(z + x\right) + x} \]

    fma-def [=>]0.01

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

    +-commutative [=>]0.01

    \[ \mathsf{fma}\left(y, \color{blue}{x + z}, x\right) \]
  3. Final simplification0.01

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

Alternatives

Alternative 1
Error22.74%
Cost1115
\[\begin{array}{l} \mathbf{if}\;x \leq -3.5 \cdot 10^{+77} \lor \neg \left(x \leq -5 \cdot 10^{-44} \lor \neg \left(x \leq -4.8 \cdot 10^{-105}\right) \land \left(x \leq 1.48 \cdot 10^{-80} \lor \neg \left(x \leq 6.9 \cdot 10^{-48}\right) \land x \leq 5600000000\right)\right):\\ \;\;\;\;x + y \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x + z\right)\\ \end{array} \]
Alternative 2
Error41.95%
Cost984
\[\begin{array}{l} \mathbf{if}\;x \leq -2.8 \cdot 10^{+84}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -8.2 \cdot 10^{-72}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq -7.5 \cdot 10^{-105}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.4 \cdot 10^{-77}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 5.4 \cdot 10^{-48}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4600000000:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error19.13%
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -2.35 \cdot 10^{-10} \lor \neg \left(y \leq 4.2 \cdot 10^{-12}\right):\\ \;\;\;\;y \cdot \left(x + z\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error0.02%
Cost448
\[x + y \cdot \left(x + z\right) \]
Alternative 5
Error54.82%
Cost64
\[x \]

Error

Reproduce?

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