?

Average Accuracy: 100.0% → 100.0%
Time: 12.1s
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
Accuracy57.4%
Cost1640
\[\begin{array}{l} t_1 := y \cdot \left(t - x\right)\\ t_2 := z \cdot \left(x - t\right)\\ \mathbf{if}\;z \leq -700:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -4.7 \cdot 10^{-226}:\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \mathbf{elif}\;z \leq -8.6 \cdot 10^{-298}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.6 \cdot 10^{-303}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 7.5 \cdot 10^{-285}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.75 \cdot 10^{-251}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 6.8 \cdot 10^{-165}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.9 \cdot 10^{-137}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.16 \cdot 10^{-97}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.18 \cdot 10^{-51}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Accuracy65.8%
Cost1376
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ t_2 := y \cdot \left(t - x\right)\\ \mathbf{if}\;y \leq -2.6 \cdot 10^{+15}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -3.6 \cdot 10^{-241}:\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \mathbf{elif}\;y \leq -5.2 \cdot 10^{-274}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.8 \cdot 10^{-159}:\\ \;\;\;\;x - z \cdot t\\ \mathbf{elif}\;y \leq 1.4 \cdot 10^{-121}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.35 \cdot 10^{-50}:\\ \;\;\;\;x + y \cdot t\\ \mathbf{elif}\;y \leq 1.7 \cdot 10^{-15}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.4 \cdot 10^{-7}:\\ \;\;\;\;x - y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Accuracy55.6%
Cost1244
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ t_2 := \left(y - z\right) \cdot t\\ \mathbf{if}\;z \leq -2.1 \cdot 10^{-18}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.8 \cdot 10^{-302}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{-287}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{elif}\;z \leq 5.6 \cdot 10^{-251}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3.7 \cdot 10^{-96}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 9.8 \cdot 10^{-27}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 220000000000:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Accuracy38.9%
Cost1180
\[\begin{array}{l} t_1 := z \cdot \left(-t\right)\\ \mathbf{if}\;z \leq -1.25 \cdot 10^{+55}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -3.2 \cdot 10^{-17}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.65 \cdot 10^{-302}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{-287}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{elif}\;z \leq 5.6 \cdot 10^{-251}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 6.8 \cdot 10^{-165}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 2.22 \cdot 10^{-23}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Accuracy38.8%
Cost984
\[\begin{array}{l} \mathbf{if}\;z \leq -1.02:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq 2.5 \cdot 10^{-303}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{-287}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{elif}\;z \leq 5.6 \cdot 10^{-251}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{-165}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 6.2 \cdot 10^{-9}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 6
Accuracy82.7%
Cost978
\[\begin{array}{l} \mathbf{if}\;t \leq -7 \cdot 10^{-37} \lor \neg \left(t \leq -1.9 \cdot 10^{-62}\right) \land \left(t \leq -3.3 \cdot 10^{-107} \lor \neg \left(t \leq 1.15 \cdot 10^{-115}\right)\right):\\ \;\;\;\;x + \left(y - z\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\left(z + 1\right) - y\right)\\ \end{array} \]
Alternative 7
Accuracy82.7%
Cost977
\[\begin{array}{l} t_1 := x + \left(y - z\right) \cdot t\\ \mathbf{if}\;t \leq -1.05 \cdot 10^{-37}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -2.1 \cdot 10^{-63}:\\ \;\;\;\;x \cdot \left(\left(z + 1\right) - y\right)\\ \mathbf{elif}\;t \leq -1.28 \cdot 10^{-107} \lor \neg \left(t \leq 8.5 \cdot 10^{-116}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + x \cdot \left(z - y\right)\\ \end{array} \]
Alternative 8
Accuracy100.0%
Cost832
\[x + \left(y \cdot \left(t - x\right) + z \cdot \left(x - t\right)\right) \]
Alternative 9
Accuracy39.2%
Cost720
\[\begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq 5.6 \cdot 10^{-251}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 6.8 \cdot 10^{-165}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 6.2 \cdot 10^{-9}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 10
Accuracy52.3%
Cost716
\[\begin{array}{l} \mathbf{if}\;x \leq -1.7 \cdot 10^{+37}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.02 \cdot 10^{-117}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq 3.15 \cdot 10^{+53}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Accuracy73.9%
Cost713
\[\begin{array}{l} \mathbf{if}\;x \leq -1.02 \cdot 10^{-117} \lor \neg \left(x \leq 2.55 \cdot 10^{-57}\right):\\ \;\;\;\;x \cdot \left(\left(z + 1\right) - y\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \end{array} \]
Alternative 12
Accuracy62.2%
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -1.02 \cdot 10^{-117} \lor \neg \left(x \leq 1.1 \cdot 10^{+26}\right):\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \end{array} \]
Alternative 13
Accuracy71.9%
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -7 \cdot 10^{-17} \lor \neg \left(z \leq 1.05 \cdot 10^{-48}\right):\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot t\\ \end{array} \]
Alternative 14
Accuracy100.0%
Cost576
\[x + \left(y - z\right) \cdot \left(t - x\right) \]
Alternative 15
Accuracy40.3%
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -3.4 \cdot 10^{-6}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 2.32 \cdot 10^{-7}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 16
Accuracy25.7%
Cost64
\[x \]

Error

Reproduce?

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