Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168822
Image: ubuntu2004

Using the notebook interface

Look at the set of 4 drop down menus directly above this cell.  Notice that the right-most one says ``gap'' (by default it would say ``sage'').

A few notes about using the sage notebook interface:

The work all happens inside "cells" these are the rectangular areas with a thin black outline that you see below.

Move your mouse into the area above or below a cell.  A blue bar appears.  Clicking on this bar creates a new cell.  Shift-clicking creates a text area.

To get rid of a cell, delete all its contents then hit "backspace" in the empty cell.

Hitting "enter" in a cell just inserts a linebreak - to execute the code in a cell you must either click  "evaluate" or hit "enter" while holding down the "shift" key.

Finally, note that the text areas (such as the one you are currently reading) understand LaTeX code so you can put in nicely formatted mathematics:

i=11/i2 =π26 \sum_{i=1}^\infty 1/i^2  = \frac{\pi^2}{6}

1+2;
3
1234 mod 11;
2
2^(2^11)-1;
323170060713110073007148766886699519604441026697154840321303454275246551388678\ 908931972014115229134636887179609218980194941195591504909210950881523864482831\ 206308773673009960917501977503896521067960576383840675682767922186426197561618\ 380943384761704705816458520363050428875758915410658086075523991239303855219143\ 333896683424206849747865645694948561760353263220580778056593310261927084603141\ 502585928641771167259436037184618573575983511523016459044036976132332872312271\ 256847108202097251571017269313234696785425806566979350459972683529986382155251\ 66389437335543602135433229604645318478604952148193555853611059596230655
Factors(last);
[ 3, 5, 17, 257, 641, 65537, 274177, 2424833, 6700417, 45592577, 6487031809, 67280421310721, 1238926361552897, 59649589127497217, 5704689200685129054721, 4659775785220018543264560743076778192897, 7455602825647884208337395736200454918783366342657, 93461639715357977769163558199606896584051237541638188580280321, 7416400626275308015247871419019374740599407810975190239058213161444157595047\ 05008092818711693940737, 1304398744054881897274847687965099039466085308416118921868952957768324162514\ 718635741402279775731048958987839288429238448311490329137987290886016179460941\ 194490105959067101305319061710183544916096191939124885381160807122996723228062\ 17820753127014424577 ]
Gcd(546119821, 882193557);
42009217


Basic arithmetic

As you can see above, GAP can do lots of interesting calculations and it can do them with rather amazingly large numbers!

It also can handle many of the standard rings in which we calculate, including cyclotomics.

QQ:=Rationals; ZZ:=Integers;
Rationals Integers
root5:=E(5)-E(5)^2-E(5)^3+E(5)^4;
E(5)-E(5)^2-E(5)^3+E(5)^4
root5^2;
5
root5 in QQ;
false


Teaching Mode

GAP is really a professional grade tool for researchers in computational group theory.  Most of what it does is heavily optimized and the conventions that experts use are followed.  For beginners it can be bewildering!

Teaching mode is designed to ameliorate this issue.  It is a work in progress, but it is definitely helpful!  Teaching mode will become available with the release of GAP 4.5 which should be any day now!


G1 := CyclicGroup(15);
<pc group of size 15 with 2 generators>

What's a PC group?  Politically correct?  Personal Computer?

 

The polycyclic group above really is Z15Z_{15} but GAP finds it more efficient to have generators for each of the primes dividing 15.  This is one of the things that "Teaching Mode" repairs.

If you want something, today, that is more evidently the cyclic group of some order (or indeed any other small group you might have in mind) you can build a group by specifying its multiplication table.

M:=[]; for i in [0..14] do Add(M, List([0..14], x->(x+i) mod 15)); od; M := 1+M;
[ ] [ [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ], [ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1 ], [ 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2 ], [ 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3 ], [ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4 ], [ 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5 ], [ 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6 ], [ 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7 ], [ 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8 ], [ 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], [ 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ], [ 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], [ 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ], [ 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ] ]
Z15:=GroupByMultiplicationTable(M);
<group of size 15 with 15 generators>
L:=Elements(Z15);
[ m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15 ]
L[4]*L[5];
m8
for x in L do Print(x, "\t", Order(x), "\n"); od;
m1 1 m2 15 m3 15 m4 5 m5 15 m6 3 m7 5 m8 15 m9 15 m10 5 m11 3 m12 15 m13 5 m14 15 m15 15

 

Or, if you are willing to describe cyclic permutations first, you can use:

 

Z8:=Group((1,2,3,4,5,6,7,8));
Group([ (1,2,3,4,5,6,7,8) ])
for x in Elements(Z8) do Print(x, "\t\t", Order(x), "\n"); od;
() 1 (1,2,3,4,5,6,7,8) 8 (1,3,5,7)(2,4,6,8) 4 (1,4,7,2,5,8,3,6) 8 (1,5)(2,6)(3,7)(4,8) 2 (1,6,3,8,5,2,7,4) 8 (1,7,5,3)(2,8,6,4) 4 (1,8,7,6,5,4,3,2) 8

Rings and groups of units

The builtin GAP commands which one might think would create cyclic groups actually construct finite rings.  Of course their additive structure is that of a cyclic group but commands like Order() will think you're asking for the multiplicative order...

im12 := Integers mod 12;
(Integers mod 12)
L:=Elements(im12);
[ ZmodnZObj( 0, 12 ), ZmodnZObj( 1, 12 ), ZmodnZObj( 2, 12 ), ZmodnZObj( 3, 12 ), ZmodnZObj( 4, 12 ), ZmodnZObj( 5, 12 ), ZmodnZObj( 6, 12 ), ZmodnZObj( 7, 12 ), ZmodnZObj( 8, 12 ), ZmodnZObj( 9, 12 ), ZmodnZObj( 10, 12 ), ZmodnZObj( 11, 12 ) ]
o:=One(im12);
ZmodnZObj( 1, 12 )
Order(o);
1
z:=Zero(im12);
ZmodnZObj( 0, 12 )
U := Filtered(L, IsUnit);
[ ZmodnZObj( 1, 12 ), ZmodnZObj( 5, 12 ), ZmodnZObj( 7, 12 ), ZmodnZObj( 11, 12 ) ]


Polynomials

The code below constructs the set of all polynomials with degree at most 2 and coefficients in GF(3).

L:=[]; F:=Integers mod 3; x:=X(F, "x"); for a in [0..2] do for b in [0..2] do for c in [0..2] do Add(L,a*x^2+b*x+c); od; od; od; Print(L);
[ 0*Z(3), Z(3)^0, -Z(3)^0, x, x+Z(3)^0, x-Z(3)^0, -x, -x+Z(3)^0, -x-Z(3)^0, x^2, x^2+Z(3)^0, x^2-Z(3)^0, x^2+x, x^2+x+Z(3)^0, x^2+x-Z(3)^0, x^2-x, x^2-x+Z(3)^0, x^2-x-Z(3)^0, -x^2, -x^2+Z(3)^0, -x^2-Z(3)^0, -x^2+x, -x^2+x+Z(3)^0, -x^2+x-Z(3)^0, -x^2-x, -x^2-x+Z(3)^0, -x^2-x-Z(3)^0 ]
Length(L);
27
L[3];
-Z(3)^0
Position(L, L[4]+L[5]);
8
SizeScreen([120,24]);; N := List(L,a->List(L,b->Position(L,a+b)));; Print(N);
[ [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27 ], [ 2, 3, 1, 5, 6, 4, 8, 9, 7, 11, 12, 10, 14, 15, 13, 17, 18, 16, 20, 21, 19, 23, 24, 22, 26, 27, 25 ], [ 3, 1, 2, 6, 4, 5, 9, 7, 8, 12, 10, 11, 15, 13, 14, 18, 16, 17, 21, 19, 20, 24, 22, 23, 27, 25, 26 ], [ 4, 5, 6, 7, 8, 9, 1, 2, 3, 13, 14, 15, 16, 17, 18, 10, 11, 12, 22, 23, 24, 25, 26, 27, 19, 20, 21 ], [ 5, 6, 4, 8, 9, 7, 2, 3, 1, 14, 15, 13, 17, 18, 16, 11, 12, 10, 23, 24, 22, 26, 27, 25, 20, 21, 19 ], [ 6, 4, 5, 9, 7, 8, 3, 1, 2, 15, 13, 14, 18, 16, 17, 12, 10, 11, 24, 22, 23, 27, 25, 26, 21, 19, 20 ], [ 7, 8, 9, 1, 2, 3, 4, 5, 6, 16, 17, 18, 10, 11, 12, 13, 14, 15, 25, 26, 27, 19, 20, 21, 22, 23, 24 ], [ 8, 9, 7, 2, 3, 1, 5, 6, 4, 17, 18, 16, 11, 12, 10, 14, 15, 13, 26, 27, 25, 20, 21, 19, 23, 24, 22 ], [ 9, 7, 8, 3, 1, 2, 6, 4, 5, 18, 16, 17, 12, 10, 11, 15, 13, 14, 27, 25, 26, 21, 19, 20, 24, 22, 23 ], [ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], [ 11, 12, 10, 14, 15, 13, 17, 18, 16, 20, 21, 19, 23, 24, 22, 26, 27, 25, 2, 3, 1, 5, 6, 4, 8, 9, 7 ], [ 12, 10, 11, 15, 13, 14, 18, 16, 17, 21, 19, 20, 24, 22, 23, 27, 25, 26, 3, 1, 2, 6, 4, 5, 9, 7, 8 ], [ 13, 14, 15, 16, 17, 18, 10, 11, 12, 22, 23, 24, 25, 26, 27, 19, 20, 21, 4, 5, 6, 7, 8, 9, 1, 2, 3 ], [ 14, 15, 13, 17, 18, 16, 11, 12, 10, 23, 24, 22, 26, 27, 25, 20, 21, 19, 5, 6, 4, 8, 9, 7, 2, 3, 1 ], [ 15, 13, 14, 18, 16, 17, 12, 10, 11, 24, 22, 23, 27, 25, 26, 21, 19, 20, 6, 4, 5, 9, 7, 8, 3, 1, 2 ], [ 16, 17, 18, 10, 11, 12, 13, 14, 15, 25, 26, 27, 19, 20, 21, 22, 23, 24, 7, 8, 9, 1, 2, 3, 4, 5, 6 ], [ 17, 18, 16, 11, 12, 10, 14, 15, 13, 26, 27, 25, 20, 21, 19, 23, 24, 22, 8, 9, 7, 2, 3, 1, 5, 6, 4 ], [ 18, 16, 17, 12, 10, 11, 15, 13, 14, 27, 25, 26, 21, 19, 20, 24, 22, 23, 9, 7, 8, 3, 1, 2, 6, 4, 5 ], [ 19, 20, 21, 22, 23, 24, 25, 26, 27, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 ], [ 20, 21, 19, 23, 24, 22, 26, 27, 25, 2, 3, 1, 5, 6, 4, 8, 9, 7, 11, 12, 10, 14, 15, 13, 17, 18, 16 ], [ 21, 19, 20, 24, 22, 23, 27, 25, 26, 3, 1, 2, 6, 4, 5, 9, 7, 8, 12, 10, 11, 15, 13, 14, 18, 16, 17 ], [ 22, 23, 24, 25, 26, 27, 19, 20, 21, 4, 5, 6, 7, 8, 9, 1, 2, 3, 13, 14, 15, 16, 17, 18, 10, 11, 12 ], [ 23, 24, 22, 26, 27, 25, 20, 21, 19, 5, 6, 4, 8, 9, 7, 2, 3, 1, 14, 15, 13, 17, 18, 16, 11, 12, 10 ], [ 24, 22, 23, 27, 25, 26, 21, 19, 20, 6, 4, 5, 9, 7, 8, 3, 1, 2, 15, 13, 14, 18, 16, 17, 12, 10, 11 ], [ 25, 26, 27, 19, 20, 21, 22, 23, 24, 7, 8, 9, 1, 2, 3, 4, 5, 6, 16, 17, 18, 10, 11, 12, 13, 14, 15 ], [ 26, 27, 25, 20, 21, 19, 23, 24, 22, 8, 9, 7, 2, 3, 1, 5, 6, 4, 17, 18, 16, 11, 12, 10, 14, 15, 13 ], [ 27, 25, 26, 21, 19, 20, 24, 22, 23, 9, 7, 8, 3, 1, 2, 6, 4, 5, 18, 16, 17, 12, 10, 11, 15, 13, 14 ] ]
3Z3 := GroupByMultiplicationTable(N);
<group of size 27 with 27 generators>
els := Elements(3Z3); for x in els do Print(x, "\t", Order(x), "\n"); od;
[ m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, m16, m17, m18, m19, m20, m21, m22, m23, m24, m25, m26, m27 ] m1 1 m2 3 m3 3 m4 3 m5 3 m6 3 m7 3 m8 3 m9 3 m10 3 m11 3 m12 3 m13 3 m14 3 m15 3 m16 3 m17 3 m18 3 m19 3 m20 3 m21 3 m22 3 m23 3 m24 3 m25 3 m26 3 m27 3
D:=DihedralGroup(8);
<pc group of size 8 with 3 generators>
L:=Elements(D);
[ <identity> of ..., f1, f2, f3, f1*f2, f1*f3, f2*f3, f1*f2*f3 ]
# Don't evaluate this. It will cause errors in GAP 4.4. U := (); _U := (1,6)(2,3)(4,5)(7,8); I := (1,7,6,8)(2,5,3,4); _I := (1,8,6,7)(2,4,3,5); J := (1,2,6,3)(4,8,5,7); _J := (1,3,6,2)(4,7,5,8); K := (1,4,6,5)(2,7,3,8); _K := (1,5,6,4)(2,8,3,7); SetNameObject(U," 1"); SetNameObject(I," i"); SetNameObject(J," j"); SetNameObject(K," k"); SetNameObject(_U," -1"); SetNameObject(_I," -i"); SetNameObject(_J," -j"); SetNameObject(_K," -k"); Q:=Group(U,I,J,K);

Permutations and Cycle Notation

This falls into the "using GAP as a fancy calculator" category:


p:=(1,2,3,4)(5,6,7,8); q:=(1,3,5,7);
(1,2,3,4)(5,6,7,8) (1,3,5,7)
p*q;
(1,2,5,6)(3,4)(7,8)
q*p;
(1,4)(2,3,6,7)(5,8)