Combinatorics quickref¶
Integer Sequences:
sage: s = oeis([1,3,19,211]); s # optional - internet
0: A000275: Coefficients of a Bessel function (reciprocal of J_0(z));
also pairs of permutations with rise/rise forbidden.
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 */)]
>>> from sage.all import *
>>> s = oeis([Integer(1),Integer(3),Integer(19),Integer(211)]); s # optional - internet
0: A000275: Coefficients of a Bessel function (reciprocal of J_0(z));
also pairs of permutations with rise/rise forbidden.
>>> 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 */)]
s = oeis([1,3,19,211]); s # optional - internet s[0].programs() # optional - internet
Combinatorial objects:
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]]
>>> 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]]
S = Subsets([1,2,3,4]); S.list(); S.<tab> # not tested P = Partitions(10000); P.cardinality() # needs sage.libs.flint Combinations([1,3,7]).random_element() # random Compositions(5, max_part=3).unrank(3) DyckWord([1,0,1,0,1,1,0,0]).to_binary_tree() # needs sage.graphs Permutation([3,1,4,2]).robinson_schensted() StandardTableau([[1, 4], [2, 5], [3]]).schuetzenberger_involution()
Constructions and Species:
sage: for (p, s) in cartesian_product([P,S]): print((p, s)) # not tested
sage: def IV_3(n):
....: return IntegerVectors(n, 3)
sage: DisjointUnionEnumeratedSets(Family(IV_3, NonNegativeIntegers)) # not tested
>>> from sage.all import *
>>> for (p, s) in cartesian_product([P,S]): print((p, s)) # not tested
>>> def IV_3(n):
... return IntegerVectors(n, Integer(3))
>>> DisjointUnionEnumeratedSets(Family(IV_3, NonNegativeIntegers)) # not tested
for (p, s) in cartesian_product([P,S]): print((p, s)) # not tested def IV_3(n): return IntegerVectors(n, 3) DisjointUnionEnumeratedSets(Family(IV_3, NonNegativeIntegers)) # not tested
Words:
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...
>>> 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...
Words('abc', 4).list() Word('aabcacbaa').is_palindrome() WordMorphism('a->ab,b->a').fixed_point('a')
Polytopes:
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.npoints(); L.plot3d() # random # needs sage.geometry.polyhedron sage.modules sage.plot
>>> 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.npoints(); L.plot3d() # random # needs sage.geometry.polyhedron sage.modules sage.plot
points = random_matrix(ZZ, 6, 3, x=7).rows() # needs sage.modules L = LatticePolytope(points) # needs sage.geometry.polyhedron sage.modules L.npoints(); L.plot3d() # random # needs sage.geometry.polyhedron sage.modules sage.plot
Root systems, Coxeter and Weyl groups:
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
>>> 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
WeylGroup(["B",3]).bruhat_poset() # needs sage.graphs sage.modules RootSystem(["A",2,1]).weight_lattice().plot() # not tested # needs sage.graphs sage.modules sage.plot
sage: CrystalOfTableaux(["A",3], shape=[3,2]).some_flashy_feature() # not tested
>>> from sage.all import *
>>> CrystalOfTableaux(["A",Integer(3)], shape=[Integer(3),Integer(2)]).some_flashy_feature() # not tested
CrystalOfTableaux(["A",3], shape=[3,2]).some_flashy_feature() # not tested
Symmetric functions and combinatorial Hopf algebras
:
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]
>>> 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]
Sym = SymmetricFunctions(QQ); Sym.inject_shorthands(verbose=False) # needs sage.sage.modules m( ( h[2,1] * (1 + 3 * p[2,1]) ) + s[2](s[3]) ) # needs sage.sage.modules
Discrete groups, Permutation groups:
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
>>> 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
S = SymmetricGroup(4) # needs sage.groups M = PolynomialRing(QQ, 'x0,x1,x2,x3') M.an_element() * S.an_element() # needs sage.groups
Graph theory, posets, lattices (Graph Theory, Posets):
sage: Poset({1: [2,3], 2: [4], 3: [4]}).linear_extensions().cardinality() # needs sage.graphs sage.modules
2
>>> 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
Poset({1: [2,3], 2: [4], 3: [4]}).linear_extensions().cardinality() # needs sage.graphs sage.modules