# Fermat’s Last Theorem

Get this book -> Problems on Array: For Interviews and Competitive Programming

In this article, we will be talking about Fermat's Last Theorem , also called as Fermat's Great theorem. Stated by Pierre de Fermat in around 1637 in a margin of his copy of Arithmetica. A Nightmare for Mathematicians to prove. This theorem resisted proof for around 358 years until a successful proof was released by Andrew Wiles in 1994.

Table of contents:

- Statement of Fermat’s Last Theorem
- Proof for n = 4
- Algorithm
- Conclusion

## Statement of Fermat’s Last Theorem

It states that there are no natural numbers x , y and z that satisfies the equation:

## x^{n} + y^{n} = z^{n} , where n > 2.

Consider an Example , let's assume n = 4 , then from Fermat's last theorem we can state that there are no 3 natural numbers x , y and z such that

x^{4} + y^{4}=z^{4}

When considering n to be 1 or 2 , we have infinite possibilities , pythogorean triplets are example of these.

Examples include:

1 + 2 = 3 , with n = 1

3^{2} + 4^{2} = 5^{2} , n = 2

## Proof for n = 4

Consider the Equation , where xyz != 0

x^{4} + y^{4} = z^{2}

We can consider x^{2} , y^{2} and z to be coprime (article linked in References).

As the Solution is in the form of a pythongorean triplet , From its Solution , we know that there exists 2 numbers p and q such that:

x^{2} = 2pq

y^{2} = p^{2} - q^{2}

z = p^{2} + q^{2}

from the above equations , we have another triplet:

y^{2} + q^{2} = p^{2}

For this equation , we have two numbers a and b such that:

q = 2ab

y = a^{2} - b^{2}

p = a^{2} + b^{2}

Combining Equations from above , we get

x^{2} = 2pq = 2(a^{2} + b^{2})(2ab) = (4ab)(a^{2} + b^{2})

We can prove that ab and a^{2} + b^{2} are relative primes , hence we can consider them squares.

Now there exists P such that P^{2} = a^{2} + b^{2} , which is less than z^{2} .

With this we reach infinite descent as P^{2} = a^{2} + b^{2} = p , which is itself less than z = p^{2} + q^{2} , which is less than z^{2} .

As the existence of a solution to the original equation leads necessarily to the existence of another smaller square with same properties , the case for n = 4 can be stated as a corollary to this.

x^{4} + y^{4} = (z^{2})^{2} has no solution when xyz != 0

## Algorithm

Consider that we're given a limit until which we need to check if there exists a counter example for Fermat's Last Theorem.

```
Algorithm checkUntilLimit(Limit , n){
if n < 3 {
write "Invalid Value of n"
return
}
for(let a <- 1 , a <= limit , a <- a+ )
for(let b <- a , b <= limit , b <- b + 1)
{
let sum <- power(a , n) + power(b , n)
let c <- power(sum , 1.0/n)
let d <- (integer)power((integer)c , n)
if c == d
{
write "Counter Example Found , Fermat's Last Theorem Defeated"
return
}
}
write " Can't Find a Counter Example for Fermat's Last Theorem"
}
```

if we pass simple values into our algorithm , say these values for limit and n were (4 , 3) , then the output would be

```
Can't Find a Counter Example for Fermat's Last Theorem
```

In case we pass values that are very large which may cause integer overflow , this may cause the algorithm to print that it found a counter example , but that is not true , due to overflow in the variables , it thinks that it found the two values to be same , but as we know that isn't the case. To overcome this issue we may use BigInteger if using Java or Other Language equivalent of BigInteger.

## Conclusion

Fermat's Last Theorem resisted proof's for around 350 odd years , but this resistance proved very prosperous for mathematics.Fermat's Last theorem might not have that many real world applications but when people were trying to prove this theorem , they tried various methods which led to the discovery of many important mathematical topics , these very same topics found applications in computer science, the most important application being Cryptography. Wiles proof for this theorem proved to be a crucial step in solving another theorem called as modularity theorem also known as **Taniyama-Shimura Conjecture**.

With this article at OpenGenus, you must have the complete idea of Fermat’s Last Theorem.