Average Error: 0.0 → 0.0
Time: 6.0s
Precision: binary64
Cost: 6720
\[x \cdot y + \left(1 - x\right) \cdot z \]
\[\mathsf{fma}\left(x, y - z, z\right) \]
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- 1.0 x) z)))
(FPCore (x y z) :precision binary64 (fma x (- y z) z))
double code(double x, double y, double z) {
	return (x * y) + ((1.0 - x) * z);
}
double code(double x, double y, double z) {
	return fma(x, (y - z), z);
}
function code(x, y, z)
	return Float64(Float64(x * y) + Float64(Float64(1.0 - x) * z))
end
function code(x, y, z)
	return fma(x, Float64(y - z), z)
end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := N[(x * N[(y - z), $MachinePrecision] + z), $MachinePrecision]
x \cdot y + \left(1 - x\right) \cdot z
\mathsf{fma}\left(x, y - z, z\right)

Error

Derivation

  1. Initial program 0.0

    \[x \cdot y + \left(1 - x\right) \cdot z \]
  2. Simplified0.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, y - z, z\right)} \]
    Proof
    (fma.f64 x (-.f64 y z) z): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (Rewrite<= unsub-neg_binary64 (+.f64 y (neg.f64 z))) z): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (+.f64 y (Rewrite=> neg-mul-1_binary64 (*.f64 -1 z))) z): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (+.f64 y (Rewrite<= *-commutative_binary64 (*.f64 z -1))) z): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 z -1) y)) z): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x (+.f64 (*.f64 z -1) y)) z)): 3 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= distribute-lft-out_binary64 (+.f64 (*.f64 x (*.f64 z -1)) (*.f64 x y))) z): 1 points increase in error, 1 points decrease in error
    (+.f64 (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (*.f64 z -1) x)) (*.f64 x y)) z): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (Rewrite<= associate-*r*_binary64 (*.f64 z (*.f64 -1 x))) (*.f64 x y)) z): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (*.f64 z (Rewrite<= neg-mul-1_binary64 (neg.f64 x))) (*.f64 x y)) z): 0 points increase in error, 0 points decrease in error
    (Rewrite=> associate-+l+_binary64 (+.f64 (*.f64 z (neg.f64 x)) (+.f64 (*.f64 x y) z))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 (+.f64 (*.f64 x y) z) (*.f64 z (neg.f64 x)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+r+_binary64 (+.f64 (*.f64 x y) (+.f64 z (*.f64 z (neg.f64 x))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 x y) (+.f64 (Rewrite<= *-rgt-identity_binary64 (*.f64 z 1)) (*.f64 z (neg.f64 x)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 x y) (Rewrite=> distribute-lft-out_binary64 (*.f64 z (+.f64 1 (neg.f64 x))))): 3 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 x y) (*.f64 z (Rewrite<= sub-neg_binary64 (-.f64 1 x)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 x y) (Rewrite<= *-commutative_binary64 (*.f64 (-.f64 1 x) z))): 0 points increase in error, 0 points decrease in error
  3. Final simplification0.0

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

Alternatives

Alternative 1
Error26.1
Cost1180
\[\begin{array}{l} t_0 := x \cdot \left(-z\right)\\ \mathbf{if}\;x \leq -6.2 \cdot 10^{+237}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -6 \cdot 10^{+102}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -3.582620232084313 \cdot 10^{-59}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -1.3941658689435104 \cdot 10^{-74}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq -1.3219459032382377 \cdot 10^{-144}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 9.597387351049036 \cdot 10^{-57}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 2 \cdot 10^{+139}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error17.9
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -1.0492324053620945 \cdot 10^{+45}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 2.618651262408433 \cdot 10^{+59}:\\ \;\;\;\;z \cdot \left(1 - x\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 3
Error12.8
Cost584
\[\begin{array}{l} t_0 := z \cdot \left(1 - x\right)\\ \mathbf{if}\;z \leq -0.007169721633182441:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.0844860211597655 \cdot 10^{-102}:\\ \;\;\;\;x \cdot \left(y - z\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error0.9
Cost584
\[\begin{array}{l} t_0 := x \cdot \left(y - z\right)\\ \mathbf{if}\;x \leq -489738.6868603319:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.004019707289654533:\\ \;\;\;\;z + x \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error24.6
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -0.007169721633182441:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 1.0844860211597655 \cdot 10^{-102}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 6
Error0.0
Cost448
\[z + x \cdot \left(y - z\right) \]
Alternative 7
Error35.0
Cost64
\[z \]

Error

Reproduce

herbie shell --seed 2022308 
(FPCore (x y z)
  :name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
  :precision binary64
  (+ (* x y) (* (- 1.0 x) z)))