Twin Pythagorean Triple

Author

Eric W. Weisstein
December 21, 2004

This notebook downloaded from http://mathworld.wolfram.com/notebooks/DiophantineEquations/TwinPythagoreanTriple.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/TwinPythagoreanTriple.html.

©2005 Wolfram Research, Inc. except for portions noted otherwise

Code

TwinTripletQ[{a_,b_,c_}]:=(b-a==1||c-b==1)

TwinLegTriplet[r_Integer?Positive]:=Module[{a,c},a=Expand[((Sqrt[2]+1)^(2r+1)-(Sqrt[2]-1)^(2r+1))/4-1/2];
c=Expand[((Sqrt[2]+1)^(2r+1)+(Sqrt[2]-1)^(2r+1))/(2Sqrt[2])];
{a,Sqrt[c^2-a^2],c}]

TwinHypotenuseTriplet[u_Integer?Positive]:=Module[{v=u+1},{v^2-u^2,2u v,u^2+v^2}]

Counts

Length[trips=With[{max=10^3},
Map[Last,List@@(Reduce[x^2+y^2==z^2&&0<x<y<z<max,{x,y,z},Integers,Backsubstitution->True]/.And:>List),{2}]
]]//Timing

Length[trips=With[{max=10^4},
Map[Last,List@@(Reduce[x^2+y^2==z^2&&0<x<y<z<max,{x,y,z},Integers,Backsubstitution->True]/.And:>List),{2}]
]]//Timing

Take[twin=Select[trips,TwinTripletQ],20]

All Twins

Table[Count[Last/@twin,_?(#<10^n&)],{n,4}]

Leg-Hypotenuse Twins

lh=Select[twin,Subtract@@Rest[#]==-1&]

Table[Count[Last/@lh,_?(#<10^n&)],{n,4}]

Table[Floor[((Sqrt[2n-1])-1)/2],{n,20}]

Table[Floor[((Sqrt[2(10^n)-1])-1)/2],{n,6}]

Leg-Leg Twins

ll=Select[twin,Subtract@@Most[#]==-1&]

Table[Count[Last/@ll,_?(#<10^n&)],{n,4}]

Junk

Table[Length[Select[tw,#[[-1]]<100i&]],{i,9}]

Table[Length[Select[tw,#[[-1]]<1000i&]],{i,5}]

Solve[1+2u(1+u)==n,u]

Floor[Table[-1.5+0.5Sqrt[2N-1]+0.567Log[ N],{N,100,1000,100}]]

Floor[Table[-1.5+0.5Sqrt[2N-1]+0.567Log[ N],{N,1000,10000,1000}]]

Transpose[Table[TwinHypotenuseTriplet[r],{r,10}]]

Transpose[Table[TwinLegTriplet[r],{r,10}]]

tw1=Select[tw,#[[-1]]<5000&]