def cardinality(self): """ Return the number of Lyndon words with the evaluation e. EXAMPLES:: sage: LyndonWords([]).cardinality() 0 sage: LyndonWords([2,2]).cardinality() 1 sage: LyndonWords([2,3,2]).cardinality() 30 Check to make sure that the count matches up with the number of Lyndon words generated:: sage: comps = [[],[2,2],[3,2,7],[4,2]] + Compositions(4).list() sage: lws = [LyndonWords(comp) for comp in comps] sage: all(lw.cardinality() == len(lw.list()) for lw in lws) True """ evaluation = self._e le = list(evaluation) if not evaluation: return Integer(0) n = sum(evaluation) return sum( moebius(j) * multinomial([ni // j for ni in evaluation]) for j in divisors(gcd(le))) // n
def cardinality(self): r""" Return the cardinality of ``self``. The number of ordered set partitions of a set of length `k` with composition shape `\mu` is equal to .. MATH:: \frac{k!}{\prod_{\mu_i \neq 0} \mu_i!}. EXAMPLES:: sage: OrderedSetPartitions(5,[2,3]).cardinality() 10 sage: OrderedSetPartitions(0, []).cardinality() 1 sage: OrderedSetPartitions(0, [0]).cardinality() 1 sage: OrderedSetPartitions(0, [0,0]).cardinality() 1 sage: OrderedSetPartitions(5, [2,0,3]).cardinality() 10 """ return multinomial(self.c)