?

Average Error: 0.0 → 0.0
Time: 6.5s
Precision: binary64
Cost: 6976

?

\[ \begin{array}{c}[x, y] = \mathsf{sort}([x, y])\\ \end{array} \]
\[\left(x + y\right) \cdot \left(z + 1\right) \]
\[\mathsf{fma}\left(1 + z, x, \left(1 + z\right) \cdot y\right) \]
(FPCore (x y z) :precision binary64 (* (+ x y) (+ z 1.0)))
(FPCore (x y z) :precision binary64 (fma (+ 1.0 z) x (* (+ 1.0 z) y)))
double code(double x, double y, double z) {
	return (x + y) * (z + 1.0);
}
double code(double x, double y, double z) {
	return fma((1.0 + z), x, ((1.0 + z) * y));
}
function code(x, y, z)
	return Float64(Float64(x + y) * Float64(z + 1.0))
end
function code(x, y, z)
	return fma(Float64(1.0 + z), x, Float64(Float64(1.0 + z) * y))
end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := N[(N[(1.0 + z), $MachinePrecision] * x + N[(N[(1.0 + z), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\left(x + y\right) \cdot \left(z + 1\right)
\mathsf{fma}\left(1 + z, x, \left(1 + z\right) \cdot y\right)

Error?

Derivation?

  1. Initial program 0.0

    \[\left(x + y\right) \cdot \left(z + 1\right) \]
  2. Taylor expanded in x around 0 0.0

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

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

    [Start]0.0

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

    +-commutative [<=]0.0

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

    fma-def [=>]0.0

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

    +-commutative [=>]0.0

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

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

Alternatives

Alternative 1
Error32.1
Cost1644
\[\begin{array}{l} \mathbf{if}\;z \leq -1.65 \cdot 10^{+227}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -5.5 \cdot 10^{+119}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;z \leq -1:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -3.4 \cdot 10^{-77}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -5.4 \cdot 10^{-110}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{-276}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2.9 \cdot 10^{-132}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 1.6 \cdot 10^{-105}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 9 \cdot 10^{-71}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 170:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.8 \cdot 10^{+66}:\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 2
Error32.0
Cost1248
\[\begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -4.2 \cdot 10^{-77}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -5.5 \cdot 10^{-110}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 8.8 \cdot 10^{-275}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 8.5 \cdot 10^{-132}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 1.1 \cdot 10^{-104}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 4.8 \cdot 10^{-71}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 2.2:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 3
Error12.5
Cost980
\[\begin{array}{l} \mathbf{if}\;z \leq -4.5 \cdot 10^{+224}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -3.1 \cdot 10^{+119}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;z \leq -1:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq 2.05 \cdot 10^{-5}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 1.6 \cdot 10^{+66}:\\ \;\;\;\;\left(1 + z\right) \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 4
Error12.3
Cost980
\[\begin{array}{l} \mathbf{if}\;z \leq -1.05 \cdot 10^{+225}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -3.8 \cdot 10^{+118}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;z \leq -1.3 \cdot 10^{-12}:\\ \;\;\;\;\left(1 + z\right) \cdot x\\ \mathbf{elif}\;z \leq 0.0076:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 7.6 \cdot 10^{+65}:\\ \;\;\;\;\left(1 + z\right) \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 5
Error12.8
Cost852
\[\begin{array}{l} \mathbf{if}\;z \leq -7 \cdot 10^{+224}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -5.5 \cdot 10^{+119}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;z \leq -1:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq 190:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 9.4 \cdot 10^{+64}:\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 6
Error1.8
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;z \cdot \left(x + y\right)\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 7
Error0.0
Cost576
\[x + \left(y + z \cdot \left(x + y\right)\right) \]
Alternative 8
Error0.0
Cost448
\[\left(1 + z\right) \cdot \left(x + y\right) \]
Alternative 9
Error31.0
Cost196
\[\begin{array}{l} \mathbf{if}\;x \leq -3.2 \cdot 10^{-60}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 10
Error43.7
Cost64
\[x \]

Error

Reproduce?

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