Science  People  Locations  Timeline
Index: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Home > Modular arithmetic


 

Modular arithmetic Group theory

In mathematics, modular arithmetic is a system of arithmetic for certain equivalence classes of integers, called congruence classes. In modular arithmetic, numbers 'wrap around' after they reach a certain value (the modulus). For example, when the modulus is 12, then any two numbers that leave the same remainder when divided by 12 are equivalent (or "congruent") to each other. The numbers

..., −34, −22, −10, 2, 14, 26, ...

are all "congruent modulo 12" to each other, because each leaves the same remainder (2) on division by 12. The collection of all such numbers is a congruence class. This particular case of modular arithmetic is sometimes called clock arithmetic.

As explained below, one can add such congruence classes to get another such congruence class, subtract two such classes to get another, and multiply such classes to get another. When the modulus is a prime number, one can always divide by any class not containing 0.

1 Definition of modulo

Two discrepant conventions prevail:

A third sort of usage by mathematicians is quite different from these, but does not conflict with them because it deals with different subject matter. It evolved ultimately from the usage introduced by Gauss in 1801. It is explained in the article titled modulo.

1.1 The older convention, used by mathematicians

The original convention is that the expression

means that a and b are both in the same "congruence class" modulo n, i.e., both leave the same remainder on division by n, or, equivalently, ab is a multiple of n. Thus we have, for example

since 63 and 83 both leave the same remainder (3) on division by 10, or, equivalently, 63 − 83 is a multiple of 10. One says:

"63 is congruent to 83, modulo 10,"

or

"63 and 83 are congruent to each other, modulo 10."

"Modulo" is usually abbreviated to "mod" in speaking, just as in writing. The parentheses, i.e., the round brackets (), are usually not written, but in this case they emphasize the difference between the traditional mathematical convention and the modern computing convention. The mathematical usage parses the phrase differently from the computing usage.

In Latin, the language in which Gauss wrote, modulo is the ablative case of modulus. The number n, which in this example is 10, is the modulus.

1.2 The newer convention, used in computing

According to the newer convention, in general, a mod n is the remainder on integer division of a by n. Depending on the implementation, the remainder r is typically constrained to 0 ≤ |r| < |n|, with a negative remainder only resulting when n < 0.

The difference in conventions is not very serious, in fact; it is reasonably thought of as reflecting the preference, for computational purposes, of a normal form over the underlying equivalence relation. This can be regarded mainly as a notational convention in this case, where there is a strict-sense normal form.

1.3 Implementation of modulo in computing

Some calculators have a mod() function button, and many programming languages have a mod() function or similar, expressed as mod(a,n), for example. Some also support expressions that use "%" as a modulo operator, such as a % n.

a mod n can be calculated by using equations, in terms of other functions. Differences may arise according to the scope of the variables, which in common implementations is broader than in the definition just given.

An implementation of a modulo function that constrains the remainder set in the manner described above, as is found in the programming languages PerlImage:Programming-republic-of-perl. gif|right|framed|Programming Republic of logo]] Perl also Practical Extraction and Report Language (a backronym, see below), is a programming language released by Larry Wall on December 18, 1987 that borrows features fr and PythonPython is an interpreted, interactive programming language created by Guido van Rossum in 1990, originally as a scripting language for Amoeba OS capable of making system calls. Python is often compared to Tcl, Perl, Scheme, Java and Ruby. Python is develo, can be described in terms of the floor function floor(z), the greatest integer less than or equal to z:

mod(a,n) = a − (n × floor(a ÷ n))

This definition allows for a and n to be typed as integers or rational numbers.

The expression a mod 0 is undefined in the majority of numerical systems, although some do define it to be a.



Read more »

Non User