Friday, October 15, 2021

Some must know stuffs of Mathematics

Modular Arithmetics:
This is one of the most important mathematical topics. We will see what is it and how it works.

Source: Internet
Modularity is just like a clock. Modular arithmetic also called "clock arithmetic", why?
You can easily understand, just look at the picture. What's happening here actually. After 12'o clock we say 1'o clock, not 13'o clock then 2'o clock not 14'o clock etc.

So, basically, modules are when a number is a warp around to reach a fixed quantity.

In clock, there are 12 sections, after reaching 13 it's rounded to 1, which means 13 is divided by 12 and the remainder 1 is its current position.
Mathematically we can  say 13
 1 mod 12(13 is congruent to 1 mod 12)

For a positive integer n, two integers a and b are congruent modulo n, at the same time (a-b) is multiple of n.
That is, a ≡ b (mod n), (a-b) is multiple of n.

Now we can simply say that modularity is "reset", which means every time if we reach our limit(that's called mod) we reset the value to zero(0).

Take an example, 6%3 = 0, 18%3 = 0, 19%3 = 1. See every time you reach multiple of the mod(3) and the result gets reset. So here we are subtracting the mod multiples cycle.

a%m = a - [a/m] * m, the range of module values always in between 0 to m - 1

So there are a few rules of modularity like addition, subtraction, multiplication, and division? (No, division in modularity is different, we will talk about it later).
Let's see the equation, we can easily understand.

(a+b)  mod m = (a mod m)+(b mod m)  mod m
(a−b)  mod m = (a mod m)−(b mod m)  mod m
(a*b)  mod m = (a mod m)*(b mod m)  mod m

suppose we want to multiply two(or many) long integers and then mod their result, they can't fit in our local variable, so simply first we can mod them separately as I mentioned above and we can get the same result.

Sometimes we get the negative results of modular, so that time we can simply do that.
x = (x%m), if x < 0 x+=m

Modulo Division:



No comments:

Post a Comment