?

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

Derivation?

  1. Initial program 0.05

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

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

    [Start]0.05

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

    +-commutative [=>]0.05

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

    fma-def [=>]0.04

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

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

Alternatives

Alternative 1
Error48.27%
Cost2401
\[\begin{array}{l} t_1 := \left(y - z\right) \cdot t\\ \mathbf{if}\;y - z \leq -5 \cdot 10^{-37}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq -1 \cdot 10^{-65}:\\ \;\;\;\;x\\ \mathbf{elif}\;y - z \leq -1 \cdot 10^{-87}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq 5 \cdot 10^{-130}:\\ \;\;\;\;x\\ \mathbf{elif}\;y - z \leq 2 \cdot 10^{-98}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq 5 \cdot 10^{-22}:\\ \;\;\;\;x\\ \mathbf{elif}\;y - z \leq 5 \cdot 10^{+57} \lor \neg \left(y - z \leq 4 \cdot 10^{+139}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \end{array} \]
Alternative 2
Error36.88%
Cost1508
\[\begin{array}{l} t_1 := x \cdot \left(1 - y\right)\\ t_2 := z \cdot \left(x - t\right)\\ t_3 := \left(y - z\right) \cdot t\\ \mathbf{if}\;z \leq -1.5 \cdot 10^{+35}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -1.42 \cdot 10^{-101}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -5 \cdot 10^{-235}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1 \cdot 10^{-257}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 2.7 \cdot 10^{-243}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.12 \cdot 10^{-206}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 1.3 \cdot 10^{-87}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4 \cdot 10^{-66}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{-8}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error36.08%
Cost1508
\[\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)\\ t_4 := \left(y - z\right) \cdot t\\ \mathbf{if}\;z \leq -7.8 \cdot 10^{+33}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -2.9 \cdot 10^{-103}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;z \leq -2.6 \cdot 10^{-213}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1 \cdot 10^{-255}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 1.8 \cdot 10^{-244}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.2 \cdot 10^{-206}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 1.55 \cdot 10^{-87}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 6.8 \cdot 10^{-67}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;z \leq 0.000445:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error63.53%
Cost1312
\[\begin{array}{l} \mathbf{if}\;z \leq -2.1 \cdot 10^{+15}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -3.2 \cdot 10^{-50}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq -2.6 \cdot 10^{-213}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -4 \cdot 10^{-256}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 1.25 \cdot 10^{-243}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2.1 \cdot 10^{-206}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 1.05 \cdot 10^{-44}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 5.7 \cdot 10^{+110}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 5
Error61.64%
Cost1180
\[\begin{array}{l} t_1 := z \cdot \left(-t\right)\\ \mathbf{if}\;y \leq -1.65 \cdot 10^{-37}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq -1.4 \cdot 10^{-231}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.3 \cdot 10^{-300}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.9 \cdot 10^{-213}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 9.5 \cdot 10^{-101}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 7 \cdot 10^{-22}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 750000000000:\\ \;\;\;\;z \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \end{array} \]
Alternative 6
Error61.19%
Cost1116
\[\begin{array}{l} \mathbf{if}\;z \leq -1.6 \cdot 10^{+17}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -1.6 \cdot 10^{-48}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq -2.6 \cdot 10^{-213}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -4.2 \cdot 10^{-256}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 1.3 \cdot 10^{-243}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2.2 \cdot 10^{-205}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 0.035:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 7
Error37.63%
Cost850
\[\begin{array}{l} \mathbf{if}\;x \leq -3.8 \cdot 10^{-106} \lor \neg \left(x \leq 1.12 \cdot 10^{-69} \lor \neg \left(x \leq 4.2 \cdot 10^{-53}\right) \land x \leq 1.22 \cdot 10^{-38}\right):\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \end{array} \]
Alternative 8
Error17.18%
Cost849
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ \mathbf{if}\;z \leq -6500000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.75 \cdot 10^{-7}:\\ \;\;\;\;x - y \cdot \left(x - t\right)\\ \mathbf{elif}\;z \leq 8.5 \cdot 10^{+53} \lor \neg \left(z \leq 5.8 \cdot 10^{+70}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(t - x\right)\\ \end{array} \]
Alternative 9
Error16.43%
Cost848
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ t_2 := x + t_1\\ \mathbf{if}\;z \leq -1.1 \cdot 10^{-18}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 6 \cdot 10^{-20}:\\ \;\;\;\;x - y \cdot \left(x - t\right)\\ \mathbf{elif}\;z \leq 8.6 \cdot 10^{+53}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 5.8 \cdot 10^{+70}:\\ \;\;\;\;y \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error29.84%
Cost716
\[\begin{array}{l} t_1 := y \cdot \left(t - x\right)\\ \mathbf{if}\;y \leq -1.1 \cdot 10^{+100}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.4 \cdot 10^{-35}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;y \leq 550000000000:\\ \;\;\;\;x - z \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error0.05%
Cost576
\[x + \left(y - z\right) \cdot \left(t - x\right) \]
Alternative 12
Error59.66%
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -1.65 \cdot 10^{-37}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 1.06 \cdot 10^{-9}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 13
Error74.21%
Cost64
\[x \]

Error

Reproduce?

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