?

Average Error: 0.04% → 0.03%
Time: 12.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

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
Error39.47%
Cost2037
\[\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 -3.6 \cdot 10^{-51}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq -1.1 \cdot 10^{-89}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y \leq -1.25 \cdot 10^{-117}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -3.6 \cdot 10^{-144}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y \leq -8.5 \cdot 10^{-158}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -2.3 \cdot 10^{-268}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 7 \cdot 10^{-227}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y \leq 1.6 \cdot 10^{-143}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.05 \cdot 10^{-74}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y \leq 2.4 \cdot 10^{-23}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 2.6 \cdot 10^{-15}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y \leq 9.6 \cdot 10^{+36} \lor \neg \left(y \leq 2.65 \cdot 10^{+160}\right):\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error46.71%
Cost1508
\[\begin{array}{l} t_1 := \left(y - z\right) \cdot t\\ t_2 := z \cdot \left(x - t\right)\\ \mathbf{if}\;z \leq -3.35 \cdot 10^{-37}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -1.02 \cdot 10^{-103}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -3.2 \cdot 10^{-217}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -3.1 \cdot 10^{-287}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 4.2 \cdot 10^{-158}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5 \cdot 10^{-94}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{elif}\;z \leq 1.5 \cdot 10^{-65}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 6 \cdot 10^{-28}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 6800:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error65.4%
Cost1444
\[\begin{array}{l} t_1 := t \cdot \left(-z\right)\\ \mathbf{if}\;y \leq -3 \cdot 10^{+136}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{elif}\;y \leq -4.5 \cdot 10^{-51}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq -1.2 \cdot 10^{-109}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -5.2 \cdot 10^{-267}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 4.4 \cdot 10^{-228}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.55 \cdot 10^{-143}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 5.1 \cdot 10^{-102}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.8 \cdot 10^{+54}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{+138}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 4
Error62.62%
Cost984
\[\begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -4.1 \cdot 10^{-104}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -8.8 \cdot 10^{-215}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq -9 \cdot 10^{-288}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.1 \cdot 10^{-154}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 5
Error0.05%
Cost832
\[\left(y - z\right) \cdot t + x \cdot \left(\left(z + 1\right) - y\right) \]
Alternative 6
Error45.43%
Cost716
\[\begin{array}{l} \mathbf{if}\;x \leq -9.5 \cdot 10^{+43}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -3.65 \cdot 10^{-44}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq 1.05 \cdot 10^{+111}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Error18.16%
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -3 \cdot 10^{-36} \lor \neg \left(z \leq 1.5 \cdot 10^{-17}\right):\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(t - x\right)\\ \end{array} \]
Alternative 8
Error16.51%
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -2.5 \cdot 10^{-57} \lor \neg \left(z \leq 2.7 \cdot 10^{-18}\right):\\ \;\;\;\;x + z \cdot \left(x - t\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(t - x\right)\\ \end{array} \]
Alternative 9
Error36.15%
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -4.9 \cdot 10^{-46} \lor \neg \left(x \leq 2.9 \cdot 10^{-7}\right):\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \end{array} \]
Alternative 10
Error28.62%
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -2.25 \cdot 10^{-36} \lor \neg \left(z \leq 4.2 \cdot 10^{-23}\right):\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot t\\ \end{array} \]
Alternative 11
Error0.04%
Cost576
\[x + \left(y - z\right) \cdot \left(t - x\right) \]
Alternative 12
Error60.83%
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -4.5 \cdot 10^{-51}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 3.6 \cdot 10^{-100}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 13
Error74.52%
Cost64
\[x \]

Error

Reproduce?

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