Average Error: 0.0 → 0.0
Time: 6.6s
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)): 2 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
Error15.7
Cost1112
\[\begin{array}{l} t_0 := x \cdot \left(1 - z\right)\\ t_1 := \left(y - x\right) \cdot z\\ \mathbf{if}\;x \leq -2.7610344307649485 \cdot 10^{+75}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -6.14050355646004 \cdot 10^{-39}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.1338017333462276 \cdot 10^{-97}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.022669151145139 \cdot 10^{-213}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.0200088596468365 \cdot 10^{-174}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 3.137708040318958 \cdot 10^{-128}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error15.7
Cost1112
\[\begin{array}{l} t_0 := x \cdot \left(1 - z\right)\\ t_1 := \left(y - x\right) \cdot z\\ \mathbf{if}\;x \leq -2.7610344307649485 \cdot 10^{+75}:\\ \;\;\;\;x - x \cdot z\\ \mathbf{elif}\;x \leq -6.14050355646004 \cdot 10^{-39}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.1338017333462276 \cdot 10^{-97}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.022669151145139 \cdot 10^{-213}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.0200088596468365 \cdot 10^{-174}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 3.137708040318958 \cdot 10^{-128}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error27.2
Cost984
\[\begin{array}{l} \mathbf{if}\;x \leq -2.7610344307649485 \cdot 10^{+75}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -6.14050355646004 \cdot 10^{-39}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq -1.1338017333462276 \cdot 10^{-97}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.119910048825879 \cdot 10^{-219}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 1.0200088596468365 \cdot 10^{-174}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.137708040318958 \cdot 10^{-128}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error16.7
Cost848
\[\begin{array}{l} t_0 := x \cdot \left(1 - z\right)\\ \mathbf{if}\;x \leq -1.1338017333462276 \cdot 10^{-97}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.119910048825879 \cdot 10^{-219}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 2.106107471649781 \cdot 10^{-152}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 3.137708040318958 \cdot 10^{-128}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error24.2
Cost784
\[\begin{array}{l} t_0 := x \cdot \left(-z\right)\\ \mathbf{if}\;z \leq -14518.540134787778:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.263832731022775 \cdot 10^{-26}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.0218201840965185 \cdot 10^{+23}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 5.5 \cdot 10^{+105}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 6
Error1.1
Cost584
\[\begin{array}{l} t_0 := \left(y - x\right) \cdot z\\ \mathbf{if}\;z \leq -14518.540134787778:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 3.4403033977396004 \cdot 10^{-8}:\\ \;\;\;\;x + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error0.0
Cost448
\[x + \left(y - x\right) \cdot z \]
Alternative 8
Error34.6
Cost64
\[x \]

Error

Reproduce

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