Sage supports computation with free modules over an arbitrary commutative ring.
Nontrivial functionality is available over , fields, and some principal
ideal domains (e.g.
and rings of integers of number 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 and change.
Create the free module of rank over an arbitrary commutative ring
using
the command FreeModule(R,n). Equivalently, R^n also creates that free
module.
The following example illustrates the creation of both a vector space and a free module over the integers and a submodule of it. Use the functions FreeModule, span and member functions of free modules to create free modules. Do not use the FreeModule_xxx constructors directly.
EXAMPLES:
sage: V = VectorSpace(QQ,3)
sage: W = V.subspace([[1,2,7], [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 = ZZ^3
sage: C = VectorSpaces(FiniteField(7))
sage: C(M)
Vector space of dimension 3 over Finite Field of size 7
sage: W = M.submodule([[1,2,7], [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]
We illustrate the exponent notation for creation of free modules.
sage: ZZ^4
Ambient free module of rank 4 over the principal ideal domain Integer Ring
sage: QQ^2
Vector space of dimension 2 over Rational Field
sage: RR^3
Vector space of dimension 3 over Real Field with 53 bits of precision
Base ring:
sage: R.<x,y> = QQ[]
sage: M = FreeModule(R,2)
sage: M.base_ring()
Multivariate Polynomial Ring in x, y over Rational Field
sage: VectorSpace(QQ, 10).base_ring()
Rational Field
TESTS: We intersect a zero-dimensional vector space with a 1-dimension submodule.
sage: V = (QQ^1).span([])
sage: W = ZZ^1
sage: V.intersection(W)
Free module of degree 1 and rank 0 over Integer Ring
Echelon basis matrix:
[]
We construct subspaces of real and complex double vector spaces and verify that the element types are correct:
sage: V = FreeModule(RDF, 3); V
Vector space of dimension 3 over Real Double Field
sage: V.0
(1.0, 0.0, 0.0)
sage: type(V.0)
<type 'sage.modules.vector_real_double_dense.Vector_real_double_dense'>
sage: W = V.span([V.0]); W
Vector space of degree 3 and dimension 1 over Real Double Field
Basis matrix:
[1.0 0.0 0.0]
sage: type(W.0)
<type 'sage.modules.vector_real_double_dense.Vector_real_double_dense'>
sage: V = FreeModule(CDF, 3); V
Vector space of dimension 3 over Complex Double Field
sage: type(V.0)
<type 'sage.modules.vector_complex_double_dense.Vector_complex_double_dense'>
sage: W = V.span_of_basis([CDF.0 * V.1]); W
Vector space of degree 3 and dimension 1 over Complex Double Field
User basis matrix:
[ 0 1.0*I 0]
sage: type(W.0)
<type 'sage.modules.vector_complex_double_dense.Vector_complex_double_dense'>
Basis vectors are immutable:
sage: A = span([[1,2,3], [4,5,6]], ZZ)
sage: A.0
(1, 2, 3)
sage: A.0[0] = 5
...
ValueError: vector is immutable; please change a copy instead (use copy())
We can save and load submodules and elements:
sage: M = ZZ^3
sage: M == loads(M.dumps())
True
sage: W = M.span_of_basis([[1,2,3],[4,5,19]])
sage: W == loads(W.dumps())
True
sage: v = W.0 + W.1
sage: v == loads(v.dumps())
True
AUTHORS:
Create the free module over the given commutative ring of the given rank.
INPUT:
OUTPUT: a free module
Note
In Sage it is the case that there is only one dense and one
sparse free ambient module of rank over
.
EXAMPLES:
First we illustrate creating free modules over various base fields. 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 than for completely general free modules.
sage: FreeModule(Integers(8),10)
Ambient free module of rank 10 over Ring of integers modulo 8
sage: FreeModule(QQ,10)
Vector space of dimension 10 over Rational Field
sage: FreeModule(ZZ,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(QQ,'x'),5)
Ambient free module of rank 5 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field
sage: FreeModule(PolynomialRing(ZZ,'x'),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. Functionality with sparse modules is identical to dense modules, but they may use less memory and arithmetic may be faster (or slower!).
sage: M = FreeModule(ZZ,200,sparse=True)
sage: M.is_sparse()
True
sage: type(M.0)
<type 'sage.modules.free_module_element.FreeModuleElement_generic_sparse'>
The default is dense.
sage: M = ZZ^200
sage: type(M.0)
<type 'sage.modules.vector_integer_dense.Vector_integer_dense'>
Note that matrices associated in some way to sparse free modules are sparse by default:
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: A = MatrixSpace(ZZ,2)([[1,0],[0,-1]])
sage: M = FreeModule(ZZ,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
You can also specify the inner product matrix by giving anything that coerces to an appropriate matrix. This is only useful if the inner product matrix takes values in the base ring.
sage: FreeModule(ZZ,2,inner_product_matrix=1).inner_product_matrix()
[1 0]
[0 1]
sage: FreeModule(ZZ,2,inner_product_matrix=[1,2,3,4]).inner_product_matrix()
[1 2]
[3 4]
sage: FreeModule(ZZ,2,inner_product_matrix=[[1,2],[3,4]]).inner_product_matrix()
[1 2]
[3 4]
TESTS:
sage: loads(dumps(ZZ^6)) is ZZ^6
True
sage: loads(dumps(RDF^3)) is RDF^3
True
Ambient free module over a commutative ring.
Compare the free module self with other.
Modules are ordered by their ambient spaces, then by dimension, then in order by their echelon matrices.
EXAMPLES:
We compare rank three free modules over the integers and rationals:
sage: QQ^3 < CC^3
True
sage: CC^3 < QQ^3
False
sage: CC^3 > QQ^3
True
sage: Q = QQ; Z = ZZ
sage: Q^3 > Z^3
True
sage: Q^3 < Z^3
False
sage: Z^3 < Q^3
True
sage: Z^3 > Q^3
False
sage: Q^3 == Z^3
False
sage: Q^3 == Q^3
True
sage: V = span([[1,2,3], [5,6,7], [8,9,10]], QQ)
sage: V
Vector space of degree 3 and dimension 2 over Rational Field
Basis matrix:
[ 1 0 -1]
[ 0 1 2]
sage: A = QQ^3
sage: V < A
True
sage: A < V
False
The hash of self.
EXAMPLES:
sage: V = QQ^7
sage: V.__hash__()
153079684 # 32-bit
-3713095619189944444 # 64-bit
sage: U = QQ^7
sage: U.__hash__()
153079684 # 32-bit
-3713095619189944444 # 64-bit
sage: U is V
True
The free module of given rank over the given base_ring.
INPUT:
EXAMPLES:
sage: FreeModule(ZZ, 4)
Ambient free module of rank 4 over the principal ideal domain Integer Ring
Creates a dense module with the same defining data as self.
N.B. This function is for internal use only! See dense_module for use.
EXAMPLES:
sage: M = FreeModule(Integers(8),3)
sage: S = FreeModule(Integers(8),3, sparse=True)
sage: M is S._dense_module()
True
Return a latex representation of this ambient free module.
EXAMPLES:
sage: latex(QQ^3) # indirect doctest
\Bold{Q}^{3}
sage: A = GF(5)^20
sage: latex(A) # indiret doctest
\Bold{F}_{5}^{20}
sage: A = PolynomialRing(QQ,3,'x') ^ 20
sage: latex(A) #indirect doctest
(\Bold{Q}[x_{0}, x_{1}, x_{2}])^{20}
The printing representation of self.
EXAMPLES:
sage: R = ZZ.quo(12)
sage: M = R^12
sage: print M
Ambient free module of rank 12 over Ring of integers modulo 12
sage: print M._repr_()
Ambient free module of rank 12 over Ring of integers modulo 12
The system representation can be overwritten, but leaves _repr_ unmodified.
sage: M.rename('M')
sage: print M
M
sage: print M._repr_()
Ambient free module of rank 12 over Ring of integers modulo 12
Sparse modules print this fact.
sage: N = FreeModule(R,12,sparse=True)
sage: print N
Ambient sparse free module of rank 12 over Ring of integers modulo 12
Creates a sparse module with the same defining data as self.
N.B. This function is for internal use only! See sparse_module for use.
EXAMPLES:
sage: M = FreeModule(Integers(8),3)
sage: S = FreeModule(Integers(8),3, sparse=True)
sage: M._sparse_module() is S
True
Return self, since self is ambient.
EXAMPLES:
sage: A = QQ^5; A.ambient_module()
Vector space of dimension 5 over Rational Field
sage: A = ZZ^5; A.ambient_module()
Ambient free module of rank 5 over the principal ideal domain Integer Ring
Return a basis for this ambient free module.
OUTPUT:
EXAMPLES:
sage: A = ZZ^3; B = A.basis(); B
[
(1, 0, 0),
(0, 1, 0),
(0, 0, 1)
]
sage: B.universe()
Ambient free module of rank 3 over the principal ideal domain Integer Ring
Return the ambient free module over R of the same rank as self.
EXAMPLES:
sage: A = ZZ^3; A.change_ring(QQ)
Vector space of dimension 3 over Rational Field
sage: A = ZZ^3; A.change_ring(GF(5))
Vector space of dimension 3 over Finite Field of size 5
For ambient modules any change of rings is defined.
sage: A = GF(5)**3; A.change_ring(QQ)
Vector space of dimension 3 over Rational Field
Write in terms of the standard basis for self and
return the resulting coefficients in a vector over the fraction
field of the base ring.
Returns a vector such that if
is the basis for self, then
If is not in self, raises an ArithmeticError
exception.
EXAMPLES:
sage: V = Integers(16)^3
sage: v = V.coordinate_vector([1,5,9]); v
(1, 5, 9)
sage: v.parent()
Ambient free module of rank 3 over Ring of integers modulo 16
Same as self.coordinate_vector(v), since self is an ambient free module.
INPUT:
OUTPUT: list
EXAMPLES:
sage: V = QQ^4
sage: v = V([-1/2,1/2,-1/2,1/2])
sage: v
(-1/2, 1/2, -1/2, 1/2)
sage: V.coordinate_vector(v)
(-1/2, 1/2, -1/2, 1/2)
sage: V.echelon_coordinate_vector(v)
(-1/2, 1/2, -1/2, 1/2)
sage: W = V.submodule_with_basis([[1/2,1/2,1/2,1/2],[1,0,1,0]])
sage: W.coordinate_vector(v)
(1, -1)
sage: W.echelon_coordinate_vector(v)
(-1/2, 1/2)
Returns the coordinate vector of v in terms of the echelon basis for self.
EXAMPLES:
sage: U = VectorSpace(QQ,3)
sage: [ U.coordinates(v) for v in U.basis() ]
[[1, 0, 0], [0, 1, 0], [0, 0, 1]]
sage: [ U.echelon_coordinates(v) for v in U.basis() ]
[[1, 0, 0], [0, 1, 0], [0, 0, 1]]
sage: V = U.submodule([[1,1,0],[0,1,1]])
sage: V
Vector space of degree 3 and dimension 2 over Rational Field
Basis matrix:
[ 1 0 -1]
[ 0 1 1]
sage: [ V.coordinates(v) for v in V.basis() ]
[[1, 0], [0, 1]]
sage: [ V.echelon_coordinates(v) for v in V.basis() ]
[[1, 0], [0, 1]]
sage: W = U.submodule_with_basis([[1,1,0],[0,1,1]])
sage: W
Vector space of degree 3 and dimension 2 over Rational Field
User basis matrix:
[1 1 0]
[0 1 1]
sage: [ W.coordinates(v) for v in W.basis() ]
[[1, 0], [0, 1]]
sage: [ W.echelon_coordinates(v) for v in W.basis() ]
[[1, 1], [0, 1]]
Return a basis for this ambient free module in echelon form.
EXAMPLES:
sage: A = ZZ^3; A.echelonized_basis()
[
(1, 0, 0),
(0, 1, 0),
(0, 0, 1)
]
The echelonized basis matrix of self.
EXAMPLES:
sage: V = ZZ^4
sage: W = V.submodule([ V.gen(i)-V.gen(0) for i in range(1,4) ])
sage: W.basis_matrix()
[ 1 0 0 -1]
[ 0 1 0 -1]
[ 0 0 1 -1]
sage: W.echelonized_basis_matrix()
[ 1 0 0 -1]
[ 0 1 0 -1]
[ 0 0 1 -1]
sage: U = V.submodule_with_basis([ V.gen(i)-V.gen(0) for i in range(1,4) ])
sage: U.basis_matrix()
[-1 1 0 0]
[-1 0 1 0]
[-1 0 0 1]
sage: U.echelonized_basis_matrix()
[ 1 0 0 -1]
[ 0 1 0 -1]
[ 0 0 1 -1]
Return True since this module is an ambient module.
EXAMPLES:
sage: A = QQ^5; A.is_ambient()
True
sage: A = (QQ^5).span([[1,2,3,4,5]]); A.is_ambient()
False
Return the linear combination of the basis for self obtained from the elements of the list v.
EXAMPLES:
sage: V = span([[1,2,3], [4,5,6]], ZZ)
sage: V
Free module of degree 3 and rank 2 over Integer Ring
Echelon basis matrix:
[1 2 3]
[0 3 6]
sage: V.linear_combination_of_basis([1,1])
(1, 5, 9)
Returns a random element of self.
INPUT:
EXAMPLES:
sage: M = FreeModule(ZZ, 3)
sage: M.random_element()
(-1, 2, 1)
sage: M.random_element()
(-95, -1, -2)
sage: M.random_element()
(-12, 0, 0)
sage: M = FreeModule(ZZ, 16)
sage: M.random_element()
(1, -1, 1, -1, -2, -1, 4, -4, -6, 5, 0, 0, -2, 0, 1, -4)
sage: M.random_element(prob=0.3)
(0, 0, 0, 0, 0, 0, 0, -6, 1, -1, 1, 0, 1, 0, 0, 0)
Ambient free module over an integral domain.
Create the ambient free module of given rank over the given integral domain.
EXAMPLES:
sage: FreeModule(PolynomialRing(GF(5),'x'), 3)
Ambient free module of rank 3 over the principal ideal domain
Univariate Polynomial Ring in x over Finite Field of size 5
The printing representation of self.
EXAMPLES:
sage: R = PolynomialRing(ZZ,'x')
sage: M = FreeModule(R,7)
sage: print M
Ambient free module of rank 7 over the integral domain Univariate Polynomial Ring in x over Integer Ring
sage: print M._repr_()
Ambient free module of rank 7 over the integral domain Univariate Polynomial Ring in x over Integer Ring
The system representation can be overwritten, but leaves _repr_ unmodified.
sage: M.rename('M')
sage: print M
M
sage: print M._repr_()
Ambient free module of rank 7 over the integral domain Univariate Polynomial Ring in x over Integer Ring
Sparse modules print this fact.
sage: N = FreeModule(R,7,sparse=True)
sage: print N
Ambient sparse free module of rank 7 over the integral domain Univariate Polynomial Ring in x over Integer Ring
Returns the ambient vector space, which is this free module tensored with its fraction field.
EXAMPLES:
sage: M = ZZ^3;
sage: V = M.ambient_vector_space(); V
Vector space of dimension 3 over Rational Field
If an inner product on the module is specified, then this is preserved on the ambient vector space.
sage: N = FreeModule(ZZ,4,inner_product_matrix=1)
sage: U = N.ambient_vector_space()
sage: U
Ambient quadratic space of dimension 4 over Rational Field
Inner product matrix:
[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 0 1]
sage: P = N.submodule_with_basis([[1,-1,0,0],[0,1,-1,0],[0,0,1,-1]])
sage: P.gram_matrix()
[ 2 -1 0]
[-1 2 -1]
[ 0 -1 2]
sage: U == N.ambient_vector_space()
True
sage: U == V
False
Return the fraction field of the base ring of self.
EXAMPLES:
sage: M = ZZ^3; M.base_field()
Rational Field
sage: M = PolynomialRing(GF(5),'x')^3; M.base_field()
Fraction Field of Univariate Polynomial Ring in x over Finite Field of size 5
Write in terms of the standard basis for self and
return the resulting coefficients in a vector over the fraction
field of the base ring.
INPUT:
OUTPUT: list
Returns a vector such that if
is the basis for self, then
If is not in self, raises an ArithmeticError exception.
EXAMPLES:
sage: V = ZZ^3
sage: v = V.coordinate_vector([1,5,9]); v
(1, 5, 9)
sage: v.parent()
Vector space of dimension 3 over Rational Field
Returns the vector space obtained from self by tensoring with the fraction field of the base ring and extending to the field.
EXAMPLES:
sage: M = ZZ^3; M.vector_space()
Vector space of dimension 3 over Rational Field
Create an element of this vector space.
EXAMPLE:
sage: k.<a> = GF(3^4)
sage: VS = k.vector_space()
sage: VS(a)
(0, 1, 0, 0)
Create the ambient vector space of given dimension over the given field.
INPUT:
EXAMPLES:
sage: QQ^3
Vector space of dimension 3 over Rational Field
The printing representation of self.
EXAMPLES:
sage: V = FreeModule(QQ,7)
sage: print V
Vector space of dimension 7 over Rational Field
sage: print V._repr_()
Vector space of dimension 7 over Rational Field
The system representation can be overwritten, but leaves _repr_ unmodified.
sage: V.rename('V')
sage: print V
V
sage: print V._repr_()
Vector space of dimension 7 over Rational Field
Sparse modules print this fact.
sage: U = FreeModule(QQ,7,sparse=True)
sage: print U
Sparse vector space of dimension 7 over Rational Field
Returns self as the ambient vector space.
EXAMPLES:
sage: M = QQ^3
sage: M.ambient_vector_space()
Vector space of dimension 3 over Rational Field
Returns the base field of this vector space.
EXAMPLES:
sage: M = QQ^3
sage: M.base_field()
Rational Field
Ambient free module over a principal ideal domain.
Create the ambient free module of given rank over the given principal ideal domain.
INPUT:
EXAMPLES:
sage: ZZ^3
Ambient free module of rank 3 over the principal ideal domain Integer Ring
The printing representation of self.
EXAMPLES:
sage: M = FreeModule(ZZ,7)
sage: print M
Ambient free module of rank 7 over the principal ideal domain Integer Ring
sage: print M._repr_()
Ambient free module of rank 7 over the principal ideal domain Integer Ring
The system representation can be overwritten, but leaves _repr_ unmodified.
sage: M.rename('M')
sage: print M
M
sage: print M._repr_()
Ambient free module of rank 7 over the principal ideal domain Integer Ring
Sparse modules print this fact.
sage: N = FreeModule(ZZ,7,sparse=True)
sage: print N
Ambient sparse free module of rank 7 over the principal ideal domain Integer Ring
Base class for all free modules.
Create an element of this free module from x.
The coerce and copy arguments are passed on to the underlying element constructor. If check is True, confirm that the element specified by x does in fact lie in self.
EXAMPLE:
sage: M = ZZ^4
sage: M([1,-1,0,1])
(1, -1, 0, 1)
sage: N = M.submodule([[1,0,0,0], [0,1,1,0]])
sage: N([1,1,1,0])
(1, 1, 1, 0)
sage: N((3,-2,-2,0))
(3, -2, -2, 0)
sage: N((0,0,0,1))
...
TypeError: element (= (0, 0, 0, 1)) is not in free module
Beware that using check=False can create invalid results:
sage: N((0,0,0,1), check=False)
(0, 0, 0, 1)
sage: N((0,0,0,1), check=False) in N
True
Here is an example showing how the numerical instability causes trouble. The equality test below returns either True or False, depending on the architecture.
sage: v = matrix(RDF, 3, range(9)).eigenspaces()[0][1].basis()[0]
sage: v.complex_vector()
(...0.440242867..., ...0.567868371..., ...0.695493875...)
sage: v.complex_vector().parent().echelonized_basis_matrix()[0] * v[0]
(...0.440242867..., ...0.567868371..., ...0.695493875...)
sage: v.complex_vector().parent().echelonized_basis_matrix()[0] * v[0] == v.complex_vector() # random
False
sage: v.complex_vector().parent().echelonized_basis_matrix()[0] * v[0] - v.complex_vector() # random
(0, -1.11022302463e-16, 0)
EXAMPLES:
We create the module , and the submodule
generated by one vector
, and check whether
certain elements are in the submodule.
sage: R = FreeModule(ZZ, 3)
sage: V = R.submodule([R.gen(0) + R.gen(1)])
sage: R.gen(0) + R.gen(1) in V
True
sage: R.gen(0) + 2*R.gen(1) in V
False
sage: w = (1/2)*(R.gen(0) + R.gen(1))
sage: w
(1/2, 1/2, 0)
sage: w.parent()
Vector space of dimension 3 over Rational Field
sage: w in V
False
sage: V.coordinates(w)
[1/2]
Create the free module of given rank over the given base_ring.
INPUT:
EXAMPLES:
sage: PolynomialRing(QQ,3,'x')^3
Ambient free module of rank 3 over the integral domain Multivariate Polynomial Ring in x0, x1, x2 over Rational Field
Return iterator over the elements of this free module.
EXAMPLES:
sage: V = VectorSpace(GF(4,'a'),2)
sage: [x for x in V]
[(0, 0), (a, 0), (a + 1, 0), (1, 0), (0, a), (a, a), (a + 1, a), (1, a), (0, a + 1), (a, a + 1), (a + 1, a + 1), (1, a + 1), (0, 1), (a, 1), (a + 1, 1), (1, 1)]
sage: W = V.subspace([V([1,1])])
sage: print [x for x in W]
[(0, 0), (a, a), (a + 1, a + 1), (1, 1)]
Return the cardinality of the free module.
N.B. Currently len(QQ) gives a TypeError, hence so does len(QQ3).
EXAMPLES:
sage: k.<a> = FiniteField(9)
sage: V = VectorSpace(k,3)
sage: len(V)
729
sage: W = V.span([[1,2,1],[0,1,1]])
sage: len(W)
81
sage: R = IntegerModRing(12)
sage: M = FreeModule(R,2)
sage: len(M)
144
Returns an arbitrary element of a free module.
EXAMPLES:
sage: V = VectorSpace(QQ,2)
sage: V._an_element_impl()
(1, 0)
sage: U = V.submodule([[1,0]])
sage: U._an_element_impl()
(1, 0)
sage: W = V.submodule([])
sage: W._an_element_impl()
(0, 0)
Canonical coercion of x into this free module.
EXAMPLES:
sage: V = QQ^5
sage: x = V([0,4/3,8/3,4,16/3])
sage: V._coerce_impl(x)
(0, 4/3, 8/3, 4, 16/3)
sage: V._coerce_impl([0,4/3,8/3,4,16/3])
...
TypeError: Automatic coercion supported only for vectors or 0.
Creates a dense module with the same defining data as self.
N.B. This function is for internal use only! See dense_module for use.
EXAMPLES:
sage: M = FreeModule(Integers(8),3)
sage: S = FreeModule(Integers(8),3, sparse=True)
sage: M is S._dense_module()
True
Return True if V canonically coerces to self.
EXAMPLES:
sage: V = QQ^3
sage: V._has_coerce_map_from_space(V)
True
sage: W = V.span([[1,1,1]])
sage: V._has_coerce_map_from_space(W)
True
sage: W._has_coerce_map_from_space(V)
False
Return whether or not the inner product on this module is induced by the dot product on the ambient vector space. This is used internally by the inner_product function for optimization.
EXAMPLES:
sage: FreeModule(ZZ, 3)._inner_product_is_dot_product()
True
sage: FreeModule(ZZ, 3, inner_product_matrix=1)._inner_product_is_dot_product()
True
sage: FreeModule(ZZ, 2, inner_product_matrix=[1,0,-1,0])._inner_product_is_dot_product()
False
sage: M = FreeModule(QQ, 3)
sage: M2 = M.span([[1,2,3]])
sage: M2._inner_product_is_dot_product()
True
EXAMPLES:
sage: R = QQ^2
sage: macaulay2(R) # optional
2
QQ
EXAMPLES:
sage: magma(QQ^9) # optional - magma
Full Vector space of degree 9 over Rational Field
sage: (QQ^9)._magma_init_(magma) # optional - magma
'RSpace(_sage_[...],9)'
sage: magma(Integers(8)^2) # optional - magma
Full RSpace of degree 2 over IntegerRing(8)
sage: magma(FreeModule(QQ['x'], 2)) # optional - magma
Full RSpace of degree 2 over Univariate Polynomial Ring in x over Rational Field
sage: A = matrix([[1,0],[0,-1]])
sage: M = FreeModule(ZZ,2,inner_product_matrix=A); M
Ambient free quadratic module of rank 2 over the principal ideal domain Integer Ring
Inner product matrix:
[ 1 0]
[ 0 -1]
sage: M._magma_init_(magma) # optional - magma
'RSpace(_sage_[...],2,_sage_ref...)'
sage: m = magma(M); m # optional - magma
Full RSpace of degree 2 over Integer Ring
Inner Product Matrix:
[ 1 0]
[ 0 -1]
sage: m.Type() # optional - magma
ModTupRng
sage: m.sage() # optional - magma
Ambient free quadratic module of rank 2 over the principal ideal domain Integer Ring
Inner product matrix:
[ 1 0]
[ 0 -1]
sage: m.sage() is M # optional - magma
True
Now over a field:
sage: N = FreeModule(QQ,2,inner_product_matrix=A); N
Ambient quadratic space of dimension 2 over Rational Field
Inner product matrix:
[ 1 0]
[ 0 -1]
sage: n = magma(N); n # optional - magma
Full Vector space of degree 2 over Rational Field
Inner Product Matrix:
[ 1 0]
[ 0 -1]
sage: n.Type() # optional - magma
ModTupFld
sage: n.sage() # optional - magma
Ambient quadratic space of dimension 2 over Rational Field
Inner product matrix:
[ 1 0]
[ 0 -1]
sage: n.sage() is N # optional - magma
True
How about some inexact fields:
sage: v = vector(RR, [1, pi, 5/6])
sage: F = v.parent()
sage: M = magma(F); M # optional - magma
Full Vector space of degree 3 over Real field of precision 15
sage: M.Type() # optional - magma
ModTupFld
sage: m = M.sage(); m # optional - magma
Vector space of dimension 3 over Real Field with 53 bits of precision
sage: m is F # optional - magma
True
For interval fields, we can convert to Magma but there is no interval field in Magma so we cannot convert back:
sage: v = vector(RealIntervalField(100), [1, pi, 0.125])
sage: F = v.parent()
sage: M = magma(v.parent()); M # optional - magma
Full Vector space of degree 3 over Real field of precision 30
sage: M.Type() # optional - magma
ModTupFld
sage: m = M.sage(); m # optional - magma
Vector space of dimension 3 over Real Field with 100 bits of precision
sage: m is F # optional - magma
False
Creates a sparse module with the same defining data as self.
N.B. This function is for internal use only! See sparse_module for use.
EXAMPLES:
sage: M = FreeModule(Integers(8),3)
sage: S = FreeModule(Integers(8),3, sparse=True)
sage: M._sparse_module() is S
True
Return the ambient module associated to this module.
EXAMPLES:
sage: R.<x,y> = QQ[]
sage: M = FreeModule(R,2)
sage: M.ambient_module()
Ambient free module of rank 2 over the integral domain Multivariate Polynomial Ring in x, y over Rational Field
sage: V = FreeModule(QQ, 4).span([[1,2,3,4], [1,0,0,0]]); V
Vector space of degree 4 and dimension 2 over Rational Field
Basis matrix:
[ 1 0 0 0]
[ 0 1 3/2 2]
sage: V.ambient_module()
Vector space of dimension 4 over Rational Field
Return the base extension of self to R. This is the same as self.change_ring(R) except that a TypeError is raised if there is no canonical coerce map from the base ring of self to R.
INPUT:
EXAMPLES:
sage: V = ZZ^7
sage: V.base_extend(QQ)
Vector space of dimension 7 over Rational Field
Return the basis of this module.
EXAMPLES:
sage: FreeModule(Integers(12),3).basis()
[
(1, 0, 0),
(0, 1, 0),
(0, 0, 1)
]
Return the matrix whose rows are the basis for this free module.
EXAMPLES:
sage: FreeModule(Integers(12),3).basis_matrix()
[1 0 0]
[0 1 0]
[0 0 1]
sage: M = FreeModule(GF(7),3).span([[2,3,4],[1,1,1]]); M
Vector space of degree 3 and dimension 2 over Finite Field of size 7
Basis matrix:
[1 0 6]
[0 1 2]
sage: M.basis_matrix()
[1 0 6]
[0 1 2]
sage: M = FreeModule(GF(7),3).span_of_basis([[2,3,4],[1,1,1]]);
sage: M.basis_matrix()
[2 3 4]
[1 1 1]
Return the category to which this free module belongs. This is the category of all free modules over the base ring.
EXAMPLES:
sage: FreeModule(GF(7),3).category()
Category of vector spaces over Finite Field of size 7
The construction functor and base ring for self.
EXAMPLES:
sage: R = PolynomialRing(QQ,3,'x')
sage: V = R^5
sage: V.construction()
(VectorFunctor, Multivariate Polynomial Ring in x0, x1, x2 over Rational Field)
Suppose V is a submodule of self (or a module commensurable with
self), and that self is a free module over of rank
. Let
be the map from self to
that sends the basis vectors of self in order to the
standard basis of
. This function returns the image
.
Warning
If there is no integer such that
is a
submodule of self, then this function will give total
nonsense.
EXAMPLES:
We illustrate this function with some
-submodules of
.
sage: V = (ZZ^3).span([[1/2,3,5], [0,1,-3]])
sage: W = (ZZ^3).span([[1/2,4,2]])
sage: V.coordinate_module(W)
Free module of degree 2 and rank 1 over Integer Ring
User basis matrix:
[1 4]
sage: V.0 + 4*V.1
(1/2, 4, 2)
In this example, the coordinate module isn’t even in
.
sage: W = (ZZ^3).span([[1/4,2,1]])
sage: V.coordinate_module(W)
Free module of degree 2 and rank 1 over Integer Ring
User basis matrix:
[1/2 2]
The following more elaborate example illustrates using this function to write a submodule in terms of integral cuspidal modular symbols:
sage: M = ModularSymbols(54)
sage: S = M.cuspidal_subspace()
sage: K = S.integral_structure(); K
Free module of degree 19 and rank 8 over Integer Ring
Echelon basis matrix:
[ 0 1 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
...
sage: L = M[0].integral_structure(); L
Free module of degree 19 and rank 2 over Integer Ring
Echelon basis matrix:
[ 0 1 1 0 -2 1 -1 1 -1 -2 2 0 0 0 0 0 0 0 0]
[ 0 0 3 0 -3 2 -1 2 -1 -4 2 -1 -2 1 2 0 0 -1 1]
sage: K.coordinate_module(L)
Free module of degree 8 and rank 2 over Integer Ring
User basis matrix:
[ 1 1 1 -1 1 -1 0 0]
[ 0 3 2 -1 2 -1 -1 -2]
sage: K.coordinate_module(L).basis_matrix() * K.basis_matrix()
[ 0 1 1 0 -2 1 -1 1 -1 -2 2 0 0 0 0 0 0 0 0]
[ 0 0 3 0 -3 2 -1 2 -1 -4 2 -1 -2 1 2 0 0 -1 1]
Return the vector whose coefficients give as a linear
combination of the basis for self.
INPUT:
OUTPUT: list
EXAMPLES:
sage: M = FreeModule(ZZ, 2); M0,M1=M.gens()
sage: W = M.submodule([M0 + M1, M0 - 2*M1])
sage: W.coordinate_vector(2*M0 - M1)
(2, -1)
Write in terms of the basis for self.
INPUT:
OUTPUT: list
Returns a list such that if
is the basis
for self, then
If is not in self, raises an
ArithmeticError exception.
EXAMPLES:
sage: M = FreeModule(ZZ, 2); M0,M1=M.gens()
sage: W = M.submodule([M0 + M1, M0 - 2*M1])
sage: W.coordinates(2*M0-M1)
[2, -1]
Return the degree of this free module. This is the dimension of the ambient vector space in which it is embedded.
EXAMPLES:
sage: M = FreeModule(ZZ, 10)
sage: W = M.submodule([M.gen(0), 2*M.gen(3) - M.gen(0), M.gen(0) + M.gen(3)])
sage: W.degree()
10
sage: W.rank()
2
Return corresponding dense module.
EXAMPLES:
We first illustrate conversion with ambient spaces:
sage: M = FreeModule(QQ,3)
sage: S = FreeModule(QQ,3, sparse=True)
sage: M.sparse_module()
Sparse vector space of dimension 3 over Rational Field
sage: S.dense_module()
Vector space of dimension 3 over Rational Field
sage: M.sparse_module() == S
True
sage: S.dense_module() == M
True
sage: M.dense_module() == M
True
sage: S.sparse_module() == S
True
Next we create a subspace:
sage: M = FreeModule(QQ,3, sparse=True)
sage: V = M.span([ [1,2,3] ] ); V
Sparse vector space of degree 3 and dimension 1 over Rational Field
Basis matrix:
[1 2 3]
sage: V.sparse_module()
Sparse vector space of degree 3 and dimension 1 over Rational Field
Basis matrix:
[1 2 3]
Return the dimension of this free module.
EXAMPLES:
sage: M = FreeModule(FiniteField(19), 100)
sage: W = M.submodule([M.gen(50)])
sage: W.dimension()
1
Return the direct sum of self and other as a free module.
EXAMPLES:
sage: V = (ZZ^3).span([[1/2,3,5], [0,1,-3]]); V
Free module of degree 3 and rank 2 over Integer Ring
Echelon basis matrix:
[1/2 0 14]
[ 0 1 -3]
sage: W = (ZZ^3).span([[1/2,4,2]]); W
Free module of degree 3 and rank 1 over Integer Ring
Echelon basis matrix:
[1/2 4 2]
sage: V.direct_sum(W)
Free module of degree 6 and rank 3 over Integer Ring
Echelon basis matrix:
[1/2 0 14 0 0 0]
[ 0 1 -3 0 0 0]
[ 0 0 0 1/2 4 2]
Return the discriminant of this free module.
EXAMPLES:
sage: M = FreeModule(ZZ, 3)
sage: M.discriminant()
1
sage: W = M.span([[1,2,3]])
sage: W.discriminant()
14
sage: W2 = M.span([[1,2,3], [1,1,1]])
sage: W2.discriminant()
6
The echelonized basis matrix (not implemented for this module).
This example works because M is an ambient module. Submodule creation should exist for generic modules.
EXAMPLES:
sage: R = IntegerModRing(12)
sage: S.<x,y> = R[]
sage: M = FreeModule(S,3)
sage: M.echelonized_basis_matrix()
[1 0 0]
[0 1 0]
[0 0 1]
TESTS:
sage: from sage.modules.free_module import FreeModule_generic
sage: FreeModule_generic.echelonized_basis_matrix(M)
...
NotImplementedError
The class of elements for this free module.
EXAMPLES:
sage: M = FreeModule(ZZ,20,sparse=False)
sage: x = M.random_element()
sage: type(x)
<type 'sage.modules.vector_integer_dense.Vector_integer_dense'>
sage: M.element_class()
<type 'sage.modules.vector_integer_dense.Vector_integer_dense'>
sage: N = FreeModule(ZZ,20,sparse=True)
sage: y = N.random_element()
sage: type(y)
<type 'sage.modules.free_module_element.FreeModuleElement_generic_sparse'>
sage: N.element_class()
<type 'sage.modules.free_module_element.FreeModuleElement_generic_sparse'>
Return this free module. (This is used by the FreeModule functor, and simply returns self.)
EXAMPLES:
sage: M = FreeModule(ZZ, 3)
sage: M.free_module()
Ambient free module of rank 3 over the principal ideal domain Integer Ring
Return ith generator for self, where i is between 0 and rank-1, inclusive.
INPUT:
OUTPUT: i-th basis vector for self.
EXAMPLES:
sage: n = 5
sage: V = QQ^n
sage: B = [ V.gen(i) for i in range(n) ]
sage: B
[(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)]
sage: V.gens() == tuple(B)
True
TESTS:
sage: (QQ^3).gen(4/3)
...
TypeError: rational is not an integer
Return the gram matrix associated to this free module, defined to be G = B*A*B.transpose(), where A is the inner product matrix (induced from the ambient space), and B the basis matrix.
EXAMPLES:
sage: V = VectorSpace(QQ,4)
sage: u = V([1/2,1/2,1/2,1/2])
sage: v = V([0,1,1,0])
sage: w = V([0,0,1,1])
sage: M = span([u,v,w], ZZ)
sage: M.inner_product_matrix() == V.inner_product_matrix()
True
sage: L = M.submodule_with_basis([u,v,w])
sage: L.inner_product_matrix() == M.inner_product_matrix()
True
sage: L.gram_matrix()
[1 1 1]
[1 2 1]
[1 1 2]
Return True if the basis of this free module is specified by the user, as opposed to being the default echelon form.
EXAMPLES:
sage: V = QQ^3
sage: W = V.subspace([[2,'1/2', 1]])
sage: W.has_user_basis()
False
sage: W = V.subspace_with_basis([[2,'1/2',1]])
sage: W.has_user_basis()
True
Return the default identity inner product matrix associated to this module.
By definition this is the inner product matrix of the ambient space, hence may be of degree greater than the rank of the module.
TODO: Differentiate the image ring of the inner product from the base ring of the module and/or ambient space. E.g. On an integral module over ZZ the inner product pairing could naturally take values in ZZ, QQ, RR, or CC.
EXAMPLES:
sage: M = FreeModule(ZZ, 3)
sage: M.inner_product_matrix()
[1 0 0]
[0 1 0]
[0 0 1]
Returns False since this is not an ambient free module.
EXAMPLES:
sage: M = FreeModule(ZZ, 3).span([[1,2,3]]); M
Free module of degree 3 and rank 1 over Integer Ring
Echelon basis matrix:
[1 2 3]
sage: M.is_ambient()
False
sage: M = (ZZ^2).span([[1,0], [0,1]])
sage: M
Free module of degree 2 and rank 2 over Integer Ring
Echelon basis matrix:
[1 0]
[0 1]
sage: M.is_ambient()
False
sage: M == M.ambient_module()
True
Return True if the underlying representation of this module uses dense vectors, and False otherwise.
EXAMPLES:
sage: FreeModule(ZZ, 2).is_dense()
True
sage: FreeModule(ZZ, 2, sparse=True).is_dense()
False
Returns True if the underlying set of this free module is finite.
EXAMPLES:
sage: FreeModule(ZZ, 2).is_finite()
False
sage: FreeModule(Integers(8), 2).is_finite()
True
sage: FreeModule(ZZ, 0).is_finite()
True
Return True if the rank of this module equals its degree.
EXAMPLES:
sage: FreeModule(ZZ, 2).is_full()
True
sage: M = FreeModule(ZZ, 2).span([[1,2]])
sage: M.is_full()
False
Return True if the underlying representation of this module uses sparse vectors, and False otherwise.
EXAMPLES:
sage: FreeModule(ZZ, 2).is_sparse()
False
sage: FreeModule(ZZ, 2, sparse=True).is_sparse()
True
Return True if self is a submodule of other.
EXAMPLES:
sage: M = FreeModule(ZZ,3)
sage: V = M.ambient_vector_space()
sage: X = V.span([[1/2,1/2,0],[1/2,0,1/2]], ZZ)
sage: Y = V.span([[1,1,1]], ZZ)
sage: N = X + Y
sage: M.is_submodule(X)
False
sage: M.is_submodule(Y)
False
sage: Y.is_submodule(M)
True
sage: N.is_submodule(M)
False
sage: M.is_submodule(N)
True
Since basis() is not implemented in general, submodule testing does not work for all PID’s. However, trivial cases are already used (and useful) for coercion, e.g.
sage: QQ(1/2) * vector(ZZ['x']['y'],[1,2,3,4])
(1/2, 1, 3/2, 2)
sage: vector(ZZ['x']['y'],[1,2,3,4]) * QQ(1/2)
(1/2, 1, 3/2, 2)
Return the basis matrix of this module, which is the matrix whose rows are a basis for this module.
EXAMPLES:
sage: M = FreeModule(ZZ, 2)
sage: M.matrix()
[1 0]
[0 1]
sage: M.submodule([M.gen(0) + M.gen(1), M.gen(0) - 2*M.gen(1)]).matrix()
[1 1]
[0 3]
Returns the number of basis elements of this free module.
EXAMPLES:
sage: FreeModule(ZZ, 2).ngens()
2
sage: FreeModule(ZZ, 0).ngens()
0
sage: FreeModule(ZZ, 2).span([[1,1]]).ngens()
1
Returns an ambient free module that is isomorphic to this free module.
Thus if this free module is of rank over a ring
, then this function returns
, as an
ambient free module.
EXAMPLES:
sage: FreeModule(ZZ, 2).span([[1,1]]).nonembedded_free_module()
Ambient free module of rank 1 over the principal ideal domain Integer Ring
Returns a random element of self.
INPUT:
EXAMPLES:
sage: M = FreeModule(ZZ, 2).span([[1,1]])
sage: M.random_element()
(-1, -1)
sage: M.random_element()
(2, 2)
sage: M.random_element()
(1, 1)
Return the rank of this free module.
EXAMPLES:
sage: FreeModule(Integers(6), 10000000).rank()
10000000
sage: FreeModule(ZZ, 2).span([[1,1], [2,2], [3,4]]).rank()
2
Return the corresponding sparse module with the same defining data.
EXAMPLES:
We first illustrate conversion with ambient spaces:
sage: M = FreeModule(Integers(8),3)
sage: S = FreeModule(Integers(8),3, sparse=True)
sage: M.sparse_module()
Ambient sparse free module of rank 3 over Ring of integers modulo 8
sage: S.dense_module()
Ambient free module of rank 3 over Ring of integers modulo 8
sage: M.sparse_module() is S
True
sage: S.dense_module() is M
True
sage: M.dense_module() is M
True
sage: S.sparse_module() is S
True
Next we convert a subspace:
sage: M = FreeModule(QQ,3)
sage: V = M.span([ [1,2,3] ] ); V
Vector space of degree 3 and dimension 1 over Rational Field
Basis matrix:
[1 2 3]
sage: V.sparse_module()
Sparse vector space of degree 3 and dimension 1 over Rational Field
Basis matrix:
[1 2 3]
Return True if the inner product on this module is the one induced by the ambient inner product.
EXAMPLES:
sage: M = FreeModule(ZZ, 2)
sage: W = M.submodule([[1,2]])
sage: W.uses_ambient_inner_product()
True
sage: W.inner_product_matrix()
[1 0]
[0 1]
sage: W.gram_matrix()
[5]
Returns the zero vector in this free module.
EXAMPLES:
sage: M = FreeModule(ZZ, 2)
sage: M.zero_vector()
(0, 0)
sage: M(0)
(0, 0)
sage: M.span([[1,1]]).zero_vector()
(0, 0)
sage: M.zero_submodule().zero_vector()
(0, 0)
Base class for all free modules over fields.
This internal function is used by self.quotient(...).
EXAMPLES:
sage: V = QQ^3; W = V.span([[1,0,-1], [1,-1,0]])
sage: A, L = V._FreeModule_generic_field__quotient_matrices(W)
sage: A
[1]
[1]
[1]
sage: L
[1 0 0]
The quotient and lift maps are used to compute in the quotient and to lift:
sage: Q = V/W
sage: Q(W.0)
(0)
sage: Q.lift_map()(Q.0)
(1, 0, 0)
sage: Q(Q.lift_map()(Q.0))
(1)
An example in characteristic 5:
sage: A = GF(5)^2; B = A.span([[1,3]]); A / B
Vector space quotient V/W of dimension 1 over Finite Field of size 5 where
V: Vector space of dimension 2 over Finite Field of size 5
W: Vector space of degree 2 and dimension 1 over Finite Field of size 5
Basis matrix:
[1 3]
Return the sum of self and other.
EXAMPLES:
sage: V = VectorSpace(QQ,3)
sage: V0 = V.span([V.gen(0)])
sage: V2 = V.span([V.gen(2)])
sage: V0 + V2
Vector space of degree 3 and dimension 2 over Rational Field
Basis matrix:
[1 0 0]
[0 0 1]
sage: QQ^3 + 0
Vector space of dimension 3 over Rational Field
Return the quotient of self by the given subspace sub.
This just calls self.quotient(sub, check)
EXAMPLES:
sage: V = RDF^3; W = V.span([[1,0,-1], [1,-1,0]])
sage: Q = V/W; Q
Vector space quotient V/W of dimension 1 over Real Double Field where
V: Vector space of dimension 3 over Real Double Field
W: Vector space of degree 3 and dimension 2 over Real Double Field
Basis matrix:
[ 1.0 0.0 -1.0]
[ 0.0 1.0 -1.0]
sage: type(Q)
<class 'sage.modules.quotient_module.FreeModule_ambient_field_quotient'>
sage: V([1,2,3])
(1.0, 2.0, 3.0)
sage: Q == V.quotient(W)
True
sage: Q(W.0)
(0.0)
Creates a vector space over a field.
EXAMPLES:
sage: FreeModule(QQ, 2)
Vector space of dimension 2 over Rational Field
sage: FreeModule(FiniteField(2), 7)
Vector space of dimension 7 over Finite Field of size 2
Return the category to which this vector space belongs.
EXAMPLES:
sage: V = QQ^4; V.category()
Category of vector spaces over Rational Field
sage: V = GF(5)**20; V.category()
Category of vector spaces over Finite Field of size 5
Return basis matrix for self in row echelon form.
EXAMPLES:
sage: V = FreeModule(QQ, 3).span_of_basis([[1,2,3],[4,5,6]])
sage: V.basis_matrix()
[1 2 3]
[4 5 6]
sage: V.echelonized_basis_matrix()
[ 1 0 -1]
[ 0 1 2]
Return the intersection of self and other, which must be R-submodules of a common ambient vector space.
EXAMPLES:
sage: V = VectorSpace(QQ,3)
sage: W1 = V.submodule([V.gen(0), V.gen(0) + V.gen(1)])
sage: W2 = V.submodule([V.gen(1), V.gen(2)])
sage: W1.intersection(W2)
Vector space of degree 3 and dimension 1 over Rational Field
Basis matrix:
[0 1 0]
sage: W2.intersection(W1)
Vector space of degree 3 and dimension 1 over Rational Field
Basis matrix:
[0 1 0]
sage: V.intersection(W1)
Vector space of degree 3 and dimension 2 over Rational Field
Basis matrix:
[1 0 0]
[0 1 0]
sage: W1.intersection(V)
Vector space of degree 3 and dimension 2 over Rational Field
Basis matrix:
[1 0 0]
[0 1 0]
sage: Z = V.submodule([])
sage: W1.intersection(Z)
Vector space of degree 3 and dimension 0 over Rational Field
Basis matrix:
[]
True if this vector space is a subspace of other.
EXAMPLES:
sage: V = VectorSpace(QQ,3)
sage: W = V.subspace([V.gen(0), V.gen(0) + V.gen(1)])
sage: W2 = V.subspace([V.gen(1)])
sage: W.is_subspace(V)
True
sage: W2.is_subspace(V)
True
sage: W.is_subspace(W2)
False
sage: W2.is_subspace(W)
True
Return the quotient of self by the given subspace sub.
INPUT:
EXAMPLES:
sage: A = QQ^3; V = A.span([[1,2,3], [4,5,6]])
sage: Q = V.quotient( [V.0 + V.1] ); Q
Vector space quotient V/W of dimension 1 over Rational Field where
V: Vector space of degree 3 and dimension 2 over Rational Field
Basis matrix:
[ 1 0 -1]
[ 0 1 2]
W: Vector space of degree 3 and dimension 1 over Rational Field
Basis matrix:
[1 1 1]
sage: Q(V.0 + V.1)
(0)
We illustrate the the base rings must be the same:
sage: (QQ^2)/(ZZ^2)
...
ValueError: base rings must be the same
Returns an ambient free module isomorphic to the quotient space of self modulo sub, together with maps from self to the quotient, and a lifting map in the other direction.
Use self.quotient(sub) to obtain the quotient module as an object equipped with natural maps in both directions, and a canonical coercion.
INPUT:
OUTPUT:
EXAMPLES:
sage: V = GF(19)^3
sage: W = V.span_of_basis([ [1,2,3], [1,0,1] ])
sage: U,pi,lift = V.quotient_abstract(W)
sage: pi(V.2)
(18)
sage: pi(V.0)
(1)
sage: pi(V.0 + V.2)
(0)
Another example involving a quotient of one subspace by another.
sage: A = matrix(QQ,4,4,[0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0,0])
sage: V = (A^3).kernel()
sage: W = A.kernel()
sage: U, pi, lift = V.quotient_abstract(W)
sage: [pi(v) == 0 for v in W.gens()]
[True]
sage: [pi(lift(b)) == b for b in U.basis()]
[True, True]
Return the product of self by the number other, which is the module spanned by other times each basis vector. Since self is a vector space this product equals self if other is nonzero, and is the zero vector space if other is 0.
EXAMPLES:
sage: V = QQ^4
sage: V.scale(5)
Vector space of dimension 4 over Rational Field
sage: V.scale(0)
Vector space of degree 4 and dimension 0 over Rational Field
Basis matrix:
[]
sage: W = V.span([[1,1,1,1]])
sage: W.scale(2)
Vector space of degree 4 and dimension 1 over Rational Field
Basis matrix:
[1 1 1 1]
sage: W.scale(0)
Vector space of degree 4 and dimension 0 over Rational Field
Basis matrix:
[]
sage: V = QQ^4; V
Vector space of dimension 4 over Rational Field
sage: V.scale(3)
Vector space of dimension 4 over Rational Field
sage: V.scale(0)
Vector space of degree 4 and dimension 0 over Rational Field
Basis matrix:
[]
Return the K-span of the given list of gens, where K is the base field of self or the user-specified base_ring. Note that this span is a subspace of the ambient vector space, but need not be a subspace of self.
INPUT:
EXAMPLES:
sage: V = VectorSpace(GF(7), 3)
sage: W = V.subspace([[2,3,4]]); W
Vector space of degree 3 and dimension 1 over Finite Field of size 7
Basis matrix:
[1 5 2]
sage: W.span([[1,1,1]])
Vector space of degree 3 and dimension 1 over Finite Field of size 7
Basis matrix:
[1 1 1]
TESTS:
sage: V = FreeModule(RDF,3)
sage: W = V.submodule([V.gen(0)])
sage: W.span([V.gen(1)], base_ring=GF(7))
Vector space of degree 3 and dimension 1 over Finite Field of size 7
Basis matrix:
[0 1 0]
sage: v = V((1, pi, e)); v
(1.0, 3.14159265359, 2.71828182846)
sage: W.span([v], base_ring=GF(7))
...
ValueError: Argument gens (= [(1.0, 3.14159265359, 2.71828182846)]) is not compatible with base_ring (= Finite Field of size 7).
sage: W = V.submodule([v])
sage: W.span([V.gen(2)], base_ring=GF(7))
Vector space of degree 3 and dimension 1 over Finite Field of size 7
Basis matrix:
[0 0 1]
Return the free K-module with the given basis, where K is the base field of self or user specified base_ring.
Note that this span is a subspace of the ambient vector space, but need not be a subspace of self.
INPUT:
EXAMPLES:
sage: V = VectorSpace(GF(7), 3)
sage: W = V.subspace([[2,3,4]]); W
Vector space of degree 3 and dimension 1 over Finite Field of size 7
Basis matrix:
[1 5 2]
sage: W.span_of_basis([[2,2,2], [3,3,0]])
Vector space of degree 3 and dimension 2 over Finite Field of size 7
User basis matrix:
[2 2 2]
[3 3 0]
The basis vectors must be linearly independent or an ArithmeticError exception is raised.
sage: W.span_of_basis([[2,2,2], [3,3,3]])
...
ValueError: The given basis vectors must be linearly independent.
Return the subspace of self spanned by the elements of gens.
INPUT:
EXAMPLES:
First we create a 1-dimensional vector subspace of an
ambient -dimensional space over the finite field of
order
.
sage: V = VectorSpace(GF(7), 3)
sage: W = V.subspace([[2,3,4]]); W
Vector space of degree 3 and dimension 1 over Finite Field of size 7
Basis matrix:
[1 5 2]
Next we create an invalid subspace, but it’s allowed since check=False. This is just equivalent to computing the span of the element.
sage: W.subspace([[1,1,0]], check=False)
Vector space of degree 3 and dimension 1 over Finite Field of size 7
Basis matrix:
[1 1 0]
With check=True (the default) the mistake is correctly detected and reported with an ArithmeticError exception.
sage: W.subspace([[1,1,0]], check=True)
...
ArithmeticError: Argument gens (= [[1, 1, 0]]) does not generate a submodule of self.
Same as self.submodule_with_basis(...).
EXAMPLES:
We create a subspace with a user-defined basis.
sage: V = VectorSpace(GF(7), 3)
sage: W = V.subspace_with_basis([[2,2,2], [1,2,3]]); W
Vector space of degree 3 and dimension 2 over Finite Field of size 7
User basis matrix:
[2 2 2]
[1 2 3]
We then create a subspace of the subspace with user-defined basis.
sage: W1 = W.subspace_with_basis([[3,4,5]]); W1
Vector space of degree 3 and dimension 1 over Finite Field of size 7
User basis matrix:
[3 4 5]
Notice how the basis for the same subspace is different if we merely use the subspace command.
sage: W2 = W.subspace([[3,4,5]]); W2
Vector space of degree 3 and dimension 1 over Finite Field of size 7
Basis matrix:
[1 6 4]
Nonetheless the two subspaces are equal (as mathematical objects):
sage: W1 == W2
True
Iterate over all subspaces of dimension dim.
INPUT:
EXAMPLE:
sage: V = VectorSpace(GF(3), 5)
sage: len(list(V.subspaces(0)))
1
sage: len(list(V.subspaces(1)))
121
sage: len(list(V.subspaces(2)))
1210
sage: len(list(V.subspaces(3)))
1210
sage: len(list(V.subspaces(4)))
121
sage: len(list(V.subspaces(5)))
1
sage: V = VectorSpace(GF(3), 5)
sage: V = V.subspace([V([1,1,0,0,0]),V([0,0,1,1,0])])
sage: list(V.subspaces(1))
[Vector space of degree 5 and dimension 1 over Finite Field of size 3
Basis matrix:
[1 1 0 0 0],
Vector space of degree 5 and dimension 1 over Finite Field of size 3
Basis matrix:
[1 1 1 1 0],
Vector space of degree 5 and dimension 1 over Finite Field of size 3
Basis matrix:
[1 1 2 2 0],
Vector space of degree 5 and dimension 1 over Finite Field of size 3
Basis matrix:
[0 0 1 1 0]]
Return the vector space associated to self. Since self is a vector space this function simply returns self, unless the base field is different.
EXAMPLES:
sage: V = span([[1,2,3]],QQ); V
Vector space of degree 3 and dimension 1 over Rational Field
Basis matrix:
[1 2 3]
sage: V.vector_space()
Vector space of degree 3 and dimension 1 over Rational Field
Basis matrix:
[1 2 3]
Return the zero submodule of self.
EXAMPLES:
sage: (QQ^4).zero_submodule()
Vector space of degree 4 and dimension 0 over Rational Field
Basis matrix:
[]
Return the zero subspace of self.
EXAMPLES:
sage: (QQ^4).zero_subspace()
Vector space of degree 4 and dimension 0 over Rational Field
Basis matrix:
[]
Base class for all free modules over a PID.
Return the sum of self and other, where both self and other must be submodules of the ambient vector space.
EXAMPLES:
We add two vector spaces:
sage: V = VectorSpace(QQ, 3)
sage: W = V.subspace([V([1,1,0])])
sage: W2 = V.subspace([V([1,-1,0])])
sage: W + W2
Vector space of degree 3 and dimension 2 over Rational Field
Basis matrix:
[1 0 0]
[0 1 0]
We add two free -modules.
sage: M = FreeModule(ZZ, 3)
sage: W = M.submodule([M([1,0,2])])
sage: W2 = M.submodule([M([2,0,-4])])
sage: W + W2
Free module of degree 3 and rank 2 over Integer Ring
Echelon basis matrix:
[1 0 2]
[0 0 8]
We can also add free -modules embedded
non-integrally into an ambient space.
sage: V = VectorSpace(QQ, 3)
sage: W = M.span([1/2*V.0 - 1/3*V.1])
Here the command M.span(...) creates the span of
the indicated vectors over the base ring of .
sage: W2 = M.span([1/3*V.0 + V.1])
sage: W + W2
Free module of degree 3 and rank 2 over Integer Ring
Echelon basis matrix:
[ 1/6 7/3 0]
[ 0 11/3 0]
We add two modules over :
sage: A = Matrix(ZZ, 3, 3, [3, 0, -1, 0, -2, 0, 0, 0, -2])
sage: V = (A+2).kernel()
sage: W = (A-3).kernel()
sage: V+W
Free module of degree 3 and rank 3 over Integer Ring
Echelon basis matrix:
[5 0 0]
[0 1 0]
[0 0 1]
We add a module to 0:
sage: ZZ^3 + 0
Ambient free module of rank 3 over the principal ideal domain Integer Ring
Return the quotient of self by the given submodule sub.
This just calls self.quotient(sub, check).
EXAMPLES:
sage: V1 = ZZ^2; W1 = V1.span([[1,2],[3,4]])
sage: V1/W1
Finitely generated module V/W over Integer Ring with invariants (2)
sage: V2 = span([[1/2,1,1],[3/2,2,1],[0,0,1]],ZZ); W2 = V2.span([2*V2.0+4*V2.1, 9*V2.0+12*V2.1, 4*V2.2])
sage: V2/W2
Finitely generated module V/W over Integer Ring with invariants (4, 12)
Create a free module over a PID.
EXAMPLES:
sage: FreeModule(ZZ, 2)
Ambient free module of rank 2 over the principal ideal domain Integer Ring
sage: FreeModule(PolynomialRing(GF(7),'x'), 2)
Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Finite Field of size 7
EXAMPLES:
sage: int(0) + QQ^3
Vector space of dimension 3 over Rational Field
sage: sum([QQ^3, QQ^3])
Vector space of degree 3 and dimension 3 over Rational Field
Basis matrix:
[1 0 0]
[0 1 0]
[0 0 1]
Return the base field, which is the fraction field of the base ring of this module.
EXAMPLES:
sage: FreeModule(GF(3), 2).base_field()
Finite Field of size 3
sage: FreeModule(ZZ, 2).base_field()
Rational Field
sage: FreeModule(PolynomialRing(GF(7),'x'), 2).base_field()
Fraction Field of Univariate Polynomial Ring in x over Finite Field of size 7
Return the matrix whose rows are the basis for this free module.
EXAMPLES:
sage: M = FreeModule(QQ,2).span_of_basis([[1,-1],[1,0]]); M
Vector space of degree 2 and dimension 2 over Rational Field
User basis matrix:
[ 1 -1]
[ 1 0]
sage: M.basis_matrix()
[ 1 -1]
[ 1 0]
The denominator of the basis matrix of self (i.e. the LCM of the coordinate entries with respect to the basis of the ambient space).
EXAMPLES:
sage: V = QQ^3
sage: L = V.span([[1,1/2,1/3], [-1/5,2/3,3]],ZZ)
sage: L
Free module of degree 3 and rank 2 over Integer Ring
Echelon basis matrix:
[ 1/5 19/6 37/3]
[ 0 23/6 46/3]
sage: L.denominator()
30
Return the lattice index [other:self] of self in other, as an element of the base field. When self is contained in other, the lattice index is the usual index. If the index is infinite, then this function returns infinity.
EXAMPLES:
sage: L1 = span([[1,2]], ZZ)
sage: L2 = span([[3,6]], ZZ)
sage: L2.index_in(L1)
3
Note that the free modules being compared need not be integral.
sage: L1 = span([['1/2','1/3'], [4,5]], ZZ)
sage: L2 = span([[1,2], [3,4]], ZZ)
sage: L2.index_in(L1)
12/7
sage: L1.index_in(L2)
7/12
sage: L1.discriminant() / L2.discriminant()
49/144
The index of a lattice of infinite index is infinite.
sage: L1 = FreeModule(ZZ, 2)
sage: L2 = span([[1,2]], ZZ)
sage: L2.index_in(L1)
+Infinity
Return the index of this module in its saturation, i.e., its
intersection with .
EXAMPLES:
sage: W = span([[2,4,6]], ZZ)
sage: W.index_in_saturation()
2
sage: W = span([[1/2,1/3]], ZZ)
sage: W.index_in_saturation()
1/6
Return the intersection of self and other.
EXAMPLES:
We intersect two submodules one of which is clearly contained in the other.
sage: A = ZZ^2
sage: M1 = A.span([[1,1]])
sage: M2 = A.span([[3,3]])
sage: M1.intersection(M2)
Free module of degree 2 and rank 1 over Integer Ring
Echelon basis matrix:
[3 3]
We intersection two submodules of of rank
, whose intersection has rank
.
sage: A = ZZ^3
sage: M1 = A.span([[1,1,1], [1,2,3]])
sage: M2 = A.span([[2,2,2], [1,0,0]])
sage: M1.intersection(M2)
Free module of degree 3 and rank 1 over Integer Ring
Echelon basis matrix:
[2 2 2]
We compute an intersection of two -modules that
are not submodules of
.
sage: A = ZZ^2
sage: M1 = A.span([[1,2]]).scale(1/6)
sage: M2 = A.span([[1,2]]).scale(1/15)
sage: M1.intersection(M2)
Free module of degree 2 and rank 1 over Integer Ring
Echelon basis matrix:
[1/3 2/3]
We intersect a -module with a
-vector space.
sage: A = ZZ^3
sage: L = ZZ^3
sage: V = QQ^3
sage: W = L.span([[1/2,0,1/2]])
sage: K = V.span([[1,0,1], [0,0,1]])
sage: W.intersection(K)
Free module of degree 3 and rank 1 over Integer Ring
Echelon basis matrix:
[1/2 0 1/2]
sage: K.intersection(W)
Free module of degree 3 and rank 1 over Integer Ring
Echelon basis matrix:
[1/2 0 1/2]
We intersect two modules over the ring of integers of a number field:
sage: L.<w> = NumberField(x^2 - x + 2)
sage: OL = L.ring_of_integers()
sage: V = L**3; W1 = V.span([[0,w/5,0], [1,0,-1/17]], OL); W2 = V.span([[0,(1-w)/5,0]], OL)
sage: W1.intersection(W2)
Free module of degree 3 and rank 1 over Maximal Order in Number Field in w with defining polynomial x^2 - x + 2
Echelon basis matrix:
[ 0 2/5 0]
True if this module is a submodule of other.
EXAMPLES:
sage: M = FreeModule(ZZ,2)
sage: M.is_submodule(M)
True
sage: N = M.scale(2)
sage: N.is_submodule(M)
True
sage: M.is_submodule(N)
False
sage: N = M.scale(1/2)
sage: N.is_submodule(M)
False
sage: M.is_submodule(N)
True
Return the quotient of self by the given submodule sub.
INPUT:
EXAMPLES:
sage: A = ZZ^3; V = A.span([[1,2,3], [4,5,6]])
sage: Q = V.quotient( [V.0 + V.1] ); Q
Finitely generated module V/W over Integer Ring with invariants (0)
Return the saturated submodule of that spans the same
vector space as self.
EXAMPLES:
We create a 1-dimensional lattice that is obviously not saturated and saturate it.
sage: L = span([[9,9,6]], ZZ); L
Free module of degree 3 and rank 1 over Integer Ring
Echelon basis matrix:
[9 9 6]
sage: L.saturation()
Free module of degree 3 and rank 1 over Integer Ring
Echelon basis matrix:
[3 3 2]
We create a lattice spanned by two vectors, and saturate.
Computation of discriminants shows that the index of lattice in its
saturation is , which is a prime of congruence between
the two generating vectors.
sage: L = span([[1,2,3], [4,5,6]], ZZ)
sage: L.saturation()
Free module of degree 3 and rank 2 over Integer Ring
Echelon basis matrix:
[ 1 0 -1]
[ 0 1 2]
sage: L.discriminant()
54
sage: L.saturation().discriminant()
6
Notice that the saturation of a non-integral lattice is
defined, but the result is integral hence does not contain
:
sage: L = span([['1/2',1,3]], ZZ)
sage: L.saturation()
Free module of degree 3 and rank 1 over Integer Ring
Echelon basis matrix:
[1 2 6]
Return the product of this module by the number other, which is the module spanned by other times each basis vector.
EXAMPLES:
sage: M = FreeModule(ZZ, 3)
sage: M.scale(2)
Free module of degree 3 and rank 3 over Integer Ring
Echelon basis matrix:
[2 0 0]
[0 2 0]
[0 0 2]
sage: a = QQ('1/3')
sage: M.scale(a)
Free module of degree 3 and rank 3 over Integer Ring
Echelon basis matrix:
[1/3 0 0]
[ 0 1/3 0]
[ 0 0 1/3]
Return the R-span of the given list of gens, where R = base_ring. The default R is the base ring of self. Note that this span need not be a submodule of self, nor even of the ambient space. It must, however, be contained in the ambient vector space, i.e., the ambient space tensored with the fraction field of R.
EXAMPLES:
sage: V = FreeModule(ZZ,3)
sage: W = V.submodule([V.gen(0)])
sage: W.span([V.gen(1)])
Free module of degree 3 and rank 1 over Integer Ring
Echelon basis matrix:
[0 1 0]
sage: W.submodule([V.gen(1)])
...
ArithmeticError: Argument gens (= [(0, 1, 0)]) does not generate a submodule of self.
Return the free R-module with the given basis, where R is the base ring of self or user specified base_ring.
Note that this R-module need not be a submodule of self, nor even of the ambient space. It must, however, be contained in the ambient vector space, i.e., the ambient space tensored with the fraction field of R.
EXAMPLES:
sage: M = FreeModule(ZZ,3)
sage: W = M.span_of_basis([M([1,2,3])])
Next we create two free -modules, neither of
which is a submodule of
.
sage: W.span_of_basis([M([2,4,0])])
Free module of degree 3 and rank 1 over Integer Ring
User basis matrix:
[2 4 0]
The following module isn’t in the ambient module
but is contained in the ambient vector space
:
sage: V = M.ambient_vector_space()
sage: W.span_of_basis([ V([1/5,2/5,0]), V([1/7,1/7,0]) ])
Free module of degree 3 and rank 2 over Integer Ring
User basis matrix:
[1/5 2/5 0]
[1/7 1/7 0]
Of course the input basis vectors must be linearly independent.
sage: W.span_of_basis([ [1,2,0], [2,4,0] ])
...
ValueError: The given basis vectors must be linearly independent.
Create the R-submodule of the ambient vector space with given generators, where R is the base ring of self.
INPUT:
OUTPUT:
EXAMPLES:
We create a submodule of :
sage: M = FreeModule(ZZ, 3)
sage: B = M.basis()
sage: W = M.submodule([B[0]+B[1], 2*B[1]-B[2]])
sage: W
Free module of degree 3 and rank 2 over Integer Ring
Echelon basis matrix:
[ 1 1 0]
[ 0 2 -1]
We create a submodule of a submodule.
sage: W.submodule([3*B[0] + 3*B[1]])
Free module of degree 3 and rank 1 over Integer Ring
Echelon basis matrix:
[3 3 0]
We try to create a submodule that isn’t really a submodule, which results in an ArithmeticError exception:
sage: W.submodule([B[0] - B[1]])
...
ArithmeticError: Argument gens (= [(1, -1, 0)]) does not generate a submodule of self.
Next we create a submodule of a free module over the principal ideal
domain , which uses the general Hermite normal form functionality:
sage: R = PolynomialRing(QQ, 'x'); x = R.gen()
sage: M = FreeModule(R, 3)
sage: B = M.basis()
sage: W = M.submodule([x*B[0], 2*B[1]- x*B[2]]); W
Free module of degree 3 and rank 2 over Univariate Polynomial Ring in x over Rational Field
Echelon basis matrix:
[ x 0 0]
[ 0 2 -x]
sage: W.ambient_module()
Ambient free module of rank 3 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field
Create the R-submodule of the ambient vector space with given basis, where R is the base ring of self.
INPUT:
OUTPUT:
EXAMPLES:
First we create a submodule of :
sage: M = FreeModule(ZZ, 3)
sage: B = M.basis()
sage: N = M.submodule_with_basis([B[0]+B[1], 2*B[1]-B[2]])
sage: N
Free module of degree 3 and rank 2 over Integer Ring
User basis matrix:
[ 1 1 0]
[ 0 2 -1]
A list of vectors in the ambient vector space may fail to generate a submodule.
sage: V = M.ambient_vector_space()
sage: X = M.submodule_with_basis([ V(B[0]+B[1])/2, V(B[1]-B[2])/2])
...
ArithmeticError: The given basis does not generate a submodule of self.
However, we can still determine the R-span of vectors in the ambient space, or over-ride the submodule check by setting check to False.
sage: X = V.span([ V(B[0]+B[1])/2, V(B[1]-B[2])/2 ], ZZ)
sage: X
Free module of degree 3 and rank 2 over Integer Ring
Echelon basis matrix:
[ 1/2 0 1/2]
[ 0 1/2 -1/2]
sage: Y = M.submodule([ V(B[0]+B[1])/2, V(B[1]-B[2])/2 ], check=False)
sage: X == Y
True
Next we try to create a submodule of a free module over the
principal ideal domain , using our general Hermite normal form implementation:
sage: R = PolynomialRing(QQ, 'x'); x = R.gen()
sage: M = FreeModule(R, 3)
sage: B = M.basis()
sage: W = M.submodule_with_basis([x*B[0], 2*B[0]- x*B[2]]); W
Free module of degree 3 and rank 2 over Univariate Polynomial Ring in x over Rational Field
User basis matrix:
[ x 0 0]
[ 2 0 -x]
Create the vector subspace of the ambient vector space with given generators.
INPUT:
OUTPUT: a vector subspace
EXAMPLES:
We create a -dimensional subspace of
.
sage: V = VectorSpace(QQ, 3)
sage: B = V.basis()
sage: W = V.vector_space_span([B[0]+B[1], 2*B[1]-B[2]])
sage: W
Vector space of degree 3 and dimension 2 over Rational Field
Basis matrix:
[ 1 0 1/2]
[ 0 1 -1/2]
We create a subspace of a vector space over
.
sage: R.<x> = QQ[]
sage: K = NumberField(x^2 + 1, 'a'); a = K.gen()
sage: V = VectorSpace(K, 3)
sage: V.vector_space_span([2*V.gen(0) + 3*V.gen(2)])
Vector space of degree 3 and dimension 1 over Number Field in a with defining polynomial x^2 + 1
Basis matrix:
[ 1 0 3/2]
We use the vector_space_span command to create a
vector subspace of the ambient vector space of a submodule of
.
sage: M = FreeModule(ZZ,3)
sage: W = M.submodule([M([1,2,3])])
sage: W.vector_space_span([M([2,3,4])])
Vector space of degree 3 and dimension 1 over Rational Field
Basis matrix:
[ 1 3/2 2]
Create the vector subspace of the ambient vector space with given basis.
INPUT:
OUTPUT: a vector subspace with user-specified basis
EXAMPLES:
sage: V = VectorSpace(QQ, 3)
sage: B = V.basis()
sage: W = V.vector_space_span_of_basis([B[0]+B[1], 2*B[1]-B[2]])
sage: W
Vector space of degree 3 and dimension 2 over Rational Field
User basis matrix:
[ 1 1 0]
[ 0 2 -1]
Return the zero submodule of this module.
EXAMPLES:
sage: V = FreeModule(ZZ,2)
sage: V.zero_submodule()
Free module of degree 2 and rank 0 over Integer Ring
Echelon basis matrix:
[]
An embedded vector subspace with echelonized basis.
EXAMPLES:
Since this is an embedded vector subspace with echelonized basis, the echelon_coordinates() and user coordinates() agree:
sage: V = QQ^3
sage: W = V.span([[1,2,3],[4,5,6]])
sage: W
Vector space of degree 3 and dimension 2 over Rational Field
Basis matrix:
[ 1 0 -1]
[ 0 1 2]
sage: v = V([1,5,9])
sage: W.echelon_coordinates(v)
[1, 5]
sage: vector(QQ, W.echelon_coordinates(v)) * W.basis_matrix()
(1, 5, 9)
sage: v = V([1,5,9])
sage: W.coordinates(v)
[1, 5]
sage: vector(QQ, W.coordinates(v)) * W.basis_matrix()
(1, 5, 9)
Create an embedded vector subspace with echelonized basis.
EXAMPLES:
sage: V = QQ^3
sage: W = V.span([[1,2,3],[4,5,6]])
sage: W
Vector space of degree 3 and dimension 2 over Rational Field
Basis matrix:
[ 1 0 -1]
[ 0 1 2]
The default printing representation of self.
EXAMPLES:
sage: V = VectorSpace(QQ,5)
sage: U = V.submodule([ V.gen(i) - V.gen(0) for i in range(1,5) ])
sage: print U # indirect doctest
Vector space of degree 5 and dimension 4 over Rational Field
Basis matrix:
[ 1 0 0 0 -1]
[ 0 1 0 0 -1]
[ 0 0 1 0 -1]
[ 0 0 0 1 -1]
sage: print U._repr_()
Vector space of degree 5 and dimension 4 over Rational Field
Basis matrix:
[ 1 0 0 0 -1]
[ 0 1 0 0 -1]
[ 0 0 1 0 -1]
[ 0 0 0 1 -1]
The system representation can be overwritten, but leaves _repr_ unmodified.
sage: U.rename('U')
sage: print U
U
sage: print U._repr_()
Vector space of degree 5 and dimension 4 over Rational Field
Basis matrix:
[ 1 0 0 0 -1]
[ 0 1 0 0 -1]
[ 0 0 1 0 -1]
[ 0 0 0 1 -1]
Sparse vector spaces print this fact.
sage: V = VectorSpace(QQ,5,sparse=True)
sage: U = V.submodule([ V.gen(i) - V.gen(0) for i in range(1,5) ])
sage: print U # indirect doctest
Sparse vector space of degree 5 and dimension 4 over Rational Field
Basis matrix:
[ 1 0 0 0 -1]
[ 0 1 0 0 -1]
[ 0 0 1 0 -1]
[ 0 0 0 1 -1]
Write in terms of the user basis for self.
INPUT:
OUTPUT: list
Returns a list such that if
is the basis for self, then
If is not in self, raises an ArithmeticError exception.
EXAMPLES:
sage: V = QQ^3
sage: W = V.span([[1,2,3],[4,5,6]]); W
Vector space of degree 3 and dimension 2 over Rational Field
Basis matrix:
[ 1 0 -1]
[ 0 1 2]
sage: v = V([1,5,9])
sage: W.coordinate_vector(v)
(1, 5)
sage: W.coordinates(v)
[1, 5]
sage: vector(QQ, W.coordinates(v)) * W.basis_matrix()
(1, 5, 9)
sage: V = VectorSpace(QQ,5, sparse=True)
sage: W = V.subspace([[0,1,2,0,0], [0,-1,0,0,-1/2]])
sage: W.coordinate_vector([0,0,2,0,-1/2])
(0, 2)
Write in terms of the echelonized basis of self.
INPUT:
OUTPUT: list
Returns a list such that if
is the basis for self, then
If is not in self, raises an ArithmeticError exception.
EXAMPLES:
sage: V = QQ^3
sage: W = V.span([[1,2,3],[4,5,6]])
sage: W
Vector space of degree 3 and dimension 2 over Rational Field
Basis matrix:
[ 1 0 -1]
[ 0 1 2]
sage: v = V([1,5,9])
sage: W.echelon_coordinates(v)
[1, 5]
sage: vector(QQ, W.echelon_coordinates(v)) * W.basis_matrix()
(1, 5, 9)
Return True if the basis of this free module is specified by the user, as opposed to being the default echelon form.
EXAMPLES:
sage: V = QQ^3
sage: W = V.subspace([[2,'1/2', 1]])
sage: W.has_user_basis()
False
sage: W = V.subspace_with_basis([[2,'1/2',1]])
sage: W.has_user_basis()
True
An -submodule of
where
is the
fraction field of a principal ideal domain
.
EXAMPLES:
sage: M = ZZ^3
sage: W = M.span_of_basis([[1,2,3],[4,5,19]]); W
Free module of degree 3 and rank 2 over Integer Ring
User basis matrix:
[ 1 2 3]
[ 4 5 19]
We can save and load submodules and elements.
sage: loads(W.dumps()) == W
True
sage: v = W.0 + W.1
sage: loads(v.dumps()) == v
True
Create an embedded free module over a PID.
EXAMPLES:
sage: V = ZZ^3
sage: W = V.span([[1,2,3],[4,5,6]])
sage: W
Free module of degree 3 and rank 2 over Integer Ring
Echelon basis matrix:
[1 2 3]
[0 3 6]
The printing representation of self.
EXAMPLES:
sage: M = ZZ^8
sage: L = M.submodule([ M.gen(i) - M.gen(0) for i in range(1,8) ])
sage: print L # indirect doctest
Free module of degree 8 and rank 7 over Integer Ring
Echelon basis matrix:
[ 1 0 0 0 0 0 0 -1]
[ 0 1 0 0 0 0 0 -1]
[ 0 0 1 0 0 0 0 -1]
[ 0 0 0 1 0 0 0 -1]
[ 0 0 0 0 1 0 0 -1]
[ 0 0 0 0 0 1 0 -1]
[ 0 0 0 0 0 0 1 -1]
Write in terms of the user basis for self.
INPUT:
OUTPUT: list
Returns a list such that if
is the basis for self, then
If is not in self, raises an ArithmeticError exception.
EXAMPLES:
sage: V = ZZ^3
sage: W = V.span_of_basis([[1,2,3],[4,5,6]])
sage: W.coordinate_vector([1,5,9])
(5, -1)
Return True if the basis of this free module is specified by the user, as opposed to being the default echelon form.
EXAMPLES:
sage: A = ZZ^3; A
Ambient free module of rank 3 over the principal ideal domain Integer Ring
sage: A.has_user_basis()
False
sage: W = A.span_of_basis([[2,'1/2',1]])
sage: W.has_user_basis()
True
sage: W = A.span([[2,'1/2',1]])
sage: W.has_user_basis()
False
An embedded vector subspace with a distinguished user basis.
EXAMPLES:
sage: M = QQ^3; W = M.submodule_with_basis([[1,2,3], [4,5,19]]); W
Vector space of degree 3 and dimension 2 over Rational Field
User basis matrix:
[ 1 2 3]
[ 4 5 19]
Since this is an embedded vector subspace with a distinguished user basis possibly different than the echelonized basis, the echelon_coordinates() and user coordinates() do not agree:
sage: V = QQ^3
sage: W = V.submodule_with_basis([[1,2,3], [4,5,6]])
sage: W
Vector space of degree 3 and dimension 2 over Rational Field
User basis matrix:
[1 2 3]
[4 5 6]
sage: v = V([1,5,9])
sage: W.echelon_coordinates(v)
[1, 5]
sage: vector(QQ, W.echelon_coordinates(v)) * W.echelonized_basis_matrix()
(1, 5, 9)
sage: v = V([1,5,9])
sage: W.coordinates(v)
[5, -1]
sage: vector(QQ, W.coordinates(v)) * W.basis_matrix()
(1, 5, 9)
We can load and save submodules:
sage: loads(W.dumps()) == W
True
sage: K.<x> = FractionField(PolynomialRing(QQ,'x'))
sage: M = K^3; W = M.span_of_basis([[1,1,x]])
sage: loads(W.dumps()) == W
True
Create a vector space with given basis.
EXAMPLES:
sage: V = QQ^3
sage: W = V.span_of_basis([[1,2,3],[4,5,6]])
sage: W
Vector space of degree 3 and dimension 2 over Rational Field
User basis matrix:
[1 2 3]
[4 5 6]
Given a list (of field elements) returns 1 as the common denominator.
N.B.: This function is for internal use only!
EXAMPLES:
sage: U = QQ^3
sage: U
Vector space of dimension 3 over Rational Field
sage: U.denominator()
1
sage: V = U.span([[1,1/2,1/3], [-1/5,2/3,3]])
sage: V
Vector space of degree 3 and dimension 2 over Rational Field
Basis matrix:
[ 1 0 -5/3]
[ 0 1 4]
sage: W = U.submodule_with_basis([[1,1/2,1/3], [-1/5,2/3,3]])
sage: W
Vector space of degree 3 and dimension 2 over Rational Field
User basis matrix:
[ 1 1/2 1/3]
[-1/5 2/3 3]
sage: W._denominator(W.echelonized_basis_matrix().list())
1
Given the ambient space and a basis, constructs and caches the __echelonized_basis_matrix and returns its rows.
N.B. This function is for internal use only!
EXAMPLES:
sage: M = ZZ^3
sage: N = M.submodule_with_basis([[1,1,0],[0,2,1]])
sage: N._echelonized_basis(M,N.basis())
[(1, 1, 0), (0, 2, 1)]
sage: V = QQ^3
sage: W = V.submodule_with_basis([[1,1,0],[0,2,1]])
sage: W._echelonized_basis(V,W.basis())
[(1, 0, -1/2), (0, 1, 1/2)]
The printing representation of self.
EXAMPLES:
sage: V = VectorSpace(QQ,5)
sage: U = V.submodule([ V.gen(i) - V.gen(0) for i in range(1,5) ])
sage: print U # indirect doctest
Vector space of degree 5 and dimension 4 over Rational Field
Basis matrix:
[ 1 0 0 0 -1]
[ 0 1 0 0 -1]
[ 0 0 1 0 -1]
[ 0 0 0 1 -1]
sage: print U._repr_()
Vector space of degree 5 and dimension 4 over Rational Field
Basis matrix:
[ 1 0 0 0 -1]
[ 0 1 0 0 -1]
[ 0 0 1 0 -1]
[ 0 0 0 1 -1]
The system representation can be overwritten, but leaves _repr_ unmodified.
sage: U.rename('U')
sage: print U
U
sage: print U._repr_()
Vector space of degree 5 and dimension 4 over Rational Field
Basis matrix:
[ 1 0 0 0 -1]
[ 0 1 0 0 -1]
[ 0 0 1 0 -1]
[ 0 0 0 1 -1]
Sparse vector spaces print this fact.
sage: V = VectorSpace(QQ,5,sparse=True)
sage: U = V.submodule([ V.gen(i) - V.gen(0) for i in range(1,5) ])
sage: print U # indirect doctest
Sparse vector space of degree 5 and dimension 4 over Rational Field
Basis matrix:
[ 1 0 0 0 -1]
[ 0 1 0 0 -1]
[ 0 0 1 0 -1]
[ 0 0 0 1 -1]
Return False since this is not an ambient module.
EXAMPLES:
sage: V = QQ^3
sage: V.is_ambient()
True
sage: W = V.span_of_basis([[1,2,3],[4,5,6]])
sage: W.is_ambient()
False
An -submodule of
with distinguished basis,
where
is the fraction field of a principal ideal domain
.
Compare the free module self with other.
Modules are ordered by their ambient spaces, then by dimension, then in order by their echelon matrices.
Note
Use is_submodule() to determine if one module is a submodule of another.
EXAMPLES:
First we compare two equal vector spaces.
sage: V = span([[1,2,3], [5,6,7], [8,9,10]], QQ)
sage: W = span([[5,6,7], [8,9,10]], QQ)
sage: V == W
True
Next we compare a one dimensional space to the two dimensional space defined above.
sage: M = span([[5,6,7]], QQ)
sage: V == M
False
sage: M < V
True
sage: V < M
False
We compare a -module to the one-dimensional
space above.
sage: V = span([[5,6,7]], ZZ).scale(1/11); V
Free module of degree 3 and rank 1 over Integer Ring
Echelon basis matrix:
[5/11 6/11 7/11]
sage: V < M
True
sage: M < V
False
We test that trac 5525 is fixed:
sage: A = (QQ^1).span([[1/3]],ZZ); B = (QQ^1).span([[1]],ZZ);
sage: A.intersection(B)
Free module of degree 1 and rank 1 over Integer Ring
Echelon basis matrix:
[1]
The hash of self.
EXAMPLES:
sage: V = QQ^7
sage: V.__hash__()
153079684 # 32-bit
-3713095619189944444 # 64-bit
sage: U = QQ^7
sage: U.__hash__()
153079684 # 32-bit
-3713095619189944444 # 64-bit
sage: U is V
True
Create a free module with basis over a PID.
EXAMPLES:
sage: M = ZZ^3
sage: W = M.span_of_basis([[1,2,3],[4,5,6]]); W
Free module of degree 3 and rank 2 over Integer Ring
User basis matrix:
[1 2 3]
[4 5 6]
sage: W = M.span_of_basis([[1,2,3/2],[4,5,6]]); W
Free module of degree 3 and rank 2 over Integer Ring
User basis matrix:
[ 1 2 3/2]
[ 4 5 6]
The LCM of the denominators of the given list B.
N.B.: This function is for internal use only!
EXAMPLES:
sage: V = QQ^3
sage: L = V.span([[1,1/2,1/3], [-1/5,2/3,3]],ZZ)
sage: L
Free module of degree 3 and rank 2 over Integer Ring
Echelon basis matrix:
[ 1/5 19/6 37/3]
[ 0 23/6 46/3]
sage: L._denominator(L.echelonized_basis_matrix().list())
30
Returns a transformation matrix from the some matrix to the row reduced echelon form for this module over a PID.
Note: For internal use only! and not used!
EXAMPLES:
sage: M = ZZ^3
sage: N = M.submodule_with_basis([[1,1,0],[1,1,2]])
sage: N
Free module of degree 3 and rank 2 over Integer Ring
User basis matrix:
[1 1 0]
[1 1 2]
sage: T = N._echelon_to_rref_matrix(); T
[1 0]
[0 2]
sage: type(T)
<type 'sage.matrix.matrix_integer_dense.Matrix_integer_dense'>
sage: U = N._rref_to_echelon_matrix(); U
[ 1 0]
[ 0 1/2]
sage: type(U)
<type 'sage.matrix.matrix_rational_dense.Matrix_rational_dense'>
Given the ambient space and a basis, constructs and caches the __echelonized_basis_matrix and returns its rows.
N.B. This function is for internal use only!
EXAMPLES:
sage: M = ZZ^3
sage: N = M.submodule_with_basis([[1,1,0],[0,2,1]])
sage: N._echelonized_basis(M,N.basis())
[(1, 1, 0), (0, 2, 1)]
sage: V = QQ^3
sage: W = V.submodule_with_basis([[1,1,0],[0,2,1]])
sage: W._echelonized_basis(V,W.basis())
[(1, 0, -1/2), (0, 1, 1/2)]
sage: V = SR^3
sage: W = V.submodule_with_basis([[1,0,1]])
sage: W._echelonized_basis(V,W.basis())
[(1, 0, 1)]
Return latex representation of this free module.
EXAMPLES:
sage: A = ZZ^3
sage: M = A.span_of_basis([[1,2,3],[4,5,6]])
sage: M._latex_()
'\\mathrm{RowSpan}_{\\Bold{Z}}\\left(\\begin{array}{rrr}\n1 & 2 & 3 \\\\\n4 & 5 & 6\n\\end{array}\\right)'
The printing representation of self.
EXAMPLES:
sage: L = ZZ^8
sage: E = L.submodule_with_basis([ L.gen(i) - L.gen(0) for i in range(1,8) ])
sage: E # indirect doctest
Free module of degree 8 and rank 7 over Integer Ring
User basis matrix:
[-1 1 0 0 0 0 0 0]
[-1 0 1 0 0 0 0 0]
[-1 0 0 1 0 0 0 0]
[-1 0 0 0 1 0 0 0]
[-1 0 0 0 0 1 0 0]
[-1 0 0 0 0 0 1 0]
[-1 0 0 0 0 0 0 1]
sage: M = FreeModule(ZZ,8,sparse=True)
sage: N = M.submodule_with_basis([ M.gen(i) - M.gen(0) for i in range(1,8) ])
sage: N # indirect doctest
Sparse free module of degree 8 and rank 7 over Integer Ring
User basis matrix:
[-1 1 0 0 0 0 0 0]
[-1 0 1 0 0 0 0 0]
[-1 0 0 1 0 0 0 0]
[-1 0 0 0 1 0 0 0]
[-1 0 0 0 0 1 0 0]
[-1 0 0 0 0 0 1 0]
[-1 0 0 0 0 0 0 1]
Returns a transformation matrix from row reduced echelon form to some matrix for this module over a PID.
Note: For internal use only!
EXAMPLES:
sage: M = ZZ^3
sage: N = M.submodule_with_basis([[1,1,0],[1,1,2]])
sage: N
Free module of degree 3 and rank 2 over Integer Ring
User basis matrix:
[1 1 0]
[1 1 2]
sage: T = N._echelon_to_rref_matrix(); T
[1 0]
[0 2]
sage: type(T)
<type 'sage.matrix.matrix_integer_dense.Matrix_integer_dense'>
sage: U = N._rref_to_echelon_matrix(); U
[ 1 0]
[ 0 1/2]
sage: type(U)
<type 'sage.matrix.matrix_rational_dense.Matrix_rational_dense'>
Returns a transformation matrix from row reduced echelon form to the user specified basis, for this module over a PID.
Note: For internal use only! See user_to_echelon_matrix.
EXAMPLES:
sage: M = ZZ^3
sage: N = M.submodule_with_basis([[1,1,0],[0,1,1]])
sage: U = N.echelon_to_user_matrix(); U # indirect doctest
[ 1 -1]
[ 0 1]
sage: N.echelonized_basis_matrix()
[ 1 0 -1]
[ 0 1 1]
sage: N.basis_matrix()
[1 1 0]
[0 1 1]
sage: U * N.basis_matrix() == N.echelonized_basis_matrix()
True
Returns a transformation matrix from the user specified basis to row reduced echelon form, for this module over a PID.
Note: For internal use only! See user_to_echelon_matrix.
EXAMPLES:
sage: M = ZZ^3
sage: N = M.submodule_with_basis([[1,1,0],[0,1,1]])
sage: T = N.user_to_echelon_matrix(); T # indirect doctest
[1 1]
[0 1]
sage: N.basis_matrix()
[1 1 0]
[0 1 1]
sage: N.echelonized_basis_matrix()
[ 1 0 -1]
[ 0 1 1]
sage: T * N.echelonized_basis_matrix() == N.basis_matrix()
True
Return the ambient module related to the -module self,
which was used when creating this module, and is of the form
. Note that self need not be contained in the ambient
module, though self will be contained in the ambient vector space.
EXAMPLES:
sage: A = ZZ^3
sage: M = A.span_of_basis([[1,2,'3/7'],[4,5,6]])
sage: M
Free module of degree 3 and rank 2 over Integer Ring
User basis matrix:
[ 1 2 3/7]
[ 4 5 6]
sage: M.ambient_module()
Ambient free module of rank 3 over the principal ideal domain Integer Ring
sage: M.is_submodule(M.ambient_module())
False
Return the ambient vector space in which this free module is embedded.
EXAMPLES:
sage: M = ZZ^3; M.ambient_vector_space()
Vector space of dimension 3 over Rational Field
sage: N = M.span_of_basis([[1,2,'1/5']])
sage: N
Free module of degree 3 and rank 1 over Integer Ring
User basis matrix:
[ 1 2 1/5]
sage: M.ambient_vector_space()
Vector space of dimension 3 over Rational Field
sage: M.ambient_vector_space() is N.ambient_vector_space()
True
If an inner product on the module is specified, then this is preserved on the ambient vector space.
sage: M = FreeModule(ZZ,4,inner_product_matrix=1)
sage: V = M.ambient_vector_space()
sage: V
Ambient quadratic space of dimension 4 over Rational Field
Inner product matrix:
[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 0 1]
sage: N = M.submodule([[1,-1,0,0],[0,1,-1,0],[0,0,1,-1]])
sage: N.gram_matrix()
[2 1 1]
[1 2 1]
[1 1 2]
sage: V == N.ambient_vector_space()
True
Return the user basis for this free module.
EXAMPLES:
sage: V = ZZ^3
sage: V.basis()
[
(1, 0, 0),
(0, 1, 0),
(0, 0, 1)
]
sage: M = V.span_of_basis([['1/8',2,1]])
sage: M.basis()
[
(1/8, 2, 1)
]
Return the free module over R obtained by coercing each element of self into a vector over the fraction field of R, then taking the resulting R-module. Raises a TypeError if coercion is not possible.
INPUT:
EXAMPLES:
sage: V = QQ^3
sage: W = V.subspace([[2,'1/2', 1]])
sage: W.change_ring(GF(7))
Vector space of degree 3 and dimension 1 over Finite Field of size 7
Basis matrix:
[1 2 4]
Returns the functorial construction of self, namely, the subspace of the ambient module spanned by the given basis.
EXAMPLE:
sage: M = ZZ^3
sage: W = M.span_of_basis([[1,2,3],[4,5,6]]); W
Free module of degree 3 and rank 2 over Integer Ring
User basis matrix:
[1 2 3]
[4 5 6]
sage: c, V = W.construction()
sage: c(V) == W
True
Write in terms of the user basis for self.
INPUT:
OUTPUT: list
Returns a vector such that if
is the basis for self, then
If is not in self, raises an ArithmeticError exception.
EXAMPLES:
sage: V = ZZ^3
sage: M = V.span_of_basis([['1/8',2,1]])
sage: M.coordinate_vector([1,16,8])
(8)
Write in terms of the user basis for self.
INPUT:
Returns a list such that if
is the echelonized basis
for self, then
If is not in self, raises an ArithmeticError exception.
EXAMPLES:
sage: V = ZZ^3
sage: M = V.span_of_basis([['1/2',3,1], [0,'1/6',0]])
sage: B = M.echelonized_basis(); B
[
(1/2, 0, 1),
(0, 1/6, 0)
]
sage: M.echelon_coordinate_vector(['1/2', 3, 1])
(1, 18)
Write in terms of the echelonized basis for self.
INPUT:
OUTPUT: list
Returns a list such that if
is the basis
for self, then
If is not in self, raises an
ArithmeticError exception.
EXAMPLES:
sage: A = ZZ^3
sage: M = A.span_of_basis([[1,2,'3/7'],[4,5,6]])
sage: M.coordinates([8,10,12])
[0, 2]
sage: M.echelon_coordinates([8,10,12])
[8, -2]
sage: B = M.echelonized_basis(); B
[
(1, 2, 3/7),
(0, 3, -30/7)
]
sage: 8*B[0] - 2*B[1]
(8, 10, 12)
We do an example with a sparse vector space:
sage: V = VectorSpace(QQ,5, sparse=True)
sage: W = V.subspace_with_basis([[0,1,2,0,0], [0,-1,0,0,-1/2]])
sage: W.echelonized_basis()
[
(0, 1, 0, 0, 1/2),
(0, 0, 1, 0, -1/4)
]
sage: W.echelon_coordinates([0,0,2,0,-1/2])
[0, 2]
Return matrix that transforms the echelon basis to the user basis
of self. This is a matrix such that if
is a
vector written with respect to the echelon basis for self then
is that vector written with respect to the user basis
of self.
EXAMPLES:
sage: V = QQ^3
sage: W = V.span_of_basis([[1,2,3],[4,5,6]])
sage: W.echelonized_basis()
[
(1, 0, -1),
(0, 1, 2)
]
sage: A = W.echelon_to_user_matrix(); A
[-5/3 2/3]
[ 4/3 -1/3]
The vector has coordinates
with
respect to the echelonized basis for self. Multiplying
we find the coordinates of this vector with respect to the user
basis.
sage: v = vector(QQ, [1,1]); v
(1, 1)
sage: v * A
(-1/3, 1/3)
sage: u0, u1 = W.basis()
sage: (-u0 + u1)/3
(1, 1, 1)
Return the basis for self in echelon form.
EXAMPLES:
sage: V = ZZ^3
sage: M = V.span_of_basis([['1/2',3,1], [0,'1/6',0]])
sage: M.basis()
[
(1/2, 3, 1),
(0, 1/6, 0)
]
sage: B = M.echelonized_basis(); B
[
(1/2, 0, 1),
(0, 1/6, 0)
]
sage: V.span(B) == M
True
Return basis matrix for self in row echelon form.
EXAMPLES:
sage: V = FreeModule(ZZ, 3).span_of_basis([[1,2,3],[4,5,6]])
sage: V.basis_matrix()
[1 2 3]
[4 5 6]
sage: V.echelonized_basis_matrix()
[1 2 3]
[0 3 6]
Return True if the basis of this free module is specified by the user, as opposed to being the default echelon form.
EXAMPLES:
sage: V = ZZ^3; V.has_user_basis()
False
sage: M = V.span_of_basis([[1,3,1]]); M.has_user_basis()
True
sage: M = V.span([[1,3,1]]); M.has_user_basis()
False
Return the linear combination of the basis for self obtained from the coordinates of v.
EXAMPLES:
sage: V = span([[1,2,3], [4,5,6]], ZZ); V
Free module of degree 3 and rank 2 over Integer Ring
Echelon basis matrix:
[1 2 3]
[0 3 6]
sage: V.linear_combination_of_basis([1,1])
(1, 5, 9)
Return matrix that transforms a vector written with respect to the user basis of self to one written with respect to the echelon basis. The matrix acts from the right, as is usual in Sage.
EXAMPLES:
sage: A = ZZ^3
sage: M = A.span_of_basis([[1,2,3],[4,5,6]])
sage: M.echelonized_basis()
[
(1, 2, 3),
(0, 3, 6)
]
sage: M.user_to_echelon_matrix()
[ 1 0]
[ 4 -1]
The vector in
is
with respect to the user basis. Multiplying the above matrix on the
right by this vector yields
, which has components
the coordinates of
with respect to the echelon basis.
sage: v0,v1 = M.basis(); v = v0+v1
sage: e0,e1 = M.echelonized_basis()
sage: v
(5, 7, 9)
sage: 5*e0 + (-1)*e1
(5, 7, 9)
Return the vector space associated to this free module via tensor product with the fraction field of the base ring.
EXAMPLES:
sage: A = ZZ^3; A
Ambient free module of rank 3 over the principal ideal domain Integer Ring
sage: A.vector_space()
Vector space of dimension 3 over Rational Field
sage: M = A.span_of_basis([['1/3',2,'3/7'],[4,5,6]]); M
Free module of degree 3 and rank 2 over Integer Ring
User basis matrix:
[1/3 2 3/7]
[ 4 5 6]
sage: M.vector_space()
Vector space of degree 3 and dimension 2 over Rational Field
User basis matrix:
[1/3 2 3/7]
[ 4 5 6]
EXAMPLES:
The base can be complicated, as long as it is a field.
sage: V = VectorSpace(FractionField(PolynomialRing(ZZ,'x')),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(ZZ,5)
...
TypeError: Argument K (= Integer Ring) must be a field.
This converts a list vecs of vectors in V to an Sequence of immutable vectors.
Should it? I.e. in most other parts of the system the return type of basis or generators is a tuple.
EXAMPLES:
sage: V = VectorSpace(QQ,2)
sage: B = V.gens()
sage: B
((1, 0), (0, 1))
sage: v = B[0]
sage: v[0] = 0 # immutable
...
ValueError: vector is immutable; please change a copy instead (use copy())
sage: sage.modules.free_module.basis_seq(V, V.gens())
[
(1, 0),
(0, 1)
]
The class of the vectors (elements of a free module) with base ring R and boolean is_sparse.
EXAMPLES:
sage: FF = FiniteField(2)
sage: P = PolynomialRing(FF,'x')
sage: sage.modules.free_module.element_class(QQ, is_sparse=True)
<type 'sage.modules.free_module_element.FreeModuleElement_generic_sparse'>
sage: sage.modules.free_module.element_class(QQ, is_sparse=False)
<type 'sage.modules.vector_rational_dense.Vector_rational_dense'>
sage: sage.modules.free_module.element_class(ZZ, is_sparse=True)
<type 'sage.modules.free_module_element.FreeModuleElement_generic_sparse'>
sage: sage.modules.free_module.element_class(ZZ, is_sparse=False)
<type 'sage.modules.vector_integer_dense.Vector_integer_dense'>
sage: sage.modules.free_module.element_class(FF, is_sparse=True)
<type 'sage.modules.free_module_element.FreeModuleElement_generic_sparse'>
sage: sage.modules.free_module.element_class(FF, is_sparse=False)
<type 'sage.modules.vector_modn_dense.Vector_modn_dense'>
sage: sage.modules.free_module.element_class(P, is_sparse=True)
<type 'sage.modules.free_module_element.FreeModuleElement_generic_sparse'>
sage: sage.modules.free_module.element_class(P, is_sparse=False)
<type 'sage.modules.free_module_element.FreeModuleElement_generic_dense'>
Return True if M inherits from from FreeModule_generic.
EXAMPLES:
sage: from sage.modules.free_module import is_FreeModule
sage: V = ZZ^3
sage: is_FreeModule(V)
True
sage: W = V.span([ V.random_element() for i in range(2) ])
sage: is_FreeModule(W)
True
Return the -span of gens (a list of vectors) where R =
base_ring.
EXAMPLES:
sage: V = span([[1,2,5], [2,2,2]], QQ); V
Vector space of degree 3 and dimension 2 over Rational Field
Basis matrix:
[ 1 0 -3]
[ 0 1 4]
sage: span([V.gen(0)], QuadraticField(-7,'a'))
Vector space of degree 3 and dimension 1 over Number Field in a with defining polynomial x^2 + 7
Basis matrix:
[ 1 0 -3]
sage: span([[1,2,3], [2,2,2], [1,2,5]], GF(2))
Vector space of degree 3 and dimension 1 over Finite Field of size 2
Basis matrix:
[1 0 1]
TESTS:
sage: span([[1,2,3], [2,2,2], [1,2/3,5]], ZZ)
Free module of degree 3 and rank 3 over Integer Ring
Echelon basis matrix:
[ 1 0 13]
[ 0 2/3 6]
[ 0 0 14]
sage: span([[1,2,3], [2,2,2], [1,2,QQ['x'].gen()]], ZZ)
...
ValueError: The elements of gens (= [[1, 2, 3], [2, 2, 2], [1, 2, x]]) must be defined over base_ring (= Integer Ring) or its field of fractions.
For backwards compatibility one can also give the base ring as the first argument:
sage: span(QQ,[[1,2],[3,4]])
Vector space of degree 2 and dimension 2 over Rational Field
Basis matrix:
[1 0]
[0 1]
Fix trac 5575:
sage: V = QQ^3
sage: span([V.0, V.1])
Vector space of degree 3 and dimension 2 over Rational Field
Basis matrix:
[1 0 0]
[0 1 0]