Average Error: 0.0 → 0.0
Time: 5.7s
Precision: binary64
Cost: 6720
\[x + \left(y - x\right) \cdot z \]
\[\mathsf{fma}\left(y - x, z, x\right) \]
(FPCore (x y z) :precision binary64 (+ x (* (- y x) z)))
(FPCore (x y z) :precision binary64 (fma (- y x) z x))
double code(double x, double y, double z) {
	return x + ((y - x) * z);
}
double code(double x, double y, double z) {
	return fma((y - x), z, x);
}
function code(x, y, z)
	return Float64(x + Float64(Float64(y - x) * z))
end
function code(x, y, z)
	return fma(Float64(y - x), z, x)
end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := N[(N[(y - x), $MachinePrecision] * z + x), $MachinePrecision]
x + \left(y - x\right) \cdot z
\mathsf{fma}\left(y - x, z, x\right)

Error

Derivation

  1. Initial program 0.0

    \[x + \left(y - x\right) \cdot z \]
  2. Simplified0.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(y - x, z, x\right)} \]
    Proof
    (fma.f64 (-.f64 y x) z x): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (-.f64 y x) z) x)): 5 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 x (*.f64 (-.f64 y x) z))): 0 points increase in error, 0 points decrease in error
  3. Final simplification0.0

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

Alternatives

Alternative 1
Error23.6
Cost1312
\[\begin{array}{l} \mathbf{if}\;z \leq -0.125:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -1.16 \cdot 10^{-42}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -7 \cdot 10^{-56}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 2.65 \cdot 10^{-95}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 4.5 \cdot 10^{-68}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 2.95 \cdot 10^{-24}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2.7 \cdot 10^{+45}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 8.5 \cdot 10^{+143}:\\ \;\;\;\;x \cdot \left(-z\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 2
Error17.2
Cost1112
\[\begin{array}{l} t_0 := x \cdot \left(1 - z\right)\\ \mathbf{if}\;x \leq -6 \cdot 10^{-96}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4.2 \cdot 10^{-231}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 1.2 \cdot 10^{-157}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4.7 \cdot 10^{-135}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 0.27:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.9 \cdot 10^{+16}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error12.2
Cost1112
\[\begin{array}{l} t_0 := \left(y - x\right) \cdot z\\ \mathbf{if}\;z \leq -0.17:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.8 \cdot 10^{-42}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{elif}\;z \leq -6.8 \cdot 10^{-56}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.65 \cdot 10^{-95}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-67}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{-20}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error23.6
Cost984
\[\begin{array}{l} \mathbf{if}\;z \leq -0.125:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -5.2 \cdot 10^{-42}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -2.8 \cdot 10^{-55}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 4.2 \cdot 10^{-95}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 7.4 \cdot 10^{-68}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 3.15 \cdot 10^{-24}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 5
Error1.0
Cost584
\[\begin{array}{l} t_0 := \left(y - x\right) \cdot z\\ \mathbf{if}\;z \leq -235000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 0.00078:\\ \;\;\;\;x + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error0.0
Cost448
\[x + \left(y - x\right) \cdot z \]
Alternative 7
Error34.5
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022331 
(FPCore (x y z)
  :name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
  :precision binary64
  (+ x (* (- y x) z)))