In the course of learning Sage I have tried to compile a list of number-theoretic functions in Maple along with their more-or-less direct Sage equivalents, if such equivalents exist.
Note this is not all of Maple's number theory functions: it is essentially the numtheory package plus a few important top-level functions like modp, irem, and iquo. There are more top-level rountines, and more functionality is available in other packages, such as GaussInt.
In the second column below I use the following abbreviations and colours:
As I'm not yet familiar with Sage, I have undoubtedly missed some obvious analogues. My main source for Sage information was the Sage Tutorial and Reference Manual; any claim that a Sage equivalent does not exist comes from my failure to find it in these documents.
Please contact me if you have any questions, corrections, or other comments about this list.
| Maple function | =? | Sage equivalent | Notes |
|---|---|---|---|
| igcd(n) | Y | gcd(n) | |
| ilcm(n) | Y | lcm(n) | |
| ilog(n,b) | Y | n.exact_log(b) | largest integer k s.t. b^k ≤ n |
| iquo(m,n) | Y | m // n | integer division |
| irem(m,n) | Y | m % n | integer remainder |
| isprime(n) | Y | n.isprime() | |
| ithprime(n) | Y | nth_prime(n) | |
| modp(m,n) | Y | Mod(m,n) | |
| mods(m,n) | N | symmetric modulus (i.e. signed) | |
| nextprime(n) | Y | next_prime(n) | |
| prevprime(n) | Y | previous_prime(n) | |
| Maple numtheory package | |||
| numtheory:-bigomega(n) | Y | sloane.A001222(n) | # of prime divisors with multiplicity |
| numtheory:-cfrac(x) | P | continued_fraction(x) | Maple has more functionality:
CFRAC data structure |
| numtheory:-cfracpol | ? | continued fraction expansions for all real roots of a rational polynomial | |
| numtheory:-cyclotomic(a,b) | Y | cyclotomic_polynomial(a,b) | |
| numtheory:-divisors(n) | Y | divisors(n) | |
| numtheory:-factorEQ(x,d) | Y | K.<r> = QuadraticField(d) K.factor_integer(x) | factor integers in Z[sqrt(d)] |
| numtheory:-factorset(n) | Y | prime_factors(n) | |
| numtheory:-fermat(n) | N | information about nth Fermat number | |
| numtheory:-GIgcd(x) | ? | GCD of Gaussian integers | |
| numtheory:-imagunit(n) | Y | R=IntegerModRing(n) sqrt( R(-1) ) | square root of -1 (mod n) |
| numtheory:-index(x,a,n) | Y | (see numtheory:-mlog(x,a,n)) | |
| numtheory:-integral_basis(x) | Y | t = QQ['z'].0 K = NumberField(x,'s') K.integral_basis() |
compute integral basis of algebraic number fields given irreducible polynom or algebraic number |
| numtheory:-invcfrac(x) | ? | convert CFRAC to surd | |
| numtheory:-invphi(n) | N | inverse of phi function: returns list L s.t. phi(x)=n for x in L | |
| numtheory:-issqrfree(n) | Y | n.is_squarefree() | |
| numtheory:-jacobi(m,n) | Y | kronecker_symbol(m,n) | |
| numtheory:-kronecker | N | Inhomogenous Diophantine approximation | |
| numtheory:-lambda(n) | N | Carmichael λ function (Sloane's A002322) | |
| numtheory:-legendre(m,n) | Y | kronecker_symbol(m,n) | |
| numtheory:-mcombine(a,ra,b,rb) | Y | CRT(ra,rb,a,b) | Chinese remaindering |
| numtheory:-migcdex(N,a,b1,...,bn) | N | solve modulo N extended GCD problem | |
| numtheory:-mipolys(n,p,m) | N | number of monic irreducible polynomials of degree n over GF(p^m) | |
| numtheory:-mersenne([n]) | Y | sloane.A000668(n) | Mersenne primes |
| numtheory:-minkowski | N | solve Minkowski's linear forms (homogeneous Diophantine approximation) | |
| numtheory:-mlog(x,a,n) | P | b=Mod(a,n) discrete_log_generic(x,b) |
Maple can also return characteristic of domain of answer |
| numtheory:-mobius(n) | Y | moebius(n) | Möbius function |
| numtheory:-mroot(x,n,p) | Y | R = IntegerModRing(p) R(x).nth_root(n) | nth root of x (mod p) |
| numtheory:-msqrt(x, n) | Y | R = IntegerModRing(n) sqrt(R(x)) | |
| numtheory:-nearestp | ? | nearby lattice point problem | |
| numtheory:-nthconver(x,n) | Y | convergent(x,n) | nth rational convergent |
| numtheory:-nthdenom | ? | denom of nth convergent of continued fraction (w.o. computing convergent) | |
| numtheory:-nthnumer | ? | numer of nth convergent of continued fraction (w.o. computing convergent) | |
| numtheory:-nthpow(m,n) | ? | largest b s.t. b^n divides m | |
| numtheory:-order(m,n) | Y | R = IntegerModRing(n) R(m).multiplicative_order() | |
| numtheory:-pdexpand(x) | N | data structure for periodic decimal expansion of rational x | |
| numtheory:-phi(n) | Y | euler_phi(n) | |
| numtheory:-pi(n) | Y | prime_pi(n) | |
| numtheory:-pprimroot | N | pseudo-primitive root | |
| numtheory:-primroot(n) | Y | primitive_root(n) | |
| numtheory:-quadres | Y | ? | |
| numtheory:-rootsunity(p,n) | P | for p prime: R = IntegerModRing(n) zeta(p, all=True) | for p composite, unknown |
| numtheory:-safeprime(n) | N | smallest prime p ≥ n s.t. (p-1)/2 is prime | |
| numtheory:-sigma(n) | Y | sigma(n) | |
| numtheory:-sigma[k](n) | Y | sigma(n,k) | |
| numtheory:-sq2factor(n) | Y |
R.<sqrt2> = QuadraticField(2) R.factor_integer(n) | factor integers in Z[sqrt(2)] |
| numtheory:-sum2sqr(n) | P | two_squares(n) | Maple returns multiple results; Sage doesn't |
| numtheory:-tau(n) | Y | sloane.A000005(n) | number of divisors |
| numtheory:-thue | N | solve Thue equation or inequality | |