Average Error: 0.0 → 0.0
Time: 3.6s
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)} \]
  3. Final simplification0.0

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

Alternatives

Alternative 1
Error24.5
Cost784
\[\begin{array}{l} t_0 := z \cdot \left(-x\right)\\ \mathbf{if}\;x \leq -151.9358696265468:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.637579584658845 \cdot 10^{-71}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{+50}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 6.4 \cdot 10^{+97}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 2
Error7.0
Cost584
\[\begin{array}{l} t_0 := z + x \cdot y\\ \mathbf{if}\;y \leq -2.8242493482857007 \cdot 10^{-129}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.0844511696676437 \cdot 10^{-150}:\\ \;\;\;\;z - x \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error7.0
Cost584
\[\begin{array}{l} t_0 := z + x \cdot y\\ \mathbf{if}\;y \leq -2.8242493482857007 \cdot 10^{-129}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.0844511696676437 \cdot 10^{-150}:\\ \;\;\;\;z \cdot \left(1 - x\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error1.2
Cost584
\[\begin{array}{l} t_0 := x \cdot \left(y - z\right)\\ \mathbf{if}\;x \leq -151.9358696265468:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.3048847798148325 \cdot 10^{-14}:\\ \;\;\;\;z + x \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error11.7
Cost520
\[\begin{array}{l} \mathbf{if}\;x \leq 2.1 \cdot 10^{+55}:\\ \;\;\;\;z + x \cdot y\\ \mathbf{elif}\;x \leq 6.4 \cdot 10^{+97}:\\ \;\;\;\;z \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 6
Error23.8
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -2.788910637546426 \cdot 10^{-45}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 2.637579584658845 \cdot 10^{-71}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 7
Error0.0
Cost448
\[z + x \cdot \left(y - z\right) \]
Alternative 8
Error34.3
Cost64
\[z \]

Error

Reproduce

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