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

Commit e43b5c2

Browse files
committed
merge ticket 21226 into ticket 30230
2 parents f884160 + 899d390 commit e43b5c2

File tree

3 files changed

+90
-61
lines changed

3 files changed

+90
-61
lines changed

src/sage/coding/linear_code.py

-54
Original file line numberDiff line numberDiff line change
@@ -1158,60 +1158,6 @@ def construction_x(self, other, aux):
11581158
G = left.augment(right)
11591159
return LinearCode(G)
11601160

1161-
def __eq__(self, right):
1162-
"""
1163-
Checks if ``self`` is equal to ``right``.
1164-
1165-
EXAMPLES::
1166-
1167-
sage: C1 = codes.HammingCode(GF(2), 3)
1168-
sage: C2 = codes.HammingCode(GF(2), 3)
1169-
sage: C1 == C2
1170-
True
1171-
1172-
TESTS:
1173-
1174-
We check that :trac:`16644` is fixed::
1175-
1176-
sage: C = codes.HammingCode(GF(2), 3)
1177-
sage: C == ZZ
1178-
False
1179-
"""
1180-
if not (isinstance(right, LinearCode)\
1181-
and self.length() == right.length()\
1182-
and self.dimension() == right.dimension()\
1183-
and self.base_ring() == right.base_ring()):
1184-
return False
1185-
Ks = self.parity_check_matrix().right_kernel()
1186-
rbas = right.gens()
1187-
if not all(c in Ks for c in rbas):
1188-
return False
1189-
Kr = right.parity_check_matrix().right_kernel()
1190-
sbas = self.gens()
1191-
if not all(c in Kr for c in sbas):
1192-
return False
1193-
return True
1194-
1195-
def __ne__(self, other):
1196-
r"""
1197-
Tests inequality of ``self`` and ``other``.
1198-
1199-
This is a generic implementation, which returns the inverse of ``__eq__`` for self.
1200-
1201-
EXAMPLES::
1202-
1203-
sage: G = Matrix(GF(2), [[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]])
1204-
sage: C1 = LinearCode(G)
1205-
sage: C2 = LinearCode(G)
1206-
sage: C1 != C2
1207-
False
1208-
sage: G = Matrix(GF(2), [[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,1,1]])
1209-
sage: C2 = LinearCode(G)
1210-
sage: C1 != C2
1211-
True
1212-
"""
1213-
return not self == other
1214-
12151161
def extended_code(self):
12161162
r"""
12171163
Returns `self` as an extended code.

src/sage/coding/linear_code_no_metric.py

+73-1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,22 @@ def __init__(self, base_field, length, default_encoder_name, default_decoder_nam
157157
- ``default_decoder_name`` -- the name of the default decoder of ``self``
158158
159159
- ``metric`` -- (default: ``Hamming``) the metric of ``self``
160+
161+
EXAMPLES:
162+
163+
sage: from sage.coding.linear_code_no_metric import AbstractLinearCodeNoMetric
164+
sage: from sage.coding.linear_code import LinearCodeSyndromeDecoder
165+
sage: class MyLinearCode(AbstractLinearCodeNoMetric):
166+
....: def __init__(self, field, length, dimension, generator_matrix):
167+
....: self._registered_decoders['Syndrome'] = LinearCodeSyndromeDecoder
168+
....: AbstractLinearCodeNoMetric.__init__(self, field, length, "Systematic", "Syndrome")
169+
....: self._dimension = dimension
170+
....: self._generator_matrix = generator_matrix
171+
....: def generator_matrix(self):
172+
....: return self._generator_matrix
173+
....: def _repr_(self):
174+
....: return "[%d, %d] dummy code over GF(%s)" % (self.length(), self.dimension(), self.base_field().cardinality())
175+
sage: C = MyLinearCode(GF(2), 1, 1, matrix(GF(2), [1]))
160176
"""
161177

162178
self._registered_encoders['Systematic'] = LinearCodeSystematicEncoder
@@ -227,7 +243,63 @@ def generator_matrix(self, encoder_name=None, **kwargs):
227243
return E.generator_matrix()
228244

229245
def __eq__(self, other):
230-
return self.generator_matrix() == other.generator_matrix()
246+
r"""
247+
Tests equality between two linear codes.
248+
249+
EXAMPLES::
250+
251+
sage: G = Matrix(GF(2), [[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]])
252+
sage: C1 = LinearCode(G)
253+
sage: C1 == 5
254+
False
255+
sage: C2 = LinearCode(G)
256+
sage: C1 == C2
257+
True
258+
sage: G = Matrix(GF(2), [[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,1,1]])
259+
sage: C2 = LinearCode(G)
260+
sage: C1 == C2
261+
False
262+
sage: G = Matrix(GF(3), [[1,2,1,0,0,0,0]])
263+
sage: C3 = LinearCode(G)
264+
sage: C1 == C3
265+
False
266+
"""
267+
# Fail without computing the generator matrix if possible:
268+
if not (isinstance(other, AbstractLinearCodeNoMetric)\
269+
and self.length() == other.length()\
270+
and self.dimension() == other.dimension()\
271+
and self.base_ring() == other.base_ring()):
272+
return False
273+
# Check that basis elements of `other` are all in `self.`
274+
# Since we're over a field and since the dimensions match, the codes
275+
# must be equal.
276+
# This implementation may avoid linear algebra altogether, if `self`
277+
# implements an efficient way to obtain a parity check matrix, and in
278+
# the worst case does only one system solving.
279+
for c in other.gens():
280+
if not (c in self):
281+
return False
282+
return True
283+
284+
def __ne__(self, other):
285+
r"""
286+
Tests inequality of ``self`` and ``other``.
287+
288+
This is a generic implementation, which returns the inverse of ``__eq__`` for self.
289+
290+
EXAMPLES::
291+
292+
sage: G = Matrix(GF(2), [[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]])
293+
sage: C1 = LinearCode(G)
294+
sage: C2 = LinearCode(G)
295+
sage: C1 != C2
296+
False
297+
sage: G = Matrix(GF(2), [[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,1,1]])
298+
sage: C2 = LinearCode(G)
299+
sage: C1 != C2
300+
True
301+
"""
302+
return not self == other
231303

232304
def dimension(self):
233305
r"""

src/sage/coding/linear_rank_metric.py

+17-6
Original file line numberDiff line numberDiff line change
@@ -557,10 +557,11 @@ def minimum_distance(self):
557557
558558
EXAMPLES::
559559
560-
sage: G = Matrix(GF(64), [[1,1,0], [0,0,1]])
561-
sage: C = codes.LinearRankMetricCode(G, GF(4))
560+
sage: F.<a> = GF(8)
561+
sage: G = Matrix(F, [[1,a,a^2,0]])
562+
sage: C = codes.LinearRankMetricCode(G, GF(2))
562563
sage: C.minimum_distance()
563-
1
564+
3
564565
"""
565566
d = Infinity
566567
for c in self:
@@ -859,6 +860,15 @@ def decode_to_code(self, r):
859860
OUTPUT:
860861
861862
- a vector of ``self``'s message space
863+
864+
EXAMPLES::
865+
866+
sage: F.<a> = GF(4)
867+
sage: G = Matrix(F, [[1,1,0]])
868+
sage: C = codes.LinearRankMetricCode(G, GF(2))
869+
sage: D = codes.decoders.LinearRankMetricCodeNearestNeighborDecoder(C)
870+
sage: D.decode_to_code(vector(F, [a, a, 1]))
871+
(a, a, 0)
862872
"""
863873
C = self.code()
864874
c_min = C.zero()
@@ -876,11 +886,12 @@ def decoding_radius(self):
876886
877887
EXAMPLES::
878888
879-
sage: G = Matrix(GF(64), [[1,1,0], [0,0,1]])
880-
sage: C = codes.LinearRankMetricCode(G, GF(4))
889+
sage: F.<a> = GF(8)
890+
sage: G = Matrix(F, [[1,a,a^2,0]])
891+
sage: C = codes.LinearRankMetricCode(G, GF(2))
881892
sage: D = codes.decoders.LinearRankMetricCodeNearestNeighborDecoder(C)
882893
sage: D.decoding_radius()
883-
0
894+
1
884895
"""
885896
return (self.code().minimum_distance()-1) // 2
886897

0 commit comments

Comments
 (0)