Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

What you ask for corresponds to Lyndon words composed of distinct elements. Check this out:

n=4
m=3
G=Zmod(n)
CMB = [ tuple(map(G,w)) for w in LyndonWords(n,m) if len(set(w))==m ]
print( CMB )

What you ask for corresponds to Lyndon words composed of distinct elements. Check this out:

n=4
m=3
G=Zmod(n)
CMB = [ tuple(map(G,w)) for w in LyndonWords(n,m) if len(set(w))==m and w[0]==0 ]
print( CMB )

What you ask for corresponds to Lyndon words composed of distinct elements. Check this out:

n=4
m=3
G=Zmod(n)
CMB = [ tuple(map(G,w)) sorted(map(G,w)) for w in LyndonWords(n,m) if len(set(w))==m and w[0]==0 w[-1]==n ]
print( CMB )

What you ask for corresponds to Lyndon words composed of distinct elements. Check this out:

n=4
m=3
G=Zmod(n)
CMB = [ sorted(map(G,w)) for w in LyndonWords(n,m) if len(set(w))==m and w[-1]==n w[0]==1 ]
print( CMB )

What you ask for corresponds to Lyndon words composed of distinct elements. the differences between consecutive elements (summing to n). Check this out:

import itertools

n=4
m=3
G=Zmod(n)
CMB = [ sorted(map(G,w)) tuple(itertools.accumulate(map(G,w))) for w in LyndonWords(n,m) if len(set(w))==m and w[0]==1 sum(w)==n ]
print( CMB )

What you ask for corresponds to Lyndon words composed of the differences between consecutive elements (summing to n). Check this out:

import itertools

n=4
m=3
G=Zmod(n)

import itertools
CMB = [ tuple(itertools.accumulate(map(G,w))) for w in LyndonWords(n,m) if sum(w)==n ]
print( CMB )

Another possible solution:

def is_canonical(c):
    try:
        LyndonWord(c[i]-c[i-1] for i in range(len(c)))
    except ValueError:
        return False
    return True

CMB = list( filter(is_canonical, Combinations(G,m)) )
print( CMB )