?

Average Error: 0.02% → 0.01%
Time: 5.4s
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.02

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

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

    [Start]0.02

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

    +-commutative [=>]0.02

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

    fma-def [=>]0.01

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

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

Alternatives

Alternative 1
Error37.57%
Cost784
\[\begin{array}{l} t_0 := x \cdot \left(-z\right)\\ \mathbf{if}\;z \leq -1.9 \cdot 10^{+86}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 6.4 \cdot 10^{-27}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2.15 \cdot 10^{+105}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error19.21%
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -72000000 \lor \neg \left(z \leq 50\right):\\ \;\;\;\;\left(y - x\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \end{array} \]
Alternative 3
Error1.52%
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 0.0125\right):\\ \;\;\;\;\left(y - x\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot z\\ \end{array} \]
Alternative 4
Error27.23%
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -1.55 \cdot 10^{+83}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{+64}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 5
Error0.02%
Cost576
\[x + \left(y \cdot z - x \cdot z\right) \]
Alternative 6
Error36.78%
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -1.02 \cdot 10^{-8}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 2.2 \cdot 10^{-28}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 7
Error0.02%
Cost448
\[x + \left(y - x\right) \cdot z \]
Alternative 8
Error53.64%
Cost64
\[x \]

Error

Reproduce?

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