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: is_MatrixMorphism(m)
True
sage: m.charpoly('x')
x^3 - 3*x^2 + 3*x - 1
sage: m.base_ring()
Rational Field
sage: m.det()
1
sage: m.fcp('x')
(x - 1)^3
sage: m.matrix()
[1 0 0]
[0 1 0]
[0 0 1]
sage: m.rank()
3
sage: m.trace()
3
AUTHOR:
A morphism defined by a matrix.
INPUT:
EXAMPLES:
sage: from sage.modules.matrix_morphism import MatrixMorphism
sage: T = End(QQ^3)
sage: M = MatrixSpace(QQ,3)
sage: I = M.identity_matrix()
sage: A = MatrixMorphism(T, I)
sage: loads(A.dumps()) == A
True
Return string representation of this morphism (this gets overloaded in the derived class).
EXAMPLES:
sage: V = ZZ^2; phi = V.hom([3*V.0, 2*V.1]) sage: phi._repr_() 'Free module morphism defined by the matrix
[3 0] [0 2] 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: sage.modules.matrix_morphism.MatrixMorphism._repr_(phi) ‘Morphism defined by the matrix
[3 0] [0 2]’
Return matrix that defines this morphism.
EXAMPLES:
sage: V = ZZ^2; phi = V.hom([3*V.0, 2*V.1])
sage: phi.matrix()
[3 0]
[0 2]
Sum of morphisms, denoted by +.
EXAMPLES:
sage: phi = (ZZ**2).endomorphism_ring()(Matrix(ZZ,2,[2..5])) ; phi
Free module morphism defined by the matrix
[2 3]
[4 5]
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: phi + 3
Free module morphism defined by the matrix
[5 3]
[4 8]
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: phi + phi
Free module morphism defined by the matrix
[ 4 6]
[ 8 10]
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 = (ZZ**3).endomorphism_ring()(Matrix(ZZ,3,[22..30])) ; psi
Free module morphism defined by the matrix
[22 23 24]
[25 26 27]
[28 29 30]
Domain: Ambient free module of rank 3 over the principal ideal domain ...
Codomain: Ambient free module of rank 3 over the principal ideal domain ...
sage: phi + psi
...
TypeError: entries has the wrong length
Evaluate this matrix morphism at an element that can be coerced into the domain.
EXAMPLES:
sage: V = QQ^3; W = QQ^2
sage: H = Hom(V, W); H
Set of Morphisms from Vector space of dimension 3 over Rational Field to Vector space of dimension 2 over Rational Field in Category of vector spaces over Rational Field
sage: phi = H(range(6)); phi
Free module morphism defined by the matrix
[0 1]
[2 3]
[4 5]
Domain: Vector space of dimension 3 over Rational Field
Codomain: Vector space of dimension 2 over Rational Field
sage: phi(V.0)
(0, 1)
sage: phi([1,2,3])
(16, 22)
sage: phi(5)
...
TypeError: 5 must be coercible into Vector space of dimension 3 over Rational Field
sage: phi([1,1])
...
TypeError: [1, 1] must be coercible into Vector space of dimension 3 over Rational Field
Compare two matrix morphisms.
EXAMPLES:
sage: V = ZZ^2; phi = V.hom([3*V.0, 2*V.1])
sage: phi == 3
False
sage: phi == phi
True
INPUT:
EXAMPLES:
sage: from sage.modules.matrix_morphism import MatrixMorphism
sage: T = End(QQ^3)
sage: M = MatrixSpace(QQ,3)
sage: I = M.identity_matrix()
sage: A = MatrixMorphism(T, I)
sage: loads(A.dumps()) == A
True
Invert this matrix morphism.
EXAMPLES:
sage: V = QQ^2; phi = V.hom([3*V.0, 2*V.1])
sage: phi^(-1)
Free module morphism defined by the matrix
[1/3 0]
[ 0 1/2]
Domain: Vector space of dimension 2 over Rational Field
Codomain: Vector space of dimension 2 over Rational Field
Check that a certain non-invertible morphism isn’t invertible:
sage: V = ZZ^2; phi = V.hom([3*V.0, 2*V.1])
sage: phi^(-1)
...
ZeroDivisionError: matrix morphism not invertible
Composition of morphisms, denoted by *.
EXAMPLES:
sage: V = ZZ^2; phi = V.hom([V.0+V.1, 2*V.1])
sage: phi*phi
Free module morphism defined by the matrix
[1 3]
[0 4]
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: V = QQ^3
sage: E = V.endomorphism_ring()
sage: phi = E(Matrix(QQ,3,range(9))) ; phi
Free module morphism defined by the matrix
[0 1 2]
[3 4 5]
[6 7 8]
Domain: Vector space of dimension 3 over Rational Field
Codomain: Vector space of dimension 3 over Rational Field
sage: phi*phi
Free module morphism defined by the matrix
[ 15 18 21]
[ 42 54 66]
[ 69 90 111]
Domain: Vector space of dimension 3 over Rational Field
Codomain: Vector space of dimension 3 over Rational Field
sage: phi.matrix()**2
[ 15 18 21]
[ 42 54 66]
[ 69 90 111]
sage: W = QQ**4
sage: E_VW = V.Hom(W)
sage: psi = E_VW(Matrix(QQ,3,4,range(12))) ; psi
Free module morphism defined by the matrix
[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]
Domain: Vector space of dimension 3 over Rational Field
Codomain: Vector space of dimension 4 over Rational Field
sage: psi*phi
Free module morphism defined by the matrix
[ 20 23 26 29]
[ 56 68 80 92]
[ 92 113 134 155]
Domain: Vector space of dimension 3 over Rational Field
Codomain: Vector space of dimension 4 over Rational Field
sage: phi*psi
...
TypeError: Incompatible composition of morphisms: domain of left morphism must be codomain of right.
sage: phi.matrix()*psi.matrix()
[ 20 23 26 29]
[ 56 68 80 92]
[ 92 113 134 155]
EXAMPLES:
sage: V = ZZ^2; phi = V.hom([V.0+V.1, 2*V.1])
sage: -phi
Free module morphism defined by the matrix
[-1 -1]
[ 0 -2]...
EXAMPLES:
sage: V = ZZ^2; phi = V.hom([V.0+V.1, 2*V.1])
sage: 2*phi
Free module morphism defined by the matrix
[2 2]
[0 4]...
sage: phi*2
Free module morphism defined by the matrix
[2 2]
[0 4]...
EXAMPLES:
sage: V = ZZ^2; phi = V.hom([V.0+V.1, 2*V.1])
sage: phi - phi
Free module morphism defined by the matrix
[0 0]
[0 0]...
Return the base ring of self, that is, the ring over which self 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
Return the characteristic polynomial of this endomorphism.
EXAMPLES:
sage: V = ZZ^2; phi = V.hom([V.0+V.1, 2*V.1])
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
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()
[
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]
]
Return the determinant of this endomorphism.
EXAMPLES:
sage: V = ZZ^2; phi = V.hom([V.0+V.1, 2*V.1])
sage: phi.det()
2
Return the factorization of the characteristic polynomial.
EXAMPLES:
sage: V = ZZ^2; phi = V.hom([V.0+V.1, 2*V.1])
sage: phi.fcp()
(x - 2) * (x - 1)
sage: phi.fcp('T')
(T - 2) * (T - 1)
Compute the image of this morphism.
EXAMPLES:
sage: V = VectorSpace(QQ,3)
sage: phi = V.Hom(V)(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, 0).image()
Vector space of degree 2 and dimension 0 over Finite Field of size 7
Basis matrix:
[]
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
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, 1).kernel()
Vector space of degree 2 and dimension 0 over Complex Field with 53 bits of precision
Basis matrix:
[]
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)
...
NotImplementedError: this method must be overridden in the extension class
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
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
Free module morphism defined by the matrix
[2]
Domain: Vector space of degree 2 and dimension 1 over Rational Field
Basis ...
Codomain: Vector space of degree 2 and dimension 1 over Rational Field
Basis ...
sage: psi.domain() == W
True
sage: psi(W.0) == 2*W.0
True
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 ...
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
Free module morphism defined 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 ...
sage: psi(V.0)
(1, 2)
sage: psi(V.1)
(2, 4)
sage: psi(V.0).parent() is X
True
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]...
EXAMPLES:
sage: V = ZZ^2; phi = V.hom([V.0+V.1, 2*V.1])
sage: phi.trace()
3
Return True if x is a Matrix morphism of free modules.
EXAMPLES:
sage: V = ZZ^2; phi = V.hom([3*V.0, 2*V.1])
sage: sage.modules.matrix_morphism.is_MatrixMorphism(phi)
True
sage: sage.modules.matrix_morphism.is_MatrixMorphism(3)
False