/usr/lib/python2.7/dist-packages/brial/coding.py is in python-brial 1.2.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | from __future__ import print_function
from .PyPolyBoRi import Polynomial
from .nf import symmGB_F2_C
from .ll import ll_encode
try:
from itertools import ifilter as filter
except ImportError:
pass
class OccCounter(object):
def __init__(self):
self.impl = dict()
def __getitem__(self, k):
try:
return self.impl[k]
except KeyError:
return 0
def increase(self, k):
try:
self.impl[k] = self.impl[k] + 1
except KeyError:
self.impl[k] = 1
def uniques(self):
def filter_fun(k):
return self.impl[k] == 1
return filter(filter_fun, self.impl.keys())
def preprocess(I, prot=True):
def min_gb(I):
strat = symmGB_F2_C(I, opt_lazy=False, opt_exchange=False, prot=prot,
selection_size=10000, opt_red_tail=True)
return list(strat.minimalize_and_tail_reduce())
I = [Polynomial(p) for p in I]
lin = [p for p in I if p.deg() == 1]
# lin_strat=symmGB_F2_C(lin, opt_lazy=False,opt_exchange=False,prot=prot,sele
# ction_size=10000,opt_red_tail=True)
lin = min_gb(lin) # list(lin_strat.minimalize_and_tail_reduce())
for m in sorted([p.lead() for p in lin]):
print(m)
lin_ll = ll_encode(lin)
square = [p.lead() for p in I if p.deg() == 2 and len(p) == 1]
assert(len(lin) + len(square) == len(I))
res = list(lin)
counter = OccCounter()
def unique_index(s):
for idx in s:
if counter[idx] == 1:
return idx
never_come_here = False
assert never_come_here
for m in square:
for idx in m:
counter.increase(idx)
systems = dict(((idx, []) for idx in counter.uniques()))
for m in square:
u_index = unique_index(m)
systems[u_index].append(ll_red_nf(m / Variable(u_index), lin_ll))
rewritings = dict()
u_var = Variable(u)
u_im = ll_red_nf(u_var, lin_ll)
if not u_im.isConstant():
if u_im != u_var:
r = u_im.navigation().value()
else:
pass
for u in counter.uniques():
#print u
u_var = Variable(u)
u_im = ll_red_nf(u_var, lin_ll)
if not u_im.isConstant():
if u_im != u_var:
r = u_im.navigation().value()
else:
pass
for u in systems.keys():
u_var = Variable(u)
u_im = ll_red_nf(u_var, lin_ll)
res.extend([u_im * p for p in min_gb(systems[u])])
#print [u_im*p for p in min_gb(systems[u])]
print("lin:", len(lin), "res:", len(res), "square:", len(square))
res = [p for p in (Polynomial(p) for p in res) if not p.is_zero()]
return res
|