Average Error: 0.0 → 0.0
Time: 3.7s
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)): 2 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): 1 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, 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, 1 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
Error27.3
Cost1312
\[\begin{array}{l} \mathbf{if}\;y \leq -5.773447051700112 \cdot 10^{-66}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq -2.981710148631162 \cdot 10^{-145}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;y \leq -1.682991552107247 \cdot 10^{-173}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 2.754382516288521 \cdot 10^{-189}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;y \leq 2.225984573575691 \cdot 10^{-87}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 4.542724604691555 \cdot 10^{+42}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;y \leq 3.2 \cdot 10^{+135}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 2.15 \cdot 10^{+170}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 2
Error16.4
Cost1112
\[\begin{array}{l} t_0 := y \cdot \left(1 - x\right)\\ \mathbf{if}\;y \leq -6.319927380519562 \cdot 10^{-97}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -2.981710148631162 \cdot 10^{-145}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;y \leq -1.682991552107247 \cdot 10^{-173}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.754382516288521 \cdot 10^{-189}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;y \leq 2.225984573575691 \cdot 10^{-87}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 3.4666447222400816 \cdot 10^{-56}:\\ \;\;\;\;x \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error16.4
Cost1112
\[\begin{array}{l} t_0 := y \cdot \left(1 - x\right)\\ \mathbf{if}\;y \leq -6.319927380519562 \cdot 10^{-97}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -2.981710148631162 \cdot 10^{-145}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;y \leq -1.682991552107247 \cdot 10^{-173}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.754382516288521 \cdot 10^{-189}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;y \leq 2.225984573575691 \cdot 10^{-87}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 3.4666447222400816 \cdot 10^{-56}:\\ \;\;\;\;x \cdot z\\ \mathbf{else}:\\ \;\;\;\;y - x \cdot y\\ \end{array} \]
Alternative 4
Error26.7
Cost984
\[\begin{array}{l} \mathbf{if}\;y \leq -5.773447051700112 \cdot 10^{-66}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq -2.981710148631162 \cdot 10^{-145}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;y \leq -1.682991552107247 \cdot 10^{-173}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 2.754382516288521 \cdot 10^{-189}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;y \leq 2.225984573575691 \cdot 10^{-87}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 4.542724604691555 \cdot 10^{+42}:\\ \;\;\;\;x \cdot z\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 5
Error8.6
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -8.454454692420731 \cdot 10^{-30}:\\ \;\;\;\;y \cdot \left(1 - x\right)\\ \mathbf{elif}\;y \leq 2.0495474832072557 \cdot 10^{-25}:\\ \;\;\;\;y + x \cdot z\\ \mathbf{else}:\\ \;\;\;\;y - x \cdot y\\ \end{array} \]
Alternative 6
Error1.1
Cost584
\[\begin{array}{l} t_0 := x \cdot \left(z - y\right)\\ \mathbf{if}\;x \leq -197977592845801.7:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 5.962689640315851 \cdot 10^{-7}:\\ \;\;\;\;y + x \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error0.0
Cost576
\[\left(y - x \cdot y\right) + x \cdot z \]
Alternative 8
Error35.3
Cost64
\[y \]

Error

Reproduce

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