Average Error: 0.0 → 0.0
Time: 6.4s
Precision: binary64
Cost: 6720
\[\left(1 - x\right) \cdot y + x \cdot z \]
\[\mathsf{fma}\left(x, z - y, y\right) \]
(FPCore (x y z) :precision binary64 (+ (* (- 1.0 x) y) (* x z)))
(FPCore (x y z) :precision binary64 (fma x (- z y) 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(x, (z - y), 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(x, Float64(z - y), 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[(x * N[(z - y), $MachinePrecision] + y), $MachinePrecision]
\left(1 - x\right) \cdot y + x \cdot z
\mathsf{fma}\left(x, z - y, y\right)

Error

Target

Original0.0
Target0.0
Herbie0.0
\[y - x \cdot \left(y - z\right) \]

Derivation

  1. Initial program 0.0

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

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

    [Start]0.0

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

    *-commutative [=>]0.0

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

    sub-neg [=>]0.0

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

    distribute-rgt-in [=>]0.0

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

    associate-+l+ [=>]0.0

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

    *-lft-identity [=>]0.0

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

    +-commutative [=>]0.0

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

    *-commutative [=>]0.0

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

    neg-mul-1 [=>]0.0

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

    associate-*r* [=>]0.0

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

    *-commutative [=>]0.0

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

    distribute-rgt-out [=>]0.0

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

    fma-def [=>]0.0

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

    +-commutative [=>]0.0

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

    *-commutative [=>]0.0

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

    metadata-eval [<=]0.0

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

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

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

    *-lft-identity [=>]0.0

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

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

Alternatives

Alternative 1
Error25.2
Cost1444
\[\begin{array}{l} t_0 := y \cdot \left(-x\right)\\ \mathbf{if}\;x \leq -1.08 \cdot 10^{+85}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -2.1 \cdot 10^{-30}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq -2.1 \cdot 10^{-63}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq -1.75 \cdot 10^{-140}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq 1.28 \cdot 10^{-101}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq 2.8 \cdot 10^{-70}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq 1.85 \cdot 10^{-38}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq 3 \cdot 10^{+51}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq 1.3 \cdot 10^{+82}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]
Alternative 2
Error13.6
Cost1112
\[\begin{array}{l} t_0 := x \cdot \left(z - y\right)\\ \mathbf{if}\;x \leq -1.8 \cdot 10^{-30}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.35 \cdot 10^{-61}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq -5.2 \cdot 10^{-141}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.15 \cdot 10^{-101}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq 9 \cdot 10^{-70}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq 3.3 \cdot 10^{-38}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error25.1
Cost984
\[\begin{array}{l} \mathbf{if}\;x \leq -1.8 \cdot 10^{-30}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq -1.9 \cdot 10^{-62}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq -1.75 \cdot 10^{-140}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq 1.28 \cdot 10^{-101}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq 3.6 \cdot 10^{-70}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq 1.75 \cdot 10^{-38}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]
Alternative 4
Error1.1
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -23000000000000 \lor \neg \left(x \leq 1\right):\\ \;\;\;\;x \cdot \left(z - y\right)\\ \mathbf{else}:\\ \;\;\;\;y + x \cdot z\\ \end{array} \]
Alternative 5
Error0.0
Cost448
\[y + x \cdot \left(z - y\right) \]
Alternative 6
Error35.1
Cost64
\[y \]

Error

Reproduce

herbie shell --seed 2022354 
(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)))