Average Error: 0.0 → 0.0
Time: 6.3s
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)): 5 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
Error26.5
Cost1444
\[\begin{array}{l} t_0 := z \cdot \left(-x\right)\\ \mathbf{if}\;z \leq -1.5 \cdot 10^{+48}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -2.3975546825524242 \cdot 10^{+20}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -4.277029720035062 \cdot 10^{-13}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -2.5556540052464727 \cdot 10^{-68}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -4.908044267308802 \cdot 10^{-158}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 1.3874543125872942 \cdot 10^{-123}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 0.06080698161188071:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 7.4 \cdot 10^{+61}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.8 \cdot 10^{+137}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error11.8
Cost916
\[\begin{array}{l} t_0 := x + y \cdot z\\ t_1 := z \cdot \left(-x\right)\\ \mathbf{if}\;z \leq -2.2 \cdot 10^{+44}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.85 \cdot 10^{+23}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 0.06080698161188071:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 7.4 \cdot 10^{+61}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.8 \cdot 10^{+137}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error7.3
Cost584
\[\begin{array}{l} t_0 := x + y \cdot z\\ \mathbf{if}\;y \leq -1.2675943329902867 \cdot 10^{-64}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 7.546039477756458 \cdot 10^{-186}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error1.0
Cost584
\[\begin{array}{l} t_0 := \left(y - x\right) \cdot z\\ \mathbf{if}\;z \leq -335.7984585828583:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 0.002967947162656754:\\ \;\;\;\;x + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error1.0
Cost584
\[\begin{array}{l} \mathbf{if}\;z \leq -335.7984585828583:\\ \;\;\;\;y \cdot z - x \cdot z\\ \mathbf{elif}\;z \leq 0.002967947162656754:\\ \;\;\;\;x + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;\left(y - x\right) \cdot z\\ \end{array} \]
Alternative 6
Error0.0
Cost576
\[\left(x - x \cdot z\right) + y \cdot z \]
Alternative 7
Error25.9
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1.7497540898071024 \cdot 10^{-9}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.5673003047544302 \cdot 10^{-114}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error0.0
Cost448
\[x + \left(y - x\right) \cdot z \]
Alternative 9
Error34.3
Cost64
\[x \]

Error

Reproduce

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