Average Error: 0.0 → 0.0
Time: 14.6s
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
Error43.6
Cost1380
\[\begin{array}{l} t_1 := z \cdot \left(-t\right)\\ \mathbf{if}\;x \leq -1.1 \cdot 10^{+235}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -0.0009901510651523333:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq -4.286992479244717 \cdot 10^{-160}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2.4554568623084444 \cdot 10^{-276}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.4689048408501454 \cdot 10^{-278}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;x \leq 8.858735921475341 \cdot 10^{-163}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.2131538962205376 \cdot 10^{-111}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{elif}\;x \leq 3.4493731872339124 \cdot 10^{-79}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;x \leq 7.8 \cdot 10^{+150}:\\ \;\;\;\;z \cdot x\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Error31.3
Cost1112
\[\begin{array}{l} t_1 := x + y \cdot t\\ t_2 := x + z \cdot x\\ t_3 := x - z \cdot t\\ \mathbf{if}\;x \leq -1495084276.792317:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -2.4554568623084444 \cdot 10^{-276}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 1.4689048408501454 \cdot 10^{-278}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 8.858735921475341 \cdot 10^{-163}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 5.2131538962205376 \cdot 10^{-111}:\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{elif}\;x \leq 7.755605636458072 \cdot 10^{-80}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error18.6
Cost980
\[\begin{array}{l} t_1 := x + y \cdot t\\ t_2 := z \cdot \left(x - t\right)\\ \mathbf{if}\;z \leq -53222354099.430115:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -9.416785135975233 \cdot 10^{-55}:\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{elif}\;z \leq 2.088185824497062 \cdot 10^{-210}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.2315246717681922 \cdot 10^{-178}:\\ \;\;\;\;y \cdot \left(t - x\right)\\ \mathbf{elif}\;z \leq 1.0678235372494206 \cdot 10^{-10}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error16.6
Cost976
\[\begin{array}{l} t_1 := \left(y - z\right) \cdot t\\ t_2 := x + x \cdot \left(z - y\right)\\ \mathbf{if}\;x \leq -5.124475940079755 \cdot 10^{-101}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 8.858735921475341 \cdot 10^{-163}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.2131538962205376 \cdot 10^{-111}:\\ \;\;\;\;y \cdot t - y \cdot x\\ \mathbf{elif}\;x \leq 7.755605636458072 \cdot 10^{-80}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error12.1
Cost976
\[\begin{array}{l} t_1 := x + x \cdot \left(z - y\right)\\ t_2 := x + \left(y - z\right) \cdot t\\ \mathbf{if}\;t \leq -9.942592609077108 \cdot 10^{-112}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 6.726316345202767 \cdot 10^{-169}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 3.4453218822847204 \cdot 10^{-134}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 6.373458067290452 \cdot 10^{-55}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error40.1
Cost852
\[\begin{array}{l} \mathbf{if}\;z \leq -53222354099.430115:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -9.416785135975233 \cdot 10^{-55}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{elif}\;z \leq -2.4059506337587555 \cdot 10^{-91}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 6.748833915209574 \cdot 10^{-211}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 129192417392308.48:\\ \;\;\;\;y \cdot t\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 7
Error24.8
Cost848
\[\begin{array}{l} t_1 := x + z \cdot x\\ t_2 := \left(y - z\right) \cdot t\\ \mathbf{if}\;x \leq -5.124475940079755 \cdot 10^{-101}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 8.858735921475341 \cdot 10^{-163}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 5.2131538962205376 \cdot 10^{-111}:\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{elif}\;x \leq 7.755605636458072 \cdot 10^{-80}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error27.6
Cost716
\[\begin{array}{l} t_1 := x \cdot \left(-y\right)\\ \mathbf{if}\;y \leq -4 \cdot 10^{+137}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -7.1032050180368726 \cdot 10^{-31}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 4333817008317618000:\\ \;\;\;\;x - z \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error27.0
Cost716
\[\begin{array}{l} t_1 := x \cdot \left(-y\right)\\ \mathbf{if}\;y \leq -4 \cdot 10^{+137}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -7.1032050180368726 \cdot 10^{-31}:\\ \;\;\;\;x + y \cdot t\\ \mathbf{elif}\;y \leq 4333817008317618000:\\ \;\;\;\;x - z \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error18.2
Cost716
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ \mathbf{if}\;z \leq -53222354099.430115:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -9.416785135975233 \cdot 10^{-55}:\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{elif}\;z \leq 1.0678235372494206 \cdot 10^{-10}:\\ \;\;\;\;x + y \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error39.9
Cost588
\[\begin{array}{l} \mathbf{if}\;z \leq -2.9125408876758023 \cdot 10^{-12}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq 6.748833915209574 \cdot 10^{-211}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 129192417392308.48:\\ \;\;\;\;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.9
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -2.9125408876758023 \cdot 10^{-12}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq 0.0015233282312769407:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 14
Error47.7
Cost64
\[x \]

Error

Reproduce

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