Opened 10 years ago

Closed 10 years ago

## #11553 closed enhancement (fixed)

Reported by: Owned by: rbeezer jason, was minor sage-4.7.2 linear algebra sd32 bijective identity inverse SimonKing, mmarco sage-4.7.2.alpha3 Rob Beezer Martin Raum N/A #11552 #10793

Adds three methods to the matrix morphism class:

1. is_bijective()
2. is_identity()
3. inverse()

I did not notice that __invert__ via ~ was available by using tab-completion, which should explain the last one.

If there is a theme, it is better support for compositions of these morphisms.

Depends

1. #11552

Apply:

### comment:1 Changed 10 years ago by rbeezer

• Authors set to Rob Beezer
• Dependencies set to #11552
• Description modified (diff)
• Status changed from new to needs_review

### comment:2 Changed 10 years ago by mmarco

The surjectivity test doesn't work fine over other euclidian domains:

sage: R=PolynomialRing(QQ,'x')
sage: A=FreeModule(R,2)
sage: B=FreeModule(R,2)
sage: H=A.hom([B([x^2-1,1]),B([x^2,1])])
sage: H
Free module morphism defined by the matrix
[x^2 - 1       1]
[    x^2       1]
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: 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()
False
sage: H.is_injective()
True
sage: H.inverse()
Free module morphism defined by the matrix
[      -1        1]
[     x^2 -x^2 + 1]
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: H.is_identity()
False

But

sage: F=A.hom([B([x^2-1,1]),B([-x^2,-1])])
sage: F.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: F.is_surjective()
True
sage: F.is
sage: F.is_identity()
False

I think the problem is in ticket 11552, it still needs work.

### comment:3 Changed 10 years ago by rbeezer

Strikes me there is a more general problem with free module equality, which I will ask about on sage-devel:

sage: R = PolynomialRing(QQ, 'a')
sage: x = vector(R, [1, 0])
sage: y = vector(R, [0, 1])
sage: z = vector(R, [0,-1])
sage: A = (R^2).span([x, y])
sage: B = (R^2).span([x, z])
sage: A == B
False
sage: A.is_submodule(B)
True
sage: B.is_submodule(A)
True

which at its root might be

sage: S = matrix([x, y])
sage: S._echelon_form_PID()[1]
[1 0]
[0 1]
sage: T = matrix([x, z])
sage: T._echelon_form_PID()[1]
[ 1  0]
[ 0 -1]

### comment:4 Changed 10 years ago by rbeezer

See #11579 for an isolation of the problem above. Surjectivity will be fixed on #11552.

### comment:5 Changed 10 years ago by rbeezer

• Description modified (diff)

v2 patch adds a nullity() method for matrix morphisms, as a companion to the rank() method.

### comment:6 Changed 10 years ago by rbeezer

• Description modified (diff)

v3 patch makes is_identity() more robust, adds is_zero() and a test to see if two matrix morphisms are equal as functions, not just that they have the same representation.

A few methods are relocated within the file, as well, to group things more logically.

### comment:7 Changed 10 years ago by mraum

• Description modified (diff)
• Reviewers set to Martin Raum

I made some very minor changes to how to access the associated matrices. Also I added a one line documentation to the trace method. Please have a look at this and if every thing is OK, you can give it a positive review.

### comment:8 Changed 10 years ago by rbeezer

• Status changed from needs_review to positive_review

Martin,

Thanks for the improvements. The changes in the review patch look good to me, and pass tests in sage/modules, sage/matrix. So, as suggested, I've set this to positive review.

Rob

### comment:9 Changed 10 years ago by jdemeyer

• Dependencies changed from #11552 to #11552, #10793
• Status changed from positive_review to needs_work

This should be rebased to #10793 because of doctest failures:

sage -t  -force_lib devel/sage/sage/modules/matrix_morphism.py
**********************************************************************
File "/mnt/usb1/scratch/jdemeyer/merger/sage-4.7.2.alpha2/devel/sage-main/sage/modules/matrix_morphism.py", line 826:
sage: phi = V1.hom(m, V2)
Exception raised:
Traceback (most recent call last):
File "/mnt/usb1/scratch/jdemeyer/merger/sage-4.7.2.alpha2/local/bin/ncadoctest.py", line 1231, in run_one_test
self.run_one_example(test, example, filename, compileflags)
File "/mnt/usb1/scratch/jdemeyer/merger/sage-4.7.2.alpha2/local/bin/sagedoctest.py", line 38, in run_one_example
OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags)
File "/mnt/usb1/scratch/jdemeyer/merger/sage-4.7.2.alpha2/local/bin/ncadoctest.py", line 1172, in run_one_example
compileflags, 1) in test.globs
File "<doctest __main__.example_26[5]>", line 1, in <module>
phi = V1.hom(m, V2)###line 826:
sage: phi = V1.hom(m, V2)
File "parent_gens.pyx", line 471, in sage.structure.parent_gens.ParentWithGens.hom (sage/structure/parent_gens.c:3949)
File "/mnt/usb1/scratch/jdemeyer/merger/sage-4.7.2.alpha2/local/lib/python/site-packages/sage/modules/free_module_homspace.py", line 163, in __call__
return free_module_morphism.FreeModuleMorphism(self, A)
File "/mnt/usb1/scratch/jdemeyer/merger/sage-4.7.2.alpha2/local/lib/python/site-packages/sage/modules/free_module_morphism.py", line 83, in __init__
A = parent._matrix_space()(A)
File "/mnt/usb1/scratch/jdemeyer/merger/sage-4.7.2.alpha2/local/lib/python/site-packages/sage/matrix/matrix_space.py", line 451, in __call__
return self.matrix(entries, copy=copy, coerce=coerce, rows=rows)
File "/mnt/usb1/scratch/jdemeyer/merger/sage-4.7.2.alpha2/local/lib/python/site-packages/sage/matrix/matrix_space.py", line 1221, in matrix
"a matrix in %s!" % (x.parent(), self))
ValueError: a matrix from Full MatrixSpace of 3 by 2 dense matrices over Rational Field cannot be converted to a matrix in Full MatrixSpace of 2 by 3 dense matrices over Rational Field!
**********************************************************************

### Changed 10 years ago by rbeezer

Rebase of v3 patch

### Changed 10 years ago by rbeezer

Doctest matrix transposes

### comment:10 Changed 10 years ago by rbeezer

• Description modified (diff)
• Status changed from needs_work to needs_review

4.7.2.alpha1 + #11552 + #10793

Rebased main patch to make v4 patch. This was a trivial change.

Got bit by the nasty bug that is fixed in #10793, so two doctests needed to have their matrix dimensions reversed (maybe not really transposes per se). This minor change to the code is on the "doctests" patch and should require a (simple) review.

### comment:11 Changed 10 years ago by mraum

• Status changed from needs_review to positive_review

I tested this on alpha2, which has #11552 and #10793 applied. No problem with this. In particular, the small changes to the doctests are all right.

### comment:13 Changed 10 years ago by leif

• Description modified (diff)
• Keywords bijective identity inverse added

### comment:14 Changed 10 years ago by rbeezer

• Description modified (diff)

"review-v2" patch is a trivial rebase to eliminate a fuzz warning. I'm going to presume this does not need a change in review status.

### comment:15 Changed 10 years ago by leif

• Dependencies changed from #11552, #10793 to #11552 #10793
• Merged in set to sage-4.7.2.alpha3
• Resolution set to fixed
• Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.