Average Error: 0.0 → 0.0
Time: 12.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

Original0.0
Target0.0
Herbie0.0
\[x + \left(t \cdot \left(y - z\right) + \left(-x\right) \cdot \left(y - z\right)\right) \]

Derivation

  1. Initial program 0.0

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

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

    [Start]0.0

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

    +-commutative [=>]0.0

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

    fma-def [=>]0.0

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

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

Alternatives

Alternative 1
Error35.3
Cost1905
\[\begin{array}{l} t_1 := y \cdot \left(-x\right)\\ t_2 := \left(y - z\right) \cdot t\\ t_3 := z \cdot \left(x - t\right)\\ \mathbf{if}\;y \leq -1.3 \cdot 10^{+215}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -4.8 \cdot 10^{+154}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -2.15 \cdot 10^{+139}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -7.4 \cdot 10^{-28}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -1 \cdot 10^{-173}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -2.7 \cdot 10^{-195}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 3.1 \cdot 10^{-210}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.7 \cdot 10^{-180}:\\ \;\;\;\;z \cdot \left(-t\right)\\ \mathbf{elif}\;y \leq 4.6 \cdot 10^{-122}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.6 \cdot 10^{-42}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 1.2 \cdot 10^{+40} \lor \neg \left(y \leq 3.7 \cdot 10^{+147}\right):\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error35.6
Cost1773
\[\begin{array}{l} t_1 := y \cdot \left(-x\right)\\ t_2 := \left(y - z\right) \cdot t\\ t_3 := z \cdot \left(-t\right)\\ \mathbf{if}\;y \leq -1.25 \cdot 10^{+216}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -3 \cdot 10^{+155}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -1.68 \cdot 10^{+137}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -7.4 \cdot 10^{-28}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -8.8 \cdot 10^{-172}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -2.75 \cdot 10^{-195}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 9.2 \cdot 10^{-210}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.7 \cdot 10^{-180}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 7.5 \cdot 10^{-127}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{+36} \lor \neg \left(y \leq 1.52 \cdot 10^{+147}\right):\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error30.0
Cost1773
\[\begin{array}{l} t_1 := y \cdot \left(-x\right)\\ t_2 := x \cdot \left(z + 1\right)\\ t_3 := \left(y - z\right) \cdot t\\ \mathbf{if}\;y \leq -3.2 \cdot 10^{+216}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -2.2 \cdot 10^{+155}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq -8.4 \cdot 10^{+136}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -7.4 \cdot 10^{-28}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq -1.15 \cdot 10^{-173}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -3.6 \cdot 10^{-198}:\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{elif}\;y \leq 1.05 \cdot 10^{-209}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 3.7 \cdot 10^{-180}:\\ \;\;\;\;z \cdot \left(-t\right)\\ \mathbf{elif}\;y \leq 1.25 \cdot 10^{-29}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 5.4 \cdot 10^{+38} \lor \neg \left(y \leq 3.7 \cdot 10^{+147}\right):\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error38.9
Cost1576
\[\begin{array}{l} t_1 := z \cdot \left(-t\right)\\ t_2 := y \cdot \left(-x\right)\\ \mathbf{if}\;y \leq -4.8 \cdot 10^{+136}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -1.26 \cdot 10^{+22}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq -1.05 \cdot 10^{-27}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -8 \cdot 10^{-174}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -8.5 \cdot 10^{-196}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.05 \cdot 10^{-209}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.7 \cdot 10^{-180}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.85 \cdot 10^{-29}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.7 \cdot 10^{+33}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 2.45 \cdot 10^{+147}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 5
Error23.4
Cost1244
\[\begin{array}{l} t_1 := x \cdot \left(z + 1\right)\\ t_2 := y \cdot \left(t - x\right)\\ \mathbf{if}\;y \leq -3.8 \cdot 10^{+102}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -7.5 \cdot 10^{-28}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;y \leq -8 \cdot 10^{-174}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -3.35 \cdot 10^{-195}:\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{elif}\;y \leq 1.6 \cdot 10^{-213}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3.7 \cdot 10^{-180}:\\ \;\;\;\;z \cdot \left(-t\right)\\ \mathbf{elif}\;y \leq 1.4 \cdot 10^{-18}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error38.9
Cost1048
\[\begin{array}{l} t_1 := y \cdot \left(-x\right)\\ \mathbf{if}\;y \leq -1.55 \cdot 10^{+137}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -2.5 \cdot 10^{+22}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq -2.5 \cdot 10^{-17}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.15 \cdot 10^{-29}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 4.3 \cdot 10^{+37}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 7.5 \cdot 10^{+147}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 7
Error23.9
Cost848
\[\begin{array}{l} t_1 := x \cdot \left(1 - y\right)\\ t_2 := \left(y - z\right) \cdot t\\ \mathbf{if}\;x \leq -5.8 \cdot 10^{-27}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.8 \cdot 10^{-55}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.36 \cdot 10^{-89}:\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \mathbf{elif}\;x \leq 3 \cdot 10^{-71}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error19.4
Cost716
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ \mathbf{if}\;z \leq -1.1 \cdot 10^{-20}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.02 \cdot 10^{-186}:\\ \;\;\;\;x + y \cdot t\\ \mathbf{elif}\;z \leq 5.2 \cdot 10^{-20}:\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error19.4
Cost716
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ \mathbf{if}\;z \leq -1.1 \cdot 10^{-20}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.55 \cdot 10^{-186}:\\ \;\;\;\;x + y \cdot t\\ \mathbf{elif}\;z \leq 1.85 \cdot 10^{-20}:\\ \;\;\;\;x - y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error16.5
Cost713
\[\begin{array}{l} \mathbf{if}\;x \leq -7.3 \cdot 10^{-96} \lor \neg \left(x \leq 1.1 \cdot 10^{-95}\right):\\ \;\;\;\;x \cdot \left(\left(z + 1\right) - y\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \end{array} \]
Alternative 11
Error11.7
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -1.1 \cdot 10^{-20} \lor \neg \left(z \leq 1.5 \cdot 10^{+40}\right):\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(t - x\right)\\ \end{array} \]
Alternative 12
Error0.0
Cost576
\[x + \left(y - z\right) \cdot \left(t - x\right) \]
Alternative 13
Error38.5
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -1.15 \cdot 10^{-18}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 1.55 \cdot 10^{-29}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 14
Error47.8
Cost64
\[x \]

Error

Reproduce

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