Macaulay2 » Documentation
Packages » Macaulay2Doc » The Macaulay2 language » lists and sequences » permutations
next | previous | forward | backward | up | index | toc

# permutations -- produce all permutations of a list

- Usage:
    `permutations x`
- Inputs:
  - x, a visible list or an integer
- Outputs:
  - a list of all the permutations of the visible list x, or, if x is an integer, of the list of integers from 0 through n-1

## Description

    i1 : permutations {a,b,c,d}

    o1 = {{a, b, c, d}, {a, b, d, c}, {a, c, b, d}, {a, c, d, b}, {a, d, b, c},
         ------------------------------------------------------------------------
         {a, d, c, b}, {b, a, c, d}, {b, a, d, c}, {b, c, a, d}, {b, c, d, a},
         ------------------------------------------------------------------------
         {b, d, a, c}, {b, d, c, a}, {c, a, b, d}, {c, a, d, b}, {c, b, a, d},
         ------------------------------------------------------------------------
         {c, b, d, a}, {c, d, a, b}, {c, d, b, a}, {d, a, b, c}, {d, a, c, b},
         ------------------------------------------------------------------------
         {d, b, a, c}, {d, b, c, a}, {d, c, a, b}, {d, c, b, a}}

    o1 : List

    i2 : permutations 3

    o2 = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2}, {1, 2, 0}, {2, 0, 1}, {2, 1, 0}}

    o2 : List

## Ways to use permutations:

- `permutations(VisibleList)`
- `permutations(ZZ)`

## For the programmer

The object permutations is a method function.

The source of this document is in /build/macaulay2-88fgJW/macaulay2-1.25.11+ds/M2/Macaulay2/packages/Macaulay2Doc/functions/permutations-doc.m2:17:0.