Average Error: 0.0 → 0.0
Time: 10.4s
Precision: binary64
Cost: 6720
\[x \cdot y + \left(1 - x\right) \cdot z \]
\[\mathsf{fma}\left(y - z, x, z\right) \]
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- 1.0 x) z)))
(FPCore (x y z) :precision binary64 (fma (- y z) x 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((y - z), x, 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(Float64(y - z), x, 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[(N[(y - z), $MachinePrecision] * x + z), $MachinePrecision]
x \cdot y + \left(1 - x\right) \cdot z
\mathsf{fma}\left(y - z, x, z\right)

Error

Derivation

  1. Initial program 0.0

    \[x \cdot y + \left(1 - x\right) \cdot z \]
  2. Taylor expanded in x around 0 0.0

    \[\leadsto \color{blue}{\left(-1 \cdot z + y\right) \cdot x + z} \]
  3. Simplified0.0

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

Alternatives

Alternative 1
Error26.9
Cost720
\[\begin{array}{l} \mathbf{if}\;z \leq -8.6 \cdot 10^{+151}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq -2.8 \cdot 10^{-7}:\\ \;\;\;\;-z \cdot x\\ \mathbf{elif}\;z \leq -8.2 \cdot 10^{-66}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 2.8 \cdot 10^{-79}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 2
Error16.2
Cost584
\[\begin{array}{l} t_0 := \left(1 - x\right) \cdot z\\ \mathbf{if}\;z \leq -7 \cdot 10^{-69}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.35 \cdot 10^{-119}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error13.4
Cost584
\[\begin{array}{l} t_0 := \left(1 - x\right) \cdot z\\ \mathbf{if}\;z \leq -7.5 \cdot 10^{-67}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.95 \cdot 10^{-79}:\\ \;\;\;\;\left(y - z\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error0.9
Cost584
\[\begin{array}{l} t_0 := \left(y - z\right) \cdot x\\ \mathbf{if}\;x \leq -1700:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;y \cdot x + z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error24.7
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -1.65 \cdot 10^{-62}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 2.35 \cdot 10^{-79}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 6
Error0.0
Cost448
\[z - \left(z - y\right) \cdot x \]
Alternative 7
Error34.6
Cost64
\[z \]

Error

Reproduce

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