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

Error

Derivation

  1. Initial program 0.0

    \[\left(x + y\right) \cdot \left(z + 1\right) \]
  2. Applied egg-rr0.0

    \[\leadsto \color{blue}{\left(\left(x + y\right) + y \cdot z\right) + x \cdot z} \]
  3. Taylor expanded in x around 0 0.0

    \[\leadsto \color{blue}{y \cdot z + \left(\left(1 + z\right) \cdot x + y\right)} \]
  4. Simplified0.0

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

    [Start]0.0

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

    fma-def [=>]0.0

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

    +-commutative [=>]0.0

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

    +-commutative [=>]0.0

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

    distribute-lft1-in [<=]0.0

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

    fma-def [=>]0.0

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

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

Alternatives

Alternative 1
Error32.6
Cost1248
\[\begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -3.5 \cdot 10^{-163}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 1.4 \cdot 10^{-296}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2.7 \cdot 10^{-245}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 9.6 \cdot 10^{-178}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3.7 \cdot 10^{-121}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 2.9 \cdot 10^{-68}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 28000:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 2
Error12.4
Cost716
\[\begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq 0.0075:\\ \;\;\;\;y + x\\ \mathbf{elif}\;z \leq 6 \cdot 10^{+19}:\\ \;\;\;\;y \cdot \left(z + 1\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 3
Error12.1
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -4.7 \cdot 10^{-5} \lor \neg \left(z \leq 4.4 \cdot 10^{-8}\right):\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
Alternative 4
Error1.6
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;z \cdot \left(y + x\right)\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
Alternative 5
Error12.7
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq 32000:\\ \;\;\;\;y + x\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 6
Error0.0
Cost448
\[\left(y + x\right) \cdot \left(z + 1\right) \]
Alternative 7
Error38.7
Cost196
\[\begin{array}{l} \mathbf{if}\;y \leq 5.1 \cdot 10^{-113}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 8
Error42.9
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022354 
(FPCore (x y z)
  :name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
  :precision binary64
  (* (+ x y) (+ z 1.0)))