Skip to content

Commit

Permalink
add of the function rank_support_of_vector
Browse files Browse the repository at this point in the history
  • Loading branch information
camille-garnier committed Feb 13, 2025
1 parent 766c7a0 commit a052a1f
Showing 1 changed file with 86 additions and 18 deletions.
104 changes: 86 additions & 18 deletions src/sage/coding/linear_rank_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
AUTHORS:
- Marketa Slukova (2019-08-16): initial version
- Camille Garnier and Rubén Muñoz--Bertrand (2024-02-13): added rank_support_of_vector, and corrected the documentation
TESTS::
Expand Down Expand Up @@ -146,9 +147,9 @@ def to_matrix_representation(v, sub_field=None, basis=None):
specified, it is the prime subfield `\GF{p}` of `\GF{q^m}`
- ``basis`` -- (default: ``None``) a basis of `\GF{q^m}` as a vector space over
``sub_field``. If not specified, given that `q = p^s`, let
`1,\beta,\ldots,\beta^{sm}` be the power basis that SageMath uses to
represent `\GF{q^m}`. The default basis is then `1,\beta,\ldots,\beta^{m-1}`.
``sub_field``. If not specified, given that `q = p^s`, let `\beta` be a generator
of the multiplicative group of `\GF{q^m}`.
The default basis is then `1,\beta,\ldots,\beta^{m-1}`.
EXAMPLES::
Expand Down Expand Up @@ -198,9 +199,9 @@ def from_matrix_representation(w, base_field=None, basis=None):
``w``.
- ``basis`` -- (default: ``None``) a basis of `\GF{q^m}` as a vector space over
`\GF{q}`. If not specified, given that `q = p^s`, let
`1,\beta,\ldots,\beta^{sm}` be the power basis that SageMath uses to
represent `\GF{q^m}`. The default basis is then `1,\beta,\ldots,\beta^{m-1}`.
`\GF{q}`. If not specified, given that `q = p^s`, let `\beta` be a generator
of the multiplicative group of `\GF{q^m}`.
The default basis is then `1,\beta,\ldots,\beta^{m-1}`.
EXAMPLES::
Expand Down Expand Up @@ -230,7 +231,7 @@ def rank_weight(c, sub_field=None, basis=None):
Return the rank of ``c`` as a matrix over ``sub_field``.
If ``c`` is a vector over some field `\GF{q^m}`, the function converts it
into a matrix over `\GF{q}`.
into a matrix over ``sub_field```.
INPUT:
Expand All @@ -241,8 +242,8 @@ def rank_weight(c, sub_field=None, basis=None):
- ``basis`` -- (default: ``None``) a basis of `\GF{q^m}` as a vector space over
``sub_field``. If not specified, given that `q = p^s`, let
`1,\beta,\ldots,\beta^{sm}` be the power basis that SageMath uses to
represent `\GF{q^m}`. The default basis is then `1,\beta,\ldots,\beta^{m-1}`.
`1,\beta,\ldots,\beta^{sm-1}` be the basis that SageMath uses to
represent `\GF{q^m}`. The default basis is then `1,\beta,\ldots,\beta^{m-1}`
EXAMPLES::
Expand Down Expand Up @@ -278,9 +279,9 @@ def rank_distance(a, b, sub_field=None, basis=None):
specified, it is the prime subfield `\GF{p}` of `\GF{q^m}`
- ``basis`` -- (default: ``None``) a basis of `\GF{q^m}` as a vector space over
``sub_field``. If not specified, given that `q = p^s`, let
`1,\beta,\ldots,\beta^{sm}` be the power basis that SageMath uses to
represent `\GF{q^m}`. The default basis is then `1,\beta,\ldots,\beta^{m-1}`.
``sub_field``. If not specified, given that `q = p^s`, let `\beta` be a generator
of the multiplicative group of `\GF{q^m}`.
The default basis is then `1,\beta,\ldots,\beta^{m-1}`.
EXAMPLES::
Expand Down Expand Up @@ -379,9 +380,9 @@ def __init__(self, base_field, sub_field, length, default_encoder_name,
- ``default_decoder_name`` -- the name of the default decoder of ``self``
- ``basis`` -- (default: ``None``) a basis of `\GF{q^m}` as a vector space over
``sub_field``. If not specified, given that `q = p^s`, let
`1,\beta,\ldots,\beta^{sm}` be the power basis that SageMath uses to
represent `\GF{q^m}`. The default basis is then `1,\beta,\ldots,\beta^{m-1}`.
``sub_field``. If not specified, given that `q = p^s`, let `\beta` be a generator
of the multiplicative group of `\GF{q^m}`.
The default basis is then `1,\beta,\ldots,\beta^{m-1}`.
EXAMPLES:
Expand Down Expand Up @@ -587,6 +588,73 @@ def rank_weight_of_vector(self, word):
2
"""
return rank_weight(word, self.sub_field())

def rank_support_of_vector(self, word, sub_field=None, basis=None):
r"""
Return the rank support of ``word`` over ``sub_field``, i.e. the vector space over
``sub_field`` generated by its coefficients.
If ``word`` is a vector over some field `\GF{q^m}`, and ``sub_field`` is a subfield of
`\GF{q^m}`, the function converts it into a matrix over ``sub_field``, with
respect to the basis ``basis``.
INPUT:
- ``word`` -- a vector over the ``base_field`` of ``self``
- ``sub_field`` -- (default: ``None``) a sub field of the ``base_field`` of ``self``; if not
specified, it is the prime subfield `\GF{p}` of the ``base_field`` of ``self``
- ``basis`` -- (default: ``None``) a basis of ``base_field`` of ``self`` as a vector space over
``sub_field``.
If not specified, given that `q = p^s`, let `\beta` be a generator of the multiplicative group
of `\GF{q^m}`. The default basis is then `1,\beta,\ldots,\beta^{m-1}`.
EXAMPLES::
sage: G = Matrix(GF(64), [[1,1,0], [0,0,1]])
sage: C = codes.LinearRankMetricCode(G, GF(4))
sage: a = GF(64).gen()
sage: c = vector([a^4 + a^3 + 1, a^4 + a^3 + 1, a^4 + a^3 + a^2 + 1])
sage: c in C
True
sage: C.rank_support_of_vector(c)
Vector space of degree 6 and dimension 2 over Finite Field of size 2
Basis matrix:
[1 0 0 1 1 0]
[0 0 1 0 0 0]
An example with a non canonical basis::
sage: K.<a> = GF(2^3)
sage: G = Matrix(K, [[1,1,0], [0,0,1]])
sage: C = codes.LinearRankMetricCode(G)
sage: c = vector([a^2, a^2, 0])
sage: basis = [a, a+1, a^2]
sage: C.rank_support_of_vector(c, basis=basis)
Vector space of degree 3 and dimension 1 over Finite Field of size 2
Basis matrix:
[0 0 1]
TESTS::
sage: C.rank_support_of_vector(a)
Traceback (most recent call last):
...
TypeError: input must be a vector
sage: C.rank_support_of_vector(c, GF(2^4))
Traceback (most recent call last):
...
TypeError: the input subfield Finite Field in z4 of size 2^4 is not a subfield of Finite Field in a of size 2^3
"""
if not isinstance(word, Vector):
raise TypeError("input must be a vector")
if sub_field != None:

Check failure on line 654 in src/sage/coding/linear_rank_metric.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (E711)

sage/coding/linear_rank_metric.py:654:25: E711 Comparison to `None` should be `cond is not None`
if self.base_field().degree() % sub_field.degree() != 0:
raise TypeError(f"the input subfield {sub_field} is not a subfield of {self.base_field()}")
return to_matrix_representation(word, sub_field, basis).column_module()

def matrix_form_of_vector(self, word):
r"""
Expand Down Expand Up @@ -679,9 +747,9 @@ def __init__(self, generator, sub_field=None, basis=None):
specified, it is the prime field of ``base_field``
- ``basis`` -- (default: ``None``) a basis of `\GF{q^m}` as a vector space over
``sub_field``. If not specified, given that `q = p^s`, let
`1,\beta,\ldots,\beta^{sm}` be the power basis that SageMath uses to
represent `\GF{q^m}`. The default basis is then `1,\beta,\ldots,\beta^{m-1}`.
``sub_field``. If not specified, given that `q = p^s`, let `\beta` be a generator
of the multiplicative group of `\GF{q^m}`.
The default basis is then `1,\beta,\ldots,\beta^{m-1}`.
EXAMPLES::
Expand Down

0 comments on commit a052a1f

Please sign in to comment.