?

Average Accuracy: 100.0% → 100.0%
Time: 14.2s
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

Original100.0%
Target100.0%
Herbie100.0%
\[x + \left(t \cdot \left(y - z\right) + \left(-x\right) \cdot \left(y - z\right)\right) \]

Derivation?

  1. Initial program 100.0%

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

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

    [Start]100.0

    \[ x + \left(y - z\right) \cdot \left(t - x\right) \]

    +-commutative [=>]100.0

    \[ \color{blue}{\left(y - z\right) \cdot \left(t - x\right) + x} \]

    fma-def [=>]100.0

    \[ \color{blue}{\mathsf{fma}\left(y - z, t - x, x\right)} \]
  3. Final simplification100.0%

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

Alternatives

Alternative 1
Accuracy50.3%
Cost2401
\[\begin{array}{l} t_1 := \left(y - z\right) \cdot t\\ t_2 := y \cdot \left(-x\right)\\ \mathbf{if}\;y - z \leq -1.5 \cdot 10^{+232}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;y - z \leq -2 \cdot 10^{+183}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y - z \leq -5 \cdot 10^{-64}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq 10^{-35}:\\ \;\;\;\;x\\ \mathbf{elif}\;y - z \leq 5 \cdot 10^{+53}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq 2 \cdot 10^{+76}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;y - z \leq 2 \cdot 10^{+178} \lor \neg \left(y - z \leq 10^{+239}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Accuracy62.0%
Cost1640
\[\begin{array}{l} t_1 := \left(y - z\right) \cdot t\\ t_2 := y \cdot \left(t - x\right)\\ t_3 := z \cdot \left(x - t\right)\\ t_4 := x \cdot \left(z + 1\right)\\ \mathbf{if}\;y \leq -1.55 \cdot 10^{-15}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -3.75 \cdot 10^{-50}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y \leq -1.2 \cdot 10^{-88}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.5 \cdot 10^{-125}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y \leq -1.9 \cdot 10^{-296}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 10^{-255}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y \leq 1.25 \cdot 10^{-214}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 1.85 \cdot 10^{-183}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{-136}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 6.6 \cdot 10^{-21}:\\ \;\;\;\;t_4\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Accuracy62.5%
Cost1640
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ t_2 := \left(y - z\right) \cdot t\\ t_3 := y \cdot \left(t - x\right)\\ t_4 := x \cdot \left(z + 1\right)\\ \mathbf{if}\;y \leq -1:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq -2.65 \cdot 10^{-50}:\\ \;\;\;\;x + y \cdot t\\ \mathbf{elif}\;y \leq -5.2 \cdot 10^{-88}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -2.9 \cdot 10^{-124}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y \leq -3 \cdot 10^{-296}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 4.3 \cdot 10^{-254}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y \leq 2 \cdot 10^{-217}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.8 \cdot 10^{-183}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{-136}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 6.6 \cdot 10^{-21}:\\ \;\;\;\;t_4\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 4
Accuracy37.1%
Cost1576
\[\begin{array}{l} t_1 := t \cdot \left(-z\right)\\ \mathbf{if}\;z \leq -1.38 \cdot 10^{+261}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.1 \cdot 10^{+118}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -3.2 \cdot 10^{+78}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -5.1 \cdot 10^{+67}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq -1:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -6.8 \cdot 10^{-134}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -1.25 \cdot 10^{-199}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 2.4 \cdot 10^{-65}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.9 \cdot 10^{+42}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{elif}\;z \leq 4.2 \cdot 10^{+231}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 5
Accuracy61.0%
Cost1113
\[\begin{array}{l} t_1 := x \cdot \left(z + 1\right)\\ \mathbf{if}\;x \leq -1.06 \cdot 10^{-35}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.2 \cdot 10^{-47}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{elif}\;x \leq -1.92 \cdot 10^{-81}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 8.8 \cdot 10^{-138}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;x \leq 7.5 \cdot 10^{-44} \lor \neg \left(x \leq 4.1 \cdot 10^{+43}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(x - t\right)\\ \end{array} \]
Alternative 6
Accuracy56.1%
Cost1112
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ \mathbf{if}\;x \leq -3.85 \cdot 10^{+52}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -9.5 \cdot 10^{-36}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -4.6 \cdot 10^{-43}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{elif}\;x \leq -2.9 \cdot 10^{-83}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.5 \cdot 10^{-82}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{+57}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Accuracy80.5%
Cost1112
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ t_2 := y \cdot \left(t - x\right)\\ \mathbf{if}\;z \leq -1.3 \cdot 10^{+96}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -5.1 \cdot 10^{+67}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -3800:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 6 \cdot 10^{-16}:\\ \;\;\;\;x + t_2\\ \mathbf{elif}\;z \leq 4.3 \cdot 10^{+43}:\\ \;\;\;\;x + x \cdot \left(z - y\right)\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{+108}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Accuracy80.6%
Cost1112
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ t_2 := y \cdot \left(t - x\right)\\ \mathbf{if}\;z \leq -1.65 \cdot 10^{+95}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -5.1 \cdot 10^{+67}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -1.65 \cdot 10^{-40}:\\ \;\;\;\;x + t_1\\ \mathbf{elif}\;z \leq 1.65 \cdot 10^{-16}:\\ \;\;\;\;x + t_2\\ \mathbf{elif}\;z \leq 4.5 \cdot 10^{+42}:\\ \;\;\;\;x + x \cdot \left(z - y\right)\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{+108}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Accuracy80.5%
Cost1112
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ t_2 := y \cdot \left(t - x\right)\\ \mathbf{if}\;z \leq -1.65 \cdot 10^{+95}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -2.9 \cdot 10^{+67}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -5 \cdot 10^{-40}:\\ \;\;\;\;x + t_1\\ \mathbf{elif}\;z \leq 6 \cdot 10^{-16}:\\ \;\;\;\;x + t_2\\ \mathbf{elif}\;z \leq 1.82 \cdot 10^{+43}:\\ \;\;\;\;x \cdot \left(\left(z + 1\right) - y\right)\\ \mathbf{elif}\;z \leq 8 \cdot 10^{+108}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Accuracy70.9%
Cost980
\[\begin{array}{l} t_1 := y \cdot \left(t - x\right)\\ \mathbf{if}\;y \leq -1:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.9 \cdot 10^{-51}:\\ \;\;\;\;x + y \cdot t\\ \mathbf{elif}\;y \leq -3.8 \cdot 10^{-83}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;y \leq 4.2 \cdot 10^{-134}:\\ \;\;\;\;x - z \cdot t\\ \mathbf{elif}\;y \leq 6.6 \cdot 10^{-21}:\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Accuracy81.5%
Cost977
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ t_2 := y \cdot \left(t - x\right)\\ \mathbf{if}\;z \leq -1.8 \cdot 10^{+95}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -5.1 \cdot 10^{+67}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -2.35 \cdot 10^{-5} \lor \neg \left(z \leq 0.0008\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + t_2\\ \end{array} \]
Alternative 12
Accuracy100.0%
Cost832
\[\left(y - z\right) \cdot t - x \cdot \left(y + \left(-1 - z\right)\right) \]
Alternative 13
Accuracy38.3%
Cost720
\[\begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -1.6 \cdot 10^{-135}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -1.15 \cdot 10^{-199}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 14
Accuracy39.8%
Cost652
\[\begin{array}{l} t_1 := y \cdot \left(-x\right)\\ \mathbf{if}\;y \leq -1:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3.7 \cdot 10^{-28}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 8 \cdot 10^{+178}:\\ \;\;\;\;y \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 15
Accuracy100.0%
Cost576
\[x + \left(y - z\right) \cdot \left(t - x\right) \]
Alternative 16
Accuracy40.2%
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -4.5 \cdot 10^{-41}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 5.2 \cdot 10^{-29}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 17
Accuracy25.1%
Cost64
\[x \]

Error

Reproduce?

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