Average Error: 0.0 → 0.0
Time: 5.8s
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)): 1 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
Error25.5
Cost1312
\[\begin{array}{l} t_0 := z \cdot \left(-x\right)\\ \mathbf{if}\;z \leq -7.6 \cdot 10^{+116}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -7.8 \cdot 10^{+41}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -108693584637327.83:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 3.6418935961236943 \cdot 10^{-103}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.45 \cdot 10^{+57}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 5.6 \cdot 10^{+126}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.4 \cdot 10^{+201}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 1.55 \cdot 10^{+233}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 2
Error13.6
Cost584
\[\begin{array}{l} t_0 := \left(y - x\right) \cdot z\\ \mathbf{if}\;z \leq -4.6181362329332:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 3.6418935961236943 \cdot 10^{-103}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error13.5
Cost584
\[\begin{array}{l} t_0 := \left(y - x\right) \cdot z\\ \mathbf{if}\;z \leq -108693584637327.83:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 3.6418935961236943 \cdot 10^{-103}:\\ \;\;\;\;x - x \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error1.3
Cost584
\[\begin{array}{l} t_0 := \left(y - x\right) \cdot z\\ \mathbf{if}\;z \leq -4.6181362329332:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.8896137520537308 \cdot 10^{-21}:\\ \;\;\;\;x + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error25.3
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -108693584637327.83:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 3.6418935961236943 \cdot 10^{-103}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 6
Error0.0
Cost448
\[x + \left(y - x\right) \cdot z \]
Alternative 7
Error35.2
Cost64
\[x \]

Error

Reproduce

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