Comparedtotheordinarymethodofmultiplying "x" withitself "n" −1times, inthisalgorithmthe "niseven" caseisoptimized, accordingto::x^n=x^{n/2} imesx^{n/2}ThiswaythealgorithmusesonlyO(log "n") multiplicationsandthereforespeedsupthecomputationof "x""n"tremendously, inmuchthesamewaythatthelongmultiplicationalgorithmspeedsupmultiplicationovertheslowermethodofrepeatedaddition. Thebenefitishadfor "n" greaterthanorequalto "4". (Note:whenmeasuredintermsofthesizeoftheproblemdata -insteadofthevalueofthedata, n- thisalgorithmislineartimesincethesizeofanintegerisalsoitslogarithm.)
xncanbecalculatedthus, ifnisaninteger: # Ifn < 0, {x = 1 / x; n = - n} # i = n; y = 1; z = x # Ifiisanoddnumber, y = y * z # z = z2 # i = i / 2, throwingawaythedivisionremainder # Ifi ≠ 0, gobacktostep3 # Theresultisy(Thismethodworksout00as1.)
Furtherapplications
Thesameideaallowsfastcomputationoflargeexponentsmoduloanumber. Especiallyincryptography, itisusefultocomputepowersinaringofintegersmodulo "q". Itcanalsobeusedtocomputeintegerpowersinagroup, usingtherule
Wemaycall*a "multiplication" anddefinean "exponentiation" Einthefollowingway: ForallelementsaofS: * E ( a, 1 ) := a * Forallnaturalnumbersn > 0isdefined:E ( a, n+1 ) := E ( a, n ) *a
functionrepeat ( s, n ) { if ( s = "" || n < 1 ) return "" varres = svarbin = n.toString ( 2 ) for ( vari = 1 ; i < bin.length ; i++ ) { res = res + resif ( bin.charAt ( i ) = '1' ) res = res + s } returnres}
Itisverysimilarinpropertiestoaforementionedapproach. Whilerecursionisanaturalwayforcalculation, itcanbeeasilytranslatedtoiterativeform. Italsomightprovidesomecomputationaladvantage (e.g., incaseofsmall "x" and "n" = 3*2"m") aswellasmemoryconsumptionreduction.
Exponentiation — Exponent redirects here. For other uses, see Exponent (disambiguation). Exponentiation is a mathematical operation, written as an, involving two numbers, the base a and the exponent (or power) n. When n is a positive integer, exponentiation… … Wikipedia
Modular exponentiation — is a type of exponentiation performed over a modulus. It is particularly useful in computer science, especially in the field of cryptography. Doing a modular exponentiation means calculating the remainder when dividing by a positive integer m… … Wikipedia
Montgomery reduction — In arithmetic computation, Montgomery reduction is an algorithm introduced in 1985 by Peter Montgomery that allows modular arithmetic to be performed efficiently when the modulus is large (typically several hundred bits). A single application of… … Wikipedia
Discrete logarithm — In mathematics, specifically in abstract algebra and its applications, discrete logarithms are group theoretic analogues of ordinary logarithms. In particular, an ordinary logarithm loga(b) is a solution of the equation ax = b over the… … Wikipedia
Computational complexity of mathematical operations — The following tables list the running time of various algorithms for common mathematical operations. Here, complexity refers to the time complexity of performing computations on a multitape Turing machine.[1] See big O notation for an explanation … Wikipedia
Primitive root modulo n — In modular arithmetic, a branch of number theory, a primitive root modulo n is any number g with the property that any number coprime to n is congruent to a power of g (mod n ). That is, if g is a primitive root (mod n ) and gcd( a , n ) = 1,… … Wikipedia
List of numerical analysis topics — This is a list of numerical analysis topics, by Wikipedia page. Contents 1 General 2 Error 3 Elementary and special functions 4 Numerical linear algebra … Wikipedia
Addition chain — In mathematics, an addition chain is a sequence a 0, a 1, a 2, a 3, ... that satisfies: a 0 = 1, and :for each k >0: a k = a i + a j for some i , j < k .As an example: 1, 2, 3, 6, 12, 24, 30, 31 is an addition chain for 31, of length 7, since:2 … Wikipedia
Doubling-oriented Doche–Icart–Kohel curve — A Doubling oriented Doche Icart Kohel curve of equation y2 = x3 − x2 − 16x In mathematics, the doubling oriented Doche–Icart–Kohel curve is a form in which an elliptic curve can be written. It is a special case of Weierstrass form and it is also… … Wikipedia
RSA — In cryptography, RSA is an algorithm for public key cryptography. It is the first algorithm known to be suitable for signing as well as encryption, and one of the first great advances in public key cryptography. RSA is widely used in electronic… … Wikipedia