Subgroup generated by a subset of the group G I'm trying to prove the set $A = \{a_1^{m_1}a_2^{m_2}\cdots a_n^{m_n}\mid m_i \in \mathbb{Z} \textrm{ and } 1 \leq i \leq n \}$ is equal to the set $\displaystyle \bigcap_{H \in \mathbb{\mathscr{L}}} H$
where $\mathscr{L}$ is the collection of all subgroups $H$ of $G$ that contains the set $S = \{a_1, a_2, \cdots, a_n\}$
For the first inclusion it was okay, it's easy to show that
$A \subset \displaystyle \bigcap_{H \in \mathbb{\mathscr{L}}} H$ , since $S \subset H$ and $H$ is a subgroup, so we can operate the elements $a_1, \cdots, a_n$ and find another element in $H$.
But I'm having some issues in the second inclusion.
We consider some $k \in \displaystyle \bigcap_{H \in \mathbb{\mathscr{L}}} H$, if $k \in A$, it means that $A$ is a subgroup of $G$ that contains $S.$
My attempt was the One-step test for subgroups,
$x, y \in A \implies xy^{-1} \in A$, so $A \leq G$
We consider $x,y \in A$, it follows that
$x = a_1^{m_1}a_2^{m_2}\cdots a_n^{m_n}$
$y = a_1^{l_1}a_2^{l_2}\cdots a_n^{l_n}$, with $m_i, l_i \in \mathbb{Z}$
Because of the sock-shoes property we have that
$y^{-1} = a_n^{-l_n}a_{n-1}^{-l_{n-1}}\cdots a_1^{-l_1}$
Then we have to show that
$xy^{-1} \in A$, I got stuck here, because for me it seems that I need some commutative property here.
That's the right way to solve this problem? if it's not, how can I show it? Don't give the answer please, just some tips.
 A: To try and furnish you with some hints, as you request:

*

*first of all, the only proper and rigorous way to define your set $A$ -- for which I will use another symbol, due to reasons of personal syntactic preference -- is as follows:

$$H\colon=\left\{x \in G \mid\ (\exists n, t, m)\left(n \in \mathbb{N} \wedge t \in S^n \wedge m \in \mathbb{Z}^n \wedge x=\prod_{k=1}^nt_k^{m_k}\right)\right\},$$
where it must be specified that by default any product of the form $\displaystyle\prod_{k=p}^qy_k$ -- of a family $y \in G^{[p, q]}$ indexed by the natural interval $[p, q]$ -- is considered with respect to the standard order on the specified interval $[p, q]$ (this needs to be mentioned because in general within a not necessarily commutative monoid $M$ one needs to specify a total order $T$ on the index set $I$ of any family $x \in M^{(I)}$ of finite support, family the product of which one would like to consider; in a general monoid, different total orders on the same index set easily lead to different values of the product of one and the same family).

*

*second, we introduce $H'\colon=\langle S \rangle=\displaystyle\bigcap_{\substack{F \leqslant G \\ F \supseteq S}} F$, by definition the subgroup generated by $S$. As you remarked, the inclusion $H \subseteq H'$ is easy to obtain, since $H'$ being a subgroup is multiplicatively stable and also closed with respect to inverses.

*in order to infer the reverse inclusion, you must follow the indications in the above comment of Arturo Magidin and first establish that $H \leqslant G$ is itself a subgroup such that $S \subseteq H$. The fact that $S$ is included in $H$ is a trivial observation, since for any $t \in S$ you have the family $s\colon=\{(1, t)\} \in S^{1}$ together with the family of exponents $m\colon=\{(1, 1)\} \in \mathbb{Z}^1$ such that $t=\displaystyle\prod_{k=1}^1s_k^{m_k}$.

*as to why $H$ is a subgroup, notice first it is clearly nonempty because $1_G \in H$ (the unity can be expressed as the product of the empty family of elements of $S$). It is multiplicatively stable because $\displaystyle\prod_{k=1}^ms_k^{p_k}\displaystyle\prod_{k=1}^nt_k^{q_k}$ -- with both families $s \in S^m, t \in S^n$ consisting of elements of $S$ -- can be equivalently expressed as the product of a family in $S^{m+n}$ (I will let you figure out how) and finally closure with respect to inverses is due to a similar token: in general you have $\left(\displaystyle\prod_{k=1}^nt_k^{m_k}\right)^{-1}=\displaystyle\prod_{k=1}^nt_{n+1-k}^{-m_{n+1-k}}$, and as long as $t \in S^n$ is a family of elements of $S$ the "reversed" family $t'\colon=\left(t_{n+1-k}\right)_{1 \leqslant k \leqslant n} \in S^n$ clearly also is a family of elements of $S$.

A: Please check again the question.
As stated by @NL1992, $a_2a_1\notin A$ but $a_2a_1\in \bigcap_{H \in \mathbb{\mathscr{L}}} H$. Unless $a_ia_j=a_ja_i$ for all $a_i,a_j\in S$,  otherwise these two sets may not be equal.
The correct version of $A$ should be
$$A=\{g_1^{m_1}\dots g_k^{m_k}:k\geq 1,m_1,\dots,m_k\in \Bbb{Z},g_1,\dots g_k\in S\}.$$
You can first show that $A$ is a subgroup of $G$ containing $S$. Since $\bigcap_{H \in \mathbb{\mathscr{L}}}H $ is the intersection of all subgroups containing $S$, we must have $A\subseteq \bigcap_{H \in \mathbb{\mathscr{L}}}H $.
