(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[         0,          0]
NotebookDataLength[     14931,        601]
NotebookOptionsPosition[     10457,        439]
NotebookOutlinePosition[     10968,        459]
CellTagsIndexPosition[     10925,        456]
WindowFrame->Normal*)

(* Beginning of Notebook Content *)
Notebook[{

Cell[CellGroupData[{
Cell["PwM`Chap02Language`", "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[{":", 
   RowBox[{"Name", ":", " ", "PwM`Chap02Language`"}]}], " ", "*)"}]], "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[{
   RowBox[{":", 
    RowBox[{"Summary", ":", " ", 
     RowBox[{
     "This", " ", "package", " ", "contains", " ", "the", " ", "functions", 
      " ", "defined", " ", "in", " ", "Chapter", " ", "2"}]}]}], ",", " ", 
   RowBox[{"The", " ", "Mathematica", " ", 
    RowBox[{"language", "."}]}]}], " ", "*)"}]], "Input"],

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

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

Cell[BoxData[
 RowBox[{"(*", " ", 
  RowBox[{
   RowBox[{":", 
    RowBox[{"Copyright", ":", " ", 
     RowBox[{"Copyright", " ", "2012"}]}]}], ",", " ", 
   RowBox[{"Cambridge", " ", "University", " ", "Press"}]}], " ", 
  "*)"}]], "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", ":", " ", 
     RowBox[{"string", " ", "characters"}]}]}], ",", " ", 
   RowBox[{"composite", " ", "numbers"}], ",", " ", 
   RowBox[{"natural", " ", "numbers"}], ",", " ", 
   RowBox[{"subsets", "."}]}], " ", "*)"}]], "Input"],

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

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

Cell[CellGroupData[{

Cell["BeginPackage", "Subsection"],

Cell[BoxData[
 RowBox[{"Remove", "[", "CompositeQ", "]"}]], "Input"],

Cell[CellGroupData[{

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

Cell[BoxData["\<\"PWM`Chap02Language`\"\>"], "Output"]
}, Closed]]
}, Closed]],

Cell[CellGroupData[{

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

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"CharacterQ", "::", "usage"}], "=", "\"\<Character[\!\(\*
StyleBox[\"c\", \"TI\"]\)] returns True if \!\(\*
StyleBox[\"c\", \"TI\"]\) is a string of length one.\>\""}], ";"}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"CompositeQ", "::", "usage"}], "=", "\"\<CompositeQ[\!\(\*
StyleBox[\"n\", \"TI\"]\)] returns True if \!\(\*
StyleBox[\"n\", \"TI\"]\) is a composite number.\>\""}], ";"}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"NaturalQ", "::", "usage"}], "=", "\"\<NaturalQ[\!\(\*
StyleBox[\"n\", \"TI\"]\)] returns True if \!\(\*
StyleBox[\"n\", \"TI\"]\) is a natural number.\>\""}], ";"}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"SubsetQ", "::", "usage"}], "=", "\"\<SubsetQ[\!\(\*SubscriptBox[
StyleBox[\"lis\", \"TI\"], \"1\"]\),\!\(\*SubscriptBox[
StyleBox[\"lis\", \"TI\"], \"2\"]\)] returns True if \!\(\*SubscriptBox[
StyleBox[\"lis\", \"TI\"], \"1\"]\) is a subset of \!\(\*SubscriptBox[
StyleBox[\"lis\", \"TI\"], \"2\"]\).\>\""}], ";"}]], "Input"]
}, Closed]],

Cell["Options", "Subsection"],

Cell[CellGroupData[{

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

Cell[CellGroupData[{

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

Cell[BoxData["\<\"PWM`Chap02Language`Private`\"\>"], "Output"]
}, Closed]]
}, Closed]],

Cell[CellGroupData[{

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

Cell[BoxData[
 RowBox[{
  RowBox[{"CharacterQ", "[", "ch_", "]"}], ":=", 
  RowBox[{
   RowBox[{"StringQ", "[", "ch", "]"}], "&&", 
   RowBox[{
    RowBox[{"StringLength", "[", "ch", "]"}], "\[Equal]", "1"}]}]}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{"NaturalQ", "[", "n_", "]"}], ":=", 
  RowBox[{
   RowBox[{"IntegerQ", "[", "n", "]"}], "&&", 
   RowBox[{"n", "\[GreaterEqual]", "0"}]}]}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{"SubsetQ", "[", 
   RowBox[{
    RowBox[{"{", "}"}], ",", "lis2_"}], "]"}], ":=", "True"}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{"SubsetQ", "[", 
   RowBox[{"lis1_", ",", "lis2_"}], "]"}], ":=", 
  RowBox[{
   RowBox[{"Intersection", "[", 
    RowBox[{"lis1", ",", "lis2"}], "]"}], "==", "lis1"}]}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{"lis1_", "\[Subset]", "lis2_"}], ":=", 
  RowBox[{
   RowBox[{"Intersection", "[", 
    RowBox[{"lis1", ",", "lis2"}], "]"}], "==", "lis1"}]}]], "Input"],

Cell[BoxData[
 RowBox[{
  RowBox[{"CompositeQ", "[", 
   RowBox[{"n_Integer", "/;", 
    RowBox[{"n", ">", "1"}]}], "]"}], ":=", 
  RowBox[{"Not", "[", 
   RowBox[{"PrimeQ", "[", "n", "]"}], "]"}]}]], "Input"]
}, Closed]],

Cell[CellGroupData[{

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

Cell[CellGroupData[{

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

Cell[BoxData["\<\"PWM`Chap02Language`Private`\"\>"], "Output"]
}, Closed]]
}, 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`Chap02Language`"}]], "Input"]
}, Closed]],

Cell[CellGroupData[{

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

Cell[CellGroupData[{

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

Cell[BoxData[
 StyleBox["\<\"Character[\\!\\(\\*\\nStyleBox[\\\"c\\\", \\\"TI\\\"]\\)] \
returns True if \\!\\(\\*\\nStyleBox[\\\"c\\\", \\\"TI\\\"]\\) is a string of \
length one.\"\>", "MSG"]], "Print", "PrintUsage"]
}, Closed]],

Cell[CellGroupData[{

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

Cell[BoxData[
 StyleBox["\<\"CompositeQ[\\!\\(\\*\\nStyleBox[\\\"n\\\", \\\"TI\\\"]\\)] \
returns True if \\!\\(\\*\\nStyleBox[\\\"n\\\", \\\"TI\\\"]\\) is a composite \
number.\"\>", "MSG"]], "Print", "PrintUsage"]
}, Closed]],

Cell[CellGroupData[{

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

Cell[BoxData[
 StyleBox["\<\"NaturalQ[\!\(\*\\nStyleBox[\\\"n\\\", \\\"TI\\\"]\)] returns \
True if \!\(\*\\nStyleBox[\\\"n\\\", \\\"TI\\\"]\) is a natural number.\"\>", 
  "MSG"]], "Print", "PrintUsage"]
}, Closed]],

Cell[CellGroupData[{

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

Cell[BoxData[
 StyleBox["\<\"SubsetQ[\\!\\(\\*SubscriptBox[\\nStyleBox[\\\"lis\\\", \
\\\"TI\\\"], \\(1\\)]\\),\\!\\(\\*SubscriptBox[\\nStyleBox[\\\"lis\\\", \
\\\"TI\\\"], \\(2\\)]\\)] returns True if \
\\!\\(\\*SubscriptBox[\\nStyleBox[\\\"lis\\\", \\\"TI\\\"], \\(1\\)]\\) is a \
subset of \\!\\(\\*SubscriptBox[\\nStyleBox[\\\"lis\\\", \\\"TI\\\"], \
\\(2\\)]\\).\"\>", "MSG"]], "Print", "PrintUsage"]
}, Closed]]
}, Closed]],

Cell[CellGroupData[{

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

Cell[CellGroupData[{

Cell["CharacterQ", "Subsubsection"],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"CharacterQ", "[", "\"\<string\>\"", "]"}]], "Input"],

Cell[BoxData["False"], "Output"]
}, Closed]],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"CharacterQ", "[", "\"\<A\>\"", "]"}]], "Input"],

Cell[BoxData["True"], "Output"]
}, Closed]]
}, Closed]],

Cell[CellGroupData[{

Cell["CompositeQ", "Subsubsection"],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"CompositeQ", "[", 
  RowBox[{
   SuperscriptBox["2", "31"], "-", "1"}], "]"}]], "Input"],

Cell[BoxData["False"], "Output"]
}, Closed]]
}, Closed]],

Cell[CellGroupData[{

Cell["NaturalQ", "Subsubsection"],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"NaturalQ", "[", "0", "]"}]], "Input"],

Cell[BoxData["True"], "Output"]
}, Closed]],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"NaturalQ", "[", 
  RowBox[{"-", "1"}], "]"}]], "Input"],

Cell[BoxData["False"], "Output"]
}, Closed]]
}, Closed]],

Cell[CellGroupData[{

Cell["SubsetQ", "Subsubsection"],

Cell[CellGroupData[{

Cell[BoxData[{
 RowBox[{
  RowBox[{"A", "=", 
   RowBox[{"{", 
    RowBox[{"a", ",", "b", ",", "c"}], "}"}]}], 
  ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"B", "=", 
   RowBox[{"{", 
    RowBox[{"a", ",", "b", ",", "c", ",", "d", ",", "e"}], "}"}]}], 
  ";"}], "\n", 
 RowBox[{"SubsetQ", "[", 
  RowBox[{"A", ",", "B"}], "]"}]}], "Input"],

Cell[BoxData["True"], "Output"]
}, Closed]],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"A", "\[Subset]", "B"}]], "Input"],

Cell[BoxData["True"], "Output"]
}, Closed]],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"B", "\[Subset]", "A"}]], "Input"],

Cell[BoxData["False"], "Output"]
}, Closed]]
}, Closed]]
}, Open  ]]
}, Open  ]]
},
AutoGeneratedPackage->Automatic,
WindowSize->{879, 838},
WindowMargins->{{475, Automatic}, {Automatic, 33}},
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[422, 15, 66, 1, 83, "Section",
 InitializationGroup->True],
Cell[491, 18, 398, 13, 34, "Text"],
Cell[CellGroupData[{
Cell[914, 35, 30, 0, 42, "Subsection"],
Cell[947, 37, 129, 3, 33, "Input"],
Cell[1079, 42, 239, 6, 33, "Input"],
Cell[1321, 50, 146, 4, 33, "Input"],
Cell[1470, 56, 365, 9, 53, "Input"],
Cell[1838, 67, 135, 4, 33, "Input"],
Cell[1976, 73, 147, 4, 33, "Input"],
Cell[2126, 79, 241, 7, 33, "Input"],
Cell[2370, 88, 256, 8, 33, "Input"],
Cell[2629, 98, 314, 8, 53, "Input"],
Cell[2946, 108, 152, 4, 33, "Input"],
Cell[3101, 114, 173, 5, 33, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[3311, 124, 34, 0, 31, "Subsection"],
Cell[3348, 126, 68, 1, 51, "Input"],
Cell[CellGroupData[{
Cell[3441, 131, 91, 1, 51, "Input"],
Cell[3535, 134, 54, 0, 51, "Output"]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[3638, 140, 57, 0, 31, "Subsection"],
Cell[3698, 142, 231, 5, 33, "Input"],
Cell[3932, 149, 228, 5, 33, "Input"],
Cell[4163, 156, 222, 5, 33, "Input"],
Cell[4388, 163, 373, 7, 33, "Input"]
}, Closed]],
Cell[4776, 173, 29, 0, 31, "Subsection"],
Cell[CellGroupData[{
Cell[4830, 177, 37, 0, 31, "Subsection"],
Cell[CellGroupData[{
Cell[4892, 181, 74, 1, 51, "Input"],
Cell[4969, 184, 62, 0, 51, "Output"]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[5080, 190, 63, 0, 31, "Subsection"],
Cell[5146, 192, 222, 6, 51, "Input"],
Cell[5371, 200, 184, 5, 51, "Input"],
Cell[5558, 207, 135, 4, 51, "Input"],
Cell[5696, 213, 214, 6, 51, "Input"],
Cell[5913, 221, 187, 5, 51, "Input"],
Cell[6103, 228, 209, 6, 51, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[6349, 239, 41, 0, 31, "Subsection"],
Cell[CellGroupData[{
Cell[6415, 243, 51, 1, 51, "Input"],
Cell[6469, 246, 62, 0, 51, "Output"]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[6580, 252, 32, 0, 31, "Subsection"],
Cell[6615, 254, 58, 1, 51, "Input"]
}, Closed]]
}, Open  ]],
Cell[CellGroupData[{
Cell[6722, 261, 27, 0, 83, "Section"],
Cell[CellGroupData[{
Cell[6774, 265, 34, 0, 42, "Subsection"],
Cell[6811, 267, 37, 0, 50, "Text"],
Cell[6851, 269, 30, 0, 51, "Input"],
Cell[6884, 271, 183, 6, 50, "Text"],
Cell[7070, 279, 63, 1, 51, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[7170, 285, 41, 0, 31, "Subsection"],
Cell[CellGroupData[{
Cell[7236, 289, 53, 1, 51, "Input"],
Cell[7292, 292, 218, 3, 76, "Print"]
}, Closed]],
Cell[CellGroupData[{
Cell[7547, 300, 53, 1, 51, "Input"],
Cell[7603, 303, 215, 3, 76, "Print"]
}, Closed]],
Cell[CellGroupData[{
Cell[7855, 311, 51, 1, 51, "Input"],
Cell[7909, 314, 204, 3, 76, "Print"]
}, Closed]],
Cell[CellGroupData[{
Cell[8150, 322, 50, 1, 51, "Input"],
Cell[8203, 325, 405, 6, 78, "Print"]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[8657, 337, 56, 0, 31, "Subsection"],
Cell[CellGroupData[{
Cell[8738, 341, 35, 0, 30, "Subsubsection"],
Cell[CellGroupData[{
Cell[8798, 345, 76, 1, 51, "Input"],
Cell[8877, 348, 32, 0, 51, "Output"]
}, Closed]],
Cell[CellGroupData[{
Cell[8946, 353, 71, 1, 51, "Input"],
Cell[9020, 356, 31, 0, 51, "Output"]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[9100, 362, 35, 0, 21, "Subsubsection"],
Cell[CellGroupData[{
Cell[9160, 366, 112, 3, 63, "Input"],
Cell[9275, 371, 32, 0, 51, "Output"]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[9356, 377, 33, 0, 21, "Subsubsection"],
Cell[CellGroupData[{
Cell[9414, 381, 61, 1, 51, "Input"],
Cell[9478, 384, 31, 0, 51, "Output"]
}, Closed]],
Cell[CellGroupData[{
Cell[9546, 389, 79, 2, 51, "Input"],
Cell[9628, 393, 32, 0, 51, "Output"]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[9709, 399, 32, 0, 21, "Subsubsection"],
Cell[CellGroupData[{
Cell[9766, 403, 348, 12, 112, "Input"],
Cell[10117, 417, 31, 0, 51, "Output"]
}, Closed]],
Cell[CellGroupData[{
Cell[10185, 422, 57, 1, 51, "Input"],
Cell[10245, 425, 31, 0, 51, "Output"]
}, Closed]],
Cell[CellGroupData[{
Cell[10313, 430, 57, 1, 51, "Input"],
Cell[10373, 433, 32, 0, 51, "Output"]
}, Closed]]
}, Closed]]
}, Open  ]]
}, Open  ]]
}
]
*)

