Average Error: 0.0 → 0.0
Time: 15.0s
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)): 4 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
Error44.2
Cost1972
\[\begin{array}{l} t_1 := z \cdot \left(-t\right)\\ \mathbf{if}\;t \leq -4.5 \cdot 10^{+185}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -1.95 \cdot 10^{+133}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;t \leq -4.8 \cdot 10^{+112}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -1.3461059874680404 \cdot 10^{-106}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;t \leq -2.8862578398302492 \cdot 10^{-226}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq -1.877422702986778 \cdot 10^{-290}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;t \leq 5.658583115329548 \cdot 10^{-239}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 3.4632354057093766 \cdot 10^{-201}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;t \leq 3.1352372731252047 \cdot 10^{-183}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{elif}\;t \leq 2.588457319069423 \cdot 10^{-30}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 7.673475440716495 \cdot 10^{-17}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 9.2 \cdot 10^{+73}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 1.75 \cdot 10^{+92}:\\ \;\;\;\;y \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error31.8
Cost1772
\[\begin{array}{l} t_1 := x - y \cdot x\\ t_2 := z \cdot \left(x - t\right)\\ \mathbf{if}\;x \leq -795940605.2244498:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -7.979544813239573 \cdot 10^{-93}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -6.975737598952257 \cdot 10^{-105}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.5724406173910193 \cdot 10^{-123}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;x \leq -3.8905299312917535 \cdot 10^{-257}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.496874091134973 \cdot 10^{-186}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;x \leq 7.017616640663974 \cdot 10^{-162}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.4711992847051553 \cdot 10^{-149}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;x \leq 6.410565182531738 \cdot 10^{-39}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 180585109.39707744:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3 \cdot 10^{+60}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \end{array} \]
Alternative 3
Error34.5
Cost1244
\[\begin{array}{l} t_1 := z \cdot \left(-t\right)\\ t_2 := x \cdot \left(z + 1\right)\\ \mathbf{if}\;x \leq -6.975737598952257 \cdot 10^{-105}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.5724406173910193 \cdot 10^{-123}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;x \leq -8.228570037727412 \cdot 10^{-147}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.2112592646936474 \cdot 10^{-103}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;x \leq 7.71896095012274 \cdot 10^{-43}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.476469735341161 \cdot 10^{-29}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;x \leq 1.5645148514637976 \cdot 10^{-12}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error33.8
Cost1244
\[\begin{array}{l} t_1 := z \cdot \left(-t\right)\\ t_2 := x - y \cdot x\\ \mathbf{if}\;x \leq -6.975737598952257 \cdot 10^{-105}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.5724406173910193 \cdot 10^{-123}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;x \leq -8.228570037727412 \cdot 10^{-147}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.2112592646936474 \cdot 10^{-103}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;x \leq 7.71896095012274 \cdot 10^{-43}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.410565182531738 \cdot 10^{-39}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;x \leq 180585109.39707744:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \end{array} \]
Alternative 5
Error23.9
Cost1112
\[\begin{array}{l} t_1 := x - y \cdot x\\ t_2 := z \cdot \left(x - t\right)\\ \mathbf{if}\;x \leq -795940605.2244498:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -9.556183105961548 \cdot 10^{-65}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.18069401837414 \cdot 10^{-72}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.410565182531738 \cdot 10^{-39}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;x \leq 180585109.39707744:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3 \cdot 10^{+60}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \end{array} \]
Alternative 6
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 -1.469298293251149 \cdot 10^{-76}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 6.90537401492698 \cdot 10^{-146}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.3337593874696084 \cdot 10^{-98}:\\ \;\;\;\;x - y \cdot \left(x - t\right)\\ \mathbf{elif}\;x \leq 6.410565182531738 \cdot 10^{-39}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Error16.6
Cost976
\[\begin{array}{l} t_1 := x + x \cdot \left(z - y\right)\\ \mathbf{if}\;x \leq -1.469298293251149 \cdot 10^{-76}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.90537401492698 \cdot 10^{-146}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;x \leq 3.3337593874696084 \cdot 10^{-98}:\\ \;\;\;\;x - y \cdot \left(x - t\right)\\ \mathbf{elif}\;x \leq 6.410565182531738 \cdot 10^{-39}:\\ \;\;\;\;y \cdot t - z \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error16.6
Cost976
\[\begin{array}{l} \mathbf{if}\;x \leq -1.469298293251149 \cdot 10^{-76}:\\ \;\;\;\;x + \left(z \cdot x - y \cdot x\right)\\ \mathbf{elif}\;x \leq 6.90537401492698 \cdot 10^{-146}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;x \leq 3.3337593874696084 \cdot 10^{-98}:\\ \;\;\;\;x - y \cdot \left(x - t\right)\\ \mathbf{elif}\;x \leq 6.410565182531738 \cdot 10^{-39}:\\ \;\;\;\;y \cdot t - z \cdot t\\ \mathbf{else}:\\ \;\;\;\;x + x \cdot \left(z - y\right)\\ \end{array} \]
Alternative 9
Error16.6
Cost976
\[\begin{array}{l} \mathbf{if}\;x \leq -1.469298293251149 \cdot 10^{-76}:\\ \;\;\;\;x + \left(z \cdot x - y \cdot x\right)\\ \mathbf{elif}\;x \leq 6.90537401492698 \cdot 10^{-146}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;x \leq 3.3337593874696084 \cdot 10^{-98}:\\ \;\;\;\;x - y \cdot \left(x - t\right)\\ \mathbf{elif}\;x \leq 6.410565182531738 \cdot 10^{-39}:\\ \;\;\;\;y \cdot t - z \cdot t\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 + \left(z - y\right)\right)\\ \end{array} \]
Alternative 10
Error0.0
Cost832
\[x + \left(y \cdot \left(t - x\right) + z \cdot \left(x - t\right)\right) \]
Alternative 11
Error16.5
Cost712
\[\begin{array}{l} t_1 := x + x \cdot \left(z - y\right)\\ \mathbf{if}\;x \leq -1.469298293251149 \cdot 10^{-76}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.410565182531738 \cdot 10^{-39}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 12
Error0.0
Cost576
\[x + \left(z - y\right) \cdot \left(x - t\right) \]
Alternative 13
Error38.7
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -417394.5752294178:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq 4.0138551071896856 \cdot 10^{-15}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 14
Error38.3
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -1.6485790481384756 \cdot 10^{-22}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 4.582696798767103 \cdot 10^{-36}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 15
Error47.6
Cost64
\[x \]

Error

Reproduce

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