8.1.1 modules.free_module - Free modules

SAGE supports computation with free modules over an arbitrary commutative ring. Nontrivial functionality is available over $ \mathbf{Z}$ and fields. All free modules over an integral domain are equipped with an embedding in an ambient vector space and an inner product, which you can specify.

The following example illustrates the creation of both a vector spaces and a free module over the integers and a submodule of it.

sage: V = VectorSpace(RationalField(),3)
sage: W = V.subspace([V([1,2,7]), V([1,1,0])])
sage: W
Vector space of degree 3 and dimension 2 over Rational Field
Basis matrix:
[ 1  0 -7]
[ 0  1  7]
sage: C = VectorSpaces(FiniteField(7))
sage: C
Category of vector spaces over Finite field of size 7
sage: C(W)
Vector space of degree 3 and dimension 2 over Finite field of size 7
Basis matrix:
[1 0 0]
[0 1 0]

sage: M = FreeModule(IntegerRing(), 3)
sage: C = VectorSpaces(FiniteField(7))
sage: C(M)
Vector space of dimension 3 over Finite field of size 7
sage: W = M.subspace([M([1,2,7]), M([8,8,0])])
sage: C(W)
Vector space of degree 3 and dimension 2 over Finite field of size 7
Basis matrix:
[1 0 0]
[0 1 0]

The module modules.free_module defines the following methods:

FreeModule( base_ring, rank, [sparse=None], [inner_product_matrix=False])

Create the free module over the given commutative ring of the given rank.

INPUT:
    base_ring -- a commutative ring
    rank -- a nonnegative integer
    sparse -- bool; (default False)
    inner_product_matrix -- the inner product matrix (default None)

OUTPUT:
    a free module

First we illustrate creating free modules over various base fields. Notice how the base field affects the free module that is created. For example, free modules over a field are vector spaces, and free modules over a principal ideal domain are special in that more functionality is available for them.

sage: FreeModule(Integers(8),10)
Ambient free module of rank 10 over Ring of integers modulo 8
sage: FreeModule(RationalField(),10)
Vector space of dimension 10 over Rational Field
sage: FreeModule(IntegerRing(),10)
Ambient free module of rank 10 over the principal ideal domain Integer Ring
sage: FreeModule(FiniteField(5),10)
Vector space of dimension 10 over Finite field of size 5
sage: FreeModule(Integers(7),10)
Vector space of dimension 10 over Ring of integers modulo 7
sage: FreeModule(PolynomialRing(RationalField()),5)
Ambient free module of rank 5 over the principal ideal domain Univariate
Polynomial Ring in x over Rational Field
sage: FreeModule(PolynomialRing(IntegerRing()),5)
Ambient free module of rank 5 over the integral domain Univariate
Polynomial Ring in x over Integer Ring

Of course we can make rank 0 free modules:

sage: FreeModule(RealField(100),0)
Vector space of dimension 0 over Real Field with 100 bits of precision

Next we create a free module with sparse representation of elements. These work exactly as with dense representations, but they may use less memory and arithmetic may be faster.

sage: M = FreeModule(IntegerRing(),200,sparse=True)
sage: M.is_sparse()
True
sage: type(M.gen(0))
<class 'sage.modules.free_module_element.FreeModuleElement_generic_sparse'>

The default is dense.

sage: M = FreeModule(IntegerRing(),200)
sage: type(M.gen(0))
<class 'sage.modules.free_module_element.FreeModuleElement_generic_dense'>

Note that matrices associated in some way to sparse free modules are sparse by default, and the default representation is dense:

sage: M = FreeModule(Integers(8), 2)
sage: A = M.basis_matrix()
sage: A.is_sparse()
False
sage: Ms = FreeModule(Integers(8), 2, sparse=True)
sage: M == Ms   # as mathematical objects they are equal
True
sage: Ms.basis_matrix().is_sparse()
True

We can also specify an inner product matrix, which is used when computing inner products of elements.

sage: Z = IntegerRing()
sage: A = MatrixSpace(Z,2)([[1,0],[0,-1]])
sage: M = FreeModule(IntegerRing(),2,inner_product_matrix=A)
sage: v, w = M.gens()
sage: v.inner_product(w)
0
sage: v.inner_product(v)
1
sage: w.inner_product(w)
-1
sage: (v+2*w).inner_product(w)
-2

VectorSpace( K, dimension, [sparse=None], [inner_product_matrix=False])

The base can be complicated:

sage: V = VectorSpace(FractionField(PolynomialRing(IntegerRing())),3)
sage: V
Vector space of dimension 3 over Fraction field of Univariate Polynomial
Ring in x over Integer Ring
sage: V.basis()
[(1, 0, 0), (0, 1, 0), (0, 0, 1)]

The base must be a field or a TypeError is raised.

sage: VectorSpace(IntegerRing(),5)
Traceback (most recent call last):
...
TypeError: K must be a field

The module modules.free_module defines the following classes:

class FreeModule_ambient
Ambient free module over a commutative ring.

class FreeModule_ambient_domain
Ambient free module over an integral domain.

class FreeModule_ambient_field

class FreeModule_ambient_pid
Ambient free module over a principal ideal domain.

class FreeModule_generic
Base class for all free modules.

class FreeModule_generic_field
Base class for all free modules over fields (i.

class FreeModule_generic_pid
Base class for all free modules over a PID

class FreeModule_submodule_field
A vector subspace.

class FreeModule_submodule_pid
An $ R$ -submodule of $ K^n$ where $ K$ is the fraction field of a principal ideal domain $ R$ .

class FreeModule_submodule_with_basis_field
A vector subspace with distinguished basis.

class FreeModule_submodule_with_basis_pid
An $ R$ -submodule of $ K^n$ with distinguished basis, where $ K$ is the fraction field of a principal ideal domain $ R$ .



Subsections
See About this document... for information on suggesting changes.