Average Error: 0.0 → 0.0
Time: 5.9s
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)): 0 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
Error16.7
Cost850
\[\begin{array}{l} \mathbf{if}\;x \leq -1.1 \cdot 10^{-36} \lor \neg \left(x \leq -5.5 \cdot 10^{-147}\right) \land \left(x \leq -6 \cdot 10^{-169} \lor \neg \left(x \leq 1.3 \cdot 10^{-134}\right)\right):\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 2
Error24.7
Cost720
\[\begin{array}{l} \mathbf{if}\;x \leq -8200000000000:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 9.2 \cdot 10^{-93}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 1.15 \cdot 10^{-61}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.3 \cdot 10^{-27}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error12.5
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -9.2 \cdot 10^{-82} \lor \neg \left(z \leq 0.42\right):\\ \;\;\;\;\left(y - x\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \end{array} \]
Alternative 4
Error0.9
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 0.95\right):\\ \;\;\;\;\left(y - x\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot z\\ \end{array} \]
Alternative 5
Error24.5
Cost520
\[\begin{array}{l} \mathbf{if}\;z \leq -4.3 \cdot 10^{-80}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(-z\right)\\ \end{array} \]
Alternative 6
Error0.0
Cost448
\[x + \left(y - x\right) \cdot z \]
Alternative 7
Error34.7
Cost64
\[x \]

Error

Reproduce

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