Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in free module homomorphism creation #5886

Closed
williamstein opened this issue Apr 24, 2009 · 5 comments
Closed

Bug in free module homomorphism creation #5886

williamstein opened this issue Apr 24, 2009 · 5 comments

Comments

@williamstein
Copy link
Contributor

Consider the following

sage: V = (QQ^3).span_of_basis([[1,1,0],[1,0,2]]); V
Vector space of degree 3 and dimension 2 over Rational Field
User basis matrix:
[1 1 0]
[1 0 2]
sage: V.hom([V.0, V.1])
Traceback (most recent call last):
...
TypeError: entries has the wrong length

The hom command above should create the identity morphism, since according to the docs hom takes as input a list of the images of the generators. Instead, what is happening is that the list is being turned into a matrix directly. Conclusion, the above just goes boom, since the matrix would have to be 2x2, as V has rank 2. E.g., this works:

sage: V.hom([[1,2],[3,4]], V)
Free module morphism defined by the matrix
[1 2]
[3 4]
Domain: Vector space of degree 3 and dimension 2 over Rational Field
User ...
Codomain: Vector space of degree 3 and dimension 2 over Rational Field
User ...

The really scary thing is that this broken code will accidentally and silently give totally wrong answers in some cases, e.g.,

sage: V = (QQ^2).span_of_basis([[1,2],[3,4]])
sage: I = V.hom([V.0,V.1]); I
Free module morphism defined by the matrix
[1 2]
[3 4]
Domain: Vector space of degree 2 and dimension 2 over Rational Field
User ...
Codomain: Vector space of degree 2 and dimension 2 over Rational Field
User ...
sage: I(V.0)
(7, 10)
sage: V.0
(1, 2)

Notice above that I should be the identity map, but it's most certainly not -- it's the map defined by the matrix [[1,2],[3,4]].

Component: linear algebra

Issue created by migration from https://trac.sagemath.org/ticket/5886

@robertwb
Copy link
Contributor

comment:2

Attachment: trac_5886.patch.gz

It looks good. I'm having trouble running any doctests (applied to a pre-3.4.1 branch after upgrading) but the examples I tried manually work.

@robertwb robertwb changed the title Bug in free module homomorphism creation [positive review pending no doctest breakage] Bug in free module homomorphism creation Apr 24, 2009
@williamstein
Copy link
Contributor Author

comment:3

No doctests break :-)

Seriously, I did apply this patch to a clean 3.4.1 build on sage.math, run --long doctests, and got no failures.

@williamstein williamstein changed the title [positive review pending no doctest breakage] Bug in free module homomorphism creation Bug in free module homomorphism creation Apr 24, 2009
@robertwb
Copy link
Contributor

comment:5

Good.

@sagetrac-mabshoff
Copy link
Mannequin

sagetrac-mabshoff mannequin commented Apr 24, 2009

comment:6

I can confirm William's observation: no doctest breakage with -long in my 3.4.2.alpha0 merge tree.

Cheers,

Michael

@sagetrac-mabshoff
Copy link
Mannequin

sagetrac-mabshoff mannequin commented Apr 24, 2009

comment:7

Merged in Sage 3.4.2.alpha0.

Cheers,

Michael

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants