In awodey's book, page 32. He defines the free monoid $M(A)$ on set $A$ is the monoid that satisfies the universal mapping property, namely given the inclusion function $i:A\rightarrow |M(A)|$ (where $|M(A)|$ stands for the underlying set of the monoid $M(A)$), and given any monoid $N$ and any function $f:A\rightarrow |N|$, there is a unique monoid homomorphism $\bar{f}:M(A)\rightarrow N$ such that $|\bar{f}|\circ i=f$.
Then he proves that an alphabet $A$ endowed with the kleene star operation, namely $A^*$ is a free monoid. In the second part, the proof deals with the uniqueness of such $\bar{f}:A^*\rightarrow N$ by proving that, given $f:A\rightarrow N$ and $i:A\rightarrow |M(A)|$, if there is another homomorphism $g:A^*\rightarrow N$ such that $g\circ i = f$, then $\bar{f}=g$, the proof proceeds as follow:
- First, from $g\circ i=f$ we know that $g(a)=f(a)$ for all $a\in A$, because $i$ is an inclusion map and $dom(i)=A$. And similarly we have $\bar{f}(a)=f(a)$ for all $a\in A$
- Since $g$ satisfies $g(a)=f(a)$ for all $a\in A$, then for all $a_1...a_i\in A^*$, we have:
$$ \begin{aligned} g(a_1...a_i) & =g(a_1*...*a_i)\\ &=g(a_1)\cdot_N...\cdot_N\ g(a_i)\\ &=f(a_1)\cdot_N...\cdot_N\ f(a_i) \\ &=\bar{f}(a_1)\cdot_N...\cdot_N\ \bar{f}(a_i)\\ &=\bar{f}(a_1*...*a_i)\\ &=\bar{f}(a_1...a_i) \end{aligned} $$
my problem occurs in line 3, from the definition it seems that $f$ is defined on $A$ but $g$ is defined on $A^*$, how does it come that $g(a_1)$ can be directed substituted to $f(a_1)$?
EDIT: I've just figured out something, even though I don't know if it's correct or wrong, I noticed the proposition was written as "The monoid $A^*$ has the UMP property" instead of "finding a free monoid over $A$". So I guess this proposition pre-assumes the definition of $A^*$, and by the definition of $A^*$ it is clear that every string $a_1...a_i\in A^*$ is generated by elements $a_1, ... ,a_i\in A$. And the proposition is just verifying that this definition enjoys the UMP property, so we can, by definition, break $g(a_1...a_i)$ into $g(a_1*...*a_i)$ and guarantee that $a_1, ..., a_i\in A$; and thus we can substitute $f(a_i)$ for $g(a_i)$: their domain now coincides.
It is common to treat $i$ as an identity, since it feels unnatural to make a distinction between a letter $a$ and the corresponding word of length 1 $a$. You are right, that $g$ is defined on $A^\ast$ as opposed to $A$, but the equality $g\circ i = f$ tells you, that on 1-character words $g$ does what $f$ does to letters.