# Modular arithmetic

### General | Latest Info

Modular arithmetic, sometimes referred to as modulus arithmetic or clock arithmetic, in its most elementary form, arithmetic do with a count that resets itself to zero every time a certain whole number N greater than one, known as modulus, has been reach. Examples are a digital clock in a 24 - hour system, which resets itself to 0 at midnight, and a circular protractor mark at 360 degrees. Modular arithmetic is important in number theory, where it is a fundamental tool in solution of Diophantine equations. Generalizations of the subject led to important 19 - century attempts to prove Fermats last theorem and the development of significant parts of modern algebra. Under modular arithmetic, only numbers are 0 1 2, N 1, and they are known as residues modulo N. Residues are added by taking the usual arithmetic sum, then subtracting modulus from the sum as many times as is necessary to reduce the sum to number M between 0 and N 1 inclusive. M is called sum of numbers modulo N. Using notation introduced by German mathematician Carl Friedrich Gauss in 1801, one write, for example, 2 + 4 + 3 + 7 6, where symbol is read is congruent to. Examples of the use of modular arithmetic occur in ancient Chinese, Indian, and Islamic cultures. In particular, they occur in calendrical and astronomical problems since these involve cycles, but one also find modular arithmetic in purely mathematical problems. An example from 3 - century - ad Chinese book, Sun Zis Sunzi suanjing, ask this is equivalent to asking for solution of simultaneous congruences X 2, X 3, and X 2, one solution of which is 23. The general solution of such problems come to be known as the Chinese remainder theorem. Swiss mathematician Leonhard Euler pioneered the modern approach to congruence about 1750, when he explicitly introduced the idea of congruence modulo number N and showed that this concept partition integers into N congruence classes, or residue classes. Two integers are in the same congruence class modulo N if their difference is divisible by N. For example, if N is 5, then 6 and 4 are members of the same congruence class {, 6 1 4 9,}. Since each congruence class may be represented by any of its members, this particular class may be call, for example, congruence class of 6 modulo 5 or congruence class of 4 modulo 5. In the Eulers system, any N numbers that leave different remainders on division by N may represent congruence classes modulo N. Thus, one possible system for arithmetic modulo 5 would be 2 1 0 1 2. Addition of congruence classes modulo N is defined by choosing any element from each class, adding elements together, and then taking congruence class modulo N that sum belongs to as answer. Euler similarly defines subtraction and multiplication of residue classes.

* Please keep in mind that all text is machine-generated, we do not bear any responsibility, and you should always get advice from professionals before taking any actions.

### Properties

Congruence relation satisfies all conditions of equivalence relation: reflexivity: symmetry: b If b For all, b, and N. Transitivity: If b and b c, then c If 1 b 1 and 2 b 2, or If b, then: + k b + k For any integer k k k b For any integer k 1 + 2 b 1 + b 2 1 2 b 1 b 2 1 2 b 1 b 2 k b k For any non - negative integer k p p, For any polynomial p with integer coefficients If b, then it is generally false that k k b. However, following is true: If c d mod, where is Euler's totient function, then c d provide that is coprime with N. For cancellation of common terms, we have the following rules: If + k b + k For any integer k, then b If k k b and k is coprime with N, then b modular multiplicative inverse is define by following rules: existence: there exist integer denote 1 such that aa 1 1 If and only If is coprime with N. This integer 1 is call modular multiplicative inverse of modulo N. If b and 1 exists, then 1 b 1 If x b and is coprime to N, then solution to this linear congruence is give by x 1 b multiplicative inverse x –1 may be efficiently compute by solving Bezout's equation {matheq}{\displaystyle ax+ny=1}{endmatheq} For {matheq}{\displaystyle x,y}{endmatheq} —using Extended Euclidean algorithm. In particular, if p is the prime number, then is coprime with p For every such that 0 < p; thus multiplicative inverse exists for all that is not congruent to zero modulo p. Some of more advanced properties of congruence relations are following: Fermat's little theorem: If p is prime and do not divide, then p 1 1. Euler's theorem: If and N are coprime, then 1, where is Euler's totient function. The simple consequence of Fermat's little theorem is that if p is prime, then 1 p 2 is multiplicative inverse of 0 < p. More generally, from Euler's theorem, If and N are coprime, then 1 1. Another simple consequence is that If b mod, where is Euler's totient function, then k k b provides k is coprime with N. Wilson's theorem: p is prime If and only If! 1. Chinese remainder theorem: For any, b and coprime m, N, there exist unique x such as x and x b.

* Please keep in mind that all text is machine-generated, we do not bear any responsibility, and you should always get advice from professionals before taking any actions.

### Residue systems

Modular arithmetic can be handled mathematically by introducing congruence relation on integers that is compatible with operations of ring of integers: addition, subtraction, and multiplication. For positive integer n, two integers and b are said to be congruent modulo n, write: \ equiv b \ pmod n, \ if their difference b is integer multiple of n. Number n is called modulus of congruence. {matheq} 38 \equiv 2 \pmod {12}\, {endmatheq} Because 38 2 = 36, which is a multiple of 12. - 8 \ equiv 7 \ pmod 5. \, 2 \ equiv - 3 \ pmod 5. \, - 3 \ equiv - 8 \ pmod 5. \, When and b are either both positive or both negative, then \ equiv b \ pmod n \, can also be thought of as asserting that both / n and b / n have the same remainder. For instance: {matheq} 38 \equiv 14 \pmod {12}\, {endmatheq} because both 38 / 12 and 14 / 12 have the same remainder, 2. It is also the case that {matheq} 38 - 14 = 24 {endmatheq} is an integer multiple of 12, which agrees with the prior definition of congruence relation. Remark on notation: Because it is common to consider several congruence relations for different moduli at the same time, modulus is incorporated into the notation. In spite of ternary notation, congruence relation for give modulus is binary. This would have been clearer if the notation n b had been used instead of the common traditional notation. Properties that make this relationship congruence relationship are following. {matheq} a_1 \equiv b_1 \pmod n {endmatheq} {matheq} a_2 \equiv b_2 \pmod n, {endmatheq} {matheq} a_1 + a_2 \equiv b_1 + b_2 \pmod n\, {endmatheq} {matheq} a_1 - a_2 \equiv b_1 - b_2 \pmod n\, {endmatheq} It should be noted that the above two properties would still hold if theory were expanded to include all real numbers, that is if {matheq} a_1, a_2, b_1, b_2, n\, {endmatheq} were not necessarily all integers. The next property, however, would fail if these variables were not all integers: {matheq} a_1 a_2 \equiv b_1 b_2 \pmod n.\, {endmatheq}

* Please keep in mind that all text is machine-generated, we do not bear any responsibility, and you should always get advice from professionals before taking any actions.

### Applications

Modular Arithmetic is used extensively in pure mathematics, where it is the cornerstone of number theory. But it also has many practical applications. It is used to calculate checksums for International Standard Book Numbers and Bank identifiers and to spot errors in them. Modular Arithmetic also underlies public key cryptography systems, which are vital for modern commerce. It is also widely used in computer science. Finally, in music theory, modulo 12 Arithmetic is used to analyse 12 - tone equal temperament system, when notes separate by octave of 12 semi - tones are treated as equivalent. Peter Lynch is emeritus professor at UCD school of mathematics and statistics. He blog at thatsmaths.

* Please keep in mind that all text is machine-generated, we do not bear any responsibility, and you should always get advice from professionals before taking any actions.

### Computational complexity

Since modular arithmetic has such a wide range of applications, it is important to know how hard it is to solve system of congruences. The Linear system of congruences can be solved in polynomial time with the form of Gaussian elimination, For details, see linear congruence theorem. Algorithms, such as Montgomery reduction, also exist to allow simple arithmetic operations, such as multiplication and exponentiation modulo n, to be performed efficiently on large numbers. Some operations, like finding discrete logarithm or quadratic congruence, appear to be as hard as integer factorization and thus are starting point for cryptographic algorithms and encryption. These problems might be NP - intermediate. The solving system of non - linear modular arithmetic equations is NP - complete.

* Please keep in mind that all text is machine-generated, we do not bear any responsibility, and you should always get advice from professionals before taking any actions.

### Example implementations

Give three numbers x, y and p, compute% p. Problem with the above solutions is, overflow may occur for large values of N or x. Therefore, power is generally evaluated under modulo of large number. Below is a fundamental modular property that is used for efficiently computing power under modular arithmetic. The Time Complexity of the above solution is O. Modular exponentiation this article was contributed by Shivam Agrawal. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above. Attention reader! Dont stop learning now. Get hold of all important DSA concepts with DSA Self pace Course at a student - friendly price and become industry ready.

* Please keep in mind that all text is machine-generated, we do not bear any responsibility, and you should always get advice from professionals before taking any actions.

###### * Please keep in mind that all text is machine-generated, we do not bear any responsibility, and you should always get advice from professionals before taking any actions

Plex.page is an Online Knowledge, where all the summaries are written by a machine. We aim to collect all the knowledge the World Wide Web has to offer.

##### Partners: Contact

General contact: contant@plex.page