Average Error: 0.0 → 0.0
Time: 3.1s
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 (-.f64 z (Rewrite<= *-lft-identity_binary64 (*.f64 1 y))) y): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (Rewrite=> cancel-sign-sub-inv_binary64 (+.f64 z (*.f64 (neg.f64 1) y))) y): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (+.f64 z (*.f64 (Rewrite=> metadata-eval -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)): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= distribute-rgt-out_binary64 (+.f64 (*.f64 (*.f64 y -1) x) (*.f64 z x))) y): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (Rewrite<= associate-*r*_binary64 (*.f64 y (*.f64 -1 x))) (*.f64 z x)) y): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (*.f64 y (Rewrite<= neg-mul-1_binary64 (neg.f64 x))) (*.f64 z x)) y): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (neg.f64 x) y)) (*.f64 z x)) y): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (*.f64 (neg.f64 x) y) (Rewrite<= *-commutative_binary64 (*.f64 x z))) y): 0 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 y (+.f64 (*.f64 (neg.f64 x) y) (*.f64 x z)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= *-lft-identity_binary64 (*.f64 1 y)) (+.f64 (*.f64 (neg.f64 x) y) (*.f64 x z))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (*.f64 1 y) (*.f64 (neg.f64 x) y)) (*.f64 x z))): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= distribute-rgt-in_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
Error26.0
Cost784
\[\begin{array}{l} \mathbf{if}\;y \leq -8.5 \cdot 10^{+37}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{-105}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;y \leq 4.6 \cdot 10^{-23}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 3 \cdot 10^{+33}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 2
Error11.8
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -8.6 \cdot 10^{-29} \lor \neg \left(x \leq 1.9 \cdot 10^{-6}\right):\\ \;\;\;\;x \cdot \left(z - y\right)\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 3
Error1.0
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 0.0076\right):\\ \;\;\;\;x \cdot \left(z - y\right)\\ \mathbf{else}:\\ \;\;\;\;y + x \cdot z\\ \end{array} \]
Alternative 4
Error0.0
Cost576
\[y \cdot \left(1 - x\right) + x \cdot z \]
Alternative 5
Error23.3
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -3.7 \cdot 10^{-29}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq 1.9 \cdot 10^{-6}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]
Alternative 6
Error34.9
Cost64
\[y \]

Error

Reproduce

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