# Pythagorean Quadruple

Given four points, check whether they form Pythagorean Quadruple.

It is defined as a tuple of integers a, b, c, d such that . They are basically the solutions of **Diophantine Equations**. In the geometric interpretation it represents a **cuboid** with integer side lengths |a|, |b|, |c| and whose space diagonal is |d| .

The cuboids sides shown here are examples of pythagorean quadruples.

It is primitive when their greatest common divisor is 1. Every Pythagorean quadruple is an integer multiple of a primitive quadruple. We can generate the set of primitive pythagorean quadruples for which a is odd can be generated by formula :

a = m^{2}+ n^{2}– p^{2}– q^{2},

b = 2(mq + np),

c = 2(nq – mp),

d = m^{2}+ n^{2}+ p^{2}+ q^{2}

where m, n, p, q are non-negative integers with greatest common divisor 1 such that m + n + p + q are odd. Thus, all primitive Pythagorean quadruples are characterized by **Lebesgue’s identity**.

(m^{2}+ n^{2}+ p^{2}+ q^{2})^{2}= (2mq + 2nq)^{2}+ 2(nq – mp)^{2}+ (m^{2}+ n^{2}– p^{2}– q^{2})m^{2}+ n^{2}– p^{2}– q^{2}

## C++

`// C++ code to detect Pythagorean Quadruples. ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// function for checking ` `bool` `pythagorean_quadruple(` `int` `a, ` `int` `b, ` `int` `c, ` ` ` `int` `d) ` `{ ` ` ` `int` `sum = a * a + b * b + c * c; ` ` ` `if` `(d * d == sum) ` ` ` `return` `true` `; ` ` ` `else` ` ` `return` `false` `; ` `} ` ` ` `// Driver Code ` `int` `main() ` `{ ` ` ` `int` `a = 1, b = 2, c = 2, d = 3; ` ` ` `if` `(pythagorean_quadruple(a, b, c, d)) ` ` ` `cout << ` `"Yes"` `<< endl; ` ` ` `else` ` ` `cout << ` `"No"` `<< endl; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java code to detect Pythagorean Quadruples. ` `import` `java.io.*; ` `import` `java.util.*; ` ` ` `class` `GFG { ` ` ` `// function for checking ` `static` `Boolean pythagorean_quadruple(` `int` `a, ` `int` `b, ` ` ` `int` `c, ` `int` `d) ` `{ ` ` ` `int` `sum = a * a + b * b + c * c; ` ` ` `if` `(d * d == sum) ` ` ` `return` `true` `; ` ` ` `else` ` ` `return` `false` `; ` `} ` ` ` `// Driver function ` ` ` `public` `static` `void` `main (String[] args) { ` ` ` `int` `a = ` `1` `, b = ` `2` `, c = ` `2` `, d = ` `3` `; ` ` ` `if` `(pythagorean_quadruple(a, b, c, d)) ` ` ` `System.out.println(` `"Yes"` `); ` ` ` `else` ` ` `System.out.println(` `"No"` `); ` ` ` ` ` `} ` `} ` `// This code is contributed by Gitanjali. ` |

*chevron_right*

*filter_none*

## Python3

`# Python code to detect ` `# Pythagorean Quadruples. ` `import` `math ` ` ` `# function for checking ` `def` `pythagorean_quadruple(a,b, c, d): ` ` ` ` ` `sum` `=` `a ` `*` `a ` `+` `b ` `*` `b ` `+` `c ` `*` `c; ` ` ` `if` `(d ` `*` `d ` `=` `=` `sum` `): ` ` ` `return` `True` ` ` `else` `: ` ` ` `return` `False` ` ` `#driver code ` `a ` `=` `1` `b ` `=` `2` `c ` `=` `2` `d ` `=` `3` `if` `(pythagorean_quadruple(a, b, c, d)): ` ` ` `print` `(` `"Yes"` `) ` `else` `: ` ` ` `print` `(` `"No"` `) ` ` ` `# This code is contributed ` `# by Gitanjali. ` |

*chevron_right*

*filter_none*

## C#

`// C# code to detect ` `// Pythagorean Quadruples. ` `using` `System; ` ` ` `class` `GFG { ` ` ` ` ` `// function for checking ` ` ` `static` `Boolean pythagorean_quadruple(` `int` `a, ` ` ` `int` `b, ` `int` `c, ` `int` `d) ` ` ` `{ ` ` ` `int` `sum = a * a + b * b + c * c; ` ` ` `if` `(d * d == sum) ` ` ` `return` `true` `; ` ` ` `else` ` ` `return` `false` `; ` ` ` `} ` ` ` ` ` `// Driver function ` ` ` `public` `static` `void` `Main () { ` ` ` ` ` `int` `a = 1, b = 2, c = 2, d = 3; ` ` ` ` ` `if` `(pythagorean_quadruple(a, b, c, d)) ` ` ` `Console.WriteLine(` `"Yes"` `); ` ` ` `else` ` ` `Console.WriteLine(` `"No"` `); ` ` ` ` ` `} ` `} ` ` ` `// This code is contributed by vt_M. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// php code to detect Pythagorean Quadruples. ` ` ` `// function for checking ` `function` `pythagorean_quadruple(` `$a` `, ` `$b` `, ` `$c` `, ` `$d` `) ` `{ ` ` ` `$sum` `= ` `$a` `* ` `$a` `+ ` `$b` `* ` `$b` `+ ` `$c` `* ` `$c` `; ` ` ` ` ` `if` `(` `$d` `* ` `$d` `== ` `$sum` `) ` ` ` `return` `true; ` ` ` `else` ` ` `return` `false; ` `} ` ` ` `// Driver Code ` ` ` `$a` `= 1; ` `$b` `= 2; ` `$c` `= 2; ` `$d` `= 3; ` ` ` ` ` `if` `(pythagorean_quadruple(` `$a` `, ` `$b` `, ` `$c` `, ` `$d` `)) ` ` ` `echo` `"Yes"` `; ` ` ` `else` ` ` `echo` `"No"` `; ` ` ` `// This code is contributed by anuj_67. ` `?> ` |

*chevron_right*

*filter_none*

Output:

Yes

## Recommended Posts:

- Number of triangles formed by joining vertices of n-sided polygon with two common sides and no common sides
- Number of triangles formed by joining vertices of n-sided polygon with one side common
- Program to calculate area of inner circle which passes through center of outer circle and touches its circumference
- Area of a Regular Pentagram
- Angle subtended by the chord when the angle subtended by another chord of same length is given
- Distance of chord from center when distance between center and another equal length chord is given
- Length of the perpendicular bisector of the line joining the centers of two circles
- Angle subtended by the chord to center of the circle when the angle subtended by the another equal chord of a congruent circle is given
- Find the original coordinates whose Manhattan distances are given
- Length of the chord the circle if length of the another chord which is equally inclined through the diameter is given
- Distance between centers of two intersecting circles if the radii and common chord length is given
- Exterior angle of a cyclic quadrilateral when the opposite interior angle is given
- Angle between a chord and a tangent when angle in the alternate segment is given
- Radii of the three tangent circles of equal radius which are inscribed within a circle of given radius

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.