(* 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[      7929,        317]
NotebookOptionsPosition[      5715,        234]
NotebookOutlinePosition[      6226,        254]
CellTagsIndexPosition[      6183,        251]
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["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[\!\(\*
StyleBox[\"n\", \"TI\"]\)\!\(\*
StyleBox[\",\", \"TI\"]\)\!\(\*
StyleBox[\" \", \"TI\"]\)\!\(\*
StyleBox[\"k\", \"TI\"]\)] returns the the number of permutations of the set \
{1,2,3,\[Ellipsis],\!\(\*
StyleBox[\"n\", \"TI\"]\)} with \!\(\*
StyleBox[\"k\", \"TI\"]\) 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,
WindowSize->{839, 901},
WindowMargins->{{495, Automatic}, {Automatic, 68}},
ShowSelection->True,
Magnification:>FEPrivate`If[
  FEPrivate`Equal[FEPrivate`$VersionNumber, 6.], 1.25, 1.25 Inherited],
FrontEndVersion->"8.0 for Mac OS X x86 (32-bit, 64-bit Kernel) (October 5, \
2011)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)

(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[CellGroupData[{
Cell[579, 22, 67, 1, 83, "Section",
 InitializationGroup->True],
Cell[649, 25, 398, 13, 34, "Text"],
Cell[CellGroupData[{
Cell[1072, 42, 34, 0, 42, "Subsection"],
Cell[1109, 44, 92, 1, 51, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[1238, 50, 57, 0, 31, "Subsection"],
Cell[1298, 52, 432, 10, 72, "Input"]
}, Closed]],
Cell[1745, 65, 29, 0, 31, "Subsection"],
Cell[CellGroupData[{
Cell[1799, 69, 37, 0, 31, "Subsection"],
Cell[1839, 71, 74, 1, 51, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[1950, 77, 63, 0, 31, "Subsection"],
Cell[2016, 79, 500, 15, 112, "Input"],
Cell[2519, 96, 807, 25, 112, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[3363, 126, 41, 0, 31, "Subsection"],
Cell[3407, 128, 51, 1, 51, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[3495, 134, 32, 0, 31, "Subsection"],
Cell[3530, 136, 58, 1, 51, "Input"]
}, Closed]]
}, Open  ]],
Cell[CellGroupData[{
Cell[3637, 143, 27, 0, 83, "Section"],
Cell[CellGroupData[{
Cell[3689, 147, 34, 0, 42, "Subsection"],
Cell[3726, 149, 37, 0, 50, "Text"],
Cell[3766, 151, 30, 0, 51, "Input"],
Cell[3799, 153, 183, 6, 50, "Text"],
Cell[3985, 161, 64, 1, 51, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[4086, 167, 41, 0, 31, "Subsection"],
Cell[CellGroupData[{
Cell[4152, 171, 57, 1, 51, "Input"],
Cell[4212, 174, 451, 6, 108, "Print"]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[4712, 186, 70, 2, 31, "Subsection"],
Cell[CellGroupData[{
Cell[4807, 192, 39, 0, 30, "Subsubsection"],
Cell[CellGroupData[{
Cell[4871, 196, 122, 3, 51, "Input"],
Cell[4996, 201, 119, 3, 51, "Output"]
}, Closed]],
Cell[CellGroupData[{
Cell[5152, 209, 143, 4, 51, "Input"],
Cell[5298, 215, 97, 2, 51, "Output"]
}, Closed]],
Cell[CellGroupData[{
Cell[5432, 222, 122, 3, 51, "Input"],
Cell[5557, 227, 106, 1, 58, "Output"]
}, Closed]]
}, Closed]]
}, Open  ]]
}, Open  ]]
}
]
*)

(* End of internal cache information *)
