Post on 14-Dec-2015
description
Modular arithmeticFrom Wikipedia, the free encyclopediaJump 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 value—the 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 , since
.
We can define addition, subtraction, and multiplication on 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 by the ideal containing all
integers divisible by n, where is the singleton set . Thus is a field when is a maximal ideal, that is, when n is prime.
In terms of groups, the residue class is the coset of a in the quotient group , a cyclic group.[2]
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 1∶2 or 2∶1 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 operationFrom Wikipedia, the free encyclopediaJump 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
Language
Operator
Result has the same
sign asActionScript
% Dividend
Adamod Divisorrem Dividend
ASP Mod Not defined
ALGOL-68
%× Always positive
AMPL mod DividendAppleScript
mod Dividend
BASIC Mod Not defined
bc % Dividendbash % Dividend
C (ISO 1990)
%Implementation defined
C (ISO 1999)
% Dividend
C++ %Implementation defined[1]
C# % DividendCLARION
% Dividend
Clojure mod DivisorColdFusion
% Dividend
Common Lisp
mod Divisorrem Dividend
D % Dividend[2]
Eiffel \\ DividendErlang rem Dividend
Euphoria
mod Divisorremainder Dividend
FileMaker
Mod Divisor
Fortranmod Dividendmodulo Divisor
GML (Game Maker)
mod Dividend
Go % Dividend
Haskellmod Divisorrem Dividend
J |~ DivisorJava % DividendJavaScript
% Dividend
Just Basic
MOD Dividend
Lua 5 % Divisor
Lua 4mod(x,y) Divisor
Liberty Basic
MOD Dividend
MathCad
mod(x,y) Divisor
Maple (software)
e mod m Divisor
Mathematica
Mod Divisor
Microsoft Excel
=MOD() Divisor
MATLAB
mod Divisorrem Dividend
Oberon MOD DivisorObjective Caml
mod Dividend
Occam \ DividendPascal (Delphi)
mod Dividend
Pascal (ISO-7185 and ISO-10206)
mod Always positive
Perl % Divisor[1]
PHP % Dividend
PL/I modDivisor (ANSI PL/I)
PowerBuilder
mod(x,y) ?
PowerShell
% Dividend
Progress modulo DividendProlog (ISO 1995)
mod Divisor
rem Dividend
Python % DivisorRealBasic
MOD Dividend
R %% DivisorRPG %REM Dividend
Ruby
%, modulus()
Divisor
remainder() Dividend
Schememodulo Divisorremainder Dividend
Scheme R6RS
mod Always positive[3]
mod0 Closest to zero[3]
SenseTalk
modulo Divisorrem Dividend
Smalltalk
\\ Divisor
SQL (SQL:1999)
mod(x,y) Dividend
Standar mod Divisor
d MLInt.rem Dividend
Statamod(x,y)
Always positive
Tcl % DivisorTorque Game Engine
% Dividend
Turing mod DivisorVerilog (2001)
% Dividend
VHDLmod Divisorrem Dividend
Visual Basic
Mod Dividend
x86 Assembly
IDIV Dividend
Floating-point modulo operators in various
programming languages
Language
Operator
Result has the
same sign as
C (ISO 1990)
fmod ?
C (ISO 1999)
fmod Dividend
remainderClosest to zero
C++ (ISO 1998)
std::fmod ?
C++ (ISO 2011)
std::fmod Dividend
std::remainder
Closest to zero
C# % Dividend
Common Lisp
mod Divisor
rem Dividend
D % ?
Fortranmod Divid
end
modulo Divisor
Go math.Fmod Dividend
Haskell (GHC)
Data.Fixed.mod'
Divisor
Java % Dividend
JavaScript
% Dividend
Objective Caml
mod_float Dividend
PerlPOSIX::fmod
Dividend
PHP fmod Dividend
Python% Diviso
r
math.fmod Dividend
Ruby
%, modulus()
Divisor
remainder()
Dividend
Scheme R6RS
flmod
Always positive
flmod0Closest to zero
Standard ML
Real.rem Dividend
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 & 1x % 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.14. 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): 127–144. 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 2006-08-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
ge Bahasa
Operator
Operator
Result has the same
sign as Hasil
memiliki tanda yang sama
seperti ActionScript ActionScript
% % Dividend Dividen
Ada Ada
mod mod Divisor Pembagi
rem rem Dividend Dividen
ASP ASP
Mod Mod
Not defined Tidak didefinisikan
ALGOL-68 ALGOL-68
%× % ×
Always positive Selalu positif
AMPL AMPL
mod mod Dividend Dividen
AppleScript AppleScript
mod mod Dividend Dividen
BASIC DASAR
Mod Mod
Not defined Tidak didefinisikan
bc bc % % Dividend Dividen
bash pesta
% % Dividend Dividen
C (ISO 1990) C (ISO 1990)
% %
Implementation defined Implementasi didefinisikan
C (ISO 1999) C (ISO 1999)
% % Dividend Dividen
C++ C % % Impleme
+ +
ntation defined [ 1
] Pelaksanaan didefinisikan [1]
C# C # % % Dividend Dividen
CLARION CLARION
% % Dividend Dividen
Clojure Clojure
mod mod Divisor Pembagi
ColdFusion ColdFusion
% % Dividend Dividen
Common Lisp Common Lisp
mod mod Divisor Pembagi
rem rem Dividend Dividen
D D % %
Dividend [ 2 ] Dividen [2]
Eiffel Eiffel
\\ \ \ Dividend Dividen
Erlang Erlang
rem rem Dividend Dividen
Euphoria Euforia
mod mod Divisor Pembagi
remain
der sisa
Dividend Dividen
FileMaker FileMaker
Mod Mod Divisor Pembagi
Fortran Fortran
mod mod Dividend Dividen
modulo Modulo
Divisor Pembagi
GML (Game Maker) GML
mod mod Dividend Dividen
(Game Maker)
Go Go % % Dividend Dividen
Haskell Haskell
mod mod Divisor Pembagi
rem rem Dividend Dividen
J J |~ | ~ Divisor Pembagi
Java Jawa
% % Dividend Dividen
JavaScript JavaScript
% % Dividend Dividen
Just Basic Hanya Dasar
MOD MOD Dividend Dividen
Lua 5 Lua 5
% % Divisor Pembagi
Lua 4 Lua 4
mod(x,
y) mod (x, y)
Divisor Pembagi
Liberty Basic Liberty Dasar
MOD MOD Dividend Dividen
MathCad Mathcad
mod(x,
y) mod (x, y)
Divisor Pembagi
Maple (software) Maple (perangkat lunak)
e mod
m e mod m
Divisor Pembagi
Mathematica Mathematica
Mod Mod Divisor Pembagi
Microsoft Excel Microsoft Excel
=MOD() = MOD
()
Divisor Pembagi
MATLAB MATLAB
mod mod Divisor Pembagi
rem rem Dividend Dividen
Oberon Oberon
MOD MOD Divisor Pembagi
Objective Caml Tujuan CAML
mod mod Dividend Dividen
Occam Occam
\ \ Dividend Dividen
Pascal (Delphi) Pascal (Delphi)
mod mod Dividend Dividen
Pascal (ISO-7185 and ISO-10206) Pascal (ISO-7185 dan ISO-10206)
mod mod
Always positive Selalu positif
Perl Perl % % Divisor [1]
Pembagi [1]
PHP PHP
% % Dividend Dividen
PL/I PL / I
mod mod
Divisor (ANSI PL/I) Pembagi (ANSI PL / I)
PowerBuilder PowerBuilder
mod(x,
y) mod (x, y)
? ?
PowerShell PowerShell
% % Dividend Dividen
Progress Kemaju
modulo Modulo
Dividend Dividen
an Prolog (ISO 1995) Prolog (ISO 1995)
mod mod Divisor Pembagi
rem rem Dividend Dividen
Python Ular sanca
% % Divisor Pembagi
RealBasic RealBasic
MOD MOD Dividend Dividen
R R %% %% Divisor Pembagi
RPG RPG
%REM % REM
Dividend Dividen
Ruby Rubi
%, modulu
s() %, Modulu
s ()
Divisor Pembagi
remain
der() sisany
a ()
Dividend Dividen
Scheme Skema
modulo Modulo
Divisor Pembagi
remain
der sisa
Dividend Dividen
Scheme R 6 RS Skema R 6 RS
mod mod
Always positive [ 3 ] Selalu positif [3]
mod0 mod0
Closest to zero [ 3 ] Terdekat ke nol [3]
SenseTalk SenseTalk
modulo Modulo
Divisor Pembagi
rem rem Dividend Dividen
Smalltalk Smalltalk
\\ \ \ Divisor Pembagi
SQL ( mod(x, Dividend
SQL:1999 ) SQL ( SQL: 1999 )
y) mod (x, y)
Dividen
Standard ML Standar ML
mod mod Divisor Pembagi
Int.re
m Int.re
m
Dividend Dividen
Stata Stata
mod(x,
y) mod (x, y)
Always positive Selalu positif
Tcl Tcl % % Divisor Pembagi
Torque Game Engine Torsi Mesin Permainan
% % Dividend Dividen
Turing Turing
mod mod Divisor Pembagi
Verilog (2001) Verilog (2001)
% % Dividend Dividen
VHDL VHDL
mod mod Divisor Pembagi
rem rem Dividend Dividen
Visual Basic Visual Basic
Mod Mod Dividend Dividen
x86 Assembly Majelis x86
IDIV IDIV
Dividend Dividen
Floating-point modulo operators in various
programming languages Floating-point modulo
operator dalam berbagai bahasa pemrograman
Language
Bahasa
Operator Operator
Result has the
same sign as
Hasil memil
iki tanda yang sama sepert
i C (ISO 1990) C (ISO 1990)
fmod FMOD ? ?
C (ISO 1999) C (ISO 1999)
fmod FMOD
Dividend Dividen
remainder sisa
Closest to zero Terdekat ke nol
C++ (ISO 1998) C + + (ISO 1998)
std::fmod std:: FMOD ? ?
C++ (ISO 2011) C + + (ISO 2011)
std::fmod std:: FMOD
Dividend Dividen
std::remai
nder std:: sisa
Closest to zero Terdekat ke nol
C# C # % %
Dividend Dividen
Comm mod mod Diviso
on Lisp Common Lisp
r Pembagi
rem rem
Dividend Dividen
D D % % ? ?
Fortran Fortran
mod mod
Dividend Dividen
modulo Modulo
Divisor Pembagi
Go Go math.Fmod math.Fmod
Dividend Dividen
Haskell (GHC) Haskell (GHC)
Data.Fixed
.mod' Data.Fixed
.mod '
Divisor Pembagi
Java Jawa
% %
Dividend Dividen
JavaScript JavaScript
% %
Dividend Dividen
Objective Caml Tujuan CAML
mod_float mod_float
Dividend Dividen
Perl Perl
POSIX::fmo
d POSIX:: FMOD
Dividend Dividen
PHP PHP
fmod FMOD
Dividend Dividen
Python Ular
% % Divisor
sanca
Pembagi
math.fmod math.fmod
Dividend Dividen
Ruby Rubi
%,
modulus() %, Modulus
()
Divisor Pembagi
remainder(
) sisanya ()
Dividend Dividen
Scheme R 6 RS Skema R 6 RS
flmod flmod
Always positive Selalu positif
flmod0 flmod0
Closest to zero Terdekat ke nol
Standard ML Standar ML
Real.rem Real.rem
Dividend Dividen
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 n == x & (2 n - 1) . x % 2 n == x & (2 n - 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 value—the 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 12-jam, 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, has n elements, and can be written as: memiliki n elemen, dan dapat ditulis sebagai:
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 by the following rules: dengan aturan sebagai berikut:
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 is the coset of a in
the quotient group adalah koset dari dalam kelompok kecerdasan , a cyclic group . [ 2 ] , Sebuah kelompok siklik . [2]
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