Proof:Functions with left inverses are injective

From CS2800 wiki
If a function [math]f : A \href{/cs2800/wiki/index.php/%5Cto}{\to} B [/math] has a left inverse [math]g : B \href{/cs2800/wiki/index.php/%5Cto}{\to} A [/math], then [math]f [/math] is injective.
Proof: Functions with left inverses are injective
Assume [math]f : A \href{/cs2800/wiki/index.php/%5Cto}{\to} B [/math] has a left inverse [math]g : B \href{/cs2800/wiki/index.php/%5Cto}{\to} A [/math], so that [math]g \href{/cs2800/wiki/index.php/%5Ccirc}{\circ} f \href{/cs2800/wiki/index.php/Equality_(functions)}{=} \href{/cs2800/wiki/index.php?title=Id&action=edit&redlink=1}{id} [/math]. We want to show that [math]f [/math] is injective, i.e. that for all [math]x_1,x_2 \href{/cs2800/wiki/index.php/%5Cin}{\in} A [/math], if [math]f(x_1) = f(x_2) [/math] then [math]x_1 = x_2 [/math]. Choose arbitrary [math]x_1 [/math] and [math]x_2 [/math] in [math]A [/math], and assume that [math]f(x_1) = f(x_2) [/math]. Since [math]g \href{/cs2800/wiki/index.php/%5Ccirc}{\circ} f = \href{/cs2800/wiki/index.php?title=Id&action=edit&redlink=1}{id} [/math] have [math]x_1 = g(f(x_1)) = g(f(x_2)) = x_2 [/math], as required.