Average Error: 0.0 → 0.0
Time: 6.4s
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): 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))))): 1 points increase in error, 2 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
Error17.0
Cost848
\[\begin{array}{l} t_0 := z \cdot \left(1 - x\right)\\ \mathbf{if}\;z \leq -1.1160656494116042 \cdot 10^{-146}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.113834169720798 \cdot 10^{-113}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;z \leq 5.737260381570398 \cdot 10^{-96}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 9.64131043765487 \cdot 10^{-5}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error17.0
Cost848
\[\begin{array}{l} t_0 := z \cdot \left(1 - x\right)\\ \mathbf{if}\;z \leq -1.1160656494116042 \cdot 10^{-146}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.113834169720798 \cdot 10^{-113}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;z \leq 5.737260381570398 \cdot 10^{-96}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 9.64131043765487 \cdot 10^{-5}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;z - x \cdot z\\ \end{array} \]
Alternative 3
Error25.1
Cost720
\[\begin{array}{l} \mathbf{if}\;z \leq -1.2850787284377724 \cdot 10^{-34}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq -5.336110641963474 \cdot 10^{-117}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;z \leq -1.1160656494116042 \cdot 10^{-146}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 0.014167047889273025:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 4
Error0.8
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -11.95597857916088:\\ \;\;\;\;x \cdot \left(y - z\right)\\ \mathbf{elif}\;x \leq 0.3361407002359509:\\ \;\;\;\;z + x \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot y - x \cdot z\\ \end{array} \]
Alternative 5
Error23.3
Cost588
\[\begin{array}{l} \mathbf{if}\;x \leq -3 \cdot 10^{+58}:\\ \;\;\;\;z \cdot \left(-x\right)\\ \mathbf{elif}\;x \leq -9.993463487810754 \cdot 10^{-53}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 4.5688526236287286 \cdot 10^{-32}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 6
Error12.2
Cost584
\[\begin{array}{l} t_0 := x \cdot \left(y - z\right)\\ \mathbf{if}\;x \leq -9.993463487810754 \cdot 10^{-53}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.3361407002359509:\\ \;\;\;\;z \cdot \left(1 - x\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error0.8
Cost584
\[\begin{array}{l} t_0 := x \cdot \left(y - z\right)\\ \mathbf{if}\;x \leq -11.95597857916088:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.3361407002359509:\\ \;\;\;\;z + x \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error0.0
Cost576
\[x \cdot y + z \cdot \left(1 - x\right) \]
Alternative 9
Error0.0
Cost448
\[z + x \cdot \left(y - z\right) \]
Alternative 10
Error34.6
Cost64
\[z \]

Error

Reproduce

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