Shared2 Mobius 2 Inversions.sagewsOpen in CoCalc
Mobius Inversions
from sage.combinat.subset import SubsetsSorted
from sage.combinat.posets.posets import FinitePoset
def leq(p,q):#leq for points in R^2
    if p[0]<=q[0] and p[1]<=q[1]:
        return True
    return False

def less(p,q):#strictly less than for points in R^2
    if p[0]<q[0] and p[1]<q[1]:
        return true
    return False

def isAntiChain(L):
    if any(leq(p,q) for p in L for q in L if p!=q):
        return False
    return True

def isDgm(T):#T is a tuple containing two tuples of points, the 0th being the tuple of minimal points and the 1st being the tuple of maximal points
    if len(T[0])==0 or len(T[1])==0:
        return False
    if T==(((0,1),(1,0)),((1,2),(2,1))):
        return False
    if all(any(less(p,q) for q in T[1]) for p in T[0]) and all(any(less(p,q) for p in T[0]) for q in T[1]) and isAntiChain(T[0]) and isAntiChain(T[1]):
        return True
    return False
def S(k):
    return [(x,y) for x in range(k) for y in range(k)]

def Dgm(k):
    return [(L,M) for L in SubsetsSorted(S(k)) for M in SubsetsSorted(S(k)) if isDgm((L,M))]

def leq_Dgm(S,T):
    if all(any(leq(q,p) for q in T[0]) for p in S[0]) and all(any(leq(p,q) for q in T[1]) for p in S[1]):
        return True
    return False
P=Poset((Dgm(3),leq_Dgm))
I=P.incidence_algebra(ZZ)
M=I.moebius().to_matrix()

v=vector([])
print M*v
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)