Average Error: 0.0 → 0.0
Time: 2.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)): 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): 2 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))): 1 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)): 0 points increase in error, 0 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
Error23.5
Cost916
\[\begin{array}{l} t_0 := x \cdot \left(-y\right)\\ \mathbf{if}\;x \leq -8.4 \cdot 10^{+189}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq -5.46527218504634 \cdot 10^{+29}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -8.671614147198734 \cdot 10^{-12}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq 4.2429390155870266 \cdot 10^{-38}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq 9.5 \cdot 10^{+80}:\\ \;\;\;\;x \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error15.9
Cost584
\[\begin{array}{l} t_0 := y - x \cdot y\\ \mathbf{if}\;y \leq -2.5393078443386733 \cdot 10^{-133}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.4392226145766074 \cdot 10^{-144}:\\ \;\;\;\;x \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error12.1
Cost584
\[\begin{array}{l} t_0 := x \cdot \left(z - y\right)\\ \mathbf{if}\;x \leq -8.671614147198734 \cdot 10^{-12}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4.2429390155870266 \cdot 10^{-38}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error0.0
Cost576
\[y \cdot \left(1 - x\right) + x \cdot z \]
Alternative 5
Error23.6
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -8.671614147198734 \cdot 10^{-12}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq 4.2429390155870266 \cdot 10^{-38}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]
Alternative 6
Error34.7
Cost64
\[y \]

Error

Reproduce

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