From Abstract Algebra in GAP by Alexander Hulpke, section 3.23 "Groups generated by elements":
We have seen so far two ways of specifying subgroups: By listing explicitly all elements, or by specifying a defining property of the elements. In some cases neither variant is satisfactory to specify certain subgroups, and it is preferrable to specify a subgroup by generating elements.
Definition: Let $G$ be a group and $a_1, a_2, ..., a_n ∈ G$. The set
$<a_1,a_2,\ldots,a_n> = \\ \bigg \{ b_1^{\epsilon_1} \cdot b_2^{\epsilon_2} \ldots \ldots b_k^{\epsilon_k} | k \in N_0 = \{0,1,2,3,\ldots\}, b_i \in \{a_1, \ldots, a_n \}, \epsilon_i \in \{ 1, -1 \} \bigg \} $
(with the convention that for $k = 0$ the product over the empty list is $e$) is called the subgroup of $G$ generated by $a_1,...,a_n$.
My question is around the interpretation of the set notation above.
Let's say we have <a,b>. If I'd like to enumerate the set according to the definition above, is this the correct interpretation?
k = 0 ()
k = 1
a
a^-1
b
b^-1
k = 2
a a
a a^-1
a^-1 a
a^-1 a^-1
a b
a b^-1
a^-1 b
a^-1 b^-1
b a
b a^-1
b^-1 a
b^-1 a^-1
b b
b b^-1
b^-1 b
b^-1 b^-1
k = 3
...
According to the definition, yes, you are correct so far, but your enumeration of the set as a set of group elements is flawed in that it fails to take into account that cancellation happens each time an element and its inverse occur next to each other.