How does modular arithmetic work - Fermat's last theorem near misses?

Since you're new to modular arithmetic, here is a very simple explanation using a couple of examples.

There are three types of modular arithmetic you are already familiar with from grade school: mod 10, mod 5, and mod 2.

Mod 2 just refers to even numbers and odd numbers. Even numbers are those which are "equal to" (actually "congruent to") 0 (mod 2). Odd numbers are those which are congruent to 1 (mod 2).

For mod 5, discard all but the last digit of a number, then (if it is greater than 4), subtract 5 from the remaining digit.

For mod 10, just take the last digit of the number.


Consider the following equation. Is it true?

$5723784602 + 2893649283 = 8617433887$

Using modular arithmetic (specifically, mod 10) you can discard all but the final digit of each number, and state:

$2 + 3 \equiv 7 \mod 10$

This is obviously false. Therefore, the original equation is false.


How about the following equation?

$234343 \times 23845 = 5587908832$

Using the rules that you were probably taught in Grade School, if you take any number that ends in a five and multiply it by anything, the product must end in either a five or a zero. Therefore, this is false.

We can state this with modular arithmetic as follows:

$3 \times 0 \equiv 2 \mod 5$

Obviously this is false. Anything times zero must equal zero.


However, the reverse approach doesn't work:

$29834620934 + 293840239843 = 17$

If we check this with modular arithmetic (mod 10), we get:

$4 + 3 \equiv 7 \mod 10$

This is true, but the original equation is false.


In summary: You can use modular arithmetic to prove an equation false.

You can't use it (in this simplistic form) to prove an equation true.


The point isn't that "true in modular form implies true in integer form" (which is false!). The point is "false in modular form implies false in integer form".

As an example, if $x \equiv y \pmod{6}$ is false, then "there is $k$ such that $x = 6k + y$" is false, so "for all $k$, we have $x \not = 6k+y$" is true. In particular setting $k=0$ yields "$x \not = y$".


You've got the inference reversed. Rather any equation true in integers remains true modulo $\,m\,$ for any $\,m.\, $ Indeed, if two integers are equal, say $\, a= b\,$ then $\, a- b = 0 = 0\cdot m\,$ is a multiple of $\,m,\,$ thus $\, a\equiv b\pmod m,\, $ by the definition of congruence, viz. $\,m\mid a-b,\,$ i.e. $\,m\,$ divides $\,a-b.$

What makes this nontrivial is that congruences are equivalence relations that are compatible with addition and multiplication, so modular reduction preserves equality of arbitrary integer polynomial expressions, cf. the Polynomial Congruence Rule. For example, write an integer as a polynomial in radix $10,\,$ say $\, n = P(10).\,$ Then mod $9\,$ we have $\,\color{#c00}{10\equiv 1}\,$ so $\,P(\color{#c00}{10})\equiv P(\color{#c00}1)\equiv $ digit sum of $\,n,\,$ which yields a fast way to check decimal arithmetic by checking the calculation mod $9,\,$ so-called casting out nines.

This is used frequently, e.g. when we compare parity of expressions, i.e. their remianders mod $\,2,\,$ (e.g. in irrationality proofs of $\sqrt 2),\, $ and also when checking aritmetic by comparing their units digits, i.e. comparing remainders mod $10,\, $ or when casting out nines and elevens, etc.

More generally we can check arithmetic mod $\,n\,$ by checking it modulo divisors $\,m\,$ of $\,n.\,$ (Above is the special case $\,n =0,\,$ since the integers mod $0$ is just the integers). If you do enough modular checks these necessary conditions are even sufficient, e.g. see the Chinese Remainder Theorem.


If an equation is true in Modular form then it is not necessarily true in integer form (e.g $1\equiv 3\pmod 2$ but $1\ne3.$)

I think you're asking why showing that things are not congruent shows that they are not equal, i.e. That $a\not\equiv b\pmod m\Rightarrow a\ne b.$

You can just rewrite the equation as $a-b\not | m$ and since $0|m,$ $a-b\ne 0$ so we are done.