?

Average Accuracy: 100.0% → 100.0%
Time: 7.4s
Precision: binary64
Cost: 6720

?

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

Error?

Derivation?

  1. Initial program 100.0%

    \[x \cdot y + \left(1 - x\right) \cdot z \]
  2. Simplified100.0%

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

    [Start]100.0

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

    +-commutative [=>]100.0

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

    *-commutative [=>]100.0

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

    sub-neg [=>]100.0

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

    distribute-rgt-in [=>]100.0

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

    associate-+l+ [=>]100.0

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

    *-lft-identity [=>]100.0

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

    +-commutative [=>]100.0

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

    *-commutative [=>]100.0

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

    neg-mul-1 [=>]100.0

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

    associate-*r* [=>]100.0

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

    *-commutative [=>]100.0

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

    distribute-rgt-out [=>]100.0

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

    fma-def [=>]100.0

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

    +-commutative [=>]100.0

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

    *-commutative [=>]100.0

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

    metadata-eval [<=]100.0

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

    cancel-sign-sub-inv [<=]100.0

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

    *-lft-identity [=>]100.0

    \[ \mathsf{fma}\left(x, y - \color{blue}{z}, z\right) \]
  3. Final simplification100.0%

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

Alternatives

Alternative 1
Accuracy60.9%
Cost1049
\[\begin{array}{l} t_0 := x \cdot \left(-z\right)\\ \mathbf{if}\;x \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.45 \cdot 10^{-62}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq -2.8 \cdot 10^{-114}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 0.0135:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 5.6 \cdot 10^{+86} \lor \neg \left(x \leq 2.15 \cdot 10^{+148}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 2
Accuracy78.6%
Cost850
\[\begin{array}{l} \mathbf{if}\;x \leq -2.2 \cdot 10^{+19} \lor \neg \left(x \leq -5.4 \cdot 10^{-63} \lor \neg \left(x \leq -2.8 \cdot 10^{-114}\right) \land x \leq 85000000\right):\\ \;\;\;\;x \cdot \left(y - z\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(1 - x\right)\\ \end{array} \]
Alternative 3
Accuracy61.8%
Cost720
\[\begin{array}{l} \mathbf{if}\;x \leq -2.55 \cdot 10^{-14}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -3.5 \cdot 10^{-64}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq -2.8 \cdot 10^{-114}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 1.2 \cdot 10^{-34}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 4
Accuracy74.5%
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -7.8 \cdot 10^{-56} \lor \neg \left(z \leq 2.7 \cdot 10^{-168}\right):\\ \;\;\;\;z \cdot \left(1 - x\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 5
Accuracy98.7%
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 0.0135\right):\\ \;\;\;\;x \cdot \left(y - z\right)\\ \mathbf{else}:\\ \;\;\;\;z + x \cdot y\\ \end{array} \]
Alternative 6
Accuracy100.0%
Cost448
\[z + x \cdot \left(y - z\right) \]
Alternative 7
Accuracy45.5%
Cost64
\[z \]

Error

Reproduce?

herbie shell --seed 2023137 
(FPCore (x y z)
  :name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
  :precision binary64
  (+ (* x y) (* (- 1.0 x) z)))