Average Error: 0.0 → 0.0
Time: 5.1s
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)): 4 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
Error23.7
Cost588
\[\begin{array}{l} \mathbf{if}\;z \leq -4.2 \cdot 10^{+95}:\\ \;\;\;\;x \cdot \left(-z\right)\\ \mathbf{elif}\;z \leq -1.3876203111632268 \cdot 10^{-21}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 5.31083779224997 \cdot 10^{-16}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 2
Error15.3
Cost584
\[\begin{array}{l} t_0 := x \cdot \left(1 - z\right)\\ \mathbf{if}\;x \leq -8.485827140897687 \cdot 10^{-103}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4.429184153709283 \cdot 10^{-100}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error7.5
Cost584
\[\begin{array}{l} t_0 := x + y \cdot z\\ \mathbf{if}\;y \leq -4.285222997519684 \cdot 10^{-192}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 8.147564249944315 \cdot 10^{-160}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \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 -32123871787600847000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 0.006601804980362321:\\ \;\;\;\;x + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error0.0
Cost576
\[x + \left(y \cdot z - x \cdot z\right) \]
Alternative 6
Error23.7
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -1.3876203111632268 \cdot 10^{-21}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 5.31083779224997 \cdot 10^{-16}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 7
Error0.0
Cost448
\[x + \left(y - x\right) \cdot z \]
Alternative 8
Error35.1
Cost64
\[x \]

Error

Reproduce

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