(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[         0,          0]
NotebookDataLength[     15100,        610]
NotebookOptionsPosition[     10350,        438]
NotebookOutlinePosition[     11061,        466]
CellTagsIndexPosition[     10935,        460]
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[{":", "Summary", ":", " ", 
   RowBox[{
   "This", " ", "package", " ", "contains", " ", "the", " ", "functions", " ",
     "defined", " ", "in", " ", "Chapter", " ", "2", " ", "The", " ", 
    "Mathematica", " ", 
    RowBox[{"language", ".", " ", "Function"}], " ", "names", " ", "updated", 
    " ", "to", " ", "be", " ", "compatible", " ", "with", " ", "Mathematica", 
    " ", "10"}]}], " ", "*)"}]], "Input"],

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

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

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

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

Cell[BoxData[
 RowBox[{"(*", " ", 
  RowBox[{
   RowBox[{":", 
    RowBox[{"Keywords", ":", " ", 
     RowBox[{"string", " ", "characters"}]}]}], ",", " ", 
   RowBox[{"composite", " ", "numbers"}], ",", " ", 
   RowBox[{"natural", " ", "numbers", " ", "and", " ", 
    RowBox[{"subsets", "."}]}]}], " ", "*)"}]], "Input"],

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

Cell[BoxData[
 RowBox[{"(*", " ", 
  RowBox[{":", 
   RowBox[{"Mathematica", " ", "Version"}], ":", " ", 
   RowBox[{"10.0", ".1"}]}], " ", "*)"}]], "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"]
}, Open  ]]
}, Closed]],

Cell[CellGroupData[{

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

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

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"compositeQ", "::", "usage"}], "=", 
   "\"\<compositeQ[n] returns True if n is a composite number.\>\""}], 
  ";"}]], "Input"],

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

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"subsetQ", "::", "usage"}], "=", 
   "\"\<subsetQ[\!\(\*SubscriptBox[\(lis\), \(1\)]\),\!\(\*SubscriptBox[\(lis\
\), \(2\)]\)] returns True if \!\(\*SubscriptBox[\(lis\), \(1\)]\) is a \
subset of \!\(\*SubscriptBox[\(lis\), \(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"]
}, Open  ]]
}, 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"]
}, Open  ]]
}, 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"]
}, Open  ]],

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["compositeQ"], "Input"],

Cell[BoxData[
 StyleBox["\<\"compositeQ[n] returns True if n is a composite number.\"\>", 
  "MSG"]], "Print", "PrintUsage",
 CellTags->"Info3637582006-7637176"]
}, 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",
 CellTags->"Info3626257853-9454454"]
}, Closed]]
}, Open  ]],

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]]
}, Closed]]
}, Open  ]]
},
AutoGeneratedPackage->Automatic,
WindowSize->{808, 699},
WindowMargins->{{109, 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->{
 "Info3637582006-7637176"->{
  Cell[7536, 301, 161, 3, 43, "Print",
   CellTags->"Info3637582006-7637176"]},
 "Info3626257853-9454454"->{
  Cell[8082, 323, 419, 7, 63, "Print",
   CellTags->"Info3626257853-9454454"]}
 }
*)
(*CellTagsIndex
CellTagsIndex->{
 {"Info3637582006-7637176", 10723, 451},
 {"Info3626257853-9454454", 10832, 454}
 }
*)
(*NotebookFileOutline
Notebook[{
Cell[CellGroupData[{
Cell[422, 15, 66, 1, 60, "Section",
 InitializationGroup->True],
Cell[491, 18, 398, 13, 29, "Text"],
Cell[CellGroupData[{
Cell[914, 35, 30, 0, 41, "Subsection"],
Cell[947, 37, 129, 3, 45, "Input"],
Cell[1079, 42, 239, 6, 45, "Input"],
Cell[1321, 50, 146, 4, 43, "Input"],
Cell[1470, 56, 458, 9, 97, "Input"],
Cell[1931, 67, 135, 4, 45, "Input"],
Cell[2069, 73, 136, 4, 45, "Input"],
Cell[2208, 79, 209, 5, 45, "Input"],
Cell[2420, 86, 397, 11, 71, "Input"],
Cell[2820, 99, 322, 8, 71, "Input"],
Cell[3145, 109, 152, 4, 45, "Input"],
Cell[3300, 115, 157, 4, 43, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[3494, 124, 34, 0, 33, "Subsection"],
Cell[3531, 126, 68, 1, 36, "Input"],
Cell[CellGroupData[{
Cell[3624, 131, 91, 1, 36, "Input"],
Cell[3718, 134, 54, 0, 70, "Output"]
}, Open  ]]
}, Closed]],
Cell[CellGroupData[{
Cell[3821, 140, 57, 0, 33, "Subsection"],
Cell[3881, 142, 176, 5, 28, "Input"],
Cell[4060, 149, 173, 5, 28, "Input"],
Cell[4236, 156, 167, 5, 28, "Input"],
Cell[4406, 163, 305, 6, 28, "Input"]
}, Closed]],
Cell[4726, 172, 29, 0, 33, "Subsection"],
Cell[CellGroupData[{
Cell[4780, 176, 37, 0, 33, "Subsection"],
Cell[CellGroupData[{
Cell[4842, 180, 74, 1, 78, "Input"],
Cell[4919, 183, 62, 0, 70, "Output"]
}, Open  ]]
}, Closed]],
Cell[CellGroupData[{
Cell[5030, 189, 63, 0, 33, "Subsection"],
Cell[5096, 191, 222, 6, 45, "Input"],
Cell[5321, 199, 184, 5, 45, "Input"],
Cell[5508, 206, 135, 4, 45, "Input"],
Cell[5646, 212, 214, 6, 45, "Input"],
Cell[5863, 220, 187, 5, 45, "Input"],
Cell[6053, 227, 209, 6, 45, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[6299, 238, 41, 0, 33, "Subsection"],
Cell[CellGroupData[{
Cell[6365, 242, 51, 1, 78, "Input"],
Cell[6419, 245, 62, 0, 70, "Output"]
}, Open  ]]
}, Closed]],
Cell[CellGroupData[{
Cell[6530, 251, 32, 0, 33, "Subsection"],
Cell[6565, 253, 58, 1, 78, "Input"]
}, Closed]]
}, Open  ]],
Cell[CellGroupData[{
Cell[6672, 260, 27, 0, 60, "Section"],
Cell[CellGroupData[{
Cell[6724, 264, 34, 0, 41, "Subsection"],
Cell[6761, 266, 37, 0, 29, "Text"],
Cell[6801, 268, 30, 0, 28, "Input"],
Cell[6834, 270, 183, 6, 29, "Text"],
Cell[7020, 278, 63, 1, 28, "Input"]
}, Open  ]],
Cell[CellGroupData[{
Cell[7120, 284, 41, 0, 41, "Subsection"],
Cell[CellGroupData[{
Cell[7186, 288, 53, 1, 28, "Input"],
Cell[7242, 291, 218, 3, 118, "Print"]
}, Closed]],
Cell[CellGroupData[{
Cell[7497, 299, 36, 0, 22, "Input"],
Cell[7536, 301, 161, 3, 43, "Print",
 CellTags->"Info3637582006-7637176"]
}, Closed]],
Cell[CellGroupData[{
Cell[7734, 309, 51, 1, 22, "Input"],
Cell[7788, 312, 204, 3, 118, "Print"]
}, Closed]],
Cell[CellGroupData[{
Cell[8029, 320, 50, 1, 22, "Input"],
Cell[8082, 323, 419, 7, 63, "Print",
 CellTags->"Info3626257853-9454454"]
}, Closed]]
}, Open  ]],
Cell[CellGroupData[{
Cell[8550, 336, 56, 0, 41, "Subsection"],
Cell[CellGroupData[{
Cell[8631, 340, 35, 0, 53, "Subsubsection"],
Cell[CellGroupData[{
Cell[8691, 344, 76, 1, 78, "Input"],
Cell[8770, 347, 32, 0, 78, "Output"]
}, Closed]],
Cell[CellGroupData[{
Cell[8839, 352, 71, 1, 78, "Input"],
Cell[8913, 355, 31, 0, 78, "Output"]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[8993, 361, 35, 0, 42, "Subsubsection"],
Cell[CellGroupData[{
Cell[9053, 365, 112, 3, 52, "Input"],
Cell[9168, 370, 32, 0, 43, "Output"]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[9249, 376, 33, 0, 53, "Subsubsection"],
Cell[CellGroupData[{
Cell[9307, 380, 61, 1, 78, "Input"],
Cell[9371, 383, 31, 0, 78, "Output"]
}, Closed]],
Cell[CellGroupData[{
Cell[9439, 388, 79, 2, 78, "Input"],
Cell[9521, 392, 32, 0, 78, "Output"]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[9602, 398, 32, 0, 42, "Subsubsection"],
Cell[CellGroupData[{
Cell[9659, 402, 348, 12, 97, "Input"],
Cell[10010, 416, 31, 0, 43, "Output"]
}, Closed]],
Cell[CellGroupData[{
Cell[10078, 421, 57, 1, 43, "Input"],
Cell[10138, 424, 31, 0, 43, "Output"]
}, Closed]],
Cell[CellGroupData[{
Cell[10206, 429, 57, 1, 43, "Input"],
Cell[10266, 432, 32, 0, 43, "Output"]
}, Closed]]
}, Closed]]
}, Closed]]
}, Open  ]]
}
]
*)

