Simultaneously Square Sums of Mostly Squares

Background

This problem is one of a family of related problems:

a2+b2+c2=d2
The well-known Pythagorean Quadruples problem.
a2+b2+c=d2 for all (a,b,c) permutations
This is what you are here for!
a2+b+c=d2 for all (a,b,c) permutations
A surprisingly simple Asia-Pacific Mathematical Olympiad 2011 question as solved in Perfect Squares are Impossible - APMO 2011.
a+b+c=d2
Wat? That's not a problem.

Exposition

So we're looking for triples of positive integers a,b,c where all of three permutations of the not-quite-sums-of-squares a+b2+c2, a2+b+c2, and a2+b2+c are perfect squares.

The fully generic problem is the most interesting one, but there will be interesting - or boring, depending on your point of view - sub-families of results where two or even three of the variables are equal.

If there was nothing special about the distribution of solutions in ℤ3, then the "volume" of the search space for each of these classes is incomparable. The a=b=c case is just a line, the a=b and b=c cases are planes, and the generic case is the full rest of the solid region. One might therefore expect almost none of the solutions to be the special cases, but those special properties might enable them to have an unexpected density to their solutions.

Of course, the solutions where these planes intersect is precisely the set of solutions along the diagonal; and of course, the solutions on the planes are precisely the intersection of the planes with the solutions to the generic version of the problem. There is only one problem being solved, we're just slicing it different ways.

a=b=c

Note that the a=b=c case is a simple quadratic diophantine equation 2·a2+a=d2, expressable as a pell equation (4·a+1)2-2·(2·d)2=1. The infinite family of solutions for this equation is known, they are derived from the subset of the solutions to the classic Pell's Equation x2-2·y2=1, with x restricted to numbers of the form 4a+1, and y even. This restriction gives them more in common with the approximants to √32, than those of just √2. This gives them a known density, they grow, and thus thin out, exponentially. They are marked up thusly in the results table.

a=b xor b=c

The a=b and b=c cases (by symmetry, these are the same case, but I've ordeded a,b, and c, so they superficially fall into two subfamilies: one-small-two-big, and two-small-one-big) also have a well-studied algebraic property, based on a similar substitution as performed above. a2+a+c2=d2 is precisely 4·a2+4·a+1+4·c^2=4·d^2+1, so (2·a+1)^2+(2·c)^2=(2·d)^2+1, so this is an instance of the "x2+y2-z2=1" problem, the hyperboloid of one sheet, with solutions as documented out there in internet land.

Of course, our solutions also need to satisfy 2·a2+c=f2, so are a very small subset of the solutions to that simpler problem. Some proper mathematician needs to have a look at this, I don't have the chops.

a≠b≠c

No clue - if you can extract anything from the known solutions, or hit this with actual maths, drop me a note. The solutions a≠b≠c are higlighted thus in the table of results.

One thing's certain - this is tractible, and the right mind will probably solve it easily. In fact, it seems Diophantus would have solved it, as he solved a harder problem, Diophantus Problem III.19 (page 8).

Results

abc √(a+b2+c2) √(a2+b+c2) √(a2+b2+c) Notes
444 6 Baudhayana's x=17, y=12
242473 7735
31135135191139 
144144144 204 Baudhayana's x=577, y=408
6363162 17490
137224224317263 
136136257 291193a2+b2+c2=3212 - spooky!
4848292 29670
68304304430312 
160240321401359289
388516516730646 
3763761337 1389533
4954951351 1439701
9359351879 20991323
9599592087 22971357
60717913534396235861892
30434494352555343633463
36494864486468796081 
490049004900 6930 Pell x=19601, y=13860
8688686052 61141230
51386467646791468260 
192172407240102397491 
142487208720123328836 
3363369433 9439485
27615856976811389101516475
8439843910783 1369311935
969712208122081726515591 
2480248012281 125293509
123060511547516616155246176
1859185915662 157722632
141801418018116 2300620054
5430959523751256162436411026
155991559930119 3391922061
167121671231337 3551523635
198762403631428395663718631190
111921119235513 3723515829
144770343889139522389187184
9088908841828 4280412854
284015430464872846017081761283
155061797083571104708526376
2671783757837511083978421 
285482854883268 8802640374
40804080138724 1387845782
2382823828142832 14480633700
44884488152593 1526596359
34007155311155311219643158991 
171605004116012816776516104552903
166075347116377417228216461455992
106948163968163968231886195764 
107635148515164274221456196396183418
166464166464166464 235416 Pell x=665857, y=470832
1158311583169218 16961416386
93103184431184431260825206599 
51845184186624 1866967344
2627926279214207 21581337167
83417220048220048311195235329 
123112129041221576256413253481178349
1283112831225982 22634618152
3674336743265127 26766151965
53045304270529 2705817519
141855141855294946 327286200614
3532035320297409 29949949953
27936257076298228393736299534258590
4248442484306544 30947460084
1640016400320000 32042023200
76708350336350336495450358636 
4739947399360823 36392367035
55715571369522 3695647902
191552379456379456536632425064 
52365236403232 4032667432
7806478064404609 412071110401
2575125751406927 40774136423
110768110768436153 449999156651
85688568436977 43706112135
1434414344467537 46775720297
236340236340512496 564366334236
77796197860514020550786519874212606
73731288003544894616324549860297292
2883128831555278 55602640780
130400130400572225 586895184415
54594586719586719829746589254 
446761595680595680842419744601 
343519658119658119930721742379 
2339123391670338 67074633090
1591115911695447 69562922517
4388735912328818081061669984985736319
4217678986238986231270845992679 
56614256775100151510339081003114262944
346040737033102593612632351082723814225
70161250264117160811980391173707259915
4307874307871440338 1503380609226
518017606856146466415854071553571797883
4343844343841543057 1603033614313
215379534291165857817425121672504576070
89540169856167192016805261674316192016
3478433478431684178 1719724491926
76255910433431707351200090318699051292309
291744355608170964117462331734355459971
272648563081198869620668752007299625619
5068805068802049444 2111196716838
6285116285112168258 2257514888850
22419224192204478 220459231740
339766473447223493922845362260618582748
8235368235362841057 29580091164657
2759842759842875904 2889116390304
4150794150793109687 3137267587013
29524295243572464 357258641796
287024920260390808040149683918606963984
11808118084357513 435752916829
149497514949754564975 48035352114215
24925614803920480392067937695412071 
782478245101897 510190311293close to axis
77979610740365212912532240652709141327268
121551912155195311303 54486171719005
152543835394875409087646422456200703854210
545731254573125487337 77390657717805close body-diagonal
42099525613268561326879383607016586 
105331210533125613412 57113801489610
565488456548845654884 7997214 Pell x=22619537, y=15994428
181286418128645868292 61419322563778
46484751398796106399798163361240675160857
81350311039036161207625931962146811371275
1668031668037046482 7048456235910
51935519357173566 717375473496
1431041431047440772 7442148202398
30600306007803225 780328543365
20708207088246948 824697429426
8309038836678783667871183242411791660 close body-diagonal
2002642002648459969 8462339283231
6971836971838569922 8598234985970
684603568460358801086 111502169681756
811737695936889728081135535590094517006549
863475586347559066494 1252039612211388
39984399849516388 951647256630
7699923769992310109038 1270753610889336
278608761741871033356212037570107025606773690
98828342477981042560711257756104723444361250
3312991331299111205122 116846344685278
1907156190715611431712 115897062697128
2126164212616412240112 124234023006852
39648828190331227272812592331122791312846781
265684149265841314728814040029134130535597325
94132817472161316136013276828131949801984660
91037619848411457556814710091146039712183665
1488841714991896149918962120174321128699 closest body-diagonal
90713690713615307108 153339641282890
152598641525986416022857 2212680321580707
111184831111848317245522 2051898415723910
313184261257911735347118402942176338146879954
4051399405139918192623 186382775729545
114764361147643618213232 2152743416230132
1861524186152418494064 185875142632596
20838218580099185800992627622818581268 close face-diagonal
1449968144996818821713 188774812050569
1799343179934318962983 190481592544659
22239341543647920402367255840082052321815595858
1994368199436821018308 211127162820466
1474599147459921250807 213019072085403
2240959224095921483842 216004023169198
1833872183387222542313 226167852593491
20067920067922726567 22727453283843
106150781073159122822635252198282517047015094600
1011188101118823499248 235209941430044
25411625411625665188 25666446359410
18825518825525680911 25681601266281
50240801718205625879905310643292636305917901521
2390344127159320271593203840907936180149 
177435921774359227521513 3274551525093229
9783808978380828634297 3025964113836395
22136822136829663033 29663859313109
1414336931675440316754404479583734689601 
69660361115224032486580343474943322504413149074
29409929409932614162 32615488415958
1711600171160034210625 342534152420575
25441673531673135445254500363623553644435408252
199078886948523585965236898714359148708919850
217321043368723338772824513630374444790540088827
15621530457193962025539737149396205633049729
77514501891301939706855439810944045638820439846
57260791398793540923010432476024132167415114574
43925841447896141307032437711234153992915130603
75969442445116941741528483757674242721725604165
2055695205569542159551 422096392907199
52993591485078342540706450583784286951015767974
3684562589588145050912519632694505241925898503
82863982863945675022 456825381171892
4074436949638584496385847019955964219099 
691836918349857858 4985790698094
2344212234421250368288 504228103315224
783287832852890953 52891011111011
136638417539295307038453099359530879712223359
148293113920783953576258663902865559068241918530
87628887628856079073 560859191239281
9194824919482457099857 5783544313003447
30409530409560837826 60838586430126
268277664828761162823047792365366831152455239682
1678520167852062911601 629339892373799
2222879863854483638544839030387667612976 
197321693746192864388744744936676734440542340933
127050252874920065188616712465596641515931431421
3192384319238465471488 655492724514720
305876473058764766747938 7342269043257466
2268895226889570074319 701110413208713
144740794588428670387807840226827186057648113062
44024112437064673637863775658647376934424765090
166091125548828176542616945395237832390957920739
159467914284644778910231897922198050543345717811
190528125477288233774482377151823597853181367
59240395148945184935962993241228514230451829122
158956001589560085330625 8679853522479775
40844864870250408702504012307199296133556 
1912464191246489110609 891311292704649
1625745656622265920982001081117919352210158909981
139249441392494492159137 9320520719692847
143640631436406393225087 9432519920313855
804961038049610395446543 124858581113838681
329452083294520896090193 10158106146591561
63743963743997580399 97582481901529
210103512101035198979223 10118459129713125
15267800222634409921472910168197110038260926995677
8510939188982983103053519136154321133654915123132367
91335479107130335107130335151505173140780249 
902312902312110080337 1100840351276105
2546150425461504124212004 12679475636008006
592525626241032312799720314240201014104662486057624
372824372824133139689 133140211527379
6187390461873904141094793 15406531387502915
5830917558309175149125879 16012022982461627
7963217594643231150786895178028169170522641123687609
187120712928967015675103515946401415786395634756676
148104148104166173777 166173843209847close to axis
25833032583303167043607 1670635813653365
92170994167950915167950915237518462191580276 
5191765551917655172160359 17981833173422653
39242287179228279179228279253467063183474067 
391686875825175118842751919722625719245549170195817
192099600192099600192099600 271669860 Pell x=768398401 y=543339720
83425212128486419776651219890861919794239322861393
191706322200127891200127891283023578277132616 
70034088139300264202539921245819005214306307155914519
3537627535376275211000850 21394588050029610
1862185518621855216078606 21687954626335284
49907194990719218855842 2189127387057958
2421489161484624227324344278843399227337241161502779
2678872426788724242504048 24397919837884980
4200138442001384250516129 25401269159398929
201302654253493855253493855358494448323700314 
209668209668255586468 255586554296946close to axis
160585505253114160259250504362322511304956601299757373
8373038783730387265682962 278564560118412650
37541963754196266534768 2665612065309260
2849922328499223267320623 26883549140303991
269060269060278436676 278436806380874close to axis
1975752819757528276252593 27695821927941369
11531551759769428450547528504919628450781217635444
3985568339855683289009522 29174471656364450
279344279344295580804 295580936395426close to axis
26528842652884296147744 2961596263751784
5665682994861129967597129984106229972952411448804
176701744277988096301426148410042808349401244329394730
48909474890947310148338 3101869006916866
87656304304657300326501460446563852338063354317016874
22521722197659399330082619384738578330850062198938348
8820739188207391335874338 347263754124744090
181739248181739248340761092 386195904257018110
1605699116056991343204322 34357973422708022
112580112580352065796 352065814160314closest to axis
4774168047741680358315556 36148209667516934
360440360440360881449 360881629510093
186528555336694230367945639498745424412525024384910258
133449304263024289389157144469707419411402479294941509
7074038370740383390950743 397299239100042011
6591122465911224392721049 39821365193212549
61506479100295911397206767409673633401940621117653377
33844793384479401067842 4010821224786418
88519204404286960404286960571748102413864224 
4941843549418435418175726 42108564469888224
228532228532421186288 421186350323844close to axis
330790679330790679422520143 536605763467808665
50785519430183215430183215608370937433170599 
80617328328786049449290336556742375456465727338525361
247085696247085696453146417 516132751349431943
75495296185407204458730368494782156464901162200188340
5604354456043544474236977 47753700379257543
380024577478552536478552536676775487611090181 
35695683569568479802793 4798160715048179
70792494452957251481066563660753592486247484458455940
2353484823534848517223273 51775844133283309
88797758879775546625150 54669727012557920
27045233564461264564461264798268775565108807 
130642831130642831581239103 595740249184756865
gaps here: 580000000-590000000 reserved for inz
gaps here: 590000000- not yet reserved

Code

Multi-threaded C

All-round guru Robert Gerbiecz from the Mersenne Forum completely reorganised Inz' C code to utilise a small-prime sieve to filter out large swathes of impossible search space. It seems to provide a ~5x improvement over the original C (still being tested).

Inz converted the GP code into a multithreaded C program at something like 100x speedup, or something absurd like that. Compile it with:

gcc -Wall -Wextra -O3 -o sssms2 sssms2.c -lm -lpthread
Run it with the range start, range end, and optional number of threads. Note - this is out of date code there's about a 3x speedup available from just naive incremental improvements.

Pari/GP Script

Here's a script that will search the range 1≤c≤b≤a≤5000. Those bounds being the first two numbers in the outermost 'for' command:

f2=[\
        19,1,0,0,17,0,0,0;\
        1,0,0,0,0,0,0,0;\
        0,0,0,136,0,0,0,136;\
        0,0,136,68,0,0,136,68;\
        17,0,0,0,17,0,0,0;\
        0,0,0,0,0,0,0,0;\
        0,0,0,136,0,0,0,136;\
        0,0,136,68,0,0,136,196\
  ]
  for(a=1,5000,\
      a8=a%8;\
      for(b=1,a,\
          b8=b%8;\
          f3=f2[1+a8,1+b8];\
          if(f3,\
             a2b2=a*a+b*b;\
             mrc=floor(sqrt(a2b2+b));\
             for(rc=sqrtint(a2b2-1)+1,mrc,\
                 c=rc*rc-a2b2;\
                 if(bittest(f3,c%8)&&\
                    issquare(a*a+b+c*c)&&\
                    issquare(a+b*b+c*c),\
                    print(c" "b" "a)\
                 )\
              )\
          )\
    )\
)

As one-line commands:

f2=[19,1,0,0,17,0,0,0;1,0,0,0,0,0,0,0;0,0,0,136,0,0,0,136;0,0,136,68,0,0,136,68;17,0,0,0,17,0,0,0;0,0,0,0,0,0,0,0;0,0,0,136,0,0,0,136;0,0,136,68,0,0,136,196]
dorange(lo,hi)=for(a=lo,hi,a8=a%8;for(b=1,a,b8=b%8;f3=f2[1+a8,1+b8];if(f3,a2b2=a*a+b*b;mrc=floor(sqrt(a2b2+b));for(rc=sqrtint(a2b2-1)+1,mrc,c=rc*rc-a2b2;if(bittest(f3,c%8)&&issquare(a*a+b+c*c)&&issquare(a+b*b+c*c),print(c" "b" "a))))))

which, if saved as sssms.gp, can be invoked thus:

echo 'dorange(1,5000)' | gp sssms.gp

or even:

echo -e '#\ndorange(1,5000)' | gp sssms.gp

I ran with the '#' directive in GP before those lines to turn on timing, so I could have a comparison of how quickly different versions of the code ran on different boxes. With my little box (a 1.5GHz Celeron, yup, in 2021) the above 1-5000 took time = 13,949 ms. Bands of 10000 at higher ranges are starting to take many hours. There's an argument for either using C or some more mathematical smarts to solve this.

Improvements Over Brute Force

Restrictions Modulo 8

The 8×8 array is a set of bitmasks of valid residues mod 8 that the third variable can have given the residues mod 8 that the other 2 variables have. This is particularly useful as squares can only be 0,1,and 4 (mod 8), and to get the 3 sums to all be simultaniously from those valid values discards many b and c values. Only 36 of the 8×8×8=512 possibilities are permitted. It even throws away 1/8 of the a values - those 5 mod 8, hence the immediate rejection of such values in the C code. There's no need to immediately reject b==5 (mod 8) separately, that's part of the test on f2[a&7][b&7].

Restrictions Modulo 3

None implemented so far, but it appears not all (a,b,c) triplets mod 3 are admissible either (not surprising, -2 isn't a square mod 3 so you'd expect only (2/3)3=8/27 of the candidates to survive such a test:

$ perl -pe 's/(\d+)\s+(\d+)\s+(\d+).*/($1%3)."\t".($2%3)."\t".($3%3)/e' < squaresums.list  | sort | uniq -c
     18 0	0	0
     42 0	0	1
      9 0	1	0
     20 1	0	0
     17 1	1	1
     19 1	1	2
      2 1	2	1
      8 1	2	2
      6 2	1	1
      5 2	1	2
     18 2	2	1
     43 2	2	2

So (000), (100)*, (111), (112)*, (122)*, and (222) are fine.

Therefore a==0 (mod 3) lets you reject b==2 (mod 3), and by symmetry, a==2 (mod 3) lets you reject b==0 (mod 3). a==1 (mod 3) brings no immediate gains.

Fin

Thanks to inz, boru, janrinok, and chromas from SoylentNews for letting me run the scripts/program on way bigger boxes than anything I have access to at home. And extra thanks to inz for converting the GP into C.