Message Boards Message Boards

0
|
5386 Views
|
5 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How do I cross reference a set of rules against pythagorean triples?

Posted 9 years ago

I used the following code to generate a list of pythagorean triples followed by the difference of a and b:

Do[Print[m^2 - n^2, ",", 2 m n, ",", m^2 + n^2, ";", 
  m^2 - n^2 - 2 m n], {n, 100}, {m, n + 1, 100}]

I want to be able to check if a certain list of rules apply to any four sets of triples. For example to generate a list of triples of which a^2+b^2=c^2 applies, which would be all of them, except I have a series of rules of all which would need to be met to qualify. I have no clue as to how to do this. If more information is required, demand and I will supply. (Note that if required, I do have excel available if I need to import it into a table & that I am an absolute newbie to mathematica)

Thanks in advance!

Update:

The rules are the following:

a12+b12=c12

a22+b22=c22

a32+b32=c32

a42+b42=c42

a1=b4

b1=a2

b2=a3

b3=a4

a1+b2=L

b1+a4=L

a2+b3=L

a3+b4=L

When all values for a, b, c, and L are whole numbers. Obviously we’re using m & n to determine the triplets and not a, b, and c, but do I need to define a, b & c from the table? What you gave me is really helpful, but I don’t know how to test with different triples simultaneously. Sorry if I’m incoherent. Thanks once again!

P.S.

the last four equations/rules just want to determine that a+b is an integer, otherwise L doesn’t matter

Here I make an array (still have zeros, haven't thought a way around that for this one yet):

PythagArrayAn = Array[
  If[#3 == 1, 1, 0] (#1^2 - #2^2) +
    If[#3 == 2, 1, 0] (2 #1 #2) +
    If[#3 == 3, 1, 0] (#1^2 + #2^2) + 
    If[#3 == 4, 1, 0] (#1^2 - #2^2 - 2 #1 #2)
   &, {10, 10, 4}, 1]
(*Pardon The Pun*)

Here is the code that was generously given by Sean Clarke (I only added in Abs[ ] aka absolute value to find the distance between a & b):

    generateValues[m_, n_] := {m^2 - n^2, 2 m n, m^2 + n^2, 
       Abs[m^2 - n^2 - 2 m n]};
    Table[generateValues[m , n], {n, 1, 20}, {m, n + 1, 20}] 
(*Makes a table of generated pythagorean triplets*)

and

    isItPythagorean[list_] := (list[[1]]^2 + list[[2]]^2 == list[[3]]^2);
    Table[isItPythagorean[generateValues[m, n]], {n, 1, 20}, {m, n + 1, 
      20}] 
(*This simply is testing if it is pythagorean or not as an example as how one might test if a rule applies. Thanks Sean!*)
POSTED BY: Jeffery Cole
5 Replies
Posted 9 years ago

Hi Jeffery

Let me see if I am reading this right, you want to generate a set of PT and from this set you want to find 4 PT's that meet a criteria using those rules. I am assuming its only 4 from the description of your rules.

If I can now make a few observations, first if we are generating PT's then we don't need to use the first 4 rules as they are by definition PT's, secondly we don't need to use the last 4 rules either as all PT's generated will have Integer lengths ( assuming you do not use fractional lengths to generate the PT's in the first place. and so really all you are wanting to check are that from this sub list of 4 PT's a1 = b4 etc.

This now brings me to the method of generating the PT's, It is my experience that using the (m n) method to generate them isn't the best way, you don't have any real control over what PT's you are going to end up with and you certainly can't guarantee that you have found all PT's that have a certain say minimal length side. I like to use a method I developed quite some time ago that will generate all PT's with a small side of any length and is easily adapted to generate all PT's below a given length.

Finally regarding choosing 4 from a list can become a huge task considering that there are an infinite set of PT's and choosing any 4 of those can be memory hungry unless we restrict out list considerably, so here is a method that could be what you are looking for.

However I also have to point out that using your rules won't find anything no matter the size of list of PT's. If our list is sorted in size order of small side then choosing 4 PT's a1 can never equal b4. The only way it could work is if you allow duplicates where a and b also appear as b and a like {3, 4, 5} and {4, 3, 5}, but that is the same PT.

The following code will generate the PT's and then make a sub list of sets of 4 and look for matches where you can see how the testing is done. Hope this helps you some way. but correct me if this isn't what you are trying to do.

Column[t = 
  Table[t = Select[Divisors[n^2], # <= n &]; 
   r = Reverse[Select[Cases[(n^2 - t^2)/(2 t), _Integer], # > n &]]; 
   Table[{n, r[[s]], Sqrt[n^2 + r[[s]]^2]}, {s, 1, Length[r]}], {n, 3,
     20}]]


ptlist = Partition[Flatten[t], 3]


sublist = 
 Cases[Subsets[
   ptlist, {4}], {{a_, b_, c_}, {d_, e_, f_}, {g_, h_, i_}, {j_, k_, 
     l_}} /; a == k && b == d && e == g && h == j]

Paul.

p.s. changing the #>n to n>0 in this line r = Reverse[Select[Cases[(n^2 - t^2)/(2 t), _Integer], # > n &]]; will generate the duplicates.

POSTED BY: Paul Cleary
Posted 9 years ago

Thanks!

Yes I believe this is what I want. However I am having trouble understanding it (extremely new to mathematica). I put the excessive rules just to be careful so as to avoid confusion, sorry if they had the opposite effect. Is it possible that you could give me the same code with step by comments explaining what is happening? Sorry if I’m asking too much.

Thanks anyway!

POSTED BY: Updating Name

Oops! The last four matter some because

a1 + b2 = b1 + a4 = a2 + b3 = a3 + b4

POSTED BY: Jeffery Cole

When you're starting off, avoid using Print or Do. Print just causes something to appear on the screen. You don't want to use print. You almost never want to actually use Print in Mathematica. You want to return the actual values so that you can use them for later. Instead of these, let's use Table:

Let's break your code down into some simpler pieces. This will make it easier to maintain and understand. Here's a function that generates a list of the values you are interested in:

generateValues[m_, n_] := {m^2 - n^2, 2 m n, m^2 + n^2,  m^2 - n^2 - 2 m n};
Table[generateValues[m, n], {n, 1, 5}, {m, n + 1, 5}]

Now let's make a function that returns True only when the first three elements of a list satisfy a^2+b^2=c^2.

 isItPythagorean[list_] := (list[[1]]^2 + list[[2]]^2 == list[[3]]^2)

Let's test that it works:

isItPythagorean[{3, 4, 5}]
True

We can apply it inside the Table:

Table[isItPythagorean[generateValues[m, n]], {n, 1, 5}, {m, n + 1, 5}]
{{True, True, True, True}, {True, True, True}, {True, True}, {True}, {}}
POSTED BY: Sean Clarke

Thank You Soo Much! You have been extremely helpful. :-)

However the rules that I am using are to find multiple triplets (Sorry for not being clear enough in the original post).

The rules are the following:

a12+b12=c12

a22+b22=c22

a32+b32=c32

a42+b42=c42

a1=b4

b1=a2

b2=a3

b3=a4

a1+b2=L

b1+a4=L

a2+b3=L

a3+b4=L

When all values for a, b, c, and L are whole numbers. Obviously we’re using m & n to determine the triplets and not a, b, and c, but do I need to define a, b & c from the table? What you gave me is really helpful, but I don’t know how to test with different triples simultaneously. Sorry if I’m incoherent. Thanks once again!

p.s.

the last four equations just want to determine that a+b is an integer, otherwise L doesn’t matter

POSTED BY: Jeffery Cole
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract