Ask Your Question

Revision history [back]

You should know that the bases of Y is a matroid, that is, for any base B2 of Y and any independent set B1 of Y, you can pick some elements of B2 and add them to B1 to form a new basis, and this can be done greedily.

Here is how i will do such a case:

First define the two bases B1 and B2:

sage: B1 = d1.right_kernel().basis()
sage: B1
[
(1, 0, 0, 0, 0, 0, 0, 0, 1, 1),
(0, 1, 0, 1, 0, 1, 0, 1, 0, 1),
(0, 0, 1, 1, 0, 1, 0, 1, 1, 0),
(0, 0, 0, 0, 1, 1, 0, 1, 1, 0),
(0, 0, 0, 0, 0, 0, 1, 1, 1, 0)
]
sage: B2 = d2.column_space().basis()
sage: B2
[
(1, 1, 0, 1, 1, 0, 0, 0, 0, 0),
(0, 0, 1, 1, 1, 0, 0, 0, 0, 0)
]

Note that B1 and B2 are not lists, but immutable Sequences (in particular you can not append new vectors to B2). The quick way is the following:

sage: B = list(B2)
sage: for v in B1:
....:     if v not in span(B):
....:         B.append(v)
sage: B
[(1, 1, 0, 1, 1, 0, 0, 0, 0, 0),
 (0, 0, 1, 1, 1, 0, 0, 0, 0, 0),
 (1, 0, 0, 0, 0, 0, 0, 0, 1, 1),
 (0, 1, 0, 1, 0, 1, 0, 1, 0, 1),
 (0, 0, 0, 0, 0, 0, 1, 1, 1, 0)]

Which looks correct, but it is not completely satisfactory since the vectors do not belong to the same space:

sage: for v in B: 
....:     print v.parent()
....:     
Vector space of degree 10 and dimension 2 over Finite Field of size 2
Basis matrix:
[1 1 0 1 1 0 0 0 0 0]
[0 0 1 1 1 0 0 0 0 0]
Vector space of degree 10 and dimension 2 over Finite Field of size 2
Basis matrix:
[1 1 0 1 1 0 0 0 0 0]
[0 0 1 1 1 0 0 0 0 0]
Vector space of degree 10 and dimension 5 over Finite Field of size 2
Basis matrix:
[1 0 0 0 0 0 0 0 1 1]
[0 1 0 1 0 1 0 1 0 1]
[0 0 1 1 0 1 0 1 1 0]
[0 0 0 0 1 1 0 1 1 0]
[0 0 0 0 0 0 1 1 1 0]
Vector space of degree 10 and dimension 5 over Finite Field of size 2
Basis matrix:
[1 0 0 0 0 0 0 0 1 1]
[0 1 0 1 0 1 0 1 0 1]
[0 0 1 1 0 1 0 1 1 0]
[0 0 0 0 1 1 0 1 1 0]
[0 0 0 0 0 0 1 1 1 0]
Vector space of degree 10 and dimension 5 over Finite Field of size 2
Basis matrix:
[1 0 0 0 0 0 0 0 1 1]
[0 1 0 1 0 1 0 1 0 1]
[0 0 1 1 0 1 0 1 1 0]
[0 0 0 0 1 1 0 1 1 0]
[0 0 0 0 0 0 1 1 1 0]

Also:

sage: type(B1)
<class 'sage.structure.sequence.Sequence_generic'>
sage: type(B)
<type 'list'>

This is not necessarily important for further computations, but to be cleaner (with respect to the current design), you should create an mutable sequence, transform the elements of B2 as elements of B1:

sage: B = Sequence(B2, universe = d1.right_kernel(), immutable=False, cr=True)
sage: B
[
(1, 1, 0, 1, 1, 0, 0, 0, 0, 0),
(0, 0, 1, 1, 1, 0, 0, 0, 0, 0)
]
sage: for v in B1:
....:     if v not in span(B):
....:         B.append(v)
....:         
sage: B
[
(1, 1, 0, 1, 1, 0, 0, 0, 0, 0),
(0, 0, 1, 1, 1, 0, 0, 0, 0, 0),
(1, 0, 0, 0, 0, 0, 0, 0, 1, 1),
(0, 1, 0, 1, 0, 1, 0, 1, 0, 1),
(0, 0, 0, 0, 0, 0, 1, 1, 1, 0)
]

In particular, you have the expected properties:

sage: span(B) == span(B1)
True
sage: B[0:2]
[
(1, 1, 0, 1, 1, 0, 0, 0, 0, 0),
(0, 0, 1, 1, 1, 0, 0, 0, 0, 0)
]
sage: B[0:2] == B2
True

Now you can check that B is of the same type as B1

sage: type(B)
<class 'sage.structure.sequence.Sequence_generic'>
sage: for v in B: 
....:     print v.parent()
....:     
Vector space of degree 10 and dimension 5 over Finite Field of size 2
Basis matrix:
[1 0 0 0 0 0 0 0 1 1]
[0 1 0 1 0 1 0 1 0 1]
[0 0 1 1 0 1 0 1 1 0]
[0 0 0 0 1 1 0 1 1 0]
[0 0 0 0 0 0 1 1 1 0]
Vector space of degree 10 and dimension 5 over Finite Field of size 2
Basis matrix:
[1 0 0 0 0 0 0 0 1 1]
[0 1 0 1 0 1 0 1 0 1]
[0 0 1 1 0 1 0 1 1 0]
[0 0 0 0 1 1 0 1 1 0]
[0 0 0 0 0 0 1 1 1 0]
Vector space of degree 10 and dimension 5 over Finite Field of size 2
Basis matrix:
[1 0 0 0 0 0 0 0 1 1]
[0 1 0 1 0 1 0 1 0 1]
[0 0 1 1 0 1 0 1 1 0]
[0 0 0 0 1 1 0 1 1 0]
[0 0 0 0 0 0 1 1 1 0]
Vector space of degree 10 and dimension 5 over Finite Field of size 2
Basis matrix:
[1 0 0 0 0 0 0 0 1 1]
[0 1 0 1 0 1 0 1 0 1]
[0 0 1 1 0 1 0 1 1 0]
[0 0 0 0 1 1 0 1 1 0]
[0 0 0 0 0 0 1 1 1 0]
Vector space of degree 10 and dimension 5 over Finite Field of size 2
Basis matrix:
[1 0 0 0 0 0 0 0 1 1]
[0 1 0 1 0 1 0 1 0 1]
[0 0 1 1 0 1 0 1 1 0]
[0 0 0 0 1 1 0 1 1 0]
[0 0 0 0 0 0 1 1 1 0]

You should know that the bases of Y is a matroid, that is, for any base B2 of Y and any independent set B1 of Y, you can pick some elements of B2 and add them to B1 to form a new basis, and this can be done greedily.

Here is how i will do such a case:

First define the two bases B1 and B2:

sage: B1 = d1.right_kernel().basis()
sage: B1
[
(1, 0, 0, 0, 0, 0, 0, 0, 1, 1),
(0, 1, 0, 1, 0, 1, 0, 1, 0, 1),
(0, 0, 1, 1, 0, 1, 0, 1, 1, 0),
(0, 0, 0, 0, 1, 1, 0, 1, 1, 0),
(0, 0, 0, 0, 0, 0, 1, 1, 1, 0)
]
sage: B2 = d2.column_space().basis()
sage: B2
[
(1, 1, 0, 1, 1, 0, 0, 0, 0, 0),
(0, 0, 1, 1, 1, 0, 0, 0, 0, 0)
]

Note that B1 and B2 are not lists, but immutable Sequences (in particular you can not append new vectors to B2). The quick way is the following:

sage: B = list(B2)
sage: for v in B1:
....:     if v not in span(B):
....:         B.append(v)
sage: B
[(1, 1, 0, 1, 1, 0, 0, 0, 0, 0),
 (0, 0, 1, 1, 1, 0, 0, 0, 0, 0),
 (1, 0, 0, 0, 0, 0, 0, 0, 1, 1),
 (0, 1, 0, 1, 0, 1, 0, 1, 0, 1),
 (0, 0, 0, 0, 0, 0, 1, 1, 1, 0)]

Which looks correct, but it is not completely satisfactory since the vectors do not belong to the same space:

sage: for v in B: 
....:     print v.parent()
....:     
Vector space of degree 10 and dimension 2 over Finite Field of size 2
Basis matrix:
[1 1 0 1 1 0 0 0 0 0]
[0 0 1 1 1 0 0 0 0 0]
Vector space of degree 10 and dimension 2 over Finite Field of size 2
Basis matrix:
[1 1 0 1 1 0 0 0 0 0]
[0 0 1 1 1 0 0 0 0 0]
Vector space of degree 10 and dimension 5 over Finite Field of size 2
Basis matrix:
[1 0 0 0 0 0 0 0 1 1]
[0 1 0 1 0 1 0 1 0 1]
[0 0 1 1 0 1 0 1 1 0]
[0 0 0 0 1 1 0 1 1 0]
[0 0 0 0 0 0 1 1 1 0]
Vector space of degree 10 and dimension 5 over Finite Field of size 2
Basis matrix:
[1 0 0 0 0 0 0 0 1 1]
[0 1 0 1 0 1 0 1 0 1]
[0 0 1 1 0 1 0 1 1 0]
[0 0 0 0 1 1 0 1 1 0]
[0 0 0 0 0 0 1 1 1 0]
Vector space of degree 10 and dimension 5 over Finite Field of size 2
Basis matrix:
[1 0 0 0 0 0 0 0 1 1]
[0 1 0 1 0 1 0 1 0 1]
[0 0 1 1 0 1 0 1 1 0]
[0 0 0 0 1 1 0 1 1 0]
[0 0 0 0 0 0 1 1 1 0]

Also:

sage: type(B1)
<class 'sage.structure.sequence.Sequence_generic'>
sage: type(B)
<type 'list'>

This is not necessarily important for further computations, but to be cleaner (with respect to the current design), you should create an mutable sequence, transform the elements of B2 as elements of B1:

sage: B = Sequence(B2, universe = d1.right_kernel(), immutable=False, cr=True)
sage: B
[
(1, 1, 0, 1, 1, 0, 0, 0, 0, 0),
(0, 0, 1, 1, 1, 0, 0, 0, 0, 0)
]
sage: for v in B1:
....:     if v not in span(B):
....:         B.append(v)
....:         
sage: B
[
(1, 1, 0, 1, 1, 0, 0, 0, 0, 0),
(0, 0, 1, 1, 1, 0, 0, 0, 0, 0),
(1, 0, 0, 0, 0, 0, 0, 0, 1, 1),
(0, 1, 0, 1, 0, 1, 0, 1, 0, 1),
(0, 0, 0, 0, 0, 0, 1, 1, 1, 0)
]

In particular, you have the expected properties:

sage: span(B) == span(B1)
True
sage: B[0:2]
[
(1, 1, 0, 1, 1, 0, 0, 0, 0, 0),
(0, 0, 1, 1, 1, 0, 0, 0, 0, 0)
]
len(B) == len(B1)
True
sage: B[0:2] == B2
True

Now Also, you can check that now B is of the same type as B1

sage: type(B)
<class 'sage.structure.sequence.Sequence_generic'>
sage: for v in B: 
....:     print v.parent()
....:     
Vector space of degree 10 and dimension 5 over Finite Field of size 2
Basis matrix:
[1 0 0 0 0 0 0 0 1 1]
[0 1 0 1 0 1 0 1 0 1]
[0 0 1 1 0 1 0 1 1 0]
[0 0 0 0 1 1 0 1 1 0]
[0 0 0 0 0 0 1 1 1 0]
Vector space of degree 10 and dimension 5 over Finite Field of size 2
Basis matrix:
[1 0 0 0 0 0 0 0 1 1]
[0 1 0 1 0 1 0 1 0 1]
[0 0 1 1 0 1 0 1 1 0]
[0 0 0 0 1 1 0 1 1 0]
[0 0 0 0 0 0 1 1 1 0]
Vector space of degree 10 and dimension 5 over Finite Field of size 2
Basis matrix:
[1 0 0 0 0 0 0 0 1 1]
[0 1 0 1 0 1 0 1 0 1]
[0 0 1 1 0 1 0 1 1 0]
[0 0 0 0 1 1 0 1 1 0]
[0 0 0 0 0 0 1 1 1 0]
Vector space of degree 10 and dimension 5 over Finite Field of size 2
Basis matrix:
[1 0 0 0 0 0 0 0 1 1]
[0 1 0 1 0 1 0 1 0 1]
[0 0 1 1 0 1 0 1 1 0]
[0 0 0 0 1 1 0 1 1 0]
[0 0 0 0 0 0 1 1 1 0]
Vector space of degree 10 and dimension 5 over Finite Field of size 2
Basis matrix:
[1 0 0 0 0 0 0 0 1 1]
[0 1 0 1 0 1 0 1 0 1]
[0 0 1 1 0 1 0 1 1 0]
[0 0 0 0 1 1 0 1 1 0]
[0 0 0 0 0 0 1 1 1 0]
B.universe() == B1.universe()
True

You should know that the bases of Y is a matroid, that is, for any base B2 of Y and any independent set B1 of Y, you can pick some elements of B2 and add them to B1 to form a new basis, and this can be done greedily.

Here is how i will do such a case:

First define the two bases B1 and B2:

sage: B1 = d1.right_kernel().basis()
sage: B1
[
(1, 0, 0, 0, 0, 0, 0, 0, 1, 1),
(0, 1, 0, 1, 0, 1, 0, 1, 0, 1),
(0, 0, 1, 1, 0, 1, 0, 1, 1, 0),
(0, 0, 0, 0, 1, 1, 0, 1, 1, 0),
(0, 0, 0, 0, 0, 0, 1, 1, 1, 0)
]
sage: B2 = d2.column_space().basis()
sage: B2
[
(1, 1, 0, 1, 1, 0, 0, 0, 0, 0),
(0, 0, 1, 1, 1, 0, 0, 0, 0, 0)
]

Note that B1 and B2 are not lists, but immutable Sequences (in particular you can not append new vectors to B2). The quick way is the following:

sage: B = list(B2)
sage: for v in B1:
....:     if v not in span(B):
....:         B.append(v)
sage: B
[(1, 1, 0, 1, 1, 0, 0, 0, 0, 0),
 (0, 0, 1, 1, 1, 0, 0, 0, 0, 0),
 (1, 0, 0, 0, 0, 0, 0, 0, 1, 1),
 (0, 1, 0, 1, 0, 1, 0, 1, 0, 1),
 (0, 0, 0, 0, 0, 0, 1, 1, 1, 0)]

Which looks correct, but it is not completely satisfactory since the vectors do not belong to the same space:

sage: for v in B: 
....:     print v.parent()
Vector space of degree 10 and dimension 2 over Finite Field of size 2
Basis matrix:
[1 1 0 1 1 0 0 0 0 0]
[0 0 1 1 1 0 0 0 0 0]
Vector space of degree 10 and dimension 2 over Finite Field of size 2
Basis matrix:
[1 1 0 1 1 0 0 0 0 0]
[0 0 1 1 1 0 0 0 0 0]
Vector space of degree 10 and dimension 5 over Finite Field of size 2
Basis matrix:
[1 0 0 0 0 0 0 0 1 1]
[0 1 0 1 0 1 0 1 0 1]
[0 0 1 1 0 1 0 1 1 0]
[0 0 0 0 1 1 0 1 1 0]
[0 0 0 0 0 0 1 1 1 0]
Vector space of degree 10 and dimension 5 over Finite Field of size 2
Basis matrix:
[1 0 0 0 0 0 0 0 1 1]
[0 1 0 1 0 1 0 1 0 1]
[0 0 1 1 0 1 0 1 1 0]
[0 0 0 0 1 1 0 1 1 0]
[0 0 0 0 0 0 1 1 1 0]
Vector space of degree 10 and dimension 5 over Finite Field of size 2
Basis matrix:
[1 0 0 0 0 0 0 0 1 1]
[0 1 0 1 0 1 0 1 0 1]
[0 0 1 1 0 1 0 1 1 0]
[0 0 0 0 1 1 0 1 1 0]
[0 0 0 0 0 0 1 1 1 0]

Also:

sage: type(B1)
<class 'sage.structure.sequence.Sequence_generic'>
sage: type(B)
<type 'list'>

This is not necessarily important for further computations, but to be cleaner (with respect to the current design), you should create an a mutable sequence, transform the elements of B2 as elements of B1:

sage: B = Sequence(B2, universe = d1.right_kernel(), immutable=False, cr=True)
sage: B
[
(1, 1, 0, 1, 1, 0, 0, 0, 0, 0),
(0, 0, 1, 1, 1, 0, 0, 0, 0, 0)
]
sage: for v in B1:
....:     if v not in span(B):
....:         B.append(v)
sage: B
[
(1, 1, 0, 1, 1, 0, 0, 0, 0, 0),
(0, 0, 1, 1, 1, 0, 0, 0, 0, 0),
(1, 0, 0, 0, 0, 0, 0, 0, 1, 1),
(0, 1, 0, 1, 0, 1, 0, 1, 0, 1),
(0, 0, 0, 0, 0, 0, 1, 1, 1, 0)
]

In particular, you have the expected properties:

sage: span(B) == span(B1)
True
sage: len(B) == len(B1)
True
sage: B[0:2] == B2
True

Also, you can check that now B is of the same type as B1

sage: type(B)
<class 'sage.structure.sequence.Sequence_generic'>
sage: B.universe() == B1.universe()
True