Average Error: 0.0 → 0.0
Time: 4.3s
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): 2 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, 1 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
Error15.6
Cost976
\[\begin{array}{l} t_0 := z - x \cdot z\\ \mathbf{if}\;z \leq -8.824385662209825 \cdot 10^{+20}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -4.2212722153057935 \cdot 10^{-34}:\\ \;\;\;\;x \cdot \left(y - z\right)\\ \mathbf{elif}\;z \leq -3.234391792784515 \cdot 10^{-196}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.3568452767469446 \cdot 10^{-80}:\\ \;\;\;\;x \cdot y - x \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error15.6
Cost848
\[\begin{array}{l} t_0 := z - x \cdot z\\ t_1 := x \cdot \left(y - z\right)\\ \mathbf{if}\;z \leq -8.824385662209825 \cdot 10^{+20}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -4.2212722153057935 \cdot 10^{-34}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -3.234391792784515 \cdot 10^{-196}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.3568452767469446 \cdot 10^{-80}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error27.6
Cost784
\[\begin{array}{l} t_0 := x \cdot \left(-z\right)\\ \mathbf{if}\;x \leq -1.8002311992849882 \cdot 10^{+21}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.0471112012912286 \cdot 10^{-192}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 6.012235599748525 \cdot 10^{-23}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{+33}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error26.7
Cost720
\[\begin{array}{l} \mathbf{if}\;z \leq -3592124502234.3394:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq -1.0231869451584741 \cdot 10^{-35}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;z \leq -3.234391792784515 \cdot 10^{-196}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 1.0419871688924338 \cdot 10^{-60}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 5
Error16.0
Cost584
\[\begin{array}{l} t_0 := x \cdot \left(y - z\right)\\ \mathbf{if}\;x \leq -1.0471112012912286 \cdot 10^{-192}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 6.012235599748525 \cdot 10^{-23}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error0.0
Cost448
\[z + x \cdot \left(y - z\right) \]
Alternative 7
Error35.2
Cost64
\[z \]

Error

Reproduce

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