(* Content-type: application/vnd.wolfram.mathematica *)

(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)

(* CreatedBy='Mathematica 8.0' *)

(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[       157,          7]
NotebookDataLength[     10647,        410]
NotebookOptionsPosition[      8007,        314]
NotebookOutlinePosition[      8450,        333]
CellTagsIndexPosition[      8407,        330]
WindowFrame->Normal*)

(* Beginning of Notebook Content *)
Notebook[{

Cell[CellGroupData[{
Cell["PwM`Chap07Recursion`", "Section",
 InitializationGroup->True],

Cell[TextData[{
 StyleBox["From",
  FontWeight->"Bold"],
 ": ",
 StyleBox[ButtonBox["Programming with Mathematica: An Introduction",
  BaseStyle->"Hyperlink",
  ButtonData->{
    URL["http://www.cambridge.org/wellin"], None},
  ButtonNote->"http://www.cambridge.org/wellin"],
  FontSlant->"Italic",
  FontVariations->{"Underline"->True}]
}], "Text",
 CellMargins->{{28, 10}, {7, 7}},
 FontSize->14],

Cell[CellGroupData[{

Cell["Metadata", "Subsection"],

Cell[BoxData[
 RowBox[{"(*", " ", 
  RowBox[{":", "Name", ":", " ", "PwM`Chap07Recursion`"}], " ", 
  "*)"}]], "Input"],

Cell[BoxData[
 RowBox[{"(*", " ", 
  RowBox[{":", 
   RowBox[{"Book", ":", " ", 
    RowBox[{"Programming", " ", "with", " ", 
     RowBox[{"Mathematica", ":", " ", 
      RowBox[{"An", " ", "Introduction"}]}]}]}]}], " ", "*)"}]], "Input"],

Cell[BoxData[
 RowBox[{"(*", " ", 
  RowBox[{":", 
   RowBox[{"Author", ":", " ", 
    RowBox[{"Paul", " ", "Wellin"}]}]}], " ", "*)"}]], "Input"],

Cell[BoxData[
 RowBox[{"(*", " ", 
  RowBox[{":", "Summary", ":", " ", 
   RowBox[{
   "This", " ", "package", " ", "contains", " ", "the", " ", "functions", " ",
     "defined", " ", "in", " ", "Chapter", " ", "7", " ", "Recursion"}]}], 
  " ", "*)"}]], "Input"],

Cell[BoxData[
 RowBox[{"(*", " ", 
  RowBox[{":", "Context", ":", " ", "PwM`Chap07Recursion`"}], " ", 
  "*)"}]], "Input"],

Cell[BoxData[
 RowBox[{"(*", " ", 
  RowBox[{":", 
   RowBox[{"Package", " ", 
    RowBox[{"Version", ":", " ", "1.0"}]}]}], " ", "*)"}]], "Input"],

Cell[BoxData[
 RowBox[{"(*", " ", 
  RowBox[{
   RowBox[{":", "Copyright", ":", " ", 
    RowBox[{"Copyright", " ", "2012"}]}], ",", " ", 
   RowBox[{"Paul", " ", 
    RowBox[{"R", ".", " ", "Wellin"}]}]}], " ", "*)"}]], "Input"],

Cell[BoxData[
 RowBox[{"(*", " ", 
  RowBox[{
   RowBox[{":", 
    RowBox[{"History", ":", " ", 
     RowBox[{
     "Version", " ", "1.0", " ", "by", " ", "Paul", " ", "Wellin"}]}]}], ",", 
   " ", 
   RowBox[{"Dec", " ", "2012"}]}], " ", "*)"}]], "Input"],

Cell[BoxData[
 RowBox[{"(*", " ", 
  RowBox[{
   RowBox[{":", 
    RowBox[{"Keywords", ":", " ", "autocorrelation"}]}], ",", " ", 
   RowBox[{"condition", " ", "number"}], ",", " ", "correlogram", ",", " ", 
   RowBox[{"digit", " ", "sum"}], ",", " ", "eigenvector", ",", " ", 
   RowBox[{"root", " ", "finding"}], ",", " ", 
   RowBox[{"lag", " ", "plot"}], ",", " ", 
   RowBox[{"radius", " ", "of", " ", "gyration"}], ",", " ", 
   RowBox[{"sparse", " ", "array"}], ",", " ", 
   RowBox[{"tridiagonal", " ", "matrix"}]}], " ", "*)"}]], "Input"],

Cell[BoxData[
 RowBox[{"(*", " ", 
  RowBox[{":", "Source", ":", " ", 
   RowBox[{"Chap07Recursion", ".", "nb"}]}], " ", "*)"}]], "Input"],

Cell[BoxData[
 RowBox[{"(*", " ", 
  RowBox[{":", 
   RowBox[{"Mathematica", " ", 
    RowBox[{"Version", ":", " ", 
     RowBox[{"8.0", ".4"}]}]}]}], " ", "*)"}]], "Input"]
}, Closed]],

Cell[CellGroupData[{

Cell["BeginPackage", "Subsection"],

Cell[BoxData[
 RowBox[{"BeginPackage", "[", "\"\<PwM`Chap07Recursion`\>\"", "]"}]], "Input"]
}, Closed]],

Cell[CellGroupData[{

Cell["Usage messages for public functions", "Subsection"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"EulerianNumber", "::", "usage"}], "=", 
   "\"\<EulerianNumber[n, k] returns the the number of permutations of the \
set {1,2,3,\[Ellipsis],n} with k increasing runs of elements.\>\""}], 
  ";"}]], "Input"]
}, Closed]],

Cell["Options", "Subsection"],

Cell[CellGroupData[{

Cell["Private context", "Subsection"],

Cell[BoxData[
 RowBox[{"Begin", "[", "\"\<`Private`\>\"", "]"}]], "Input"]
}, Closed]],

Cell[CellGroupData[{

Cell["Function definitions (public and private)", "Subsection"],

Cell[BoxData[{
 RowBox[{
  RowBox[{
   RowBox[{"EulerianNumber", "[", 
    RowBox[{"0", ",", "k_"}], "]"}], "=", "0"}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{"EulerianNumber", "[", 
    RowBox[{"n_Integer", ",", "0"}], "]"}], "=", "1"}], 
  ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{
    RowBox[{"EulerianNumber", "[", 
     RowBox[{"n_Integer", ",", "k_Integer"}], "]"}], "/;", 
    RowBox[{"k", "\[GreaterEqual]", "n"}]}], "=", "0"}], ";"}]}], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{"EulerianNumber", "[", 
   RowBox[{"n_Integer", ",", "k_Integer"}], "]"}], ":=", 
  RowBox[{"Block", "[", 
   RowBox[{
    RowBox[{"{", 
     RowBox[{"$RecursionLimit", "=", "Infinity"}], "}"}], ",", 
    "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"EulerianNumber", "[", 
      RowBox[{"n", ",", "k"}], "]"}], "=", 
     RowBox[{
      RowBox[{
       RowBox[{"(", 
        RowBox[{"k", "+", "1"}], ")"}], 
       RowBox[{"EulerianNumber", "[", 
        RowBox[{
         RowBox[{"n", "-", "1"}], ",", "k"}], "]"}]}], "+", 
      RowBox[{
       RowBox[{"(", 
        RowBox[{"n", "-", "k"}], ")"}], 
       RowBox[{"EulerianNumber", "[", 
        RowBox[{
         RowBox[{"n", "-", "1"}], ",", 
         RowBox[{"k", "-", "1"}]}], "]"}]}]}]}]}], "]"}]}]], "Input"]
}, Closed]],

Cell[CellGroupData[{

Cell["End private context", "Subsection"],

Cell[BoxData[
 RowBox[{"End", "[", "]"}]], "Input"]
}, Closed]],

Cell[CellGroupData[{

Cell["EndPackage", "Subsection"],

Cell[BoxData[
 RowBox[{"EndPackage", "[", "]"}]], "Input"]
}, Closed]]
}, Open  ]],

Cell[CellGroupData[{

Cell["Examples", "Section"],

Cell[CellGroupData[{

Cell["Load package", "Subsection"],

Cell["Quit current session:", "Text"],

Cell[BoxData["Quit"], "Input"],

Cell[TextData[{
 "Load package (do ",
 StyleBox["not",
  FontSlant->"Italic"],
 " say \[OpenCurlyDoubleQuote]Yes\[CloseCurlyDoubleQuote] to evaluate init \
cells dialog)."
}], "Text"],

Cell[BoxData[
 RowBox[{"<<", "PwM`Chap07Recursion`"}]], "Input"]
}, Closed]],

Cell[CellGroupData[{

Cell["Test usage messages", "Subsection"],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"?", "EulerianNumber"}]], "Input"],

Cell[BoxData[
 StyleBox["\<\"EulerianNumber[\!\(\*\\nStyleBox[\\\"n\\\", \
\\\"TI\\\"]\)\!\(\*\\nStyleBox[\\\",\\\", \\\"TI\\\"]\)\!\(\*\\nStyleBox[\\\" \
\\\", \\\"TI\\\"]\)\!\(\*\\nStyleBox[\\\"k\\\", \\\"TI\\\"]\)] returns the \
the number of permutations of the set {1,2,3,\[Ellipsis],\!\(\*\\nStyleBox[\\\
\"n\\\", \\\"TI\\\"]\)} with \!\(\*\\nStyleBox[\\\"k\\\", \\\"TI\\\"]\) \
increasing runs of elements.\"\>", "MSG"]], "Print", "PrintUsage"]
}, Closed]]
}, Closed]],

Cell[CellGroupData[{

Cell["Exercise the functions and their options", "Subsection"],

Cell[CellGroupData[{

Cell["EulerianNumber", "Subsubsection"],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{
  RowBox[{"EulerianNumber", "[", 
   RowBox[{"25", ",", "15"}], "]"}], "//", "Timing"}]], "Input"],

Cell[BoxData[
 RowBox[{"{", 
  RowBox[{"0.001829999999998222`", ",", "531714261368950897339996"}], 
  "}"}]], "Output"]
}, Closed]],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"EulerianNumber", "[", 
    RowBox[{"600", ",", "65"}], "]"}], ";"}], "//", "Timing"}]], "Input"],

Cell[BoxData[
 RowBox[{"{", 
  RowBox[{"9.999999996068709`*^-6", ",", "Null"}], "}"}]], "Output"]
}, Closed]],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"N", "[", 
  RowBox[{"EulerianNumber", "[", 
   RowBox[{"600", ",", "65"}], "]"}], "]"}]], "Input"],

Cell[BoxData["4.99814710204916063085997018086950402091392578524497`15.\
954589770191005*^1091"], "Output"]
}, Closed]]
}, Closed]]
}, Open  ]]
}, Open  ]]
},
AutoGeneratedPackage->Automatic,
ScreenStyleEnvironment->"Working",
WindowSize->{809, 607},
WindowMargins->{{80, Automatic}, {Automatic, 0}},
ShowSelection->True,
FrontEndVersion->"10.1 for Mac OS X x86 (32-bit, 64-bit Kernel) (March 23, \
2015)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)

(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[CellGroupData[{
Cell[579, 22, 67, 1, 60, "Section",
 InitializationGroup->True],
Cell[649, 25, 398, 13, 29, "Text"],
Cell[CellGroupData[{
Cell[1072, 42, 30, 0, 41, "Subsection"],
Cell[1105, 44, 119, 3, 28, "Input"],
Cell[1227, 49, 239, 6, 28, "Input"],
Cell[1469, 57, 146, 4, 28, "Input"],
Cell[1618, 63, 263, 6, 28, "Input"],
Cell[1884, 71, 122, 3, 28, "Input"],
Cell[2009, 76, 147, 4, 28, "Input"],
Cell[2159, 82, 229, 6, 28, "Input"],
Cell[2391, 90, 256, 8, 28, "Input"],
Cell[2650, 100, 547, 11, 63, "Input"],
Cell[3200, 113, 138, 3, 28, "Input"],
Cell[3341, 118, 173, 5, 28, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[3551, 128, 34, 0, 33, "Subsection"],
Cell[3588, 130, 92, 1, 36, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[3717, 136, 57, 0, 33, "Subsection"],
Cell[3777, 138, 253, 6, 63, "Input"]
}, Closed]],
Cell[4045, 147, 29, 0, 33, "Subsection"],
Cell[CellGroupData[{
Cell[4099, 151, 37, 0, 33, "Subsection"],
Cell[4139, 153, 74, 1, 63, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[4250, 159, 63, 0, 33, "Subsection"],
Cell[4316, 161, 500, 15, 140, "Input"],
Cell[4819, 178, 807, 25, 140, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[5663, 208, 41, 0, 33, "Subsection"],
Cell[5707, 210, 51, 1, 63, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[5795, 216, 32, 0, 33, "Subsection"],
Cell[5830, 218, 58, 1, 63, "Input"]
}, Closed]]
}, Open  ]],
Cell[CellGroupData[{
Cell[5937, 225, 27, 0, 60, "Section"],
Cell[CellGroupData[{
Cell[5989, 229, 34, 0, 41, "Subsection"],
Cell[6026, 231, 37, 0, 62, "Text"],
Cell[6066, 233, 30, 0, 63, "Input"],
Cell[6099, 235, 183, 6, 62, "Text"],
Cell[6285, 243, 64, 1, 63, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[6386, 249, 41, 0, 33, "Subsection"],
Cell[CellGroupData[{
Cell[6452, 253, 57, 1, 63, "Input"],
Cell[6512, 256, 451, 6, 135, "Print"]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[7012, 268, 62, 0, 33, "Subsection"],
Cell[CellGroupData[{
Cell[7099, 272, 39, 0, 32, "Subsubsection"],
Cell[CellGroupData[{
Cell[7163, 276, 122, 3, 63, "Input"],
Cell[7288, 281, 119, 3, 63, "Output"]
}, Closed]],
Cell[CellGroupData[{
Cell[7444, 289, 143, 4, 63, "Input"],
Cell[7590, 295, 97, 2, 63, "Output"]
}, Closed]],
Cell[CellGroupData[{
Cell[7724, 302, 122, 3, 63, "Input"],
Cell[7849, 307, 106, 1, 72, "Output"]
}, Closed]]
}, Closed]]
}, Open  ]]
}, Open  ]]
}
]
*)

(* End of internal cache information *)
