3
$\begingroup$

I generated this text file containing tuples $(\sqrt{s}, \sqrt{t}, \sqrt{u}, s,t,u,t+u,t+u-s,t-s)$ where the six variables $s,t,u,t+u,t+u-s,t-s$ are all squares. An excerpt of the data set is:

153, 185, 672, 23409, 34225, 451584, 485809, 462400, 10816
264, 520, 975, 69696, 270400, 950625, 1221025, 1151329, 200704
264, 561, 952, 69696, 314721, 906304, 1221025, 1151329, 245025
306, 370, 1344, 93636, 136900, 1806336, 1943236, 1849600, 43264
357, 1325, 6960, 127449, 1755625, 48441600, 50197225, 50069776, 1628176
448, 952, 495, 200704, 906304, 245025, 1151329, 950625, 705600
459, 555, 2016, 210681, 308025, 4064256, 4372281, 4161600, 97344

My task is to iterate each line/row of this file and to try finding a solution $0<w<x<y<z$ of the following system of six diophantine equation:

  • $x^2-w^2=s\qquad z^2-w^2=t+u$
  • $y^2-w^2=t\qquad z^2-x^2=t+u-s$
  • $z^2-y^2=u\qquad y^2-x^2=t-s$

What I tried so far is running the following script with more relaxed conditions:

ClearAll["Global`*"]
arr = Import[
   "C:/Users/esultano/git/pythagorean/pythagorean_stu_Arty_.txt", 
   "CSV", "HeaderLines" -> 0];
f[i_] := Part[arr[[i]], 1 ;; 3];
len = Length[arr];
For[i = 1, i < len, i++, {
  triplet = f[i];
  s = triplet[[1]];
  t = triplet[[2]];
  u = triplet[[3]];
  (*Print[FactorInteger[s]];*)
  ins = FindInstance[
    x*x - w*w == s*s && y*y - w*w == t*t && w != 0, {w, x, y}, 
    Integers];
  If[Length[ins] > 
    0, {ins = 
     Join[First[ins], {"z" -> N[Sqrt[u^2 + First[ins][[3, 2]]^2], 20],
        "s" -> s, "t" -> t, "u" -> u}]; Print[ins]}, Continue];
  ins = FindInstance[
    y*y - w*w == t*t && z*z - y*y == u*u && w != 0, {w, y, z}, 
    Integers];
  If[Length[ins] > 
    0, {ins = 
     Join[First[ins], {"x" -> N[Sqrt[s^2 + First[ins][[1, 2]]^2], 20],
        "s" -> s, "t" -> t, "u" -> u}]; Print[ins]}, Continue];
  }
 ]

It gives me "almost" solutions, for example $(w,x,y,z)=(40579,58565,65221,196605.2940)$. It seems not to be possible to combine the conditions such for example:

ins = FindInstance[x*x-w*w==s*s && y*y-w*w==t*t && z*z-y*y==u*u && w > 0, {w, x, y, z}, Integers]

Is there a way to let Mathematica solve such a system of diophantine equations?

The background is a quite inteersting problem, namely a search for four squares as described here at this MSE post - an extended version of Mengoli's Six Square Problem. It would be great if Mathematica can solve the above shown system of these six diophantine equations.

$\endgroup$
11
  • $\begingroup$ Mathematically interesting problem of finding 4-tuples. UpVoting this question, as it will be useful for the whole world of Math. $\endgroup$
    – Arty
    Commented Jan 25, 2022 at 8:01
  • 1
    $\begingroup$ Yes, it often happens that bigger values may give some solution. For example after many distributed (on cluster) CPU-years of computation just recently mathematicians found solution 42 = (-80538738812075974)^3 + 80435758145817515^3 + 12602123297335631^3, i.e. represented 42 as sum of cubes. To remind, 42 was the Ultimate Answer to Meaning of Life according to Hitchhiker's Guide. It is a good example when in small numbers solution doesn't exist but start existing from 20 or 30 digit numbers size. $\endgroup$
    – Arty
    Commented Jan 25, 2022 at 10:26
  • 1
    $\begingroup$ BTW, regarding my comment above - informal description of 42 as cubes finding is here which also includes 3 as sum of cubes which is 569936821221962380720^3 + (−569936821113563493509)^3 + (−472715493453327032)^3 = 3. Probably their distributed search was registering all found answers below 1000. $\endgroup$
    – Arty
    Commented Jan 25, 2022 at 10:55
  • 1
    $\begingroup$ Would be more accommodating if rather than post a link to the data you simply posted some examples of the data such as the first 10 lines of the file. $\endgroup$
    – josh
    Commented Jan 25, 2022 at 13:32
  • 1
    $\begingroup$ @EldarSultanow Now that you have an accepted answer, have you found any solutions for your large data set? If so, I would appreciate seeing a few here. Thanks. $\endgroup$
    – bbgodfrey
    Commented Jan 26, 2022 at 13:30

1 Answer 1

2
$\begingroup$
ClearAll["Global`*"]

arr = Cases[
   Import[
    "/Users/roberthanlon/Downloads/data.txt", "CSV"],
   {_Integer ..}, 1];

Length@arr

(* 27060 *)

Verifying that every line of arr matches the template {Sqrt[s], Sqrt[t], Sqrt[u], s, t, u, t+u, t+u-s, t-s}

And @@ ((repl = Thread[{s, t, u} -> #[[4 ;; 6]]];
     # == ({Sqrt[s], Sqrt[t], Sqrt[u], s, t, u, t + u, t + u - s, t - s} /.
              repl)) & /@ arr)

(* True *)

Since there are more equations than variables, the Solve option MaxExtraConditions must be used.

sol[s_Integer?Positive, t_Integer?Positive, u_Integer?Positive] :=
 Solve[{
   x^2 - w^2 == s, z^2 - w^2 == t + u, y^2 - w^2 == t,
   z^2 - x^2 == t + u - s, z^2 - y^2 == u, y^2 - x^2 == t - s,
   0 < w < x < y < z}, {w, x, y, z}, Integers,
  MaxExtraConditions -> All]

There are no solutions for the first 20 lines of arr

at = AbsoluteTiming[
  arr2 = Select[arr[[1 ;; 20]], Length[sol @@ #[[4 ;; 6]]] > 0 &]]

(* {2.05478, {}} *)

It would take about 50 minutes to run through the data (assuming that nothing else is competing for processing time).

Length[arr]*(at/20)/60

(* 46.3353 *)
$\endgroup$
5
  • 1
    $\begingroup$ BTW, does Mathematica Guarantee that for each (s, t, u) line in data file it finds exactly ALL possible solutions for system? In other words does it search symbolically all Infinite space of possible (w, x, y, z)? Or it finds them until some limit, for example 2^64 at most? $\endgroup$
    – Arty
    Commented Jan 25, 2022 at 17:34
  • 1
    $\begingroup$ In general Solve can miss solutions for some problems. If you want more rigor, use Reduce $\endgroup$
    – Bob Hanlon
    Commented Jan 25, 2022 at 17:38
  • 1
    $\begingroup$ Have you obtained a few solutions that you could share? $\endgroup$
    – bbgodfrey
    Commented Jan 25, 2022 at 17:46
  • $\begingroup$ @bbgodfrey - As shown, I only tested the first 20 lines and found no solutions. $\endgroup$
    – Bob Hanlon
    Commented Jan 25, 2022 at 17:49
  • $\begingroup$ My code above has a relaxed condition and it found some "almost" solutions, for example [w=67375, x=-89425, y=−114695, z=196769.2970]. See here the MSE Post that describes the mathematical motivation and provides some "almost" solutions. $\endgroup$ Commented Jan 25, 2022 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.