3

I'm trying to solve a Pythagorean pairs for m and n (for m and n < 100) which give integer p values in the following equation:

Sqrt[m^2 + n^2] == p     

I may do a trial and error using manipulate:

Manipulate[Sqrt[m^2 + n^2],
{{n, 1, "n"}, 0, 100, 1, Appearance -> "Labeled"},
{{m, 1, "m"}, 0, 100, 1, Appearance -> "Labeled"}]

I tried the following but failed to get any value

Solve[IntegerQ[Sqrt[m^2 + n^2]] == True && m <= 100 && n <= 100, {m, n}]
Out[]= {}

Any advice is appreciated.

iFikr
  • 347
  • 1
  • 3
  • 10

3 Answers3

7

Since m and n are interchangeable, reduce the duplicate cases by requiring m <= n

sol=Solve[{Sqrt[m^2 + n^2] == p, 0 < m <= n < 100}, {m, n, p}, Integers]

(*  {{m -> 3, n -> 4, p -> 5}, {m -> 5, n -> 12, p -> 13}, {m -> 6, n -> 8, 
  p -> 10}, {m -> 7, n -> 24, p -> 25}, {m -> 8, n -> 15, p -> 17}, {m -> 9, 
  n -> 12, p -> 15}, {m -> 9, n -> 40, p -> 41}, {m -> 10, n -> 24, 
  p -> 26}, {m -> 11, n -> 60, p -> 61}, {m -> 12, n -> 16, 
  p -> 20}, {m -> 12, n -> 35, p -> 37}, {m -> 13, n -> 84, 
  p -> 85}, {m -> 14, n -> 48, p -> 50}, {m -> 15, n -> 20, 
  p -> 25}, {m -> 15, n -> 36, p -> 39}, {m -> 16, n -> 30, 
  p -> 34}, {m -> 16, n -> 63, p -> 65}, {m -> 18, n -> 24, 
  p -> 30}, {m -> 18, n -> 80, p -> 82}, {m -> 20, n -> 21, 
  p -> 29}, {m -> 20, n -> 48, p -> 52}, {m -> 20, n -> 99, 
  p -> 101}, {m -> 21, n -> 28, p -> 35}, {m -> 21, n -> 72, 
  p -> 75}, {m -> 24, n -> 32, p -> 40}, {m -> 24, n -> 45, 
  p -> 51}, {m -> 24, n -> 70, p -> 74}, {m -> 25, n -> 60, 
  p -> 65}, {m -> 27, n -> 36, p -> 45}, {m -> 28, n -> 45, 
  p -> 53}, {m -> 28, n -> 96, p -> 100}, {m -> 30, n -> 40, 
  p -> 50}, {m -> 30, n -> 72, p -> 78}, {m -> 32, n -> 60, 
  p -> 68}, {m -> 33, n -> 44, p -> 55}, {m -> 33, n -> 56, 
  p -> 65}, {m -> 35, n -> 84, p -> 91}, {m -> 36, n -> 48, 
  p -> 60}, {m -> 36, n -> 77, p -> 85}, {m -> 39, n -> 52, 
  p -> 65}, {m -> 39, n -> 80, p -> 89}, {m -> 40, n -> 42, 
  p -> 58}, {m -> 40, n -> 75, p -> 85}, {m -> 40, n -> 96, 
  p -> 104}, {m -> 42, n -> 56, p -> 70}, {m -> 45, n -> 60, 
  p -> 75}, {m -> 48, n -> 55, p -> 73}, {m -> 48, n -> 64, 
  p -> 80}, {m -> 48, n -> 90, p -> 102}, {m -> 51, n -> 68, 
  p -> 85}, {m -> 54, n -> 72, p -> 90}, {m -> 56, n -> 90, 
  p -> 106}, {m -> 57, n -> 76, p -> 95}, {m -> 60, n -> 63, 
  p -> 87}, {m -> 60, n -> 80, p -> 100}, {m -> 60, n -> 91, 
  p -> 109}, {m -> 63, n -> 84, p -> 105}, {m -> 65, n -> 72, 
  p -> 97}, {m -> 66, n -> 88, p -> 110}, {m -> 69, n -> 92, 
  p -> 115}, {m -> 72, n -> 96, p -> 120}, {m -> 80, n -> 84, p -> 116}}  *)

ListPlot[{
  Tooltip[{m, n}] /. sol,
  Tooltip[{{0, 0}, {81, 81}}, "n = m"],
  Tooltip[{{0, 0}, {81, 81*4/3}}, "n = 4m/3"]},
 Joined -> {False, True, True},
 Frame -> True, Axes -> False,
 FrameLabel -> (Style[#, 14] & /@ {"m", "n"}),
 PlotLegends -> (TraditionalForm /@ {
     Sqrt[m^2 + n^2] == p, n == m,
     n == 4 m / 3})]

enter image description here

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
3

Perhaps something like this.

To get the leg pairs that satisfy the condition the hypotenuse is an integer:

pythagorus[k_Integer?Positive] :=
  With[
    {u = 
       Transpose[
         TakeDrop[#, 2] & /@ 
            Flatten[
              Table[{m, n, IntegerQ @ Sqrt[m^2 + n^2]}, {m, k}, {n, m}],
              1]]},
    Pick[u[[1]], Flatten @ u[[2]]]]

p = pythagorus[100]
{{4, 3}, {8, 6}, {12, 5}, {12, 9}, {15, 8}, {16, 12}, {20, 15}, {21, 20}, {24, 7}, 
 {24, 10}, {24, 18}, {28, 21}, {30, 16}, {32, 24}, {35, 12}, {36, 15}, {36, 27}, 
 {40, 9}, {40, 30}, {42, 40}, {44, 33}, {45, 24}, {45, 28}, {48, 14}, {48, 20}, 
 {48, 36}, {52, 39}, {55, 48}, {56, 33}, {56, 42}, {60, 11}, {60, 25}, {60, 32}, 
 {60, 45}, {63, 16}, {63, 60}, {64, 48}, {68, 51}, {70, 24}, {72, 21}, {72, 30}, 
 {72, 54}, {72, 65}, {75, 40}, {76, 57}, {77, 36}, {80, 18}, {80, 39}, {80, 60}, 
 {84, 13}, {84, 35}, {84, 63}, {84, 80}, {88, 66}, {90, 48}, {90, 56}, {91, 60}, 
 {92, 69}, {96, 28}, {96, 40}, {96, 72}, {99, 20}, {100, 75}}

To get the full triples:

triple[p : {a_, b_}] := {a, b, Norm[p]}
{{4, 3, 5}, {8, 6, 10}, ..., {99, 20, 101}, {100, 75, 125}}

Update

My brain wasn't working very well earlier today when I formulated the above. It can and should be expressed much more simply. Like so:

triples[n_Integer?Positive] :=
  With[{u = Flatten[Table[{i, j, Norm[{i, j}]}, {i, n}, {j, i}], 1]},
    Pick[u, IntegerQ /@ u[[All, 3]]]]
{{4, 3, 5}, {8, 6, 10}, {12, 5, 13}, {12, 9, 15}, {15, 8, 17}, 
 {16, 12, 20}, {20, 15, 25}, {21, 20, 29}, {24, 7, 25}, {24, 10, 26}, 
 {24, 18, 30}, {28, 21, 35}, {30, 16, 34}, {32, 24, 40}, {35, 12, 37}, 
 {36, 15, 39}, {36, 27, 45}, {40, 9, 41}, {40, 30, 50}, {42, 40,58}, 
 {44, 33, 55}, {45, 24, 51}, {45, 28, 53}, {48, 14, 50}, {48, 20, 52}, 
 {48, 36, 60}, {52, 39, 65}, {55, 48, 73}, {56, 33, 65}, {56, 42, 70}, 
 {60, 11, 61}, {60, 25, 65}, {60, 32, 68}, {60, 45, 75}, {63, 16, 65}, 
 {63, 60, 87}, {64, 48, 80}, {68, 51, 85}, {70, 24, 74}, {72, 21, 75}, 
 {72, 30, 78}, {72, 54, 90}, {72, 65, 97}, {75, 40, 85}, {76, 57, 95}, 
 {77, 36, 85}, {80, 18, 82}, {80, 39, 89}, {80, 60, 100}, {84, 13, 85}, 
 {84, 35, 91}, {84, 63, 105}, {84, 80, 116}, {88, 66, 110}, {90, 48, 102}, 
 {90, 56, 106}, {91, 60, 109}, {92, 69, 115}, {96, 28, 100}, {96, 40, 104}, 
 {96, 72, 120}, {99, 20, 101}, {100, 75, 125}}
m_goldberg
  • 107,779
  • 16
  • 103
  • 257
1

I think you mean you want to pick up all the {m,n,p} coordinates with the relationship Sqrt[m^2+n^2]==p when m<100,n<100.

Clear["Global`*"];
p[m_, n_] := Sqrt[m^2 + n^2];
list = Flatten[Table[{m, n, p[m, n]}, {m, 1, 100}, {n, 1, 100}], 1];
integerPythagorasPoint=Select[list, IntegerQ[#[[3]]] &]

Update

Now, we can visualize the distribution of the integer Pythagorean coordinates:

pythagorasPointPlot = ListPointPlot3D[list];
integerPythagorasPointPlot = Graphics3D[{Yellow, Point@integerPythagorasPoint}];
Show[pythagorasPointPlot, integerPythagorasPointPlot, ImageSize -> Large]

distribution of integer Pythagoras coordinates

PureLine
  • 1,310
  • 7
  • 20