Morphisms defined by a matrix¶
A matrix morphism is a morphism that is defined by multiplication
by a matrix. Elements of domain must either have a method
vector()
that returns a vector that the defining
matrix can hit from the left, or be coercible into vector space of
appropriate dimension.
EXAMPLES:
sage: from sage.modules.matrix_morphism import MatrixMorphism, is_MatrixMorphism
sage: V = QQ^3
sage: T = End(V)
sage: M = MatrixSpace(QQ,3)
sage: I = M.identity_matrix()
sage: m = MatrixMorphism(T, I); m
Morphism defined by the matrix
[1 0 0]
[0 1 0]
[0 0 1]
sage: m.charpoly('x') # needs sage.libs.pari
x^3 - 3*x^2 + 3*x - 1
sage: m.base_ring()
Rational Field
sage: m.det()
1
sage: m.fcp('x') # needs sage.libs.pari
(x - 1)^3
sage: m.matrix()
[1 0 0]
[0 1 0]
[0 0 1]
sage: m.rank()
3
sage: m.trace()
3
>>> from sage.all import *
>>> from sage.modules.matrix_morphism import MatrixMorphism, is_MatrixMorphism
>>> V = QQ**Integer(3)
>>> T = End(V)
>>> M = MatrixSpace(QQ,Integer(3))
>>> I = M.identity_matrix()
>>> m = MatrixMorphism(T, I); m
Morphism defined by the matrix
[1 0 0]
[0 1 0]
[0 0 1]
>>> m.charpoly('x') # needs sage.libs.pari
x^3 - 3*x^2 + 3*x - 1
>>> m.base_ring()
Rational Field
>>> m.det()
1
>>> m.fcp('x') # needs sage.libs.pari
(x - 1)^3
>>> m.matrix()
[1 0 0]
[0 1 0]
[0 0 1]
>>> m.rank()
3
>>> m.trace()
3
AUTHOR:
William Stein: initial versions
David Joyner (2005-12-17): added examples
William Stein (2005-01-07): added __reduce__
Craig Citro (2008-03-18): refactored MatrixMorphism class
Rob Beezer (2011-07-15): additional methods, bug fixes, documentation
- class sage.modules.matrix_morphism.MatrixMorphism(parent, A, copy_matrix=True, side='left')[source]¶
Bases:
MatrixMorphism_abstract
A morphism defined by a matrix.
INPUT:
parent
– a homspaceA
– matrix or aMatrixMorphism_abstract
instancecopy_matrix
– boolean (default:True
); make an immutable copy of the matrixA
if it is mutable. IfFalse
, then this makesA
immutable.
- is_injective()[source]¶
Tell whether
self
is injective.EXAMPLES:
sage: V1 = QQ^2 sage: V2 = QQ^3 sage: phi = V1.hom(Matrix([[1,2,3], [4,5,6]]),V2) sage: phi.is_injective() True sage: psi = V2.hom(Matrix([[1,2], [3,4], [5,6]]),V1) sage: psi.is_injective() False
>>> from sage.all import * >>> V1 = QQ**Integer(2) >>> V2 = QQ**Integer(3) >>> phi = V1.hom(Matrix([[Integer(1),Integer(2),Integer(3)], [Integer(4),Integer(5),Integer(6)]]),V2) >>> phi.is_injective() True >>> psi = V2.hom(Matrix([[Integer(1),Integer(2)], [Integer(3),Integer(4)], [Integer(5),Integer(6)]]),V1) >>> psi.is_injective() False
AUTHOR:
– Simon King (2010-05)
- is_surjective()[source]¶
Tell whether
self
is surjective.EXAMPLES:
sage: V1 = QQ^2 sage: V2 = QQ^3 sage: phi = V1.hom(Matrix([[1,2,3], [4,5,6]]), V2) sage: phi.is_surjective() False sage: psi = V2.hom(Matrix([[1,2], [3,4], [5,6]]), V1) sage: psi.is_surjective() True
>>> from sage.all import * >>> V1 = QQ**Integer(2) >>> V2 = QQ**Integer(3) >>> phi = V1.hom(Matrix([[Integer(1),Integer(2),Integer(3)], [Integer(4),Integer(5),Integer(6)]]), V2) >>> phi.is_surjective() False >>> psi = V2.hom(Matrix([[Integer(1),Integer(2)], [Integer(3),Integer(4)], [Integer(5),Integer(6)]]), V1) >>> psi.is_surjective() True
An example over a PID that is not \(\ZZ\).
sage: R.<x> = PolynomialRing(QQ) sage: A = R^2 sage: B = R^2 sage: H = A.hom([B([x^2 - 1, 1]), B([x^2, 1])]) sage: H.image() Free module of degree 2 and rank 2 over Univariate Polynomial Ring in x over Rational Field Echelon basis matrix: [ 1 0] [ 0 -1] sage: H.is_surjective() True
>>> from sage.all import * >>> R = PolynomialRing(QQ, names=('x',)); (x,) = R._first_ngens(1) >>> A = R**Integer(2) >>> B = R**Integer(2) >>> H = A.hom([B([x**Integer(2) - Integer(1), Integer(1)]), B([x**Integer(2), Integer(1)])]) >>> H.image() Free module of degree 2 and rank 2 over Univariate Polynomial Ring in x over Rational Field Echelon basis matrix: [ 1 0] [ 0 -1] >>> H.is_surjective() True
This tests if Issue #11552 is fixed.
sage: V = ZZ^2 sage: m = matrix(ZZ, [[1,2], [0,2]]) sage: phi = V.hom(m, V) sage: phi.lift(vector(ZZ, [0, 1])) Traceback (most recent call last): ... ValueError: element is not in the image sage: phi.is_surjective() False
>>> from sage.all import * >>> V = ZZ**Integer(2) >>> m = matrix(ZZ, [[Integer(1),Integer(2)], [Integer(0),Integer(2)]]) >>> phi = V.hom(m, V) >>> phi.lift(vector(ZZ, [Integer(0), Integer(1)])) Traceback (most recent call last): ... ValueError: element is not in the image >>> phi.is_surjective() False
AUTHORS:
Simon King (2010-05)
Rob Beezer (2011-06-28)
- matrix(side=None)[source]¶
Return a matrix that defines this morphism.
INPUT:
side
– (default:None
) the side of the matrix where a vector is placed to effect the morphism (function)
OUTPUT:
A matrix which represents the morphism, relative to bases for the domain and codomain. If the modules are provided with user bases, then the representation is relative to these bases.
Internally, Sage represents a matrix morphism with the matrix multiplying a row vector placed to the left of the matrix. If the option
side='right'
is used, then a matrix is returned that acts on a vector to the right of the matrix. These two matrices are just transposes of each other and the difference is just a preference for the style of representation.EXAMPLES:
sage: V = ZZ^2; W = ZZ^3 sage: m = column_matrix([3*V.0 - 5*V.1, 4*V.0 + 2*V.1, V.0 + V.1]) sage: phi = V.hom(m, W) sage: phi.matrix() [ 3 4 1] [-5 2 1] sage: phi.matrix(side='right') [ 3 -5] [ 4 2] [ 1 1]
>>> from sage.all import * >>> V = ZZ**Integer(2); W = ZZ**Integer(3) >>> m = column_matrix([Integer(3)*V.gen(0) - Integer(5)*V.gen(1), Integer(4)*V.gen(0) + Integer(2)*V.gen(1), V.gen(0) + V.gen(1)]) >>> phi = V.hom(m, W) >>> phi.matrix() [ 3 4 1] [-5 2 1] >>> phi.matrix(side='right') [ 3 -5] [ 4 2] [ 1 1]
- class sage.modules.matrix_morphism.MatrixMorphism_abstract(parent, side='left')[source]¶
Bases:
Morphism
INPUT:
parent
– a homspaceA
– matrix
EXAMPLES:
sage: from sage.modules.matrix_morphism import MatrixMorphism sage: T = End(ZZ^3) sage: M = MatrixSpace(ZZ,3) sage: I = M.identity_matrix() sage: A = MatrixMorphism(T, I) sage: loads(A.dumps()) == A True
>>> from sage.all import * >>> from sage.modules.matrix_morphism import MatrixMorphism >>> T = End(ZZ**Integer(3)) >>> M = MatrixSpace(ZZ,Integer(3)) >>> I = M.identity_matrix() >>> A = MatrixMorphism(T, I) >>> loads(A.dumps()) == A True
- base_ring()[source]¶
Return the base ring of
self
, that is, the ring over whichself
is given by a matrix.EXAMPLES:
sage: sage.modules.matrix_morphism.MatrixMorphism((ZZ**2).endomorphism_ring(), Matrix(ZZ,2,[3..6])).base_ring() Integer Ring
>>> from sage.all import * >>> sage.modules.matrix_morphism.MatrixMorphism((ZZ**Integer(2)).endomorphism_ring(), Matrix(ZZ,Integer(2),(ellipsis_range(Integer(3),Ellipsis,Integer(6))))).base_ring() Integer Ring
- characteristic_polynomial()[source]¶
Return the characteristic polynomial of this endomorphism.
characteristic_polynomial()
andcharpoly()
are the same method.INPUT:
var
– variable
EXAMPLES:
sage: # needs sage.modules sage: V = ZZ^2; phi = V.hom([V.0 + V.1, 2*V.1]) sage: phi.characteristic_polynomial() x^2 - 3*x + 2 sage: phi.charpoly() x^2 - 3*x + 2 sage: phi.matrix().charpoly() x^2 - 3*x + 2 sage: phi.charpoly('T') T^2 - 3*T + 2 sage: W = CombinatorialFreeModule(ZZ, ['x', 'y']) sage: M = matrix(ZZ, [[1, 0], [1, 2]]) sage: psi = W.module_morphism(matrix=M, codomain=W) sage: psi.charpoly() x^2 - 3*x + 2
>>> from sage.all import * >>> # needs sage.modules >>> V = ZZ**Integer(2); phi = V.hom([V.gen(0) + V.gen(1), Integer(2)*V.gen(1)]) >>> phi.characteristic_polynomial() x^2 - 3*x + 2 >>> phi.charpoly() x^2 - 3*x + 2 >>> phi.matrix().charpoly() x^2 - 3*x + 2 >>> phi.charpoly('T') T^2 - 3*T + 2 >>> W = CombinatorialFreeModule(ZZ, ['x', 'y']) >>> M = matrix(ZZ, [[Integer(1), Integer(0)], [Integer(1), Integer(2)]]) >>> psi = W.module_morphism(matrix=M, codomain=W) >>> psi.charpoly() x^2 - 3*x + 2
- charpoly()[source]¶
Return the characteristic polynomial of this endomorphism.
characteristic_polynomial()
andcharpoly()
are the same method.INPUT:
var
– variable
EXAMPLES:
sage: # needs sage.modules sage: V = ZZ^2; phi = V.hom([V.0 + V.1, 2*V.1]) sage: phi.characteristic_polynomial() x^2 - 3*x + 2 sage: phi.charpoly() x^2 - 3*x + 2 sage: phi.matrix().charpoly() x^2 - 3*x + 2 sage: phi.charpoly('T') T^2 - 3*T + 2 sage: W = CombinatorialFreeModule(ZZ, ['x', 'y']) sage: M = matrix(ZZ, [[1, 0], [1, 2]]) sage: psi = W.module_morphism(matrix=M, codomain=W) sage: psi.charpoly() x^2 - 3*x + 2
>>> from sage.all import * >>> # needs sage.modules >>> V = ZZ**Integer(2); phi = V.hom([V.gen(0) + V.gen(1), Integer(2)*V.gen(1)]) >>> phi.characteristic_polynomial() x^2 - 3*x + 2 >>> phi.charpoly() x^2 - 3*x + 2 >>> phi.matrix().charpoly() x^2 - 3*x + 2 >>> phi.charpoly('T') T^2 - 3*T + 2 >>> W = CombinatorialFreeModule(ZZ, ['x', 'y']) >>> M = matrix(ZZ, [[Integer(1), Integer(0)], [Integer(1), Integer(2)]]) >>> psi = W.module_morphism(matrix=M, codomain=W) >>> psi.charpoly() x^2 - 3*x + 2
- decomposition(*args, **kwds)[source]¶
Return decomposition of this endomorphism, i.e., sequence of subspaces obtained by finding invariant subspaces of
self
.See the documentation for
self.matrix().decomposition
for more details. All inputs to this function are passed onto the matrix one.EXAMPLES:
sage: V = ZZ^2; phi = V.hom([V.0+V.1, 2*V.1]) sage: phi.decomposition() # needs sage.libs.pari [ Free module of degree 2 and rank 1 over Integer Ring Echelon basis matrix: [0 1], Free module of degree 2 and rank 1 over Integer Ring Echelon basis matrix: [ 1 -1] ] sage: phi2 = V.hom(phi.matrix(), side='right') sage: phi2.decomposition() # needs sage.libs.pari [ Free module of degree 2 and rank 1 over Integer Ring Echelon basis matrix: [1 1], Free module of degree 2 and rank 1 over Integer Ring Echelon basis matrix: [1 0] ]
>>> from sage.all import * >>> V = ZZ**Integer(2); phi = V.hom([V.gen(0)+V.gen(1), Integer(2)*V.gen(1)]) >>> phi.decomposition() # needs sage.libs.pari [ Free module of degree 2 and rank 1 over Integer Ring Echelon basis matrix: [0 1], Free module of degree 2 and rank 1 over Integer Ring Echelon basis matrix: [ 1 -1] ] >>> phi2 = V.hom(phi.matrix(), side='right') >>> phi2.decomposition() # needs sage.libs.pari [ Free module of degree 2 and rank 1 over Integer Ring Echelon basis matrix: [1 1], Free module of degree 2 and rank 1 over Integer Ring Echelon basis matrix: [1 0] ]
- det()[source]¶
Return the determinant of this endomorphism.
determinant()
anddet()
are the same method.EXAMPLES:
sage: # needs sage.modules sage: V = ZZ^2; phi = V.hom([V.0 + V.1, 2*V.1]) sage: phi.determinant() 2 sage: phi.det() 2 sage: W = CombinatorialFreeModule(ZZ, ['x', 'y']) sage: M = matrix(ZZ, [[1, 0], [1, 2]]) sage: psi = W.module_morphism(matrix=M, codomain=W) sage: psi.det() 2
>>> from sage.all import * >>> # needs sage.modules >>> V = ZZ**Integer(2); phi = V.hom([V.gen(0) + V.gen(1), Integer(2)*V.gen(1)]) >>> phi.determinant() 2 >>> phi.det() 2 >>> W = CombinatorialFreeModule(ZZ, ['x', 'y']) >>> M = matrix(ZZ, [[Integer(1), Integer(0)], [Integer(1), Integer(2)]]) >>> psi = W.module_morphism(matrix=M, codomain=W) >>> psi.det() 2
- determinant()[source]¶
Return the determinant of this endomorphism.
determinant()
anddet()
are the same method.EXAMPLES:
sage: # needs sage.modules sage: V = ZZ^2; phi = V.hom([V.0 + V.1, 2*V.1]) sage: phi.determinant() 2 sage: phi.det() 2 sage: W = CombinatorialFreeModule(ZZ, ['x', 'y']) sage: M = matrix(ZZ, [[1, 0], [1, 2]]) sage: psi = W.module_morphism(matrix=M, codomain=W) sage: psi.det() 2
>>> from sage.all import * >>> # needs sage.modules >>> V = ZZ**Integer(2); phi = V.hom([V.gen(0) + V.gen(1), Integer(2)*V.gen(1)]) >>> phi.determinant() 2 >>> phi.det() 2 >>> W = CombinatorialFreeModule(ZZ, ['x', 'y']) >>> M = matrix(ZZ, [[Integer(1), Integer(0)], [Integer(1), Integer(2)]]) >>> psi = W.module_morphism(matrix=M, codomain=W) >>> psi.det() 2
- fcp()[source]¶
Return the factorization of the characteristic polynomial.
INPUT:
var
– variable
EXAMPLES:
sage: # needs sage.modules sage: V = ZZ^2; phi = V.hom([V.0 + V.1, 2*V.1]) sage: phi.fcp() # needs sage.libs.pari (x - 2) * (x - 1) sage: phi.fcp('T') # needs sage.libs.pari (T - 2) * (T - 1) sage: W = CombinatorialFreeModule(ZZ, ['x', 'y']) sage: M = matrix(ZZ, [[1, 0], [1, 2]]) sage: psi = W.module_morphism(matrix=M, codomain=W) sage: psi.fcp() # needs sage.libs.pari (x - 2) * (x - 1)
>>> from sage.all import * >>> # needs sage.modules >>> V = ZZ**Integer(2); phi = V.hom([V.gen(0) + V.gen(1), Integer(2)*V.gen(1)]) >>> phi.fcp() # needs sage.libs.pari (x - 2) * (x - 1) >>> phi.fcp('T') # needs sage.libs.pari (T - 2) * (T - 1) >>> W = CombinatorialFreeModule(ZZ, ['x', 'y']) >>> M = matrix(ZZ, [[Integer(1), Integer(0)], [Integer(1), Integer(2)]]) >>> psi = W.module_morphism(matrix=M, codomain=W) >>> psi.fcp() # needs sage.libs.pari (x - 2) * (x - 1)
- image()[source]¶
Compute the image of this morphism.
EXAMPLES:
sage: V = VectorSpace(QQ, 3) sage: phi = V.Hom(V)(matrix(QQ, 3, range(9))) sage: phi.image() Vector space of degree 3 and dimension 2 over Rational Field Basis matrix: [ 1 0 -1] [ 0 1 2] sage: hom(GF(7)^3, GF(7)^2, zero_matrix(GF(7), 3, 2)).image() Vector space of degree 2 and dimension 0 over Finite Field of size 7 Basis matrix: [] sage: m = matrix(3, [1, 0, 0, 1, 0, 0, 0, 0, 1]); m [1 0 0] [1 0 0] [0 0 1] sage: f1 = V.hom(m) sage: f2 = V.hom(m, side='right') sage: f1.image() Vector space of degree 3 and dimension 2 over Rational Field Basis matrix: [1 0 0] [0 0 1] sage: f2.image() Vector space of degree 3 and dimension 2 over Rational Field Basis matrix: [1 1 0] [0 0 1]
>>> from sage.all import * >>> V = VectorSpace(QQ, Integer(3)) >>> phi = V.Hom(V)(matrix(QQ, Integer(3), range(Integer(9)))) >>> phi.image() Vector space of degree 3 and dimension 2 over Rational Field Basis matrix: [ 1 0 -1] [ 0 1 2] >>> hom(GF(Integer(7))**Integer(3), GF(Integer(7))**Integer(2), zero_matrix(GF(Integer(7)), Integer(3), Integer(2))).image() Vector space of degree 2 and dimension 0 over Finite Field of size 7 Basis matrix: [] >>> m = matrix(Integer(3), [Integer(1), Integer(0), Integer(0), Integer(1), Integer(0), Integer(0), Integer(0), Integer(0), Integer(1)]); m [1 0 0] [1 0 0] [0 0 1] >>> f1 = V.hom(m) >>> f2 = V.hom(m, side='right') >>> f1.image() Vector space of degree 3 and dimension 2 over Rational Field Basis matrix: [1 0 0] [0 0 1] >>> f2.image() Vector space of degree 3 and dimension 2 over Rational Field Basis matrix: [1 1 0] [0 0 1]
Compute the image of the identity map on a ZZ-submodule:
sage: V = (ZZ^2).span([[1,2], [3,4]]) sage: phi = V.Hom(V)(identity_matrix(ZZ,2)) sage: phi(V.0) == V.0 True sage: phi(V.1) == V.1 True sage: phi.image() Free module of degree 2 and rank 2 over Integer Ring Echelon basis matrix: [1 0] [0 2] sage: phi.image() == V True
>>> from sage.all import * >>> V = (ZZ**Integer(2)).span([[Integer(1),Integer(2)], [Integer(3),Integer(4)]]) >>> phi = V.Hom(V)(identity_matrix(ZZ,Integer(2))) >>> phi(V.gen(0)) == V.gen(0) True >>> phi(V.gen(1)) == V.gen(1) True >>> phi.image() Free module of degree 2 and rank 2 over Integer Ring Echelon basis matrix: [1 0] [0 2] >>> phi.image() == V True
- inverse()[source]¶
Return the inverse of this matrix morphism, if the inverse exists.
This raises a
ZeroDivisionError
if the inverse does not exist.EXAMPLES:
An invertible morphism created as a restriction of a non-invertible morphism, and which has an unequal domain and codomain.
sage: V = QQ^4 sage: W = QQ^3 sage: m = matrix(QQ, [[2, 0, 3], [-6, 1, 4], [1, 2, -4], [1, 0, 1]]) sage: phi = V.hom(m, W) sage: rho = phi.restrict_domain(V.span([V.0, V.3])) sage: zeta = rho.restrict_codomain(W.span([W.0, W.2])) sage: x = vector(QQ, [2, 0, 0, -7]) sage: y = zeta(x); y (-3, 0, -1) sage: inv = zeta.inverse(); inv Vector space morphism represented by the matrix: [-1 3] [ 1 -2] Domain: Vector space of degree 3 and dimension 2 over Rational Field Basis matrix: [1 0 0] [0 0 1] Codomain: Vector space of degree 4 and dimension 2 over Rational Field Basis matrix: [1 0 0 0] [0 0 0 1] sage: inv(y) == x True
>>> from sage.all import * >>> V = QQ**Integer(4) >>> W = QQ**Integer(3) >>> m = matrix(QQ, [[Integer(2), Integer(0), Integer(3)], [-Integer(6), Integer(1), Integer(4)], [Integer(1), Integer(2), -Integer(4)], [Integer(1), Integer(0), Integer(1)]]) >>> phi = V.hom(m, W) >>> rho = phi.restrict_domain(V.span([V.gen(0), V.gen(3)])) >>> zeta = rho.restrict_codomain(W.span([W.gen(0), W.gen(2)])) >>> x = vector(QQ, [Integer(2), Integer(0), Integer(0), -Integer(7)]) >>> y = zeta(x); y (-3, 0, -1) >>> inv = zeta.inverse(); inv Vector space morphism represented by the matrix: [-1 3] [ 1 -2] Domain: Vector space of degree 3 and dimension 2 over Rational Field Basis matrix: [1 0 0] [0 0 1] Codomain: Vector space of degree 4 and dimension 2 over Rational Field Basis matrix: [1 0 0 0] [0 0 0 1] >>> inv(y) == x True
An example of an invertible morphism between modules, (rather than between vector spaces).
sage: M = ZZ^4 sage: p = matrix(ZZ, [[ 0, -1, 1, -2], ....: [ 1, -3, 2, -3], ....: [ 0, 4, -3, 4], ....: [-2, 8, -4, 3]]) sage: phi = M.hom(p, M) sage: x = vector(ZZ, [1, -3, 5, -2]) sage: y = phi(x); y (1, 12, -12, 21) sage: rho = phi.inverse(); rho Free module morphism defined by the matrix [ -5 3 -1 1] [ -9 4 -3 2] [-20 8 -7 4] [ -6 2 -2 1] Domain: Ambient free module of rank 4 over the principal ideal domain ... Codomain: Ambient free module of rank 4 over the principal ideal domain ... sage: rho(y) == x True
>>> from sage.all import * >>> M = ZZ**Integer(4) >>> p = matrix(ZZ, [[ Integer(0), -Integer(1), Integer(1), -Integer(2)], ... [ Integer(1), -Integer(3), Integer(2), -Integer(3)], ... [ Integer(0), Integer(4), -Integer(3), Integer(4)], ... [-Integer(2), Integer(8), -Integer(4), Integer(3)]]) >>> phi = M.hom(p, M) >>> x = vector(ZZ, [Integer(1), -Integer(3), Integer(5), -Integer(2)]) >>> y = phi(x); y (1, 12, -12, 21) >>> rho = phi.inverse(); rho Free module morphism defined by the matrix [ -5 3 -1 1] [ -9 4 -3 2] [-20 8 -7 4] [ -6 2 -2 1] Domain: Ambient free module of rank 4 over the principal ideal domain ... Codomain: Ambient free module of rank 4 over the principal ideal domain ... >>> rho(y) == x True
A non-invertible morphism, despite having an appropriate domain and codomain.
sage: V = QQ^2 sage: m = matrix(QQ, [[1, 2], [20, 40]]) sage: phi = V.hom(m, V) sage: phi.is_bijective() False sage: phi.inverse() Traceback (most recent call last): ... ZeroDivisionError: matrix morphism not invertible
>>> from sage.all import * >>> V = QQ**Integer(2) >>> m = matrix(QQ, [[Integer(1), Integer(2)], [Integer(20), Integer(40)]]) >>> phi = V.hom(m, V) >>> phi.is_bijective() False >>> phi.inverse() Traceback (most recent call last): ... ZeroDivisionError: matrix morphism not invertible
The matrix representation of this morphism is invertible over the rationals, but not over the integers, thus the morphism is not invertible as a map between modules. It is easy to notice from the definition that every vector of the image will have a second entry that is an even integer.
sage: V = ZZ^2 sage: q = matrix(ZZ, [[1, 2], [3, 4]]) sage: phi = V.hom(q, V) sage: phi.matrix().change_ring(QQ).inverse() [ -2 1] [ 3/2 -1/2] sage: phi.is_bijective() False sage: phi.image() Free module of degree 2 and rank 2 over Integer Ring Echelon basis matrix: [1 0] [0 2] sage: phi.lift(vector(ZZ, [1, 1])) Traceback (most recent call last): ... ValueError: element is not in the image sage: phi.inverse() Traceback (most recent call last): ... ZeroDivisionError: matrix morphism not invertible
>>> from sage.all import * >>> V = ZZ**Integer(2) >>> q = matrix(ZZ, [[Integer(1), Integer(2)], [Integer(3), Integer(4)]]) >>> phi = V.hom(q, V) >>> phi.matrix().change_ring(QQ).inverse() [ -2 1] [ 3/2 -1/2] >>> phi.is_bijective() False >>> phi.image() Free module of degree 2 and rank 2 over Integer Ring Echelon basis matrix: [1 0] [0 2] >>> phi.lift(vector(ZZ, [Integer(1), Integer(1)])) Traceback (most recent call last): ... ValueError: element is not in the image >>> phi.inverse() Traceback (most recent call last): ... ZeroDivisionError: matrix morphism not invertible
The unary invert operator (~, tilde, “wiggle”) is synonymous with the
inverse()
method (and a lot easier to type).sage: V = QQ^2 sage: r = matrix(QQ, [[4, 3], [-2, 5]]) sage: phi = V.hom(r, V) sage: rho = phi.inverse() sage: zeta = ~phi sage: rho.is_equal_function(zeta) True
>>> from sage.all import * >>> V = QQ**Integer(2) >>> r = matrix(QQ, [[Integer(4), Integer(3)], [-Integer(2), Integer(5)]]) >>> phi = V.hom(r, V) >>> rho = phi.inverse() >>> zeta = ~phi >>> rho.is_equal_function(zeta) True
- is_bijective()[source]¶
Tell whether
self
is bijective.EXAMPLES:
Two morphisms that are obviously not bijective, simply on considerations of the dimensions. However, each fullfills half of the requirements to be a bijection.
sage: V1 = QQ^2 sage: V2 = QQ^3 sage: m = matrix(QQ, [[1, 2, 3], [4, 5, 6]]) sage: phi = V1.hom(m, V2) sage: phi.is_injective() True sage: phi.is_bijective() False sage: rho = V2.hom(m.transpose(), V1) sage: rho.is_surjective() True sage: rho.is_bijective() False
>>> from sage.all import * >>> V1 = QQ**Integer(2) >>> V2 = QQ**Integer(3) >>> m = matrix(QQ, [[Integer(1), Integer(2), Integer(3)], [Integer(4), Integer(5), Integer(6)]]) >>> phi = V1.hom(m, V2) >>> phi.is_injective() True >>> phi.is_bijective() False >>> rho = V2.hom(m.transpose(), V1) >>> rho.is_surjective() True >>> rho.is_bijective() False
We construct a simple bijection between two one-dimensional vector spaces.
sage: V1 = QQ^3 sage: V2 = QQ^2 sage: phi = V1.hom(matrix(QQ, [[1, 2], [3, 4], [5, 6]]), V2) sage: x = vector(QQ, [1, -1, 4]) sage: y = phi(x); y (18, 22) sage: rho = phi.restrict_domain(V1.span([x])) sage: zeta = rho.restrict_codomain(V2.span([y])) sage: zeta.is_bijective() True
>>> from sage.all import * >>> V1 = QQ**Integer(3) >>> V2 = QQ**Integer(2) >>> phi = V1.hom(matrix(QQ, [[Integer(1), Integer(2)], [Integer(3), Integer(4)], [Integer(5), Integer(6)]]), V2) >>> x = vector(QQ, [Integer(1), -Integer(1), Integer(4)]) >>> y = phi(x); y (18, 22) >>> rho = phi.restrict_domain(V1.span([x])) >>> zeta = rho.restrict_codomain(V2.span([y])) >>> zeta.is_bijective() True
AUTHOR:
Rob Beezer (2011-06-28)
- is_equal_function(other)[source]¶
Determines if two morphisms are equal functions.
INPUT:
other
– a morphism to compare withself
OUTPUT:
Returns
True
precisely when the two morphisms have equal domains and codomains (as sets) and produce identical output when given the same input. Otherwise returnsFalse
.This is useful when
self
andother
may have different representations.Sage’s default comparison of matrix morphisms requires the domains to have the same bases and the codomains to have the same bases, and then compares the matrix representations. This notion of equality is more permissive (it will return
True
“more often”), but is more correct mathematically.EXAMPLES:
Three morphisms defined by combinations of different bases for the domain and codomain and different functions. Two are equal, the third is different from both of the others.
sage: B = matrix(QQ, [[-3, 5, -4, 2], ....: [-1, 2, -1, 4], ....: [ 4, -6, 5, -1], ....: [-5, 7, -6, 1]]) sage: U = (QQ^4).subspace_with_basis(B.rows()) sage: C = matrix(QQ, [[-1, -6, -4], ....: [ 3, -5, 6], ....: [ 1, 2, 3]]) sage: V = (QQ^3).subspace_with_basis(C.rows()) sage: H = Hom(U, V) sage: D = matrix(QQ, [[-7, -2, -5, 2], ....: [-5, 1, -4, -8], ....: [ 1, -1, 1, 4], ....: [-4, -1, -3, 1]]) sage: X = (QQ^4).subspace_with_basis(D.rows()) sage: E = matrix(QQ, [[ 4, -1, 4], ....: [ 5, -4, -5], ....: [-1, 0, -2]]) sage: Y = (QQ^3).subspace_with_basis(E.rows()) sage: K = Hom(X, Y) sage: f = lambda x: vector(QQ, [x[0]+x[1], 2*x[1]-4*x[2], 5*x[3]]) sage: g = lambda x: vector(QQ, [x[0]-x[2], 2*x[1]-4*x[2], 5*x[3]]) sage: rho = H(f) sage: phi = K(f) sage: zeta = H(g) sage: rho.is_equal_function(phi) True sage: phi.is_equal_function(rho) True sage: zeta.is_equal_function(rho) False sage: phi.is_equal_function(zeta) False
>>> from sage.all import * >>> B = matrix(QQ, [[-Integer(3), Integer(5), -Integer(4), Integer(2)], ... [-Integer(1), Integer(2), -Integer(1), Integer(4)], ... [ Integer(4), -Integer(6), Integer(5), -Integer(1)], ... [-Integer(5), Integer(7), -Integer(6), Integer(1)]]) >>> U = (QQ**Integer(4)).subspace_with_basis(B.rows()) >>> C = matrix(QQ, [[-Integer(1), -Integer(6), -Integer(4)], ... [ Integer(3), -Integer(5), Integer(6)], ... [ Integer(1), Integer(2), Integer(3)]]) >>> V = (QQ**Integer(3)).subspace_with_basis(C.rows()) >>> H = Hom(U, V) >>> D = matrix(QQ, [[-Integer(7), -Integer(2), -Integer(5), Integer(2)], ... [-Integer(5), Integer(1), -Integer(4), -Integer(8)], ... [ Integer(1), -Integer(1), Integer(1), Integer(4)], ... [-Integer(4), -Integer(1), -Integer(3), Integer(1)]]) >>> X = (QQ**Integer(4)).subspace_with_basis(D.rows()) >>> E = matrix(QQ, [[ Integer(4), -Integer(1), Integer(4)], ... [ Integer(5), -Integer(4), -Integer(5)], ... [-Integer(1), Integer(0), -Integer(2)]]) >>> Y = (QQ**Integer(3)).subspace_with_basis(E.rows()) >>> K = Hom(X, Y) >>> f = lambda x: vector(QQ, [x[Integer(0)]+x[Integer(1)], Integer(2)*x[Integer(1)]-Integer(4)*x[Integer(2)], Integer(5)*x[Integer(3)]]) >>> g = lambda x: vector(QQ, [x[Integer(0)]-x[Integer(2)], Integer(2)*x[Integer(1)]-Integer(4)*x[Integer(2)], Integer(5)*x[Integer(3)]]) >>> rho = H(f) >>> phi = K(f) >>> zeta = H(g) >>> rho.is_equal_function(phi) True >>> phi.is_equal_function(rho) True >>> zeta.is_equal_function(rho) False >>> phi.is_equal_function(zeta) False
AUTHOR:
Rob Beezer (2011-07-15)
- is_identity()[source]¶
Determines if this morphism is an identity function or not.
EXAMPLES:
A homomorphism that cannot possibly be the identity due to an unequal domain and codomain.
sage: V = QQ^3 sage: W = QQ^2 sage: m = matrix(QQ, [[1, 2], [3, 4], [5, 6]]) sage: phi = V.hom(m, W) sage: phi.is_identity() False
>>> from sage.all import * >>> V = QQ**Integer(3) >>> W = QQ**Integer(2) >>> m = matrix(QQ, [[Integer(1), Integer(2)], [Integer(3), Integer(4)], [Integer(5), Integer(6)]]) >>> phi = V.hom(m, W) >>> phi.is_identity() False
A bijection, but not the identity.
sage: V = QQ^3 sage: n = matrix(QQ, [[3, 1, -8], [5, -4, 6], [1, 1, -5]]) sage: phi = V.hom(n, V) sage: phi.is_bijective() True sage: phi.is_identity() False
>>> from sage.all import * >>> V = QQ**Integer(3) >>> n = matrix(QQ, [[Integer(3), Integer(1), -Integer(8)], [Integer(5), -Integer(4), Integer(6)], [Integer(1), Integer(1), -Integer(5)]]) >>> phi = V.hom(n, V) >>> phi.is_bijective() True >>> phi.is_identity() False
A restriction that is the identity.
sage: V = QQ^3 sage: p = matrix(QQ, [[1, 0, 0], [5, 8, 3], [0, 0, 1]]) sage: phi = V.hom(p, V) sage: rho = phi.restrict(V.span([V.0, V.2])) sage: rho.is_identity() True
>>> from sage.all import * >>> V = QQ**Integer(3) >>> p = matrix(QQ, [[Integer(1), Integer(0), Integer(0)], [Integer(5), Integer(8), Integer(3)], [Integer(0), Integer(0), Integer(1)]]) >>> phi = V.hom(p, V) >>> rho = phi.restrict(V.span([V.gen(0), V.gen(2)])) >>> rho.is_identity() True
An identity linear transformation that is defined with a domain and codomain with wildly different bases, so that the matrix representation is not simply the identity matrix.
sage: A = matrix(QQ, [[1, 1, 0], [2, 3, -4], [2, 4, -7]]) sage: B = matrix(QQ, [[2, 7, -2], [-1, -3, 1], [-1, -6, 2]]) sage: U = (QQ^3).subspace_with_basis(A.rows()) sage: V = (QQ^3).subspace_with_basis(B.rows()) sage: H = Hom(U, V) sage: id = lambda x: x sage: phi = H(id) sage: phi([203, -179, 34]) (203, -179, 34) sage: phi.matrix() [ 1 0 1] [ -9 -18 -2] [-17 -31 -5] sage: phi.is_identity() True
>>> from sage.all import * >>> A = matrix(QQ, [[Integer(1), Integer(1), Integer(0)], [Integer(2), Integer(3), -Integer(4)], [Integer(2), Integer(4), -Integer(7)]]) >>> B = matrix(QQ, [[Integer(2), Integer(7), -Integer(2)], [-Integer(1), -Integer(3), Integer(1)], [-Integer(1), -Integer(6), Integer(2)]]) >>> U = (QQ**Integer(3)).subspace_with_basis(A.rows()) >>> V = (QQ**Integer(3)).subspace_with_basis(B.rows()) >>> H = Hom(U, V) >>> id = lambda x: x >>> phi = H(id) >>> phi([Integer(203), -Integer(179), Integer(34)]) (203, -179, 34) >>> phi.matrix() [ 1 0 1] [ -9 -18 -2] [-17 -31 -5] >>> phi.is_identity() True
AUTHOR:
Rob Beezer (2011-06-28)
- is_zero()[source]¶
Determines if this morphism is a zero function or not.
EXAMPLES:
A zero morphism created from a function.
sage: V = ZZ^5 sage: W = ZZ^3 sage: z = lambda x: zero_vector(ZZ, 3) sage: phi = V.hom(z, W) sage: phi.is_zero() True
>>> from sage.all import * >>> V = ZZ**Integer(5) >>> W = ZZ**Integer(3) >>> z = lambda x: zero_vector(ZZ, Integer(3)) >>> phi = V.hom(z, W) >>> phi.is_zero() True
An image list that just barely makes a nonzero morphism.
sage: V = ZZ^4 sage: W = ZZ^6 sage: z = zero_vector(ZZ, 6) sage: images = [z, z, W.5, z] sage: phi = V.hom(images, W) sage: phi.is_zero() False
>>> from sage.all import * >>> V = ZZ**Integer(4) >>> W = ZZ**Integer(6) >>> z = zero_vector(ZZ, Integer(6)) >>> images = [z, z, W.gen(5), z] >>> phi = V.hom(images, W) >>> phi.is_zero() False
AUTHOR:
Rob Beezer (2011-07-15)
- kernel()[source]¶
Compute the kernel of this morphism.
EXAMPLES:
sage: V = VectorSpace(QQ, 3) sage: id = V.Hom(V)(identity_matrix(QQ,3)) sage: null = V.Hom(V)(0*identity_matrix(QQ,3)) sage: id.kernel() Vector space of degree 3 and dimension 0 over Rational Field Basis matrix: [] sage: phi = V.Hom(V)(matrix(QQ, 3, range(9))) sage: phi.kernel() Vector space of degree 3 and dimension 1 over Rational Field Basis matrix: [ 1 -2 1] sage: hom(CC^2, CC^2, matrix(CC, [[1,0], [0,1]])).kernel() Vector space of degree 2 and dimension 0 over Complex Field with 53 bits of precision Basis matrix: [] sage: m = matrix(3, [1, 0, 0, 1, 0, 0, 0, 0, 1]); m [1 0 0] [1 0 0] [0 0 1] sage: f1 = V.hom(m) sage: f2 = V.hom(m, side='right') sage: f1.kernel() Vector space of degree 3 and dimension 1 over Rational Field Basis matrix: [ 1 -1 0] sage: f2.kernel() Vector space of degree 3 and dimension 1 over Rational Field Basis matrix: [0 1 0]
>>> from sage.all import * >>> V = VectorSpace(QQ, Integer(3)) >>> id = V.Hom(V)(identity_matrix(QQ,Integer(3))) >>> null = V.Hom(V)(Integer(0)*identity_matrix(QQ,Integer(3))) >>> id.kernel() Vector space of degree 3 and dimension 0 over Rational Field Basis matrix: [] >>> phi = V.Hom(V)(matrix(QQ, Integer(3), range(Integer(9)))) >>> phi.kernel() Vector space of degree 3 and dimension 1 over Rational Field Basis matrix: [ 1 -2 1] >>> hom(CC**Integer(2), CC**Integer(2), matrix(CC, [[Integer(1),Integer(0)], [Integer(0),Integer(1)]])).kernel() Vector space of degree 2 and dimension 0 over Complex Field with 53 bits of precision Basis matrix: [] >>> m = matrix(Integer(3), [Integer(1), Integer(0), Integer(0), Integer(1), Integer(0), Integer(0), Integer(0), Integer(0), Integer(1)]); m [1 0 0] [1 0 0] [0 0 1] >>> f1 = V.hom(m) >>> f2 = V.hom(m, side='right') >>> f1.kernel() Vector space of degree 3 and dimension 1 over Rational Field Basis matrix: [ 1 -1 0] >>> f2.kernel() Vector space of degree 3 and dimension 1 over Rational Field Basis matrix: [0 1 0]
- matrix()[source]¶
EXAMPLES:
sage: V = ZZ^2; phi = V.hom(V.basis()) sage: phi.matrix() [1 0] [0 1] sage: sage.modules.matrix_morphism.MatrixMorphism_abstract.matrix(phi) Traceback (most recent call last): ... NotImplementedError: this method must be overridden in the extension class
>>> from sage.all import * >>> V = ZZ**Integer(2); phi = V.hom(V.basis()) >>> phi.matrix() [1 0] [0 1] >>> sage.modules.matrix_morphism.MatrixMorphism_abstract.matrix(phi) Traceback (most recent call last): ... NotImplementedError: this method must be overridden in the extension class
- nullity()[source]¶
Return the nullity of the matrix representing this morphism, which is the dimension of its kernel.
EXAMPLES:
sage: V = ZZ^2; phi = V.hom(V.basis()) sage: phi.nullity() 0 sage: V = ZZ^2; phi = V.hom([V.0, V.0]) sage: phi.nullity() 1
>>> from sage.all import * >>> V = ZZ**Integer(2); phi = V.hom(V.basis()) >>> phi.nullity() 0 >>> V = ZZ**Integer(2); phi = V.hom([V.gen(0), V.gen(0)]) >>> phi.nullity() 1
sage: m = matrix(2, [1, 2]) sage: V = ZZ^2 sage: h1 = V.hom(m) sage: h1.nullity() 1 sage: W = ZZ^1 sage: h2 = W.hom(m, side='right') sage: h2.nullity() 0
>>> from sage.all import * >>> m = matrix(Integer(2), [Integer(1), Integer(2)]) >>> V = ZZ**Integer(2) >>> h1 = V.hom(m) >>> h1.nullity() 1 >>> W = ZZ**Integer(1) >>> h2 = W.hom(m, side='right') >>> h2.nullity() 0
- rank()[source]¶
Return the rank of the matrix representing this morphism.
EXAMPLES:
sage: V = ZZ^2; phi = V.hom(V.basis()) sage: phi.rank() 2 sage: V = ZZ^2; phi = V.hom([V.0, V.0]) sage: phi.rank() 1
>>> from sage.all import * >>> V = ZZ**Integer(2); phi = V.hom(V.basis()) >>> phi.rank() 2 >>> V = ZZ**Integer(2); phi = V.hom([V.gen(0), V.gen(0)]) >>> phi.rank() 1
- restrict(sub)[source]¶
Restrict this matrix morphism to a subspace sub of the domain.
The codomain and domain of the resulting matrix are both sub.
EXAMPLES:
sage: V = ZZ^2; phi = V.hom([3*V.0, 2*V.1]) sage: phi.restrict(V.span([V.0])) Free module morphism defined by the matrix [3] Domain: Free module of degree 2 and rank 1 over Integer Ring Echelon ... Codomain: Free module of degree 2 and rank 1 over Integer Ring Echelon ... sage: V = (QQ^2).span_of_basis([[1,2], [3,4]]) sage: phi = V.hom([V.0 + V.1, 2*V.1]) sage: phi(V.1) == 2*V.1 True sage: W = span([V.1]) sage: phi(W) Vector space of degree 2 and dimension 1 over Rational Field Basis matrix: [ 1 4/3] sage: psi = phi.restrict(W); psi Vector space morphism represented by the matrix: [2] Domain: Vector space of degree 2 and dimension 1 over Rational Field Basis matrix: [ 1 4/3] Codomain: Vector space of degree 2 and dimension 1 over Rational Field Basis matrix: [ 1 4/3] sage: psi.domain() == W True sage: psi(W.0) == 2*W.0 True
>>> from sage.all import * >>> V = ZZ**Integer(2); phi = V.hom([Integer(3)*V.gen(0), Integer(2)*V.gen(1)]) >>> phi.restrict(V.span([V.gen(0)])) Free module morphism defined by the matrix [3] Domain: Free module of degree 2 and rank 1 over Integer Ring Echelon ... Codomain: Free module of degree 2 and rank 1 over Integer Ring Echelon ... >>> V = (QQ**Integer(2)).span_of_basis([[Integer(1),Integer(2)], [Integer(3),Integer(4)]]) >>> phi = V.hom([V.gen(0) + V.gen(1), Integer(2)*V.gen(1)]) >>> phi(V.gen(1)) == Integer(2)*V.gen(1) True >>> W = span([V.gen(1)]) >>> phi(W) Vector space of degree 2 and dimension 1 over Rational Field Basis matrix: [ 1 4/3] >>> psi = phi.restrict(W); psi Vector space morphism represented by the matrix: [2] Domain: Vector space of degree 2 and dimension 1 over Rational Field Basis matrix: [ 1 4/3] Codomain: Vector space of degree 2 and dimension 1 over Rational Field Basis matrix: [ 1 4/3] >>> psi.domain() == W True >>> psi(W.gen(0)) == Integer(2)*W.gen(0) True
sage: V = ZZ^3 sage: h1 = V.hom([V.0, V.1+V.2, -V.1+V.2]) sage: h2 = h1.side_switch() sage: SV = V.span([2*V.1,2*V.2]) sage: h1.restrict(SV) Free module morphism defined by the matrix [ 1 1] [-1 1] Domain: Free module of degree 3 and rank 2 over Integer Ring Echelon basis matrix: [0 2 0] [0 0 2] Codomain: Free module of degree 3 and rank 2 over Integer Ring Echelon basis matrix: [0 2 0] [0 0 2] sage: h2.restrict(SV) Free module morphism defined as left-multiplication by the matrix [ 1 -1] [ 1 1] Domain: Free module of degree 3 and rank 2 over Integer Ring Echelon basis matrix: [0 2 0] [0 0 2] Codomain: Free module of degree 3 and rank 2 over Integer Ring Echelon basis matrix: [0 2 0] [0 0 2]
>>> from sage.all import * >>> V = ZZ**Integer(3) >>> h1 = V.hom([V.gen(0), V.gen(1)+V.gen(2), -V.gen(1)+V.gen(2)]) >>> h2 = h1.side_switch() >>> SV = V.span([Integer(2)*V.gen(1),Integer(2)*V.gen(2)]) >>> h1.restrict(SV) Free module morphism defined by the matrix [ 1 1] [-1 1] Domain: Free module of degree 3 and rank 2 over Integer Ring Echelon basis matrix: [0 2 0] [0 0 2] Codomain: Free module of degree 3 and rank 2 over Integer Ring Echelon basis matrix: [0 2 0] [0 0 2] >>> h2.restrict(SV) Free module morphism defined as left-multiplication by the matrix [ 1 -1] [ 1 1] Domain: Free module of degree 3 and rank 2 over Integer Ring Echelon basis matrix: [0 2 0] [0 0 2] Codomain: Free module of degree 3 and rank 2 over Integer Ring Echelon basis matrix: [0 2 0] [0 0 2]
- restrict_codomain(sub)[source]¶
Restrict this matrix morphism to a subspace sub of the codomain.
The resulting morphism has the same domain as before, but a new codomain.
EXAMPLES:
sage: V = ZZ^2; phi = V.hom([4*(V.0+V.1),0]) sage: W = V.span([2*(V.0+V.1)]) sage: phi Free module morphism defined by the matrix [4 4] [0 0] Domain: Ambient free module of rank 2 over the principal ideal domain ... Codomain: Ambient free module of rank 2 over the principal ideal domain ... sage: psi = phi.restrict_codomain(W); psi Free module morphism defined by the matrix [2] [0] Domain: Ambient free module of rank 2 over the principal ideal domain ... Codomain: Free module of degree 2 and rank 1 over Integer Ring Echelon ... sage: phi2 = phi.side_switch(); phi2.restrict_codomain(W) Free module morphism defined as left-multiplication by the matrix [2 0] Domain: Ambient free module of rank 2 over the principal ideal domain Integer Ring Codomain: Free module of degree 2 and rank 1 over Integer Ring Echelon ...
>>> from sage.all import * >>> V = ZZ**Integer(2); phi = V.hom([Integer(4)*(V.gen(0)+V.gen(1)),Integer(0)]) >>> W = V.span([Integer(2)*(V.gen(0)+V.gen(1))]) >>> phi Free module morphism defined by the matrix [4 4] [0 0] Domain: Ambient free module of rank 2 over the principal ideal domain ... Codomain: Ambient free module of rank 2 over the principal ideal domain ... >>> psi = phi.restrict_codomain(W); psi Free module morphism defined by the matrix [2] [0] Domain: Ambient free module of rank 2 over the principal ideal domain ... Codomain: Free module of degree 2 and rank 1 over Integer Ring Echelon ... >>> phi2 = phi.side_switch(); phi2.restrict_codomain(W) Free module morphism defined as left-multiplication by the matrix [2 0] Domain: Ambient free module of rank 2 over the principal ideal domain Integer Ring Codomain: Free module of degree 2 and rank 1 over Integer Ring Echelon ...
An example in which the codomain equals the full ambient space, but with a different basis:
sage: V = QQ^2 sage: W = V.span_of_basis([[1,2],[3,4]]) sage: phi = V.hom(matrix(QQ,2,[1,0,2,0]),W) sage: phi.matrix() [1 0] [2 0] sage: phi(V.0) (1, 2) sage: phi(V.1) (2, 4) sage: X = V.span([[1,2]]); X Vector space of degree 2 and dimension 1 over Rational Field Basis matrix: [1 2] sage: phi(V.0) in X True sage: phi(V.1) in X True sage: psi = phi.restrict_codomain(X); psi Vector space morphism represented by the matrix: [1] [2] Domain: Vector space of dimension 2 over Rational Field Codomain: Vector space of degree 2 and dimension 1 over Rational Field Basis matrix: [1 2] sage: psi(V.0) (1, 2) sage: psi(V.1) (2, 4) sage: psi(V.0).parent() is X True
>>> from sage.all import * >>> V = QQ**Integer(2) >>> W = V.span_of_basis([[Integer(1),Integer(2)],[Integer(3),Integer(4)]]) >>> phi = V.hom(matrix(QQ,Integer(2),[Integer(1),Integer(0),Integer(2),Integer(0)]),W) >>> phi.matrix() [1 0] [2 0] >>> phi(V.gen(0)) (1, 2) >>> phi(V.gen(1)) (2, 4) >>> X = V.span([[Integer(1),Integer(2)]]); X Vector space of degree 2 and dimension 1 over Rational Field Basis matrix: [1 2] >>> phi(V.gen(0)) in X True >>> phi(V.gen(1)) in X True >>> psi = phi.restrict_codomain(X); psi Vector space morphism represented by the matrix: [1] [2] Domain: Vector space of dimension 2 over Rational Field Codomain: Vector space of degree 2 and dimension 1 over Rational Field Basis matrix: [1 2] >>> psi(V.gen(0)) (1, 2) >>> psi(V.gen(1)) (2, 4) >>> psi(V.gen(0)).parent() is X True
- restrict_domain(sub)[source]¶
Restrict this matrix morphism to a subspace sub of the domain. The subspace sub should have a basis() method and elements of the basis should be coercible into domain.
The resulting morphism has the same codomain as before, but a new domain.
EXAMPLES:
sage: V = ZZ^2; phi = V.hom([3*V.0, 2*V.1]) sage: phi.restrict_domain(V.span([V.0])) Free module morphism defined by the matrix [3 0] Domain: Free module of degree 2 and rank 1 over Integer Ring Echelon ... Codomain: Ambient free module of rank 2 over the principal ideal domain ... sage: phi.restrict_domain(V.span([V.1])) Free module morphism defined by the matrix [0 2]... sage: m = matrix(2, range(1,5)) sage: f1 = V.hom(m); f2 = V.hom(m, side='right') sage: SV = V.span([V.0]) sage: f1.restrict_domain(SV) Free module morphism defined by the matrix [1 2]... sage: f2.restrict_domain(SV) Free module morphism defined as left-multiplication by the matrix [1] [3]...
>>> from sage.all import * >>> V = ZZ**Integer(2); phi = V.hom([Integer(3)*V.gen(0), Integer(2)*V.gen(1)]) >>> phi.restrict_domain(V.span([V.gen(0)])) Free module morphism defined by the matrix [3 0] Domain: Free module of degree 2 and rank 1 over Integer Ring Echelon ... Codomain: Ambient free module of rank 2 over the principal ideal domain ... >>> phi.restrict_domain(V.span([V.gen(1)])) Free module morphism defined by the matrix [0 2]... >>> m = matrix(Integer(2), range(Integer(1),Integer(5))) >>> f1 = V.hom(m); f2 = V.hom(m, side='right') >>> SV = V.span([V.gen(0)]) >>> f1.restrict_domain(SV) Free module morphism defined by the matrix [1 2]... >>> f2.restrict_domain(SV) Free module morphism defined as left-multiplication by the matrix [1] [3]...
- side()[source]¶
Return the side of vectors acted on, relative to the matrix.
EXAMPLES:
sage: m = matrix(2, [1, 1, 0, 1]) sage: V = ZZ^2 sage: h1 = V.hom(m); h2 = V.hom(m, side='right') sage: h1.side() 'left' sage: h1([1, 0]) (1, 1) sage: h2.side() 'right' sage: h2([1, 0]) (1, 0)
>>> from sage.all import * >>> m = matrix(Integer(2), [Integer(1), Integer(1), Integer(0), Integer(1)]) >>> V = ZZ**Integer(2) >>> h1 = V.hom(m); h2 = V.hom(m, side='right') >>> h1.side() 'left' >>> h1([Integer(1), Integer(0)]) (1, 1) >>> h2.side() 'right' >>> h2([Integer(1), Integer(0)]) (1, 0)
- side_switch()[source]¶
Return the same morphism, acting on vectors on the opposite side.
EXAMPLES:
sage: m = matrix(2, [1,1,0,1]); m [1 1] [0 1] sage: V = ZZ^2 sage: h = V.hom(m); h.side() 'left' sage: h2 = h.side_switch(); h2 Free module morphism defined as left-multiplication by the matrix [1 0] [1 1] Domain: Ambient free module of rank 2 over the principal ideal domain Integer Ring Codomain: Ambient free module of rank 2 over the principal ideal domain Integer Ring sage: h2.side() 'right' sage: h2.side_switch().matrix() [1 1] [0 1]
>>> from sage.all import * >>> m = matrix(Integer(2), [Integer(1),Integer(1),Integer(0),Integer(1)]); m [1 1] [0 1] >>> V = ZZ**Integer(2) >>> h = V.hom(m); h.side() 'left' >>> h2 = h.side_switch(); h2 Free module morphism defined as left-multiplication by the matrix [1 0] [1 1] Domain: Ambient free module of rank 2 over the principal ideal domain Integer Ring Codomain: Ambient free module of rank 2 over the principal ideal domain Integer Ring >>> h2.side() 'right' >>> h2.side_switch().matrix() [1 1] [0 1]
- trace()[source]¶
Return the trace of this endomorphism.
EXAMPLES:
sage: # needs sage.modules sage: V = ZZ^2; phi = V.hom([V.0 + V.1, 2*V.1]) sage: phi.trace() 3 sage: W = CombinatorialFreeModule(ZZ, ['x', 'y']) sage: M = matrix(ZZ, [[1, 0], [1, 2]]) sage: psi = W.module_morphism(matrix=M, codomain=W) sage: psi.trace() 3
>>> from sage.all import * >>> # needs sage.modules >>> V = ZZ**Integer(2); phi = V.hom([V.gen(0) + V.gen(1), Integer(2)*V.gen(1)]) >>> phi.trace() 3 >>> W = CombinatorialFreeModule(ZZ, ['x', 'y']) >>> M = matrix(ZZ, [[Integer(1), Integer(0)], [Integer(1), Integer(2)]]) >>> psi = W.module_morphism(matrix=M, codomain=W) >>> psi.trace() 3
- sage.modules.matrix_morphism.is_MatrixMorphism(x)[source]¶
Return
True
if x is a Matrix morphism of free modules.This function is deprecated.
EXAMPLES:
sage: V = ZZ^2; phi = V.hom([3*V.0, 2*V.1]) sage: sage.modules.matrix_morphism.is_MatrixMorphism(phi) doctest:warning... DeprecationWarning: is_MatrixMorphism is deprecated; use isinstance(..., MatrixMorphism_abstract) or categories instead See https://github.com/sagemath/sage/issues/37731 for details. True sage: sage.modules.matrix_morphism.is_MatrixMorphism(3) False
>>> from sage.all import * >>> V = ZZ**Integer(2); phi = V.hom([Integer(3)*V.gen(0), Integer(2)*V.gen(1)]) >>> sage.modules.matrix_morphism.is_MatrixMorphism(phi) doctest:warning... DeprecationWarning: is_MatrixMorphism is deprecated; use isinstance(..., MatrixMorphism_abstract) or categories instead See https://github.com/sagemath/sage/issues/37731 for details. True >>> sage.modules.matrix_morphism.is_MatrixMorphism(Integer(3)) False