?

Average Error: 0.02% → 0.01%
Time: 4.1s
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
Error37.98%
Cost1116
\[\begin{array}{l} \mathbf{if}\;y \leq -4 \cdot 10^{+31}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq -13.5:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 1.85 \cdot 10^{-66}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 4.2 \cdot 10^{-39}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 1.65 \cdot 10^{-10}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.2 \cdot 10^{+176}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 7.5 \cdot 10^{+251}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 2
Error19.02%
Cost848
\[\begin{array}{l} t_0 := y \cdot \left(x + z\right)\\ \mathbf{if}\;y \leq -1.2 \cdot 10^{-18}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 9.6 \cdot 10^{-66}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 2.65 \cdot 10^{-42}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 2.35 \cdot 10^{-11}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error19.01%
Cost848
\[\begin{array}{l} t_0 := y \cdot \left(x + z\right)\\ t_1 := x \cdot \left(y + 1\right)\\ \mathbf{if}\;y \leq -2050000000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.05 \cdot 10^{-65}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 8 \cdot 10^{-44}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 31000:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error1.4%
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -13.5 \lor \neg \left(y \leq 1\right):\\ \;\;\;\;y \cdot \left(x + z\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot z\\ \end{array} \]
Alternative 5
Error36.7%
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -13.5:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 6
Error0.02%
Cost448
\[x + y \cdot \left(x + z\right) \]
Alternative 7
Error54.23%
Cost64
\[x \]

Error

Reproduce?

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