Skip to content

Commit 0cb098b

Browse files
committed
Issue #40513, #40514: Allow zero code, add intersection, and fix CI
1 parent 7e86f9e commit 0cb098b

File tree

5 files changed

+28
-36
lines changed

5 files changed

+28
-36
lines changed

src/sage/coding/databases.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,10 @@ def self_orthogonal_binary_codes(n, k, b=2, parent=None, BC=None, equal=False,
232232
[4, 1] linear code over GF(2)
233233
[1 1 1 1]
234234
[6, 2] linear code over GF(2)
235-
[1 1 1 1 0 0]
235+
[1 0 1 0 1 1]
236236
[0 1 0 1 1 1]
237237
[7, 3] linear code over GF(2)
238-
[1 0 1 1 0 1 0]
238+
[1 0 0 1 1 0 1]
239239
[0 1 0 1 1 1 0]
240240
[0 0 1 0 1 1 1]
241241
@@ -248,7 +248,7 @@ def self_orthogonal_binary_codes(n, k, b=2, parent=None, BC=None, equal=False,
248248
[4, 1] linear code over GF(2)
249249
[1 1 1 1]
250250
[6, 2] linear code over GF(2)
251-
[1 1 1 1 0 0]
251+
[1 0 1 0 1 1]
252252
[0 1 0 1 1 1]
253253
254254
Generate all self-orthogonal codes of length equal to 8 and
@@ -263,8 +263,8 @@ def self_orthogonal_binary_codes(n, k, b=2, parent=None, BC=None, equal=False,
263263
[0 0 1 0 0 1 0 0]
264264
[0 0 0 0 0 0 1 1]
265265
[8, 4] linear code over GF(2)
266-
[1 0 0 1 1 0 1 0]
267-
[0 1 0 1 1 1 0 0]
266+
[1 0 0 0 1 1 0 1]
267+
[0 1 0 0 1 0 1 1]
268268
[0 0 1 0 1 1 1 0]
269269
[0 0 0 1 0 1 1 1]
270270

src/sage/coding/decoder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def decode_to_message(self, r):
293293
sage: w_err = word + vector(GF(2), (1, 0, 0, 0, 0, 0, 0))
294294
sage: D = C.decoder()
295295
sage: D.decode_to_message(w_err)
296-
(0, 1, 1, 0)
296+
(1, 1, 0, 0)
297297
"""
298298
self.defaulting_decode_to_message = True
299299
return self.code().unencode(self.decode_to_code(r))

src/sage/coding/encoder.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def encode(self, word):
149149
sage: word = vector(GF(2), (0, 1, 1, 0))
150150
sage: E = codes.encoders.LinearCodeGeneratorMatrixEncoder(C)
151151
sage: E.encode(word)
152-
(1, 1, 0, 0, 1, 1, 0)
152+
(0, 1, 1, 0, 0, 1, 1)
153153
154154
If ``word`` is not in the message space of ``self``, it will return an exception::
155155
@@ -183,7 +183,7 @@ def __call__(self, m):
183183
sage: word = vector(GF(2), (0, 1, 1, 0))
184184
sage: E = codes.encoders.LinearCodeGeneratorMatrixEncoder(C)
185185
sage: E(word)
186-
(1, 1, 0, 0, 1, 1, 0)
186+
(0, 1, 1, 0, 0, 1, 1)
187187
188188
sage: F = GF(11)
189189
sage: Fx.<x> = F[]
@@ -224,7 +224,7 @@ def unencode(self, c, nocheck=False):
224224
True
225225
sage: E = codes.encoders.LinearCodeGeneratorMatrixEncoder(C)
226226
sage: E.unencode(c)
227-
(0, 1, 1, 0)
227+
(1, 1, 0, 0)
228228
229229
TESTS:
230230
@@ -241,11 +241,10 @@ def unencode(self, c, nocheck=False):
241241
242242
Note that since :issue:`21326`, codes cannot be of length zero::
243243
244-
sage: G = Matrix(GF(17), [])
244+
sage: G = matrix(GF(2), 0, 0)
245245
sage: C = LinearCode(G)
246-
Traceback (most recent call last):
247-
...
248-
ValueError: length must be a nonzero positive integer
246+
sage: C
247+
[0, 0] linear code over GF(2)
249248
"""
250249
if not nocheck and c not in self.code():
251250
raise EncodingError("Given word is not in the code")
@@ -268,10 +267,10 @@ def _unencoder_matrix(self):
268267
sage: E = C.encoder()
269268
sage: E._unencoder_matrix()
270269
(
271-
[0 0 1 1]
272-
[0 1 0 1]
273-
[1 1 1 0]
274-
[0 1 1 1], (0, 1, 2, 3)
270+
[1 0 0 0]
271+
[0 1 0 0]
272+
[0 0 1 0]
273+
[0 0 0 1], (0, 1, 2, 3)
275274
)
276275
"""
277276
info_set = self.code().information_set()
@@ -306,7 +305,7 @@ def unencode_nocheck(self, c):
306305
True
307306
sage: E = codes.encoders.LinearCodeGeneratorMatrixEncoder(C)
308307
sage: E.unencode_nocheck(c)
309-
(0, 1, 1, 0)
308+
(1, 1, 0, 0)
310309
311310
Taking a vector that does not belong to ``C`` will not raise an error but
312311
probably just give a non-sensical result::
@@ -316,7 +315,7 @@ def unencode_nocheck(self, c):
316315
False
317316
sage: E = codes.encoders.LinearCodeGeneratorMatrixEncoder(C)
318317
sage: E.unencode_nocheck(c)
319-
(0, 1, 1, 0)
318+
(1, 1, 0, 0)
320319
sage: m = vector(GF(2), (0, 1, 1, 0))
321320
sage: c1 = E.encode(m)
322321
sage: c == c1
@@ -375,10 +374,10 @@ def generator_matrix(self):
375374
sage: C = LinearCode(G)
376375
sage: E = C.encoder()
377376
sage: E.generator_matrix()
378-
[1 1 1 0 0 0 0]
379-
[1 0 0 1 1 0 0]
380-
[0 1 0 1 0 1 0]
381-
[1 1 0 1 0 0 1]
377+
[1 0 0 0 0 1 1]
378+
[0 1 0 0 1 0 1]
379+
[0 0 1 0 1 1 0]
380+
[0 0 0 1 1 1 1]
382381
"""
383382

384383

src/sage/coding/linear_code.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2318,11 +2318,6 @@ def __init__(self, generator, d=None):
23182318
[3, 0] linear code over GF(2)
23192319
sage: C.dimension()
23202320
0
2321-
sage: C_dual = C.dual_code()
2322-
sage: C_dual
2323-
[3, 3] linear code over GF(2)
2324-
sage: C_dual.dimension() == C_dual.length()
2325-
True
23262321
"""
23272322

23282323
from sage.matrix.constructor import matrix
@@ -2399,7 +2394,6 @@ def _latex_(self):
23992394
def intersection(self, other):
24002395
"""
24012396
Return the intersection of this linear code with another.
2402-
24032397
The intersection of two linear codes C1 and C2 is the set of all
24042398
codewords that are in both C1 and C2. It is also a linear code.
24052399
@@ -2452,7 +2446,6 @@ def generator_matrix(self, encoder_name=None, **kwargs):
24522446
Return a generator matrix of ``self``.
24532447
24542448
INPUT:
2455-
24562449
- ``encoder_name`` -- (default: ``None``) name of the encoder which will be
24572450
used to compute the generator matrix. ``self._generator_matrix``
24582451
will be returned if default value is kept.
@@ -3127,4 +3120,4 @@ def decoding_radius(self):
31273120
LinearCode._registered_encoders["GeneratorMatrix"] = LinearCodeGeneratorMatrixEncoder
31283121

31293122
LinearCodeSyndromeDecoder._decoder_type = {"hard-decision", "dynamic"}
3130-
LinearCodeNearestNeighborDecoder._decoder_type = {"hard-decision", "always-succeed", "complete"}
3123+
LinearCodeNearestNeighborDecoder._decoder_type = {"hard-decision", "always-succeed", "complete"}

src/sage/coding/linear_code_no_metric.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ def generator_matrix(self, encoder_name=None, **kwargs):
238238
sage: G = matrix(GF(3), 2, [1,-1,1,-1,1,1])
239239
sage: code = LinearCode(G)
240240
sage: code.generator_matrix()
241-
[1 2 1]
242-
[2 1 1]
241+
[1 2 0]
242+
[0 0 1]
243243
"""
244244
E = self.encoder(encoder_name, **kwargs)
245245
return E.generator_matrix()
@@ -528,8 +528,8 @@ def systematic_generator_matrix(self, systematic_positions=None):
528528
....: [ 2, 1, 1, 1]])
529529
sage: C = LinearCode(G)
530530
sage: C.generator_matrix()
531-
[1 2 1 0]
532-
[2 1 1 1]
531+
[1 2 0 1]
532+
[0 0 1 2]
533533
sage: C.systematic_generator_matrix()
534534
[1 2 0 1]
535535
[0 0 1 2]
@@ -762,7 +762,7 @@ def __getitem__(self, i):
762762
sage: G = Matrix(GF(3), [[1,1,1,0,0,0,0],[1,0,0,1,1,0,0],[0,1,0,1,0,1,0],[1,1,0,1,0,0,1]])
763763
sage: C = LinearCode(G)
764764
sage: C[24]
765-
(2, 2, 0, 1, 2, 2, 0)
765+
(0, 2, 2, 0, 0, 2, 1)
766766
sage: C[24] == C.list()[24]
767767
True
768768

0 commit comments

Comments
 (0)