The GAP command to compute all the divisors of an integer
is DivisorsInt(n);
For example, DivisorsInt(15);
returns [1,3,5,15].
The remainder and quotient of
divided by
are
the commands
RemInt( n, m ); QuoInt( n, m );,
respectively. For example, RemInt(155, 15 );
returns 5.
GAP does not have a base
conversion directly.
One must use it's p-adic numbers package to convert from
decimal to base
and this only works when
is
a prime. The command fam:=PurePadicNumberFamily(p,k);
creates the data needed to work with base
notation,
when
is a prime. The integer
indicates the
number of
-ary digits which will be used.
The command PadicNumber(fam,a); returns the
expansion of
in base
out to
places.
For example, fam2:=PurePadicNumberFamily(2,6);
and PadicNumber(fam2,14); returns
0.111(2) This is read least significant to most
significant digits, left to right:
the 0 is the
's place, those to the right of the
decimal point are the
's place,
's places, and so
on. The
in the parentheses is the base
,
so the output tells us
.
The greatest common divisor of
and
is given by
GcdInt( m, n); . For example, GcdInt( 108,801);
returns 9.
To find
such that
, use the GAP
command Gcdex( m,n);. For example,
Gcdex( 108,801);
returns
rec( gcd := 9, coeff1 := -37, coeff2 := 5,
coeff3 := 89, coeff4 := -12 ),
where ![]()
coeff1, ![]()
coeff2 .
To find the least common divisor of
and
,
use the GAP command LcmInt( m, n); .
For example, LcmInt( 155,15);
returns 255 .
The Euler totient function
is given by the
command Phi(n);. For example,
Phi(2^{13}-1); returns 8190.
The next prime after
is given by the command
NextPrimeInt(n);. The
prime is given by
the command Primes(n);.
For example, NextPrimeInt(100);
Primes(100); returns 101 and
541, respectively.
The prime factorization of
is given by the command
FactorsInt(n); . For example, FactorsInt( 2^63 - 1 );
returns
[ 7, 7, 73, 127, 337, 92737, 649657 ] .
Program the Lucas-Lehmer sequence
,
, ....
, by typing
lucaslehmer :=function(n) if n = 1 then return 4; fi; if 1 < n then return lucaslehmer(n - 1)^2 - 2; fi; return 0; end;
(b) What is the largest prime you can find on your computer using this test?
(c) Rewrite the code so that the
procedure computes
and
.
(d) Find the smallest
for which your computer
takes more than 1 minute (by your watch) to compute
.
The Lucas-Perrin sequence
Program this sequence into GAP by typing
lucasperrin:=function(n) if n = 1 then return 0; fi; if n = 2 then return 2; fi; if n = 3 then return 3; fi; if n > 3 then return lucasperrin(n-2)+lucasperrin(n-3); fi; return -1; end;
(a) Compute
.
(b) What is the largest ``prime candidate'' you can find on your computer 1.10?
Question: Is
divisible by
if and only if
is prime?
If the answer was yes, this would be a very fast primality
test. On the other hand, it is ``yes'' for all
up to 15000,
as can be checked using GAP.
(Exercise: Do this!) However,
the answer is ``no''. Indeed,
the smallest counterexample (discovered by D. Shanks and W. Adams
[AS]) seems to be
.
The Chinese remainder theorem commands
give us the
minimal solution
of
,
,
...,
.
The command for the Chinese remainder theorem
is
ChineseRem([n1,n2,...,nk],[a1,a2,...,ak]); .
For example,
ChineseRem([5,7],[1,2]);
returns 16.
The multiplicative order of
mod
in GAP is given by
OrderMod( a, m ); . For example, OrderMod(2,7);
returns 3.
(a) the order of
mod
,
(b) the order of
mod
.
PowerMod( r, e, m ); returns the
power of
modulo
.
The primitive root mod
is given by
PrimitiveRootMod(m); .
The discrete log is given by
LogMod( a, b,m); .
For example, PrimitiveRootMod(7); and LogMod( 64, 5,97);
returns 3 and 12, respectively.
(a) Find the
discrete log of
to base
mod
, if it exists.
(b) Is
a prime?
Is
a primitive root mod
?
Find the
discrete log of
to base
mod
, if it exists
(ans:
),