Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit 9c5405f

Browse files
author
David Lucas
committed
Fixed a bug because of which it was impossible to build a PC matrix when the subfield was the prime field
1 parent 1808bb1 commit 9c5405f

File tree

3 files changed

+57
-22
lines changed

3 files changed

+57
-22
lines changed

src/doc/en/reference/coding/index.rst

+9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Linear codes and related constructions
2929
sage/coding/hamming_code
3030
sage/coding/linear_code
3131
sage/coding/code_constructions
32+
sage/coding/subfield_subcode
3233
sage/coding/sd_codes
3334
sage/coding/guava
3435

@@ -67,3 +68,11 @@ Canonical forms
6768
sage/coding/codecan/autgroup_can_label
6869

6970
.. include:: ../footer.txt
71+
72+
Other tools
73+
-----------
74+
75+
.. toctree::
76+
:maxdepth: 1
77+
78+
sage/coding/field_embedding

src/sage/coding/field_embedding.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,12 @@ def small_field_polynomial_representation(self, b):
210210
pol = Fq.zero()
211211
s = self.small_field_power()
212212
sm = self.big_field_power()
213-
for i in range(0, sm, s):
214-
pol += Fq(vect[i:i+s])
213+
if s == 1:
214+
for i in vect:
215+
pol += i
216+
else:
217+
for i in range(0, sm, s):
218+
pol += Fq(vect[i:i+s])
215219
return pol
216220

217221
def big_field_representation(self, a):

src/sage/coding/subfield_subcode.py

+42-20
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"""
1010

1111
#*****************************************************************************
12-
# Copyright (C) 2016 David Lucas <[email protected]>
12+
# Copyright (C) 2016 David Lucas, Inria <[email protected]>
1313
#
1414
# This program is free software: you can redistribute it and/or modify
1515
# it under the terms of the GNU General Public License as published by
@@ -240,12 +240,20 @@ def parity_check_matrix(self):
240240
s = log(Fq.order(), p)
241241
m = log(Fqm.order(), p) / s
242242
H = matrix(Fq, H_original.nrows()*m, n)
243-
for i in range(H_original.nrows()):
244-
for j in range(H_original.ncols()):
245-
h = H_original[i][j]
246-
h_vect = E.small_field_vector_representation(h)
247-
for k in range(m):
248-
H[i*m + k, j] = Fq(h_vect[k*s:k*s+s])
243+
if s == 1:
244+
for i in range(H_original.nrows()):
245+
for j in range(H_original.ncols()):
246+
h = H_original[i][j]
247+
h_vect = E.small_field_vector_representation(h)
248+
for k in range(m):
249+
H[i*m+k, j] = h_vect[k]
250+
else:
251+
for i in range(H_original.nrows()):
252+
for j in range(H_original.ncols()):
253+
h = H_original[i][j]
254+
h_vect = E.small_field_vector_representation(h)
255+
for k in range(m):
256+
H[i*m + k, j] = Fq(h_vect[k*s:k*s+s])
249257
H = H.echelon_form()
250258
delete = []
251259
for i in range(H.nrows()):
@@ -279,12 +287,27 @@ class SubfieldSubcodeOriginalCodeDecoder(Decoder):
279287
280288
EXAMPLES::
281289
282-
r"""
290+
sage: C = codes.GeneralizedReedSolomonCode(GF(16, 'aa').list()[:13], 5)
291+
sage: Cs = codes.SubfieldSubcode(C, GF(4, 'a'))
292+
sage: codes.decoders.SubfieldSubcodeOriginalCodeDecoder(Cs)
293+
Decoder of Subfield subcode over Finite Field in a of size 2^2 coming from [13, 5, 9] Generalized Reed-Solomon Code over Finite Field in aa of size 2^4 through Gao decoder for [13, 5, 9] Generalized Reed-Solomon Code over Finite Field in aa of size 2^4
294+
"""
283295

284296
def __init__(self, code, original_decoder = None, **kwargs):
285297
r"""
286298
TESTS:
287299
300+
If the original decoder is not a decoder over ``code``'s original code, an error is
301+
raised::
302+
303+
sage: C = codes.GeneralizedReedSolomonCode(GF(16, 'aa').list()[:13], 5)
304+
sage: Cs = codes.SubfieldSubcode(C, GF(4, 'a'))
305+
sage: Cbis = codes.GeneralizedReedSolomonCode(GF(16, 'aa').list()[:9], 5)
306+
sage: D = Cbis.decoder()
307+
sage: codes.decoders.SubfieldSubcodeOriginalCodeDecoder(Cs, original_decoder = D)
308+
Traceback (most recent call last):
309+
...
310+
ValueError: original_decoder must have the original code as associated code
288311
"""
289312
original_code = code.original_code()
290313
if original_decoder is not None and not original_decoder.code() == code.original_code():
@@ -305,11 +328,11 @@ def _repr_(self):
305328
306329
EXAMPLES::
307330
308-
sage: C = codes.RandomLinearCode(7, 3, GF(16, 'aa'))
331+
sage: C = codes.GeneralizedReedSolomonCode(GF(16, 'aa').list()[:13], 5)
309332
sage: Cs = codes.SubfieldSubcode(C, GF(4, 'a'))
310333
sage: D = codes.decoders.SubfieldSubcodeOriginalCodeDecoder(Cs)
311334
sage: D
312-
335+
Decoder of Subfield subcode over Finite Field in a of size 2^2 coming from [13, 5, 9] Generalized Reed-Solomon Code over Finite Field in aa of size 2^4 through Gao decoder for [13, 5, 9] Generalized Reed-Solomon Code over Finite Field in aa of size 2^4
313336
"""
314337
return "Decoder of %s through %s" % (self.code(), self.original_decoder())
315338

@@ -319,13 +342,13 @@ def _latex_(self):
319342
320343
EXAMPLES::
321344
322-
sage: C = codes.RandomLinearCode(7, 3, GF(16, 'aa'))
345+
sage: C = codes.GeneralizedReedSolomonCode(GF(16, 'aa').list()[:13], 5)
323346
sage: Cs = codes.SubfieldSubcode(C, GF(4, 'a'))
324347
sage: D = codes.decoders.SubfieldSubcodeOriginalCodeDecoder(Cs)
325348
sage: latex(D)
326-
349+
\textnormal{Decoder of Subfield subcode over Finite Field in a of size 2^2 coming from [13, 5, 9] Generalized Reed-Solomon Code over Finite Field in aa of size 2^4 through } Gao decoder for [13, 5, 9] Generalized Reed-Solomon Code over Finite Field in aa of size 2^4
327350
"""
328-
return "\\textnormal{Decoder of } %s \\textnormal{ through } %s" % (self.code(), self.original_decoder())
351+
return "\\textnormal{Decoder of %s through } %s" % (self.code(), self.original_decoder())
329352

330353
def original_decoder(self):
331354
r"""
@@ -334,11 +357,11 @@ def original_decoder(self):
334357
335358
EXAMPLES::
336359
337-
sage: C = codes.RandomLinearCode(7, 3, GF(16, 'aa'))
360+
sage: C = codes.GeneralizedReedSolomonCode(GF(16, 'aa').list()[:13], 5)
338361
sage: Cs = codes.SubfieldSubcode(C, GF(4, 'a'))
339362
sage: D = codes.decoders.SubfieldSubcodeOriginalCodeDecoder(Cs)
340363
sage: D.original_decoder()
341-
Syndrome decoder for Linear code of length 7, dimension 3 over Finite Field in aa of size 16
364+
Gao decoder for [13, 5, 9] Generalized Reed-Solomon Code over Finite Field in aa of size 2^4
342365
"""
343366
return self._original_decoder
344367

@@ -353,10 +376,8 @@ def decode_to_code(self, y):
353376
sage: D = codes.decoders.SubfieldSubcodeOriginalCodeDecoder(Cs)
354377
sage: F = Cs.base_field()
355378
sage: a = F.gen()
356-
sage: c = vector(F, (a + 1, a, a + 1, 1, 1, a, 1,
357-
a + 1, 0, 0, 1, 0, a + 1))
358-
sage: y = vector(F, (a + 1, a, a + 1, a, 1, a, 0,
359-
0, 0, 0, 1, 0, 1))
379+
sage: c = vector(F, (a + 1, a, a + 1, 1, 1, a, 1, a + 1, 0, 0, 1, 0, a + 1))
380+
sage: y = vector(F, (a + 1, a, a + 1, a, 1, a, 0, 0, 0, 0, 1, 0, 1))
360381
sage: D.decode_to_code(y) == c
361382
True
362383
@@ -375,10 +396,11 @@ def decoding_radius(self):
375396
376397
EXAMPLES::
377398
378-
sage: C = codes.RandomLinearCode(7, 3, GF(16, 'aa'))
399+
sage: C = codes.GeneralizedReedSolomonCode(GF(16, 'aa').list()[:13], 5)
379400
sage: Cs = codes.SubfieldSubcode(C, GF(4, 'a'))
380401
sage: D = codes.decoders.SubfieldSubcodeOriginalCodeDecoder(Cs)
381402
sage: D.decoding_radius()
403+
4
382404
"""
383405
return self.original_decoder().decoding_radius()
384406

0 commit comments

Comments
 (0)