Average Error: 0.0 → 0.0
Time: 4.1s
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)): 5 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): 0 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))))): 0 points increase in error, 3 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
Error25.9
Cost1444
\[\begin{array}{l} t_0 := z \cdot \left(-x\right)\\ \mathbf{if}\;x \leq -3.2 \cdot 10^{+165}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -5.8 \cdot 10^{+134}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -195.2286821300134:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -3.322402143460988 \cdot 10^{-9}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -6.507492726819882 \cdot 10^{-27}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq -4.7171428347380356 \cdot 10^{-138}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 3.1141371189478446 \cdot 10^{-34}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 48.04864713860373:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 5.8 \cdot 10^{+67}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 2
Error11.8
Cost980
\[\begin{array}{l} t_0 := z \cdot \left(1 - x\right)\\ \mathbf{if}\;x \leq -3.2 \cdot 10^{+165}:\\ \;\;\;\;z \cdot \left(-x\right)\\ \mathbf{elif}\;x \leq -5.8 \cdot 10^{+134}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -195.2286821300134:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 48.04864713860373:\\ \;\;\;\;z + x \cdot y\\ \mathbf{elif}\;x \leq 5.8 \cdot 10^{+67}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 3
Error1.0
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -3.8984196462695966:\\ \;\;\;\;x \cdot \left(y - z\right)\\ \mathbf{elif}\;x \leq 1.1124146480757623 \cdot 10^{-8}:\\ \;\;\;\;z + x \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot y - x \cdot z\\ \end{array} \]
Alternative 4
Error15.7
Cost584
\[\begin{array}{l} t_0 := z \cdot \left(1 - x\right)\\ \mathbf{if}\;z \leq -2.2024825167068496 \cdot 10^{-144}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 8.957661735392605 \cdot 10^{-138}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error0.9
Cost584
\[\begin{array}{l} t_0 := x \cdot \left(y - z\right)\\ \mathbf{if}\;x \leq -3.8984196462695966:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.1124146480757623 \cdot 10^{-8}:\\ \;\;\;\;z + x \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error0.0
Cost576
\[x \cdot y + z \cdot \left(1 - x\right) \]
Alternative 7
Error25.8
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -2.2024825167068496 \cdot 10^{-144}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 1645020192140757.5:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 8
Error35.0
Cost64
\[z \]

Error

Reproduce

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