# Coordinates in a free submodule

I am working with free ℤ-modules that are presented a submodules of ℤ^n, for example:

A = Matrix([[1, 1, 1]])
V = A.right_kernel()


When creating this ℤ-module Sage computes a basis (in this case [(1, 0, -1), (0, 1, -1)]).

I can also create elements of V as follows :

v = V([2, -1, -1])


but then I could not find a way to get the coordinates of v in the basis of V.

Is there a function somewhere in Sage that does this?

edit retag close merge delete

Sort by » oldest newest most voted

Using dot-tab exploration on v and on V reveals a solution.

Maybe slightly surprisingly at first, one can ask V for the coordinates of v.

Let us replay the whole sequence.

Define a matrix, compute its kernel, display it.

sage: A = Matrix([[1, 1, 1]])
sage: V = A.right_kernel()
sage: V
Free module of degree 3 and rank 2 over Integer Ring
Echelon basis matrix:
[ 1  0 -1]
[ 0  1 -1]


Create a vector as an element of the kernel.

sage: v = V([2, -1, -1])
sage: v
(2, -1, -1)
sage: v in V
True


Try typing v. then hitting the TAB key. Same with V. and TAB key.

There are promising methods coordinates and coordinate_vector for V.

One gives the coordinates as a list:

sage: V.coordinates(v)
[2, -1]


The other one gives the coordinates as a vector:

sage: V.coordinate_vector(v)
(2, -1)


Check the result with the linear_combination_of_basis method:

sage: V.linear_combination_of_basis((2, -1))
(2, -1, -1)

more

Thank you Samuel! (I tried the dot method but with v. and not V, so it goes).

( 2020-12-16 19:41:44 +0200 )edit

It might be worth improving Sage by adding an element method in addition to the parent method, so that one could do v.something(V) and not only V.something(V).

( 2020-12-16 21:19:00 +0200 )edit