I want to solve a quadratic equation over the integers but the naive method is unbearably slow (considering how easy the problem is).
I have a positive non-degenerate quadratic form $Q$ on $\mathbb Z^n$(This is why I only have finitely many solutions) and I want to find all solutions of
$$Q(x)=a$$
With $a$ some fixed constant. In principle the problem is solved by
xx = Array[x, n]
Solve[Q[xx]==a,xx,Integers]
but this takes an insane amount of time even for small numbers (for instance $n=6$). Any ideas on how can I speed up the process?
A concrete example:
mat = {{4/3, 5/3, 2, 4/3, 2/3, 1}, {5/3, 10/3, 4, 8/3, 4/3, 2}, {2, 4,
6, 4, 2, 3}, {4/3, 8/3, 4, 10/3, 5/3, 2}, {2/3, 4/3, 2, 5/3, 4/3,
1}, {1, 2, 3, 2, 1, 2}};
Q[xx_] := xx . mat . xx;
xx = Array[x, 6];
Solve[Q[xx] == 26, xx, Integers]
xx . mat . xxwithxx . mat[[1 ;; 5, 1 ;; 5]] . xxand replacexx = Array[x, 6];withxx = Array[x, 5];. – JimB Aug 17 '22 at 16:52