# Wolfram Function Repository

Instant-use add-on functions for the Wolfram Language

Function Repository Resource:

Finds the position of a primitive Pythagorean triple in Barning-Hall tree

Contributed by:
Shenghui Yang

ResourceFunction["BarningHallTreePosition"][ finds the position of the primitive Pythagorean | |

ResourceFunction["BarningHallTreePosition"][ creates a pruned tree from root node to the primitive Pythagorean | |

ResourceFunction["BarningHallTreePosition"][ also includes Fibonacci matrices in the labels. |

A primitive Pythagorean triple (*a*,*b*,*c*) is defined as a leg of odd length, leg of even length and hypotenuse of odd length in an integral right triangle. The greatest common divisor of the three numbers (*a*,*b*,*c*) is one.

The Fibonacci matrices in the nodes of the Barning-Hall tree are of the form .

Given the parent node , the three child nodes are in this order: , and .

The root node associated with (3,4,5) is and is defined by setting *a*=1 and *b*=1.

The corresponding Pythagorean triple for each node matrix is (*a*×*c*,2*b*×*d*,*a*×*d*+*b*×*c*).

The algorithm effectively uses a reverse formula of the Fibonacci matrix generation to find the parent node of the input iteratively.

The list returned by this function uses the same convention as TreePosition.

Given a primitive Pythagorean triple, find its position on the Barning-Hall tree:

In[1]:= |

Out[2]= |

See the tree:

In[3]:= |

Out[3]= |

Use "PathWithFibonacciPythagoreanPair" to show the tree withFibonacci matrices from the root node to the target:

In[4]:= |

Out[5]= |

Use "PathWithPythagoreanTriple" to show the tree from root node to the target with Fibonacci matrices:

In[6]:= |

Out[8]= |

BarningHallTreePosition with "PathWithFibonacciPythagoreanPair" automatically aligns the Pythagorean triples vertically in the node to minimize the width of each node as the triples grows rapidly:

In[9]:= |

Out[11]= |

"PathWithPythagoreanTriple" saves raw data therefore no automatic formatting implemented:

In[12]:= |

Out[14]= |

Use TreeMap and Column or TableForm function to convert the tree into more compact and legible form:

In[15]:= |

Out[15]= |

BarningHallTreePosition properly handles the display of gigantic Pythagorean triples with deep tree levels using the Format function internally. Together with TreeExtract and TreeElementStyle we can create a neat subtree. Specify a Pythagorean triple with huge values:

In[16]:= |

Each number is close to 170 digits:

In[17]:= |

Out[17]= |

The path on the tree has 300 levels of depth and would not be a useful visualization:

In[18]:= |

Out[20]= |

Take the last three levels including the target input on the tree:

In[21]:= |

Customize the coordinate for the tree nodes to arrange the sibling, parents and grandparent node for the input:

In[22]:= |

Out[22]= |

The input must be Pythagorean triple. For instance {5,12,14} is not Pythagorean. The function returns unevaluated:

In[23]:= |

Out[23]= |

The Pythagorean triple must be primitive. For instance {5,12,13} with GCD[5,12,13] = 1. {10,24,26} is Pythagorean but not primitive. The input yields unevaluated form:

In[24]:= |

Out[24]= |

The function uses canonical primitive Pythagorean triple notation as it is compatible with its intermediate triples. Changing the sequence of the input results in an unevaluated result:

In[25]:= |

Out[25]= |

Schinzel’s hypothesis H implies that there are infinite number of primitive Pythagorean triples with two primes. This requires that both odd leg *a* and odd hypotenuse being prime number and the length of the even leg is one less than that of the hypotenuse. Let's take a look at the example:

In[26]:= |

Out[27]= |

Solve for the Pythagorean equation and notice that *b* is one less than *c*:

In[28]:= |

Out[28]= |

Actually, given such *c*, the other two variables are determined in this Diophantine equation:

In[29]:= |

Out[29]= |

For other cases, we choose prime *p* such that is also a prime number:

In[30]:= |

Pick 5 elements and we can check the location of the triples on the tree with obvious pattern:

In[31]:= |

Out[31]= |

For instance, we can visualize the {11,60,61} on the B-H tree:

In[32]:= |

Out[33]= |

The number of 3's in each position for primitive Pythagorean triple with two primes defines an interesting sequence. The sequence is A068501 with each term minus one:

In[34]:= |

Out[35]= |

Plot the curve of the sequence:

In[36]:= |

Out[36]= |

Notice that the tree position of repeating 3's is *just a necessary condition* for Pythagorean triple to have 2 primes. (7,24,25) is at {3,3} and 25 is not prime. In fact, the tree position of repeating 3's is *sufficient and necessary condition* for primitive Pythagorean triple with (*a*,*c*-1,*c*) form in our Barning-Hall tree convention. Those triples with two primes are strictly in the subset of the (*a*,*c*-1,*c*) cases.

- Prime numbers and Pythagorean triplets - Stack overflow
- Schinzel's hypothesis H - Wikipedia
- A068501 - OEIS
- A048161 - OEIS

Wolfram Language 13.0 (December 2021) or above

- 1.0.0 – 30 July 2024

This work is licensed under a Creative Commons Attribution 4.0 International License