Modular arithmetic: what is it and where is it used

Table of contents:

Modular arithmetic: what is it and where is it used
Modular arithmetic: what is it and where is it used
Anonim

In mathematics, modular arithmetic is a calculation system for integers, with the help of which they "turn over" when they reach a certain value - the module (or the plural of them). The modern approach to this kind of science was developed by Carl Friedrich Gauss in his Disquisitiones Arithmeticae published in 1801. Computer scientists are very fond of using this method, as it is very interesting and opens up certain new possibilities in operations with numbers.

Visualization of modular arithmetic
Visualization of modular arithmetic

Essence

Because the number of hours starts again after it reaches 12, it is arithmetic modulo 12. According to the definition below, 12 corresponds not only to 12, but also to 0, so one can also name the time called "12:00". "0:00". After all, 12 is the same as 0 modulo 12.

Modular arithmetic can be processed mathematically by introducing a congruent relation to integers that is compatible with operations on integersnumbers: addition, subtraction and multiplication. For a positive integer n, two numbers a and b are said to be congruent modulo n if their difference a - b is a multiple of n (that is, if there exists an integer k such that a - b=kn).

Modular numbers
Modular numbers

Deductions

In theoretical mathematics, modular arithmetic is one of the foundations of number theory, affecting almost all aspects of its study, and is also widely used in the theory of groups, rings, knots and abstract algebra. In the field of applied mathematics, it is used in computer algebra, cryptography, computer science, chemistry, visual arts and music.

Practice

A very practical application is the calculation of checksums in serial number identifiers. For example, some common book standards use arithmetic modulo 11 (if released before January 1, 2007) or modulo 10 (if released before or after January 1, 2007). Similarly, for example, in International Bank Account Numbers (IBANs). This uses modulo 97 arithmetic to detect user input errors in bank account numbers.

In chemistry, the last digit of the CAS registration number (the unique identification number for each chemical compound) is the check digit. It is calculated by taking the last digit of the first two parts of the CAS registration number multiplied by 1, the previous digit 2 times, the previous digit 3 times, etc., adding it all up and calculating the sum modulo 10.

What is cryptography? The fact is thatit has a very strong connection with the topic under discussion. In cryptography, the laws of modular arithmetic directly underlie public-key systems such as RSA and Diffie-Hellman. Here it provides the finite fields that underlie elliptic curves. Used in various symmetric key algorithms, including Advanced Encryption Standard (AES), International Data Encryption Algorithm, and RC4.

Elementary arithmetic
Elementary arithmetic

Application

This method is used in areas where you need to read numbers. It was developed by mathematicians, and everyone uses it, especially computer scientists. This is well documented in books like Modular Arithmetic for Dummies. However, a number of experts recommend not to take such literature seriously.

In computer science, modular arithmetic is often used in bitwise and other operations involving fixed-width circular data structures. Analysts love to use it. The modulo operation is implemented in many programming languages and calculators. In this case, it is one example of such an application. Modulo comparison, division with a remainder, and other tricks are also used in programming.

In music, arithmetic modulo 12 is used when considering a system of equal temperament of twelve tones, in which the octave and enharmonic are equivalent. In other words, the keys in the ratio 1-2 or 2-1 are equivalent. In music and other humanities, arithmetic plays a rather significant role, but in textbookscomputer scientists don't usually write about it.

Children's arithmetic
Children's arithmetic

Method of reducing nines

The 9s conversion method offers a quick check of manual decimal arithmetic calculations. It is based on modular arithmetic modulo 9 and in particular on the decisive property 10 10 1.

there are other examples. Arithmetic modulo 7 is used in algorithms that determine the day of the week for a particular date. In particular, the Zeller congruence and the Doomsday algorithm make heavy use of arithmetic modulo 7.

Other applications

It has already been said about modular arithmetic in cryptography. In this area, she is simply irreplaceable. More generally, modular arithmetic also finds applications in disciplines such as law, economics (such as game theory), and other areas of the social sciences. In other words, where the proportional division and distribution of resources plays a major role.

Counting project
Counting project

Because modular arithmetic has such a wide range of uses, it's important to know how difficult it is to solve a system of comparisons. A linear system of congruences can be solved in polynomial time in the form of Gaussian elimination. This is described in more detail by the linear congruence theorem. Algorithms such as Montgomery reduction also exist to allow simple arithmetic operations to be performed efficiently. For example, multiplication and exponentiation modulo n, for large numbers. This is very important to know in order to understand whatcryptography. After all, it just works with similar operations.

Congruence

Some operations, such as finding the discrete logarithm or the quadratic congruence, seem to be as complex as integer factorization and thus are the starting point for cryptographic algorithms and encryption. These problems may be NP-intermediate.

Examples

The following are three fairly fast C functions - two for performing modular multiplication and one for raising to modular numbers for unsigned integers up to 63 bits, without transient overflow.

Shortly after discovering integers (1, 2, 3, 4, 5…) it becomes apparent that they fall into two groups:

  • Even: divisible by 2 (0, 2, 4, 6..).
  • Odd: not divisible by 2 (1, 3, 5, 7…).

Why is this distinction important? This is the beginning of abstraction. We notice the properties of the number (e.g., even or odd) and not just the number itself ("37").

This allows us to explore the math at a deeper level and find relationships between number types rather than specific ones.

Counting on fingers
Counting on fingers

Properties of a number

Being a "three" is just another property of a number. Maybe not as immediately useful as even/odd, but it's there. We can create rules like "thirteen x three vein=thirteen" and so on. But it's crazy. We can't make new words all the time.

The modulo operation (abbreviated mod or "%" in many programming languages) is the remainder whendivision. For example, "5 mod 3=2", which means 2 is the remainder when you divide 5 by 3.

When converting everyday terms to math, an "even number" is where it is "0 mod 2", meaning the remainder is 0 when divided by 2. An odd number is "1 mod 2" (has a remainder of 1).

Counting devices
Counting devices

Even and odd numbers

What is even x even x odd x odd? Well, it's 0 x 0 x 1 x 1=0. Actually, you can see if an even number is multiplied anywhere, where the whole result will be zero.

The trick with modular math is that we've already used it to store time - sometimes called "clock arithmetic".

For example: 7:00 am (am/pm - doesn't matter). Where will the hour hand be in 7 hours?

Modulations

(7 + 7) mod 12=(14) mod 12=2 mod 12 [2 is the remainder when 14 is divided by 12. Equation 14 mod 12=2 mod 12 means 14 hours and 2 hours look the same on a 12-hour clock. They are congruent, marked with a triple equal sign: 14 ≡ 2 mod 12.

Another example: it's 8:00 am. Where will the big hand be in 25 hours?

Instead of adding 25 to 8, you can understand that 25 hours is just "1 day + 1 hour". The answer is simple. So, the clock will end 1 hour ahead - at 9:00.

(8 + 25) mod 12 ≡ (8) mod 12 + (25) mod 12 ≡ (8) mod 12 + (1) mod 12 ≡ 9 mod 12. You intuitively converted 25 to 1 and added this to 8.

Using the clock as an analogy, we can figure out if thethe rules of modular arithmetic, and they work.

The power of numbers and formulas
The power of numbers and formulas

Addition/Subtraction

Let's say two times look the same on our clock ("2:00" and "14:00"). If we add the same x hours to both, what happens? Well, they change for the same amount on the clock! 2:00 + 5 hours ≡ 14:00 + 5 hours - both will show 7:00.

Why? We can just add 5 to the 2 remainders that both have and they advance the same way. For all congruent numbers (2 and 14), addition and subtraction have the same result.

It's harder to know if the multiplication stays the same. If 14 ≡ 2 (mod 12), can we multiply both numbers and get the same result? Let's see what happens when we multiply by 3.

Well, 2:003 × 6:00. But what is 14:003?

Remember, 14=12 + 2. So we can say

143=(12 + 2)3=(123) + (23)

The first part (123) can be ignored! The overflow of 12 hours that carries 14 simply repeats itself several times. But who cares? We ignore the overflow anyway.

Arithmetic tools
Arithmetic tools

Multiplication

When multiplying, only the remainder matters, that is, the same 2 hours for 14:00 and 2:00. Intuitively, this is how I see multiplication not changing the relationship with modular math (you can multiply both sides of a modular relationship and get the same result).

We do it intuitively, but it's nice to give it a name. You have a flight arriving at 3pm. Hedelayed by 14 hours. What time will it land?

14 ≡ 2 mod 12. So, think of it as 2 o'clock, so the plane will land at 5 o'clock in the morning. The solution is simple: 3 + 2=5 am. This is a little more complicated than the simple modulo operation, but the principle is the same.

Recommended: