?

Average Accuracy: 100.0% → 100.0%
Time: 4.4s
Precision: binary64
Cost: 6848

?

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

Error?

Target

Original100.0%
Target100.0%
Herbie100.0%
\[y - x \cdot \left(y - z\right) \]

Derivation?

  1. Initial program 100.0%

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

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

    [Start]100.0

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

    +-commutative [=>]100.0

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

    *-commutative [=>]100.0

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

    fma-def [=>]100.0

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

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

Alternatives

Alternative 1
Accuracy100.0%
Cost6720
\[\mathsf{fma}\left(x, z - y, y\right) \]
Alternative 2
Accuracy68.3%
Cost849
\[\begin{array}{l} \mathbf{if}\;z \leq -1.4 \cdot 10^{+122}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq 1.8 \cdot 10^{-70} \lor \neg \left(z \leq 1.8 \cdot 10^{+23}\right) \land z \leq 4.2 \cdot 10^{+126}:\\ \;\;\;\;\left(1 - x\right) \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 3
Accuracy62.4%
Cost652
\[\begin{array}{l} \mathbf{if}\;x \leq -6 \cdot 10^{-26}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{-64}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq 10^{+45}:\\ \;\;\;\;z \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \end{array} \]
Alternative 4
Accuracy81.0%
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -62000 \lor \neg \left(x \leq 7.8 \cdot 10^{-64}\right):\\ \;\;\;\;x \cdot \left(z - y\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 - x\right) \cdot y\\ \end{array} \]
Alternative 5
Accuracy98.5%
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\ \;\;\;\;x \cdot \left(z - y\right)\\ \mathbf{else}:\\ \;\;\;\;y + z \cdot x\\ \end{array} \]
Alternative 6
Accuracy100.0%
Cost576
\[\left(1 - x\right) \cdot y + z \cdot x \]
Alternative 7
Accuracy62.6%
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1.95 \cdot 10^{-22}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq 7.8 \cdot 10^{-64}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 8
Accuracy100.0%
Cost448
\[y + x \cdot \left(z - y\right) \]
Alternative 9
Accuracy44.5%
Cost64
\[y \]

Error

Reproduce?

herbie shell --seed 2023135 
(FPCore (x y z)
  :name "Diagrams.Color.HSV:lerp  from diagrams-contrib-1.3.0.5"
  :precision binary64

  :herbie-target
  (- y (* x (- y z)))

  (+ (* (- 1.0 x) y) (* x z)))