# Solving Diophantine equations

Given a complex number $z$ and a positive integer $n$, I would like to be able to find integer solutions $\alpha,\beta,\gamma$ to the Diophantine equation $$0 < a^2\vert z \vert^2 + \beta\textrm{ Re}(z) + \gamma^2 \leq n.$$ As an example, I tried

z := 2 + 3*i
Solve[0 < a^2*Norm[z^2] + b*Re[z] + c^2 <= 100,{a,b,c},Integers]


But when I hit return+shift I got "This system cannot be solved with the methods available to Solve". Can anyone explain why this doesn't work and offer a method which will work? Thanks.

• You have a couple of errors there. For one thing, Mma uses I not i. Commented Jan 31, 2017 at 1:54

See if this is what you want:

z = 2 + 3*I;
rul = FindInstance[0 < a^2*Norm[z^2] + b*Re[z] + c^2 <= 100, {a, b, c}, Integers, 5]


Change the 5 for more or less.

0 < a^2*Norm[z^2] + b*Re[z] + c^2 <= 100 /. rul


a^2*Norm[z^2] + b*Re[z] + c^2 /. rul

• Great, thanks. Is there a way to take the solutions $(a,b,c)$ and plug them back into the equation to obtain and store the values of $a^2\vert z \vert^2 + b\textrm{ b}(z) + c^2$ at those points? Commented Jan 31, 2017 at 3:54
• I have added it to the answer. Commented Jan 31, 2017 at 4:10
• Is there a way to directly list out the finitely many real numbers $x \in (0,n]$ such that $$x = a^2\vert z \vert^2 + b\textrm{Re}(z) + c^2$$ for some integers $a,b,c$? It appears that there are infinitely many solutions to the Diophantine equation I posted, but only finitely many such $x$. Commented Feb 1, 2017 at 2:00
• The x you have there is what is inside of FindInstance. If there are a finite number of real x (which I doubt) then it is a large number. Commented Feb 1, 2017 at 2:31
• There must be a finite number because the set of such points $x$ is a lattice in a bounded region. Commented Feb 1, 2017 at 3:24

A general expression can be obtained using Reduce. Because this function seems to prefer working with polynomials, replace z in the question by u + I v. Then, using the form of the equation to be solved given by the OP in a comment above, we have.

s = Reduce[x == a^2*(u^2 + v^2) + b*u + c^2 > 0 /. {u -> 2, v -> 3},
{a, b, c}, Integers]
(* (C[3] ∈ Integers && C[2] ∈ Integers && C[1] ∈ Integers && C[1] >= 1 &&
x == 2 C[1] && a == 2 C[2] &&
b == 1/2 (-13 a^2 + x - 4 C[3]^2) && c == 2 C[3]) ||
(C[3] ∈ Integers && C[2] ∈ Integers && C[1] ∈ Integers && C[1] >= 1 &&
x == 2 C[1] && a == 1 + 2 C[2] &&
b == 1/2 (-13 a^2 + x - (1 + 2 C[3])^2) && c == 1 + 2 C[3]) ||
(C[3] ∈ Integers && C[2] ∈ Integers && C[1] ∈ Integers && C[1] >= 0 &&
x == 1 + 2 C[1] && a == 2 C[2] &&
b == 1/2 (-13 a^2 + x - (1 + 2 C[3])^2) && c == 1 + 2 C[3]) ||
(C[3] ∈ Integers && C[2] ∈ Integers && C[1] ∈ Integers && C[1] >= 0 &&
x == 1 + 2 C[1] && a == 1 + 2 C[2] &&
b == 1/2 (-13 a^2 + x - 4 C[3]^2) && c == 2 C[3]) *)


Note that each of the four solutions contains three arbitrary integer constants, {C[1], C[2], C[3]}. The first of these C[1] >= 0 determines x. Thus, for any given value of x the equation has an infinite number of solutions. s can be evaluated simply to obtain a finite set of them. For instance,

Union[Flatten[List @@
Reduce[s /. Thread[{C[1], C[2], C[3]} -> #], {a, b, c}] & /@
Tuples[{{0, 1}, {-1, 0, 1}, {-1, 0, 1}}]]]


yields 54 solutions, the first several of which are

(* {x == 1 && a == -2 && b == -30 && c == 3,
x == 1 && a == -2 && b == -26 && c == -1,
x == 1 && a == -2 && b == -26 && c == 1,
x == 1 && a == -1 && b == -8 && c == -2,
x == 1 && a == -1 && b == -8 && c == 2,
x == 1 && a == -1 && b == -6 && c == 0,
x == 1 && a == 0 && b == -4 && c == 3,
x == 1 && a == 0 && b == 0 && c == -1,
x == 1 && a == 0 && b == 0 && c == 1,
x == 1 && a == 1 && b == -8 && c == -2,
x == 1 && a == 1 && b == -8 && c == 2,
x == 1 && a == 1 && b == -6 && c == 0,
x == 1 && a == 2 && b == -30 && c == 3,
x == 1 && a == 2 && b == -26 && c == -1,
x == 1 && a == 2 && b == -26 && c == 1,
x == 1 && a == 3 && b == -60 && c == -2,
x == 1 && a == 3 && b == -60 && c == 2,
x == 1 && a == 3 && b == -58 && c == 0, ... *)