When is an algebra map on generators well-defined? Let $A$ be an $R$-algebra ($R$ comm. ring) and let $a,b$ a generating set of $A$, i.e. any element of $A$ can be written as products, sums, $R$-multiples of $a,b$. Then one can define any map $f:A\to B$ by its image on the generators. This is quite clear.
My question, however, is there any criterion such that the map is well-defined? For example look at the $\mathbb{Z}$-algebra $\mathbb{Z}$: Then $1$ generates $\mathbb{Z}$ but also $\{1,2\}$. If I naivly define $f:\mathbb{Z}\to\mathbb{Z}$ as $f(1)=1$ and $f(2)=3$ then there is an obvious contradiction $2=3$. How can one systematically check that $f$ is a real map?
 A: If $A=R[a_1,\dots,a_p]$ is a finitely generated $R$-algebra, then it is isomorphic to a quotient $R[x_1,\dots,x_p]/I$, where $I$ is an ideal of $A$ describing the relations between the generators $a_1,\dots,a_p$ (the $a_i$'s correspond to the classes of the $x_i$'s under the isomorphism). The key point is that you must preserve the relations! In fact, if $g\in I$, then $g(a_1,\dots,a_p)=0$, so your morphism $f$ have to be compatible with that, i.e. we must have
$$g(f(a_1),\dots,f(a_p))=f(g(a_1,\dots,a_p))=0$$
since $f$ is a $R$-algebra morphism. 
In your example, $\Bbb Z=\Bbb Z[1,2] \simeq \Bbb Z[x,y]/(y-2x,x-1)$ so you must have $f(2)=2f(1)$.
Now, if you preserve the relations, then $f$ exists and is unique. Indeed, if we want to have $f(a_i)=b_i$ for all $i$ then universal property of polynomial rings shows there exists a unique $R$-algebra morphism $f_1 : R[x_1,\dots,x_p]\to B$ s.t. $f_1(x_i)=b_i$ for all $i$. 
Finally, preserving the relations means exactly that $f_1(I)=(0)$. Thus $f_1$ passes to the quotient and gives a morphism $f_0 : R[x_1,\dots,x_p]/I\to B$ s.t. $f_0([x_i]) = b_i$ for all $i$. By composing with the isomorphism $A=R[a_1,\dots,a_p]\to R[x_1,\dots,x_p]/I$, we obtain the existence of $f:A\to B$ s.t. $f(a_i)=b_i$ for all $i$. 
A: If $A$ is generated by $a,b$ as an $R$ algebra, then there is a surjective map $\phi:R[X,Y]\to A$ mapping $X$ to $a$ and $Y$ to $b$. 
Then for any $R$-algebra map $f:A\to B$ there is an $R$-algebra map $F:R[X,Y]\to B$ given by $F=f\circ\phi$. In particular, we must have $\ker(\phi)\subset\ker(F)$, and this gives you the consistency condition the images of $a$ and $b$ must satisfy.
A: If you algebra $A$ is presented as a quotient of a free $k$-algebra by some relations, say $A=k\langle X \mid R\rangle$ then a map of $k$-algebras $f:A\longrightarrow B$ will be properly defined whenever you define it for all generators in $X$ and the relations $R$ hold in $B$ for the image $f(X)$.  
In your example, $\mathbb Z$ is the free $\mathbb Z$-algebra on no generators, and in particular for any choice of ring $A$ there is only one map of $\mathbb Z$-algebras (rings!) 
$$\mathbb Z\longrightarrow A$$
namely the map that sends $1\in\mathbb Z$ to $1\in A$.  
