Modular Arithmetic

in furl •  7 months ago  (edited)

The set of integers in mathematics are denoted with double struck Z.

image.png

It stands for "zahlen" which means numbers in German. In image.png, counting from 0 to 10 are simply


image.png

Meanwhile the set of integers modulo image.png is denoted by

image.png

and counting 1 to 10 in image.png works as follows

image.png

This sequence repeats every 6 numbers starting from 0. The modulo operator

image.png

while returns the remainder of image.png divided by image.png, also yields the image.png-th number in the sequence of integers modulo image.png (image.png). The 10th number in the sequence of integers modulo 6

image.png

is also the remainder of 10 divided by 6.

Periodicity

Two integers a,b are in the same equivalence class modulo n if both integers returns the same remainder after division by n. The image.png-th and image.png-th number in the sequence of image.png will be the same.

Take 10 and 16 modulo 6 for example

image.png

In the sequence of image.png, integers within the same equivalence class are the same.

image.png

In congruence relations, this can be written as follows

image.png

stating that a is congruent to b modulo n. Two integers are said to be congruent modulo n if they returns the same remainder when divided by n. With modulo operator, this will be

image.png

Notice the repeating nature of image.png sequence. For example n=6

image.png

Any term is the same as the n-th next term.

image.png

This can be generalized further given any integer q

image.png

showing that image.png and image.png are congruent modulo image.png.

Compare it to image.png sequence

image.png

The only scenario where

image.png

is when (if and only if?) image.png.

Quotient Remainder Theorem

Division between any two integers does not always yield another integer. Division between 22 and 7

image.png

left a remainder of 1. Quotient Remainder Theorem states that given any integer a and a natural number n, there exist another two integers q and r such that

image.png

this can be rewritten with modulo operator into

image.png

and the division above can be rewritten algebraically into

image.png

or with modulo operator

image.png

This is used to better demonstrate

Modular Addition

Given two integers image.png and image.png, a positive integer n, and

image.png

This can be algebraically written into

image.png

with integers image.png and image.png. Add together image.png and image.png gives

image.png

Take modulo on both sides

image.png

Because

image.png

and

image.png

we can drop image.png out from the equation which results into a more tidy equation

image.png

Plugging back the definitions of image.png and image.png gives

image.png

The equation above can be used as a tool to simplify additions under modulo operator. For example

image.png

Substituting image.png gives similar equation for subtraction

image.png

In case of negative integers inside modulo operator,


image.png

Modular Multiplication

Similar to addition, start with two integers image.png and image.png, a positive integer n, and

image.png

This can be algebraically written into

image.png

multiplying image.png and image.png gives

image.png

take modulo on both sides

image.png

removing image.png inside the modulo gives

image.png

Plugging back the definitions of image.png and image.png gives

image.png

The equation above can be used as a tool to simplify multiplications under modulo operator similar to additions under modulo operator. For example 190 squared divided by 7

image.png

which is easier to evaluate this way. It would've taken longer to first find out that

image.png

Sidenote :

-Some programming language like Python uses percent sign (%) for modulo operator. In excel, modulo operator is written with '=mod([number];[divisor])'
-I am very sorry for night mode readers as the latex rendered are transparent.
-There's more to modular arithmetic but i'm going to leave it here. I might add more on my next posts.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!