Combinatorics quickref - Combinatorics

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

# Combinatorics quickref

Integer Sequences:

Sage

    sage: s = oeis([1,3,19,211]); s                         # optional - internet
    0: A000275: ...
    sage: s[0].programs()                                   # optional - internet
    [('maple', ...),
     ('mathematica', ...),
     ('pari',
      0: {a(n) = if( n<0, 0, n!^2 * 4^n * polcoeff( 1 / besselj(0, x + x * O(x^(2*n))), 2*n))}; /* _Michael Somos_, May 17 2004 */)]

Python

    >>> from sage.all import *
    >>> s = oeis([Integer(1),Integer(3),Integer(19),Integer(211)]); s                         # optional - internet
    0: A000275: ...
    >>> s[Integer(0)].programs()                                   # optional - internet
    [('maple', ...),
     ('mathematica', ...),
     ('pari',
      0: {a(n) = if( n<0, 0, n!^2 * 4^n * polcoeff( 1 / besselj(0, x + x * O(x^(2*n))), 2*n))}; /* _Michael Somos_, May 17 2004 */)]

Combinatorial objects:

Sage

    sage: S = Subsets([1,2,3,4]); S.list(); S.<tab>                       # not tested
    sage: P = Partitions(10000); P.cardinality()                                        # needs sage.libs.flint
    3616...315650422081868605887952568754066420592310556052906916435144
    sage: Combinations([1,3,7]).random_element()            # random
    sage: Compositions(5, max_part=3).unrank(3)
    [2, 2, 1]

    sage: DyckWord([1,0,1,0,1,1,0,0]).to_binary_tree()                                  # needs sage.graphs
    [., [., [[., .], .]]]
    sage: Permutation([3,1,4,2]).robinson_schensted()
    [[[1, 2], [3, 4]], [[1, 3], [2, 4]]]
    sage: StandardTableau([[1, 4], [2, 5], [3]]).schuetzenberger_involution()
    [[1, 3], [2, 4], [5]]

[Python]

    >>> from sage.all import *
    >>> S = Subsets([Integer(1),Integer(2),Integer(3),Integer(4)]); S.list(); S.<tab>                       # not tested
    >>> P = Partitions(Integer(10000)); P.cardinality()                                        # needs sage.libs.flint
    3616...315650422081868605887952568754066420592310556052906916435144
    >>> Combinations([Integer(1),Integer(3),Integer(7)]).random_element()            # random
    >>> Compositions(Integer(5), max_part=Integer(3)).unrank(Integer(3))
    [2, 2, 1]

    >>> DyckWord([Integer(1),Integer(0),Integer(1),Integer(0),Integer(1),Integer(1),Integer(0),Integer(0)]).to_binary_tree()                                  # needs sage.graphs
    [., [., [[., .], .]]]
    >>> Permutation([Integer(3),Integer(1),Integer(4),Integer(2)]).robinson_schensted()
    [[[1, 2], [3, 4]], [[1, 3], [2, 4]]]
    >>> StandardTableau([[Integer(1), Integer(4)], [Integer(2), Integer(5)], [Integer(3)]]).schuetzenberger_involution()
    [[1, 3], [2, 4], [5]]

Constructions and Species:

Sage

    sage: for ps in cartesian_product([P,S]): print(ps) # not tested
    sage: def IV_3(n):
    ....:     return IntegerVectors(n, 3)
    sage: DisjointUnionEnumeratedSets(Family(IV_3, NonNegativeIntegers))  # not tested

Python

    >>> from sage.all import *
    >>> for ps in cartesian_product([P,S]): print(ps) # not tested
    >>> def IV_3(n):
    ...     return IntegerVectors(n, Integer(3))
    >>> DisjointUnionEnumeratedSets(Family(IV_3, NonNegativeIntegers))  # not tested

Words:

Sage

    sage: Words('abc', 4).list()
    [word: aaaa, ..., word: cccc]

    sage: Word('aabcacbaa').is_palindrome()
    True
    sage: WordMorphism('a->ab,b->a').fixed_point('a')
    word: abaababaabaababaababaabaababaabaababaaba...

[Python]

    >>> from sage.all import *
    >>> Words('abc', Integer(4)).list()
    [word: aaaa, ..., word: cccc]

    >>> Word('aabcacbaa').is_palindrome()
    True
    >>> WordMorphism('a->ab,b->a').fixed_point('a')
    word: abaababaabaababaababaabaababaabaababaaba...

Polytopes:

Sage

    sage: points = random_matrix(ZZ, 6, 3, x=7).rows()                                  # needs sage.modules
    sage: L = LatticePolytope(points)                                                   # needs sage.geometry.polyhedron sage.modules
    sage: L.n_points(); L.plot3d()                           # random                    # needs sage.geometry.polyhedron sage.modules sage.plot

Python

    >>> from sage.all import *
    >>> points = random_matrix(ZZ, Integer(6), Integer(3), x=Integer(7)).rows()                                  # needs sage.modules
    >>> L = LatticePolytope(points)                                                   # needs sage.geometry.polyhedron sage.modules
    >>> L.n_points(); L.plot3d()                           # random                    # needs sage.geometry.polyhedron sage.modules sage.plot

Root systems, Coxeter and Weyl groups:

Sage

    sage: WeylGroup(["B",3]).bruhat_poset()                                             # needs sage.graphs sage.modules
    Finite poset containing 48 elements
    sage: RootSystem(["A",2,1]).weight_lattice().plot()         # not tested            # needs sage.graphs sage.modules sage.plot

[Python]

    >>> from sage.all import *
    >>> WeylGroup(["B",Integer(3)]).bruhat_poset()                                             # needs sage.graphs sage.modules
    Finite poset containing 48 elements
    >>> RootSystem(["A",Integer(2),Integer(1)]).weight_lattice().plot()         # not tested            # needs sage.graphs sage.modules sage.plot

Crystals:

Sage

    sage: CrystalOfTableaux(["A",3], shape=[3,2]).some_flashy_feature()   # not tested

Python

    >>> from sage.all import *
    >>> CrystalOfTableaux(["A",Integer(3)], shape=[Integer(3),Integer(2)]).some_flashy_feature()   # not tested

`Symmetric functions and combinatorial Hopf algebras`:

Sage

    sage: Sym = SymmetricFunctions(QQ); Sym.inject_shorthands(verbose=False)            # needs sage.sage.modules
    sage: m( ( h[2,1] * (1 + 3 * p[2,1]) ) + s[2](s[3]) )                               # needs sage.sage.modules
    3*m[1, 1, 1] + ... + 10*m[5, 1] + 4*m[6]

[Python]

    >>> from sage.all import *
    >>> Sym = SymmetricFunctions(QQ); Sym.inject_shorthands(verbose=False)            # needs sage.sage.modules
    >>> m( ( h[Integer(2),Integer(1)] * (Integer(1) + Integer(3) * p[Integer(2),Integer(1)]) ) + s[Integer(2)](s[Integer(3)]) )                               # needs sage.sage.modules
    3*m[1, 1, 1] + ... + 10*m[5, 1] + 4*m[6]

Discrete groups, Permutation groups:

Sage

    sage: S = SymmetricGroup(4)                                                         # needs sage.groups
    sage: M = PolynomialRing(QQ, 'x0,x1,x2,x3')
    sage: M.an_element() * S.an_element()                                               # needs sage.groups
    x0

Python

    >>> from sage.all import *
    >>> S = SymmetricGroup(Integer(4))                                                         # needs sage.groups
    >>> M = PolynomialRing(QQ, 'x0,x1,x2,x3')
    >>> M.an_element() * S.an_element()                                               # needs sage.groups
    x0

Graph theory, posets, lattices (Graph Theory, Posets):

Sage

    sage: Poset({1: [2,3], 2: [4], 3: [4]}).linear_extensions().cardinality()           # needs sage.graphs sage.modules
    2

[Python]

    >>> from sage.all import *
    >>> Poset({Integer(1): [Integer(2),Integer(3)], Integer(2): [Integer(4)], Integer(3): [Integer(4)]}).linear_extensions().cardinality()           # needs sage.graphs sage.modules
    2