Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 19204
1
r"""
2
Boolean linear codes
3
====================
4
5
The ``boolean_linear_code`` module defines the functions:
6
7
* ``boolean_linear_code_graph``;
8
which returns the Boolean linear code corresponding to a Boolean function,
9
* ``linear_code_from_code_gens``;
10
which return the Boolean linear code corresponding to a list of generators; and
11
* ``print_latex_code_parameters``,
12
which prints the standard parameters of a linear code.
13
14
AUTHORS:
15
16
- Paul Leopardi (2016-10-28): initial version
17
18
"""
19
#*****************************************************************************
20
# Copyright (C) 2016-2017 Paul Leopardi [email protected]
21
#
22
# Distributed under the terms of the GNU General Public License (GPL)
23
# as published by the Free Software Foundation; either version 2 of
24
# the License, or (at your option) any later version.
25
# http://www.gnu.org/licenses/
26
#*****************************************************************************
27
28
from sage.coding.linear_code import LinearCode
29
from sage.matrix.constructor import matrix
30
from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF
31
32
from boolean_cayley_graphs.integer_bits import inner
33
34
35
def boolean_linear_code(dim, f):
36
r"""
37
Return the Boolean linear code corresponding to a Boolean function.
38
39
INPUT:
40
41
- ``dim`` -- positive integer. The assumed dimension of function ``f``.
42
- ``f`` -- a Python function that takes a positive integer and returns 0 or 1.
43
This is assumed to represent a Boolean function on :math:`\mathbb{F}_2^{dim}`
44
via lexicographical ordering.
45
46
OUTPUT:
47
48
An object of class ``LinearCode``, representing the Boolean linear code
49
corresponding to the Boolean function represented by ``f``.
50
51
EXAMPLES:
52
53
::
54
55
sage: from sage.crypto.boolean_function import BooleanFunction
56
sage: bf = BooleanFunction([0,1,0,0,0,1,0,0,1,0,0,0,0,0,1,1])
57
sage: dim = bf.nvariables()
58
sage: from boolean_cayley_graphs.boolean_linear_code import boolean_linear_code
59
sage: bc = boolean_linear_code(dim, bf)
60
sage: bc.characteristic_polynomial()
61
-2/3*x + 2
62
sage: bc.generator_matrix().echelon_form()
63
[1 0 0 0 1]
64
[0 1 0 0 0]
65
[0 0 1 0 0]
66
[0 0 0 1 1]
67
68
REFERENCES:
69
70
.. Carlet [Car2010]_.
71
72
.. Calderbank and Kantor [CalK1986]_.
73
74
.. Ding [Din2015]_ Corollary 10.
75
76
"""
77
v = 2 ** dim
78
support = [
79
y
80
for y in range(v)
81
if f(y) == 1]
82
M = matrix(GF(2), [[
83
inner(2 ** k, y)
84
for y in support]
85
for k in range(dim)])
86
return LinearCode(M)
87
88
89
def linear_code_from_code_gens(gens):
90
r"""
91
Return the Boolean linear code corresponding to a list of generators.
92
93
INPUT:
94
95
- ``gens`` -- list. A list of strings of 0,1 characters.
96
This is assumed to represent the generators of a linear code.
97
98
OUTPUT:
99
100
An object of class ``LinearCode`` representing the Boolean linear code
101
corresponding to the generators represented by ``gens``.
102
103
EXAMPLE:
104
105
::
106
107
sage: from boolean_cayley_graphs.boolean_linear_code import linear_code_from_code_gens
108
sage: gens = (
109
....: "10001",
110
....: "01000",
111
....: "00100",
112
....: "00011")
113
sage: c = linear_code_from_code_gens(gens)
114
sage: c.basis()
115
[
116
(1, 0, 0, 0, 1),
117
(0, 1, 0, 0, 0),
118
(0, 0, 1, 0, 0),
119
(0, 0, 0, 1, 1)
120
]
121
"""
122
M = matrix(GF(2), [list(s) for s in gens])
123
return LinearCode(M)
124
125
126
def print_latex_code_parameters(c):
127
r"""
128
Print the standard parameters of a linear code.
129
130
INPUT:
131
132
- ``c`` -- ``LinearCode``.
133
134
OUTPUT:
135
136
A string representing the standard parameters of the linear code ``c``.
137
138
EXAMPLE:
139
140
::
141
142
sage: from boolean_cayley_graphs.boolean_linear_code import linear_code_from_code_gens
143
sage: from boolean_cayley_graphs.boolean_linear_code import print_latex_code_parameters
144
sage: gens = (
145
....: "10001",
146
....: "01000",
147
....: "00100",
148
....: "00011")
149
sage: c = linear_code_from_code_gens(gens)
150
sage: print_latex_code_parameters(c)
151
[5,4,1]
152
"""
153
print((
154
"[" + str(c.length()) +
155
"," + str(c.dimension()) +
156
"," + str(c.minimum_distance()) + "]"), end=' ')
157
158