Wolfram Research

Function Repository Resource:

PythagoreanTripleQ (1.0.1) current version: 2.0.0 »

Source Notebook

Determine whether a triple of integers constitutes a Pythagorean triple

Contributed by: Jordan Hasler, Wolfram|Alpha Math Team

ResourceFunction["PythagoreanTripleQ"][{a,b,c}]

determines whether the triple of integers {a,b,c} satisfies a2+b2=c2.

Details

The option "UnorderedTriple" determines whether to treat the input as ordered and defaults to False. When set to True, ResourceFunction["PythagoreanTripleQ"] returns True if any ordering of the triples satisfies a2+b2=c2.

Examples

Basic Examples (2) 

The ordered triple {3, 4, 5} is a Pythagorean triple:

In[1]:=
ResourceFunction["PythagoreanTripleQ"][{3, 4, 5}]
Out[1]=

{2, 3, 4} is not a Pythagorean triple:

In[2]:=
ResourceFunction["PythagoreanTripleQ"][{2, 3, 4}]
Out[2]=

Options (2) 

{5, 4, 3} is not a Pythagorean triple:

In[3]:=
ResourceFunction["PythagoreanTripleQ"][{5, 4, 3}]
Out[3]=

Specify that the triple is unordered to determine if any ordering of the numbers is a Pythagorean triple:

In[4]:=
ResourceFunction["PythagoreanTripleQ"][{5, 4, 3}, "UnorderedTriple" -> True]
Out[4]=

Properties and Relations (2) 

To determine whether any ordering of potentially noninteger side lengths forms a right triangle, use RightTriangleQ

In[5]:=
ResourceFunction["RightTriangleQ"] {5, 4, 3}]
Out[5]=
In[6]:=
ResourceFunction["RightTriangleQ"][{Sqrt[2], Sqrt[3], Sqrt[5]}]
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]:=
ResourceFunction["RightTriangleQ"][{5, 4, 3}]
Out[7]=
In[8]:=
ResourceFunction[
ResourceObject[
Association["Name" -> InterpretationBox[
TagBox[
FrameBox[
PaneBox[
GridBox[{{
StyleBox[
StyleBox[
AdjustmentBox[
              "\"[\[FilledSmallSquare]]\"", BoxBaselineShift -> -0.25,
                BoxMargins -> {{0, 0}, {-1, -1}}], "ResourceFunctionIcon", FontColor -> RGBColor[
               0.8745098039215686, 0.2784313725490196, 0.03137254901960784]], ShowStringCharacters -> False, FontFamily -> "Source Sans Pro Black", FontSize -> 0.65 Inherited, FontWeight -> "Heavy", PrivateFontOptions -> {"OperatorSubstitution" -> False}], 
StyleBox[
RowBox[{
StyleBox["\"PythagoreanTripleQ\"", "ResourceFunctionLabel", FontFamily -> "Source Sans Pro"], " "}], ShowAutoStyles -> False, ShowStringCharacters -> False, FontSize -> 0.9 Inherited, FontColor -> GrayLevel[0.1]]}}, GridBoxSpacings -> {"Columns" -> {{0.25}}}], Alignment -> Left, BaseStyle -> {
          LineSpacing -> {0, 0}, LineBreakWithin -> False}, BaselinePosition -> Baseline, FrameMargins -> {{3, 0}, {0, 0}}], Background -> RGBColor[0.968627, 0.976471, 0.984314], BaselinePosition -> Baseline, DefaultBaseStyle -> {}, FrameMargins -> {{0, 0}, {1, 1}}, FrameStyle -> RGBColor[0.831373, 0.847059, 0.85098], RoundingRadius -> 4], {"FunctionResourceBox", 
RGBColor[0.8745098039215686, 0.2784313725490196, 0.03137254901960784],
         "\"PythagoreanTripleQ\""}, TagBoxNote -> "FunctionResourceBox"], 
ResourceFunction["PythagoreanTripleQ"], BoxID -> "PythagoreanTripleQ",
       Selectable -> False], "ShortName" -> InterpretationBox[
TagBox[
FrameBox[
PaneBox[
GridBox[{{
StyleBox[
StyleBox[
AdjustmentBox[
              "\"[\[FilledSmallSquare]]\"", BoxBaselineShift -> -0.25,
                BoxMargins -> {{0, 0}, {-1, -1}}], "ResourceFunctionIcon", FontColor -> RGBColor[
               0.8745098039215686, 0.2784313725490196, 0.03137254901960784]], ShowStringCharacters -> False, FontFamily -> "Source Sans Pro Black", FontSize -> 0.65 Inherited, FontWeight -> "Heavy", PrivateFontOptions -> {"OperatorSubstitution" -> False}], 
StyleBox[
RowBox[{
StyleBox["\"PythagoreanTripleQ\"", "ResourceFunctionLabel", FontFamily -> "Source Sans Pro"], " "}], ShowAutoStyles -> False, ShowStringCharacters -> False, FontSize -> 0.9 Inherited, FontColor -> GrayLevel[0.1]]}}, GridBoxSpacings -> {"Columns" -> {{0.25}}}], Alignment -> Left, BaseStyle -> {
          LineSpacing -> {0, 0}, LineBreakWithin -> False}, BaselinePosition -> Baseline, FrameMargins -> {{3, 0}, {0, 0}}], Background -> RGBColor[0.968627, 0.976471, 0.984314], BaselinePosition -> Baseline, DefaultBaseStyle -> {}, FrameMargins -> {{0, 0}, {1, 1}}, FrameStyle -> RGBColor[0.831373, 0.847059, 0.85098], RoundingRadius -> 4], {"FunctionResourceBox", 
RGBColor[0.8745098039215686, 0.2784313725490196, 0.03137254901960784],
         "\"PythagoreanTripleQ\""}, TagBoxNote -> "FunctionResourceBox"], 
ResourceFunction["PythagoreanTripleQ"], BoxID -> "PythagoreanTripleQ",
       Selectable -> False], "UUID" -> "ce5855d7-bdf0-4bf6-89c8-e84ef1912ab9", "ResourceType" -> "Function", "Version" -> None, "Description" -> "Determine whether a triple {a, b, c} satisfies \
a^2+b^2= c^2", "SymbolName" -> "FunctionRepository`$\
ce5855d7bdf04bf689c8e84ef1912ab9`PythagoreanTripleQ", "FunctionLocation" -> None]]][{5, 4, 3}]
Out[8]=

Publisher

Wolfram|Alpha Math Team

Version History

  • 2.0.0 – 23 March 2023
  • 1.0.1 – 29 March 2021
  • 1.0.0 – 18 September 2020

Related Resources

Author Notes

To view the full source code for PythagoreanTripleQ, run the following code:

In[1]:=
FileNameJoin[
  ReplacePart[
   FileNameSplit[FindFile["ResourceFunctionHelpers`"]], -1 -> "PythagoreanTripleQ.wl"]] // SystemOpen

License Information