Average Error: 0.0 → 0.0
Time: 4.0s
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
    (fma.f64 x (-.f64 z y) y): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (Rewrite<= unsub-neg_binary64 (+.f64 z (neg.f64 y))) y): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (+.f64 z (Rewrite=> neg-mul-1_binary64 (*.f64 -1 y))) y): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (+.f64 z (Rewrite<= *-commutative_binary64 (*.f64 y -1))) y): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 y -1) z)) y): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x (+.f64 (*.f64 y -1) z)) y)): 3 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= distribute-lft-out_binary64 (+.f64 (*.f64 x (*.f64 y -1)) (*.f64 x z))) y): 0 points increase in error, 1 points decrease in error
    (+.f64 (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (*.f64 y -1) x)) (*.f64 x z)) y): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (Rewrite<= associate-*r*_binary64 (*.f64 y (*.f64 -1 x))) (*.f64 x z)) y): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (*.f64 y (Rewrite<= neg-mul-1_binary64 (neg.f64 x))) (*.f64 x z)) y): 0 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 y (+.f64 (*.f64 y (neg.f64 x)) (*.f64 x z)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 y (*.f64 y (neg.f64 x))) (*.f64 x z))): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (Rewrite<= *-rgt-identity_binary64 (*.f64 y 1)) (*.f64 y (neg.f64 x))) (*.f64 x z)): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite=> distribute-lft-out_binary64 (*.f64 y (+.f64 1 (neg.f64 x)))) (*.f64 x z)): 2 points increase in error, 2 points decrease in error
    (+.f64 (*.f64 y (Rewrite<= sub-neg_binary64 (-.f64 1 x))) (*.f64 x z)): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (-.f64 1 x) y)) (*.f64 x z)): 0 points increase in error, 0 points decrease in error
  3. Final simplification0.0

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

Alternatives

Alternative 1
Error25.1
Cost1180
\[\begin{array}{l} t_0 := y \cdot \left(-x\right)\\ \mathbf{if}\;x \leq -2.7 \cdot 10^{+111}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq -2.05 \cdot 10^{+36}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -7.8 \cdot 10^{+16}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq 3.8 \cdot 10^{-121}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq 4.6 \cdot 10^{-43}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq 5.5 \cdot 10^{-24}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq 2.3 \cdot 10^{+21}:\\ \;\;\;\;x \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error19.2
Cost848
\[\begin{array}{l} t_0 := y \cdot \left(1 - x\right)\\ \mathbf{if}\;z \leq -5.2 \cdot 10^{+150}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -2.1 \cdot 10^{+54}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.9 \cdot 10^{-16}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq 3.4 \cdot 10^{-31}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]
Alternative 3
Error13.7
Cost848
\[\begin{array}{l} t_0 := x \cdot \left(z - y\right)\\ \mathbf{if}\;x \leq -7.8 \cdot 10^{+16}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 3.8 \cdot 10^{-121}:\\ \;\;\;\;y \cdot \left(1 - x\right)\\ \mathbf{elif}\;x \leq 5.5 \cdot 10^{-43}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq 2.05 \cdot 10^{-23}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error25.3
Cost720
\[\begin{array}{l} \mathbf{if}\;x \leq -7.8 \cdot 10^{+16}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq 3.8 \cdot 10^{-121}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq 4.6 \cdot 10^{-43}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq 8.2 \cdot 10^{-24}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]
Alternative 5
Error0.9
Cost584
\[\begin{array}{l} t_0 := x \cdot \left(z - y\right)\\ \mathbf{if}\;x \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;y + x \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error0.9
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;x \cdot z - x \cdot y\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;y + x \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(z - y\right)\\ \end{array} \]
Alternative 7
Error0.0
Cost576
\[x \cdot z + y \cdot \left(1 - x\right) \]
Alternative 8
Error34.1
Cost64
\[y \]

Error

Reproduce

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