Average Error: 0.0 → 0.0
Time: 8.5s
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)): 1 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): 3 points increase in error, 0 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, 1 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)): 3 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
Error29.9
Cost1512
\[\begin{array}{l} \mathbf{if}\;z \leq -6.5 \cdot 10^{+112}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -1.3295594800096171 \cdot 10^{+47}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq -3.9169128715632526 \cdot 10^{-19}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -2.7202787906946868 \cdot 10^{-185}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq -5.717775777224681 \cdot 10^{-251}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{elif}\;z \leq 4.190838602459173 \cdot 10^{-48}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 1.2467689497507308 \cdot 10^{-16}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq 4.6 \cdot 10^{+83}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 2.05 \cdot 10^{+125}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq 1.05 \cdot 10^{+165}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]
Alternative 2
Error25.9
Cost720
\[\begin{array}{l} \mathbf{if}\;y \leq -2.3801812722991917 \cdot 10^{-121}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 2.372665985168963 \cdot 10^{-77}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;y \leq 7.72570889896901 \cdot 10^{+55}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 3.6 \cdot 10^{+100}:\\ \;\;\;\;x \cdot z\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 3
Error15.9
Cost584
\[\begin{array}{l} t_0 := y \cdot \left(1 - x\right)\\ \mathbf{if}\;y \leq -2.3801812722991917 \cdot 10^{-121}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 8.89789429233346 \cdot 10^{-80}:\\ \;\;\;\;x \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error6.9
Cost584
\[\begin{array}{l} t_0 := y + x \cdot z\\ \mathbf{if}\;z \leq -8.769300275088442 \cdot 10^{-39}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.211919398067523 \cdot 10^{-77}:\\ \;\;\;\;y \cdot \left(1 - x\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error6.9
Cost584
\[\begin{array}{l} t_0 := y + x \cdot z\\ \mathbf{if}\;z \leq -8.769300275088442 \cdot 10^{-39}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.211919398067523 \cdot 10^{-77}:\\ \;\;\;\;y - x \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error1.1
Cost584
\[\begin{array}{l} t_0 := x \cdot \left(z - y\right)\\ \mathbf{if}\;x \leq -13330597388.302998:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.00026611670553742216:\\ \;\;\;\;y + x \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error0.0
Cost448
\[y + x \cdot \left(z - y\right) \]
Alternative 8
Error34.9
Cost64
\[y \]

Error

Reproduce

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