Misplaced Pages

Miller–Rabin primality test

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.

The Miller–Rabin primality test or Rabin–Miller primality test is a probabilistic primality test : an algorithm which determines whether a given number is likely to be prime , similar to the Fermat primality test and the Solovay–Strassen primality test .

#247752

114-486: It is of historical significance in the search for a polynomial-time deterministic primality test. Its probabilistic variant remains widely used in practice, as one of the simplest and fastest tests known. Gary L. Miller discovered the test in 1976. Miller's version of the test is deterministic , but its correctness relies on the unproven extended Riemann hypothesis . Michael O. Rabin modified it to obtain an unconditional probabilistic algorithm in 1980. Similarly to

228-407: A such that 0 < a < p ; thus a multiplicative inverse exists for all a that is not congruent to zero modulo p . Some of the more advanced properties of congruence relations are the following: The congruence relation is an equivalence relation . The equivalence class modulo m of an integer a is the set of all integers of the form a + k m , where k is any integer. It

342-471: A , then ( a / b ) mod m = ( a mod b m ) / b . The modular multiplicative inverse is defined by the following rules: The multiplicative inverse x ≡ a (mod m ) may be efficiently computed by solving Bézout's equation a x + m y = 1 for x , y , by using the Extended Euclidean algorithm . In particular, if p is a prime number, then a is coprime with p for every

456-496: A CDC 6600 supercomputer to disprove it two decades earlier via a brute force search . 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. The logical operator XOR sums 2 bits, modulo 2. The use of long division to turn

570-480: A computational hardness assumption to prove the difficulty of several other problems in computational game theory , property testing , and machine learning . The complexity class QP consists of all problems that have quasi-polynomial time algorithms. It can be defined in terms of DTIME as follows. In complexity theory, the unsolved P versus NP problem asks if all problems in NP have polynomial-time algorithms. All

684-529: A constant multiplier , and such a multiplier is irrelevant to big O classification, the standard usage for logarithmic-time algorithms is O ( log ⁡ n ) {\displaystyle O(\log n)} regardless of the base of the logarithm appearing in the expression of T . Algorithms taking logarithmic time are commonly found in operations on binary trees or when using binary search . An O ( log ⁡ n ) {\displaystyle O(\log n)} algorithm

798-439: A modulus , two integers a and b are said to be congruent modulo m , if m is a divisor of their difference; that is, if there is an integer k such that Congruence modulo m is a congruence relation , meaning that it is an equivalence relation that is compatible with the operations of addition , subtraction , and multiplication . Congruence modulo m is denoted The parentheses mean that (mod m ) applies to

912-575: A ≡ b (mod m ) , and this explains why " = " is often used instead of " ≡ " in this context. Each residue class modulo m may be represented by any one of its members, although we usually represent each residue class by the smallest nonnegative integer which belongs to that class (since this is the proper remainder which results from division). Any two members of different residue classes modulo m are incongruent modulo m . Furthermore, every integer belongs to one and only one residue class modulo m . The set of integers {0, 1, 2, ..., m − 1}

1026-429: A ≡ 1 (mod n ) , because the congruence relation is compatible with exponentiation . And a = a ≡ −1 (mod n ) holds trivially for a ≡ −1 (mod n ) since d is odd, for the same reason. That is why random a are usually chosen in the interval 1 < a < n − 1 . For testing arbitrarily large n , choosing bases at random is essential, as we don't know the distribution of witnesses and strong liars among

1140-439: A certain value, called the modulus . The modern approach to modular arithmetic was developed by Carl Friedrich Gauss in his book Disquisitiones Arithmeticae , published in 1801. 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. Simple addition would result in 7 + 8 = 15 , but 15:00 reads as 3:00 on

1254-422: A constant. Linear time is the best possible time complexity in situations where the algorithm has to sequentially read its entire input. Therefore, much research has been invested into discovering algorithms exhibiting linear time or, at least, nearly linear time. This research includes both software and hardware methods. There are several hardware technologies which exploit parallelism to provide this. An example

SECTION 10

#1733092481248

1368-792: A deterministic Turing machine form the complexity class known as EXP . Sometimes, exponential time is used to refer to algorithms that have T ( n ) = 2 , where the exponent is at most a linear function of n . This gives rise to the complexity class E . An algorithm is said to be factorial time if T(n) is upper bounded by the factorial function n! . Factorial time is a subset of exponential time (EXP) because n ! ≤ n n = 2 n log ⁡ n = O ( 2 n 1 + ϵ ) {\displaystyle n!\leq n^{n}=2^{n\log n}=O\left(2^{n^{1+\epsilon }}\right)} for all ϵ > 0 {\displaystyle \epsilon >0} . However, it

1482-440: A deterministic machine which is robust in terms of machine model changes. (For example, a change from a single-tape Turing machine to a multi-tape machine can lead to a quadratic speedup, but any algorithm that runs in polynomial time under one model also does so on the other.) Any given abstract machine will have a complexity class corresponding to the problems which can be solved in polynomial time on that machine. An algorithm

1596-415: A field because it has zero-divisors . If m > 1 , ( Z / m Z ) × {\displaystyle (\mathbb {Z} /m\mathbb {Z} )^{\times }} denotes the multiplicative group of the integers modulo m that are invertible. It consists of the congruence classes a m , where a is coprime to m ; these are precisely the classes possessing

1710-443: A fixed amount of time to perform. Thus, the amount of time taken and the number of elementary operations performed by the algorithm are taken to be related by a constant factor . Since an algorithm's running time may vary among different inputs of the same size, one commonly considers the worst-case time complexity , which is the maximum amount of time required for inputs of a given size. Less common, and usually specified explicitly,

1824-407: A multiplicative inverse. They form an abelian group under multiplication; its order is φ ( m ) , where φ is Euler's totient function In pure mathematics, modular arithmetic is one of the foundations of number theory , touching on almost every aspect of its study, and it is also used extensively in group theory , ring theory , knot theory , and abstract algebra . In applied mathematics, it

1938-1239: A number a {\displaystyle a} such that 2 ≤ a ≤ n − 2 {\displaystyle 2\leq a\leq n-2} . Say a = 174 {\displaystyle a=174} : a s 0 d  mod  n → 174 2 0 55  mod  221 ≡ 174 55 ≡ 47 . Since  47 ≠ 1  and  47 ≠ n − 1 , we continue. 174 2 1 55  mod  221 ≡ 174 110 ≡ 220 = n − 1 {\displaystyle {\begin{aligned}a^{{s^{0}}d}{\text{ mod }}n\rightarrow &174^{{2^{0}}55}{\text{ mod }}221\equiv 174^{55}\equiv 47{\text{. Since }}47\neq 1{\text{ and }}47\neq n-1{\text{, we continue.}}\\&174^{{2^{1}}55}{\text{ mod }}221\equiv 174^{110}\equiv 220=n-1\end{aligned}}} Since 220 ≡ − 1  mod  n {\displaystyle 220\equiv -1{\text{ mod }}n} , either 221

2052-466: A paper dictionary. As a result, the search space within the dictionary decreases as the algorithm gets closer to the target word. An algorithm is said to run in polylogarithmic time if its time T ( n ) {\displaystyle T(n)} is O ( ( log ⁡ n ) k ) {\displaystyle O{\bigl (}(\log n)^{k}{\bigr )}} for some constant k . Another way to write this

2166-578: A probability at most 4. This is an improvement over the Solovay–Strassen test , whose worst‐case error bound is 2. Moreover, the Miller–Rabin test is strictly stronger than the Solovay–Strassen test in the sense that for every composite n , the set of strong liars for n is a subset of the set of Euler liars for n , and for many n , the subset is proper. In addition, for large values of n ,

2280-414: A strong probable prime is in fact composite. These two probabilities are related by Bayes' law : In the last equation, we simplified the expression using the fact that all prime numbers are correctly reported as strong probable primes (the test has no false negative ). By dropping the left part of the denominator , we derive a simple upper bound: Hence this conditional probability is related not only to

2394-445: A strong probable prime to base a . If x is a nontrivial square root of 1 modulo n , Polynomial-time In theoretical computer science , the time complexity is the computational complexity that describes the amount of computer time it takes to run an algorithm . Time complexity is commonly estimated by counting the number of elementary operations performed by the algorithm, supposing that each elementary operation takes

SECTION 20

#1733092481248

2508-488: A term n c {\displaystyle n^{c}} for any c > 1 {\displaystyle c>1} . Algorithms which run in quasilinear time include: In many cases, the O ( n log ⁡ n ) {\displaystyle O(n\log n)} running time is simply the result of performing a Θ ( log ⁡ n ) {\displaystyle \Theta (\log n)} operation n times (for

2622-478: A witness is known. A naïve solution is to try all possible bases, which yields an inefficient deterministic algorithm. The Miller test is a more efficient variant of this (see section Miller test below ). Another solution is to pick a base at random. This yields a fast probabilistic test . When n is composite, most bases are witnesses, so the test will detect n as composite with a reasonably high probability (see section Accuracy below ). We can quickly reduce

2736-457: Is O ( log k ⁡ n ) {\displaystyle O(\log ^{k}n)} . For example, matrix chain ordering can be solved in polylogarithmic time on a parallel random-access machine , and a graph can be determined to be planar in a fully dynamic way in O ( log 3 ⁡ n ) {\displaystyle O(\log ^{3}n)} time per insert/delete operation. An algorithm

2850-517: Is content-addressable memory . This concept of linear time is used in string matching algorithms such as the Boyer–Moore string-search algorithm and Ukkonen's algorithm . An algorithm is said to run in quasilinear time (also referred to as log-linear time ) if T ( n ) = O ( n log k ⁡ n ) {\displaystyle T(n)=O(n\log ^{k}n)} for some positive constant k ; linearithmic time

2964-454: Is coprime to n . Then, n is said to be a strong probable prime to base a if one of these congruence relations holds: This simplifies to first checking for a d mod n = 1 {\displaystyle a^{d}{\bmod {n}}=1} and then a 2 r d = n − 1 {\displaystyle a^{2^{r}d}=n-1} for successive values of r. For each value of r,

3078-422: Is n . Another example was the graph isomorphism problem , which the best known algorithm from 1982 to 2016 solved in 2 O ( n log ⁡ n ) {\displaystyle 2^{O\left({\sqrt {n\log n}}\right)}} . However, at STOC 2016 a quasi-polynomial time algorithm was presented. It makes a difference whether the algorithm is allowed to be sub-exponential in

3192-446: Is {0, 1, 2, 3} . Some other complete residue systems modulo 4 include: Some sets that are not complete residue systems modulo 4 are: Given the Euler's totient function φ ( m ) , any set of φ ( m ) integers that are relatively prime to m and mutually incongruent under modulus m is called a reduced residue system modulo m . The set {5, 15} from above, for example,

3306-433: Is a commutative ring . For example, in the ring Z / 24 Z {\displaystyle \mathbb {Z} /24\mathbb {Z} } , one has as in the arithmetic for the 24-hour clock. The notation Z / m Z {\displaystyle \mathbb {Z} /m\mathbb {Z} } is used because this ring is the quotient ring of Z {\displaystyle \mathbb {Z} } by

3420-521: Is a field if and only if m is prime (this ensures that every nonzero element has a multiplicative inverse ). If m = p is a prime power with k > 1 , there exists a unique (up to isomorphism) finite field G F ( m ) = F m {\displaystyle \mathrm {GF} (m)=\mathbb {F} _{m}} with m elements, which is not isomorphic to Z / m Z {\displaystyle \mathbb {Z} /m\mathbb {Z} } , which fails to be

3534-461: Is a polynomial time algorithm . The following table summarizes some classes of commonly encountered time complexities. In the table, poly( x ) = x , i.e., polynomial in  x . formerly-best algorithm for graph isomorphism An algorithm is said to be constant time (also written as O ( 1 ) {\textstyle O(1)} time) if the value of T ( n ) {\textstyle T(n)} (the complexity of

Miller–Rabin primality test - Misplaced Pages Continue

3648-407: Is a special case, here applied with the polynomial X − 1 over the finite field Z / n Z , of the more general fact that a polynomial over some field has no more roots than its degree (this theorem follows from the existence of an Euclidean division for polynomials ). Here follows a more elementary proof. Suppose that x is a square root of 1 modulo n . Then: In other words, n divides

3762-427: Is a synonym for "tractable", "feasible", "efficient", or "fast". Some examples of polynomial-time algorithms: These two concepts are only relevant if the inputs to the algorithms consist of integers. The concept of polynomial time leads to several complexity classes in computational complexity theory. Some important classes defined using polynomial time are the following. P is the smallest time-complexity class on

3876-460: Is a witness for the compositeness of 221, and 174 was in fact a strong liar. Note that this tells us nothing about the factors of 221 (which are 13 and 17). However, the example with 341 in a later section shows how these calculations can sometimes produce a factor of n . For a practical guide to choosing the value of a see Testing against small sets of bases . The algorithm can be written in pseudocode as follows. The parameter k determines

3990-789: Is an instance of a reduced residue system modulo 4. Covering systems represent yet another type of residue system that may contain residues with varying moduli. Remark: In the context of this paragraph, the modulus m is almost always taken as positive. The set of all congruence classes modulo m is called the ring of integers modulo m , and is denoted Z / m Z {\textstyle \mathbb {Z} /m\mathbb {Z} } , Z / m {\displaystyle \mathbb {Z} /m} , or Z m {\displaystyle \mathbb {Z} _{m}} . The notation Z m {\displaystyle \mathbb {Z} _{m}} is, however, not recommended because it can be confused with

4104-430: Is an open problem. Other computational problems with quasi-polynomial time solutions but no known polynomial time solution include the planted clique problem in which the goal is to find a large clique in the union of a clique and a random graph . Although quasi-polynomially solvable, it has been conjectured that the planted clique problem has no polynomial time solution; this planted clique conjecture has been used as

4218-548: Is called the congruence class or residue class of a modulo  m , and may be denoted as ( a mod m ) , or as a or [ a ] when the modulus m is known from the context. Each residue class modulo  m contains exactly one integer in the range 0 , . . . , | m | − 1 {\displaystyle 0,...,|m|-1} . Thus, these | m | {\displaystyle |m|} integers are representatives of their respective residue classes. It

4332-403: Is called the least residue system modulo m . Any set of m integers, no two of which are congruent modulo m , is called a complete residue system modulo m . The least residue system is a complete residue system, and a complete residue system is simply a set containing precisely one representative of each residue class modulo m . For example, the least residue system modulo 4

4446-489: Is clearly superpolynomial, but some algorithms are only very weakly superpolynomial. For example, the Adleman–Pomerance–Rumely primality test runs for n time on n -bit inputs; this grows faster than any polynomial for large enough n , but the input size must become impractically large before it cannot be dominated by a polynomial with small degree. An algorithm that requires superpolynomial time lies outside

4560-441: Is composite. This is only possible if n ≡ 1 (mod 4), and we pass probable prime tests with two or more bases a such that a ≢ ±1 (mod n ), but it is an inexpensive addition to the basic Miller-Rabin test. The Miller–Rabin algorithm can be made deterministic by trying all possible values of a below a certain limit. Taking n as the limit would imply O( n ) trials, hence the running time would be exponential with respect to

4674-701: Is congruent to either 1 or −1 modulo n . If it is congruent to −1, we are done. Otherwise, it is congruent to 1 and we can iterate the reasoning . At the end, either one of the terms is congruent to −1, or all of them are congruent to 1, and in particular the last term, a , is. Suppose we wish to determine if n = 221 {\displaystyle n=221} is prime. We write n − 1  as  2 2 × 55 {\displaystyle n-1{\text{ as }}2^{2}\times 55} , so that we have s = 2  and  d = 55 {\displaystyle s=2{\text{ and }}d=55} . We randomly select

Miller–Rabin primality test - Misplaced Pages Continue

4788-591: Is considered highly efficient, as the ratio of the number of operations to the size of the input decreases and tends to zero when n increases. An algorithm that must access all elements of its input cannot take logarithmic time, as the time taken for reading an input of size n is of the order of n . An example of logarithmic time is given by dictionary search. Consider a dictionary D which contains n entries, sorted in alphabetical order . We suppose that, for 1 ≤ k ≤ n {\displaystyle 1\leq k\leq n} , one may access

4902-535: Is defined by the divisibility by m and because -1 is a unit in the ring of integers, a number is divisible by - m exactly if it is divisible by m . This means that every non-zero integer m may be taken as modulus. In modulus 12, one can assert that: because the difference is 38 − 14 = 24 = 2 × 12 , a multiple of 12 . Equivalently, 38 and 14 have the same remainder 2 when divided by 12 . The definition of congruence also applies to negative values. For example: The congruence relation satisfies all

5016-436: Is defined to take superpolynomial time if T ( n ) is not bounded above by any polynomial. Using little omega notation , it is ω ( n ) time for all constants c , where n is the input parameter, typically the number of bits in the input. For example, an algorithm that runs for 2 steps on an input of size n requires superpolynomial time (more specifically, exponential time). An algorithm that uses exponential resources

5130-402: Is generally easier to work with integers than sets of integers; that is, the representatives most often considered, rather than their residue classes. Consequently, ( a mod m ) denotes generally the unique integer k such that 0 ≤ k < m and k ≡ a (mod m ) ; it is called the residue of a modulo  m . In particular, ( a mod m ) = ( b mod m ) is equivalent to

5244-423: Is known. Such problems arise in approximation algorithms; a famous example is the directed Steiner tree problem , for which there is a quasi-polynomial time approximation algorithm achieving an approximation factor of O ( log 3 ⁡ n ) {\displaystyle O(\log ^{3}n)} ( n being the number of vertices), but showing the existence of such a polynomial time algorithm

5358-438: Is not a subset of E. An example of an algorithm that runs in factorial time is bogosort , a notoriously inefficient sorting algorithm based on trial and error . Bogosort sorts a list of n items by repeatedly shuffling the list until it is found to be sorted. In the average case, each pass through the bogosort algorithm will examine one of the n ! orderings of the n items. If the items are distinct, only one such ordering

5472-477: Is not an empty set ; rather, it is isomorphic to Z {\displaystyle \mathbb {Z} } , since a 0 = { a } . Addition, subtraction, and multiplication are defined on Z / m Z {\displaystyle \mathbb {Z} /m\mathbb {Z} } by the following rules: The properties given before imply that, with these operations, Z / m Z {\displaystyle \mathbb {Z} /m\mathbb {Z} }

5586-537: Is not an exact characterization of prime numbers. If n is composite, it may nonetheless be a strong probable prime to base a , in which case it is called a strong pseudoprime , and a is a strong liar . No composite number is a strong pseudoprime to all bases at the same time (contrary to the Fermat primality test for which Fermat pseudoprimes to all bases exist: the Carmichael numbers ). However no simple way of finding

5700-553: Is not controlled, since a cryptographic adversary might send a carefully chosen pseudoprime in order to defeat the primality test. In such contexts, only the worst‐case error bound of 4 can be relied upon. The above error measure is the probability for a composite number to be declared as a strong probable prime after k rounds of testing; in mathematical words, it is the conditional probability Pr ( M R k ∣ ¬ P ) {\displaystyle \Pr(M\!R_{k}\mid \lnot P)} where P

5814-401: Is not generally agreed upon, however the two most widely used are below. A problem is said to be sub-exponential time solvable if it can be solved in running times whose logarithms grow smaller than any given polynomial. More precisely, a problem is in sub-exponential time if for every ε > 0 there exists an algorithm which solves the problem in time O (2 ). The set of all such problems

SECTION 50

#1733092481248

5928-472: Is not used in practice. For most purposes, proper use of the probabilistic Miller–Rabin test or the Baillie–PSW primality test gives sufficient confidence while running much faster. It is also slower in practice than commonly used proof methods such as APR-CL and ECPP which give results that do not rely on unproven assumptions. For theoretical purposes requiring a deterministic polynomial time algorithm, it

6042-485: Is of great practical importance. An algorithm is said to be of polynomial time if its running time is upper bounded by a polynomial expression in the size of the input for the algorithm, that is, T ( n ) = O ( n ) for some positive constant k . Problems for which a deterministic polynomial-time algorithm exists belong to the complexity class P , which is central in the field of computational complexity theory . Cobham's thesis states that polynomial time

6156-1061: Is prime, or 174 is a strong liar for 221. We try another random a {\displaystyle a} , this time choosing a = 137 {\displaystyle a=137} : a s 0 d  mod  n → 137 2 0 55  mod  221 ≡ 137 55 ≡ 188 . Since  188 ≠ 1  and  188 ≠ n − 1 , we continue. 137 2 1 55  mod  221 ≡ 137 110 ≡ 205 ≠ n − 1 {\displaystyle {\begin{aligned}a^{{s^{0}}d}{\text{ mod }}n\rightarrow &137^{{2^{0}}55}{\text{ mod }}221\equiv 137^{55}\equiv 188{\text{. Since }}188\neq 1{\text{ and }}188\neq n-1{\text{, we continue.}}\\&137^{{2^{1}}55}{\text{ mod }}221\equiv 137^{110}\equiv 205\neq n-1\end{aligned}}} Hence 137

6270-425: Is said to be subquadratic time if T ( n ) = o ( n 2 ) {\displaystyle T(n)=o(n^{2})} . For example, simple, comparison-based sorting algorithms are quadratic (e.g. insertion sort ), but more advanced algorithms can be found that are subquadratic (e.g. shell sort ). No general-purpose sorts run in linear time, but the change from quadratic to sub-quadratic

6384-449: Is said to run in sub-linear time (often spelled sublinear time ) if T ( n ) = o ( n ) {\displaystyle T(n)=o(n)} . In particular this includes algorithms with the time complexities defined above. The specific term sublinear time algorithm commonly refers to randomized algorithms that sample a small fraction of their inputs and process them efficiently to approximately infer properties of

6498-620: Is significantly faster than exponential time . The worst case running time of a quasi-polynomial time algorithm is 2 O ( log c ⁡ n ) {\displaystyle 2^{O(\log ^{c}n)}} for some fixed c > 0 {\displaystyle c>0} . When c = 1 {\displaystyle c=1} this gives polynomial time, and for c < 1 {\displaystyle c<1} it gives sub-linear time. There are some problems for which we know quasi-polynomial time algorithms, but no polynomial time algorithm

6612-433: Is sorted. Bogosort shares patrimony with the infinite monkey theorem . An algorithm is said to be double exponential time if T ( n ) is upper bounded by 2 , where poly( n ) is some polynomial in n . Such algorithms belong to the complexity class 2-EXPTIME . Modular arithmetic#Properties In mathematics , modular arithmetic is a system of arithmetic for integers , where numbers "wrap around" when reaching

6726-410: Is that 3SAT , the satisfiability problem of Boolean formulas in conjunctive normal form with at most three literals per clause and with n variables, cannot be solved in time 2 . More precisely, the hypothesis is that there is some absolute constant c > 0 such that 3SAT cannot be decided in time 2 by any deterministic Turing machine. With m denoting the number of clauses, ETH is equivalent to

6840-449: Is the average-case complexity , which is the average of the time taken on inputs of a given size (this makes sense because there are only a finite number of possible inputs of a given size). In both cases, the time complexity is generally expressed as a function of the size of the input. Since this function is generally difficult to compute exactly, and the running time for small inputs is usually not consequential, one commonly focuses on

6954-400: Is the event that the number being tested is prime, and MR k is the event that it passes the Miller–Rabin test with k rounds. We are often interested instead in the inverse conditional probability Pr ( ¬ P ∣ M R k ) {\displaystyle \Pr(\lnot P\mid M\!R_{k})} : the probability that a number which has been declared as

SECTION 60

#1733092481248

7068-549: Is the case k = 1 {\displaystyle k=1} . Using soft O notation these algorithms are O ~ ( n ) {\displaystyle {\tilde {O}}(n)} . Quasilinear time algorithms are also O ( n 1 + ε ) {\displaystyle O(n^{1+\varepsilon })} for every constant ε > 0 {\displaystyle \varepsilon >0} and thus run faster than any polynomial time algorithm whose time bound includes

7182-588: Is the class of all parameterized problems ( L , k ) {\displaystyle (L,k)} for which there is a computable function f : N → N {\displaystyle f:\mathbb {N} \to \mathbb {N} } with f ∈ o ( k ) {\displaystyle f\in o(k)} and an algorithm that decides L in time 2 f ( k ) ⋅ poly ( n ) {\displaystyle 2^{f(k)}\cdot {\text{poly}}(n)} . The exponential time hypothesis ( ETH )

7296-452: Is the complexity class SUBEXP which can be defined in terms of DTIME as follows. This notion of sub-exponential is non-uniform in terms of ε in the sense that ε is not part of the input and each ε may have its own algorithm for the problem. Some authors define sub-exponential time as running times in 2 o ( n ) {\displaystyle 2^{o(n)}} . This definition allows larger running times than

7410-531: Is the size in units of bits needed to represent the input. Algorithmic complexities are classified according to the type of function appearing in the big O notation. For example, an algorithm with time complexity O ( n ) {\displaystyle O(n)} is a linear time algorithm and an algorithm with time complexity O ( n α ) {\displaystyle O(n^{\alpha })} for some constant α > 0 {\displaystyle \alpha >0}

7524-417: Is used by the most efficient implementations of polynomial greatest common divisor , exact linear algebra and Gröbner basis algorithms over the integers and the rational numbers. As posted on Fidonet in the 1980s and archived at Rosetta Code , modular arithmetic was used to disprove Euler's sum of powers conjecture on a Sinclair QL microcomputer using just one-fourth of the integer precision used by

7638-530: Is used in computer algebra , cryptography , computer science , chemistry and the visual and musical arts. A very practical application is to calculate checksums within serial number identifiers. For example, International Standard Book Number (ISBN) uses modulo 11 (for 10-digit ISBN) or modulo 10 (for 13-digit ISBN) arithmetic for error detection. Likewise, International Bank Account Numbers (IBANs), for example, make use of modulo 97 arithmetic to spot user input errors in bank account numbers. In chemistry,

7752-472: Is used in a variety of symmetric key algorithms including Advanced Encryption Standard (AES), International Data Encryption Algorithm (IDEA), and RC4 . RSA and Diffie–Hellman use modular exponentiation . In computer algebra, modular arithmetic is commonly used to limit the size of integer coefficients in intermediate calculations and data. It is used in polynomial factorization , a problem for which all known efficient algorithms use modular arithmetic. It

7866-400: The b here need not be the remainder in the division of a by m . Rather, a ≡ b (mod m ) asserts that a and b have the same remainder when divided by m . That is, where 0 ≤ r < m is the common remainder. We recover the previous relation ( a − b = k m ) by subtracting these two expressions and setting k = p − q . Because the congruence modulo m

7980-524: The Miller test , which is deterministic assuming the ERH: The full power of the generalized Riemann hypothesis is not needed to ensure the correctness of the test: as we deal with subgroups of even index , it suffices to assume the validity of GRH for quadratic Dirichlet characters . The running time of the algorithm is, in the soft-O notation, Õ((log n )) (using FFT‐based multiplication). The Miller test

8094-417: The complexity class P . Cobham's thesis posits that these algorithms are impractical, and in many cases they are. Since the P versus NP problem is unresolved, it is unknown whether NP-complete problems require superpolynomial time. Quasi-polynomial time algorithms are algorithms whose running time exhibits quasi-polynomial growth , a type of behavior that may be slower than polynomial time but yet

8208-485: The floor function . If w = D ( ⌊ n 2 ⌋ ) {\displaystyle w=D\left(\left\lfloor {\frac {n}{2}}\right\rfloor \right)} --that is to say, the word w is exactly in the middle of the dictionary--then we are done. Else, if w < D ( ⌊ n 2 ⌋ ) {\displaystyle w<D\left(\left\lfloor {\frac {n}{2}}\right\rfloor \right)} --i.e., if

8322-554: The ideal m Z {\displaystyle m\mathbb {Z} } , the set formed by all k m with k ∈ Z . {\displaystyle k\in \mathbb {Z} .} Considered as a group under addition, Z / m Z {\displaystyle \mathbb {Z} /m\mathbb {Z} } is a cyclic group , and all cyclic groups are isomorphic with Z / m Z {\displaystyle \mathbb {Z} /m\mathbb {Z} } for some m . The ring of integers modulo m

8436-524: The k th entry of the dictionary in a constant time. Let D ( k ) {\displaystyle D(k)} denote this k th entry. Under these hypotheses, the test to see if a word w is in the dictionary may be done in logarithmic time: consider D ( ⌊ n 2 ⌋ ) {\displaystyle D\left(\left\lfloor {\frac {n}{2}}\right\rfloor \right)} , where ⌊ ⌋ {\displaystyle \lfloor \;\rfloor } denotes

8550-413: The Fermat and Solovay–Strassen tests, the Miller–Rabin primality test checks whether a specific property, which is known to hold for prime values, holds for the number under testing. The property is the following. For a given odd integer n > 2 , let’s write n − 1 as 2 d where s is a positive integer and d is an odd positive integer. Let’s consider an integer  a , called a base , which

8664-476: The accuracy of the test. The greater the number of rounds, the more accurate the result. Using repeated squaring , the running time of this algorithm is O ( k log n ) , where n is the number tested for primality, and k is the number of rounds performed; thus this is an efficient, polynomial-time algorithm. FFT -based multiplication ( Harvey-Hoeven algorithm ) can decrease the running time to O( k log n log log n ) = Õ ( k log n ) . The error made by

8778-454: The algorithm) is bounded by a value that does not depend on the size of the input. For example, accessing any single element in an array takes constant time as only one operation has to be performed to locate it. In a similar manner, finding the minimal value in an array sorted in ascending order; it is the first element. However, finding the minimal value in an unordered array is not a constant time operation as scanning over each element in

8892-434: The appropriate range, without any assumptions. There is a small list of potential witnesses for every possible input size (at most b values for b ‐bit numbers). However, no finite set of bases is sufficient for all composite numbers. Alford, Granville, and Pomerance have shown that there exist infinitely many composite numbers n whose smallest compositeness witness is at least (ln n ) . They also argue heuristically that

9006-437: The array is needed in order to determine the minimal value. Hence it is a linear time operation, taking O ( n ) {\textstyle O(n)} time. If the number of elements is known in advance and does not change, however, such an algorithm can still be said to run in constant time. Despite the name "constant time", the running time does not have to be independent of the problem size, but an upper bound for

9120-559: The behavior of the complexity when the input size increases—that is, the asymptotic behavior of the complexity. Therefore, the time complexity is commonly expressed using big O notation , typically O ( n ) {\displaystyle O(n)} , O ( n log ⁡ n ) {\displaystyle O(n\log n)} , O ( n α ) {\displaystyle O(n^{\alpha })} , O ( 2 n ) {\displaystyle O(2^{n})} , etc., where n

9234-437: The best-known algorithms for NP-complete problems like 3SAT etc. take exponential time. Indeed, it is conjectured for many natural NP-complete problems that they do not have sub-exponential time algorithms. Here "sub-exponential time" is taken to mean the second definition presented below. (On the other hand, many graph problems represented in the natural way by adjacency matrices are solvable in subexponential time simply because

9348-419: The case when we use the Miller–Rabin test to generate primes (see below ), the distribution is chosen by the generator itself, so we can exploit this result. Caldwell points out that strong probable prime tests to different bases sometimes provide an additional primality test. Just as the strong test checks for the existence of more than two square roots of 1 modulo n , two such tests can sometimes check for

9462-425: The clock face because clocks "wrap around" every 12 hours and the hour number starts over at zero when it reaches 12. We say that 15 is congruent to 3 modulo 12, written 15 ≡ 3 (mod 12), so that 7 + 8 ≡ 3 (mod 12). Similarly, 8:00 represents a period of 8 hours, and twice this would give 16:00, which reads as 4:00 on the clock face, written as 2 × 8 ≡ 4 (mod 12). Given an integer m ≥ 1 , called

9576-423: The conditions of an equivalence relation : If a 1 ≡ b 1 (mod m ) and a 2 ≡ b 2 (mod m ) , or if a ≡ b (mod m ) , then: If a ≡ b (mod m ) , then it is generally false that k ≡ k (mod m ) . However, the following is true: For cancellation of common terms, we have the following rules: The last rule can be used to move modular arithmetic into division. If b divides

9690-475: The entire equation, not just to the right-hand side (here, b ). This notation is not to be confused with the notation b mod m (without parentheses), which refers to the modulo operation, the remainder of b when divided by m : that is, b mod m denotes the unique integer r such that 0 ≤ r < m and r ≡ b (mod m ) . The congruence relation may be rewritten as explicitly showing its relationship with Euclidean division . However,

9804-425: The entire instance. This type of sublinear time algorithm is closely related to property testing and statistics . Other settings where algorithms can run in sublinear time include: An algorithm is said to take linear time , or O ( n ) {\displaystyle O(n)} time, if its time complexity is O ( n ) {\displaystyle O(n)} . Informally, this means that

9918-418: The error measure discussed above — which is bounded by 4 — but also to the probability distribution of the input number. In the general case, as said earlier, this distribution is controlled by a cryptographic adversary, thus unknown, so we cannot deduce much about Pr ( ¬ P ∣ M R k ) {\displaystyle \Pr(\lnot P\mid M\!R_{k})} . However, in

10032-511: The existence of more than two square roots of −1. Suppose, in the course of our probable prime tests, come across two bases a and a ′ for which a 2 r d ≡ a ′ 2 r ′ d ≡ − 1 ( mod n ) {\displaystyle a^{2^{r}d}\equiv a^{\prime \,2^{r'}d}\equiv -1{\pmod {n}}} with r , r ′ ≥ 1 . This means that we have computed two square roots as part of

10146-403: The first definition of sub-exponential time. An example of such a sub-exponential time algorithm is the best-known classical algorithm for integer factorization, the general number field sieve , which runs in time about 2 O ~ ( n 1 / 3 ) {\displaystyle 2^{{\tilde {O}}(n^{1/3})}} , where the length of the input

10260-418: The hypothesis that k SAT cannot be solved in time 2 for any integer k ≥ 3 . The exponential time hypothesis implies P ≠ NP . An algorithm is said to be exponential time , if T ( n ) is upper bounded by 2 , where poly( n ) is some polynomial in n . More formally, an algorithm is exponential time if T ( n ) is bounded by O (2 ) for some constant k . Problems which admit exponential time algorithms on

10374-439: The known inapproximability results for the set cover problem. The term sub-exponential time is used to express that the running time of some algorithm may grow faster than any polynomial but is still significantly smaller than an exponential. In this sense, problems that have sub-exponential time algorithms are somewhat more tractable than those that only have exponential algorithms. The precise definition of "sub-exponential"

10488-610: The last digit of the CAS registry number (a unique identifying number 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 previous digit times 2, the previous digit times 3 etc., adding all these up and computing the sum modulo 10. In cryptography, modular arithmetic directly underpins public key systems such as RSA and Diffie–Hellman , and provides finite fields which underlie elliptic curves , and

10602-655: The notation, see Big O notation § Family of Bachmann–Landau notations ). For example, binary tree sort creates a binary tree by inserting each element of the n -sized array one by one. Since the insert operation on a self-balancing binary search tree takes O ( log ⁡ n ) {\displaystyle O(\log n)} time, the entire algorithm takes O ( n log ⁡ n ) {\displaystyle O(n\log n)} time. Comparison sorts require at least Ω ( n log ⁡ n ) {\displaystyle \Omega (n\log n)} comparisons in

10716-587: The numbers 2, 3, ..., n − 2 . However, a pre-selected set of a few small bases guarantees the identification of all composites up to a pre-computed maximum. This maximum is generally quite large compared to the bases. This gives very fast deterministic tests for small enough n (see section Testing against small sets of bases below ). Here is a proof that, if n is a prime, then the only square roots of 1 modulo n are 1 and −1. Certainly 1 and −1, when squared modulo n , always yield 1. It remains to show that there are no other square roots of 1 modulo n . This

10830-422: The primality test is measured by the probability that a composite number is declared probably prime. The more bases a are tried, the better the accuracy of the test. It can be shown that if n is composite, then at most ⁠ 1 / 4 ⁠ of the bases a are strong liars for n . As a consequence, if n is composite then running k iterations of the Miller–Rabin test will declare n probably prime with

10944-538: The probability for a composite number to be declared probably prime is often significantly smaller than 4. For instance, for most numbers n , this probability is bounded by 8; the proportion of numbers n which invalidate this upper bound vanishes as we consider larger values of n . Hence the average case has a much better accuracy than 4, a fact which can be exploited for generating probable primes (see below ). However, such improved error bounds should not be relied upon to verify primes whose probability distribution

11058-421: The probability of a false positive to an arbitrarily small rate, by combining the outcome of as many independently chosen bases as necessary to achieve the said rate. This is the Miller–Rabin test. There seems to be diminishing returns in trying many bases, because if n is a pseudoprime to some base, then it seems more likely to be a pseudoprime to another base. Note that a ≡ 1 (mod n ) holds trivially for

11172-450: The product ( x − 1)( x + 1) . By Euclid's lemma , since n is prime, it divides one of the factors x − 1 or x + 1, implying that x is congruent to either 1 or −1 modulo n . Here is a proof that, if n is an odd prime, then it is a strong probable prime to base a . If n is an odd prime and we write n − 1= 2 d where s is a positive integer and d is an odd positive integer, by Fermat's little theorem: Each term of

11286-418: The running time has to be independent of the problem size. For example, the task "exchange the values of a and b if necessary so that a ≤ b {\textstyle a\leq b} " is called constant time even though the time may depend on whether or not it is already true that a ≤ b {\textstyle a\leq b} . However, there is some constant t such that

11400-418: The running time increases at most linearly with the size of the input. More precisely, this means that there is a constant c such that the running time is at most c n {\displaystyle cn} for every input of size n . For example, a procedure that adds up all elements of a list requires time proportional to the length of the list, if the adding time is constant, or, at least, bounded by

11514-446: The said subgroup, hence must be a witness for the compositeness of n . Assuming the truth of the extended Riemann hypothesis (ERH), it is known that the group is generated by its elements smaller than O(( ln n )) , which was already noted by Miller. The constant involved in the Big O notation was reduced to 2 by Eric Bach . This leads to the following primality testing algorithm, known as

11628-416: The sequence a 2 s d , a 2 s − 1 d , … , a 2 d , a d {\displaystyle a^{2^{s}d},a^{2^{s-1}d},\dots ,a^{2d},a^{d}} is a square root of the previous term. Since the first term is congruent to 1, the second term is a square root of 1 modulo n . By the previous lemma , it

11742-498: The set of m -adic integers . The ring Z / m Z {\displaystyle \mathbb {Z} /m\mathbb {Z} } is fundamental to various branches of mathematics (see § Applications below). For m > 0 one has When m = 1 , Z / m Z {\displaystyle \mathbb {Z} /m\mathbb {Z} } is the zero ring ; when m = 0 , Z / m Z {\displaystyle \mathbb {Z} /m\mathbb {Z} }

11856-406: The size log n of the input. To improve the running time, the challenge is then to lower the limit as much as possible while keeping the test reliable. If the tested number n is composite, the strong liars a coprime to n are contained in a proper subgroup of the group ( Z / n Z )*, which means that if we test all a from a set which generates ( Z / n Z )*, one of them must lie outside

11970-430: The size of the input is the square of the number of vertices.) This conjecture (for the k-SAT problem) is known as the exponential time hypothesis . Since it is conjectured that NP-complete problems do not have quasi-polynomial time algorithms, some inapproximability results in the field of approximation algorithms make the assumption that NP-complete problems do not have quasi-polynomial time algorithms. For example, see

12084-427: The size of the instance, the number of vertices, or the number of edges. In parameterized complexity , this difference is made explicit by considering pairs ( L , k ) {\displaystyle (L,k)} of decision problems and parameters k . SUBEPT is the class of all parameterized problems that run in time sub-exponential in k and polynomial in the input size n : More precisely, SUBEPT

12198-401: The smallest number w such that every composite number below n has a compositeness witness less than w should be of order Θ (log n log log n ). By inserting greatest common divisor calculations into the above algorithm, we can sometimes obtain a factor of n instead of merely determining that n is composite. This occurs for example when n is a probable prime to base a but not

12312-440: The testing, and can check whether a 2 r − 1 d ≡ ± a ′ 2 r ′ − 1 d ( mod n ) {\displaystyle a^{2^{r-1}d}\equiv \pm a^{\prime \,2^{r'-1}d}{\pmod {n}}} . This must always hold if n is prime; if not, we have found more than two square roots of −1 and proved that n

12426-419: The time required is always at most t . An algorithm is said to take logarithmic time when T ( n ) = O ( log ⁡ n ) {\displaystyle T(n)=O(\log n)} . Since log a ⁡ n {\displaystyle \log _{a}n} and log b ⁡ n {\displaystyle \log _{b}n} are related by

12540-444: The value of the expression may be calculated using the value obtained for the previous value of r by squaring under the modulus of n. The idea beneath this test is that when n is an odd prime, it passes the test because of two facts: Hence, by contraposition , if n is not a strong probable prime to base a , then n is definitely composite, and a is called a witness for the compositeness of n . However, this property

12654-418: The word w comes earlier in alphabetical order than the middle word of the whole dictionary--we continue the search in the same way in the left (i.e. earlier) half of the dictionary, and then again repeatedly until the correct word is found. Otherwise, if it comes after the middle word, continue similarly with the right half of the dictionary. This algorithm is similar to the method often used to find an entry in

12768-460: The worst case because log ⁡ ( n ! ) = Θ ( n log ⁡ n ) {\displaystyle \log(n!)=\Theta (n\log n)} , by Stirling's approximation . They also frequently arise from the recurrence relation T ( n ) = 2 T ( n 2 ) + O ( n ) {\textstyle T(n)=2T\left({\frac {n}{2}}\right)+O(n)} . An algorithm

12882-448: Was extended (see OEIS :  A014233 ), with the first result later shown using different methods in Jiang and Deng: Sorenson and Webster verify the above and calculate precise results for these larger than 64‐bit results: Other criteria of this sort, often more efficient (fewer bases required) than those shown above, exist. They give very fast deterministic primality tests for numbers in

12996-469: Was superseded by the AKS primality test , which also does not rely on unproven assumptions. When the number n to be tested is small, trying all a < 2(ln n ) is not necessary, as much smaller sets of potential witnesses are known to suffice. For example, Pomerance, Selfridge, Wagstaff and Jaeschke have verified that Using the 2010 work of Feitsma and Galway enumerating all base 2 pseudoprimes up to 2, this

#247752