?

Average Error: 0.0 → 0.0
Time: 3.2s
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

    [Start]0.0

    \[ x + \left(y - x\right) \cdot z \]

    +-commutative [=>]0.0

    \[ \color{blue}{\left(y - x\right) \cdot z + x} \]

    fma-def [=>]0.0

    \[ \color{blue}{\mathsf{fma}\left(y - x, z, x\right)} \]
  3. Final simplification0.0

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

Alternatives

Alternative 1
Error24.0
Cost1312
\[\begin{array}{l} t_0 := z \cdot \left(-x\right)\\ \mathbf{if}\;z \leq -4.7 \cdot 10^{+93}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -3.5 \cdot 10^{+68}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -8 \cdot 10^{+37}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -9 \cdot 10^{-16}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -1.25 \cdot 10^{-71}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -2.8 \cdot 10^{-90}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 1.2 \cdot 10^{-62}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 9 \cdot 10^{+28}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error18.7
Cost849
\[\begin{array}{l} \mathbf{if}\;y \leq -1.5 \cdot 10^{+132}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq -4 \cdot 10^{+89} \lor \neg \left(y \leq -7.5 \cdot 10^{-44}\right) \land y \leq 3.1 \cdot 10^{+66}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 3
Error12.8
Cost848
\[\begin{array}{l} t_0 := \left(y - x\right) \cdot z\\ \mathbf{if}\;z \leq -1.1 \cdot 10^{-7}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1 \cdot 10^{-71}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{elif}\;z \leq -1.04 \cdot 10^{-91}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 10^{-62}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error24.3
Cost720
\[\begin{array}{l} \mathbf{if}\;z \leq -4 \cdot 10^{-26}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -8 \cdot 10^{-72}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -3.1 \cdot 10^{-90}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 1.22 \cdot 10^{-62}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 5
Error0.0
Cost448
\[x + \left(y - x\right) \cdot z \]
Alternative 6
Error34.7
Cost64
\[x \]

Error

Reproduce?

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