Average Error: 0.0 → 0.0
Time: 8.8s
Precision: binary64
Cost: 6848
\[x + \left(y - z\right) \cdot \left(t - x\right) \]
\[\mathsf{fma}\left(y - z, t - x, x\right) \]
(FPCore (x y z t) :precision binary64 (+ x (* (- y z) (- t x))))
(FPCore (x y z t) :precision binary64 (fma (- y z) (- t x) x))
double code(double x, double y, double z, double t) {
	return x + ((y - z) * (t - x));
}
double code(double x, double y, double z, double t) {
	return fma((y - z), (t - x), x);
}
function code(x, y, z, t)
	return Float64(x + Float64(Float64(y - z) * Float64(t - x)))
end
function code(x, y, z, t)
	return fma(Float64(y - z), Float64(t - x), x)
end
code[x_, y_, z_, t_] := N[(x + N[(N[(y - z), $MachinePrecision] * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := N[(N[(y - z), $MachinePrecision] * N[(t - x), $MachinePrecision] + x), $MachinePrecision]
x + \left(y - z\right) \cdot \left(t - x\right)
\mathsf{fma}\left(y - z, t - x, x\right)

Error

Target

Original0.0
Target0.0
Herbie0.0
\[x + \left(t \cdot \left(y - z\right) + \left(-x\right) \cdot \left(y - z\right)\right) \]

Derivation

  1. Initial program 0.0

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(y - z, t - x, x\right)} \]
    Proof
    (fma.f64 (-.f64 y z) (-.f64 t x) x): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (-.f64 y z) (-.f64 t x)) x)): 2 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 x (*.f64 (-.f64 y z) (-.f64 t x)))): 0 points increase in error, 0 points decrease in error
  3. Final simplification0.0

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

Alternatives

Alternative 1
Error28.6
Cost2400
\[\begin{array}{l} t_1 := \left(y - z\right) \cdot t\\ t_2 := z \cdot \left(x - t\right)\\ t_3 := x \cdot \left(z + 1\right)\\ t_4 := y \cdot \left(t - x\right)\\ \mathbf{if}\;y - z \leq -4 \cdot 10^{-6}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y - z \leq 5 \cdot 10^{-154}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y - z \leq 5 \cdot 10^{-116}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq 2 \cdot 10^{-11}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y - z \leq 4 \cdot 10^{+16}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq 5 \cdot 10^{+137}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y - z \leq 2 \cdot 10^{+155}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y - z \leq 5 \cdot 10^{+157}:\\ \;\;\;\;t_4\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error30.0
Cost1880
\[\begin{array}{l} t_1 := \left(y - z\right) \cdot t\\ \mathbf{if}\;y - z \leq -5 \cdot 10^{+229}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq -5 \cdot 10^{+159}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;y - z \leq -5 \cdot 10^{-50}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq 5 \cdot 10^{-154}:\\ \;\;\;\;x\\ \mathbf{elif}\;y - z \leq 5 \cdot 10^{-116}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq 2 \cdot 10^{-11}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error28.9
Cost1880
\[\begin{array}{l} t_1 := \left(y - z\right) \cdot t\\ t_2 := z \cdot \left(x - t\right)\\ \mathbf{if}\;y - z \leq -4 \cdot 10^{-6}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y - z \leq 5 \cdot 10^{-154}:\\ \;\;\;\;x\\ \mathbf{elif}\;y - z \leq 5 \cdot 10^{-116}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq 2 \cdot 10^{-11}:\\ \;\;\;\;x\\ \mathbf{elif}\;y - z \leq 5 \cdot 10^{+137}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq 2 \cdot 10^{+155}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error28.8
Cost1880
\[\begin{array}{l} t_1 := x \cdot \left(z + 1\right)\\ t_2 := \left(y - z\right) \cdot t\\ t_3 := z \cdot \left(x - t\right)\\ \mathbf{if}\;y - z \leq -4 \cdot 10^{-6}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y - z \leq 5 \cdot 10^{-154}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq 5 \cdot 10^{-116}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y - z \leq 2 \cdot 10^{-11}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq 5 \cdot 10^{+137}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y - z \leq 2 \cdot 10^{+155}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error38.4
Cost1048
\[\begin{array}{l} t_1 := z \cdot \left(-t\right)\\ \mathbf{if}\;z \leq -2.9 \cdot 10^{+162}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -3.25 \cdot 10^{+134}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -3.1 \cdot 10^{-13}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.16 \cdot 10^{-39}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.7 \cdot 10^{+94}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.6 \cdot 10^{+222}:\\ \;\;\;\;z \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error11.4
Cost976
\[\begin{array}{l} t_1 := x \cdot \left(\left(z + 1\right) - y\right)\\ t_2 := x + \left(y - z\right) \cdot t\\ \mathbf{if}\;t \leq -1.62 \cdot 10^{-69}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -1.62 \cdot 10^{-149}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -5.5 \cdot 10^{-190}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 1.55 \cdot 10^{-113}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Error17.8
Cost848
\[\begin{array}{l} t_1 := y \cdot \left(t - x\right)\\ \mathbf{if}\;y \leq -1.8 \cdot 10^{+24}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -2.3 \cdot 10^{-26}:\\ \;\;\;\;x \cdot \left(\left(z + 1\right) - y\right)\\ \mathbf{elif}\;y \leq -4.4 \cdot 10^{-60}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;y \leq 2.6 \cdot 10^{-9}:\\ \;\;\;\;x - z \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error10.6
Cost844
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ \mathbf{if}\;z \leq -3.7 \cdot 10^{-10}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4.3 \cdot 10^{-119}:\\ \;\;\;\;x + y \cdot \left(t - x\right)\\ \mathbf{elif}\;z \leq 175:\\ \;\;\;\;x + \left(y - z\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error17.4
Cost584
\[\begin{array}{l} t_1 := y \cdot \left(t - x\right)\\ \mathbf{if}\;y \leq -0.02:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 6 \cdot 10^{-10}:\\ \;\;\;\;x - z \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error0.0
Cost576
\[x + \left(y - z\right) \cdot \left(t - x\right) \]
Alternative 11
Error38.1
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -2.2 \cdot 10^{-58}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 2.7 \cdot 10^{-9}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 12
Error37.8
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -1.4:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{elif}\;y \leq 1.05 \cdot 10^{-10}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 13
Error47.4
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022325 
(FPCore (x y z t)
  :name "Data.Metrics.Snapshot:quantile from metrics-0.3.0.2"
  :precision binary64

  :herbie-target
  (+ x (+ (* t (- y z)) (* (- x) (- y z))))

  (+ x (* (- y z) (- t x))))