Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/sage/coding/abstract_code.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# sage.doctest: optional - sage.modules sage.rings.finite_rings
# sage.doctest: needs sage.modules sage.rings.finite_rings
r"""
Codes

Expand Down
2 changes: 1 addition & 1 deletion src/sage/coding/ag_code.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# sage.doctest: optional - sage.rings.finite_rings sage.schemes
# sage.doctest: needs sage.rings.finite_rings sage.schemes
"""
AG codes

Expand Down
2 changes: 1 addition & 1 deletion src/sage/coding/ag_code_decoders.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# sage.doctest: optional - sage.rings.finite_rings sage.schemes
# sage.doctest: needs sage.rings.finite_rings sage.schemes
r"""
Decoders for AG codes

Expand Down
2 changes: 1 addition & 1 deletion src/sage/coding/bch_code.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# sage.doctest: optional - sage.modules sage.rings.finite_rings
# sage.doctest: needs sage.modules sage.rings.finite_rings
r"""
BCH code

Expand Down
4 changes: 3 additions & 1 deletion src/sage/coding/binary_code.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# sage.doctest: optional - sage.modules sage.rings.finite_rings
# sage.doctest: needs sage.modules sage.rings.finite_rings
r"""
Optimized low-level binary code representation

Expand Down Expand Up @@ -899,6 +899,7 @@ cdef class BinaryCode:

EXAMPLES::

sage: # needs sage.graphs
sage: import sage.coding.binary_code
sage: from sage.coding.binary_code import *
sage: M = Matrix(GF(2), [[1,1,1,1]])
Expand Down Expand Up @@ -3977,6 +3978,7 @@ cdef class BinaryCodeClassifier:

MORE EXAMPLES::

sage: # needs sage.groups
sage: soc_iter = codes.databases.self_orthogonal_binary_codes(12, 6, 4)
sage: L = list(soc_iter)
sage: for n in range(13):
Expand Down
2 changes: 1 addition & 1 deletion src/sage/coding/channel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# sage.doctest: optional - sage.modules sage.rings.finite_rings
# sage.doctest: needs sage.modules sage.rings.finite_rings
r"""
Channels

Expand Down
64 changes: 34 additions & 30 deletions src/sage/coding/code_bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def _check_n_q_d(n, q, d, field_based=True):

TESTS::

sage: # needs sage.libs.pari
sage: from sage.coding.code_bounds import _check_n_q_d
sage: _check_n_q_d(20, 16, 5)
True
Expand Down Expand Up @@ -251,26 +252,26 @@ def codesize_upper_bound(n, d, q, algorithm=None):

EXAMPLES::

sage: codes.bounds.codesize_upper_bound(10,3,2)
sage: codes.bounds.codesize_upper_bound(10, 3, 2)
93
sage: codes.bounds.codesize_upper_bound(24,8,2,algorithm="LP")
sage: codes.bounds.codesize_upper_bound(24, 8, 2, algorithm="LP") # needs sage.numerical.mip
4096
sage: codes.bounds.codesize_upper_bound(10,3,2,algorithm="gap") # optional - gap_package_guava
sage: codes.bounds.codesize_upper_bound(10, 3, 2, algorithm="gap") # optional - gap_package_guava
85
sage: codes.bounds.codesize_upper_bound(11,3,4,algorithm=None)
sage: codes.bounds.codesize_upper_bound(11, 3, 4, algorithm=None) # needs sage.symbolic
123361
sage: codes.bounds.codesize_upper_bound(11,3,4,algorithm="gap") # optional - gap_package_guava
sage: codes.bounds.codesize_upper_bound(11, 3, 4, algorithm="gap") # optional - gap_package_guava
123361
sage: codes.bounds.codesize_upper_bound(11,3,4,algorithm="LP")
sage: codes.bounds.codesize_upper_bound(11, 3, 4, algorithm="LP") # needs sage.numerical.mip
109226

TESTS:

Make sure :issue:`22961` is fixed::

sage: codes.bounds.codesize_upper_bound(19,10,2)
sage: codes.bounds.codesize_upper_bound(19, 10, 2)
20
sage: codes.bounds.codesize_upper_bound(19,10,2,algorithm="gap") # optional - gap_package_guava
sage: codes.bounds.codesize_upper_bound(19, 10, 2, algorithm="gap") # optional - gap_package_guava
20

Meaningless parameters are rejected::
Expand Down Expand Up @@ -308,18 +309,18 @@ def dimension_upper_bound(n, d, q, algorithm=None):

EXAMPLES::

sage: codes.bounds.dimension_upper_bound(10,3,2)
sage: codes.bounds.dimension_upper_bound(10,3,2) # needs sage.libs.pari sage.symbolic
6
sage: codes.bounds.dimension_upper_bound(30,15,4)
sage: codes.bounds.dimension_upper_bound(30,15,4) # needs sage.libs.pari sage.symbolic
13
sage: codes.bounds.dimension_upper_bound(30,15,4,algorithm="LP")
sage: codes.bounds.dimension_upper_bound(30,15,4,algorithm="LP") # needs sage.libs.pari sage.numerical.mip
12

TESTS:

Meaningless code parameters are rejected::

sage: codes.bounds.dimension_upper_bound(13,3,6)
sage: codes.bounds.dimension_upper_bound(13,3,6) # needs sage.libs.pari
Traceback (most recent call last):
...
ValueError: The alphabet size does not make sense for a code over a field
Expand Down Expand Up @@ -421,23 +422,23 @@ def griesmer_upper_bound(n,q,d,algorithm=None):

The bound is reached for the ternary Golay codes::

sage: codes.bounds.griesmer_upper_bound(12,3,6)
sage: codes.bounds.griesmer_upper_bound(12,3,6) # needs sage.libs.pari
729
sage: codes.bounds.griesmer_upper_bound(11,3,5)
sage: codes.bounds.griesmer_upper_bound(11,3,5) # needs sage.libs.pari
729

::

sage: codes.bounds.griesmer_upper_bound(10,2,3)
sage: codes.bounds.griesmer_upper_bound(10,2,3) # needs sage.libs.pari
128
sage: codes.bounds.griesmer_upper_bound(10,2,3,algorithm="gap") # optional - gap_package_guava
sage: codes.bounds.griesmer_upper_bound(10,2,3,algorithm="gap") # optional - gap_package_guava, needs sage.libs.pari
128

TESTS::

sage: codes.bounds.griesmer_upper_bound(11,3,6)
sage: codes.bounds.griesmer_upper_bound(11,3,6) # needs sage.libs.pari
243
sage: codes.bounds.griesmer_upper_bound(11,3,6)
sage: codes.bounds.griesmer_upper_bound(11,3,6) # needs sage.libs.pari
243
"""
_check_n_q_d(n, q, d)
Expand All @@ -448,7 +449,7 @@ def griesmer_upper_bound(n,q,d,algorithm=None):
else:
# To compute the bound, we keep summing up the terms on the RHS
# until we start violating the inequality.
from sage.functions.other import ceil
from sage.arith.misc import integer_ceil as ceil
den = 1
s = 0
k = 0
Expand Down Expand Up @@ -570,7 +571,7 @@ def gv_info_rate(n, delta, q):

EXAMPLES::

sage: RDF(codes.bounds.gv_info_rate(100,1/4,3)) # abs tol 1e-15
sage: RDF(codes.bounds.gv_info_rate(100,1/4,3)) # abs tol 1e-15 # needs sage.libs.pari sage.symbolic
0.36704992608261894
"""
q = ZZ(q)
Expand All @@ -592,9 +593,9 @@ def entropy(x, q=2):

sage: codes.bounds.entropy(0, 2)
0
sage: codes.bounds.entropy(1/5,4).factor() # optional - sage.symbolic
sage: codes.bounds.entropy(1/5,4).factor() # needs sage.symbolic
1/10*(log(3) - 4*log(4/5) - log(1/5))/log(2)
sage: codes.bounds.entropy(1, 3) # optional - sage.symbolic
sage: codes.bounds.entropy(1, 3) # needs sage.symbolic
log(2)/log(3)

Check that values not within the limits are properly handled::
Expand Down Expand Up @@ -641,8 +642,9 @@ def entropy_inverse(x, q=2):

EXAMPLES::

sage: # needs sage.symbolic
sage: from sage.coding.code_bounds import entropy_inverse
sage: entropy_inverse(0.1)
sage: entropy_inverse(0.1) # needs scipy
0.012986862055...
sage: entropy_inverse(1)
1/2
Expand Down Expand Up @@ -678,10 +680,11 @@ def gv_bound_asymp(delta, q):

EXAMPLES::

sage: RDF(codes.bounds.gv_bound_asymp(1/4,2))
sage: # needs sage.symbolic
sage: RDF(codes.bounds.gv_bound_asymp(1/4,2)) # needs sage.libs.pari
0.18872187554086...
sage: f = lambda x: codes.bounds.gv_bound_asymp(x,2)
sage: plot(f,0,1)
sage: plot(f,0,1) # needs sage.libs.pari sage.plot
Graphics object consisting of 1 graphics primitive
"""
return 1 - entropy(delta, q)
Expand All @@ -693,10 +696,11 @@ def hamming_bound_asymp(delta, q):

EXAMPLES::

sage: RDF(codes.bounds.hamming_bound_asymp(1/4,2))
sage: # needs sage.symbolic
sage: RDF(codes.bounds.hamming_bound_asymp(1/4,2)) # needs sage.libs.pari
0.456435556800...
sage: f = lambda x: codes.bounds.hamming_bound_asymp(x,2)
sage: plot(f,0,1)
sage: plot(f,0,1) # needs sage.libs.pari sage.plot
Graphics object consisting of 1 graphics primitive
"""
return 1 - entropy(delta / 2, q)
Expand All @@ -711,7 +715,7 @@ def singleton_bound_asymp(delta, q):
sage: codes.bounds.singleton_bound_asymp(1/4,2)
3/4
sage: f = lambda x: codes.bounds.singleton_bound_asymp(x,2)
sage: plot(f,0,1)
sage: plot(f,0,1) # needs sage.plot
Graphics object consisting of 1 graphics primitive
"""
return 1 - delta
Expand Down Expand Up @@ -740,7 +744,7 @@ def elias_bound_asymp(delta, q):

EXAMPLES::

sage: codes.bounds.elias_bound_asymp(1/4,2)
sage: codes.bounds.elias_bound_asymp(1/4,2) # needs sage.symbolic
0.39912396330...
"""
r = 1 - 1 / q
Expand All @@ -755,7 +759,7 @@ def mrrw1_bound_asymp(delta, q):

EXAMPLES::

sage: codes.bounds.mrrw1_bound_asymp(1/4,2) # abs tol 4e-16
sage: codes.bounds.mrrw1_bound_asymp(1/4,2) # abs tol 4e-16 # needs sage.symbolic
0.3545789026652697
"""
return RDF(entropy((q-1-delta*(q-2)-2*sqrt((q-1)*delta*(1-delta)))/q,q))
50 changes: 26 additions & 24 deletions src/sage/coding/code_constructions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# sage.doctest: optional - sage.modules sage.rings.finite_rings
# sage.doctest: needs sage.modules sage.rings.finite_rings
r"""
Linear code constructors that do not preserve the structural information

Expand Down Expand Up @@ -227,47 +227,49 @@ def permutation_action(g, v):

EXAMPLES::

sage: # needs sage.groups
sage: V = VectorSpace(GF(3),5)
sage: v = V([0,1,2,0,1])
sage: G = SymmetricGroup(5) # optional - sage.groups
sage: g = G([(1,2,3)]) # optional - sage.groups
sage: permutation_action(g,v) # optional - sage.groups
sage: G = SymmetricGroup(5)
sage: g = G([(1,2,3)])
sage: permutation_action(g,v)
(1, 2, 0, 0, 1)
sage: g = G([()]) # optional - sage.groups
sage: permutation_action(g,v) # optional - sage.groups
sage: g = G([()])
sage: permutation_action(g,v)
(0, 1, 2, 0, 1)
sage: g = G([(1,2,3,4,5)]) # optional - sage.groups
sage: permutation_action(g,v) # optional - sage.groups
sage: g = G([(1,2,3,4,5)])
sage: permutation_action(g,v)
(1, 2, 0, 1, 0)
sage: L = Sequence([1,2,3,4,5])
sage: permutation_action(g,L) # optional - sage.groups
sage: permutation_action(g,L)
[2, 3, 4, 5, 1]
sage: MS = MatrixSpace(GF(3),3,7)
sage: A = MS([[1,0,0,0,1,1,0],[0,1,0,1,0,1,0],[0,0,0,0,0,0,1]])
sage: S5 = SymmetricGroup(5) # optional - sage.groups
sage: g = S5([(1,2,3)]) # optional - sage.groups
sage: S5 = SymmetricGroup(5)
sage: g = S5([(1,2,3)])
sage: A
[1 0 0 0 1 1 0]
[0 1 0 1 0 1 0]
[0 0 0 0 0 0 1]
sage: permutation_action(g,A) # optional - sage.groups
sage: permutation_action(g,A)
[0 1 0 1 0 1 0]
[0 0 0 0 0 0 1]
[1 0 0 0 1 1 0]

It also works on lists and is a "left action"::

sage: # needs sage.groups
sage: v = [0,1,2,0,1]
sage: G = SymmetricGroup(5) # optional - sage.groups
sage: g = G([(1,2,3)]) # optional - sage.groups
sage: gv = permutation_action(g,v); gv # optional - sage.groups
sage: G = SymmetricGroup(5)
sage: g = G([(1,2,3)])
sage: gv = permutation_action(g,v); gv
[1, 2, 0, 0, 1]
sage: permutation_action(g,v) == g(v) # optional - sage.groups
sage: permutation_action(g,v) == g(v)
True
sage: h = G([(3,4)]) # optional - sage.groups
sage: gv = permutation_action(g,v) # optional - sage.groups
sage: hgv = permutation_action(h,gv) # optional - sage.groups
sage: hgv == permutation_action(h*g,v) # optional - sage.groups
sage: h = G([(3,4)])
sage: gv = permutation_action(g,v)
sage: hgv = permutation_action(h,gv)
sage: hgv == permutation_action(h*g,v)
True

AUTHORS:
Expand Down Expand Up @@ -729,15 +731,15 @@ def ToricCode(P,F):
sage: C = codes.ToricCode([[0,0],[1,0],[2,0],[0,1],[1,1]], GF(7))
sage: C
[36, 5] linear code over GF(7)
sage: C.minimum_distance()
sage: C.minimum_distance() # needs sage.groups
24
sage: C.minimum_distance(algorithm="guava") # optional - gap_package_guava
...24
sage: C = codes.ToricCode([[-2,-2],[-1,-2],[-1,-1],[-1,0],
....: [0,-1],[0,0],[0,1],[1,-1],[1,0]], GF(5))
sage: C
[16, 9] linear code over GF(5)
sage: C.minimum_distance()
sage: C.minimum_distance() # needs sage.groups
6
sage: C.minimum_distance(algorithm="guava") # optional - gap_package_guava
6
Expand Down Expand Up @@ -786,9 +788,9 @@ def WalshCode(m):
[8, 3] linear code over GF(2)
sage: C.spectrum()
[1, 0, 0, 0, 7, 0, 0, 0, 0]
sage: C.minimum_distance()
sage: C.minimum_distance() # needs sage.libs.gap
4
sage: C.minimum_distance(algorithm='gap') # check d=2^(m-1)
sage: C.minimum_distance(algorithm='gap') # check d=2^(m-1) # needs sage.libs.gap
4

REFERENCES:
Expand Down
1 change: 1 addition & 0 deletions src/sage/coding/codecan/codecan.pyx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# sage.doctest: needs sage.libs.pari
r"""
Canonical forms and automorphism group computation for linear codes over finite fields

Expand Down
4 changes: 2 additions & 2 deletions src/sage/coding/cyclic_code.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# sage.doctest: optional - sage.modules sage.rings.finite_rings
# sage.doctest: needs sage.modules sage.rings.finite_rings
r"""
Cyclic code

Expand Down Expand Up @@ -977,7 +977,7 @@ def message_space(self):
sage: g = x ** 3 + x + 1
sage: C = codes.CyclicCode(generator_pol=g, length=n)
sage: E = codes.encoders.CyclicCodePolynomialEncoder(C)
sage: E.message_space()
sage: E.message_space() # needs sage.libs.ntl
Univariate Polynomial Ring in x over Finite Field of size 2 (using GF2X)
"""
return self._polynomial_ring
Expand Down
Loading