?

Average Accuracy: 100.0% → 100.0%
Time: 11.5s
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
Accuracy56.3%
Cost1376
\[\begin{array}{l} t_1 := \left(y - z\right) \cdot t\\ t_2 := x \cdot \left(1 - y\right)\\ t_3 := x \cdot \left(z + 1\right)\\ \mathbf{if}\;t \leq -9 \cdot 10^{-38}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -2.1 \cdot 10^{-102}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq -6 \cdot 10^{-144}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -4.8 \cdot 10^{-304}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 1.3 \cdot 10^{-167}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 4.8 \cdot 10^{-122}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 4.4 \cdot 10^{-94}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 5 \cdot 10^{+44}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Accuracy38.4%
Cost1312
\[\begin{array}{l} t_1 := z \cdot \left(-t\right)\\ t_2 := y \cdot \left(-x\right)\\ \mathbf{if}\;y \leq -1:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -1 \cdot 10^{-261}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -3.8 \cdot 10^{-300}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 4.1 \cdot 10^{-179}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.3 \cdot 10^{-114}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.05 \cdot 10^{-18}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.25 \cdot 10^{+28}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 9.5 \cdot 10^{+261}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 3
Accuracy73.0%
Cost1108
\[\begin{array}{l} t_1 := x \cdot \left(\left(z + 1\right) - y\right)\\ \mathbf{if}\;x \leq -3.7 \cdot 10^{-138}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.3 \cdot 10^{-127}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;x \leq 2.8 \cdot 10^{-48}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.6 \cdot 10^{-35}:\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{-8}:\\ \;\;\;\;y \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Accuracy38.6%
Cost984
\[\begin{array}{l} t_1 := z \cdot \left(-t\right)\\ \mathbf{if}\;y \leq -1.05 \cdot 10^{-25}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq -1.6 \cdot 10^{-259}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -3.3 \cdot 10^{-298}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3.2 \cdot 10^{-179}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 2.7 \cdot 10^{-114}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 4.3 \cdot 10^{-13}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 5
Accuracy62.3%
Cost849
\[\begin{array}{l} t_1 := x \cdot \left(z + 1\right)\\ \mathbf{if}\;x \leq -6.5 \cdot 10^{-57}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{-7}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;x \leq 7.2 \cdot 10^{+67} \lor \neg \left(x \leq 3.4 \cdot 10^{+98}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \end{array} \]
Alternative 6
Accuracy64.5%
Cost848
\[\begin{array}{l} t_1 := y \cdot \left(t - x\right)\\ t_2 := x \cdot \left(z + 1\right)\\ \mathbf{if}\;y \leq -9.2 \cdot 10^{-26}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 7.2 \cdot 10^{-180}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 1.18 \cdot 10^{-135}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;y \leq 7.8 \cdot 10^{-13}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Accuracy52.4%
Cost784
\[\begin{array}{l} \mathbf{if}\;x \leq -7.8 \cdot 10^{-53}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.6 \cdot 10^{-7}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;x \leq 2.8 \cdot 10^{+67}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{+160}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Accuracy81.3%
Cost713
\[\begin{array}{l} \mathbf{if}\;t \leq -1.52 \cdot 10^{-123} \lor \neg \left(t \leq 5.8 \cdot 10^{-7}\right):\\ \;\;\;\;x + \left(y - z\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\left(z + 1\right) - y\right)\\ \end{array} \]
Alternative 9
Accuracy38.5%
Cost588
\[\begin{array}{l} \mathbf{if}\;z \leq -1.12 \cdot 10^{+14}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -9.8 \cdot 10^{-169}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 82000:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 10
Accuracy70.7%
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -8.4 \cdot 10^{-26} \lor \neg \left(y \leq 8 \cdot 10^{-13}\right):\\ \;\;\;\;y \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;x - z \cdot t\\ \end{array} \]
Alternative 11
Accuracy100.0%
Cost576
\[x + \left(y - z\right) \cdot \left(t - x\right) \]
Alternative 12
Accuracy39.9%
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -6.2 \cdot 10^{-26}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 4.3 \cdot 10^{-14}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 13
Accuracy25.3%
Cost64
\[x \]

Error

Reproduce?

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