Suppose I have a quadratic function $$f(x)=ax^2+bx+c, \hspace{1 cm}a,b,c\in \mathbb Z$$and I want to find rational (non-integer) values of $x$ for which $f(x)\in \mathbb Z$.
I start by assuming $x=\frac pq$ for coprime integers $p,q$. Then, $f(x)$ will be an integer when $ax^2+bx=x(ax+b)$ is an integer. $$x(ax+b) =\frac pq \left( a\frac pq +b\right)=p\cdot\frac{ap+bq}{q^2} $$ Since $q\nmid p$, $$ap+bq=kq^2 \implies a\frac pq=kq-b$$ for some $k$. The LHS must be an integer, and so $q|a\implies a=nq$ for $n\in\mathbb Z$, which gives $$kq-np=b$$
Questions:
$\bullet$ Is what I have done correct?
$\bullet$ Am I really free to choose integers $p,q,k,n$ only satisfying this equation, and $f(x)$ will be an integer?
$\bullet$ If there is a better way, please let me know.
You need to add the condition that $q\not=\pm 1$. (I would define $p,q$ as integers satisfying $\gcd(p,q)=1,q\gt 0$ and $q\not=1$.) Except this, what you've done is correct.
Yes. If there are integers $p,q,n,k$ such that $a=nq$ and $b=kq-np$, then $$f\bigg(\frac pq\bigg)=nq\bigg(\frac pq\bigg)^2+(kq-np)\cdot\frac pq+c=kp+c$$ is an integer.