?

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

?

\[ \begin{array}{c}[x, y] = \mathsf{sort}([x, y])\\ \end{array} \]
\[\left(x + y\right) \cdot \left(1 - z\right) \]
\[\mathsf{fma}\left(1 - z, x, \left(1 - z\right) \cdot y\right) \]
(FPCore (x y z) :precision binary64 (* (+ x y) (- 1.0 z)))
(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) * (1.0 - z);
}
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(1.0 - z))
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[(1.0 - z), $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(1 - z\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(1 - z\right) \]
  2. Applied egg-rr0.0

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

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

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

    [Start]0.0

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

    fma-def [=>]0.0

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

    fma-def [=>]0.0

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

    +-commutative [<=]0.0

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

    *-commutative [<=]0.0

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

    mul-1-neg [=>]0.0

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

    sub-neg [<=]0.0

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

    *-commutative [=>]0.0

    \[ \mathsf{fma}\left(\mathsf{fma}\left(-1, z, 1\right), x, y - \color{blue}{y \cdot z}\right) \]
  5. Applied egg-rr0.0

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

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

Alternatives

Alternative 1
Error12.5
Cost980
\[\begin{array}{l} t_0 := x \cdot \left(-z\right)\\ \mathbf{if}\;z \leq -2.6 \cdot 10^{+231}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -5.4 \cdot 10^{+119}:\\ \;\;\;\;z \cdot \left(-y\right)\\ \mathbf{elif}\;z \leq -11.6:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 7.6 \cdot 10^{-6}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 9.5 \cdot 10^{+64}:\\ \;\;\;\;\left(1 - z\right) \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error12.3
Cost980
\[\begin{array}{l} t_0 := x \cdot \left(-z\right)\\ \mathbf{if}\;z \leq -2 \cdot 10^{+229}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -6.2 \cdot 10^{+118}:\\ \;\;\;\;z \cdot \left(-y\right)\\ \mathbf{elif}\;z \leq -1.3 \cdot 10^{-12}:\\ \;\;\;\;\left(1 - z\right) \cdot x\\ \mathbf{elif}\;z \leq 2.25 \cdot 10^{-5}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 8.5 \cdot 10^{+64}:\\ \;\;\;\;\left(1 - z\right) \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error12.3
Cost980
\[\begin{array}{l} t_0 := x \cdot \left(-z\right)\\ \mathbf{if}\;z \leq -6.2 \cdot 10^{+224}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.7 \cdot 10^{+119}:\\ \;\;\;\;z \cdot \left(-y\right)\\ \mathbf{elif}\;z \leq -1.3 \cdot 10^{-12}:\\ \;\;\;\;x - z \cdot x\\ \mathbf{elif}\;z \leq 3.3 \cdot 10^{-5}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 9 \cdot 10^{+64}:\\ \;\;\;\;\left(1 - z\right) \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error12.8
Cost916
\[\begin{array}{l} t_0 := x \cdot \left(-z\right)\\ t_1 := z \cdot \left(-y\right)\\ \mathbf{if}\;z \leq -9 \cdot 10^{+225}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -6.2 \cdot 10^{+118}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -19.5:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 2.7 \cdot 10^{+65}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error1.8
Cost905
\[\begin{array}{l} \mathbf{if}\;1 - z \leq -1 \lor \neg \left(1 - z \leq 2\right):\\ \;\;\;\;z \cdot \left(\left(-y\right) - x\right)\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 6
Error12.7
Cost521
\[\begin{array}{l} \mathbf{if}\;z \leq -25.5 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;x \cdot \left(-z\right)\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 7
Error0.0
Cost448
\[\left(1 - z\right) \cdot \left(x + y\right) \]
Alternative 8
Error31.0
Cost196
\[\begin{array}{l} \mathbf{if}\;x \leq -4.7 \cdot 10^{-60}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 9
Error23.9
Cost192
\[x + y \]
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, H"
  :precision binary64
  (* (+ x y) (- 1.0 z)))