Fast set partition iterators - Combinatorics

Skip to content
Back to top
View this page
Edit this page

# Fast set partition iterators

sage.combinat.set_partition_iterator.set_partition_iterator(base_set)

  A fast iterator for the set partitions of the base set, which returns lists of lists instead of set partitions types.

  EXAMPLES:

  Sage

      sage: from sage.combinat.set_partition_iterator import set_partition_iterator
      sage: list(set_partition_iterator([1,-1,x]))                                    # needs sage.symbolic
      [[[1, -1, x]],
       [[1, -1], [x]],
       [[1, x], [-1]],
       [[1], [-1, x]],
       [[1], [-1], [x]]]

  Python

      >>> from sage.all import *
      >>> from sage.combinat.set_partition_iterator import set_partition_iterator
      >>> list(set_partition_iterator([Integer(1),-Integer(1),x]))                                    # needs sage.symbolic
      [[[1, -1, x]],
       [[1, -1], [x]],
       [[1, x], [-1]],
       [[1], [-1, x]],
       [[1], [-1], [x]]]

sage.combinat.set_partition_iterator.set_partition_iterator_blocks(base_set, k)

  A fast iterator for the set partitions of the base set into the specified number of blocks, which returns lists of lists instead of set partitions types.

  EXAMPLES:

  Sage

      sage: from sage.combinat.set_partition_iterator import set_partition_iterator_blocks
      sage: list(set_partition_iterator_blocks([1,-1,x], 2))                          # needs sage.symbolic
      [[[1, x], [-1]], [[1], [-1, x]], [[1, -1], [x]]]

  Python

      >>> from sage.all import *
      >>> from sage.combinat.set_partition_iterator import set_partition_iterator_blocks
      >>> list(set_partition_iterator_blocks([Integer(1),-Integer(1),x], Integer(2)))                          # needs sage.symbolic
      [[[1, x], [-1]], [[1], [-1, x]], [[1, -1], [x]]]