Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Partition backtrack functions for binary codes
EXAMPLES::
sage: import sage.groups.perm_gps.partn_ref.refinement_binary
REFERENCE:
- [1] McKay, Brendan D. Practical Graph Isomorphism. Congressus Numerantium, Vol. 30 (1981), pp. 45-87.
- [2] Leon, Jeffrey. Permutation Group Algorithms Based on Partitions, I: Theory and Algorithms. J. Symbolic Computation, Vol. 12 (1991), pp. 533-583.
"""
#***************************************************************************** # Copyright (C) 2006 - 2011 Robert L. Miller <rlmillster@gmail.com> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # http://www.gnu.org/licenses/ #*****************************************************************************
from __future__ import print_function
include "sage/data_structures/bitset.pxi" from .data_structures cimport * from sage.rings.integer cimport Integer from .double_coset cimport double_coset
cdef class LinearBinaryCodeStruct(BinaryCodeStruct):
def __cinit__(self, matrix): cdef int i,j raise NotImplementedError # By the time the dimension gets this big, the computation is infeasible anyway...
sig_free(self.basis) sig_free(self.scratch_bitsets) sig_free(self.alpha_is_wd) PS_dealloc(self.word_ps) sig_free(self.alpha) sig_free(self.scratch) raise MemoryError
except MemoryError: for j from 0 <= j < i: bitset_free(&self.basis[j]) memerr = 1 break except MemoryError: for j from 0 <= j < i: bitset_free(&self.scratch_bitsets[j]) for j from 0 <= j < self.dimension: bitset_free(&self.basis[j]) memerr = 1 break except MemoryError: for j from 0 <= j < 2*self.dimension+2: bitset_free(&self.scratch_bitsets[j]) for j from 0 <= j < self.dimension: bitset_free(&self.basis[j]) memerr = 1 sig_free(self.basis); sig_free(self.scratch_bitsets) sig_free(self.alpha_is_wd); PS_dealloc(self.word_ps) sig_free(self.alpha); sig_free(self.scratch) raise MemoryError else:
def run(self, partition=None): """ Perform the canonical labeling and automorphism group computation, storing results to self.
INPUT: partition -- an optional list of lists partition of the columns. default is the unit partition.
EXAMPLES: sage: from sage.groups.perm_gps.partn_ref.refinement_binary import LinearBinaryCodeStruct
sage: B = LinearBinaryCodeStruct(matrix(GF(2),[[1,0,1],[0,1,1]])) sage: B.run() sage: B.automorphism_group() ([[0, 2, 1], [1, 0, 2]], 6, [0, 1]) sage: B.canonical_relabeling() [0, 1, 2]
sage: B = LinearBinaryCodeStruct(matrix(GF(2),[[1,1,1,1]])) sage: B.automorphism_group() ([[0, 1, 3, 2], [0, 2, 1, 3], [1, 0, 2, 3]], 24, [0, 1, 2]) sage: B.canonical_relabeling() [0, 1, 2, 3]
sage: B = LinearBinaryCodeStruct(matrix(GF(2),[[0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]])) sage: B.automorphism_group()[1] == factorial(14) True
sage: M = Matrix(GF(2),[\ ....: [1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0],\ ....: [0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0],\ ....: [0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1],\ ....: [0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1],\ ....: [0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1]]) sage: B = LinearBinaryCodeStruct(M) sage: B.automorphism_group()[1] 322560
sage: M = Matrix(GF(2),[\ ....: [1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0],\ ....: [0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0],\ ....: [0,0,0,0,0,1,0,1,0,0,0,1,1,1,1,1,1],\ ....: [0,0,0,1,1,0,0,0,0,1,1,0,1,1,0,1,1]]) sage: B = LinearBinaryCodeStruct(M) sage: B.automorphism_group()[1] 2304
sage: M=Matrix(GF(2),[\ ....: [1,0,0,1,1,1,1,0,0,1,0,0,0,0,0,0,0],\ ....: [0,1,0,0,1,1,1,1,0,0,1,0,0,0,0,0,0],\ ....: [0,0,1,0,0,1,1,1,1,0,0,1,0,0,0,0,0],\ ....: [0,0,0,1,0,0,1,1,1,1,0,0,1,0,0,0,0],\ ....: [0,0,0,0,1,0,0,1,1,1,1,0,0,1,0,0,0],\ ....: [0,0,0,0,0,1,0,0,1,1,1,1,0,0,1,0,0],\ ....: [0,0,0,0,0,0,1,0,0,1,1,1,1,0,0,1,0],\ ....: [0,0,0,0,0,0,0,1,0,0,1,1,1,1,0,0,1]]) sage: B = LinearBinaryCodeStruct(M) sage: B.automorphism_group()[1] 136
sage: M = Matrix(GF(2),[\ ....: [1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0], ....: [0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0], ....: [0,0,0,0,1,1,0,0,0,0,0,0,1,1,1,1,1,1], ....: [0,0,1,1,0,0,0,0,0,0,1,1,1,1,0,0,1,1], ....: [0,0,0,1,0,0,0,1,0,1,0,1,0,1,1,1,0,1], ....: [0,1,0,0,0,1,0,0,0,1,1,1,0,1,0,1,1,0]]) sage: B = LinearBinaryCodeStruct(M) sage: B.automorphism_group()[1] 2160
sage: M=Matrix(GF(2),[\ ....: [0,1,0,1,1,1,0,0,0,1,0,0,0,1,0,0,0,1,1,1,0,1],\ ....: [1,0,1,1,1,0,0,0,1,0,0,0,1,0,0,0,1,1,1,0,1,0],\ ....: [0,1,1,1,0,0,0,1,0,0,1,1,0,0,0,1,1,1,0,1,0,0],\ ....: [1,1,1,0,0,0,1,0,0,1,0,0,0,0,1,1,1,0,1,0,0,1],\ ....: [1,1,0,0,0,1,0,0,1,0,1,0,0,1,1,1,0,1,0,0,1,0],\ ....: [1,0,0,0,1,0,0,1,0,1,1,0,1,1,1,0,1,0,0,1,0,0],\ ....: [0,0,0,1,0,0,1,0,1,1,1,1,1,1,0,1,0,0,1,0,0,0],\ ....: [0,0,1,0,0,1,0,1,1,1,0,1,1,0,1,0,0,1,0,0,0,1],\ ....: [0,1,0,0,1,0,1,1,1,0,0,1,0,1,0,0,1,0,0,0,1,1],\ ....: [1,0,0,1,0,1,1,1,0,0,0,0,1,0,0,1,0,0,0,1,1,1],\ ....: [0,0,1,0,1,1,1,0,0,0,1,1,0,0,1,0,0,0,1,1,1,0]]) sage: B = LinearBinaryCodeStruct(M) sage: B.automorphism_group()[1] 887040
sage: M = Matrix(GF(2),[\ ....: [1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], ....: [0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0], ....: [0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], ....: [0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0], ....: [0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0], ....: [0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0], ....: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1], ....: [1,0,1,0,1,0,1,0,1,1,0,0,0,0,0,0,1,1,0,0], ....: [1,1,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,1,0,0], ....: [1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,0,1,0]]) sage: B = LinearBinaryCodeStruct(M) sage: B.automorphism_group()[1] 294912
sage: M = Matrix(GF(2), [\ ....: [1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], ....: [0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], ....: [0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0], ....: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0], ....: [0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0], ....: [0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0], ....: [0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,1], ....: [0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,1,0,0,1,1,1,0,1], ....: [0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,1,1,1,1,0,0,0,1]]) sage: B = LinearBinaryCodeStruct(M) sage: B.automorphism_group()[1] 442368
sage: M = Matrix(GF(2), [\ ....: [1,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0],\ ....: [1,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,0,0,1,1,0,0,0,0,1]]) sage: B = LinearBinaryCodeStruct(M) sage: B.automorphism_group()[1] 17868913969917295853568000000
""" cdef PartitionStack *part else: part = PS_from_list(partition) raise MemoryError
def automorphism_group(self): """ Returns a list of generators of the automorphism group, along with its order and a base for which the list of generators is a strong generating set.
EXAMPLES: (For more examples, see self.run()) sage: from sage.groups.perm_gps.partn_ref.refinement_binary import LinearBinaryCodeStruct
sage: B = LinearBinaryCodeStruct(matrix(GF(2),[[1,1,1,1]])) sage: B.automorphism_group() ([[0, 1, 3, 2], [0, 2, 1, 3], [1, 0, 2, 3]], 24, [0, 1, 2])
""" cdef int i, j cdef list generators, base cdef Integer order
def canonical_relabeling(self): """ Returns a canonical relabeling (in list permutation format).
EXAMPLES: (For more examples, see self.run()) sage: from sage.groups.perm_gps.partn_ref.refinement_binary import LinearBinaryCodeStruct
sage: B = LinearBinaryCodeStruct(matrix(GF(2), [[1,1,0]])) sage: B.automorphism_group() ([[1, 0, 2]], 2, [0]) sage: B.canonical_relabeling() [1, 2, 0] sage: B = LinearBinaryCodeStruct(matrix(GF(2), [[1,0,1]])) sage: B.automorphism_group() ([[2, 1, 0]], 2, [0]) sage: B.canonical_relabeling() [1, 0, 2]
""" cdef int i self.run()
def is_isomorphic(self, LinearBinaryCodeStruct other): """ Calculate whether self is isomorphic to other.
EXAMPLES: sage: from sage.groups.perm_gps.partn_ref.refinement_binary import LinearBinaryCodeStruct
sage: B = LinearBinaryCodeStruct(Matrix(GF(2), [[1,1,1,1,0,0],[0,0,1,1,1,1]])) sage: C = LinearBinaryCodeStruct(Matrix(GF(2), [[1,1,1,0,0,1],[1,1,0,1,1,0]])) sage: B.is_isomorphic(C) [0, 1, 2, 5, 3, 4]
""" cdef int *output cdef int *ordering cdef PartitionStack *part PS_dealloc(part) sig_free(ordering) sig_free(output) raise MemoryError
else: output_py = False
def __dealloc__(self): cdef int j
cdef int ith_word_linear(BinaryCodeStruct self, int i, bitset_s *word): cdef int j
cdef class NonlinearBinaryCodeStruct(BinaryCodeStruct):
def __cinit__(self, arg): cdef int i,j else: raise NotImplementedError
sig_free(self.words) sig_free(self.scratch_bitsets) sig_free(self.alpha_is_wd) PS_dealloc(self.word_ps) sig_free(self.alpha) sig_free(self.scratch) raise MemoryError
except MemoryError: for j from 0 <= j < i: bitset_free(&self.words[j]) memerr = 1 break except MemoryError: for j from 0 <= j < i: bitset_free(&self.scratch_bitsets[j]) for j from 0 <= j < self.nwords: bitset_free(&self.words[j]) memerr = 1 break except MemoryError: for j from 0 <= j < 4*self.nwords: bitset_free(&self.scratch_bitsets[j]) for j from 0 <= j < self.nwords: bitset_free(&self.words[j]) memerr = 1 except MemoryError: for j from 0 <= j < 4*self.nwords + 1: bitset_free(&self.scratch_bitsets[j]) for j from 0 <= j < self.nwords: bitset_free(&self.words[j]) memerr = 1 sig_free(self.words); sig_free(self.scratch_bitsets) sig_free(self.alpha_is_wd); PS_dealloc(self.word_ps) sig_free(self.alpha); sig_free(self.scratch) raise MemoryError else:
def __dealloc__(self): cdef int j
def run(self, partition=None): """ Perform the canonical labeling and automorphism group computation, storing results to self.
INPUT: partition -- an optional list of lists partition of the columns. default is the unit partition.
EXAMPLES: sage: from sage.groups.perm_gps.partn_ref.refinement_binary import NonlinearBinaryCodeStruct
sage: B = NonlinearBinaryCodeStruct(Matrix(GF(2), [[1,0,0,0],[0,0,1,0]])) sage: B.run() sage: B.automorphism_group() ([[2, 1, 0, 3], [0, 3, 2, 1]], 4, [1, 0]) sage: B.canonical_relabeling() [2, 0, 3, 1]
sage: B = NonlinearBinaryCodeStruct(Matrix(GF(2), [[1,1,1,0],[1,1,0,1],[1,0,1,1],[0,1,1,1]])) sage: B.run() sage: B.automorphism_group() ([[0, 1, 3, 2], [0, 2, 1, 3], [1, 0, 2, 3]], 24, [0, 1, 2]) sage: B.canonical_relabeling() [0, 1, 2, 3]
sage: B = NonlinearBinaryCodeStruct(Matrix(GF(2), [[1,1,1,0,0,0],[1,1,0,1,0,0],[1,0,1,1,0,0],[0,1,1,1,0,0],[0,0,0,0,1,0],[0,0,0,0,0,1]])) sage: B.run() sage: B.automorphism_group() ([[0, 1, 3, 2, 4, 5], [0, 2, 1, 3, 4, 5], [1, 0, 2, 3, 4, 5], [0, 1, 2, 3, 5, 4]], 48, [4, 0, 1, 2]) sage: B.canonical_relabeling() [2, 3, 4, 5, 0, 1]
""" cdef PartitionStack *part else: part = PS_from_list(partition) raise MemoryError
def automorphism_group(self): """ Returns a list of generators of the automorphism group, along with its order and a base for which the list of generators is a strong generating set.
EXAMPLES: (For more examples, see self.run()) sage: from sage.groups.perm_gps.partn_ref.refinement_binary import NonlinearBinaryCodeStruct
sage: B = NonlinearBinaryCodeStruct(Matrix(GF(2), [[1,1,1,0,0,0],[1,1,0,1,0,0],[1,0,1,1,0,0],[0,1,1,1,0,0],[0,0,0,0,1,0],[0,0,0,0,0,1]])) sage: B.run() sage: B.automorphism_group() ([[0, 1, 3, 2, 4, 5], [0, 2, 1, 3, 4, 5], [1, 0, 2, 3, 4, 5], [0, 1, 2, 3, 5, 4]], 48, [4, 0, 1, 2])
""" cdef int i, j cdef list generators, base cdef Integer order self.run()
def canonical_relabeling(self): """ Returns a canonical relabeling (in list permutation format).
EXAMPLES: (For more examples, see self.run()) sage: from sage.groups.perm_gps.partn_ref.refinement_binary import NonlinearBinaryCodeStruct
sage: B = NonlinearBinaryCodeStruct(Matrix(GF(2), [[1,1,1,0,0,0],[1,1,0,1,0,0],[1,0,1,1,0,0],[0,1,1,1,0,0],[0,0,0,0,1,0],[0,0,0,0,0,1]])) sage: B.run() sage: B.canonical_relabeling() [2, 3, 4, 5, 0, 1]
""" cdef int i self.run()
def is_isomorphic(self, NonlinearBinaryCodeStruct other): """ Calculate whether self is isomorphic to other.
EXAMPLES: sage: from sage.groups.perm_gps.partn_ref.refinement_binary import NonlinearBinaryCodeStruct
sage: B = NonlinearBinaryCodeStruct(Matrix(GF(2), [[1,1,1,1,0,0],[0,0,1,1,1,1]])) sage: C = NonlinearBinaryCodeStruct(Matrix(GF(2), [[1,1,0,0,1,1],[1,1,1,1,0,0]])) sage: B.is_isomorphic(C) [2, 3, 0, 1, 4, 5]
""" cdef int *output cdef int *ordering cdef PartitionStack *part PS_dealloc(part) sig_free(ordering) sig_free(output) raise MemoryError
else: output_py = False
cdef int ith_word_nonlinear(BinaryCodeStruct self, int i, bitset_s *word):
cdef int refine_by_bip_degree(PartitionStack *col_ps, void *S, int *cells_to_refine_by, int ctrb_len): """ Refines the input partition by checking degrees of vertices to the given cells in the associated bipartite graph (vertices split into columns and words).
INPUT: col_ps -- a partition stack, whose finest partition is the partition to be refined. S -- a binary code struct object cells_to_refine_by -- a list of pointers to cells to check degrees against in refining the other cells (updated in place) ctrb_len -- how many cells in cells_to_refine_by
OUTPUT:
An integer $I$ invariant under the orbits of $S_n$. That is, if $\gamma$ is a permutation of the columns, then $$ I(G, PS, cells_to_refine_by) = I( \gamma(G), \gamma(PS), \gamma(cells_to_refine_by) ) .$$
""" cdef int current_cell, i, r, j cdef int first_largest_subcell
cdef bint necessary_to_split_cell cdef int against_index # now, i points to the next cell (before refinement) else: # now, i points to the next cell (before refinement)
cdef int compare_linear_codes(int *gamma_1, int *gamma_2, void *S1, void *S2, int degree): """ Compare gamma_1(S1) and gamma_2(S2).
Return return -1 if gamma_1(S1) < gamma_2(S2), 0 if gamma_1(S1) == gamma_2(S2), 1 if gamma_1(S1) > gamma_2(S2). (Just like the python \code{cmp}) function.
Abstractly, what this function does is relabel the basis of B by gamma_1 and gamma_2, run a row reduction on each, and verify that the matrices are the same, which holds if and only if the rowspan is the same. In practice, if the codes are not equal, the reductions (which are carried out in an interleaved way) will terminate as soon as this is discovered, and whichever code has a 1 in the entry in which they differ is reported as larger.
INPUT: gamma_1, gamma_2 -- list permutations (inverse) S1, S2 -- binary code struct objects
""" cdef bint is_pivot_1, is_pivot_2 return <int>is_pivot_2 - <int>is_pivot_1 else:
cdef int compare_nonlinear_codes(int *gamma_1, int *gamma_2, void *S1, void *S2, int degree): """ Compare gamma_1(S1) and gamma_2(S2).
Return return -1 if gamma_1(S1) < gamma_2(S2), 0 if gamma_1(S1) == gamma_2(S2), 1 if gamma_1(S1) > gamma_2(S2). (Just like the python \code{cmp}) function.
INPUT: gamma_1, gamma_2 -- list permutations (inverse) S1, S2 -- a binary code struct object
""" cdef int where_0, where_1 cdef bitset_s *B_1_this cdef bitset_s *B_1_other cdef bitset_s *B_2_this cdef bitset_s *B_2_other
else: if n_one_1 > n_one_2: return 1 else: return -1 else: else:
cdef bint all_children_are_equivalent(PartitionStack *col_ps, void *S): """ Returns True if any refinement of the current partition results in the same structure.
WARNING: Converse does not hold in general! See Lemma 2.25 of [1] for details, noting that the binary code is interpreted as a bipartite graph (see module docs for details).
INPUT: col_ps -- the partition stack to be checked S -- a binary code struct object """ else: else: return 1 return 1
cdef inline int word_degree(PartitionStack *word_ps, BinaryCodeStruct BCS, int entry, int cell_index, PartitionStack *col_ps): """ Returns the number of edges from the vertex corresponding to entry to vertices in the cell corresponding to cell_index.
INPUT: word_ps -- the partition stack to be checked col_ps -- corresponding partition stack on columns BCS -- a binary code struct object entry -- the position of the vertex in question in the entries of word_ps cell_index -- the starting position of the cell in question in the entries of PS """ cdef bitset_t cell, word cdef int i, h
cdef inline int col_degree(PartitionStack *col_ps, BinaryCodeStruct BCS, int entry, int cell_index, PartitionStack *word_ps): """ Returns the number of edges from the vertex corresponding to entry to vertices in the cell corresponding to cell_index.
INPUT: col_ps -- the partition stack to be checked word_ps -- corresponding partition stack on words BCS -- a binary code struct object entry -- the position of the vertex in question in the entries of word_ps cell_index -- the starting position of the cell in question in the entries of PS """ cdef bitset_t word
cdef inline int sort_by_function_codes(PartitionStack *PS, int start, int *degrees, int *counts, int *output, int count_max): """ A simple counting sort, given the degrees of vertices to a certain cell.
INPUT: PS -- the partition stack to be checked start -- beginning index of the cell to be sorted degrees -- the values to be sorted by count, count_max, output -- scratch space
""" cdef int i, j, max, max_location # i+start is the right endpoint of the cell now
""" Tests to make sure that C(gamma(B)) == C(B) for random permutations gamma and random codes B, and that is_isomorphic returns an isomorphism.
INPUT: num -- run tests for this many codes n_max -- test codes with at most this many columns k_max -- test codes with at most this for dimension perms_per_code -- test each code with this many random permutations
DISCUSSION:
This code generates num random linear codes B on at most n_max columns with dimension at most k_max, and a random nonlinear code B2 on at most n_max columns with number of words at most nwords_max. The density of entries in the basis is chosen randomly between 0 and 1.
For each code B (B2) generated, we uniformly generate perms_per_code random permutations and verify that the canonical labels of B and the image of B under the generated permutation are equal, and check that the double coset function returns an isomorphism.
TESTS::
sage: import sage.groups.perm_gps.partn_ref.refinement_binary sage: sage.groups.perm_gps.partn_ref.refinement_binary.random_tests() # long time (up to 5s on sage.math, 2012) All passed: ... random tests on ... codes.
""" from sage.misc.misc import walltime from sage.misc.prandom import random, randint from sage.combinat.permutation import Permutations from sage.matrix.constructor import random_matrix, matrix from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF cdef int h, i, j, n, k, num_tests = 0, num_codes = 0 cdef LinearBinaryCodeStruct B, C cdef NonlinearBinaryCodeStruct B_n, C_n for mmm in range(num): p = random()*(density_range[1]-density_range[0]) + density_range[0] n = randint(2, n_max) k = randint(1, min(n-1,k_max) ) nwords = randint(1, min(n-1,nwords_max) ) S = Permutations(n)
M = random_matrix(GF(2), k, n, sparse=False, density=p).row_space().basis_matrix() M_n = random_matrix(GF(2), nwords, n, sparse=False, density=p) B = LinearBinaryCodeStruct( M ) B_n = NonlinearBinaryCodeStruct( M_n ) B.run() B_n.run()
for i from 0 <= i < perms_per_code: perm = [a-1 for a in list(S.random_element())] C = LinearBinaryCodeStruct( matrix(GF(2), B.dimension, B.degree) ) C_n = NonlinearBinaryCodeStruct( matrix(GF(2), B_n.nwords, B_n.degree) ) for j from 0 <= j < B.dimension: for h from 0 <= h < B.degree: bitset_set_to(&C.basis[j], perm[h], bitset_check(&B.basis[j], h)) for j from 0 <= j < B_n.nwords: for h from 0 <= h < B_n.degree: bitset_set_to(&C_n.words[j], perm[h], bitset_check(&B_n.words[j], h)) # now C is a random permutation of B, and C_n of B_n C.run() C_n.run() B_relab = B.canonical_relabeling() C_relab = C.canonical_relabeling() B_n_relab = B_n.canonical_relabeling() C_n_relab = C_n.canonical_relabeling() B_M = matrix(GF(2), B.dimension, B.degree) C_M = matrix(GF(2), B.dimension, B.degree) B_n_M = matrix(GF(2), B_n.nwords, B_n.degree) C_n_M = matrix(GF(2), B_n.nwords, B_n.degree) for j from 0 <= j < B.dimension: for h from 0 <= h < B.degree: B_M[j,B_relab[h]] = bitset_check(&B.basis[j], h) C_M[j,C_relab[h]] = bitset_check(&C.basis[j], h) for j from 0 <= j < B_n.nwords: for h from 0 <= h < B_n.degree: B_n_M[j,B_n_relab[h]] = bitset_check(&B_n.words[j], h) C_n_M[j,C_n_relab[h]] = bitset_check(&C_n.words[j], h) if B_M.row_space() != C_M.row_space(): print("can_lab error -- B:") for j from 0 <= j < B.dimension: print(bitset_string(&B.basis[j])) print(perm) return if sorted(B_n_M.rows()) != sorted(C_n_M.rows()): print("can_lab error -- B_n:") for j from 0 <= j < B_n.nwords: print(bitset_string(&B_n.words[j])) print(perm) return isom = B.is_isomorphic(C) if not isom: print("isom -- B:") for j from 0 <= j < B.dimension: print(bitset_string(&B.basis[j])) print(perm) print(isom) return isom = B_n.is_isomorphic(C_n) if not isom: print("isom -- B_n:") for j from 0 <= j < B_n.nwords: print(bitset_string(&B_n.words[j])) print(perm) print(isom) return
num_tests += 4*perms_per_code num_codes += 2
print("All passed: %d random tests on %d codes." % (num_tests, num_codes))
|