Extending $f: S \rightarrow G'$ to $f': G \rightarrow G'$ where $f’$ is a homomorphism I was trying to prove that if $G, G'$ are groups and $S$ a set of generators for $G$. If $f: S \rightarrow G'$ is a map then there exists at most one extension to $f': G \rightarrow G'$ where $f'$ is a homomorphism.
I was examining any two functions $p, q: G \rightarrow G'$ and was trying to make use of the homomorphism property to write $p(x)=p(x_1)^{a_1}p(x_2)^{a_2}...p(x_n)^{a_n}$, and since $p$ and $q$ agree on $S$, we're done. But my question is, what if we express $x$ in two different ways, not just $x = x_1^{a_1}...x_n^{a_n}$? How do we deal with that question? I have a rough idea of what a free group is, and I think it has something to do with this.
 A: Let $G$ be a group, $S \subseteq G$. Define the subgroup "generated by S" to be $\{x \in G : $ for every subgroup $S'$ of $G$ such that $S \subseteq S'$, $x \in S'\}$.
Note that this is the smallest subgroup of $G$ which contains $S$; that is, the subgroup generated by $S$ is a subgroup of every subgroup of $G$ which is a superset of $S$.
Then $S$ generates $G$ iff the group generated by $S$ is $G$.
Now suppose that $S$ generates $G$ and that $f : S \to G'$ as sets. Suppose now that we have $g, g' : G \to G'$ as groups such that $g \circ f = g' \circ f$. We can consider the equaliser of these maps $E = \{x \in G : g(x) = g'(x)\}$, which is a subgroup of $G$. This equaliser contains $S$. Therefore, the subgroup generated by $S$ is a subgroup of $E$. Then $G$ is a subgroup of $E$, which is a subgroup of $G$. Then $E = G$.
Clearly, the equaliser of two maps can only be $G$ when the two maps are equal.
Edit:
Alternately, we can express the subgroup generated by $S$ as the set of $x$ which can be written in the form $y_1^{s_1} ... y_n^{s_n}$ where $y_i \in S$, $s_i = \pm 1$. Suppose we have $p, q : G \to G'$ group maps which extend $f : S \to G'$. Consider $x \in G$, and write it in the above form. Then $p(x) = p(y_1)^{s_1} ... p(y_n)^{s_n} = q(y_1)^{s_1} ... q(y_n)^{s_n} = q(x)$. Note that it doesn't matter that $x$ could possibly be written in multiple ways; we only need one such way to show that $p(x) = q(x)$.
Finally, there is a third proof. Let $F_S$ be the free group on $S$, and let $\eta_S : S \to F_S$ be the universal map. We say that the subgroup generated by $S$ is the image of the group map $g : F_S \to G$ such that $g \circ \eta_S$ is the inclusion map $i : S \subseteq G$.  Now suppose that we have $p, q : G \to G'$ such that $p$ and $q$ agree on $S$; that is, such that $p \circ i = q \circ i$. Then $p \circ g \circ \eta_S = q \circ g \circ \eta_S$; then $p \circ g = q \circ g$. The fact that $p = q$ follows from the fact that $g$ is surjective.
A: Your question is about whether there exists an extension. Indeed, there is an extension if and only if all ways of writing $g\in G$ as a product of elements of $S$ yield the same element of $G'$. This is succinctly stated as the function extends to a homomorphism $G\to G'$ if and only if, when extending it using your method, it is well-defined.
Of course, sometimes this works and sometimes it doesn't, depending on your choices for the images of elements of $S$.
A: In order to adress your question:

But my question is, what if we express x in two different ways, not
just x = $x_1^{a_1}...x_n^{a_n}$? How do we deal with that question?

This is essentially the key observation which justifies the concrete construction of a free group via reduced words.
Take, just for instance, any generating set with two elements such as $\{a,b\}$ where $a$ and $b$ are called letters and all possible linearcombinations (juxtapositions) are words. Let $W=W(\{a,b\})$ be the set of all words. Two elements of $W$ could be $$abb^{-1}a$$ and $$abaa^{-1}b^{-1}a$$
And you might immediately notice that we encounter redundancies within $W$ since even though these two are considered to be two distinct elements in $W$, they would correspond to the same group element if we would start cancelling pairs such as $aa^{-1}, a^{-1}a$ and analogously for $b$.
This leads to the process of reducing words. In Algebra: Chapter $0$ by Paolo Aluffi this is described in a somewhat successive process, so that we successively eliminate cancelling pairs by successively applying a reduction map $$r\colon W(A)\to W(A)$$ given a generating set $A$, observe that in my example we have $A=\{a,b\}$.
Finally, we can define the free group $F(A)$ as the set of all reduced words on the generating set $A$.
There is a function $j\colon A\to F(A)$ defined by sending the element $a \in A$ to the word consisting of the single letter $a$.

Proposition: $j\colon A\to F(A)$ satisfies the universal property for free groups on $A$.

That is, Any function $f\colon A\to G$ extends uniquely to a map $\varphi\colon F(A) \to G$.
I will only provide a quick discussion on this. To check that the extension $\varphi\colon F(A) \to G$ exists as a homomorphism, proceed as follows. If $f\colon A\to G$ is any function, you can extend $f$ to a set-function $$\tilde{\varphi}\colon W(A)\to G$$ by insisting that on one-letter words $a$ or $a^{-1}$ for $a \in A$ it holds that $$\tilde{\varphi} = f(a),\ \tilde{\varphi}(a^{-1}) = f(a)^{-1}$$
and that $\tilde{\varphi}$ is compatible with juxtaposition $$\tilde{\varphi}(\omega \omega') = \tilde{\varphi}(\omega)\tilde{\varphi}(w')$$ for any two words $\omega, \omega'$.
They key observation now is that reduction is invisible for $\tilde{\varphi}$: $$\tilde{\varphi}(R(\omega)) = \tilde{\varphi}(\omega)$$
where $R(\omega)$ is the reduced word of $\omega$. I think that this in particular is what adresses your question.
Anyway, since $\varphi\colon F(A)\to G$ agress with $\tilde{\varphi}$ on reduced words, we have for $\omega, \omega' \in F(A)$ that $$\varphi(\omega\omega') = \tilde{\varphi}(\omega\omega') = \tilde{\varphi}(R(\omega\omega')) = \tilde{\varphi}(\omega\omega') = \tilde{\varphi}(\omega)\tilde{\varphi}(\omega') = \varphi(\omega)\varphi(\omega').$$
