TITLE: Rational Diophantine set for the non-squares
QUESTION [7 upvotes]: Related to Hilbert's Tenth problem.
Is there polynomial with integer coefficients $P(a,x_1,...,x_n)$
such that $P(A,X_i)=0$ has rational solutions $X_i$ iff $A$ is
not the square of integer (or as another question not the square
of rational)?
We think if $P$ is homogeneous and ask about integer solutions,
scaling the solution might cause problems: $A^2,A X_1, A X_2, ...$
Over the integers solution is trivial via Pell equation:
$$
(2+x_1^2+x_2^2+x_3^2+x_4^2)^2- a x_5^2=1
$$

REPLY [10 votes]: The set $A$ of non-squares (of rationals) is Diophantine in $\mathbb{Q}$ by [1]. The set $B:=\mathbb{Q}\smallsetminus\mathbb{Z}$ is also Diophantine by [2]. The set of non-squares of integers is equal to $A\cup B$, hence Diophantine.  
For a generalization of [1], see also [3].  
[EDIT] The paper [1] treats arbitrary (non-)$n$-th powers, but the case of (non-)squares was proved earlier by Poonen [4].
[1] Colliot-Thélène, Jean-Louis; van Geel, Jan, Le complémentaire des puissances $n$-ièmes dans un corps de nombres est un ensemble diophantien, Compos. Math. 151, No. 10, 1965-1980 (2015). ZBL1346.14066.. 
[2] Koenigsmann, Jochen, Defining $\mathbb Z$ in $\mathbb Q$, Ann. Math. (2) 183, No. 1, 73-93 (2016). ZBL1390.03032..  
[3] Dittmann, Philip, Irreducibility of polynomials over global fields is diophantine, Compos. Math. 154, 761-772 (2018). ZBL06861881.
[4] 
Poonen, Bjorn, The set of nonsquares in a number field is diophantine, Math. Res. Lett. 16, No. 1, 165-170 (2009). ZBL1183.14031.