Introduction to GMP Maple uses the GMP library to perform arbitrary-precision integer arithmetic. For more information about GMP, see ?gmp. Arbitrary-precision integer arithmetic involves working with numbers that are too large to fit into hardware integers. In Maple, the greatest number that can be represented by hardware integer is given by kernelopts(maximmediate); NiMiK0I9dXQ1 Integers greater than the above are represented by software integers. Arithmetic for software integers requires special algorithms for large integer arithmetic. To illustrate exact arbitrary-precision integer arithmetic in Maple, consider the following examples.
<Text-field style="Text" size="18" bold="true" layout="Normal" spacebelow="4" spaceabove="8" bookmark="bkmrk0"><Font bold="true" size="18">Basic Integer Arithmetic</Font></Text-field> 133!/2^31 + 141^41; NiMiZHhUeF44PHdpdGdyWCttaTpHZ2RvJmVnKj0sLGlqJyk9Uil6KXlGYGtyPzQocF4leWNpUiQ+aypwJWZ4NTlpNT9FSGJbXDtWcVhHKFF2a1kxczxGXSo9I3oocCV6bV9zd3BZODZnYnNwJ3ppWVxRIXpLZCJSa0Rw p := nextprime(%); # Find the smallest prime greater than the previous number NiM+JSJwRyJkeF4nPU5yaEZPMjtkL2dFYyJHZ2RvJmVnKj0sLGlqJyk9Uil6KXlGYGtyPzQocF4leWNpUiQ+aypwJWZ4NTlpNT9FSGJbXDtWcVhHKFF2a1kxczxGXSo9I3oocCV6bV9zd3BZODZnYnNwJ3ppWVxRIXpLZCJSa0Rw isprime(p); NiMlJXRydWVH igcd(p, 2*p); # Greatest common divisor of p and 2*p is p NiMiZHheJz1OcmhGTzI7ZC9nRWMiR2dkbyZlZyo9LCxpaicpPVIpeil5RmBrcj80KHBeJXljaVIkPmsqcCVmeDU5aTU/RUhiW1w7VnFYRyhRdmtZMXM8Rl0qPSN6KHAlem1fc3dwWTg2Z2JzcCd6aVlcUSF6S2QiUmtEcA==
<Text-field style="Text" size="18" bold="true" layout="Normal" spacebelow="4" spaceabove="8" bookmark="bkmrk1"><Font bold="true" size="18">Fermat's Little Theorem</Font></Text-field> Fermat's Little Theorem states "If p is prime and a is an integer, then a^p = a (mod p)" Consider this Mersenne prime (that is, prime of the form 2^n-1), which is more than 600 digits long. p := 2^2281-1: isprime(p); NiMlJXRydWVH Let a be a random integer between 2 and p-1. a := rand(2..p-1)(): Verify the correctness of Fermat's Little Theorem. evalb(a &^p mod p = a); NiMlJXRydWVH
<Text-field style="Text" size="18" bold="true" layout="Normal" spacebelow="4" spaceabove="8" bookmark="bkmrk2"><Font bold="true" size="18">A Very Large Summation</Font></Text-field> This example demonstrates the improvement of Maple 9 with arbitrary-precision integer arithmetic with GMP. Maple 9 computes this summation 25 times faster than Maple 8 (tested on a Pentium 4 1.5 GHz) S := add(1/k^2, k=1..100000): You can verify that the above sum is computed correctly by using the knowledge that it asymptotically approaches Pi^2/6. evalf(sqrt(6*S)); # This should be approximately Pi NiMkIisvSmVUSiEiKg==