?

Average Accuracy: 79.0% → 79.0%
Time: 9.8s
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 78.9%

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, y - z, z\right)} \]
    Step-by-step derivation

    [Start]78.9

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

    sub-neg [=>]78.9

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

    +-commutative [=>]78.9

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

    distribute-lft1-in [<=]78.9

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

    associate-+r+ [=>]78.9

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

    +-commutative [<=]78.9

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

    *-commutative [=>]78.9

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

    neg-mul-1 [=>]78.9

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

    associate-*r* [=>]78.9

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

    *-commutative [=>]78.9

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

    distribute-rgt-out [=>]78.9

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

    fma-def [=>]78.9

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

    +-commutative [=>]78.9

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

    *-commutative [=>]78.9

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

    neg-mul-1 [<=]78.9

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

    unsub-neg [=>]78.9

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

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

Alternatives

Alternative 1
Accuracy48.9%
Cost916
\[\begin{array}{l} t_0 := x \cdot \left(-z\right)\\ \mathbf{if}\;x \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -5.2 \cdot 10^{-139}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq -7.2 \cdot 10^{-158}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 3.6 \cdot 10^{+72}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 2
Accuracy63.1%
Cost850
\[\begin{array}{l} \mathbf{if}\;x \leq -31000000 \lor \neg \left(x \leq -2.2 \cdot 10^{-115} \lor \neg \left(x \leq -7.2 \cdot 10^{-158}\right) \land x \leq 2500000000\right):\\ \;\;\;\;x \cdot \left(y - z\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(1 - x\right)\\ \end{array} \]
Alternative 3
Accuracy49.6%
Cost720
\[\begin{array}{l} \mathbf{if}\;x \leq -30000000:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -5.2 \cdot 10^{-139}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq -7.2 \cdot 10^{-158}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 1.75 \cdot 10^{-7}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 4
Accuracy59.4%
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \cdot 10^{-184} \lor \neg \left(z \leq 10^{-66}\right):\\ \;\;\;\;z \cdot \left(1 - x\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 5
Accuracy77.9%
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\ \;\;\;\;x \cdot \left(y - z\right)\\ \mathbf{else}:\\ \;\;\;\;z + x \cdot y\\ \end{array} \]
Alternative 6
Accuracy79.0%
Cost576
\[x \cdot y + z \cdot \left(1 - x\right) \]
Alternative 7
Accuracy79.0%
Cost448
\[z + x \cdot \left(y - z\right) \]
Alternative 8
Accuracy36.7%
Cost64
\[z \]

Error

Reproduce?

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