Average Error: 0.0 → 0.0
Time: 16.3s
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)): 1 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
Error40.4
Cost1248
\[\begin{array}{l} t_1 := z \cdot \left(-t\right)\\ \mathbf{if}\;x \leq -4.1006611721142095 \cdot 10^{-83}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -3.4315903237798376 \cdot 10^{-224}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -5.4958845846448846 \cdot 10^{-285}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;x \leq 8.900092287523576 \cdot 10^{-300}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.988417099435108 \cdot 10^{-232}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;x \leq 1.0253906347513692 \cdot 10^{-187}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 7.920151886179179 \cdot 10^{-28}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{+81}:\\ \;\;\;\;z \cdot x\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Error27.5
Cost1244
\[\begin{array}{l} t_1 := \left(y - z\right) \cdot t\\ \mathbf{if}\;z \leq -5.77153786029173 \cdot 10^{+21}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.0889460563304394 \cdot 10^{-66}:\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \mathbf{elif}\;z \leq -3.4192777763563525 \cdot 10^{-114}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -4.916906512291579 \cdot 10^{-135}:\\ \;\;\;\;x - y \cdot x\\ \mathbf{elif}\;z \leq 4.509960072977815 \cdot 10^{+19}:\\ \;\;\;\;x + y \cdot t\\ \mathbf{elif}\;z \leq 2.2 \cdot 10^{+159}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq 8.2 \cdot 10^{+242}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 3
Error39.9
Cost1116
\[\begin{array}{l} \mathbf{if}\;y \leq -3.2 \cdot 10^{+82}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{elif}\;y \leq -7.146527790639123 \cdot 10^{-18}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq -5.47982240684575 \cdot 10^{-107}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -1.9017122512870445 \cdot 10^{-204}:\\ \;\;\;\;z \cdot \left(-t\right)\\ \mathbf{elif}\;y \leq 1.1131909193751116 \cdot 10^{-244}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 2.8254888053718344 \cdot 10^{-161}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;y \leq 2.5890732026356553 \cdot 10^{-10}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 4
Error31.1
Cost1112
\[\begin{array}{l} t_1 := z \cdot \left(-t\right)\\ t_2 := x + y \cdot t\\ \mathbf{if}\;x \leq -8.2 \cdot 10^{-84}:\\ \;\;\;\;x - y \cdot x\\ \mathbf{elif}\;x \leq -5.4958845846448846 \cdot 10^{-285}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 8.900092287523576 \cdot 10^{-300}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.988417099435108 \cdot 10^{-232}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.0253906347513692 \cdot 10^{-187}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 7.920151886179179 \cdot 10^{-28}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \end{array} \]
Alternative 5
Error20.8
Cost1112
\[\begin{array}{l} t_1 := y \cdot \left(t - x\right)\\ t_2 := x - z \cdot t\\ \mathbf{if}\;y \leq -7.146527790639123 \cdot 10^{-18}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.104467709170796 \cdot 10^{-256}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -5.48865896304011 \cdot 10^{-288}:\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \mathbf{elif}\;y \leq 1.1131909193751116 \cdot 10^{-244}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 2.8254888053718344 \cdot 10^{-161}:\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{elif}\;y \leq 3.4110040958713487 \cdot 10^{+24}:\\ \;\;\;\;x + y \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error18.8
Cost980
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ t_2 := x + y \cdot t\\ \mathbf{if}\;z \leq -515.266684896522:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -6.421633956521063 \cdot 10^{-66}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -3.4192777763563525 \cdot 10^{-114}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;z \leq -4.916906512291579 \cdot 10^{-135}:\\ \;\;\;\;x - y \cdot x\\ \mathbf{elif}\;z \leq 4.509960072977815 \cdot 10^{+19}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error11.6
Cost976
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ t_2 := x + y \cdot \left(t - x\right)\\ \mathbf{if}\;z \leq -515.266684896522:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.8464076454203436 \cdot 10^{-140}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 3.7306453993956905 \cdot 10^{-80}:\\ \;\;\;\;x - z \cdot t\\ \mathbf{elif}\;z \leq 4.509960072977815 \cdot 10^{+19}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error12.5
Cost976
\[\begin{array}{l} t_1 := x + z \cdot \left(x - t\right)\\ t_2 := x + y \cdot \left(t - x\right)\\ \mathbf{if}\;y \leq -7.146527790639123 \cdot 10^{-18}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 2.8254888053718344 \cdot 10^{-161}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.8827519273200803 \cdot 10^{-74}:\\ \;\;\;\;x + y \cdot t\\ \mathbf{elif}\;y \leq 1.1221862075006597 \cdot 10^{-39}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 9
Error27.7
Cost848
\[\begin{array}{l} t_1 := x + y \cdot t\\ \mathbf{if}\;z \leq -1.3392622670540824 \cdot 10^{+29}:\\ \;\;\;\;z \cdot \left(-t\right)\\ \mathbf{elif}\;z \leq -9.927660450342344 \cdot 10^{-107}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -4.916906512291579 \cdot 10^{-135}:\\ \;\;\;\;x - y \cdot x\\ \mathbf{elif}\;z \leq 4.509960072977815 \cdot 10^{+19}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 10
Error38.3
Cost588
\[\begin{array}{l} \mathbf{if}\;z \leq -515.266684896522:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq 3.7185797476227183 \cdot 10^{-81}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 4.509960072977815 \cdot 10^{+19}:\\ \;\;\;\;y \cdot t\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 11
Error27.7
Cost584
\[\begin{array}{l} \mathbf{if}\;z \leq -1.3392622670540824 \cdot 10^{+29}:\\ \;\;\;\;z \cdot \left(-t\right)\\ \mathbf{elif}\;z \leq 4.509960072977815 \cdot 10^{+19}:\\ \;\;\;\;x + y \cdot t\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 12
Error0.0
Cost576
\[x + \left(y - z\right) \cdot \left(t - x\right) \]
Alternative 13
Error38.0
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -515.266684896522:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq 7068537.597878154:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 14
Error47.3
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022316 
(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))))