?

Average Error: 0.04% → 0.03%
Time: 12.6s
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.04%
Target0.05%
Herbie0.03%
\[x + \left(t \cdot \left(y - z\right) + \left(-x\right) \cdot \left(y - z\right)\right) \]

Derivation?

  1. Initial program 0.04

    \[x + \left(y - z\right) \cdot \left(t - x\right) \]
  2. Simplified0.03

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

    [Start]0.04

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

    +-commutative [=>]0.04

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

    fma-def [=>]0.03

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

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

Alternatives

Alternative 1
Error45.6%
Cost2140
\[\begin{array}{l} t_1 := \left(y - z\right) \cdot t\\ t_2 := z \cdot \left(x - t\right)\\ \mathbf{if}\;y - z \leq -1 \cdot 10^{+91}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq -10000000:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y - z \leq -5 \cdot 10^{-38}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq 4 \cdot 10^{-87}:\\ \;\;\;\;x\\ \mathbf{elif}\;y - z \leq 4 \cdot 10^{+52}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq 10^{+58}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{elif}\;y - z \leq 2 \cdot 10^{+190}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error46.47%
Cost1881
\[\begin{array}{l} t_1 := \left(y - z\right) \cdot t\\ \mathbf{if}\;y - z \leq -5 \cdot 10^{-38}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq 4 \cdot 10^{-87}:\\ \;\;\;\;x\\ \mathbf{elif}\;y - z \leq 4 \cdot 10^{+52}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq 10^{+58}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{elif}\;y - z \leq 2 \cdot 10^{+190} \lor \neg \left(y - z \leq 10^{+230}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 3
Error62.63%
Cost1577
\[\begin{array}{l} t_1 := z \cdot \left(-t\right)\\ \mathbf{if}\;z \leq -8.1 \cdot 10^{+90}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -2.8 \cdot 10^{-65}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.15 \cdot 10^{-82}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq -9 \cdot 10^{-121}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -2.3 \cdot 10^{-160}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{elif}\;z \leq -9.5 \cdot 10^{-210}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -2.95 \cdot 10^{-254}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{-43}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.72 \cdot 10^{+14} \lor \neg \left(z \leq 1.2 \cdot 10^{+78}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 4
Error35.91%
Cost1244
\[\begin{array}{l} t_1 := x \cdot \left(1 - y\right)\\ t_2 := z \cdot \left(x - t\right)\\ t_3 := y \cdot \left(t - x\right)\\ \mathbf{if}\;z \leq -290000000000:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -6.4 \cdot 10^{-71}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;z \leq -6.4 \cdot 10^{-125}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -3.5 \cdot 10^{-169}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -6.6 \cdot 10^{-209}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.12 \cdot 10^{-254}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-28}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error34.05%
Cost980
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ t_2 := x + y \cdot t\\ \mathbf{if}\;z \leq -12.4:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.45 \cdot 10^{-127}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -2.2 \cdot 10^{-169}:\\ \;\;\;\;y \cdot \left(t - x\right)\\ \mathbf{elif}\;z \leq -9.5 \cdot 10^{-239}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-28}:\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error25.53%
Cost978
\[\begin{array}{l} \mathbf{if}\;x \leq -7.2 \cdot 10^{-14} \lor \neg \left(x \leq -2.9 \cdot 10^{-32} \lor \neg \left(x \leq -2.9 \cdot 10^{-90}\right) \land x \leq 1.22 \cdot 10^{-73}\right):\\ \;\;\;\;x \cdot \left(\left(z + 1\right) - y\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \end{array} \]
Alternative 7
Error20%
Cost978
\[\begin{array}{l} \mathbf{if}\;t \leq -1.12 \cdot 10^{-69} \lor \neg \left(t \leq -1.48 \cdot 10^{-143} \lor \neg \left(t \leq -1.45 \cdot 10^{-208}\right) \land t \leq 1.2 \cdot 10^{-76}\right):\\ \;\;\;\;x + \left(y - z\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\left(z + 1\right) - y\right)\\ \end{array} \]
Alternative 8
Error19.87%
Cost977
\[\begin{array}{l} t_1 := x + \left(y - z\right) \cdot t\\ \mathbf{if}\;t \leq -3 \cdot 10^{-67}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -5 \cdot 10^{-145}:\\ \;\;\;\;x \cdot \left(\left(z + 1\right) - y\right)\\ \mathbf{elif}\;t \leq -1.45 \cdot 10^{-208} \lor \neg \left(t \leq 5.2 \cdot 10^{-84}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + x \cdot \left(z - y\right)\\ \end{array} \]
Alternative 9
Error58.99%
Cost917
\[\begin{array}{l} \mathbf{if}\;y \leq -3 \cdot 10^{-38}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 8.2 \cdot 10^{-29}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 4.2 \cdot 10^{+52} \lor \neg \left(y \leq 1.2 \cdot 10^{+80}\right) \land y \leq 9.5 \cdot 10^{+181}:\\ \;\;\;\;y \cdot t\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \end{array} \]
Alternative 10
Error40.34%
Cost849
\[\begin{array}{l} t_1 := x \cdot \left(z + 1\right)\\ \mathbf{if}\;x \leq -3.8 \cdot 10^{+128}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 7.2 \cdot 10^{-57}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{+94} \lor \neg \left(x \leq 2.4 \cdot 10^{+145}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \end{array} \]
Alternative 11
Error35.2%
Cost716
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ \mathbf{if}\;z \leq -52000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.1 \cdot 10^{-70}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;z \leq 1.9 \cdot 10^{-28}:\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 12
Error28.78%
Cost716
\[\begin{array}{l} t_1 := y \cdot \left(t - x\right)\\ \mathbf{if}\;y \leq -4 \cdot 10^{-27}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -3.8 \cdot 10^{-101}:\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \mathbf{elif}\;y \leq 6.4 \cdot 10^{-20}:\\ \;\;\;\;x - z \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 13
Error0.04%
Cost576
\[x + \left(y - z\right) \cdot \left(t - x\right) \]
Alternative 14
Error59.05%
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -4.8 \cdot 10^{-38}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 1.12 \cdot 10^{-27}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 15
Error73.82%
Cost64
\[x \]

Error

Reproduce?

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