---
language: sage
category: Mathematics / Combinatorics
---
title: Introduction
descr: |
This goes through some of the basic functionalities regarding combinatorics.
Check out these resources for more in-depth information:
* [Tutorial/Combinatorics](http://doc.sagemath.org/html/en/reference/combinat/sage/combinat/tutorial.html)
* [Reference/Combinatorics](http://doc.sagemath.org/html/en/reference/combinat/index.html)
* [Reference/Graph Theory](http://doc.sagemath.org/html/en/reference/graphs/index.html)
code: ""
---
title: Permutations
descr: >
SageMath offers various way to construct and work with [Permutations](http://doc.sagemath.org/html/en/reference/combinat/sage/combinat/permutation.html).
code: |
p = Permutation([2,3,7,4,5,6,1])
p.left_tableau()
p.longest_increasing_subsequences()
p.complement()
p.peaks()
p.retract_okounkov_vershik(6)
p.saliances()
# and many more: http://doc.sagemath.org/html/en/reference/combinat/sage/combinat/permutation.html
---
title: Cartesian Product
descr: |
Build a [cartesian product](http://doc.sagemath.org/html/en/reference/combinat/sage/combinat/cartesian_product.html) of sets.
code: |
S1 = Permutations(3)
S2 = ['A', 'B']
cp = cartesian_product([S1, S2])
cp
cp.cardinality()
cp.list()
---
title: Finite State Machine
descr: |
Transitions and a plot of a [Finite State Machine](http://doc.sagemath.org/html/en/reference/combinat/sage/combinat/finite_state_machine.html)
code: |
fsm = Automaton([(0, 0, 0), (0, 1, 1), (0, 0, 2), (1, 2, 2), (2, 0, 0)], initial_states=[0, 1, 2], final_states=[0, 1])
for transition in fsm.accessible_components().transitions():
print transition
fsm.plot()
---