Suppose that $k$ is a field and I have two ring homomorphisms $$ \phi, \psi :k[x_1,...,x_m] \to k[y_1,...,y_n]. $$ How can I use Gröbner bases (or other computational tools) to compute the subring of elements $a$ such that $f(a)=g(a)$?

Comments:

- When I say "compute", I mean actually compute, for example using Sage, Macaulay2, etc. I actually don't care about using Gröbner bases, I just want to do the computation.
- I intend to apply this in the case $k[x_1, ..., x_m] \to k[x_1, ..., x_m, z_1, ..., z_q]$ where $\psi$ is the obvious inclusion, and $\phi$ is some other algebra homomorphism (not linear, not degree-preserving).
- If it matters, let's assume that $k$ has positive characteristic.
- I have the same question with the domain and codomain replaced by quotients of polynomial algebras.