?

Average Accuracy: 100.0% → 100.0%
Time: 13.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

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
Accuracy61.4%
Cost2036
\[\begin{array}{l} t_1 := y \cdot \left(t - x\right)\\ t_2 := \left(y - z\right) \cdot t\\ t_3 := z \cdot \left(x - t\right)\\ t_4 := x - y \cdot x\\ t_5 := x - z \cdot t\\ \mathbf{if}\;z \leq -1.45 \cdot 10^{+67}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -2.25 \cdot 10^{+17}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -1.4 \cdot 10^{-14}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -1.4 \cdot 10^{-99}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;z \leq -3.5 \cdot 10^{-125}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -6.2 \cdot 10^{-142}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;z \leq -1.02 \cdot 10^{-160}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -2.9 \cdot 10^{-210}:\\ \;\;\;\;t_5\\ \mathbf{elif}\;z \leq -3.7 \cdot 10^{-292}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 10^{-202}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;z \leq 6.2 \cdot 10^{-89}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.2 \cdot 10^{-58}:\\ \;\;\;\;t_5\\ \mathbf{elif}\;z \leq 1.25 \cdot 10^{+37}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 2
Accuracy37.3%
Cost1180
\[\begin{array}{l} t_1 := y \cdot \left(-x\right)\\ \mathbf{if}\;y \leq -3 \cdot 10^{+91}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -2.5 \cdot 10^{-15}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq -3 \cdot 10^{-224}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -1.65 \cdot 10^{-254}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;y \leq 3.1 \cdot 10^{-71}:\\ \;\;\;\;z \cdot \left(-t\right)\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{-8}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 2.6 \cdot 10^{+64}:\\ \;\;\;\;y \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Accuracy38.7%
Cost1048
\[\begin{array}{l} t_1 := y \cdot \left(-x\right)\\ \mathbf{if}\;y \leq -2.8 \cdot 10^{+90}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -6.5 \cdot 10^{-18}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq -3.4 \cdot 10^{-224}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -2.6 \cdot 10^{-276}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;y \leq 4.2 \cdot 10^{-8}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 4.2 \cdot 10^{+64}:\\ \;\;\;\;y \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Accuracy61.3%
Cost980
\[\begin{array}{l} t_1 := y \cdot \left(t - x\right)\\ t_2 := z \cdot \left(x - t\right)\\ \mathbf{if}\;y \leq -5.3 \cdot 10^{-39}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 9.2 \cdot 10^{-141}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 5.7 \cdot 10^{-80}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;y \leq 4.4 \cdot 10^{-70}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 3.1 \cdot 10^{-5}:\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Accuracy81.8%
Cost977
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ \mathbf{if}\;z \leq -7 \cdot 10^{+66}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.85 \cdot 10^{+19}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;z \leq -96 \lor \neg \left(z \leq 2.9 \cdot 10^{+35}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(t - x\right)\\ \end{array} \]
Alternative 6
Accuracy56.0%
Cost848
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ t_2 := \left(y - z\right) \cdot t\\ \mathbf{if}\;z \leq -4.8 \cdot 10^{+66}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.46 \cdot 10^{-291}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 3.1 \cdot 10^{-203}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.2 \cdot 10^{-41}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Accuracy71.0%
Cost848
\[\begin{array}{l} t_1 := y \cdot \left(t - x\right)\\ t_2 := x - z \cdot t\\ \mathbf{if}\;y \leq -4.7 \cdot 10^{-15}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -2.4 \cdot 10^{-234}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -3.1 \cdot 10^{-276}:\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{elif}\;y \leq 370000000:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Accuracy100.0%
Cost832
\[x + \left(y \cdot \left(t - x\right) + z \cdot \left(x - t\right)\right) \]
Alternative 9
Accuracy38.8%
Cost720
\[\begin{array}{l} \mathbf{if}\;y \leq -2.25 \cdot 10^{-14}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq -2.8 \cdot 10^{-224}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -1.35 \cdot 10^{-276}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{-8}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 10
Accuracy83.8%
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -5.8 \cdot 10^{-39} \lor \neg \left(y \leq 370000000\right):\\ \;\;\;\;x + y \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(x - t\right)\\ \end{array} \]
Alternative 11
Accuracy54.0%
Cost652
\[\begin{array}{l} \mathbf{if}\;x \leq -2.4 \cdot 10^{+90}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.6 \cdot 10^{-41}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;x \leq 3.8 \cdot 10^{+70}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Accuracy59.7%
Cost585
\[\begin{array}{l} \mathbf{if}\;t \leq -5 \cdot 10^{-135} \lor \neg \left(t \leq 2.15 \cdot 10^{-75}\right):\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \end{array} \]
Alternative 13
Accuracy100.0%
Cost576
\[x + \left(y - z\right) \cdot \left(t - x\right) \]
Alternative 14
Accuracy39.6%
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -2.15 \cdot 10^{-14}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 2.25 \cdot 10^{-7}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 15
Accuracy24.7%
Cost64
\[x \]

Error

Reproduce?

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