(***********************************************************************

                    Mathematica-Compatible Notebook

This notebook can be used on any computer system with Mathematica 4.0,
MathReader 4.0, or any compatible application. The data for the notebook 
starts with the line containing stars above.

To get the notebook into a Mathematica-compatible application, do one of 
the following:

* Save the data starting with the line of stars above into a file
  with a name ending in .nb, then open the file inside the application;

* Copy the data starting with the line of stars above to the
  clipboard, then use the Paste menu command inside the application.

Data for notebooks contains only printable 7-bit ASCII and can be
sent directly in email or through ftp in text mode.  Newlines can be
CR, LF or CRLF (Unix, Macintosh or MS-DOS style).

NOTE: If you modify the data for this notebook not in a Mathematica-
compatible application, you must delete the line below containing the 
word CacheID, otherwise Mathematica-compatible applications may try to 
use invalid cache data.

For more information on notebooks and Mathematica-compatible 
applications, contact Wolfram Research:
  web: http://www.wolfram.com
  email: info@wolfram.com
  phone: +1-217-398-0700 (U.S.)

Notebook reader applications are available free of charge from 
Wolfram Research.
***********************************************************************)

(*CacheID: 232*)


(*NotebookFileLineBreakTest
NotebookFileLineBreakTest*)
(*NotebookOptionsPosition[      9967,        308]*)
(*NotebookOutlinePosition[     13169,        410]*)
(*  CellTagsIndexPosition[     12889,        395]*)
(*WindowFrame->Normal*)



Notebook[{
Cell[TextData[{
  "DiscreteMath",
  StyleBox["`", "MB"],
  "Permutations",
  StyleBox["`", "MB"]
}], "Subsection",
  CellTags->{"S5.20.1", "1.1"}],

Cell[TextData[{
  "A permutation is a rule for rearranging a finite collection of elements. \
In this package, a permutation on ",
  Cell[BoxData[
      \(TraditionalForm\`n\)], "InlineFormula"],
  " elements is represented by a list containing the first ",
  Cell[BoxData[
      \(TraditionalForm\`n\)], "InlineFormula"],
  " positive integers. If the integer ",
  Cell[BoxData[
      \(TraditionalForm\`j\)], "InlineFormula"],
  " is in the ",
  Cell[BoxData[
      \(TraditionalForm\`i\^th\)], "InlineFormula"],
  " place in the list, this means that the permutation moves the ",
  Cell[BoxData[
      \(TraditionalForm\`i\^th\)], "InlineFormula"],
  " element to the ",
  Cell[BoxData[
      \(TraditionalForm\`j\^th\)], "InlineFormula"],
  " place. Thus, for example, ",
  Cell[BoxData[
      \(TraditionalForm\`{\)], "InlineFormula"],
  StyleBox["3,", "MR"],
  " ",
  StyleBox["1,", "MR"],
  " ",
  StyleBox["2", "MR"],
  Cell[BoxData[
      \(TraditionalForm\`}\)], "InlineFormula"],
  " represents the permutation that moves ",
  Cell[BoxData[
      \(TraditionalForm\`3\)], "InlineFormula"],
  " to ",
  Cell[BoxData[
      \(TraditionalForm\`2\)], "InlineFormula"],
  ", ",
  Cell[BoxData[
      \(TraditionalForm\`2\)], "InlineFormula"],
  " to ",
  Cell[BoxData[
      \(TraditionalForm\`1\)], "InlineFormula"],
  ", and ",
  Cell[BoxData[
      \(TraditionalForm\`1\)], "InlineFormula"],
  " to ",
  Cell[BoxData[
      \(TraditionalForm\`3\)], "InlineFormula"],
  ". "
}], "Text",
  CellTags->{"S5.20.1", "1.2"}],

Cell[BoxData[
    FormBox[
      StyleBox[
        FrameBox[
          StyleBox[GridBox[{
                {"\<\"\\!\\(\\*StyleBox[\\\"\\\\\\\"RandomPermutation[\\\\\\\"\
\\\", \\\"MR\\\"]\\)\\!\\(\\*StyleBox[\\\"\\\\\\\"n\\\\\\\"\\\", \
\\\"TI\\\"]\\)\\!\\(\\*StyleBox[\\\"\\\\\\\"]\\\\\\\"\\\", \\\"MR\\\"]\\) \
\"\>", "\<\"give a random permutation on \
\\!\\(\\*StyleBox[\\\"\\\\\\\"n\\\\\\\"\\\", \\\"TI\\\"]\\) elements\"\>"},
                {"\<\"\\!\\(\\*StyleBox[\\\"\\\\\\\"Ordering[\\\\\\\"\\\", \\\
\"MR\\\"]\\)\\!\\(\\*StyleBox[\\\"\\\\\\\"list\\\\\\\"\\\", \\\"TI\\\"]\\)\\!\
\\(\\*StyleBox[\\\"\\\\\\\"]\\\\\\\"\\\", \\\"MR\\\"]\\) \"\>", "\<\"give the \
permutation that puts the elements in \
\\!\\(\\*StyleBox[\\\"\\\\\\\"list\\\\\\\"\\\", \\\"TI\\\"]\\) in \
order\"\>"},
                {"\<\"\\!\\(\\*StyleBox[\\\"\\\\\\\"ToCycles[\\\\\\\"\\\", \\\
\"MR\\\"]\\)\\!\\(\\*StyleBox[\\\"\\\\\\\"perm\\\\\\\"\\\", \\\"TI\\\"]\\)\\!\
\\(\\*StyleBox[\\\"\\\\\\\"]\\\\\\\"\\\", \\\"MR\\\"]\\) \"\>", "\<\"give the \
cyclic decomposition of \\!\\(\\*StyleBox[\\\"\\\\\\\"perm\\\\\\\"\\\", \
\\\"TI\\\"]\\)\"\>"},
                {
                  
                  RowBox[{"\<\"\\!\\(\\*StyleBox[\\\"\\\\\\\"FromCycles[\\\\\\\
\"\\\", \\\"MR\\\"]\\)\"\>", 
                    StyleBox["{",
                      "InlineFormula"], 
                    StyleBox[
                      
                      SubscriptBox["\<\"\\!\\(\\*StyleBox[\\\"\\\\\\\"cyc\\\\\
\\\"\\\", \\\"TI\\\"]\\)\"\>", "1"],
                      
                      "InlineFormula"], \
"\<\"\\!\\(\\*StyleBox[\\\"\\\\\\\",\\\\\\\"\\\", \\\"MR\\\"]\\) \"\>", 
                    StyleBox[
                      
                      SubscriptBox["\<\"\\!\\(\\*StyleBox[\\\"\\\\\\\"cyc\\\\\
\\\"\\\", \\\"TI\\\"]\\)\"\>", "2"],
                      
                      "InlineFormula"], \
"\<\"\\!\\(\\*StyleBox[\\\"\\\\\\\",\\\\\\\"\\\", \\\"MR\\\"]\\) \[Ellipsis] \
\"\>", 
                    StyleBox["}",
                      
                      "InlineFormula"], \
"\<\"\\!\\(\\*StyleBox[\\\"\\\\\\\"]\\\\\\\"\\\", \\\"MR\\\"]\\) \"\>"}], \
\("give the permutation that has the given cyclic decomposition"\)},
                {"\<\"\\!\\(\\*StyleBox[\\\"\\\\\\\"PermutationQ[\\\\\\\"\\\",\
 \\\"MR\\\"]\\)\\!\\(\\*StyleBox[\\\"\\\\\\\"list\\\\\\\"\\\", \\\"TI\\\"]\\)\
\\!\\(\\*StyleBox[\\\"\\\\\\\"]\\\\\\\"\\\", \\\"MR\\\"]\\) \"\>", "\<\"give \
\\!\\(\\*StyleBox[\\\"\\\\\\\"True\\\\\\\"\\\", \\\"MR\\\"]\\) if \
\\!\\(\\*StyleBox[\\\"\\\\\\\"list\\\\\\\"\\\", \\\"TI\\\"]\\) represents a \
permutation, and \\!\\(\\*StyleBox[\\\"\\\\\\\"False\\\\\\\"\\\", \\\"MR\\\"]\
\\) otherwise\"\>"}
                },
              ColumnAlignments->{Right, Left}],
            GridBoxOptions->{RowLines->False}]],
        "2ColumnBox"], TraditionalForm]], "Text",
  CellTags->{"S5.20.1", "1.3"}],

Cell["Working with permutations. ", "Caption",
  CellTags->"S5.20.1"],

Cell[TextData[{
  "A cyclic permutation, or cycle, is a permutation in which any element can \
be moved to any other element by repeated application of the permutation. All \
permutations are not cycles, but it is a basic fact that any permutation can \
be decomposed into a product of cycles. This cyclic decomposition is \
represented as a list containing the cycles as sublists. \nCycles are \
represented differently than permutations. If the integer ",
  Cell[BoxData[
      \(TraditionalForm\`j\)], "InlineFormula"],
  " follows the integer ",
  Cell[BoxData[
      \(TraditionalForm\`i\)], "InlineFormula"],
  " in the sublist representing the cycle, this means that the cycle moves \
the ",
  Cell[BoxData[
      \(TraditionalForm\`i\^th\)], "InlineFormula"],
  " element to the ",
  Cell[BoxData[
      \(TraditionalForm\`j\^th\)], "InlineFormula"],
  " element. The sublist is treated cyclically so the last element is thought \
of as being before the first. As an example, ",
  StyleBox["{{1,", "MR"],
  " ",
  StyleBox["3,", "MR"],
  " ",
  StyleBox["2},", "MR"],
  " ",
  StyleBox["{5,", "MR"],
  " ",
  StyleBox["4}}", "MR"],
  " represents a permutation containing a cycle that sends ",
  Cell[BoxData[
      \(TraditionalForm\`1\)], "InlineFormula"],
  " to ",
  Cell[BoxData[
      \(TraditionalForm\`3\)], "InlineFormula"],
  ", ",
  Cell[BoxData[
      \(TraditionalForm\`3\)], "InlineFormula"],
  " to ",
  Cell[BoxData[
      \(TraditionalForm\`2\)], "InlineFormula"],
  ", and ",
  Cell[BoxData[
      \(TraditionalForm\`2\)], "InlineFormula"],
  " to ",
  Cell[BoxData[
      \(TraditionalForm\`1\)], "InlineFormula"],
  ", and a cycle that switches ",
  Cell[BoxData[
      \(TraditionalForm\`4\)], "InlineFormula"],
  " and ",
  Cell[BoxData[
      \(TraditionalForm\`5\)], "InlineFormula"],
  ". "
}], "Text",
  CellTags->{"S5.20.1", "1.4"}],

Cell["This loads the package. ", "MathCaption",
  CellTags->{"S5.20.1", "1.5"}],

Cell["<<DiscreteMath`Permutations`", "Input",
  CellLabel->"In[1]:= ",
  CellTags->"S5.20.1"],

Cell[TextData[{
  "Here is a randomly chosen permutation of ",
  Cell[BoxData[
      \(TraditionalForm\`10\)], "InlineFormula"],
  " elements. "
}], "MathCaption",
  CellTags->{"S5.20.1", "1.6"}],

Cell[CellGroupData[{

Cell["RandomPermutation[10]", "Input",
  CellLabel->"In[2]:= ",
  CellTags->"S5.20.1"],

Cell[BoxData[
    \({1, 9, 3, 10, 8, 6, 2, 7, 5, 4}\)], "Output",
  CellLabel->"Out[2]= ",
  CellTags->"S5.20.1"]
}, Open  ]],

Cell["This is the permutation's cyclic decomposition. ", "MathCaption",
  CellTags->{"S5.20.1", "1.7"}],

Cell[CellGroupData[{

Cell["ToCycles[%]", "Input",
  CellLabel->"In[3]:= ",
  CellTags->"S5.20.1"],

Cell[BoxData[
    \({{1}, {9, 5, 8, 7, 2}, {3}, {10, 4}, {6}}\)], "Output",
  CellLabel->"Out[3]= ",
  CellTags->"S5.20.1"]
}, Open  ]],

Cell["\<\
This transforms the cyclic decomposition back into a permutation. \
\
\>", "MathCaption",
  CellTags->{"S5.20.1", "1.8"}],

Cell[CellGroupData[{

Cell["FromCycles[%]", "Input",
  CellLabel->"In[4]:= ",
  CellTags->"S5.20.1"],

Cell[BoxData[
    \({1, 9, 3, 10, 8, 6, 2, 7, 5, 4}\)], "Output",
  CellLabel->"Out[4]= ",
  CellTags->"S5.20.1"]
}, Open  ]],

Cell["\<\
To transform the given list into one arranged in numerical order, \
you need to reverse the order of the elements. \
\>", "MathCaption",
  CellTags->{"S5.20.1", "1.9"}],

Cell[CellGroupData[{

Cell["Ordering[{4, 3, 2, 1}]", "Input",
  CellLabel->"In[5]:= ",
  CellTags->"S5.20.1"],

Cell[BoxData[
    \({4, 3, 2, 1}\)], "Output",
  CellLabel->"Out[5]= ",
  CellTags->"S5.20.1"]
}, Open  ]]
},
FrontEndVersion->"4.0 for X",
ScreenRectangle->{{0, 800}, {0, 600}},
WindowSize->{520, 455},
WindowMargins->{{140, Automatic}, {Automatic, 72}},
StyleDefinitions -> "HelpBrowser.nb"
]


(***********************************************************************
Cached data follows.  If you edit this Notebook file directly, not using
Mathematica, you must remove the line containing CacheID at the top of 
the file.  The cache data will then be recreated when you save this file 
from within Mathematica.
***********************************************************************)

(*CellTagsOutline
CellTagsIndex->{
  "S5.20.1"->{
    Cell[1717, 49, 146, 6, 70, "Subsection",
      CellTags->{"S5.20.1", "1.1"}],
    Cell[1866, 57, 1526, 50, 70, "Text",
      CellTags->{"S5.20.1", "1.2"}],
    Cell[3395, 109, 2899, 58, 70, "Text",
      CellTags->{"S5.20.1", "1.3"}],
    Cell[6297, 169, 69, 1, 70, "Caption",
      CellTags->"S5.20.1"],
    Cell[6369, 172, 1867, 56, 70, "Text",
      CellTags->{"S5.20.1", "1.4"}],
    Cell[8239, 230, 79, 1, 70, "MathCaption",
      CellTags->{"S5.20.1", "1.5"}],
    Cell[8321, 233, 93, 2, 70, "Input",
      CellTags->"S5.20.1"],
    Cell[8417, 237, 195, 6, 70, "MathCaption",
      CellTags->{"S5.20.1", "1.6"}],
    Cell[8637, 247, 86, 2, 70, "Input",
      CellTags->"S5.20.1"],
    Cell[8726, 251, 113, 3, 70, "Output",
      CellTags->"S5.20.1"],
    Cell[8854, 257, 103, 1, 70, "MathCaption",
      CellTags->{"S5.20.1", "1.7"}],
    Cell[8982, 262, 76, 2, 70, "Input",
      CellTags->"S5.20.1"],
    Cell[9061, 266, 123, 3, 70, "Output",
      CellTags->"S5.20.1"],
    Cell[9199, 272, 131, 4, 70, "MathCaption",
      CellTags->{"S5.20.1", "1.8"}],
    Cell[9355, 280, 78, 2, 70, "Input",
      CellTags->"S5.20.1"],
    Cell[9436, 284, 113, 3, 70, "Output",
      CellTags->"S5.20.1"],
    Cell[9564, 290, 178, 4, 70, "MathCaption",
      CellTags->{"S5.20.1", "1.9"}],
    Cell[9767, 298, 87, 2, 70, "Input",
      CellTags->"S5.20.1"],
    Cell[9857, 302, 94, 3, 70, "Output",
      CellTags->"S5.20.1"]},
  "1.1"->{
    Cell[1717, 49, 146, 6, 70, "Subsection",
      CellTags->{"S5.20.1", "1.1"}]},
  "1.2"->{
    Cell[1866, 57, 1526, 50, 70, "Text",
      CellTags->{"S5.20.1", "1.2"}]},
  "1.3"->{
    Cell[3395, 109, 2899, 58, 70, "Text",
      CellTags->{"S5.20.1", "1.3"}]},
  "1.4"->{
    Cell[6369, 172, 1867, 56, 70, "Text",
      CellTags->{"S5.20.1", "1.4"}]},
  "1.5"->{
    Cell[8239, 230, 79, 1, 70, "MathCaption",
      CellTags->{"S5.20.1", "1.5"}]},
  "1.6"->{
    Cell[8417, 237, 195, 6, 70, "MathCaption",
      CellTags->{"S5.20.1", "1.6"}]},
  "1.7"->{
    Cell[8854, 257, 103, 1, 70, "MathCaption",
      CellTags->{"S5.20.1", "1.7"}]},
  "1.8"->{
    Cell[9199, 272, 131, 4, 70, "MathCaption",
      CellTags->{"S5.20.1", "1.8"}]},
  "1.9"->{
    Cell[9564, 290, 178, 4, 70, "MathCaption",
      CellTags->{"S5.20.1", "1.9"}]}
  }
*)

(*CellTagsIndex
CellTagsIndex->{
  {"S5.20.1", 10592, 325},
  {"1.1", 12030, 364},
  {"1.2", 12124, 367},
  {"1.3", 12214, 370},
  {"1.4", 12305, 373},
  {"1.5", 12396, 376},
  {"1.6", 12491, 379},
  {"1.7", 12587, 382},
  {"1.8", 12683, 385},
  {"1.9", 12779, 388}
  }
*)

(*NotebookFileOutline
Notebook[{
Cell[1717, 49, 146, 6, 70, "Subsection",
  CellTags->{"S5.20.1", "1.1"}],
Cell[1866, 57, 1526, 50, 70, "Text",
  CellTags->{"S5.20.1", "1.2"}],
Cell[3395, 109, 2899, 58, 70, "Text",
  CellTags->{"S5.20.1", "1.3"}],
Cell[6297, 169, 69, 1, 70, "Caption",
  CellTags->"S5.20.1"],
Cell[6369, 172, 1867, 56, 70, "Text",
  CellTags->{"S5.20.1", "1.4"}],
Cell[8239, 230, 79, 1, 70, "MathCaption",
  CellTags->{"S5.20.1", "1.5"}],
Cell[8321, 233, 93, 2, 70, "Input",
  CellTags->"S5.20.1"],
Cell[8417, 237, 195, 6, 70, "MathCaption",
  CellTags->{"S5.20.1", "1.6"}],

Cell[CellGroupData[{
Cell[8637, 247, 86, 2, 70, "Input",
  CellTags->"S5.20.1"],
Cell[8726, 251, 113, 3, 70, "Output",
  CellTags->"S5.20.1"]
}, Open  ]],
Cell[8854, 257, 103, 1, 70, "MathCaption",
  CellTags->{"S5.20.1", "1.7"}],

Cell[CellGroupData[{
Cell[8982, 262, 76, 2, 70, "Input",
  CellTags->"S5.20.1"],
Cell[9061, 266, 123, 3, 70, "Output",
  CellTags->"S5.20.1"]
}, Open  ]],
Cell[9199, 272, 131, 4, 70, "MathCaption",
  CellTags->{"S5.20.1", "1.8"}],

Cell[CellGroupData[{
Cell[9355, 280, 78, 2, 70, "Input",
  CellTags->"S5.20.1"],
Cell[9436, 284, 113, 3, 70, "Output",
  CellTags->"S5.20.1"]
}, Open  ]],
Cell[9564, 290, 178, 4, 70, "MathCaption",
  CellTags->{"S5.20.1", "1.9"}],

Cell[CellGroupData[{
Cell[9767, 298, 87, 2, 70, "Input",
  CellTags->"S5.20.1"],
Cell[9857, 302, 94, 3, 70, "Output",
  CellTags->"S5.20.1"]
}, Open  ]]
}
]
*)




(***********************************************************************
End of Mathematica Notebook file.
***********************************************************************)

