Routines for combinatorics