def getGradingInfo(self): """Shows the distribution of gradings in an easy-to-read format.""" distr_by_spinc = dict() for x in self.generators: ref_grading = self.grading[x] break for x in self.generators: maslov, mod, spinc = \ self.gr_set.eltDiffShortForm(self.grading[x], ref_grading) spinc = tuple(spinc) if spinc not in distr_by_spinc: distr_by_spinc[spinc] = [] distr_by_spinc[spinc].append(maslov) distr_count = dict() for spinc, distr in distr_by_spinc.items(): min_gr, max_gr = min(distr), max(distr) cur_count = [0] * fracToInt(max_gr - min_gr + 1) for gr in distr: cur_count[fracToInt(gr - min_gr)] += 1 cur_count = tuple(cur_count) if cur_count not in distr_count: distr_count[cur_count] = 0 distr_count[cur_count] += 1 return distr_count
def __init__(self, vecs): """vecs is a nonempty list of vectors. Each element of vecs is a vector of integers (rational inputs are possible, but they must have integer value, and will be converted to integers. """ assert len(vecs) > 0 self.ori_vecs = [list(vec) for vec in vecs] self.ori_vecs = [[fracToInt(n) for n in vec] for vec in self.ori_vecs] self.num_row = len(self.ori_vecs) self.num_col = len(self.ori_vecs[0]) self._rowReduce() self.num_reduced_row = len(self.reduced_vecs) assert self.num_reduced_row == len(self.pivot)
def vecReduce(self, vec, use_rational = False): """Reduce the given vector to a standard form. If use_rational is set to True, then rational multiples of the original vectors are allowed. Otherwise only integer multiples are allowed to reduce the vector. If use_rational is set to false, only integer values are allowed in vec. Returns a tuple (comb, reduced_vec), where comb is a vector of length num_row, specifying the linear combination of original vectors that, when subtracted, will yield the standard form reduced_vec. """ if not use_rational: vec = [fracToInt(n) for n in vec] comb = [0] * self.num_row cur_row = 0 for col in range(self.num_col): if vec[col] == 0: continue while cur_row < self.num_reduced_row and self.pivot[cur_row] < col: cur_row += 1 if cur_row >= self.num_reduced_row or self.pivot[cur_row] != col: continue pivot_val = self.reduced_vecs[cur_row][col] assert pivot_val > 0 if use_rational: factor = Fraction(vec[col]) / pivot_val else: factor = vec[col] / pivot_val # integer division for i in range(self.num_col): vec[i] -= self.reduced_vecs[cur_row][i] * factor for i in range(self.num_row): comb[i] += self.reduced_comb[cur_row][i] * factor if use_rational: assert vec[col] == 0 else: # Python definition of integer division means assert vec[col] >= 0 and vec[col] < pivot_val return (comb, vec)