def reduction_matrix_ABCD_to_ApBCpD(A,B,C,D,st = None): r""" returns the reduction/equivalence of the product of ABCD to A(BC)D. """ mat = matrix_multiply(A,matrix_multiply(matrix_multiply(B,C),D)) dim = mat.nrows() d = dict() for i in range(dim): for j in range(dim): newsetA = set() newsetB = set() dic_f = dict() dic_f0 = dict() for elm in mat[i,j]: tmp0 = elm.get_object()[0] tmp1 = elm.get_object()[1].get_object()[0] tmp2 = elm.get_object()[1].get_object()[1] tmpB = CombinatorialObject((tmp0,tmp1,tmp2),elm.get_sign(),elm.get_weight()) newsetB.add(tmpB) tmp10 = tmp1.get_object()[0] tmp11 = tmp1.get_object()[1] tmpA = CombinatorialObject((tmp0,tmp10,tmp11,tmp2),elm.get_sign(),elm.get_weight()) newsetA.add(tmpA) dic_f[tmpA] = tmpA dic_f0[tmpA] = tmpB f = FiniteSetMaps(newsetA,newsetA).from_dict(dic_f) f0 = FiniteSetMaps(newsetA,newsetB).from_dict(dic_f0) d[i,j] = ReductionMaps(CombinatorialScalarWrapper(newsetA),CombinatorialScalarWrapper(newsetB),f,f0) return ReductionMapsDict(d,st)
def reduction_matrix_ABCD_to_pABpCD(A,B,C,D,st = None,reduction = None): r""" returns the reduction/equivalence of the product of ABCD to (AB)CD. """ if reduction == None: mat = matrix_multiply(matrix_multiply(matrix_multiply(A,B),C),D) else: #not used... yet mat = reduction.get_matrix_A() d = dict() dim = mat.nrows() for i in range(dim): for j in range(dim): newsetA = set() newsetB = set() dic_f = dict() dic_f0 = dict() for elm in mat[i,j]: tmp0 = elm.get_object()[0].get_object()[0] tmp01 = tmp0.get_object()[0] tmp02 = tmp0.get_object()[1] tmp1 = elm.get_object()[0].get_object()[1] tmp2 = elm.get_object()[1] tmpB = CombinatorialObject((tmp0,tmp1,tmp2),elm.get_sign(),elm.get_weight()) newsetB.add(tmpB) tmpA = CombinatorialObject((tmp01,tmp02,tmp1,tmp2),elm.get_sign(),elm.get_weight()) newsetA.add(tmpA) dic_f[tmpA] = tmpA dic_f0[tmpA] = tmpB f = FiniteSetMaps(newsetA,newsetA).from_dict(dic_f) f0 = FiniteSetMaps(newsetA,newsetB).from_dict(dic_f0) d[i,j] = ReductionMaps(CombinatorialScalarWrapper(newsetA),CombinatorialScalarWrapper(newsetB),f,f0) return ReductionMapsDict(d,st)
def matrix_adjoint_lemma_40(mat): r""" Returns a matrix which is the target in the reduction of adjoint(A) times A to det(A) times I. """ if mat.nrows() != mat.ncols(): raise ValueError, "Make sure that this is indeed a Combinatorial Adjoint matrix" else: dim = mat.nrows() L = list() mat_space = MatrixSpace(CombinatorialScalarRing(), dim) for i in range(dim): L.append(list()) for j in range(dim): if i == j: copyset = deepcopy(mat[i, j].get_set()) for elm in copyset: tmp = list(elm.get_object()[0].get_object()) #object is tuple, elements come from the actual tuple, hence double get_object() index = tmp.index(CombinatorialObject('_', 1)) tmp[index] = elm.get_object()[1] elm.set_object(tuple(tmp)) else: copyset = CombinatorialScalarWrapper(set()) L[i].append(CombinatorialScalarWrapper(copyset)) return mat_space(L)
def reduction_matrix_IAB_AB(mat,st = "remove left Identity matrix"): r""" Input IAB and output is AB, that is, we remove the left Combinatorial Object 1 from each triple and return only the other two entries. """ if mat.nrows()!=mat.ncols(): raise ValueError, "Check dimensions" else: dim = mat.nrows() d = dict() for i in range(dim): for j in range(dim): dic_f0 = dict() dic_f = dict() newset = set() for elm in mat[i,j]: newelm1 = elm.get_object()[1] newelm2 = elm.get_object()[2] tmp = newelm1*newelm2 newset.add(tmp) dic_f[elm] = elm dic_f0[elm] = tmp f = FiniteSetMaps(mat[i,j],mat[i,j]).from_dict(dic_f) f0 = FiniteSetMaps(mat[i,j],newset).from_dict(dic_f0) d[i,j] = ReductionMaps(mat[i,j],CombinatorialScalarWrapper(newset),f,f0) return ReductionMapsDict(d,st)
def transitive(self, other=None): r""" TBD """ if other is None: raise ValueError, "Enter a reduction map as a parameter" elif self.get_B() != other.get_A(): raise ValueError, "These are not good candidate sets for reduction mapping" else: dic_h = dict() dic_h0 = dict() A = self.get_A() B = self.get_B() C = other.get_B() f = self.get_SRWP() f0 = self.get_SPWP() g = other.get_SRWP() g0 = other.get_SPWP() for elm in A: if elm in fixed_points(f): if f0(elm) in fixed_points(g): dic_h0[elm] = g0(f0(elm)) dic_h[elm] = elm else: dic_h[elm] = inverse(f0)(g(f0(elm))) else: dic_h[elm] = f(elm) h = FiniteSetMaps(A, A).from_dict(dic_h) h0 = FiniteSetMaps(CombinatorialScalarWrapper(dic_h0.keys()), C).from_dict(dic_h0) return ReductionMaps(A, C, h, h0)
def matrix_combinatorial_adjoint(mat): r""" Return Combinatorial Adjoint. """ dim = mat.nrows() M = list() mat_space = MatrixSpace(CombinatorialScalarRing(), dim) prnt = mat_space.base_ring() #create list L of lists of sets, dimension is increased by one to mitigate index confusion L = list() for i in range(dim + 1): L.append(list()) for j in range(dim + 1): L[i].append(set()) P = Permutations(dim) for p in P: p_comb = CombinatorialScalarWrapper( [CombinatorialObject(p, p.signature())]) l = list() for i in range(1, dim + 1): l.append(mat[p(i) - 1, i - 1]) #This list will have empty sets, which will yield to an empty cartesian product #especially when the matrix input is triangular (except for the identity permutation). #We will now iterate through the selected entries in each column #and create a set of a singleton of an empty string that corresponds #to the "missing" element of the tuple described in definition 39. for i in range(1, dim + 1): copy_l = copy(l) copy_l[i - 1] = CombinatorialScalarWrapper( [CombinatorialObject('_', 1)]) cp = CartesianProduct(p_comb, *copy_l) for tupel in cp: tupel = tuple(tupel) tupel_weight = 1 tupel_sign = 1 for elm in tupel: tupel_sign = tupel_sign * elm.get_sign() tupel_weight = tupel_weight * elm.get_weight() L[i][p(i)].add( CombinatorialObject(tupel, tupel_sign, tupel_weight)) #turn these sets into CombinatorialScalars for i in range(1, dim + 1): l = list() for j in range(1, dim + 1): l.append(CombinatorialScalarWrapper(L[i][j])) M.append(l) return mat_space(M)
def fixed_points(func): r""" Returns the Combinatorial Scalar of the fixed points of a map. """ S = set() for i in func.domain(): if func(i) == i: S.add(i) return CombinatorialScalarWrapper(S)
def _product_row(mat1, mat2, row): dim = mat1.nrows() r = list() for j in range(dim): C = CombinatorialScalarWrapper(set()) for k in range(dim): C = C + (mat1[row, k] * mat2[k, j]) for elm in C: elm.set_row(row) elm.set_col(j) r.append(C) return r
def reduction_identity_matrix(mat,st=None,involution_dict=None): r""" When a matrix reduces to the identity, this returns a ReductionMapDict of from a matrix to I. """ dim = mat.nrows() if involution_dict is None: fs = _involution_dict(mat) else: fs = involution_dict f0s = dict() I = identity_matrix(dim) for i in range(dim): for j in range(dim): if i==j: tmp = CombinatorialScalarWrapper(set(fixed_points(fs[i,j]))) f0s[i,j] = FiniteSetMaps(tmp,I[i,j]).from_dict({tmp.get_set().pop():CombinatorialObject(1,1)}) else: f0s[i,j] = FiniteSetMaps(set(),set()).from_dict({}) d = dict() for i in range(dim): for j in range(dim): d[i,j] = ReductionMaps(mat[i,j],I[i,j],fs[i,j],f0s[i,j]) return ReductionMapsDict(d,st)
def matrix_clean_up(mat): r""" Apply get_cleaned_up_version to each object within each entry and return a cleaned up matrix """ dim = mat.nrows() L = list() mat_space = MatrixSpace(CombinatorialScalarRing(), dim) prnt = mat_space.base_ring() for i in range(dim): L.append(list()) for j in range(dim): L[i].append( CombinatorialScalarWrapper(mat[i, j].get_cleaned_up_version())) return mat_space(L)
def matrix_determinant(mat): r""" Return determinant scalar, the form of which is: (\sigma,a_1,...,a_n) where sign \sigma is sgn(\sigma) and weight \sigma is 1. """ dim = mat.nrows() P = Permutations(dim) S = set() for p in P: l = list() p_comb = CombinatorialScalarWrapper( [CombinatorialObject(p, p.signature())]) for i in range(1, dim + 1): l.append(mat[i - 1, p(i) - 1]) cp = CartesianProduct(p_comb, *l) for i in cp: weight = 1 sign = 1 for elm in i: sign = sign * elm.get_sign() weight = weight * elm.get_weight() S.add(CombinatorialObject(tuple(i), sign, weight)) return CombinatorialScalarWrapper(S)
def matrix_identity_multiply_scalar(scal, nrows, ncols): r""" Currently this method only returns for the same number of rows and columns. """ if nrows != ncols: raise ValueError, "check dimensions" else: L = list() for i in range(nrows): L.append(list()) for j in range(ncols): if i == j: L[i].append(scal) else: L[i].append(CombinatorialScalarWrapper(set())) return matrix(CombinatorialScalarRing(), nrows, ncols, L)
def confluence(self, other=None): r""" Returns the reduction of C to B, where the usage is: r1.confluence(r2), and r1 maps A to B, B fully cancelled, and r2 maps A to C. """ if other is None: raise ValueError, "Enter a redution map as a parameter" elif self.get_A() != other.get_A(): raise ValueError, """ "A" """ " sets have to match" elif not (self.get_B().is_fully_cancelled()): raise ValueError, """ "B" """ " on the left is not fully cancelled" else: dic_h = dict() dic_h0 = dict() A = self.get_A() B = self.get_B() C = other.get_B() f = self.get_SRWP() f0 = self.get_SPWP() g = other.get_SRWP() g0 = other.get_SPWP() fxd_f = fixed_points(self.get_SRWP()) fxd_g = fixed_points(other.get_SRWP()) for c in C: x = inverse(g0)(c) while True: if x in fxd_f: #a fixed point of h dic_h[c] = c dic_h0[c] = f0(x) break else: x = f(x) if x in fxd_g: #not a fixed point of h dic_h[c] = g0(x) break else: x = g(x) h = FiniteSetMaps(C, C).from_dict(dic_h) h0 = FiniteSetMaps(CombinatorialScalarWrapper(dic_h0.keys()), B).from_dict(dic_h0) return ReductionMaps(C, B, h, h0)
def reduction_lemma_28_68(mat, red_adjAA_to_I, st = "an application of lemma 28, reduction_68"): r""" Because only one matrix here has a nontrivial SRWP map, we need not apply the formal indexing given in the proof of lemma 28. Simply enter a matrix (adj_AA)BA and the reduction of adj_AA to I. """ d = dict() dim = mat.nrows() for i in range(dim): for j in range(dim): dic_f = dict() dic_f0 = dict() newset = set() for elm in mat[i,j]: #break tuple apart tmp0 = elm.get_object()[0] tmp1 = elm.get_object()[1] tmp2 = elm.get_object()[2] row = tmp0.get_row() col = tmp0.get_col() f_row_col = red_adjAA_to_I[row,col].get_SRWP() f0_row_col = red_adjAA_to_I[row,col].get_SPWP() #assign map tmp = f_row_col(tmp0) sign = tmp.get_sign()*tmp1.get_sign()*tmp2.get_sign() weight = tmp.get_weight()*tmp1.get_weight()*tmp2.get_weight() dic_f[elm] = CombinatorialObject((tmp,tmp1,tmp2),sign,weight) if tmp in fixed_points(f_row_col): tmpfxd = CombinatorialObject((f0_row_col(tmp0),tmp1,tmp2),elm.get_sign(),elm.get_weight()) dic_f0[elm] = tmpfxd newset.add(tmpfxd) f = FiniteSetMaps(mat[i,j],mat[i,j]).from_dict(dic_f) f0 = FiniteSetMaps(dic_f0.keys(),newset).from_dict(dic_f0) d[i,j] = ReductionMaps(mat[i,j],CombinatorialScalarWrapper(newset),f,f0) return ReductionMapsDict(d,st)
def not_fixed_points(func): r""" Returns the Combinatorial Scalar of the non-fixed points of a map. """ return CombinatorialScalarWrapper(set(func.domain()).difference(fixed_points(func)))