Sie sind auf Seite 1von 39

Modular arithmetic

From Wikipedia, the free encyclopedia


Jump to: navigation, search
In mathematics, modular arithmetic (sometimes called clock arithmetic) is a system of
arithmetic for integers, where numbers "wrap around" after they reach a certain valuethe
modulus.
The Swiss mathematician Leonhard Euler pioneered the modern approach to congruence in
about 1750, when he explicitly introduced the idea of congruence modulo a number N.[1]
Modular arithmetic was further advanced by Carl Friedrich Gauss in his book Disquisitiones
Arithmeticae, published in 1801.

Time-keeping on this clock uses arithmetic modulo 12.


A familiar use of modular arithmetic is in the 12-hour clock, in which the day is divided into
two 12-hour periods. If the time is 7:00 now, then 8 hours later it will be 3:00. Usual addition
would suggest that the later time should be 7 + 8 = 15, but this is not the answer because
clock time "wraps around" every 12 hours; in 12-hour time, there is no "15 o'clock".
Likewise, if the clock starts at 12:00 (noon) and 21 hours elapse, then the time will be 9:00
the next day, rather than 33:00. Since the hour number starts over after it reaches 12, this is
arithmetic modulo 12. 12 is congruent not only to 12 itself, but also to 0, so the time called
"12:00" could also be called "0:00", since 0 12 mod 12.

Contents
[hide]

1 Congruence relation

2 Ring of congruence classes

3 Remainders
o 3.1 Functional representation of the remainder operation

4 Applications

5 Computational complexity

6 See also

7 Notes

8 References

9 External links

[edit] Congruence relation


Modular arithmetic can be handled mathematically by introducing a congruence relation on
the integers that is compatible with the operations of the ring of integers: addition,
subtraction, and multiplication. For a positive integer n, two integers a and b are said to be
congruent modulo n, written:

if their difference a b is an integer multiple of n. The number n is called the modulus of the
congruence.
For example,

because 38 2 = 36, which is a multiple of 12.


The same rule holds for negative values:

When a and b are either both positive or both negative, then


can also be
thought of as asserting that both a / n and b / n have the same remainder. For instance:

because both 38 / 12 and 14 / 12 have the same remainder, 2. It is also the case that 38 14 =
24 is an integer multiple of 12, which agrees with the prior definition of the congruence
relation.

A remark on the notation: Because it is common to consider several congruence relations for
different moduli at the same time, the modulus is incorporated in the notation. In spite of the
ternary notation, the congruence relation for a given modulus is binary. This would have been
clearer if the notation a n b had been used, instead of the common traditional notation.
The properties that make this relation a congruence relation (respecting addition, subtraction,
and multiplication) are the following.
If

and

then:

It should be noted that the above two properties would still hold if the theory were expanded
to include all real numbers, that is if
were not necessarily all integers. The
next property, however, would fail if these variables were not all integers:

[edit] Ring of congruence classes


Like any congruence relation, congruence modulo n is an equivalence relation, and the
equivalence class of the integer a, denoted by , is the set
. This set, consisting of the integers
congruent to a modulo n, is called the congruence class or residue class or simply residue
of the integer a, modulo n. When the modulus n is known from the context, that residue may
also be denoted .
The set of all congruence classes modulo n is denoted
or
(the alternate notation
is not recommended because of the possible confusion with the set of n-adic integers). It
is defined by:

When n 0,

has n elements, and can be written as:

When n = 0,
.

does not have zero elements; rather, it is isomorphic to

We can define addition, subtraction, and multiplication on

, since

by the following rules:

The verification that this is a proper definition uses the properties given before.
In this way,

becomes a commutative ring. For example, in the ring

, we have

as in the arithmetic for the 24-hour clock.


The notation

is used, because it is the factor ring of

integers divisible by n, where


is the singleton set
a maximal ideal, that is, when n is prime.
In terms of groups, the residue class
group.[2]

by the ideal

. Thus

containing all

is a field when

is the coset of a in the quotient group

is

, a cyclic

The set
has a number of important mathematical properties that are foundational to
various branches of mathematics.
Rather than excluding the special case n = 0, it is more useful to include
(which, as
mentioned before, is isomorphic to the ring of integers), for example when discussing the
characteristic of a ring.

[edit] Remainders
The notion of modular arithmetic is related to that of the remainder in division. The operation
of finding the remainder is sometimes referred to as the modulo operation and we may see 2
= 14 (mod 12). The difference is in the use of congruency, indicated by "", and equality
indicated by "=". Equality implies specifically the "common residue", the least non-negative
member of an equivalence class. When working with modular arithmetic, each equivalence
class is usually represented by its common residue, for example 38 2 (mod 12) which can
be found using long division. It follows that, while it is correct to say 38 14 (mod 12), and 2
14 (mod 12), it is incorrect to say 38 = 14 (mod 12) (with "=" rather than "").

The difference is clearest when dividing a negative number, since in that case remainders are
negative. Hence to express the remainder we would have to write 5 17 (mod 12), rather
than 7 = 17 (mod 12), since equivalence can only be said of common residues with the same
sign.
In computer science, it is the remainder operator that is usually indicated by either "%" (e.g.
in C, Java, Javascript, Perl and Python) or "mod" (e.g. in BASIC, SQL, Haskell), with
exceptions (e.g. Excel). These operators are commonly pronounced as "mod", but it is
specifically a remainder that is computed (since in C++ negative number will be returned if
the first argument is negative, and in Python a negative number will be returned if the second
argument is negative). The function modulo instead of mod, like 38 14 (modulo 12) is
sometimes used to indicate the common residue rather than a remainder (e.g. in Ruby).
Parentheses are sometimes dropped from the expression, e.g. 38 14 mod 12 or 2 = 14 mod
12, or placed around the divisor e.g. 38 14 mod (12). Notation such as 38(mod 12) has also
been observed, but is ambiguous without contextual clarification.

[edit] Functional representation of the remainder operation


The remainder operation can be represented using the floor function. If b a (mod n), where
n > 0, then if the remainder b is calculated

where

is the largest integer less than or equal to

, then

If instead a remainder b in the range n b < 0 is required, then

[edit] Applications
Modular arithmetic is referenced in number theory, group theory, ring theory, knot theory,
abstract algebra, cryptography, computer science, chemistry and the visual and musical arts.
It is one of the foundations of number theory, touching on almost every aspect of its study,
and provides key examples for group theory, ring theory and abstract algebra.
Modular arithmetic is often used to calculate checksums that are used within identifiers International Bank Account Numbers (IBANs) for example make use of modulo 97
arithmetic to trap user input errors in bank account numbers.

In cryptography, modular arithmetic directly underpins public key systems such as RSA and
Diffie-Hellman, as well as providing finite fields which underlie elliptic curves, and is used in
a variety of symmetric key algorithms including AES, IDEA, and RC4.
In computer science, modular arithmetic is often applied in bitwise operations and other
operations involving fixed-width, cyclic data structures. The modulo operation, as
implemented in many programming languages and calculators, is an application of modular
arithmetic that is often used in this context. XOR is the sum of 2 bits, modulo 2.
In chemistry, the last digit of the CAS registry number (a number which is unique for each
chemical compound) is a check digit, which is calculated by taking the last digit of the first
two parts of the CAS registry number times 1, the next digit times 2, the next digit times 3
etc., adding all these up and computing the sum modulo 10.
In music, arithmetic modulo 12 is used in the consideration of the system of twelve-tone
equal temperament, where octave and enharmonic equivalency occurs (that is, pitches in a 12
or 21 ratio are equivalent, and C-sharp is considered the same as D-flat).
The method of casting out nines offers a quick check of decimal arithmetic computations
performed by hand. It is based on modular arithmetic modulo 9, and specifically on the
crucial property that 10 1 (mod 9).
Arithmetic modulo 7 is especially important in determining the day of the week in the
Gregorian calendar. In particular, Zeller's congruence and the doomsday algorithm make
heavy use of modulo-7 arithmetic.
More generally, modular arithmetic also has application in disciplines such as law (see e.g.,
apportionment), economics, (see e.g., game theory) and other areas of the social sciences,
where proportional division and allocation of resources plays a central part of the analysis.

Modulo operation
From Wikipedia, the free encyclopedia
Jump to: navigation, search

Quotient (red) and remainder (green) functions using different algorithms.


In computing, the modulo operation finds the remainder of division of one number by
another.
Given two positive numbers, a (the dividend) and n (the divisor), a modulo n (abbreviated as
a mod n) can be thought of as the remainder, on division of a by n. For instance, the
expression "5 mod 4" would evaluate to 1 because 5 divided by 4 leaves a remainder of 1,
while "9 mod 3" would evaluate to 0 because the division of 9 by 3 leaves a remainder of 0;
there is nothing to subtract from 9 after multiplying 3 times 3. (Notice that doing the division
with a calculator won't show you the result referred to here by this operation, the quotient will
be expressed as a decimal.) When either a or n is negative, this naive definition breaks down
and programming languages differ in how these values are defined. Although typically
performed with a and n both being integers, many computing systems allow other types of
numeric operands. The range of numbers for an integer modulo of n is 0 to n - 1. (n mod 1 is
always 0; n mod 0 is undefined, possibly resulting in a "Division by zero" error in computer
programming languages) See modular arithmetic for an older and related convention applied
in number theory.

Contents
[hide]

1 Remainder calculation for the modulo operation

2 Common pitfalls

3 Modulo operation expression

4 Performance issues

5 See also

6 Notes

7 References

8 External links

[edit] Remainder calculation for the modulo operation


Integer modulo operators in
various programming
languages
Langua Operat Result

ge

or

ActionS %
cript
Ada
ASP

mod
rem
Mod

ALGOL %
-68
AMPL mod
AppleSc mod
ript
BASIC Mod
bc
bash

%
%

C (ISO %
1990)
C (ISO %
1999)
C++

%
C#
CLARI %
ON
Clojure mod
ColdFus %
ion
Commo mod
n Lisp rem

Eiffel \\
Erlang rem
mod

has the
same
sign as
Dividend
Divisor
Dividend
Not
defined
Always
positive
Dividend
Dividend
Not
defined
Dividend
Dividend
Impleme
ntation
defined
Dividend
Impleme
ntation
defined[1]
Dividend
Dividend
Divisor
Dividend
Divisor
Dividend
Dividend[
2]

Dividend
Dividend
Divisor

Euphori
remain
a
Dividend
der
FileMak Mod
er

Divisor

mod
Dividend
Fortran modulo
Divisor
mod
GML
Dividend
(Game

Maker)
%
Go
mod

Haskell rem
|~
J
%
Java
JavaScri %
pt
Just
MOD
Basic
Lua 5 %
Lua 4

mod(x,
y)

Liberty MOD
Basic
MathCa mod(x,
y)
d
Maple
e mod
(softwar m
e)
Mathem Mod
atica
Microso =MOD()
ft Excel
MATLA mod
rem
B
Oberon MOD
Objectiv mod
e Caml
Occam \
Pascal mod
(Delphi)
Pascal
(ISO7185
mod
and
ISO10206)
%
Perl
%
PHP
PL/I

mod

Dividend
Divisor
Dividend
Divisor
Dividend
Dividend
Dividend
Divisor
Divisor
Dividend
Divisor
Divisor
Divisor
Divisor
Divisor
Dividend
Divisor
Dividend
Dividend
Dividend

Always
positive
Divisor[1]
Dividend
Divisor
(ANSI
PL/I)

PowerB mod(x,
?
uilder y)
PowerS %
Dividend
hell

Progress modulo
Prolog mod
(ISO
rem
1995)
Python %
RealBas MOD
ic
%%
R
%REM
RPG
Ruby

Scheme

%,
modulu
s()
remain
der()
modulo
remain
der

Dividend
Divisor
Dividend
Divisor
Dividend
Divisor
Dividend
Divisor
Dividend
Divisor
Dividend

Always
positive[3]
Closest to
zero[3]
SenseTa modulo Divisor
rem
lk
Dividend
Smalltal \\
Divisor
k
SQL
mod(x,
(SQL:1 y)
Dividend
999)
mod
Divisor
Standar
mod

Scheme
R6RS mod0

d ML

Int.re
m

Dividend

Stata

mod(x,
y)

Tcl
Torque
Game
Engine
Turing
Verilog
(2001)

Always
positive
Divisor

Dividend

mod

Divisor

Dividend

mod
Divisor
VHDL rem
Dividend
Visual Mod
Dividend
Basic
x86
Assemb IDIV
Dividend
ly
Floating-point modulo
operators in various

programming languages
Resul
t has
Langu
the
Operator
age
same
sign
as
C (ISO fmod
?
1990)
Divid
fmod
end
C (ISO
Closes
1999) remainder
t to
zero
C++
(ISO std::fmod ?
1998)
Divid
std::fmod
end
C++
(ISO
Closes
std::remai
2011) nder
t to
zero
Divid
%
C#
end
Diviso
Comm mod
r
on
Divid
Lisp rem
end
%
D
?
Divid
mod
end
Fortran
Diviso
modulo
r
Divid
math.Fmod
Go
end
Haskel
Data.Fixed Diviso
l
.mod'
r
(GHC)
Divid
Java %
end
JavaSc %
Divid
ript
end
Objecti
Divid
mod_float
ve
end
Caml
POSIX::fmo Divid
Perl
d
end
fmod
PHP
Divid

end
Diviso
%
r
Python
Divid
math.fmod
end
%,
Diviso
modulus() r
Ruby
remainder( Divid
)
end
Alway
s
flmod
positi
Schem
ve
e R6RS
Closes
flmod0
t to
zero
Standa Real.rem Divid
rd ML
end
There are various ways of defining a remainder, and computers and calculators have various
ways of storing and representing numbers, so what exactly constitutes the result of a modulo
operation depends on the programming language and/or the underlying hardware.
In nearly all computing systems, the quotient q and the remainder r satisfy

This means, that if the remainder is nonzero, there are two possible choices for the remainder,
one negative and the other positive, and there are also two possible choices for the quotient.
Usually, in number theory, the positive remainder is always chosen, but programming
languages choose depending on the language and the signs of a and n.[2] However, Pascal and
Algol68 give a positive remainder (or 0) even for negative divisors, and some programming
languages, such as C89, don't even define a result if either of n or a is negative. See the table
for details. a modulo 0 is undefined in the majority of systems, although some do define it to
be a.
Many implementations use truncated division where the quotient is defined by truncation q
= trunc(a/n), in other words it is the first integer in the direction of 0 from the exact rational
quotient, and the remainder by r=a n q. Informally speaking the quotient is "rounded
towards zero", and the remainder therefore has the same sign as the dividend.
Knuth[4] described floored division where the quotient is defined by the floor function
q=floor(a/n) and the remainder r is

Here the quotient is always rounded downwards (even if it is already negative) and the
remainder has the same sign as the divisor.
Raymond T. Boute[5] introduces the Euclidean definition, which is the one in which the
remainder is always positive or 0, and is therefore consistent with the division algorithm. This
definition is marked as "Always positive" in the table. Let q be the integer quotient of a and
n, then:

Two corollaries are that

or, equivalently,

As described by Leijen,[6]
Boute argues that Euclidean division is superior to the other ones in terms of
regularity and useful mathematical properties, although floored division, promoted by
Knuth, is also a good definition. Despite its widespread use, truncated division is
shown to be inferior to the other definitions.
Common Lisp also defines round- and ceiling-division where the quotient is given by
q=round(a/n), q=ceil(a/n). IEEE 754 defines a remainder function where the quotient is a/n
rounded according to the round to nearest convention.

[edit] Common pitfalls


When the result of a modulo operation has the sign of the dividend, it can sometimes lead to
surprising mistakes:
For example, to test whether an integer is odd, one might be inclined to test whether the
remainder by 2 is equal to 1:
bool is_odd(int n) {
return n % 2 == 1;
}

But in a language where modulo has the sign of the dividend, that is incorrect, because when
n (the dividend) is negative and odd, n % 2 returns -1, and the function returns false.

One correct alternative is to test that it is not 0 (because remainder 0 is the same regardless of
the signs):
bool is_odd(int n) {
return n % 2 != 0;
}

[edit] Modulo operation expression


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 "%", "mod", or "Mod" as a modulo or remainder operator, such as
a % n

or
a mod n

or equivalent, for environments lacking a mod() function


a - (n * int(a/n)).

In most cases

means modulo function and not remainder function. For example

a mod n = n * floor(a/n);
16 mod 7 = 7 * floor(16/7) = 7 * floor(2.285714286) = 7 * 0.285714286
= 2;

this is because (16 mod 7) = 16 - 7 * 2 = 2.

[edit] Performance issues


Modulo operations might be implemented such that a division with a remainder is calculated
each time. For special cases, there are faster alternatives on some hardware. For example, the
modulo of powers of 2 can alternatively be expressed as a bitwise AND operation:
x % 2n == x & (2n - 1).

Examples (assuming x is a positive integer):


x % 2 == x & 1
x % 4 == x & 3
x % 8 == x & 7.

In devices and software that implement bitwise operations more efficiently than modulo,
these alternative forms can result in faster calculations.
Optimizing C compilers generally recognize expressions of the form expression %
constant where constant is a power of two and automatically implement them as
expression & (constant-1). This can allow the programmer to write clearer code without

compromising performance. (Note: This will not work for the languages whose modulo have
the sign of the dividend (including C), because if the dividend is negative, the modulo will be
negative; however, expression & (constant-1) will always produce a positive result. So
special treatment has to be made when the dividend is negative.)
In some compilers, the modulo operation is implemented as mod(a, n) = a - n *
floor(a / n). For example, mod(7, 3) = 7 - 3 * floor(7 / 3) = 7 - 3 *
floor(2.33) = 7 - 3 * 2 = 7 - 6 = 1.

[edit] See also

Modulo and modulo (jargon) many uses of the word "modulo", all of which grew
out of Carl F. Gauss's introduction of modular arithmetic in 1801.

[edit] Notes

^ Perl usually uses arithmetic modulo operator that is machine-independent. See the
Perl documentation for exceptions and examples.

^ Mathematically, these two choices are but two of the infinite number of choices
available for the inequality satisfied by a remainder.

[edit] References
1. ^ ISO/IEC 14882:2003 : Programming languages -- C++. 5.6.4: ISO, IEC. 2003.
"the binary % operator yields the remainder from the division of the first expression
by the second. .... If both operands are nonnegative then the remainder is nonnegative;
if not, the sign of the remainder is implementation-defined".
2. ^ "Expressions". D Programming Language 2.0. Digital Mars.
http://www.digitalmars.com/d/2.0/expression.html#MulExpression. Retrieved 29 July
2010.
3. ^ a b http://www.r6rs.org/final/html/r6rs/r6rs-Z-H-14.html#node_sec_11.7.3.1
4. ^ Knuth, Donald. E. (1972). The Art of Computer Programming. Addison-Wesley.
5. ^ Boute, Raymond T. (April 1992). "The Euclidean definition of the functions div and
mod". ACM Transactions on Programming Languages and Systems (TOPLAS) (ACM
Press (New York, NY, USA)) 14 (2): 127144. doi:10.1145/128861.128862.
http://portal.acm.org/citation.cfm?id=128862&coll=portal&dl=ACM.
6. ^ Leijen, Daan (December 3, 2001). "Division and Modulus for Computer Scientists"
(PDF). http://www.cs.uu.nl/~daan/download/papers/divmodnote.pdf. Retrieved 200608-27.

Modulo operasi
From Wikipedia, the free encyclopedia Dari Wikipedia, ensiklopedia bebas
Jump to: navigation , search Langsung ke: navigasi , cari

Quotient (red) and remainder (green) functions using different algorithms. Quotient (merah)
dan sisanya (hijau) fungsi dengan menggunakan algoritma yang berbeda.
In computing , the modulo operation finds the remainder of division of one number by
another. Dalam komputasi , operasi modulo menemukan sisa dari pembagian dari satu nomor
dengan yang lain.
Given two positive numbers, a (the dividend ) and n (the divisor ), a modulo n (abbreviated
as a mod n ) can be thought of as the remainder, on division of a by n . Mengingat dua
bilangan positif, (yang dividen ) dan n (yang pembagi ), n modulo (disingkat sebagai mod n)
dapat dianggap sebagai sisanya, pada pembagian oleh n. For instance, the expression "5 mod
4" would evaluate to 1 because 5 divided by 4 leaves a remainder of 1, while "9 mod 3"
would evaluate to 0 because the division of 9 by 3 leaves a remainder of 0; there is nothing to
subtract from 9 after multiplying 3 times 3. Misalnya, ungkapan "5 mod 4" akan
mengevaluasi ke 1 karena 5 dibagi dengan 4 daun sisa 1, sedangkan "9 mod 3" akan
mengevaluasi ke 0, karena pembagian 9 dengan 3 daun sisa 0; ada apa-apa untuk mengurangi
dari 9 setelah mengalikan 3 kali 3. (Notice that doing the division with a calculator won't
show you the result referred to here by this operation, the quotient will be expressed as a
decimal.) When either a or n is negative, this naive definition breaks down and programming
languages differ in how these values are defined. (Perhatikan bahwa melakukan divisi dengan
kalkulator tidak akan menunjukkan hasil yang disebut di sini dengan operasi ini, hasilbaginya
akan dinyatakan sebagai desimal.) Bila a atau n adalah negatif, definisi naif rusak dan bahasa
pemrograman yang berbeda dalam bagaimana nilai-nilai ini didefinisikan. Although typically
performed with a and n both being integers, many computing systems allow other types of
numeric operands. Meskipun biasanya dilakukan dengan baik dan n bilangan bulat sedang,
sistem komputasi banyak memungkinkan jenis lain dari operan numerik. The range of

numbers for an integer modulo of n is 0 to n - 1. Kisaran angka untuk integer modulo n


adalah 0 sampai n - 1. ( n mod 1 is always 0; n mod 0 is undefined, possibly resulting in a
"Division by zero" error in computer programming languages) See modular arithmetic for an
older and related convention applied in number theory . (N mod 1 adalah selalu 0, n mod 0
tidak terdefinisi, mungkin menghasilkan "Pembagian dengan nol" kesalahan dalam bahasa
pemrograman komputer) Lihat aritmatika modular untuk konvensi tua dan terkait diterapkan
di nomor teori .

Contents Isi
[hide]

1 Remainder calculation for the modulo operation 1 Sisa perhitungan untuk operasi
modulo

2 Common pitfalls 2 Umum perangkap

3 Modulo operation expression 3 Modulo operasi ekspresi

4 Performance issues 4 Masalah kinerja

5 See also 5 Lihat juga

6 Notes 6 Catatan

7 References 7 Referensi

8 External links 8 Pranala luar

[ edit ] Remainder calculation for the modulo operation [


sunting ] Perhitungan Remainder untuk operasi modulo
Integer modulo operators in
various programming
languages Integer modulo
operator di berbagai bahasa
pemrograman
Langua Operat Result
ge
or
has the
Bahasa Operat same
or
sign as
Hasil
memiliki
tanda
yang

sama
seperti
ActionS
cript
%%
ActionS
cript
Ada
Ada

ASP
ASP

mod mod
rem rem

Mod Mod

Dividend
Dividen
Divisor
Pembagi
Dividend
Dividen
Not
defined
Tidak
didefinisi
kan
Always
positive
Selalu
positif
Dividend
Dividen

ALGOL
-68
% %
ALGOL
-68
AMPL mod mod
AMPL
AppleSc
ript
Dividend
mod mod
AppleSc
Dividen
ript
Not
defined
BASIC Mod Mod
Tidak
DASAR
didefinisi
kan
Dividend
bc bc % %
Dividen
bash
Dividend
%%
pesta
Dividen
Impleme
ntation
C (ISO
defined
1990) C % %
Impleme
(ISO
ntasi
1990)
didefinisi
kan
C (ISO
1999) C % %
Dividend
(ISO
Dividen
1999)
C++ C % %
Impleme
++
ntation
defined [ 1
]

C# C # % %
CLARI
ON
%%
CLARI
ON
Clojure mod mod
Clojure
ColdFus
ion
%%
ColdFus
ion
Commo mod mod
n Lisp
Commo rem rem
n Lisp
DD

%%

Pelaksan
aan
didefinisi
kan [1]
Dividend
Dividen
Dividend
Dividen
Divisor
Pembagi
Dividend
Dividen
Divisor
Pembagi
Dividend
Dividen
Dividend
[2]

Dividen
[2]

Eiffel \\ \ \ Dividend
Eiffel
Dividen
Erlang rem rem Dividend
Erlang
Dividen
Divisor
Euphori mod mod Pembagi
a
remain
Dividend
Euforia der
Dividen
sisa
FileMak
er
Divisor
Mod Mod
FileMak
Pembagi
er
Dividend
mod mod
Dividen
Fortran
Fortran modulo Divisor
Modulo Pembagi
GML
(Game
Maker) mod mod Dividend
GML
Dividen
(Game
Maker)
Dividend
Go Go % %
Dividen

Divisor
mod mod
Pembagi
Haskell
Haskell rem rem Dividend
Dividen
Divisor
|~ | ~
JJ
Pembagi
Java
Dividend
%%
Jawa
Dividen
JavaScri
pt
Dividend
%%
JavaScri
Dividen
pt
Just
Basic MOD MOD Dividend
Hanya
Dividen
Dasar
Lua 5 % %
Divisor
Lua 5
Pembagi
Lua 4
Lua 4

mod(x,
y) mod
(x, y)

Liberty
Basic MOD MOD
Liberty
Dasar
MathCa
mod(x,
d
y) mod
Mathca (x, y)
d
Maple
(softwar
e)
e mod
Maple m e mod
(perang m
kat
lunak)
Mathem
atica
Mod Mod
Mathem
atica
Microso
=MOD()
ft Excel = MOD
Microso ()
ft Excel
MATLA mod mod
B
MATLA rem rem
B
Oberon MOD MOD

Divisor
Pembagi
Dividend
Dividen
Divisor
Pembagi

Divisor
Pembagi

Divisor
Pembagi
Divisor
Pembagi
Divisor
Pembagi
Dividend
Dividen
Divisor

Oberon
Objectiv
e Caml mod mod
Tujuan
CAML
Occam \ \
Occam
Pascal
(Delphi) mod mod
Pascal
(Delphi)
Pascal
(ISO7185
and
ISO10206) mod mod
Pascal
(ISO7185
dan
ISO10206)
Perl Perl % %

Pembagi
Dividend
Dividen
Dividend
Dividen
Dividend
Dividen

Always
positive
Selalu
positif

Divisor [1]
Pembagi
[1]

PHP
PHP
PL/I
PL / I

Dividend
Dividen
Divisor
(ANSI
PL/I)
mod mod
Pembagi
(ANSI
PL / I)
%%

PowerB
mod(x,
uilder y) mod
PowerB (x, y)
uilder
PowerS
hell
%%
PowerS
hell
Progress
modulo
Kemaju Modulo
an
Prolog mod mod
(ISO
1995) rem rem
Prolog

??

Dividend
Dividen
Dividend
Dividen
Divisor
Pembagi
Dividend
Dividen

(ISO
Python
%%
Ular
sanca
RealBas
ic
MOD MOD
RealBas
ic
RR
RPG
RPG

Ruby
Rubi

Divisor
Pembagi
Dividend
Dividen

Divisor
Pembagi
%REM % Dividend
REM
Dividen
%% %%

%,
modulu
s() %,
Modulu
s ()
remain
der()
sisany
a ()
modulo
Modulo

Divisor
Pembagi
Dividend
Dividen
Divisor
Pembagi

Scheme
Skema remain
Dividend
der
Dividen
sisa
mod mod

Scheme
R 6 RS
Skema
R 6 RS mod0
mod0

SenseTa modulo
Modulo
lk
SenseTa rem rem
lk
Smalltal
k
\\ \ \
Smalltal
k
SQL (
SQL:19
mod(x,
99 )
y) mod
SQL ( (x, y)
SQL:
1999 )
Standar mod mod

Always
positive
[3]
Selalu
positif [3]
Closest to
zero [ 3 ]
Terdekat
ke nol [3]
Divisor
Pembagi
Dividend
Dividen
Divisor
Pembagi

Dividend
Dividen
Divisor

Pembagi
d ML Int.re
Standar m
Dividend
Int.re Dividen
ML
m

Stata
Stata

mod(x,
y) mod
(x, y)

Tcl Tcl % %
Torque
Game
Engine
%%
Torsi
Mesin
Permain
an
Turing mod mod
Turing
Verilog
(2001) % %
Verilog
(2001)

Always
positive
Selalu
positif
Divisor
Pembagi

Dividend
Dividen

Divisor
Pembagi
Dividend
Dividen

Divisor
Pembagi
VHDL
VHDL rem rem Dividend
Dividen
Visual
Basic Mod Mod Dividend
Visual
Dividen
Basic
x86
Assemb
IDIV
Dividend
ly
IDIV
Dividen
Majelis
x86
Floating-point modulo
operators in various
programming languages
Floating-point modulo
operator dalam berbagai
bahasa pemrograman
Langu Operator Resul
age Operator t has
Bahas
the
a
same
sign
as
mod mod

Hasil
memil
iki
tanda
yang
sama
sepert
i
C (ISO
1990) fmod FMOD
C (ISO
1990)

??

Divid
end
fmod FMOD
Divid
en
C (ISO
1999)
Closes
C (ISO
t to
1999) remainder zero
sisa
Terde
kat ke
nol
C++
(ISO
1998) std::fmod
??
C + + std:: FMOD
(ISO
1998)
Divid
std::fmod end
C++ std:: FMOD Divid
en
(ISO
2011)
Closes
C++
t to
(ISO std::remai
zero
nder std::
2011) sisa
Terde
kat ke
nol
Divid
end
C# C # % %
Divid
en
Comm
Diviso
on
r
mod mod
Lisp
Pemb
Comm
agi
rem rem
on
Divid
Lisp
end
Divid

en
??
Divid
end
mod mod
Divid
en
Fortran
Fortran
Diviso
modulo
r
Modulo
Pemb
agi
Divid
math.Fmod end
Go Go math.Fmod
Divid
en
Haskel
l
Data.Fixed Diviso
(GHC) .mod'
r
Haskel Data.Fixed Pemb
.mod '
l
agi
(GHC)
Divid
Java % %
end
Jawa
Divid
en
JavaSc
Divid
ript
end
%%
JavaSc
Divid
ript
en
Objecti
Divid
ve
mod_float end
Caml mod_float
Divid
Tujuan
en
CAML
Divid
POSIX::fmo
Perl
end
d POSIX::
Perl
Divid
FMOD
en
Divid
PHP fmod FMOD end
PHP
Divid
en
Diviso
r
%%
Pemb
Python
agi
Ular
Divid
sanca
math.fmod end
math.fmod Divid
en
DD

%%

Diviso
r
Pemb
agi
Ruby
Rubi
Divid
remainder(
end
) sisanya
Divid
()
en
Alway
s
flmod
positi
flmod
ve
Schem
Selalu
eR6
positif
RS
Closes
Skema
t to
R 6 RS
flmod0
zero
flmod0
Terde
kat ke
nol
Standa
Divid
rd ML Real.rem end
Standa Real.rem Divid
r ML
en
%,
modulus()
%, Modulus
()

There are various ways of defining a remainder, and computers and calculators have various
ways of storing and representing numbers, so what exactly constitutes the result of a modulo
operation depends on the programming language and/or the underlying hardware . Ada
berbagai cara untuk mendefinisikan sisanya, dan komputer dan kalkulator memiliki berbagai
cara untuk menyimpan dan mewakili angka, jadi apa sebenarnya merupakan hasil dari
operasi modulo tergantung pada bahasa pemrograman dan / atau yang mendasari perangkat
keras .
In nearly all computing systems, the quotient q and the remainder r satisfy Dalam hampir
semua sistem komputasi, kecerdasan q dan r sisanya memuaskan

This means, that if the remainder is nonzero, there are two possible choices for the remainder,
one negative and the other positive, and there are also two possible choices for the quotient.
Ini berarti, bahwa jika sisanya adalah nol, ada dua pilihan yang mungkin untuk sisanya, satu
negatif dan yang positif lainnya, dan ada juga dua pilihan yang mungkin untuk hasil bagi.
Usually, in number theory, the positive remainder is always chosen, but programming
languages choose depending on the language and the signs of a and n . [2] However, Pascal
and Algol68 give a positive remainder (or 0) even for negative divisors, and some
programming languages, such as C89, don't even define a result if either of n or a is negative.
Biasanya, di nomor teori, sisanya positif selalu dipilih, tapi bahasa pemrograman memilih

tergantung pada bahasa dan tanda-tanda dan n. [2] Namun, Pascal dan Algol68 memberikan
sisanya positif (atau 0) bahkan untuk pembagi negatif, dan bahasa pemrograman beberapa,
seperti C89, bahkan tidak menentukan hasil jika salah satu dari n atau negatif. See the table
for details. a modulo 0 is undefined in the majority of systems, although some do define it to
be a . Lihat tabel untuk rincian. Sebuah Modulo 0 is undefined dalam sistem mayoritas,
meskipun beberapa melakukan define itu menjadi.
Many implementations use truncated division where the quotient is defined by truncation q
= trunc( a / n ), in other words it is the first integer in the direction of 0 from the exact
rational quotient, and the remainder by r = a n q . Banyak implementasi menggunakan
pembagian terpotong mana kecerdasan didefinisikan oleh pemotongan q = trunc (a / n),
dengan kata lain itu adalah integer pertama dalam arah 0 dari kecerdasan rasional yang tepat,
dan sisanya oleh r = a - n q . Informally speaking the quotient is "rounded towards zero", and
the remainder therefore has the same sign as the dividend. Hasilbagi berbicara informal
adalah "bulat menuju nol", dan sisanya oleh karena itu memiliki tanda yang sama sebagai
dividen.
Knuth [ 4 ] described floored division where the quotient is defined by the floor function q
=floor( a / n ) and the remainder r is Knuth [4] dijelaskan divisi mana berlantai hasilbagi
didefinisikan oleh fungsi lantai lantai q = (a / n) dan r adalah sisanya

Here the quotient is always rounded downwards (even if it is already negative) and the
remainder has the same sign as the divisor. Berikut hasil bagi selalu dibulatkan ke bawah
(bahkan jika itu sudah negatif) dan sisanya memiliki tanda yang sama sebagai pembagi.
Raymond T. Boute [ 5 ] introduces the Euclidean definition , which is the one in which the
remainder is always positive or 0, and is therefore consistent with the division algorithm .
Raymond T. Boute [5] memperkenalkan definisi Euclidean, yang merupakan satu di mana
sisanya selalu positif atau 0, dan karena itu konsisten dengan algoritma pembagian . This
definition is marked as "Always positive" in the table. Definisi ini ditandai sebagai "Selalu
positif" dalam tabel. Let q be the integer quotient of a and n , then: Biarkan q adalah hasil
bagi bilangan bulat a dan n, maka:

Two corollaries are that Dua kololari adalah bahwa

or, equivalently, atau, ekuivalen,

As described by Leijen, [ 6 ] Seperti dijelaskan oleh Leijen, [6]


Boute argues that Euclidean division is superior to the other ones in terms of
regularity and useful mathematical properties, although floored division, promoted by
Knuth, is also a good definition. Boute berpendapat bahwa pembagian Euclidean
adalah lebih unggul dari yang lain dalam hal keteraturan dan sifat matematika yang
berguna, meskipun berlantai divisi, dipromosikan oleh Knuth, juga merupakan
definisi yang baik. Despite its widespread use, truncated division is shown to be
inferior to the other definitions. Meskipun digunakan secara luas, divisi terpotong
ditampilkan akan kalah dengan definisi lainnya.
Common Lisp also defines round- and ceiling-division where the quotient is given by q
=round( a / n ) , q=ceil( a / n ) . IEEE 754 defines a remainder function where the quotient is
a / n rounded according to the round to nearest convention . Common Lisp juga
mendefinisikan bulat dan langit-langit-divisi mana kecerdasan yang diberikan oleh q = bulat
(a / n), q = ceil (a / n). IEEE 754 mendefinisikan fungsi sisa di mana hasil bagi adalah / n
dibulatkan sesuai dengan yang bulat untuk konvensi terdekat .

[ edit ] Common pitfalls [ sunting ] perangkap Umum


When the result of a modulo operation has the sign of the dividend, it can sometimes lead to
surprising mistakes: Ketika hasil dari operasi modulo memiliki tanda dividen, kadang-kadang
dapat menyebabkan kesalahan mengejutkan:
For example, to test whether an integer is odd, one might be inclined to test whether the
remainder by 2 is equal to 1: Misalnya, untuk menguji apakah integer ganjil, satu mungkin
cenderung untuk menguji apakah sisanya oleh 2 adalah sama dengan 1:
bool is_odd ( int n ) { is_odd bool (int n) {
return n % 2 == 1 ; kembali n% 2 == 1;
} }

But in a language where modulo has the sign of the dividend, that is incorrect, because when
n (the dividend) is negative and odd, n % 2 returns -1, and the function returns false. Namun
dalam bahasa dimana modulo memiliki tanda dividen, yang tidak benar, karena jika n
(dividen) adalah negatif dan aneh, n% 2 kembali -1, dan fungsi mengembalikan palsu.
One correct alternative is to test that it is not 0 (because remainder 0 is the same regardless of
the signs): Salah satu alternatif yang benar adalah untuk menguji bahwa tidak 0 (karena
sisanya 0 adalah sama terlepas dari tanda-tanda):
bool is_odd ( int n ) { is_odd bool (int n) {
return n % 2 ! = 0 ; kembali n% 2 = 0;!
} }

[ edit ] Modulo operation expression [ sunting ] Modulo


ekspresi operasi
Some calculators have a mod() function button, and many programming languages have a
mod() function or similar, expressed as mod( a , n ), for example. Beberapa kalkulator
memiliki mod () fungsi tombol, dan banyak bahasa pemrograman memiliki mod () fungsi
atau serupa, dinyatakan sebagai mod (a, n), misalnya. Some also support expressions that use
"%", "mod", or "Mod" as a modulo or remainder operator , such as Beberapa juga
mendukung ekspresi yang menggunakan "%", "mod", atau "Mod" sebagai modulo atau sisa
Operator , seperti
a % n

or atau
a mod n

or equivalent, for environments lacking a mod() function atau setara, untuk lingkungan
kurang mod () fungsi
a - (n * int(a/n)) . a - (n * int(a/n))

In most cases Dalam kasus yang paling


means modulo function and not
remainder function. berarti fungsi modulo dan tidak berfungsi sisanya. For example Sebagai
contoh
a mod n = n * floor(a/n) ; a mod n = n * floor(a/n) ;
16 mod 7 = 7 * floor(16/7) = 7 * floor(2.285714286) = 7 * 0.285714286
= 2 ; 16 mod 7 = 7 * floor(16/7) = 7 * floor(2.285714286) = 7 *
0.285714286 = 2 ;

this is because (16 mod 7) = 16 - 7 * 2 = 2. ini adalah karena (16 mod 7) = 16 - 7 * 2


= 2.

[ edit ] Performance issues [ sunting ] Masalah kinerja


Modulo operations might be implemented such that a division with a remainder is calculated
each time. Modulo operasi mungkin dilaksanakan sedemikian rupa sehingga pembagian
dengan sisa yang dihitung setiap kali. For special cases, there are faster alternatives on some
hardware. Untuk kasus khusus, ada alternatif lebih cepat pada beberapa hardware. For
example, the modulo of powers of 2 can alternatively be expressed as a bitwise AND
operation: Sebagai contoh, modulo kekuatan dari 2 alternatif dapat dinyatakan sebagai
bitwise DAN operasi:
x % 2

== x & (2

- 1) . x % 2

== x & (2

- 1)

Examples (assuming x is a positive integer): Contoh (dengan asumsi x adalah bilangan bulat
positif):
x % 2 == x & 1

x % 4 == x & 3
x % 8 == x & 7 . x % 8 == x & 7

In devices and software that implement bitwise operations more efficiently than modulo,
these alternative forms can result in faster calculations. Dalam perangkat dan software yang
melaksanakan operasi bitwise lebih efisien daripada Modulo, bentuk-bentuk alternatif dapat
menghasilkan perhitungan lebih cepat.
Optimizing C compilers generally recognize expressions of the form expression %
constant where constant is a power of two and automatically implement them as
expression & (constant-1) . Mengoptimalkan C compiler umumnya mengakui ekspresi
bentuk expression % constant mana constant adalah kekuatan dari dua dan secara
otomatis menerapkan mereka sebagai expression & (constant-1) . This can allow the
programmer to write clearer code without compromising performance. Hal ini dapat
memungkinkan programmer untuk menulis kode yang lebih jelas tanpa mengorbankan
kinerja. (Note: This will not work for the languages whose modulo have the sign of the
dividend (including C), because if the dividend is negative, the modulo will be negative;
however, expression & (constant-1) will always produce a positive result. So special
treatment has to be made when the dividend is negative.) (Catatan: Ini tidak akan bekerja
untuk bahasa yang modulo memiliki tanda dividen (termasuk C), karena jika dividen adalah
negatif, Modulo akan negatif, namun, expression & (constant-1) akan selalu
menghasilkan positif hasilnya. Jadi perlakuan khusus harus dibuat ketika dividen adalah
negatif.)
In some compilers, the modulo operation is implemented as mod(a, n) = a - n *
floor(a / n) . Pada beberapa compiler, modulo operasi diimplementasikan sebagai mod(a,
n) = a - n * floor(a / n) . For example, mod(7, 3) = 7 - 3 * floor(7 / 3) = 7
- 3 * floor(2.33) = 7 - 3 * 2 = 7 - 6 = 1. Sebagai contoh, mod(7, 3) = 7 - 3 *
floor(7 / 3) = 7 - 3 * floor(2.33) = 7 - 3 * 2 = 7 - 6 = 1.

Aritmatika modular
From Wikipedia, the free encyclopedia Dari Wikipedia, ensiklopedia bebas
Jump to: navigation , search Langsung ke: navigasi , cari
In mathematics , modular arithmetic (sometimes called clock arithmetic ) is a system of
arithmetic for integers , where numbers "wrap around" after they reach a certain valuethe
modulus . Dalam matematika , aritmatika modular (kadang-kadang disebut aritmatika
jam) adalah sistem aritmatika untuk bilangan bulat , di mana angka "membungkus" setelah
mereka mencapai nilai-modulus tertentu.
The Swiss mathematician Leonhard Euler pioneered the modern approach to congruence in
about 1750, when he explicitly introduced the idea of congruence modulo a number N . [ 1 ]
Para matematikawan Swiss Leonhard Euler memelopori pendekatan modern untuk
kongruensi di sekitar tahun 1750, ketika ia secara eksplisit memperkenalkan ide kongruensi
modulo nomor N. [1]
Modular arithmetic was further advanced by Carl Friedrich Gauss in his book Disquisitiones
Arithmeticae , published in 1801. Aritmatika modular lebih lanjut dikemukakan oleh Carl
Friedrich Gauss dalam bukunya Disquisitiones Arithmeticae , diterbitkan pada tahun 1801.

Time-keeping on this clock uses arithmetic modulo 12. Waktu menjaga pada jam ini
menggunakan aritmatika modulo 12.
A familiar use of modular arithmetic is in the 12-hour clock , in which the day is divided into
two 12-hour periods. Sebuah penggunaan akrab aritmatika modular dalam waktu 12-jam , di
mana hari ini dibagi menjadi dua 12-jam periode. If the time is 7:00 now, then 8 hours later it
will be 3:00. Jika waktu adalah 7:00 sekarang, kemudian 8 jam kemudian itu akan 3:00.
Usual addition would suggest that the later time should be 7 + 8 = 15, but this is not the
answer because clock time "wraps around" every 12 hours; in 12-hour time, there is no "15
o'clock". Selain itu biasanya akan menyarankan bahwa waktu selanjutnya harus 7 + 8 = 15,
tetapi ini tidak menjawab karena waktu jam "membungkus" setiap 12 jam, dalam waktu 12jam, tidak ada "15 jam". Likewise, if the clock starts at 12:00 (noon) and 21 hours elapse,
then the time will be 9:00 the next day, rather than 33:00. Demikian juga, jika jam dimulai
pada 12:00 (siang) dan 21 jam berlalu, maka waktu akan 9:00 hari berikutnya, bukan 33:00.
Since the hour number starts over after it reaches 12, this is arithmetic modulo 12. Karena
jumlah jam mulai berakhir setelah mencapai 12, aritmatika modulo ini adalah 12. 12 is
congruent not only to 12 itself, but also to 0, so the time called "12:00" could also be called
"0:00", since 0 12 mod 12. 12 adalah kongruen tidak hanya untuk 12 itu sendiri, tetapi juga
untuk 0, sehingga waktu yang disebut "12:00" juga bisa disebut "0:00", karena 0 12 mod
12.

Contents Isi
[hide]

1 Congruence relation 1 Kesesuaian hubungan

2 Ring of congruence classes 2 Cincin kelas kongruensi

3 Remainders 3 Remainders
o 3.1 Functional representation of the remainder operation 3,1 Fungsional
representasi dari operasi sisa

4 Applications 4 Aplikasi

5 Computational complexity 5 Komputasi kompleksitas

6 See also 6 Lihat juga

7 Notes 7 Catatan

8 References 8 Referensi

9 External links 9 Pranala luar

[ edit ] Congruence relation [ sunting ] hubungan


Kongruensi
Modular arithmetic can be handled mathematically by introducing a congruence relation on
the integers that is compatible with the operations of the ring of integers: addition ,
subtraction , and multiplication . Aritmatika modular dapat ditangani matematis dengan
memperkenalkan relasi kongruensi pada bilangan bulat yang kompatibel dengan operasi
cincin dari bilangan bulat: Selain itu , pengurangan , dan perkalian . For a positive integer n ,
two integers a and b are said to be congruent modulo n , written: Untuk bilangan bulat
positif n, dua bilangan bulat a dan b dikatakan kongruen modulo n, ditulis:

if their difference a b is an integer multiple of n . jika perbedaan mereka a - b adalah


bilangan bulat ganda n. The number n is called the modulus of the congruence. Jumlah n
disebut modulus kongruensi tersebut.
For example, Sebagai contoh,

because 38 2 = 36, which is a multiple of 12. karena 38-2 = 36, yang merupakan kelipatan
dari 12.
The same rule holds for negative values: Aturan yang sama berlaku untuk nilai negatif:

When a and b are either both positive or both negative, then Ketika a dan b adalah baik baik
positif atau keduanya negatif, maka
can also be thought of as asserting
that both a / n and b / n have the same remainder . juga dapat dianggap sebagai menyatakan
bahwa kedua a / n dan b / n yang sama memiliki sisanya . For instance: Sebagai contoh:

because both 38 / 12 and 14 / 12 have the same remainder, 2 . karena kedua 38 / 12 dan 14 /
12 memiliki sisa yang sama, 2. It is also the case that 38 14 = 24 is an integer multiple of

12 , which agrees with the prior definition of the congruence relation. Hal ini juga terjadi
bahwa 38-14 = 24 merupakan kelipatan integer dari 12, yang setuju dengan definisi
sebelumnya hubungan kongruensi.
A remark on the notation: Because it is common to consider several congruence relations for
different moduli at the same time, the modulus is incorporated in the notation. Sebuah
komentar pada notasi: Karena itu adalah umum untuk mempertimbangkan hubungan
kongruensi beberapa modulus yang berbeda pada saat yang sama, modulus yang tergabung
dalam notasi. In spite of the ternary notation, the congruence relation for a given modulus is
binary . Terlepas dari notasi terner, hubungan kecocokan untuk modulus diberikan biner .
This would have been clearer if the notation a n b had been used, instead of the common
traditional notation. Ini akan lebih jelas jika notasi a b n telah digunakan, bukan notasi
tradisional umum.
The properties that make this relation a congruence relation (respecting addition, subtraction,
and multiplication) are the following. Sifat-sifat yang membuat relasi relasi kongruensi
(penambahan menghormati, pengurangan, dan perkalian) adalah sebagai berikut.
If Jika

and dan

then: maka:

It should be noted that the above two properties would still hold if the theory were expanded
to include all real numbers , that is if Perlu dicatat bahwa dua di atas properti masih akan
terus jika teori diperluas untuk mencakup semua bilangan real , yaitu jika
were not necessarily all integers. tidak selalu semua bilangan bulat. The next property,
however, would fail if these variables were not all integers: Properti berikutnya,
bagaimanapun, akan gagal jika variabel-variabel ini tidak semua bilangan bulat:

[ edit ] Ring of congruence classes [ sunting ] Cincin kelas


kongruensi
Like any congruence relation, congruence modulo n is an equivalence relation , and the
equivalence class of the integer a , denoted by Seperti semua hubungan kongruensi,
kongruensi modulo n adalah relasi ekivalen , dan kelas kesetaraan dari integer, dinotasikan

dengan , is the set , Adalah mengatur


. . This set, consisting of the integers congruent to a modulo n , is called the congruence
class or residue class or simply residue of the integer a , modulo n . Ini set, terdiri dari
bilangan bulat yang kongruen dengan n modulo, disebut kelas kongruensi atau kelas residu
atau hanya residu dari integer, modulo n. When the modulus n is known from the context,
that residue may also be denoted Ketika n modulus dikenal dari konteks, residu yang
mungkin juga akan dilambangkan . .
The set of all congruence classes modulo n is denoted Himpunan semua kelas kongruensi
modulo n dilambangkan
or atau
(the alternate notation (Notasi alternatif
is
not recommended because of the possible confusion with the set of n-adic integers ). tidak
dianjurkan karena kebingungan mungkin dengan set n-adic bilangan bulat ). It is defined by:
Hal ini didefinisikan oleh:

When n 0, Jika n 0,
dapat ditulis sebagai:

has n elements, and can be written as: memiliki n elemen, dan

When n = 0, Jika n = 0,
does not have zero elements; rather, it is isomorphic to tidak
memiliki elemen nol, melainkan adalah isomorfik untuk , since , Karena
..
We can define addition, subtraction, and multiplication on Kita dapat menentukan
penambahan, pengurangan, dan perkalian pada
sebagai berikut:

by the following rules: dengan aturan

The verification that this is a proper definition uses the properties given before. Verifikasi
bahwa ini adalah definisi yang tepat menggunakan sifat yang diberikan sebelumnya.
In this way, Dengan cara ini,

becomes a commutative ring . menjadi cincin komutatif .

For example, in the ring Sebagai contoh, di ring

, we have , Kami telah

as in the arithmetic for the 24-hour clock. seperti dalam aritmatika untuk jam 24-jam.

The notation Notasi


is used, because it is the factor ring of digunakan, karena itu
adalah cincin faktor dari by the ideal oleh yang ideal
containing all integers divisible by
n , where mengandung semua bilangan bulat dibagi dengan n, di mana
is the singleton set
adalah diatur tunggal
. . Thus Jadi
is a field when adalah bidang yang saat
is a
maximal ideal , that is, when n is prime. adalah maksimal yang ideal , yaitu ketika n adalah
prima.
In terms of groups, the residue class Dalam hal kelompok, kelas residu
the quotient group adalah koset dari dalam kelompok kecerdasan
[2]
, Sebuah kelompok siklik . [2]

is the coset of a in
, a cyclic group .

The set Mengatur


has a number of important mathematical properties that are
foundational to various branches of mathematics. memiliki sejumlah sifat matematika penting
yang mendasar bagi berbagai cabang matematika.
Rather than excluding the special case n = 0, it is more useful to include Daripada tidak
termasuk kasus khusus n = 0, itu lebih berguna untuk memasukkan
(which, as
mentioned before, is isomorphic to the ring (Yang, seperti disebutkan sebelumnya, adalah
isomorfis ke ring of integers), for example when discussing the characteristic of a ring . dari
bilangan bulat), misalnya ketika membahas karakteristik dari sebuah cincin .

[ edit ] Remainders [ sunting ] Remainders


The notion of modular arithmetic is related to that of the remainder in division . Gagasan
aritmatika modular terkait dengan bahwa dari sisanya di divisi . The operation of finding the
remainder is sometimes referred to as the modulo operation and we may see 2 = 14 (mod
12) . Operasi untuk menemukan sisanya kadang-kadang disebut sebagai operasi modulo dan
kita dapat melihat 2 = 14 (mod 12). The difference is in the use of congruency, indicated by
"", and equality indicated by "=". Perbedaannya adalah dalam penggunaan kongruensi,
ditandai dengan "", dan kesetaraan ditunjukkan oleh "=". Equality implies specifically the
"common residue", the least non-negative member of an equivalence class. Kesetaraan berarti
khususnya "residu umum", setidaknya anggota non-negatif dari sebuah kelas kesetaraan.
When working with modular arithmetic, each equivalence class is usually represented by its
common residue, for example 38 2 (mod 12) which can be found using long division .
Ketika bekerja dengan aritmatika modular, masing-masing kelas kesetaraan biasanya diwakili
oleh residu umum, misalnya 38 2 (mod 12) yang dapat ditemukan menggunakan
pembagian panjang . It follows that, while it is correct to say 38 14 (mod 12) , and 2 14
(mod 12) , it is incorrect to say 38 = 14 (mod 12) (with "=" rather than ""). Oleh karena itu,
ketika sedang benar untuk mengatakan 38 14 (mod 12), dan 2 14 (mod 12), adalah salah
untuk mengatakan 38 = 14 (mod 12) (dengan "=" daripada "") .
The difference is clearest when dividing a negative number, since in that case remainders are
negative. Perbedaannya adalah jelas ketika membagi angka negatif, karena dalam kasus yang
sisa adalah negatif. Hence to express the remainder we would have to write 5 17 (mod
12) , rather than 7 = 17 (mod 12) , since equivalence can only be said of common residues
with the same sign. Oleh karena itu untuk mengekspresikan sisanya kita harus menulis -5 -17
(mod 12), daripada 7 = -17 (mod 12), karena kesetaraan hanya dapat dikatakan residu
umum dengan tanda yang sama.

In computer science , it is the remainder operator that is usually indicated by either "%" (eg in
C , Java , Javascript , Perl and Python ) or "mod" (eg in BASIC , SQL , Haskell ), with
exceptions (eg Excel). Dalam ilmu komputer , itu adalah operator sisanya yang biasanya
ditunjukkan dengan baik "%" (misalnya di C , Java , Javascript , Perl dan Python ) atau
"mod" (misalnya di BASIC , SQL , Haskell ), dengan pengecualian (misalnya Excel ). These
operators are commonly pronounced as "mod", but it is specifically a remainder that is
computed (since in C++ negative number will be returned if the first argument is negative,
and in Python a negative number will be returned if the second argument is negative).
Operator ini biasanya diucapkan sebagai "mod", tetapi secara khusus suatu sisa yang dihitung
(karena di C + + angka negatif akan dikembalikan jika argumen pertama adalah negatif, dan
dengan Python angka negatif akan dikembalikan jika argumen kedua adalah negatif ). The
function modulo instead of mod , like 38 14 (modulo 12) is sometimes used to indicate the
common residue rather than a remainder (eg in Ruby ). Fungsi Modulo bukan mod, seperti 38
14 (modulo 12) kadang-kadang digunakan untuk menunjukkan residu umum daripada
sisanya (misalnya di Ruby ).
Parentheses are sometimes dropped from the expression, eg 38 14 mod 12 or 2 = 14 mod
12 , or placed around the divisor eg 38 14 mod (12) . Kurung kadang-kadang jatuh dari
ekspresi, misalnya 38 14 mod 12 atau 2 = 14 mod 12, atau ditempatkan di sekitar misalnya
pembagi 38 14 mod (12). Notation such as 38(mod 12) has also been observed, but is
ambiguous without contextual clarification. Notasi seperti 38 (mod 12) juga telah diamati,
tetapi ambigu tanpa klarifikasi kontekstual.

[ edit ] Functional representation of the remainder operation [ sunting ]


Fungsional representasi dari operasi sisa
The remainder operation can be represented using the floor function . Operasi sisanya dapat
direpresentasikan dengan menggunakan fungsi lantai . If b a (mod n ), where n > 0, then if
the remainder b is calculated Jika b a (mod n), dimana n> 0, maka jika b sisanya dihitung

where mana

is the largest integer less than or equal to adalah bilangan bulat terbesar

kurang dari atau sama dengan

, then , Kemudian

If instead a remainder b in the range n b < 0 is required, then Jika bukan b sisanya dalam
kisaran-n b <0 diperlukan, maka

Das könnte Ihnen auch gefallen