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 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 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 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)
Пример #5
0
 def __mul__(self, other):
     new_set = set()
     for s in self:
         for o in other:
             new_set.add(
                 CombinatorialObject((s, o),
                                     s.get_sign() * o.get_sign(),
                                     s.get_weight() * o.get_weight()))
     return CombinatorialScalarWrapper(new_set)
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 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 reduction_lemma_40(mat, st = "lemma 40"):
    r"""
    Returns the reduction of mat = adj_A times A
    to det_A times I.
    """
    dim = mat.nrows()
    d = dict()
    B = matrix_adjoint_lemma_40(mat)
    A = mat
    for i in range(dim):
        for j in range(dim):
            dic_f = dict()
            dic_f0 = dict()
            copyset = deepcopy(A[i,j].get_set())
            if i==j:
                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]
                    dic_f[elm] = elm
                    copyelm= deepcopy(elm)
                    dic_f0[elm] = copyelm.set_object(tuple(tmp))
                f0 = FiniteSetMaps(A[i,j],B[i,j]).from_dict(dic_f0)
            else:
                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()
                    p = tmp[0].get_object()
                    ii = i+1
                    jj = j+1
                    q = Permutation((ii,jj))
                    pq = q*p #p composed with q
                    tmp[0] = CombinatorialObject(pq,pq.signature())
                    elm_range2 = tmp[jj]
                    tmp[jj] = elm.get_object()[1]
                    sgn = 1
                    weight = 1
                    for flop in tmp:
                        sgn *= flop.get_sign()
                        weight *= flop.get_weight()
                    elm_range1 = CombinatorialObject(tuple(tmp),sgn,weight)
                    elm_range = CombinatorialObject((elm_range1,elm_range2),elm_range1.get_sign()*elm_range2.get_sign(),elm_range1.get_weight()*elm_range2.get_weight())
                    dic_f[elm] = elm_range
                f0 = FiniteSetMaps(set(),set()).from_dict({})
            f = FiniteSetMaps(A[i,j],A[i,j]).from_dict(dic_f)
            d[i,j] = ReductionMaps(A[i,j],B[i,j],f,f0)
    return ReductionMapsDict(d,st)
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)
Пример #10
0
 def _one(self):
     return CombinatorialScalarWrapper([CombinatorialObject(1, 1)])