Here is an extended example of some of Magma's features.
The books "Solving Problems with Magma" and "An Introduction to Magma" contain additional hard-copy examples of Magma code.
> GF81<w> := GF(3, 4);
> print GF81, PrimeField(GF81);
Finite field of size 3^4
Finite field of size 3
> print Set(GF81);
{ 1, w^67, w, w^68, w^2, w^69, w^3, w^70, w^4, w^71, w^5,
w^72, w^6, w^73, w^7, w^74, w^8, w^75, w^9, w^76, w^10, w^77,
w^11, w^78, w^12, w^79, w^13, 0, w^14, w^15, w^16, w^17,
w^18, w^19, w^20, w^21, w^22, w^23, w^24, w^25, w^26, w^27,
w^28, w^29, w^30, w^31, w^32, w^33, w^34, w^35, w^36, w^37,
w^38, w^39, 2, w^41, w^42, w^43, w^44, w^45, w^46, w^47,
w^48, w^49, w^50, w^51, w^52, w^53, w^54, w^55, w^56, w^57,
w^58, w^59, w^60, w^61, w^62, w^63, w^64, w^65, w^66 }
> // NB: there is no particular order in the elements of a set
> e := 2 * w^5; print e;
w^45
> P<x> := PolynomialRing(GF81);
> print P;
Univariate Polynomial Algebra in x
over Finite field of size 3^4
> p := 2*x^6 - w*x^2 + 1; print p;
2*x^6 + w^41*x^2 + 1
> p_at_e := Evaluate(p, e);
> print p_at_e;
w^47
> // Another way of constructing a polynomial is to
> // give a sequence containing coefficients,
> // starting with the constant term
> pp := P![w^5, 1, 1, 0, w^31, 1]; print pp;
x^5 + w^31*x^4 + x^2 + x + w^5
> // [Above] coefficients given with constant term first
> /* Now, the same polynomial construction method,
> but this time the coefficient sequence is
> built using a sequence constructor */
> ppp := P![ w^(5*i) : i in [1..8] ];
> print ppp;
2*x^7 + w^35*x^6 + w^30*x^5 + w^25*x^4 + w^20*x^3 + w^15*x^2
+ w^10*x + w^5
> FF := FieldOfFractions(P); print FF;
Field of Fractions in x over Univariate Polynomial Algebra
in x over Finite field of size 3^4
> V5 := VectorSpace(FF, 5); print V5;
Full Vector space of degree 5 over Field of Fractions in x
over Univariate Polynomial Algebra in x over GF(3^4)
> print Basis(V5);
[
( 1 0 0 0 0),
( 0 1 0 0 0),
( 0 0 1 0 0),
( 0 0 0 1 0),
( 0 0 0 0 1)
]
> // the generators V5.i (here they are the same as the basis vectors)
> for i in [1..5] do
for> print V5.i;
for> end for;
( 1 0 0 0 0)
( 0 1 0 0 0)
( 0 0 1 0 0)
( 0 0 0 1 0)
( 0 0 0 0 1)
> V5sub := sub< V5 | $.1, x^2*$.3 - w^7*$.4,
> 2*$.1 - w*x^3*$.3 + w^8*x*$.4 >;
> print V5sub;
Vector space of degree 5, dimension 2 over Field of Fractions
in x over Univariate Polynomial Algebra in x over GF(3^4)
Generators:
( 1 0 0 0 0)
( 0 0 x^2 w^47 0)
( 2 0 w^41*x^3 w^8*x 0)
Echelonized basis:
( 1 0 0 0 0)
( 0 0 1 w^47 / x^2 0)
> // multiple assignment: Q will be the quotient group
> // and f will be the natural homomorphism
> Q, f := quo< V5 | V5sub >;
> print Q;
Full Vector space of degree 3 over Field of Fractions in x
over Univariate Polynomial Algebra in x over GF(3^4)
> print f;
Mapping from: ModTupFld: V5 to ModTupFld: Q
> print Image(f);
Full Vector space of degree 3 over Field of Fractions in x
over Univariate Polynomial Algebra in x over GF(3^4)
> print Kernel(f);
Vector space of degree 5, dimension 2 over
Field of Fractions in x over
Univariate Polynomial Algebra in x over GF(3^4)
Echelonized basis:
( 1 0 0 0 0)
( 0 0 1 w^47 / x^2 0)
> print V5sub eq Kernel(f);
true
> for n in [1..3] do
for> print Q.n, (Q.n)@@f, ""; // preimages
for> end for;
( 1 0 0)
( 0 1 0 0 0)
( 0 1 0)
( 0 0 w^73*x^2 0 0)
( 0 0 1)
( 0 0 0 0 1)
[Next][Prev] [Right] [____] [Up] [Index] [Root]