@@ -157,6 +157,22 @@ def __init__(self, base_field, length, default_encoder_name, default_decoder_nam
157
157
- ``default_decoder_name`` -- the name of the default decoder of ``self``
158
158
159
159
- ``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]))
160
176
"""
161
177
162
178
self ._registered_encoders ['Systematic' ] = LinearCodeSystematicEncoder
@@ -227,7 +243,63 @@ def generator_matrix(self, encoder_name=None, **kwargs):
227
243
return E .generator_matrix ()
228
244
229
245
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
231
303
232
304
def dimension (self ):
233
305
r"""
0 commit comments