Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Determine whether a triple of integers constitutes a Pythagorean triple
ResourceFunction["PythagoreanTripleQ"][{a,b,c}] determines whether the triple of integers {a,b,c} satisfies a2+b2=c2. |
The ordered triple {3,4,5} is a Pythagorean triple:
In[1]:= |
Out[1]= |
{2,3,4} is not a Pythagorean triple:
In[2]:= |
Out[2]= |
{5,4,3} is not a Pythagorean triple:
In[3]:= |
Out[3]= |
Specify that the triple is unordered to determine if any ordering of the numbers is a Pythagorean triple:
In[4]:= |
Out[4]= |
To determine whether any ordering of potentially noninteger side lengths forms a right triangle, use RightTriangleQ:
In[5]:= |
Out[5]= |
In[6]:= |
Out[6]= |
The integers {5,4,3} can form a right triangle when considered as edge lengths, but do not form a Pythagorean triple due to their ordering:
In[7]:= |
Out[7]= |
In[8]:= |
Out[8]= |
This work is licensed under a Creative Commons Attribution 4.0 International License