Is it possible to eliminate the variable $q$ from the following gcd expression? $$\gcd\left(a (e-gq),(q^2-d)g+(e-gq)(q-p)\right)$$
What I tried was the following:
Assuming that the gcd is $m$, I get $$\frac{a(e-gq)}{n_1}=m \tag1$$ and so $$q=\frac{ae-mn_1}{a g} \tag2$$ for some integer $n_1$. Now $$\frac{(q^2-d)g+(e-gq)(q-p)}{n_2}=m \tag3$$ for some integer $n_2$. Substituting for $q$ from $(2)$, I have $$a (e^2-d g^2)=m(n_2 a g+n_1 (e+g p)) \tag4$$ Therefore I conclude $$\gcd\big(a (e-gq),(q^2-d)g+(e-gq)(q-p)\big)=\gcd\big(a (e-gq),a(e^2-d g^2)\big) \tag5$$
But this seems to be wrong. A simple substitution of $e1=4,g1=1,a=-3,d=17,q=5, p=4$ shows there is something not correct.
Can someone please point me where I am going astray? What then is the correct simplification?
Thanks.