from lie_algebra_multiplicity import *
def WeightsWithMultiplicity1InG2(l):
    tot = 3 * l - 1
    if tot < 0:
        return []
    else:
        m1 = 0
        m2 = 0
        solns = []
        if tot % 3 == 0:
            m2 = tot / 3
        elif tot % 3 == 1:
            m1 = 2
            m2 = (tot - 4) / 3
        elif tot % 3 == 2:
            m1 = 1
            m2 = (tot - 2) / 3
        
        while m1 >= 0 and m2 >= 0:
            solns.append([m1,m2])
            m1 += 3
            m2 -= 2
            
        return solns
    
def getAltSetsG(l):
    weights = WeightsWithMultiplicity1InG2(l)
    altsets = [findAltSet("G2", lamb = [0, l], mu = weight, simple = False) for weight in weights]
    return altsets

def multCheckG(l):
    weights = WeightsWithMultiplicity1InG2(l)
    mults = [calculateMultiplicity("G2", lamb = [0,l], mu = weight, q_analog = True, simple=False) for weight in weights]
    return mults
    
    
test = 1
print WeightsWithMultiplicity1InG2(test)
print getAltSetsG(test)
print multCheckG(test)
[[1, 0]] [[1, s1]] [q^2]
#getAltSetsG(1000)
from lie_algebra_multiplicity import *
def noElementsGreaterThan(arr, maxVal):
    for i in arr:
        if i > maxVal:
            return False
        
    return True

def countIndices(partition, r):
    ret = [0 for i in range(0,r)]
    for i in partition:
        ret[i-1] += 1
        
    return ret

def WeightsWithMultiplicity1InA(r, l):
    mod = r+1
    multiple = l / mod
    distance = l % mod
    all_weights = []
    
    while multiple >= 0:
        partitions = [partition for partition in Partitions(distance).list() if noElementsGreaterThan(partition, r)]
        weights = [countIndices(partition, r) for partition in partitions]
        all_weights = all_weights + weights  # this is not the best way, but I'll fix it later
        multiple -= 1
        distance += mod
        
    return all_weights

def getAltSetsA(r, l):
    weights = WeightsWithMultiplicity1InA(r, l)
    altsets = [findAltSet("A" + str(r), lamb = [l], mu = weight, simple = False) for weight in weights]
    return altsets

def multCheckA(r, l):
    weights = WeightsWithMultiplicity1InA(r, l)
    mults = [calculateMultiplicity("A" + str(r), lamb = [l], mu = weight, q_analog = True, simple=False) for weight in weights]
    return mults
        
test_l = 10
test_r = 6
print WeightsWithMultiplicity1InA(test_r, test_l)
#print multCheckA(test_r, test_l)
print getAltSetsA(test_r, test_l)
[[0, 0, 1, 0, 0, 0], [1, 1, 0, 0, 0, 0], [3, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 1], [1, 0, 1, 0, 0, 1], [0, 2, 0, 0, 0, 1], [2, 1, 0, 0, 0, 1], [4, 0, 0, 0, 0, 1], [0, 0, 0, 0, 2, 0], [1, 0, 0, 1, 1, 0], [0, 1, 1, 0, 1, 0], [2, 0, 1, 0, 1, 0], [1, 2, 0, 0, 1, 0], [3, 1, 0, 0, 1, 0], [5, 0, 0, 0, 1, 0], [0, 1, 0, 2, 0, 0], [2, 0, 0, 2, 0, 0], [0, 0, 2, 1, 0, 0], [1, 1, 1, 1, 0, 0], [3, 0, 1, 1, 0, 0], [0, 3, 0, 1, 0, 0], [2, 2, 0, 1, 0, 0], [4, 1, 0, 1, 0, 0], [6, 0, 0, 1, 0, 0], [1, 0, 3, 0, 0, 0], [0, 2, 2, 0, 0, 0], [2, 1, 2, 0, 0, 0], [4, 0, 2, 0, 0, 0], [1, 3, 1, 0, 0, 0], [3, 2, 1, 0, 0, 0], [5, 1, 1, 0, 0, 0], [7, 0, 1, 0, 0, 0], [0, 5, 0, 0, 0, 0], [2, 4, 0, 0, 0, 0], [4, 3, 0, 0, 0, 0], [6, 2, 0, 0, 0, 0], [8, 1, 0, 0, 0, 0], [10, 0, 0, 0, 0, 0]] [[1, s2, s3, s4, s5, s6, s2*s3, s4*s2, s5*s2, s6*s2, s3*s2, s3*s4, s5*s3, s6*s3, s4*s3, s4*s5, s6*s4, s5*s4, s5*s6, s2*s3*s2, s2*s3*s4, s5*s2*s3, s6*s2*s3, s4*s2*s3, s4*s5*s2, s6*s4*s2, s5*s4*s2, s5*s6*s2, s3*s4*s2, s5*s3*s2, s6*s3*s2, s3*s4*s3, s3*s4*s5, s6*s3*s4, s5*s3*s4, s5*s6*s3, s4*s3*s2, s4*s5*s3, s6*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*s2, s5*s3*s4*s2, s5*s6*s3*s2, s3*s4*s3*s2, s3*s4*s5*s3, s6*s3*s4*s3, s3*s4*s5*s4, s3*s4*s5*s6, s6*s4*s3*s2, s2*s3*s4*s2*s3, s2*s3*s4*s5*s2, s6*s2*s3*s4*s2, s5*s2*s3*s4*s2, s5*s6*s2*s3*s2, s2*s3*s4*s3*s2, s2*s3*s4*s5*s3, s6*s2*s3*s4*s3, s2*s3*s4*s5*s4, s2*s3*s4*s5*s6, s6*s4*s2*s3*s2, s3*s4*s2*s3*s2, s6*s3*s4*s2*s3, s3*s4*s5*s4*s2, s6*s3*s4*s3*s2, s2*s3*s4*s2*s3*s2, s6*s2*s3*s4*s2*s3, s2*s3*s4*s5*s4*s2, s6*s2*s3*s4*s3*s2, s6*s3*s4*s2*s3*s2, s6*s2*s3*s4*s2*s3*s2], [1, s2, s3, s4, s5, s2*s3, s4*s2, s5*s2, s3*s2, s3*s4, s5*s3, s4*s3, s4*s5, s2*s3*s2, s2*s3*s4, s5*s2*s3, s4*s2*s3, s4*s5*s2, s3*s4*s2, s5*s3*s2, s3*s4*s3, s3*s4*s5, s2*s3*s4*s2, s5*s2*s3*s2, s2*s3*s4*s3, s2*s3*s4*s5, s3*s4*s2*s3, s3*s4*s5*s2, s2*s3*s4*s2*s3, s2*s3*s4*s5*s2], [1, s2, s3, s4, s5, s2*s3, s4*s2, s5*s2, s3*s2, s3*s4, s5*s3, s4*s3, s4*s5, s2*s3*s2, s2*s3*s4, s5*s2*s3, s4*s2*s3, s4*s5*s2, s3*s4*s2, s5*s3*s2, s3*s4*s3, s3*s4*s5, s2*s3*s4*s2, s5*s2*s3*s2, s2*s3*s4*s3, s2*s3*s4*s5], [1, s2, s3, s4, s5, s2*s3, s4*s2, s5*s2, s3*s2, s3*s4, s5*s3, s4*s3, s4*s5, s2*s3*s2, s2*s3*s4, s5*s2*s3, s4*s2*s3, s4*s5*s2, s3*s4*s2, s5*s3*s2, s3*s4*s3, s3*s4*s5, s2*s3*s4*s2, s5*s2*s3*s2, s2*s3*s4*s3, s2*s3*s4*s5], [1, s2, s3, s4, s5, s2*s3, s4*s2, s5*s2, s3*s2, s3*s4, s5*s3, s4*s3, s4*s5, s2*s3*s2, s2*s3*s4, s5*s2*s3, s4*s2*s3, s4*s5*s2, s3*s4*s2, s5*s3*s2, s3*s4*s3, s3*s4*s5, s2*s3*s4*s2, s5*s2*s3*s2, s2*s3*s4*s3, s2*s3*s4*s5], [1, s2, s3, s4, s5, s2*s3, s4*s2, s5*s2, s3*s2, s3*s4, s5*s3, s4*s3, s4*s5, s2*s3*s2, s2*s3*s4, s5*s2*s3, s4*s2*s3, s4*s5*s2, s3*s4*s2, s5*s3*s2, s3*s4*s3, s3*s4*s5, s2*s3*s4*s2, s5*s2*s3*s2, s2*s3*s4*s3, s2*s3*s4*s5], [1, s2, s3, s4, s2*s3, s4*s2, s3*s2, s3*s4, s4*s3, s2*s3*s2, s2*s3*s4, s4*s2*s3, s3*s4*s2, s3*s4*s3, s2*s3*s4*s2, s2*s3*s4*s3, s3*s4*s2*s3, s2*s3*s4*s2*s3], [1, s2, s3, s4, s2*s3, s4*s2, s3*s2, s3*s4, s2*s3*s2, s2*s3*s4, s3*s4*s2, s2*s3*s4*s2], [1, s2, s3, s4, s2*s3, s4*s2, s3*s2, s3*s4, s2*s3*s2, s2*s3*s4], [1, s2, s3, s4, s2*s3, s4*s2, s3*s2, s3*s4, s2*s3*s2, s2*s3*s4], [1, s2, s3, s4, s2*s3, s4*s2, s3*s2, s3*s4, s2*s3*s2, s2*s3*s4], [1, s2, s3, s4, s2*s3, s4*s2, s3*s2, s3*s4, s2*s3*s2, s2*s3*s4], [1, s2, s3, s4, s2*s3, s4*s2, s3*s2, s3*s4, s2*s3*s2, s2*s3*s4], [1, s2, s3, s2*s3, s3*s2, s2*s3*s2], [1, s2, s3, s2*s3, s3*s2, s2*s3*s2], [1, s2, s3, s2*s3], [1, s2, s3, s2*s3], [1, s2, s3, s2*s3], [1, s2, s3, s2*s3], [1, s2, s3, s2*s3], [1, s2, s3, s2*s3], [1, s2, s3, s2*s3], [1, s2], [1, s2], [1, s2], [1, s2], [1, s2], [1, s2], [1, s2], [1, s2], [1], [1], [1], [1], [1], [1]]




def allEvenElements(arr):
    for i in arr:
        if i % 2 == 1:
            return False
        
    return True

def WeightsWithMultiplicity1InB(r, l):
    if r < 2:
        return []
    tot = l - 1
    m_r = int((tot * 2) / r)
    m_r = m_r if m_r % 2 == 0 else m_r - 1
    all_weights = []
    
    while m_r >= 0:
        sub_tot = int(tot - ((r * m_r)/2)) # this is always an integer, but sage automatically casts some things and causes issues with partitioning
        partitions = [partition for partition in Partitions(sub_tot).list() if noElementsGreaterThan(partition, r-1)]
        weights = [countIndices(partition, r-1) for partition in partitions]
        weights = [weight + [m_r] for weight in weights if allEvenElements(weight)]
        all_weights = all_weights + weights  # this is not the best way, but I'll fix it later
        m_r -= 2
        
    return all_weights

def getAltSetsB(r, l):
    weights = WeightsWithMultiplicity1InB(r, l)
    altsets = [findAltSet("B" + str(r), lamb = [l], mu = weight, simple = False) for weight in weights]
    return altsets

def multCheckB(r, l):
    weights = WeightsWithMultiplicity1InB(r, l)
    mults = [calculateMultiplicity("B" + str(r), lamb = [l], mu = weight, q_analog = False, simple=False) for weight in weights]
    return mults

test_r = 7
test_l = 11
print WeightsWithMultiplicity1InB(test_r, test_l)
#print multCheckB(test_r, test_l)
print getAltSetsB(test_r, test_l)
[[0, 0, 0, 0, 2, 0, 0], [2, 0, 0, 2, 0, 0, 0], [0, 2, 2, 0, 0, 0, 0], [4, 0, 2, 0, 0, 0, 0], [2, 4, 0, 0, 0, 0, 0], [6, 2, 0, 0, 0, 0, 0], [10, 0, 0, 0, 0, 0, 0]] [[1, s2, s3, s4, s5, s6, s7, s2*s3, s4*s2, s5*s2, s6*s2, s7*s2, s3*s2, s3*s4, s5*s3, s6*s3, s7*s3, s4*s3, s4*s5, s6*s4, s7*s4, s7*s5, s2*s3*s2, s2*s3*s4, s5*s2*s3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s3, s6*s2*s3*s4*s2*s3*s2, s7*s2*s3*s4*s2*s3*s2, s7*s2*s3*s4*s5*s2*s3], [1, s2, s3, s4, s5, s6, s7, s2*s3, s4*s2, s5*s2, s6*s2, s7*s2, s3*s2, s3*s4, s5*s3, s6*s3, s7*s3, s6*s4, s7*s4, s7*s5, s2*s3*s2, s2*s3*s4, s5*s2*s3, s6*s2*s3, s7*s2*s3, s6*s4*s2, s7*s4*s2, s7*s5*s2, s3*s4*s2, s5*s3*s2, s6*s3*s2, s7*s3*s2, s6*s3*s4, s7*s3*s4, s7*s5*s3, s2*s3*s4*s2, s5*s2*s3*s2, s6*s2*s3*s2, s7*s2*s3*s2, s6*s2*s3*s4, s7*s2*s3*s4, s7*s5*s2*s3, s6*s3*s4*s2, s7*s3*s4*s2, s7*s5*s3*s2, s6*s2*s3*s4*s2, s7*s2*s3*s4*s2, s7*s5*s2*s3*s2], [1, s2, s3, s4, s5, s6, s7, s2*s3, s4*s2, s5*s2, s6*s2, s7*s2, s5*s3, s6*s3, s7*s3, s6*s4, s7*s4, s7*s5, s5*s2*s3, s6*s2*s3, s7*s2*s3, s6*s4*s2, s7*s4*s2, s7*s5*s2, s7*s5*s3, s7*s5*s2*s3], [1, s2, s3, s4, s5, s6, s7, s2*s3, s4*s2, s5*s2, s6*s2, s7*s2, s5*s3, s6*s3, s7*s3, s6*s4, s7*s4, s7*s5, s5*s2*s3, s6*s2*s3, s7*s2*s3, s6*s4*s2, s7*s4*s2, s7*s5*s2, s7*s5*s3, s7*s5*s2*s3], [1, s2, s3, s4, s5, s6, s7, s4*s2, s5*s2, s6*s2, s7*s2, s5*s3, s6*s3, s7*s3, s6*s4, s7*s4, s7*s5, s6*s4*s2, s7*s4*s2, s7*s5*s2, s7*s5*s3], [1, s2, s3, s4, s5, s6, s7, s4*s2, s5*s2, s6*s2, s7*s2, s5*s3, s6*s3, s7*s3, s6*s4, s7*s4, s7*s5, s6*s4*s2, s7*s4*s2, s7*s5*s2, s7*s5*s3], [1, s2, s3, s4, s5, s6, s7, s4*s2, s5*s2, s6*s2, s7*s2, s5*s3, s6*s3, s7*s3, s6*s4, s7*s4, s7*s5, s6*s4*s2, s7*s4*s2, s7*s5*s2, s7*s5*s3]]