These are the solutions for the third set of homework problems homework 3


The reason that I am posting the solutions is because 100 people could do these problems and you will see 100 solutions. It is interesting to compare how they are all done.

Exercise 1:

I have the first solution to this problem (Farid).
def subset_to_monomial(SS,d):
    S=list(SS)
    vx=[var("x"+str(i)) for i in range(1,len(S)+2)]
    a=[]
    b=1
    for j in range(len(S)+1):
        if j==0:
            a.append(vx[j]^(S[j]-1))
        elif j>0 and j<=(len(S)-1):
            a.append(vx[j]^(S[j]-S[j-1]-1))
        else:
            a.append(vx[j]^(j+d-S[j-1]))
    for k in range(len(S)+1):
        b=b*a[k]
    return b
Second solution (Eric and Pavel).
def count_zeros(word):
    """
    This function counts the occurrences of 0's in a word.
    """
    out = 0
    for i in range(word.length()):
        if word[i] == 0:
            out = out+1
    return out

def list_all_monomials(n,k):
    """
    Generates a list of all monomials in n variables with
    degree k. The procedure uses binary strings of length
    n+k-1 with n-1 zeros to construct the monomials.

    EXAMPLES::

    sage: list_all_monomials(3,2)
    [x3^2, x2*x3, x2^2, x1*x3, x1*x2, x1^2]
    """
    vx =[var("x"+str(i)) for i in range(n+1)]
    s =[]
    for w in Words(alphabet=[0,1],length=n+k-1):
        if count_zeros(w)==n-1:
            mono=1
            j=1
            for i in range(w.length()):
                if w[i]== 1:
                    mono= mono*vx[j]
                else:
                    j=j+1
            s.append(mono)
    return s
Third solution (Sam).
ax = [var('a'+str(i)) for i in range(2^10)]
def subset_to_monomial(SS,d):
    return var('a1')^(SS[0]-1)*mul( ax[i+1]^( SS[i] - SS[i-1]-1) for i in range(1,len(SS)))*var( 'a'+str(len(SS)+1))^(d+(len(SS))-SS[len(SS)-1])
def list_all_monomials(n,d):
    return [subset_to_monomial(SS,d) for SS in Subsets(n+d-1, n-1)]
Fourth solution (Sirous).
def subset_to_monomial(SS,d):
    S=list(SS)
    vx=[var("x"+str(i)) for i in range(1,len(S)+2)]
    a=1
    for j in range(1,len(S)):
        a=a*(vx[j]^(S[j]-S[j-1]-1))
    b=vx[0]^(S[0]-1)*a*vx[len(S)]^(len(S)+d-S[len(S)-1])
    return b



Exercise 2:

(Farid).
def dihed_action(grouplet,poly,n):
    S=Set(list(poly))
    a=[]
    b=0
    while len(S)>0:
        g=S[0]
        c={(g[0],g[1])}
        a=(multi(grouplet ,(g[0],g[1]),n))
        S=S.difference(c)
        b=b+a
    return b



Exercise 3:

(Farid).
def dihed_char(deg,grouplet,n):
    coef =[]
    actout =[]
    char =0
    for i in range(deg+1):
        actout.append(dihed_action(grouplet,(a[0]^i)*(a[1]^(deg-i)),n))
        if actout[i].degree(a[0])==i and actout[i].degree(a[1])==deg-i:
            coef.append(actout[i].coefficients())
    for j in range(len(coef)):
        SS=Set(coef[j])
        char=char+SS[0]
    return char



Exercise 4:

(Farid). There is a longer solution to this problem posted.