USING MAPLE IN NUMBER THEORY
Maple has several functions that are useful in solving problems involving integers. The first batch is loaded with the Maple kernel (i.e., they can be used immediately without further preparation.)
1. To find the (n,k) binomial coefficient.
binomial(n,k)
| > | binomial(10,3); |
2. To generate a random number.
rand() generates a 12 digit positive random integer.
| > | rand(); |
rand(m..n) creates a program to generate a random integer between m and n. rand() then elicits numbers in this range.
| > | die :=rand(1..6): |
| > | die(); die(); die(); die(); |
Change the seed to change the sequence of random numbers.
| > | _seed :=100: |
randomize() sets the seed to depend on the time current when the command was entered.
| > | randomize(); |
3. To employ the division algorithm to divide b by a.
iquo(b,a,r) returns the quotient q; enter r to find the remainder.
| > | iquo(19,4,'r'); |
| > | r; |
4. To employ the Euclidean algorithm to find the gcd of a and b.
igcd(a,b)
| > | igcd(326,78); |
Another command is necessary in order to express the gcd as a linear combination of a and b: (a,b) = sa + tb.
| > | igcdex(326,78,s,t); |
| > | s;t; |
5. To find the lcm of a and b.
ilcm(a,b)
| > | ilcm(326,78); |
6. To factor the number n into primes.
ifactors(n)
| > | ifactor(100); |
| > | ifactor(1234567890); |
7. To find the ith prime number.
ithprime(i)
| > | ithprime(4); |
| > | ithprime(1000); |
THE FOLLOWING COMMANDS REQUIRE THAT THE NUMTHEORY PACKAGE BE LOADED.
| > | with(numtheory): |
Warning, the protected name order has been redefined and unprotected
8. To find the set of prime factors of integer n.
factorset(n)
| > | factorset(100); |
| > | factorset(1234567890); |
9. To obtain the complete list of factors of integer n.
| > | divisors(100); |
| > | divisors(1234567890); |
![]()