Start by making a list of polynomial terms to choose from: for example, all terms up to third order in $f$ and $g$,
terms = DeleteDuplicates[Times @@@ Tuples[{1, F, G}, 3]]
(* {1, F, G, F^2, F G, G^2, F^3, F^2 G, F G^2, G^3} *)
Express these terms as polynomials in $p$, and list their polynomial coefficients (here up to sixth order in $p$):
f = p^2 + p;
g = p + 4;
X = CoefficientList[terms /. {F -> f, G -> g}, p, 7]
(* {{ 1, 0, 0, 0, 0, 0, 0},
{ 0, 1, 1, 0, 0, 0, 0},
{ 4, 1, 0, 0, 0, 0, 0},
{ 0, 0, 1, 2, 1, 0, 0},
{ 0, 4, 5, 1, 0, 0, 0},
{16, 8, 1, 0, 0, 0, 0},
{ 0, 0, 0, 1, 3, 3, 1},
{ 0, 0, 4, 9, 6, 1, 0},
{ 0, 16, 24, 9, 1, 0, 0},
{64, 48, 12, 1, 0, 0, 0}} *)
Find the null-space of this matrix: the polynomials that combine to zero,
NullSpace[Transpose[X]] . terms
(* {84 - 7 F - 37 G - F G + G^3,
12 F - F^2 - 7 F G + F G^2,
12 - F - 7 G + G^2} *)
Verify these three solutions:
% /. {F -> f, G -> g} // Expand
(* {0, 0, 0} *)
So we have the solutions
$$
-f g-7 f+g^3-37 g+84 = 0\\
-f^2+f g^2-7 f g+12 f = 0\\
-f+g^2-7 g+12 = 0
$$
There will be many more solutions if you increase the order of terms in terms
. Factoring these solutions will show you the minimal function $P$, which in this case is $P(f,g)=-f+g^2-7 g+12=0$. You can add constants $C$ to this solution at will.
Rational functions
An extension of the above procedure to rational functions is straightforward through extending all functions by the common denominator. As an example,
f = p/(p + 1);
g = p*(p - 1)/(p^3 + 7);
denom = PolynomialLCM @@ Denominator /@ {f, g}
(* (1 + p) (7 + p^3) *)
Expanding the rational functions by the denom
gives polynomials of order
e = Max@Exponent[{f, g}*denom, p]
(* 4 *)
Use polynomial terms up to fifth order in the result:
maxorder = 5;
terms = DeleteDuplicates[Times @@@ Tuples[{1, F, G}, maxorder]]
(* {1, F, G, F^2, F G, G^2, F^3, F^2 G, F G^2, G^3, F^4, F^3 G,
F^2 G^2, F G^3, G^4, F^5, F^4 G, F^3 G^2, F^2 G^3, F G^4, G^5} *)
Compute the coefficients matrix:
X = CoefficientList[terms*denom^maxorder /. {F -> f, G -> g}, p, e*maxorder + 1]
(* 21x21 matrix with integer coefficients *)
Pick the null-space solution that has the smallest number of non-zero coefficients:
MinimalBy[NullSpace[Transpose[X]], Total@*Unitize] . terms
(* {-F + 3 F^2 - 2 F^3 - 7 G + 21 F G - 21 F^2 G + 6 F^3 G} *)
So we see that
$$
6 f^3 g-21 f^2 g-2 f^3+3 f^2+21 f g-f-7 g = 0
$$
-Resultant[f,g,p]
. $\endgroup$