(************** Content-type: application/mathematica ************** CreatedBy='Mathematica 5.1' Mathematica-Compatible Notebook This notebook can be used with any Mathematica-compatible application, such as Mathematica, MathReader or Publicon. 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[ 114814, 4037]*) (*NotebookOutlinePosition[ 116089, 4080]*) (* CellTagsIndexPosition[ 115902, 4071]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell["Mathematica Programming", "Title", TextAlignment->Center, TextJustification->0], Cell["Version 1.0", "Text"], Cell[TextData[{ "Tutorial intended for a user familiar with procedural programming and \ interested in learning Mathematica and functional programming and emphasizes \ good programming practices.\n", "\n", "Using correct programming practices makes your code easier to debug and \ maintain as well as allows you to reuse code and save time. When I started \ programming in ", StyleBox["Mathematica", FontSlant->"Italic"], ", I found that ", StyleBox["Mathematica", FontSlant->"Italic"], " was missing some key features I had become accustomed to in procedural \ langauges. After some searching, I found Mathematica supports all these \ features or can support these features with some simple tricks. " }], "Text"], Cell[CellGroupData[{ Cell["ToDo", "Subsection"], Cell["\<\ Need more example in Creating and accessing a database with pattern matching, \ like select (see Conditions on arguments) Add optional arguments section under Modularization \ \>", "Text"] }, Closed]], Cell[CellGroupData[{ Cell[TextData[{ "Naming ", Cell[BoxData[ \(TraditionalForm\`Conventions\)]] }], "Subtitle"], Cell[TextData[{ StyleBox["Mathematica", FontFamily->"Times New Roman", FontWeight->"Bold", FontSlant->"Italic"], StyleBox[" uses \n1. ", FontFamily->"Times New Roman"], StyleBox["Capital Letters\n", FontFamily->"Times New Roman", FontSlant->"Italic"], StyleBox["All built-in ", FontFamily->"Times New Roman"], StyleBox["Mathematica ", FontFamily->"Times New Roman", FontSlant->"Italic"], StyleBox["commands", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman", FontWeight->"Bold"], StyleBox["begin with a capital letter.\n2. ", FontFamily->"Times New Roman"], StyleBox["Complete Words (mostly)\n", FontFamily->"Times New Roman", FontSlant->"Italic"], StyleBox["Most ", FontFamily->"Times New Roman"], StyleBox["Mathematica ", FontFamily->"Times New Roman", FontSlant->"Italic"], StyleBox["commands are complete words strung together e.g. \ ToInversionVector.\n\n", FontFamily->"Times New Roman"], StyleBox["Begin all your variable names, functions definitions, and other \ expression with a lower case\nletter to distinguish them from ", FontFamily->"Times New Roman", FontWeight->"Bold"], StyleBox["Mathematica", FontFamily->"Times New Roman", FontWeight->"Bold", FontSlant->"Italic"], StyleBox["'s built in commands. ", FontFamily->"Times New Roman", FontWeight->"Bold"] }], "Text"], Cell["", "Text"] }, Closed]], Cell[CellGroupData[{ Cell[TextData[Cell[BoxData[ \(TraditionalForm\`Modularization\)]]], "Subtitle"], Cell["Packages and Context", "Text"], Cell[TextData[{ "From ", StyleBox["Mathematica", FontSlant->"Italic"], " Book\nIn Mathematica the mechanism of \[OpenCurlyDoubleQuote]contexts\ \[CloseCurlyDoubleQuote] is used to keep package symbols separate from \ symbols in\nthe main session. The basic idea is that the full name of any \ symbol is broken into two parts: a context\nand a short name. The full name \ is written as context\[OpenCurlyQuote]short, where \[OpenCurlyQuote] is the \ backquote or grav\.b4e accent\ncharacter, called a context mark in \ Mathematica.\nContexts in Mathematica work somewhat like file directories in \ many operating systems. You can always\nspecify a particular file by giving \ its complete name, including its directory. But at any given point, there\nis \ usually a current working directory, analogous to the current Mathematica \ context. Variables that are\nin the current context can be specified just by \ giving their short names in the same way that files in the\ncurrent working \ directory can be specified by just giving their short names. The global \ variable $Context\ngives the current Mathematica context.\nAs is also the \ case with directories, contexts in Mathematica can be hierarchical. By \ convention, the\nsymbols that are created by loading a standard Mathematica \ package have a context whose name is\nrelated to the name of the package. As \ an example, loading the package Calculus\[OpenCurlyQuote]LaplaceTransform\ \[OpenCurlyQuote]\ndefines the symbol \ Calculus\[OpenCurlyQuote]LaplaceTransform\[OpenCurlyQuote]LaplaceTransform, \ which you can then use to compute\nthe Laplace transform of a function." }], "Text"], Cell[CellGroupData[{ Cell["Function Organization", "Section"], Cell[TextData[{ "This doesn't fit anywhere else so I put it here. These suggsetions come \ from Richard Johnson's ", ButtonBox["Programming tutorial for Matlab", ButtonData:>{ URL[ "http://www.datatool.com/MatlabStyle.pdf"], None}, ButtonStyle->"Hyperlink"], " but are general enough to be applicable here." }], "Text"], Cell["\<\ Structuring code, both among and within files is essential to making it \ understandable. Thoughtful partitioning and ordering increase the value of the code.\ \>", "Text"], Cell["\<\ Modularize. The best way to write a big program is to assemble it from well designed \ small pieces (usually functions). This approach enhances readability, understanding and testing by \ reducing the amount of text which must be read to see what the code is doing. Code longer than \ two editor screens is a candidate for partitioning. Small well designed functions are more likely to \ be usable in other applications.\ \>", "Text"], Cell[TextData[{ "Make interaction clear.\nA function interacts with other code through \ input and output arguments and global variables. The use of arguments is \ almost always clearer than the use of globals. Structures and databases can \ be used to avoid long lists of input or output arguments. They can be used \ interchangably, but subtle differences between the two in ", StyleBox["Mathematica", FontSlant->"Italic"], " make one more appropriate than the other in some cases. In general, \ structures allow direct access to data, while databases store data and use \ pattern matching functions to access. See sections on \"Creating and \ accessing a database with pattern matching\" and \"Structured Data Types in \ ", StyleBox["Mathematica", FontSlant->"Italic"], " and using Down-values and Up-values\"." }], "Text"], Cell["\<\ Partitioning All subfunctions and many functions should do one thing very well. Every function should hide something.\ \>", "Text"], Cell["\<\ Use existing functions. Developing a function that is correct, readable and reasonably flexible can \ be a significant task. It may be quicker or surer to find an existing function that provides some or \ all of the required functionality.\ \>", "Text"] }, Closed]], Cell[CellGroupData[{ Cell[BoxData[ StyleBox[\(Using\ packages\ \((overview)\)\), FontFamily->"Arial"]], "Section", CellTags->"UsingPackages"], Cell[TextData[{ "See Michael A. Morrison's ", ButtonBox["Mathematica Tips, Tricks, and Techniques: Packages", ButtonData:>{ URL[ "http://www.nhn.ou.edu/~morrison/Mathematica/TipSheets/Packages.pdf"], None}, ButtonStyle->"Hyperlink"] }], "Text"], Cell[TextData[Cell[BoxData[ RowBox[{ StyleBox["Under", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["3.6", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["the", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["author", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["does", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["not", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["include", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["information", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["about", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["the", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["MATHEMATICA_USERBASE", "MR", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["operating", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["system", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["environment", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox[\(variable . \ It\), FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["allows", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["the", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["user", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["to", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["set", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["the", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["base", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["directory", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["where", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["user\[Hyphen]specific", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["files", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["to", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["be", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["loaded", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["by", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["Mathematica", "TI", FontFamily->"Times New Roman"], StyleBox[ RowBox[{ StyleBox[" ", "TI", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"]}]], StyleBox["should", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["be", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["conventionally", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox[\(placed . \ See\), FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["help", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["browser", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox["entry", FontFamily->"Times New Roman"], StyleBox[" ", FontFamily->"Times New Roman"], StyleBox[ RowBox[{ ButtonBox["$UserBaseDirectory", ButtonStyle->"RefGuideLink"], ".", " "}], FontFamily->"Times New Roman"]}]]]], "Text"] }, Closed]], Cell[CellGroupData[{ Cell[TextData[{ "Writing ", Cell[BoxData[ \(TraditionalForm\`Packages\^4\)]] }], "Section"], Cell["\<\ I suggest using a Mathematica notebook with the AutoSavePackage feature to \ write your packages. This provides a way to include notes, examples, and other information about the package in a \ Mathematica notebook together with the contents of the actual package.\ \>", "Text"], Cell[TextData[{ "Roman ", "The best description of Packages and Context I've found is Roman Maedar's \ section on Packages in his book Programming in Mathematica. Here is an \ excerpt taken from Roman ", "E.Maeder's ", ButtonBox["Mathematica's Programming Language", ButtonData:>{ URL[ "http://library.wolfram.com/infocenter/Conferences/183/"], None}, ButtonStyle->"Hyperlink"] }], "Text"], Cell[CellGroupData[{ Cell["Package Design", "Subsection"], Cell[TextData[Cell[BoxData[ RowBox[{"see", " ", \(Gayley'\), "s", " ", ButtonBox[\(Packaging\ Design\ Tutorial\), ButtonData:>{ URL[ "http://library.wolfram.com/infocenter/Conferences/184/"], None}, ButtonStyle->"Hyperlink"]}]], FontFamily->"Times New Roman"]], "Text"] }, Closed]], Cell[CellGroupData[{ Cell["Modularization", "Subsection", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ StyleBox["Good programming style suggests separating definition and \ implementation. The\nexported functions are declared and documented. Any \ needed functions are\ndeclared and imported. The package mechanism in ", Evaluatable->False, AspectRatioFixed->True], StyleBox["Mathematica", Evaluatable->False, AspectRatioFixed->True, FontSlant->"Italic"], StyleBox[" provides for these\nfeatures. It is explained in detail in ", Evaluatable->False, AspectRatioFixed->True], StyleBox["Programming in Mathematica", Evaluatable->False, AspectRatioFixed->True, FontSlant->"Italic"], StyleBox["\n(Addison-Wesley, 1991).", Evaluatable->False, AspectRatioFixed->True] }], "Text", Evaluatable->False, AspectRatioFixed->True] }, Closed]], Cell[CellGroupData[{ Cell["A Demonstration Package", "Subsection", Evaluatable->False, AspectRatioFixed->True], Cell["\<\ Create a clean state for a new package and declare any imports.\ \>", "Text", Evaluatable->False, AspectRatioFixed->True], Cell["BeginPackage[\"Demo`\", \"Needed1`\"]", "Input", AspectRatioFixed->True], Cell["\<\ Create the public symbols. This is best done with a usage message.\ \>", "Text", Evaluatable->False, AspectRatioFixed->True], Cell["SampleFunction::usage = \"SampleFunction[n] does nothing\"", "Input", AspectRatioFixed->True], Cell["Start the implementation part.", "Text", Evaluatable->False, AspectRatioFixed->True], Cell["Begin[\"`Private`\"]", "Input", AspectRatioFixed->True], Cell["All new symbols in this part will not be exported.", "Text", Evaluatable->False, AspectRatioFixed->True], Cell["SampleFunction[n_] := n^3 + 2n^2 + 3n + 4", "Input", AspectRatioFixed->True], Cell["AuxFunction[m_] := something", "Input", AspectRatioFixed->True], Cell["End[]", "Input", AspectRatioFixed->True], Cell[TextData[{ StyleBox["End the package and add its context to ", Evaluatable->False, AspectRatioFixed->True], StyleBox["$ContextPath.", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier", FontWeight->"Bold"] }], "Text", Evaluatable->False, AspectRatioFixed->True], Cell["EndPackage[]", "Input", AspectRatioFixed->True], Cell["Reading it in.", "Text", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True], Cell["This is a machine-independent way of reading in packages.", "Text", Evaluatable->False, AspectRatioFixed->True], Cell["<< Demo`", "Input", AspectRatioFixed->True], Cell["The exported function can be used outside.", "Text", Evaluatable->False, AspectRatioFixed->True], Cell[CellGroupData[{ Cell["?SampleFunction", "Input", AspectRatioFixed->True], Cell["SampleFunction[n] does nothing", "Print", Evaluatable->False, AspectRatioFixed->True] }, Closed]], Cell["The private symbols are not found.", "Text", Evaluatable->False, AspectRatioFixed->True], Cell[CellGroupData[{ Cell["?AuxFunction", "Input", AspectRatioFixed->True], Cell["Information::notfound: Symbol AuxFunction not found.", "Message", Evaluatable->False, AspectRatioFixed->True] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["Import of Packages: Details", "Subsection", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ StyleBox["Transitivity: if ", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True], StyleBox["A`", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier", FontWeight->"Bold"], StyleBox[" needs ", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True], StyleBox["B`", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier", FontWeight->"Bold"], StyleBox[" and ", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True], StyleBox["B`", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier", FontWeight->"Bold"], StyleBox[" needs ", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True], StyleBox["C`", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier", FontWeight->"Bold"], StyleBox[", can ", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True], StyleBox["A", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True, FontWeight->"Bold"], StyleBox["`", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier", FontWeight->"Bold"], StyleBox[" use ", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True], StyleBox["C`", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier", FontWeight->"Bold"], StyleBox["?", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True] }], "Text", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True], Cell[CellGroupData[{ Cell["\<\ BeginPackage[\"A`\", \"B`\"]; a::usage = \"a in A\"; Print[$Context, $ContextPath]; EndPackage[];\ \>", "Input", AspectRatioFixed->True], Cell["A`{A`, B`, System`}", "Print", Evaluatable->False, AspectRatioFixed->True] }, Closed]], Cell["\<\ BeginPackage[\"B`\", \"C`\"] b::usage = \"b in B\" EndPackage[]\ \>", "Input", Evaluatable->False, AspectRatioFixed->True], Cell["\<\ BeginPackage[\"C`\"] c::usage = \"c in C\" EndPackage[]\ \>", "Input", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ StyleBox["In Version 2.2, ", Evaluatable->False, AspectRatioFixed->True], StyleBox["C`", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier", FontWeight->"Bold"], StyleBox[" is not available inside the package ", Evaluatable->False, AspectRatioFixed->True], StyleBox["A`", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier", FontWeight->"Bold"], StyleBox[". This will be fixed in the next\nversion.", Evaluatable->False, AspectRatioFixed->True] }], "Text", Evaluatable->False, AspectRatioFixed->True], Cell["Hidden import", "Text", CellDingbat->"\[FilledCircle]", Evaluatable->False, PageBreakBelow->False, AspectRatioFixed->True], Cell[CellGroupData[{ Cell["\<\ BeginPackage[\"D1`\"]; Needs[\"E`\"]; (* hidden import *) Print[$Context, $ContextPath]; EndPackage[];\ \>", "Input", AspectRatioFixed->True], Cell["D1`{E`, D1`, System`}", "Print", Evaluatable->False, PageBreakAbove->False, AspectRatioFixed->True] }, Closed]], Cell[CellGroupData[{ Cell["\<\ BeginPackage[\"D2`\"]; Needs[\"E`\"]; (* hidden import *) Print[$Context, $ContextPath]; EndPackage[];\ \>", "Input", AspectRatioFixed->True], Cell["D2`{E`, D2`, System`}", "Print", Evaluatable->False, PageBreakAbove->False, AspectRatioFixed->True] }, Closed]], Cell[CellGroupData[{ Cell["$Packages", "Input", AspectRatioFixed->True], Cell[OutputFormData["\<\ {\"D2`\", \"D1`\", \"E`\", \"Global`\", \"System`\"}\ \>", "\<\ {D2`, D1`, E`, Global`, System`}\ \>"], "Output", Evaluatable->False, AspectRatioFixed->True] }, Closed]], Cell[CellGroupData[{ Cell["$ContextPath", "Input", AspectRatioFixed->True], Cell[OutputFormData["\<\ {\"D2`\", \"D1`\", \"Global`\", \"System`\"}\ \>", "\<\ {D2`, D1`, Global`, System`}\ \>"], "Output", Evaluatable->False, AspectRatioFixed->True] }, Closed]], Cell[TextData[{ StyleBox["In Version 2.2.0, a second attempt at hidden import fails, since \ the package is not\nread again, and it is not put on ", Evaluatable->False, AspectRatioFixed->True], StyleBox["$ContextPath", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier", FontWeight->"Bold"], StyleBox[". This is now fixed.", Evaluatable->False, AspectRatioFixed->True] }], "Text", Evaluatable->False, AspectRatioFixed->True] }, Closed]] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["Function Overloading with Conditional Patterns", "Subtitle"], Cell["\<\ Conidtional patterns allow for flexible function overloading, i.e. functions \ behave differently depending on details of their arguments.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[{ \(Attributes[Pair] = {Orderless}\), "\n", \(Pair[p_List, j_] := \(Pair[#, j] &\) /@ p\ (*Type\ Checking*) \), "\n", \(Pair[n_?NumberQ\ i_, j_] := \(\(n\)\(\ \)\(Pair[i, j]\)\(\ \)\( (*Pattern\ Test*) \)\)\)}], "Input"], Cell[BoxData[ \({Orderless}\)], "Output"] }, Closed]], Cell[CellGroupData[{ Cell[BoxData[ \(Pair[3 y, 3 x]\)], "Input"], Cell[BoxData[ \(9\ Pair[x, y]\)], "Output"] }, Closed]], Cell[CellGroupData[{ Cell[BoxData[ \(Pair[List[1, 2, 3], 3 x]\)], "Input"], Cell[BoxData[ \({3\ Pair[1, x], 3\ Pair[2, x], 3\ Pair[3, x]}\)], "Output"] }, Closed]], Cell[TextData[{ "Other commonly used fuctions for testing properties of expressions, ", ButtonBox["2.3.5 and ", ButtonData:>{"2.3.5", "5.1"}, ButtonStyle->"MainBookLink"], " ", ButtonBox["2.3.5", ButtonData:>{"2.3.5", "5.2"}, ButtonStyle->"MainBookLink"] }], "Text"], Cell[TextData[{ "It is common to use ", StyleBox["/;", "MR"], " to set up patterns and transformation rules that apply only to \ expressions with certain properties. " }], "Text"], Cell[BoxData[{ \(f[x_]\ := \ 1 /; x > 0; \ (*Condition*) \[IndentingNewLine]f[x_]\ := \ \(-1\) /; x < 0;\), "\[IndentingNewLine]", \(\(f[x_]\ := \ 1/2 /; x === 0;\)\)}], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(Plot[f[x], \ {x, \(-10\), 10}]\)], "Input"], Cell[GraphicsData["PostScript", "\<\ %! %%Creator: Mathematica %%AspectRatio: .61803 MathPictureStart /Mabs { Mgmatrix idtransform Mtmatrix dtransform } bind def /Mabsadd { Mabs 3 -1 roll add 3 1 roll add exch } bind def %% Graphics %%IncludeResource: font Courier %%IncludeFont: Courier /Courier findfont 10 scalefont setfont % Scaling calculations 0.5 0.0476191 0.309017 0.294302 [ [.02381 .29652 -9 -9 ] [.02381 .29652 9 0 ] [.2619 .29652 -6 -9 ] [.2619 .29652 6 0 ] [.7381 .29652 -3 -9 ] [.7381 .29652 3 0 ] [.97619 .29652 -6 -9 ] [.97619 .29652 6 0 ] [.4875 .01472 -12 -4.5 ] [.4875 .01472 0 4.5 ] [.4875 .16187 -24 -4.5 ] [.4875 .16187 0 4.5 ] [.4875 .45617 -18 -4.5 ] [.4875 .45617 0 4.5 ] [.4875 .60332 -6 -4.5 ] [.4875 .60332 0 4.5 ] [ 0 0 0 0 ] [ 1 .61803 0 0 ] ] MathScale % Start of Graphics 1 setlinecap 1 setlinejoin newpath 0 g .25 Mabswid [ ] 0 setdash .02381 .30902 m .02381 .31527 L s [(-10)] .02381 .29652 0 1 Mshowa .2619 .30902 m .2619 .31527 L s [(-5)] .2619 .29652 0 1 Mshowa .7381 .30902 m .7381 .31527 L s [(5)] .7381 .29652 0 1 Mshowa .97619 .30902 m .97619 .31527 L s [(10)] .97619 .29652 0 1 Mshowa .125 Mabswid .07143 .30902 m .07143 .31277 L s .11905 .30902 m .11905 .31277 L s .16667 .30902 m .16667 .31277 L s .21429 .30902 m .21429 .31277 L s .30952 .30902 m .30952 .31277 L s .35714 .30902 m .35714 .31277 L s .40476 .30902 m .40476 .31277 L s .45238 .30902 m .45238 .31277 L s .54762 .30902 m .54762 .31277 L s .59524 .30902 m .59524 .31277 L s .64286 .30902 m .64286 .31277 L s .69048 .30902 m .69048 .31277 L s .78571 .30902 m .78571 .31277 L s .83333 .30902 m .83333 .31277 L s .88095 .30902 m .88095 .31277 L s .92857 .30902 m .92857 .31277 L s .25 Mabswid 0 .30902 m 1 .30902 L s .5 .01472 m .50625 .01472 L s [(-1)] .4875 .01472 1 0 Mshowa .5 .16187 m .50625 .16187 L s [(-0.5)] .4875 .16187 1 0 Mshowa .5 .45617 m .50625 .45617 L s [(0.5)] .4875 .45617 1 0 Mshowa .5 .60332 m .50625 .60332 L s [(1)] .4875 .60332 1 0 Mshowa .125 Mabswid .5 .04415 m .50375 .04415 L s .5 .07358 m .50375 .07358 L s .5 .10301 m .50375 .10301 L s .5 .13244 m .50375 .13244 L s .5 .1913 m .50375 .1913 L s .5 .22073 m .50375 .22073 L s .5 .25016 m .50375 .25016 L s .5 .27959 m .50375 .27959 L s .5 .33845 m .50375 .33845 L s .5 .36788 m .50375 .36788 L s .5 .39731 m .50375 .39731 L s .5 .42674 m .50375 .42674 L s .5 .4856 m .50375 .4856 L s .5 .51503 m .50375 .51503 L s .5 .54446 m .50375 .54446 L s .5 .57389 m .50375 .57389 L s .25 Mabswid .5 0 m .5 .61803 L s 0 0 m 1 0 L 1 .61803 L 0 .61803 L closepath clip newpath .5 Mabswid .02381 .01472 m .06244 .01472 L .10458 .01472 L .14415 .01472 L .18221 .01472 L .22272 .01472 L .26171 .01472 L .30316 .01472 L .34309 .01472 L .3815 .01472 L .42237 .01472 L .46172 .01472 L .48147 .01472 L .49012 .01472 L .49468 .01472 L .49719 .01472 L .49842 .01472 L .49955 .01472 L .50085 .60332 L .50154 .60332 L .50226 .60332 L .50471 .60332 L .5095 .60332 L .51896 .60332 L .53984 .60332 L .57781 .60332 L .61824 .60332 L .65714 .60332 L .6985 .60332 L .73835 .60332 L .77668 .60332 L .81746 .60332 L .85673 .60332 L .89448 .60332 L .93468 .60332 L .97337 .60332 L .97619 .60332 L s % End of Graphics MathPictureEnd \ \>"], "Graphics", ImageSize->{288, 177.938}, ImageMargins->{{35, 0}, {0, 0}}, ImageRegion->{{0, 1}, {0, 1}}, ImageCache->GraphicsData["Bitmap", "\<\ CF5dJ6E]HGAYHf4PAg9QL6QYHg0=WI f@00T03IfMT00`000000fMWI0=WIf@2=0=WIf@00T03IfMT00`000000fMWI0=WIf@2=0=WIf@00T03I fMT00`000000fMWI0=WIf@2=0=WIf@00T03IfMT00`000000fMWI0=WIf@2=0=WIf@00T03IfMT00`00 0000fMWI0=WIf@2=0=WIf@00T03IfMT00`000000fMWI0=WIf@2=0=WIf@00T03IfMT00`000000fMWI 0=WIf@2=0=WIf@00T03IfMT00`000000fMWI0=WIf@2=0=WIf@00T03IfMT2000008h0fMWI002@0=WI f@030000003IfMT0fMWI08d0fMWI002@0=WIf@030000003IfMT0fMWI08d0fMWI002@0=WIf@030000 003IfMT0fMWI08d0fMWI002@0=WIf@030000003IfMT0fMWI08d0fMWI002@0=WIf@030000003IfMT0 fMWI08d0fMWI001l0=WIf@040;j5?0000000000003b5_P80fMWI00<0fMVR06<00000?8D00`3IfMT0 102nQC`000000000000lQKh40=WIf@030000003IfMT0fMWI08d0fMWI001l0=WIf@0508ESQ@3IfMT0 fMWI08DlH`2RfMT01P3IfMT01P3I_XD0?3b50=WIf@3IfMT0QC`l08Fnf@<0fMWI00<000000=WIf@3I fMT0S@3IfMT007/0fMWI00H0fMVR06Rf@3IfJ80Hcb50080 fMWI00<0XVRf@P0fMWI00@0XV<00000 0000000006>R103IfMT00`000000fMWI0=WIf@2=0=WIf@00T03IfMT00`000000fMWI0=WIf@2=0=WI f@00T03IfMT00`000000fMWI0=WIf@2=0=WIf@00T03IfMT00`000000fMWI0=WIf@2=0=WIf@00T03I fMT00`000000fMWI0=WIf@2=0=WIf@00T03IfMT00`000000fMWI0=WIf@2=0=WIf@00T03IfMT20000 08h0fMWI002@0=WIf@030000003IfMT0fMWI08d0fMWI002@0=WIf@030000003IfMT0fMWI08d0fMWI 002@0=WIf@030000003IfMT0fMWI08d0fMWI002@0=WIf@030000003IfMT0fMWI08d0fMWI002@0=WI f@030000003IfMT0fMWI08d0fMWI002@0=WIf@030000003IfMT0fMWI08d0fMWI002@0=WIf@030000 003IfMT0fMWI08d0fMWI002@0=WIf@800000SP3IfMT00900fMWI00<000000=WIf@3IfMT0S@3IfMT0 0900fMWI00<000000=WIf@3IfMT0S@3IfMT00900fMWI00<000000=WIf@3IfMT0S@3IfMT00900fMWI 00<000000=WIf@3IfMT0S@3IfMT00900fMWI00<000000=WIf@3IfMT0S@3IfMT00900fMWI00<00000 0=WIf@3IfMT0S@3IfMT00900fMWI00<000000=WIf@3IfMT0S@3IfMT00900fMWI0P00002>0=WIf@00 T03IfMT00`000000fMWI0=WIf@2=0=WIf@00T03IfMT00`000000fMWI0=WIf@2=0=WIf@00T03IfMT0 0`000000fMWI0=WIf@2=0=WIf@00T03IfMT00`000000fMWI0=WIf@2=0=WIf@001P3IfMT0203IfJ80 H`00000000000000000l08Fnf@3IfMT0_XDl0P0000000`0lQKh0fMWI0=WIf@0j0=WIf@040;j5?000 0000000003b5_Sl0fMWI00<000000=WIf@3IfMT0?`3IfMT0102nQC`000000000000lQKhl0=WIf@08 0=WIXP1S000000000000000003`0QKkI0=WIf@2nQC`20000000303b5_P3IfMT0fMWI0040fMWI0008 0=WIf@030=VRH`0lQKh0fMWI0080fMWI00D0QF>50=WIf@3IfMT0QCaS0:;If@0j0=WIf@060=VnQ@0l ?8D0fMWI0=WIf@25?3`0QKkI?P3IfMT00`000000fMWI0=WIf@0n0=WIf@060=VnQ@0l?8D0fMWI0=WI f@25?3`0QKkI?@3IfMT00`3IXV<0?8Fn0=WIf@020=WIf@0508ESQ@3IfMT0fMWI08DlH`2RfMT00P3I fMT000P0fMWI00H0fJ9S03b5_P3IfMT0fMWI0=WIXP1S?8D20=WIf@030:9S?025_]T0fMWI03d0fMWI 00<0XVRf@3IfMT0fMWI0=VRH`0lQKh00P3IfMT01P3IfJ80Hcb50=WIf@3IfMT0 XV`3IfMT00`2RHc`0QKkI0=WIf@100=WI f@800000@03IfMT00`2RHc`0QKkI0=WIf@0n0=WIf@0308DlH`2RXV<0?8Fn00<0fMWI00D0QC`l08Fn f@3IfJ80H`1S0:;If@020=WIf@001`3IfMT00`3IXV<0000003b5_P030=WIf@040=VnQ@0l00000000 06>RfC`0fMWI00@0XV<000000000000006>R?`3IfMT00`000000fMWI0=WIf@0o0=WIf@040:9S0000 00000000001SXSd0fMWI00<0fJ9S0000000lQKh00`3IfMT0103I_XD0?0000000001SX]T30=WIf@00 T03IfMT00`000000fMWI0=WIf@2=0=WIf@00T03IfMT00`000000fMWI0=WIf@2=0=WIf@00T03IfMT0 0`000000fMWI0=WIf@2=0=WIf@00T03IfMT00`000000fMWI0=WIf@2=0=WIf@00T03IfMT00`000000 fMWI0=WIf@2=0=WIf@00T03IfMT00`000000fMWI0=WIf@2=0=WIf@000P3IfMWo000001l000000009 0=WIf@030000003IfMT0fMWI00X0fMWI00<000000=WIf@3IfMT02`3IfMT00`000000fMWI0=WIf@0: 0=WIf@030000003IfMT0fMWI00/0fMWI00<000000=WIf@3IfMT02P3IfMT00`000000fMWI0=WIf@0; 0=WIf@030000003IfMT0fMWI00X0fMWI00<000000=WIf@3IfMT02`3IfMT00`000000fMWI0=WIf@0; 0=WIf@030000003IfMT0fMWI00X0fMWI00<000000=WIf@3IfMT02`3IfMT00`000000fMWI0=WIf@0: 0=WIf@030000003IfMT0fMWI00/0fMWI00<000000=WIf@3IfMT02P3IfMT00`000000fMWI0=WIf@0; 0=WIf@030000003IfMT0fMWI00X0fMWI00<000000=WIf@3IfMT02`3IfMT00`000000fMWI0=WIf@0; 0=WIf@030000003IfMT0fMWI00X0fMWI00<000000=WIf@3IfMT02`3IfMT00`000000fMWI0=WIf@05 0=WIf@002@3IfMT00`000000fMWI0=WIf@100=WIf@030000003IfMT0fMWI0440fMWI00<000000=WI f@3IfMT0@@3IfMT00`000000fMWI0=WIf@110=WIf@030000003IfMT0fMWI00D0fMWI002@0=WIf@03 0000003IfMT0fMWI08d0fMWI002@0=WIf@030000003IfMT0fMWI08d0fMWI002@0=WIf@030000003I fMT0fMWI08d0fMWI002@0=WIf@030000003IfMT0fMWI08d0fMWI002@0=WIf@030000003IfMT0fMWI 08d0fMWI002@0=WIf@800000SP3IfMT00900fMWI00<000000=WIf@3IfMT0S@3IfMT00900fMWI00<0 00000=WIf@3IfMT0S@3IfMT00900fMWI00<000000=WIf@3IfMT0S@3IfMT00900fMWI00<000000=WI f@3IfMT0S@3IfMT00900fMWI00<000000=WIf@3IfMT0S@3IfMT00900fMWI00<000000=WIf@3IfMT0 S@3IfMT00900fMWI00<000000=WIf@3IfMT0S@3IfMT00900fMWI00<000000=WIf@3IfMT0S@3IfMT0 0900fMWI0P00002>0=WIf@00T03IfMT00`000000fMWI0=WIf@2=0=WIf@00T03IfMT00`000000fMWI 0=WIf@2=0=WIf@00T03IfMT00`000000fMWI0=WIf@2=0=WIf@00T03IfMT00`000000fMWI0=WIf@2= 0=WIf@00T03IfMT00`000000fMWI0=WIf@2=0=WIf@00T03IfMT00`000000fMWI0=WIf@2=0=WIf@00 T03IfMT00`000000fMWI0=WIf@2=0=WIf@00T03IfMT2000008h0fMWI002@0=WIf@030000003IfMT0 fMWI08d0fMWI002@0=WIf@030000003IfMT0fMWI08d0fMWI002@0=WIf@030000003IfMT0fMWI08d0 fMWI002@0=WIf@030000003IfMT0fMWI08d0fMWI002@0=WIf@030000003IfMT0fMWI08d0fMWI002@ 0=WIf@030000003IfMT0fMWI08d0fMWI002@0=WIf@030000003IfMT0fMWI08d0fMWI002@0=WIf@03 0000003IfMT0fMWI08d0fMWI002@0=WIf@800000SP3IfMT00900fMWI00<000000=WIf@3IfMT0S@3I fMT00900fMWI00<000000=WIf@3IfMT0S@3IfMT00900fMWI00<000000=WIf@3IfMT0S@3IfMT00900 fMWI00<000000=WIf@3IfMT0S@3IfMT00900fMWI00<000000=WIf@3IfMT0S@3IfMT007`0fMWI00@0 _XDl000000000000?8Fn0P3IfMT00`3IfJ80H`00000lQ@030=WIf@040;j5?0000000000003b5_P@0 fMWI00<000000=WIf@3IfMT0S@3IfMT007`0fMWI00D0QF>50=WIf@3IfMT0QCaS0:;If@060=WIf@06 0=VnQ@0l?8D0fMWI0=WIf@25?3`0QKkI0`3IfMT00`000000fMWI0=WIf@2=0=WIf@00N`3IfMT01P3I fJ80Hcb50=WIf@3IfMT0XVRf@P0 fMWI00@0XV<000000000000006>R103IfMT00`000000fMWI0=WIf@2=0=WIf@00T03IfMT00`000000 fMWI0=WIf@2=0=WIf@00T03IfMT00`000000fMWI0=WIf@2=0=WIf@00T03IfMT00`000000fMWI0=WI f@2=0=WIf@00T03IfMT00`000000fMWI0=WIf@2=0=WIf@00T03IfMT2000008h0fMWI002@0=WIf@03 0000003IfMT0fMWI08d0fMWI002@0=WIf@030000003IfMT0fMWI08d0fMWI002@0=WIf@030000003I fMT0fMWI08d0fMWI002@0=WIf@030000003IfMT0fMWI08d0fMWI002@0=WIf@030000003IfMT0fMWI 08d0fMWI002@0=WIf@030000003IfMT0fMWI08d0fMWI002@0=WIf@030000003IfMT0fMWI08d0fMWI 002@0=WIf@030000003IfMT0fMWI08d0fMWI002@0=WIf@800000SP3IfMT00900fMWI00<000000=WI f@3IfMT0S@3IfMT00900fMWI00<000000=WIf@3IfMT0S@3IfMT00900fMWI00<000000=WIf@3IfMT0 S@3IfMT00900fMWI00<000000=WIf@3IfMT0S@3IfMT00900fMWI00<000000=WIf@3IfMT0S@3IfMT0 0900fMWI00<000000=WIf@3IfMT0S@3IfMT00900fMWI00<000000=WIf@3IfMT0S@3IfMT00900fMWI 0P00002>0=WIf@00T03IfMT00`000000fMWI0=WIf@2=0=WIf@00T03IfMT00`000000fMWI0=WIf@2= 0=WIf@00T03IfMT00`000000fMWI0=WIf@2=0=WIf@00T03IfMT00`000000fMWI0=WIf@2=0=WIf@00 T03IfMT00`000000fMWI0=WIf@2=0=WIf@00T03IfMT00`000000fMWI0=WIf@2=0=WIf@00T03IfMT0 0`000000fMWI0=WIf@2=0=WIf@00T03IfMT2000008h0fMWI002@0=WIf@030000003IfMT0fMWI08d0 fMWI002@0=WIf@030000003IfMT0fMWI08d0fMWI002@0=WIf@030000003IfMT0fMWI08d0fMWI002@ 0=WIf@030000003IfMT0fMWI08d0fMWI002@0=WIf@030000003IfMT0fMWI08d0fMWI002@0=WIf@03 0000003IfMT0fMWI08d0fMWI00270=WIf@060=WIXP1S000000000000000003`0QKkI0`3IfMT00`00 0000fMWI0=WIf@2=0=WIf@00R@3IfMT00`3IXV<0?8Fn0=WIf@040=WIf@030000003IfMT0fMWI08d0 fMWI00290=WIf@030=VRH`0lQKh0fMWI00@0fMWIR@0000070=WIf@00R@3IfMT00`3IXV<0?8Fn0=WI f@040=WIf@030000003IfMT0fMWI08d0fMWI00280=WIf@0308DlH`2RXV<0?8Fn00D0fMWI00<00000 0=WIf@3IfMT0S@3IfMT008P0fMWI00<0fJ9S0000000lQKh01@3IfMT00`000000fMWI0=WIf@2=0=WI f@00T03IfMT00`000000fMWI0=WIf@2=0=WIf@00\ \>"], ImageRangeCache->{{{0, 287}, {176.938, 0}} -> {-10.6638, -1.05557, \ 0.0737416, 0.0119317}}], Cell[BoxData[ TagBox[\(\[SkeletonIndicator] Graphics \[SkeletonIndicator]\), False, Editable->False]], "Output"] }, Closed]], Cell[TextData[{ " The form ", StyleBox["s", "TI"], StyleBox["_", "MR"], " is equivalent to ", StyleBox["s", "TI"], StyleBox[":_", "MR"], "." }], "Text"], Cell[BoxData[ \(\(function2[tree : \ {a__, \ b__}] := tree;\)\)], "Input"], Cell["Does not pattern match", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(function2[1, 2]\)], "Input"], Cell[BoxData[ \(function2[1, 2]\)], "Output"] }, Open ]], Cell["Matches pattern returns tree", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(function2[{1, 2}]\)], "Input"], Cell[BoxData[ \({1, 2}\)], "Output"] }, Open ]], Cell[TextData[{ "See ", ButtonBox["Messages", ButtonData:>"Messages", ButtonStyle->"Hyperlink"], " for information on giving users feedback when they enter incorrect \ arguments (incorrect type or number of arguments)." }], "Text"] }, Closed]], Cell[CellGroupData[{ Cell["Messages", "Subtitle", CellTags->"Messages"], Cell[TextData[{ "In addition to what I present here you might also want to study the Error \ handling section of Tod ", "Gayley's", " ", ButtonBox["PackageDesignTutorial.nb", ButtonData:>{ URL[ "http://library.wolfram.com/infocenter/Conferences/184"], None}, ButtonStyle->"Hyperlink"], ". The section covers good use of messages." }], "Text", FontFamily->"Times New Roman"], Cell[TextData[{ "Messages ", Cell[BoxData[ ButtonBox[\(2.9 .21\), ButtonData:>{"2.9.21", "21.28"}, ButtonStyle->"MainBookLink"]], FontFamily->"Times New Roman"] }], "Text"], Cell[TextData[{ "Why messages? Messages give a notebook user feedback if he/she is doing \ something wrong. They are not intended for true error handling, see ", ButtonBox["Exceptions", ButtonData:>"Exceptions", ButtonStyle->"Hyperlink"], "." }], "Text", FontFamily->"Times New Roman"], Cell["\<\ Messages are useful for interacting with the user, warning the user s/he has \ done something wrong, while catch and throw allows a program to handle errors \ correctly. For example, if a user tries to divide by 0 it is useful to show \ the user an error message. On the other hand, if in our program we are taking \ averages and we do not care about division by 0 (it just means there is no \ data for that interval), we may want to just handle these cases by returning \ some value.\ \>", "Text", FontFamily->"Times New Roman"], Cell[CellGroupData[{ Cell["Creating error messages similar to Mathematica's", "Subsection"], Cell[CellGroupData[{ Cell[BoxData[ \(Sin[1, 2, 3, 4]\)], "Input"], Cell[BoxData[ RowBox[{\(Sin::"argx"\), \(\(:\)\(\ \)\), "\<\"\\!\\(Sin\\) called with \ \\!\\(4\\) arguments; 1 argument is expected. \\!\\(\\*ButtonBox[\\\"More\ \[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, \ ButtonData:>\\\"General::argx\\\"]\\)\"\>"}]], "Message"], Cell[BoxData[ \(Sin[1, 2, 3, 4]\)], "Output"] }, Closed]], Cell["\<\ this is a nontrivial example of messages, which requires a good understanding \ of the /; operator\ \>", "Text"], Cell[BoxData[ \(computation[x___ /; Length[{x}] === 3]\ := Module[{}, \[IndentingNewLine] (*x\ should\ have\ 3\ arguments\ *) \[IndentingNewLine]"\"\[IndentingNewLine]]\)], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(computation[1, 2, 3]\)], "Input"], Cell[BoxData[ \("happy"\)], "Output"] }, Closed]], Cell[CellGroupData[{ Cell[BoxData[ \(computation::"\" = "\<`1` called with `2` arguments; 3 arguments \ are expected.\>"\)], "Input"], Cell[BoxData[ \("`1` called with `2` arguments; 3 arguments are expected."\)], "Output"] }, Closed]], Cell[CellGroupData[{ Cell[BoxData[ \(Message[computation::argx, 1233, 99]\)], "Input"], Cell[BoxData[ RowBox[{\(computation::"argx"\), \(\(:\)\(\ \)\), "\<\"\\!\\(1233\\) \ called with \\!\\(99\\) arguments; 3 arguments are expected. \ \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\ \\\", ButtonFrame->None, ButtonData:>\\\"General::argx\\\"]\\)\"\>"}]], \ "Message"] }, Closed]], Cell["\<\ We could use the definition \ computation[expr____]:=Message[computation::argx,expr,Length[{expr}]]. That \ would cause computation[expr] with an invalid argument to evaluate to a \ message and the input expression would not be returned. But we want \ computation to work like a built-in function so we have it post a message, \ and return expression passed to computation. This can be done by putting the \ message in a condition as in the next line. When this is done the condition \ will never evaluate to True, so the right side of the definition can be \ almost anything. (Text compliments of Ted Ersek)\ \>", "Text"], Cell[BoxData[ \(\(computation[expr___] /; Message[computation::"\", computation, Length[{expr}]] := "\";\)\)], "Input"], Cell["\<\ This last definition is a \"catch-all\" that traps any cases that do not meet \ the conditions for the more specific function definition(s).\ \>", "Text"], Cell["\<\ Now computation works like built in function, returning the unevaluted \ expression when given bad input.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(computation[1, 2, 3, 4]\)], "Input"], Cell[BoxData[ RowBox[{\(computation::"argx"\), \(\(:\)\(\ \)\), \ "\<\"\\!\\(computation\\) called with \\!\\(4\\) arguments; 3 arguments are \ expected. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", \ ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, \ ButtonData:>\\\"General::argx\\\"]\\)\"\>"}]], "Message"], Cell[BoxData[ \(computation[1, 2, 3, 4]\)], "Output"] }, Closed]], Cell["Alternatively this can be done using argument count", "Text"] }, Closed]], Cell[CellGroupData[{ Cell["Preexisting error messages and error functions", "Subsection"], Cell["\<\ Typing General:: into the Mathematica Help Browser brings up notes for the \ hundreds of preexisting Mathematica messages. The messages are categorized by \ the type of function they are associated to. These can be reused in your own \ functions with little effort. Because there are so many built in messages, it \ can be a daunting task to find a message appropriate for your function. Using \ a search engine to search Wolfram's Documentation site is a quick way to find \ the message you need. For example, if you are looking for a message to warn \ the user about not using a matrix, we could do a search for matrix on \ Wolframs message notes documentation using the following search command in \ the Yahoo search engine:\ \>", "Text"], Cell[BoxData[ RowBox[{ ButtonBox[ ButtonBox[\(\(matrix\ \*"\"\<\>" warning\ messages\) \*"\"\<\>"\ \(inurl : functions\ \(hostname : documents . wolfram . com\)\)\), ButtonStyle->"Hyperlink"], ButtonData:>{ URL[ "http://search.yahoo.com/search?p=matrix%20%22warning%20messages%22%\ 20inurl:functions%20hostname:documents.wolfram.com"], None}, ButtonStyle->"Hyperlink"], "."}]], "Text"], Cell["\<\ This command searches the hostname \"documents.wolfram.com\" in any \ subdirectory named \"functions\" for any files containg the words \"Warning \ Messages\". The command may need to be modified if the documentation site \ ever changes.\ \>", "Text"], Cell["\<\ In addition to built in error messages, Mathematica provides some functions \ useful for handling errors.\ \>", "Text"], Cell[CellGroupData[{ Cell["Argument Count", "Subsubsection"], Cell["\<\ The method provided in example above is cumbersome. Mathematica has a built \ in argumentcountq for argument count error checking\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(\(?ArgumentCountQ\)\)], "Input"], Cell[BoxData[ \("ArgumentCountQ[head, len, min, max] tests whether the number len of \ arguments of a function head is between min and max."\)], "Print", CellTags->"Info3332076394-1177643"] }, Open ]], Cell["\<\ (*ClearAll[ , ,...] clear all values for the, including attributes, messages \ and defaults*)\ \>", "Text"], Cell[BoxData[ \(\(\(ClearAll[computation]\)\(\ \)\)\)], "Input"], Cell[BoxData[ \(computation[expr___] := Module[{}, \[IndentingNewLine] (*x\ should\ have\ 3\ arguments\ *) \[IndentingNewLine]"\"\[IndentingNewLine]] /; ArgumentCountQ[computation, Length[{expr}], 3, 3]\)], "Input"], Cell["\<\ When ArgumentCountQ test fails, a warning message is automatically generated.\ \ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(computation[1, 2, 3, 4]\)], "Input"], Cell[BoxData[ RowBox[{\(computation::"argrx"\), \(\(:\)\(\ \)\), "\<\"\\!\\(computation\ \\) called with \\!\\(4\\) arguments; \\!\\(3\\) arguments are expected. \ \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\ \\\", ButtonFrame->None, ButtonData:>\\\"General::argrx\\\"]\\)\"\>"}]], \ "Message"], Cell[BoxData[ \(computation[1, 2, 3, 4]\)], "Output"] }, Open ]], Cell["When ArgumentCountQ test passes, the function is evaluated.", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(computation[1, 2, 3]\)], "Input"], Cell[BoxData[ \("happy"\)], "Output"] }, Open ]] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["Search path for messages", "Subsection"], Cell[TextData[{ "From Mathbook section 2.9.21\nWhen you call ", StyleBox["Message", "MR"], ", it first tries to find a message with the explicit name you have \ specified. If this fails, it tries to find a message with the appropriate tag \ associated with the symbol ", StyleBox["General", "MR"], ". If this too fails, then ", StyleBox["Mathematica", "TI"], " takes any function you have defined as the value of the global variable \ ", StyleBox["$NewMessage", "MR"], ", and applies this function to the symbol and tag of the message you have \ requested. " }], "Text"], Cell[TextData[{ "By setting up the value of ", StyleBox["$NewMessage", "MR"], " appropriately, you can, for example, get ", StyleBox["Mathematica", "TI"], " to read in the text of a message from a file when that message is first \ needed. " }], "Text"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["Creating and Accessing a Database with Pattern Matching", "Subtitle"], Cell[TextData[{ "Structures and databases can be used to avoid long lists of input or \ output arguments. They can be used interchangably, but subtle differences \ between the two in ", StyleBox["Mathematica", FontSlant->"Italic"], " make one more appropriate than the other in some cases. In general, \ structures allow direct access to data, while databases store data and and \ allow the use of pattern matching functions to access parts of the data. See \ section on \"Structured Data Types in Mathmatica and using Down-values and \ Up-values\" and \"Modularization\"->\"Function Organization\"." }], "Text"], Cell[CellGroupData[{ Cell["Example Database", "Section"], Cell[BoxData[ \(Clear[patientDB]\)], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(mypatientDB\ = \ \ "\"[\[IndentingNewLine]\[IndentingNewLine]"\"["\"["\"], "\"["\"], \ \ "\"["\<555-1232\>"]], \[IndentingNewLine]"\"["\"["\"], "\"["\"], \ \ "\"["\<555-1232\>"]], \[IndentingNewLine]"\"["\"["\"], "\"["\"], \ \ "\"["\<555-1232\>"]], \[IndentingNewLine]"\"["\"["\"], "\"["\"], \ \ "\"["\<934-8234\>"]]\[IndentingNewLine]"\"["\"["\"], "\"["\"], \ \ "\"["\<398-1234\>"]]\[IndentingNewLine]]\)], "Input"], Cell[BoxData[ \("patientDB"[ "patient record"["name"["John Doe"], "address"["Columbia, MD"], "phone"["555-1232"]], "patient record"["name"["Jim Doe"], "address"["Columbia, MD"], "phone"["555-1232"]], "patient record"["name"["Jane Doe"], "address"["Columbia, MD"], "phone"["555-1232"]], "patient record"["name"["John Smith"], "address"["Columbia, MD"], "phone"["398-1234"]]\ "patient record"["name"["John Smith"], "address"["Washington, DC"], "phone"["934-8234"]]]\)], "Output"] }, Closed]], Cell["Get all phone numbers", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(Cases[mypatientDB, "\"[_], \[Infinity]]\)], "Input"], Cell[BoxData[ \({"phone"["555-1232"], "phone"["555-1232"], "phone"["555-1232"], "phone"["398-1234"], "phone"["934-8234"]}\)], "Output"] }, Closed]], Cell["Get all patient records with the name field \"John Doe\"", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(Cases[ mypatientDB, "\"["\"["\"], ___]]\)], \ "Input"], Cell[BoxData[ \({"patient record"["name"["John Doe"], "address"["Columbia, MD"], "phone"["555-1232"]]}\)], "Output"] }, Closed]], Cell[CellGroupData[{ Cell["\<\ While it may be tempting to use symbols for entries in your database, it is \ not recommended. Using a symbol for entries will cause complication when \ manipulating the database in a package with context (see below) or a module \ with local variables. For Example,\ \>", "Subsection"], Cell[TextData[{ "The below example demonstrates the concept as the example used in ", "Structured Data Types in ", StyleBox["Mathematica", FontSlant->"Italic"], " and using Down-values and Up-values ->", "Managing simple structures with down values. " }], "Text"], Cell["\<\ (*Create a database, note that there are no downvalues assigned here*)\ \>", "Text"], Cell[BoxData[ \(\(myDb\ = \ dbCell[deliver, \ rules[op \[Rule] 3, \ \ T \[Rule] 2]];\)\)], "Input"], Cell["\<\ (*Create a function that prints the database entries, the Module command \ mimics package context*)\ \>", "Text"], Cell[BoxData[ \(f[db_] := Module[{op, deliver, T, \ rules}, p = {op /. \((List @@ db[\([\(-1\)]\)])\), MemberQ[db, \ deliver], \ T /. List @@ db[\([\(-1\)]\)]}]\)], "Input"], Cell["\<\ (*function does not work because the symbols (op, deliver and T) are defined \ as local and do not pattern match the global symbols.*)\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(f[myDb]\)], "Input"], Cell[BoxData[ \({op$33, False, T$33}\)], "Output"] }, Open ]], Cell["\<\ There are two potential solutions to this problem. (1) Export all symbols \ used in your database in the same manner used when exporting your functions. \ (2) Use global symbols for all symbols in your database (see below). The \ problem with (1) is that databases may contain the same symbols such as unit, \ or have symbols generated on the fly. If the same symbols are used in \ different packages, they will cause shadowing problems if exported. (2) is \ cumbersome and likely to be overlooked when developing new functions outside \ of a package, which most certainly will lead to problems when moving these \ functions into a package.\ \>", "Text"], Cell[TextData[{ "In addition, if you decide to use single letters as symbols in your \ database, exporting will not work conflicting with internal ", StyleBox["Mathematica", FontSlant->"Italic"], " functions and symbols. Of course, using capital uppercase symbols is \ contrary to the self-documenting naming conventions defined in the above." }], "Text"], Cell["\<\ (*Example of (2) Corrected function using the Symbol function to create the \ global symbol*)\ \>", "Text"], Cell[BoxData[ \(f[db_] := Module[{op, deliver, T, \ rules}, p = {Symbol["\"] /. \((List @@ db[\([\(-1\)]\)])\), MemberQ[db, \ Symbol["\"]], \ Symbol["\"] /. List @@ db[\([\(-1\)]\)]}]\)], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(f[myDb]\)], "Input"], Cell[BoxData[ \({3, True, 2}\)], "Output"] }, Open ]], Cell[TextData[{ "To avoid such problems altogether use ", StyleBox["strings", FontWeight->"Bold"], " for your database patterns e.g. \"db\"[\"unit\"[4]->{\"entry\"}]." }], "Text"] }, Closed]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell[TextData[{ "Structured Data Types in ", StyleBox["Mathematica", FontSlant->"Italic"] }], "Subtitle", CellTags->"Exceptions"], Cell[TextData[{ "Structures and databases can be used to avoid long lists of input or \ output arguments. They can be used interchangably, but subtle differences \ between the two in ", StyleBox["Mathematica", FontSlant->"Italic"], " make one more appropriate than the other in some cases. In general, \ structures allow direct access to data, while databases store data and allow \ the use of pattern matching functions to access parts of the data. See \ section on \"Creating and accessing a database with pattern matching\" and \ \"Modularization\"->\"Function Organization\"." }], "Text"], Cell[CellGroupData[{ Cell["Managing simple structures with down values", "Section"], Cell["\<\ Mathematica allows for many ways to handle structured data. I present a \ simple method of using creating and accessing structured data without the \ hassle of full OOP\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(myline@"\" = {1, 2}\)], "Input"], Cell[BoxData[ \({1, 2}\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(myline@"\" = {3, 4}\)], "Input"], Cell[BoxData[ \({3, 4}\)], "Output"] }, Open ]], Cell["Methods", "Text"], Cell[BoxData[ \(distance /: x_[distance] /; \ \((ValueQ[x@"\"] && ValueQ[x@"\"])\) := Sqrt[\((\((x@"\")\)[\([2]\)] - \ \((x@"\")\)[\([2]\)])\)^2 + \((\((x@"\")\)[\([1]\)] - \ \((x@"\")\)[\([1]\)])\)^2]\)], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(myline@distance\)], "Input"], Cell[BoxData[ \(2\ \@2\)], "Output"] }, Open ]], Cell["Alternatively", "Text"], Cell[BoxData[ \(distance[ x_]\ /; \ \((ValueQ[x@"\"] && ValueQ[x@"\"])\) := \ Sqrt[\((\((x@"\")\)[\([2]\)] - \ \((x@"\")\)[\([2]\)])\)^2 + \((\((x@"\")\)[\([1]\)] - \ \((x@"\")\)[\([1]\)])\)^2]\)], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(myline // distance\)], "Input"], Cell[BoxData[ \(2\ \@2\)], "Output"] }, Open ]], Cell[BoxData[ \( (*Potential\ context\ problem\ when\ creating\ definition\ in\ one\ \ context\ then\ using\ in\ another\ context . \ Make\ sure\ to\ Export\ distance\ when\ exporting\ your\ other\ \ functions*) \)], "Input"], Cell[CellGroupData[{ Cell["\<\ While it may be tempting to use symbols to reference downvalues, it is not \ recommended. Using a symbol to reference a downvalue will cause complication \ when manipulating the database in a package with context (see below) or a \ module with local variables. For Example,\ \>", "Subsection"], Cell["(*Create a structure with the following down values*)", "Text"], Cell[BoxData[{ \(\(Struct[theNumber] = 1;\)\), "\n", \(\(Struct[theRule] = PlotRange \[Rule] {{0, 1}, {0, 1}};\)\), "\n", \(\(Struct[theList] = {1, 2, 3};\)\)}], "Input"], Cell["\<\ (*Create a function that prints the structure entries, the Module command \ mimics package context*)\ \>", "Text"], Cell[BoxData[ \(f[struct_] := Module[{theNumber, theRule, theList}, p = {struct, struct[theNumber], struct[theRule], struct[theList]}; Print[p]]\)], "Input"], Cell["\<\ (*function does not work because the symbols (theNumber, theRule, and \ theList) are defined as local and do not pattern match the global \ symbols.*)\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(f[Struct]\)], "Input"], Cell[BoxData[ \({Struct, Struct[theNumber$48], Struct[theRule$48], Struct[theList$48]}\)], "Print"] }, Closed]], Cell["\<\ There are two potential solutions to this problem. (1) Export all downvalues \ used in the same manner used when exporting your functions via usage \ messages. (2) Use global symbols for all downvalues (see below). The problem \ with (1) is that most structures will use the same fields such as time or \ size. If these symbols are used for downvalues in different packages, they \ will cause shadowing problems if exported. (2) is cumbersome and likely to be \ overlooked when developing new functions outside of a package, which most \ certainly will lead to problems when moving these functions into a package.\ \>", "Text"], Cell["\<\ (*Example of (2) Corrected function using the Symbol function to create the \ global symbol*)\ \>", "Text"], Cell[BoxData[ \(f[db_] := Module[{theNumber, theRule, theList}, p = {db, db[Symbol["\"]], db[Symbol["\"]], db[Symbol["\"]]}; Print[p]]\)], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(f[Struct]\)], "Input"], Cell[BoxData[ \({Struct, 1, PlotRange \[Rule] {{0, 1}, {0, 1}}, {1, 2, 3}}\)], "Print"] }, Closed]], Cell[TextData[{ "To avoid such problems altogether use ", StyleBox["strings", FontWeight->"Bold"], " for your Structure patterns e.g. Struct[\"theNumber\"]=1." }], "Text"] }, Closed]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell[TextData[Cell[BoxData[ \(TraditionalForm\`Abstraction\^4\)]]], "Subtitle"], Cell[BoxData[""], "Text"], Cell[TextData[{ "This section is primarly derived from ", ButtonBox["Mathematica's Programming Language.", ButtonData:>{ URL[ "http://library.wolfram.com/infocenter/Conferences/183/"], None}, ButtonStyle->"Hyperlink"] }], "Text"], Cell["\<\ Abstraction refers to the act of representing essential features without \ including the background details or explanations. Abstract Data Types (ADTs) allow for handling data bits in meaningful \ manners. Classes created in OOP use the concept of abstraction and are defined as a \ list of abstract attributes. \ \>", "Text"], Cell[CellGroupData[{ Cell[TextData[{ "Abstract Data Types (taken from Roman E. Maeder ", ButtonBox["Mathematica's\nProgramming Language", ButtonData:>{ URL[ "http://library.wolfram.com/infocenter/Conferences/183/"], None}, ButtonStyle->"Hyperlink"], ")" }], "Section", Evaluatable->False, AspectRatioFixed->True], Cell["\<\ Abstract data types are both a theoretically well-defined concept and a \ useful tool for program development. Following the principles of abstract data type design, one arrives at a clear separation of specification and \ implementation.\ \>", "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ StyleBox["Abstract data types are defined in terms of type names, function \ names, and\nequations. These can be realized in ", CellMargins->{{Inherited, Inherited}, {Inherited, 4}}, Evaluatable->False, AspectRatioFixed->True], StyleBox["Mathematica", CellMargins->{{Inherited, Inherited}, {Inherited, 4}}, Evaluatable->False, AspectRatioFixed->True, FontSlant->"Italic"], StyleBox[" very easily. The equations\nbecome rewrite rules. The \ interactive nature of ", CellMargins->{{Inherited, Inherited}, {Inherited, 4}}, Evaluatable->False, AspectRatioFixed->True], StyleBox["Mathematica", CellMargins->{{Inherited, Inherited}, {Inherited, 4}}, Evaluatable->False, AspectRatioFixed->True, FontSlant->"Italic"], StyleBox[" makes it well\nsuited for rapid prototyping and testing of \ designs.", CellMargins->{{Inherited, Inherited}, {Inherited, 4}}, Evaluatable->False, AspectRatioFixed->True] }], "Text", CellMargins->{{Inherited, Inherited}, {Inherited, 4}}, Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ StyleBox["A detailed discussion of abstract data types in ", Evaluatable->False, AspectRatioFixed->True], StyleBox["Mathematica", Evaluatable->False, AspectRatioFixed->True, FontSlant->"Italic"], StyleBox[" can be found in\n", Evaluatable->False, AspectRatioFixed->True], StyleBox["The Mathematica Programmer", Evaluatable->False, AspectRatioFixed->True, FontSlant->"Italic"], StyleBox[", and in Vol. 2, No. 3 of ", Evaluatable->False, AspectRatioFixed->True], StyleBox["The", Evaluatable->False, AspectRatioFixed->True, FontSlant->"Italic"], StyleBox[" ", Evaluatable->False, AspectRatioFixed->True], StyleBox["Mathematica", Evaluatable->False, AspectRatioFixed->True, FontSlant->"Italic"], StyleBox["\n", Evaluatable->False, AspectRatioFixed->True], StyleBox["Journal", Evaluatable->False, AspectRatioFixed->True, FontSlant->"Italic"], StyleBox[". Here is a short excerpt and an example.", Evaluatable->False, AspectRatioFixed->True] }], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[CellGroupData[{ Cell["How to Define a Data Type", "Subsection", Evaluatable->False, AspectRatioFixed->True], Cell["Define the names of the sorts to be used.", "Text", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True], Cell["Define the constants to be used.", "Text", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True], Cell["Define constructors and selectors.", "Text", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True], Cell["Write down the equations that should hold.", "Text", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True] }, Closed]], Cell[CellGroupData[{ Cell["How to implement a Data Type", "Subsection", Evaluatable->False, AspectRatioFixed->True], Cell["\<\ Choose a representation for elements of the sorts defined. Usually you can use a normal expression having the name of the sort as head. This corresponds roughly to a record in many programming languages.\ \>", "Text", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True], Cell["\<\ Derive rules for normal forms for the data elements. This ensures that elements are stored in a unique way. The rules are derived from the equations and can normally be put into the constructors.\ \>", "Text", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True], Cell["\<\ Define constructors and selectors. These are the only operations that are allowed access to the details of the internal representations.\ \>", "Text", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ StyleBox["Define the other operations.\nAn operation for which exactly one \ equation exists can usually be turned into\na simple rewrite rule. (Such an \ operation is called a ", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True], StyleBox["derived", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True, FontSlant->"Italic"], StyleBox[" operation.) The\nvariables in the left side of the rules are in \ the form ", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True], StyleBox["n", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier", FontWeight->"Bold"], StyleBox["_", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier"], StyleBox["type", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier", FontWeight->"Bold", FontSlant->"Italic"], StyleBox[", restricting\nthe arguments to the correct types. Use only \ selectors to access parts of the\ndata elements on the right side of the \ rules.", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True] }], "Text", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True], Cell["\<\ Use overloading where appropriate. Overloading built-in functions is most easily done by defining up-values, rules of the form\ \>", "Text", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ StyleBox["g/: f[n_g, ", Evaluatable->False, AspectRatioFixed->True], StyleBox["...", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Times", FontWeight->"Plain"], StyleBox["] := ", Evaluatable->False, AspectRatioFixed->True], StyleBox["...", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Times", FontWeight->"Plain"] }], "Input", Evaluatable->False, AspectRatioFixed->True], Cell["Choose a suitable output representation of data elements.", "Text", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True], Cell["Define automatic type conversions where useful.", "Text", CellDingbat->"\[FilledCircle]", Evaluatable->False, AspectRatioFixed->True] }, Closed]], Cell[CellGroupData[{ Cell["An Example", "Subsection", Evaluatable->False, AspectRatioFixed->True], Cell["This is a data type for modular numbers.", "Text", Evaluatable->False, AspectRatioFixed->True], Cell["Design", "Text", CellDingbat->"\[GrayCircle]", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ StyleBox["Sorts: ", Evaluatable->False, AspectRatioFixed->True], StyleBox[" mod, Integer", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier", FontWeight->"Bold"] }], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ StyleBox["Constants: ", Evaluatable->False, AspectRatioFixed->True], StyleBox[" p", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier", FontWeight->"Bold"] }], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ StyleBox["Constructors: ", Evaluatable->False, AspectRatioFixed->True], StyleBox[" makemod", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier", FontWeight->"Bold"] }], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ StyleBox["Selectors: ", Evaluatable->False, AspectRatioFixed->True], StyleBox[" rep", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier", FontWeight->"Bold"] }], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ StyleBox["Derived Operations: ", Evaluatable->False, AspectRatioFixed->True], StyleBox[" Plus, Times", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier", FontWeight->"Bold"] }], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ StyleBox["Equations: ", Evaluatable->False, AspectRatioFixed->True], StyleBox[" Mod[ rep[", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier", FontWeight->"Bold"], StyleBox[" ", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier", FontWeight->"Bold", FontSlant->"Italic"], StyleBox["mod[n] ] - n, p ] == 0", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier", FontWeight->"Bold"] }], "Text", Evaluatable->False, AspectRatioFixed->True], Cell["Implementation", "Text", CellDingbat->"\[GrayCircle]", Evaluatable->False, AspectRatioFixed->True], Cell["makemod[n_Integer] := mod[ Mod[n, p] ]", "Input", AspectRatioFixed->True], Cell["rep[ mod[n_] ] := n", "Input", AspectRatioFixed->True], Cell["\<\ mod/: m1_mod + m2_mod := makemod[ rep[m1] + rep[m2] ] mod/: m1_mod * m2_mod := makemod[ rep[m1] * rep[m2] ]\ \>", "Input", AspectRatioFixed->True], Cell[TextData[{ StyleBox["Note that we have ", Evaluatable->False, AspectRatioFixed->True], StyleBox["overloaded", Evaluatable->False, AspectRatioFixed->True, FontSlant->"Italic"], StyleBox[" the built-in addition and subtraction functions.\nThis \ corresponds directly to the use of the same names in the specification.", Evaluatable->False, AspectRatioFixed->True] }], "Text", Evaluatable->False, AspectRatioFixed->True], Cell["Usage", "Text", CellDingbat->"\[GrayCircle]", Evaluatable->False, PageBreakBelow->False, AspectRatioFixed->True], Cell["This sets the modulus to 5 for the computations that follow.", "Text", Evaluatable->False, PageBreakBelow->False, AspectRatioFixed->True], Cell["p = 5;", "Input", AspectRatioFixed->True], Cell[TextData[{ StyleBox["This makes two modular numbers and assigns them to the variables \ ", Evaluatable->False, AspectRatioFixed->True], StyleBox["m2", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier", FontWeight->"Bold"], StyleBox[" and ", Evaluatable->False, AspectRatioFixed->True], StyleBox["m3", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier", FontWeight->"Bold"], StyleBox[".", Evaluatable->False, AspectRatioFixed->True] }], "Text", Evaluatable->False, AspectRatioFixed->True], Cell["m2 = makemod[2]; m3 = makemod[3];", "Input", AspectRatioFixed->True], Cell["Their sum is 0 (modulo 5).", "Text", Evaluatable->False, AspectRatioFixed->True], Cell[CellGroupData[{ Cell["m2 + m3", "Input", AspectRatioFixed->True], Cell[OutputFormData["\<\ mod[0]\ \>", "\<\ mod[0]\ \>"], "Output", Evaluatable->False, AspectRatioFixed->True] }, Closed]], Cell["Their product is 1 (modulo 5).", "Text", Evaluatable->False, AspectRatioFixed->True], Cell[CellGroupData[{ Cell["m2 m3", "Input", AspectRatioFixed->True], Cell[OutputFormData["\<\ mod[1]\ \>", "\<\ mod[1]\ \>"], "Output", Evaluatable->False, AspectRatioFixed->True] }, Closed]] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["OOP", "Section"], Cell["\<\ In addition to abstraction, OOP provides Encapsulation, Inheritance, and \ Polymorphism.\ \>", "Text"], Cell["\<\ Although I have not used tried using the below OOP implemetation, it appears \ to be the most complete avaliable.\ \>", "Text"], Cell["In some cases full OOP may be an overkill", "Text"], Cell[CellGroupData[{ Cell["Download the required package", "Subsection"], Cell[TextData[{ "Download ", Cell[BoxData[ ButtonBox[\(classes . m\), ButtonData:>{ URL[ "http://library.wolfram.com/infocenter/Articles/3243/"], None}, ButtonStyle->"Hyperlink"]]], " and save to the ", " ", ButtonBox["appropriate directory", ButtonData:>"UsingPackages", ButtonStyle->"Hyperlink"], "." }], "Text"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Object-oriented Programming ", "(taken from Roman E. Maeder ", ButtonBox["Mathematica's\nProgramming Language", ButtonData:>{ URL[ "http://library.wolfram.com/infocenter/Conferences/183/"], None}, ButtonStyle->"Hyperlink"], ")" }], "Subsection", Evaluatable->False, AspectRatioFixed->True], Cell["\<\ Object-oriented programming is a programming style that is becoming more and more popular. It promises code-reuse and easier maintenance of larger \ projects than is possible with traditional procedural languages. Its use of methods \ and message passing instead of procedure calls shifts the programmer's view towards close integration of data and operations.\ \>", "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ StyleBox["An interactive object-oriented language can easily be implemented \ in\n", Evaluatable->False, AspectRatioFixed->True], StyleBox["Mathematica", Evaluatable->False, AspectRatioFixed->True, FontSlant->"Italic"], StyleBox[". The implementation is in the package ", Evaluatable->False, AspectRatioFixed->True], StyleBox["Classes.m", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier", FontWeight->"Bold"], StyleBox[", available from\n", Evaluatable->False, AspectRatioFixed->True], StyleBox["MathSource.", Evaluatable->False, AspectRatioFixed->True, FontSlant->"Italic"] }], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[CellGroupData[{ Cell["Objects and Classes", "Subsubsection", Evaluatable->False, AspectRatioFixed->True], Cell["\<\ The first important aspect of object-oriented languages is that functions are considered part of data. A data object \"knows\" which operations can be performed on it. The functions defined for a certain type of object are part of that object.\ \>", "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ StyleBox["Thus an ", Evaluatable->False, AspectRatioFixed->True], StyleBox["object", Evaluatable->False, AspectRatioFixed->True, FontSlant->"Italic"], StyleBox[" is a collection of data elements and operations", Evaluatable->False, AspectRatioFixed->True], StyleBox[" ", Evaluatable->False, AspectRatioFixed->True], StyleBox["that act on these data elements. The operations are called ", Evaluatable->False, AspectRatioFixed->True], StyleBox["methods", Evaluatable->False, AspectRatioFixed->True, FontSlant->"Italic"], StyleBox[".", Evaluatable->False, AspectRatioFixed->True] }], "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ StyleBox["Methods are usually not defined for each object separately but \ are collected\nin a ", Evaluatable->False, AspectRatioFixed->True], StyleBox["class", Evaluatable->False, AspectRatioFixed->True, FontSlant->"Italic"], StyleBox[". Objects then belong to a class from which they take their \ methods.", Evaluatable->False, AspectRatioFixed->True] }], "Text", Evaluatable->False, AspectRatioFixed->True] }, Closed]], Cell[CellGroupData[{ Cell["Message Passing", "Subsubsection", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ StyleBox["A uniform mechanism, called ", Evaluatable->False, AspectRatioFixed->True], StyleBox["message passing", Evaluatable->False, AspectRatioFixed->True, FontSlant->"Italic"], StyleBox[", is provided for invoking the\ncorrect piece of code, if a \ function is called or, as we now prefer to say, if\na message is passed to an \ object to execute a certain method. This viewpoint\nemphasizes that it is the \ object's responsibility to react to a message.", Evaluatable->False, AspectRatioFixed->True] }], "Text", Evaluatable->False, AspectRatioFixed->True] }, Closed]], Cell[CellGroupData[{ Cell["Inheritance", "Subsubsection", Evaluatable->False, AspectRatioFixed->True], Cell["\<\ Often a number of related data types have some common characteristics. Some operations on them can be written in a way that does not depend on which of the data types the operations are applied to. Common characteristics of \ related data types can then be isolated and encapsulated in a new data type. The other data \ types are then made subtypes of the new type. They inherit the characteristics of the common type, and need only implement those aspects in which they differ from their supertype.\ \>", "Text", Evaluatable->False, AspectRatioFixed->True], Cell["\<\ Thus, much of the code needs to be written only once. This saves development time and--perhaps more important--ensures consistency, since a change needs to be made only once, instead of being applied to several almost identical pieces of code.\ \>", "Text", Evaluatable->False, AspectRatioFixed->True] }, Closed]], Cell[CellGroupData[{ Cell["An Example", "Subsubsection", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ StyleBox["The implementation of the object-oriented system in the package ", Evaluatable->False, AspectRatioFixed->True], StyleBox["Classes.m", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier", FontWeight->"Bold"], StyleBox[" is\ndescribed in detail in Vol. 3, No. 1 of ", Evaluatable->False, AspectRatioFixed->True], StyleBox["The", Evaluatable->False, AspectRatioFixed->True, FontSlant->"Italic"], StyleBox[" ", Evaluatable->False, AspectRatioFixed->True], StyleBox["Mathematica", Evaluatable->False, AspectRatioFixed->True, FontSlant->"Italic"], StyleBox[" ", Evaluatable->False, AspectRatioFixed->True], StyleBox["Journal", Evaluatable->False, AspectRatioFixed->True, FontSlant->"Italic"], StyleBox[". An update", Evaluatable->False, AspectRatioFixed->True], StyleBox["d\nversion of the package is available from ", Evaluatable->False, AspectRatioFixed->True], StyleBox["MathSource.", Evaluatable->False, AspectRatioFixed->True, FontSlant->"Italic"] }], "Text", Evaluatable->False, AspectRatioFixed->True], Cell["Needs[\"Classes`\"]", "Input", AspectRatioFixed->True], Cell["A class is declared with", "Text", Evaluatable->False, AspectRatioFixed->True], Cell[TextData[{ StyleBox["Class[ ", AspectRatioFixed->True], StyleBox["name", AspectRatioFixed->True, FontSlant->"Italic"], StyleBox[", ", AspectRatioFixed->True], StyleBox["superclass", AspectRatioFixed->True, FontSlant->"Italic"], StyleBox[", ", AspectRatioFixed->True], StyleBox["instance variables", AspectRatioFixed->True, FontSlant->"Italic"], StyleBox[", ", AspectRatioFixed->True], StyleBox["methods", AspectRatioFixed->True, FontSlant->"Italic"], StyleBox[" ]", AspectRatioFixed->True] }], "Input", AspectRatioFixed->True], Cell["\<\ An account has one instance variable, the balance, and methods to initialize it and to deposit and withdraw money and to ask what the balance is.\ \>", "Text", Evaluatable->False, AspectRatioFixed->True], Cell["\<\ Class[ Account, Object, {bal}, {{new, (new[super]; bal = #1)&}, {balance, bal&}, {deposit, Function[bal += #1]}, {withdraw, Function[bal -= #1]}, {delete, (If[ bal != 0, Print[\"Remaining balance:\", bal]]; delete[super])&} } ];\ \>", "Input", AspectRatioFixed->True], Cell[CellGroupData[{ Cell["a1 = new[Account, 100]", "Input", AspectRatioFixed->True], Cell[BoxData[ InterpretationBox["\<\"-\\!\\(Account\\)-\"\>", StringForm[ "-`1`-", Account], Editable->False]], "Output"] }, Closed]], Cell["\<\ Message passing is made to look like ordinary function calls. The object that receives the message is the first argument.\ \>", "Text", Evaluatable->False, AspectRatioFixed->True], Cell[CellGroupData[{ Cell["deposit[ a1, 200 ]", "Input", AspectRatioFixed->True], Cell[BoxData[ \(300\)], "Output"] }, Closed]], Cell[CellGroupData[{ Cell["withdraw[ a1, 500 ]", "Input", AspectRatioFixed->True], Cell[BoxData[ \(\(-200\)\)], "Output"] }, Closed]], Cell[TextData[{ StyleBox["Here is a subclass of ", Evaluatable->False, AspectRatioFixed->True], StyleBox["Account", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier", FontWeight->"Bold"], StyleBox[". It inherits most behavior. The method for\nwithdrawing money is \ ", Evaluatable->False, AspectRatioFixed->True], StyleBox["overridden", Evaluatable->False, AspectRatioFixed->True, FontSlant->"Italic"], StyleBox[" to check whether the balance is sufficient for\nthe withdrawal. \ If it is, we invoke the method in the superclass ", Evaluatable->False, AspectRatioFixed->True], StyleBox["Account", Evaluatable->False, AspectRatioFixed->True, FontFamily->"Courier", FontWeight->"Bold"], StyleBox[" to\nperform an ordinary withdrawal.", Evaluatable->False, AspectRatioFixed->True] }], "Text", Evaluatable->False, AspectRatioFixed->True], Cell["\<\ Class[ NoCreditAccount, Account, {}, {{withdraw, Function[ If[ balance[self] < #1, Print[\"cannot withdraw \", #1], withdraw[super, #1] ] ]} } ];\ \>", "Input", AspectRatioFixed->True], Cell[CellGroupData[{ Cell["a2 = new[NoCreditAccount, 1000]", "Input", AspectRatioFixed->True], Cell[BoxData[ InterpretationBox["\<\"-\\!\\(NoCreditAccount\\)-\"\>", StringForm[ "-`1`-", NoCreditAccount], Editable->False]], "Output"] }, Closed]], Cell[CellGroupData[{ Cell["withdraw[ a2, 900 ]", "Input", AspectRatioFixed->True], Cell[BoxData[ \(100\)], "Output"] }, Closed]], Cell[CellGroupData[{ Cell["withdraw[ a2, 110 ]", "Input", AspectRatioFixed->True], Cell[BoxData[ InterpretationBox[\("cannot withdraw "\[InvisibleSpace]110\), SequenceForm[ "cannot withdraw ", 110], Editable->False]], "Print"] }, Closed]], Cell[CellGroupData[{ Cell["balance[ a2]", "Input", AspectRatioFixed->True], Cell[BoxData[ \(100\)], "Output"] }, Closed]] }, Closed]] }, Open ]] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[TextData[Cell[BoxData[ \(TraditionalForm\`Exceptions\^5\)]]], "Subtitle"], Cell["\<\ The goal of exceptions (source wikipedia.org) Exception handling is intended to facilitate use of reasonable mechanisms for \ handling erroneous or exceptional situations that arise in programs. \ Exception handling can be used to pass information about error situations \ that occur within library code to its users, and selectively respond to those \ errors. A possible role of exception handling is to allow the program to \ continue its normal operation and prevent crashing and displaying of cryptic \ error messages to the user. In many cases, it is sufficient to stop the \ program and produce an error report; the difference with systems that do not \ use exceptions to signal improper program executions is that with proper \ exception handling, the erroneous condition may be pointed precisely, whereas \ otherwise it is often detected later, making debugging difficult. Exception \ handling makes the signal-handling technique used in other languages \ obsolete.\ \>", "Text"], Cell[TextData[{ "A thrown exception may seem cryptic to an end user who has no knowledge of \ a functions implementation. Thus, exceptions are not a good way to present \ errors to users. Mathematica provides ", ButtonBox["messages", ButtonData:>"Messages", ButtonStyle->"Hyperlink"], " which are more suitable for doing this." }], "Text"], Cell[CellGroupData[{ Cell[TextData[{ "Playing Catch and Throw (taken from Maeder's ", ButtonBox["Programming Bits", ButtonData:>{ URL[ "http://www.mathconsult.ch/math/stuff/Programming.nb"], None}, ButtonStyle->"Hyperlink"], ")" }], "Section"], Cell[TextData[{ "The rest of the section is taken from Maeder's ", ButtonBox["Programming Bits", ButtonData:>{ URL[ "http://www.mathconsult.ch/math/stuff/Programming.nb"], None}, ButtonStyle->"Hyperlink"], " with minor modifications." }], "Text"], Cell[TextData[{ "Exception handling in a program requires two primitive operations: ", StyleBox["raising", FontSlant->"Italic"], " an exception condition and ", StyleBox["handling", FontSlant->"Italic"], " an exception that has been raised.\nRaising an exception abandons the \ current flow of control and resumes execution of the program at a place where \ the exception is handled." }], "Text"], Cell[TextData[{ "Other terms used are ", StyleBox["throw", FontSlant->"Italic"], " for raise and ", StyleBox["catch", FontSlant->"Italic"], " for handle." }], "Text"], Cell[TextData[{ "In C:\n", StyleBox["setjmp(jmp_buf env)", FontFamily->"Courier"], " and ", StyleBox["longjmp(jmp_buf env, int val)", FontFamily->"Courier"], "." }], "Text"], Cell["Functional languages: handler is wrapper around expression.", "Text"], Cell[TextData[{ "Catch[ \[Ellipsis]Throw[", StyleBox["val", FontSlant->"Italic"], ",", StyleBox["tag", FontSlant->"Italic"], "]\[Ellipsis], ", StyleBox["tag", FontSlant->"Italic"], " ]" }], "Input", Evaluatable->False], Cell[TextData[{ "If an exception was thrown, ", StyleBox["Catch", "Input"], " returns with ", StyleBox["val", "Input", FontSlant->"Italic"], ", otherwise with the normal result." }], "Text"], Cell[CellGroupData[{ Cell["SML-style Raise/Handle", "Subsection"], Cell[TextData[{ "To get hold of ", StyleBox["tag", "Input", FontSlant->"Italic"], ":" }], "Text"], Cell[TextData[{ "Catch[ \[Ellipsis]Throw[", StyleBox["val", FontSlant->"Italic"], ",", StyleBox["tag", FontSlant->"Italic"], "]\[Ellipsis], ", StyleBox["pat", FontSlant->"Italic"], ", ", StyleBox["f", FontSlant->"Italic"], " ]" }], "Input", Evaluatable->False], Cell[TextData[{ "returns ", StyleBox["f[", "Input"], StyleBox["val", "Input", FontSlant->"Italic"], StyleBox[",", "Input"], StyleBox["tag", "Input", FontSlant->"Italic"], StyleBox["]", "Input"], " if an error is thrown and ", StyleBox["tag", "Input", FontSlant->"Italic"], " matches ", StyleBox["pat", "Input", FontSlant->"Italic"], "." }], "Text"], Cell["Use this to define SML-style functions:", "Text"], Cell[TextData[{ "Raise[", StyleBox["e", FontSlant->"Italic"], "]" }], "Input", Evaluatable->False], Cell[TextData[{ "Raise exception ", StyleBox["e", "Input", FontSlant->"Italic"], "." }], "Text"], Cell[TextData[{ "Handle[ ", StyleBox["compuation", FontSlant->"Italic"], ", ", StyleBox["pat", FontSlant->"Italic"], " :> ", StyleBox["action", FontSlant->"Italic"], " ]" }], "Input", Evaluatable->False], Cell[TextData[{ "Handle exceptions matching ", StyleBox["pat", "Input", FontSlant->"Italic"], " that happen during evaluation of ", StyleBox["computation", "Input", FontSlant->"Italic"], " and return corresponding ", StyleBox["action", "Input", FontSlant->"Italic"], "." }], "Text"], Cell["Java and newer versions of C++ offer similar features.", "Text"] }, Closed]], Cell[CellGroupData[{ Cell["Implementation", "Subsection"], Cell[TextData[{ "`errorCookie\nRaise[ error_ ] := ", StyleBox["Throw", FontColor->RGBColor[0, 0, 1]], "[", StyleBox["errorCookie", FontColor->RGBColor[1, 0, 0]], ", error]" }], "Input", Evaluatable->False], Cell[TextData[{ "SetAttributes[Handle, {HoldFirst}]\nHandle[try_, (", StyleBox["pattern", FontColor->RGBColor[0, 1, 1]], "_ :> ", StyleBox["action", FontColor->RGBColor[1, 0, 1]], "_)|(pattern_ -> action_)] :=\n ", StyleBox["Catch", FontColor->RGBColor[0, 0, 1]], "[try, ", StyleBox["pattern", FontColor->RGBColor[0, 1, 1]], ", exec[", StyleBox["pattern", FontColor->RGBColor[0, 1, 1]], " :> ", StyleBox["action", FontColor->RGBColor[1, 0, 1]], "]]" }], "Input", Evaluatable->False], Cell[TextData[{ "exec[rule_][ ", StyleBox["errorCookie", FontColor->RGBColor[1, 0, 0]], ", error_ ] := Replace[error, rule]" }], "Input", Evaluatable->False], Cell[TextData[{ "(", StyleBox["Replace[", "Input"], StyleBox["e", "Input", FontSlant->"Italic"], StyleBox[",", "Input"], StyleBox["r", "Input", FontSlant->"Italic"], StyleBox["]", "Input"], " is like ", StyleBox["e", "Input", FontSlant->"Italic"], StyleBox["/.", "Input"], StyleBox["r", "Input", FontSlant->"Italic"], " but matches only the whole expression.)" }], "Text"] }, Closed]], Cell[CellGroupData[{ Cell["Examples", "Subsection"], Cell[TextData[{ "Download ", ButtonBox["exceptions.m", ButtonData:>{ URL[ "http://www.mathconsult.ch/math/stuff/Exceptions.m"], None}, ButtonStyle->"Hyperlink"], " and save to the ", ButtonBox["appropriate directory", ButtonData:>"UsingPackages", ButtonStyle->"Hyperlink"], "." }], "Text"], Cell[BoxData[ \(Needs["\"]\)], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(\(?Exceptions`*\)\)], "Input"], Cell[BoxData[GridBox[{ { StyleBox["Exceptions`", FontFamily->"Helvetica", FontSize->12, FontWeight->"Bold"]}, {GridBox[{ { ButtonBox[ StyleBox["Exception", FontColor->RGBColor[0, 0, 1], FontVariations->{"Underline"->True}], ButtonFunction:>( Internal`PutInformation[ #, LongForm -> False]&), ButtonEvaluator->Automatic, ButtonData:>{"Info3330757616-5560609", "Exceptions`Exception"}, ButtonFrame->"None", ButtonNote->"Exceptions`"], ButtonBox[ StyleBox["Handle", FontColor->RGBColor[0, 0, 1], FontVariations->{"Underline"->True}], ButtonFunction:>( Internal`PutInformation[ #, LongForm -> False]&), ButtonEvaluator->Automatic, ButtonData:>{"Info3330757616-5560609", "Exceptions`Handle"}, ButtonFrame->"None", ButtonNote->"Exceptions`"], ButtonBox[ StyleBox["Intercept", FontColor->RGBColor[0, 0, 1], FontVariations->{"Underline"->True}], ButtonFunction:>( Internal`PutInformation[ #, LongForm -> False]&), ButtonEvaluator->Automatic, ButtonData:>{"Info3330757616-5560609", "Exceptions`Intercept"}, ButtonFrame->"None", ButtonNote->"Exceptions`"], ButtonBox[ StyleBox["Raise", FontColor->RGBColor[0, 0, 1], FontVariations->{"Underline"->True}], ButtonFunction:>( Internal`PutInformation[ #, LongForm -> False]&), ButtonEvaluator->Automatic, ButtonData:>{"Info3330757616-5560609", "Exceptions`Raise"}, ButtonFrame->"None", ButtonNote->"Exceptions`"], "", "", "", "", "", ""} }, RowMinHeight->1.05]} }, RowSpacings->{2, 3}, ColumnAlignments->{Left}, ColumnsEqual->True]], "Print", CellMargins->{{20, Inherited}, {Inherited, Inherited}}, ShowCellLabel->False, CellFrameMargins->{{Inherited, Inherited}, {14, 14}}, Background->RGBColor[0.964706, 0.929412, 0.839216], ButtonBoxOptions->{Active->True}] }, Closed]], Cell["computation", "Text"], Cell[BoxData[ \(compuation[x___]\ := Module[{}, \[IndentingNewLine] (*x\ should\ have\ 3\ arguments\ *) \[IndentingNewLine]If[Length[{x}] =!= 3, Raise["\"]]; \[IndentingNewLine]restofcompuation\ \[IndentingNewLine]]\)], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(Handle[\ compuation[1, 2, 3, 4], \ "\" \[RuleDelayed] $Failed]\)], "Input"], Cell[BoxData[ \($Failed\)], "Output"] }, Closed]], Cell["\<\ example modified (argument of Raise changed from symbol to string) to handle \ context correctly\ \>", "Text"], Cell[BoxData[ \(recip[x_]\ := \ If[\ x\ == \ 0, \ Raise["\"], \ 1/x\ ]\)], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(Handle[\ 1\ + \ recip[2], "\" :> \ Infinity\ ]\)], "Input"], Cell[BoxData[ \(3\/2\)], "Output"] }, Closed]], Cell[CellGroupData[{ Cell[BoxData[ \(Handle[\ 1\ + \ recip[0], \ "\"\ :> \ Infinity\ ]\)], "Input"], Cell[BoxData[ \(\[Infinity]\)], "Output"] }, Closed]], Cell["You may use patterns to handle several sorts of errors:", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(Handle[\ recip[0], \ e_\ :> \ Print["\", \ e]\ ]\)], "Input"], Cell[BoxData[ InterpretationBox[\("Error: "\[InvisibleSpace]"zeroDivision"\), SequenceForm[ "Error: ", "zeroDivision"], Editable->False]], "Print"] }, Closed]], Cell["Default handler:", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(recip[0]\)], "Input"], Cell[BoxData[ \(Exception::"uncaught" \(\(:\)\(\ \)\) "Uncaught exception \!\(\"zeroDivision\"\)."\)], "Message"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[TextData[{ "Interfacing With ", StyleBox["Mathematica", FontSlant->"Italic"], "'s Error Messages" }], "Subsection"], Cell[BoxData[ \(Needs["\"]\)], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(1/0\)], "Input"], Cell[BoxData[ RowBox[{\(Power::"infy"\), \(\(:\)\(\ \)\), "\<\"Infinite expression \ \\!\\(1\\/0\\) encountered. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", \ ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, \ ButtonData:>\\\"Power::infy\\\"]\\)\"\>"}]], "Message"], Cell[BoxData[ \(ComplexInfinity\)], "Output"] }, Closed]], Cell[CellGroupData[{ Cell[BoxData[ \(MessageList[]\)], "Input"], Cell[BoxData[ RowBox[{"{", TagBox[\(Power::"infy"\), HoldForm], "}"}]], "Output"] }, Closed]], Cell[BoxData[ \(Intercept[Power::infy, "\"]\)], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(Handle[1/0, "\" -> Infinity]\)], "Input"], Cell[BoxData[ \(\[Infinity]\)], "Output"] }, Closed]], Cell[CellGroupData[{ Cell[BoxData[ \($MessageList\)], "Input"], Cell[BoxData[ \({}\)], "Output"] }, Closed]], Cell["Useful for deeply nested errors, especially with I/O", "Text"], Cell[BoxData[ \(Intercept[\ OpenRead::noopen, \ IOError\ ]\)], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(Handle[\ OpenRead["\"], \ IOError\ -> \ $Failed\ ]\)], "Input"], Cell[BoxData[ \($Failed\)], "Output"] }, Open ]], Cell["\<\ Intercepting the message is not particularly useful unless you want to change \ what is returned from the function when an error occurs.\ \>", "Text"] }, Closed]], Cell[CellGroupData[{ Cell["Programmers' Maxim for Error Handling", "Subsection"], Cell["Never test for an error you don't know how to handle.", "Text", TextAlignment->Center], Cell[TextData[{ "More about this topic: ", StyleBox["The Mathematica Journa", FontSlant->"Italic"], "l, Vol.7, Issue 1." }], "Text"] }, Closed]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell["Debugging", "Subtitle"], Cell[TextData[{ StyleBox["Debugging functions in ", FontFamily->"Times New Roman"], StyleBox["Mathematica", FontFamily->"Times New Roman", FontSlant->"Italic"], StyleBox[" can be quite tricky. According Dave Withoff of Wolfram Research \ \"The next major release of Mathematica is expected to have additional \ features for debugging. These features are still under development and have \ not yet been widely used, so it is not yet known how useful these features \ will be in actual practice. The need for better debugging and error checking \ features in Mathematica has long been a concern of the programmers at Wolfram \ Research, and will probably continue to be so for the foreseeable future.\" \ He also offers some ", FontFamily->"Times New Roman"], StyleBox[ButtonBox["notes", ButtonData:>{ URL[ "http://library.wolfram.com/infocenter/Conferences/364"], None}, ButtonStyle->"Hyperlink"], FontFamily->"Times New Roman"], StyleBox[" that he put together on a ", FontFamily->"Times New Roman"], StyleBox["variety of ways of debugging Mathematica programs. \n\nI look \ forward to these additional features, but for now I debug functions using \ print messages or evaluting the function line by line in separate cells. ", FontFamily->"Times New Roman"] }], "Text"], Cell[TextData[{ "A function can be broken up for testing and debugging and put back \ together easily using ", ButtonBox["Divide Cell", ButtonStyle->"OtherInformationLink"], " (menu command) and ", ButtonBox["Merge Cells", ButtonStyle->"OtherInformationLink"], " (menu command). This does not work for debugging functions looping \ constructs within functions. ", StyleBox["(I am not sure if this is the most correct", FontFamily->"Times New Roman"], " way to debug, but I have yet to find appropriate alternative.)" }], "Text"], Cell[TextData[{ StyleBox["Using the methods discussed in the sections above to organize \ your code and handle errors can greatly reduce the amount of debugging. In \ addition to these methods, I use assert statements throughout my code to test \ for conditions that should hold. Because ", FontFamily->"Times New Roman"], StyleBox["Mathematica", FontFamily->"Times New Roman", FontSlant->"Italic"], StyleBox[" error messages don't include a line number (with the exception \ of some of the syntax error messages), it is often unclear where in a \ function an error is occuring. And for whatever reason, when an error occurs \ in ", FontFamily->"Times New Roman"], StyleBox["Mathematica", FontFamily->"Times New Roman", FontSlant->"Italic"], StyleBox[", the evalution continues on the $Failed or Null return argument \ (not sure of any other programming languages that do this) resuling in \ numerous beeps as each line of the remaing code in your function fails. Using \ assert messages can help to track down where an error is occuring in a large \ function or in functions that call other functions.", FontFamily->"Times New Roman"], "\n" }], "Text"], Cell[CellGroupData[{ Cell["Assert", "Section"], Cell[CellGroupData[{ Cell["Motivation", "Subsection"], Cell[TextData[{ "Assert statements can be used as a crude method to track down and prevent \ unknown states. For example, if you are calculating a speed of a car you can \ use an assert statement to see if the speed is resonable (between 0 and 100 \ mph). Assertions are widely used by programmers as a quick and effective way \ to detect and correct bugs. Moreover, assert statemetns add to the \ readability of code and help serve to document the logic or principles \ beneath the code. \n\n", StyleBox["Mathematica", FontFamily->"Times New Roman", FontSlant->"Italic"], StyleBox[" is a typeless programming language. As a result, it lacks some \ of the built in error detection of strongly typed programs. Using assert \ statements, it is possible to gain the effect of type checking. Users can \ also add type checking to function using the methods described in the \"", FontFamily->"Times New Roman"], "Function Overloading with Conditional Patterns\" section.", StyleBox["\n", FontFamily->"Times New Roman"], "\nEach assert statement contains an expression that should evaluate to a \ Boolean True or False and an error message." }], "Text"] }, Closed]], Cell[CellGroupData[{ Cell["Implementation", "Subsection"], Cell["\<\ Returns immediately when an assert condition fails printing the failed \ call.\ \>", "Text"], Cell[BoxData[ \(\(SetAttributes[assert, \ HoldFirst]\ ;\)\)], "Input", Evaluatable->False], Cell[BoxData[ \(assert[condition_, \ errmsg_String] := \ Module[{msg}, \[IndentingNewLine]\[IndentingNewLine]\ \(If[\(! \ ReleaseHold[condition]\), \[IndentingNewLine]msg\ = \ {"\", HoldForm[condition], "\<, \"\>", errmsg, "\<\"] failed. Error message is \"\>", \ errmsg, "\<\". \>"}; \ \[IndentingNewLine]\[IndentingNewLine]If[$Context =!= \ "\", \ \ \[IndentingNewLine]\(msg\ = \ Join[msg, \ {"\", \ \ $Context, \ "\<.\>"}];\)\[IndentingNewLine]]; \[IndentingNewLine]logMessage[ msg]; \[IndentingNewLine]\[IndentingNewLine]Throw[error, \ assert];\ \[IndentingNewLine]\[IndentingNewLine]];\)\ \[IndentingNewLine]]\)], "Input", Evaluatable->False], Cell[BoxData[ \(logMessage[msg_List] := Module[{y\ = \ StringJoin @@ \((ToString /@ msg)\)}, \ Print[y]; If[ValueQ[logStream], y >>> logStream\ ];]\)], "Input", Evaluatable->False] }, Closed]], Cell[CellGroupData[{ Cell["Examples", "Subsection"], Cell[TextData[{ "Read in the package for the following examples, requires ", ButtonBox["exceptions.m", ButtonData:>{ URL[ "http://www.mathconsult.ch/math/stuff/Exceptions.m"], None}, ButtonStyle->"Hyperlink"], "." }], "Text"], Cell[TextData[{ "Download programmingExtras.m and save to the ", ButtonBox["appropriate directory", ButtonData:>"UsingPackages", ButtonStyle->"Hyperlink"], "." }], "Text"], Cell[BoxData[ \(<< "\"\)], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(\(?assert`*\)\)], "Input"], Cell[BoxData[GridBox[{ { StyleBox["assert`", FontFamily->"Helvetica", FontSize->12, FontWeight->"Bold"]}, {GridBox[{ { ButtonBox[ StyleBox["assert", "Hyperlink"], ButtonFunction:>( Internal`PutInformation[ #, LongForm -> False]&), ButtonEvaluator->Automatic, ButtonData:>{"Info3332505384-1311217", "assert`assert"}, ButtonFrame->"None", ButtonNote->"assert`"], ButtonBox[ StyleBox["logMessage", "Hyperlink"], ButtonFunction:>( Internal`PutInformation[ #, LongForm -> False]&), ButtonEvaluator->Automatic, ButtonData:>{"Info3332505384-1311217", "assert`logMessage"}, ButtonFrame->"None", ButtonNote->"assert`"], "", "", "", "", "", "", ""} }, RowMinHeight->1.05]} }, RowSpacings->{2, 3}, ColumnsEqual->True]], "Print", CellMargins->{{20, Inherited}, {Inherited, Inherited}}, ShowCellLabel->False, CellFrameMargins->{{Inherited, Inherited}, {14, 14}}, Background->RGBColor[0.964706, 0.929412, 0.839216], ButtonBoxOptions->{Active->True}, GridBoxOptions->{ColumnAlignments->{Left}}] }, Closed]], Cell[CellGroupData[{ Cell["example 1,2", "Subsubsection"], Cell[CellGroupData[{ Cell[BoxData[ \(x\ = \ {{1, 2, 3}, \ {3, 4}, \ {5, 6, 7}}\)], "Input"], Cell[BoxData[ \({{1, 2, 3}, {3, 4}, {5, 6, 7}}\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(assert[MatrixQ[x], "\"]\)], "Input"], Cell[BoxData[ \(assert::"err2" \(\(:\)\(\ \)\) "assert[\!\(MatrixQ[x]\), ...] failed. Error message is \"\!\(\"not a \ matrix\"\)\". "\)], "Message"], Cell[BoxData[ \(Exception::"uncaught" \(\(:\)\(\ \)\) "Uncaught exception \!\(assert\)."\)], "Message"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(assert[ ValueQ[y] && y =!= {} && y =!= Null, "\"]\)], "Input"], Cell[BoxData[ \(assert::"err2" \(\(:\)\(\ \)\) "assert[\!\(\(\(ValueQ[y]\)\) && \(\(y =!= \(\({}\)\)\)\) && \(\(y =!= \ Null\)\)\), ...] failed. Error message is \"\!\(\"y is empty\"\)\". "\)], \ "Message"], Cell[BoxData[ \(Exception::"uncaught" \(\(:\)\(\ \)\) "Uncaught exception \!\(assert\)."\)], "Message"] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell["example 3 using assert for type checking", "Subsubsection"], Cell["(* matrix data gets corrupted*)", "Text"], Cell[BoxData[ \(\(x\ = \ {{1, 2}, {3, 4, 3}};\)\)], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(assert[ Dimensions[x] === {2, 2}, "\"]\)], "Input"], Cell[BoxData[ \(assert::"err2" \(\(:\)\(\ \)\) "assert[\!\(\(\(Dimensions[x]\)\) === \(\({2, 2}\)\)\), ...] failed. \ Error message is \"\!\(\"Variable should be a 2x2 matrix\"\)\". "\)], \ "Message"], Cell[BoxData[ \(Exception::"uncaught" \(\(:\)\(\ \)\) "Uncaught exception \!\(assert\)."\)], "Message"] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell["\<\ assert will write failed assert messages to file if the global variable \ logStream exists.\ \>", "Subsubsection"], Cell["Ensure tmp file does not exist by attempting to delete.", "Text"], Cell[BoxData[ \(Intercept[\ DeleteFile::"\", \ NoFile\ ]\)], "Input"], Cell[BoxData[ \(Handle[\ DeleteFile["\"], \ NoFile\ -> \ "\"\ ]\)], "Input"], Cell["Open a stream", "Text"], Cell[BoxData[ \(\(logStream\ = \ OpenAppend["\"];\)\)], "Input"], Cell["Attempt an assert statement that fails", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(assert[ ValueQ[y] && y =!= {} && y =!= Null, "\"]\)], "Input"], Cell[BoxData[ \(assert::"err2" \(\(:\)\(\ \)\) "assert[\!\(\(\(ValueQ[y]\)\) && \(\(y =!= \(\({}\)\)\)\) && \(\(y =!= \ Null\)\)\), ...] failed. Error message is \"\!\(\"y is empty\"\)\". "\)], \ "Message"], Cell[BoxData[ \(Exception::"uncaught" \(\(:\)\(\ \)\) "Uncaught exception \!\(assert\)."\)], "Message"] }, Open ]], Cell["Display the file's contents", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(\(!! tmp\)\)], "Input"], Cell["\<\ assert[ValueQ[y] && y =!= {} && y =!= Null, ...] failed. Error message is \"y \ is empty\". \ \>", "Print"] }, Open ]], Cell[BoxData[ \(Clear[logStream]\)], "Input"] }, Closed]], Cell[CellGroupData[{ Cell["assert can tell you what package it failed in", "Subsubsection"], Cell["\<\ Assert returns the package where the assert statement was called (using a \ simple hack) if provided with an optional variable. \ \>", "Text"], Cell["\<\ Create a clean state for a new package and declare any imports.\ \>", "Text", Evaluatable->False, AspectRatioFixed->True], Cell[CellGroupData[{ Cell["BeginPackage[\"Demo`\", \"assert`\"]", "Input", AspectRatioFixed->True], Cell[BoxData[ \("Demo`"\)], "Output"] }, Open ]], Cell["\<\ Create the public symbols. This is best done with a usage message.\ \>", "Text", Evaluatable->False, AspectRatioFixed->True], Cell[CellGroupData[{ Cell["SampleFunction::usage = \"SampleFunction[n]\"", "Input", AspectRatioFixed->True], Cell[BoxData[ \("SampleFunction[n]"\)], "Output"] }, Open ]], Cell["Start the implementation part.", "Text", Evaluatable->False, AspectRatioFixed->True], Cell[CellGroupData[{ Cell["Begin[\"`Private`\"]", "Input", AspectRatioFixed->True], Cell[BoxData[ \("Demo`Private`"\)], "Output"] }, Open ]], Cell[BoxData[ \( (*define\ function\ that\ calls\ assert\ statement*) \)], "Input"], Cell[BoxData[ \(\(SampleFunction[x_] := Module[{}, assert[ListQ[ x], "\", \ `c]];\)\)], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(End[]\)], "Input"], Cell[BoxData[ \("Demo`Private`"\)], "Output"] }, Open ]], Cell[BoxData[ \(EndPackage[]\)], "Input"], Cell["\<\ Prints the assert command, the error message, and the package where the error \ occured.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(Demo`SampleFunction[3]\)], "Input"], Cell[BoxData[ \(assert::"err3" \(\(:\)\(\ \)\) "assert[\!\(ListQ[3]\), ...] failed. Error message is \ \"\!\(\"SampleFunction: x isn't a list\"\)\". The error occured in the \ package \!\(\"Demo`Private`\"\)."\)], "Message"], Cell[BoxData[ \(Exception::"uncaught" \(\(:\)\(\ \)\) "Uncaught exception \!\(assert\)."\)], "Message"] }, Open ]], Cell["\<\ Now, we know that the error occured in the Demo package, and from the error \ mesasge provided the error occured in SampleFunction. To find where the \ assert is failing, simply search the package for the error message. \ \>", "Text"] }, Closed]] }, Closed]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell["References", "Subtitle"], Cell[TextData[{ "1. Ted Ersek's ", ButtonBox["Mathematica Tricks", ButtonData:>{ URL[ "http://www.verbeia.com/mathematica/tips/Tricks.html"], None}, ButtonStyle->"Hyperlink"] }], "Text"], Cell[TextData[{ "2. Tod Gayley's ", ButtonBox["PackageDesignTutorial.nb", ButtonData:>{ URL[ "http://library.wolfram.com/infocenter/Conferences/184"], None}, ButtonStyle->"Hyperlink"] }], "Text"], Cell[TextData[{ "3. Richard Johnson's ", ButtonBox["Programming tutorial for Matlab", ButtonData:>{ URL[ "http://www.datatool.com/MatlabStyle.pdf"], None}, ButtonStyle->"Hyperlink"] }], "Text"], Cell[TextData[{ "4. Roman E.Maeder's ", ButtonBox["Mathematica's Programming Language", ButtonData:>{ URL[ "http://library.wolfram.com/infocenter/Conferences/183/"], None}, ButtonStyle->"Hyperlink"] }], "Text"], Cell[TextData[{ "5. Roman E.", ButtonBox[" ", ButtonData:>{ URL[ "http://www.datatool.com/MatlabStyle.pdf"], None}, ButtonStyle->"Hyperlink"], "Maeder's ", ButtonBox["Programming Bits", ButtonData:>{ URL[ "http://www.mathconsult.ch/math/stuff/Programming.nb"], None}, ButtonStyle->"Hyperlink"], " " }], "Text"], Cell[TextData[{ "6. Michael A. Morrison's ", ButtonBox["Mathematica Tips, Tricks, and Techniques: Packages", ButtonData:>{ URL[ "http://www.nhn.ou.edu/~morrison/Mathematica/TipSheets/Packages.pdf"], None}, ButtonStyle->"Hyperlink"] }], "Text"], Cell[TextData[{ "7. Michael A. Morrison's ", ButtonBox["Mathematica Tips, Tricks, and Techniques: Syntax", ButtonData:>{ URL[ "http://www.nhn.ou.edu/~morrison/Mathematica/TipSheets/Syntax.pdf"], None}, ButtonStyle->"Hyperlink"] }], "Text"], Cell[CellGroupData[{ Cell["Separated by document type", "Subsection"], Cell[CellGroupData[{ Cell["Web Pages", "Subsubsection"], Cell[TextData[{ "Richard Johnson's ", ButtonBox["Programming tutorial for Matlab", ButtonData:>{ URL[ "http://www.datatool.com/MatlabStyle.pdf"], None}, ButtonStyle->"Hyperlink"] }], "Text"] }, Closed]], Cell[CellGroupData[{ Cell["Notebooks", "Subsubsection"], Cell[TextData[{ "Tod Gayley's ", ButtonBox["PackageDesignTutorial.nb", ButtonData:>{ URL[ "http://library.wolfram.com/infocenter/Conferences/184"], None}, ButtonStyle->"Hyperlink"] }], "Text"], Cell[TextData[{ "Roman E.Maeder's ", ButtonBox["Mathematica's Programming Language", ButtonData:>{ URL[ "http://library.wolfram.com/infocenter/Conferences/183/"], None}, ButtonStyle->"Hyperlink"] }], "Text"], Cell[TextData[{ "Roman E.", ButtonBox[" ", ButtonData:>{ URL[ "http://www.datatool.com/MatlabStyle.pdf"], None}, ButtonStyle->"Hyperlink"], "Maeder's ", ButtonBox["Programming Bits", ButtonData:>{ URL[ "http://www.mathconsult.ch/math/stuff/Programming.nb"], None}, ButtonStyle->"Hyperlink"], " " }], "Text"] }, Closed]], Cell[CellGroupData[{ Cell["PDFs", "Subsubsection"], Cell[TextData[{ "Ted Ersek's ", ButtonBox["Mathematica Tricks", ButtonData:>{ URL[ "http://www.verbeia.com/mathematica/tips/Tricks.html"], None}, ButtonStyle->"Hyperlink"] }], "Text"], Cell[TextData[{ "Michael A. Morrison's ", ButtonBox["Mathematica Tips, Tricks, and Techniques: Packages", ButtonData:>{ URL[ "http://www.nhn.ou.edu/~morrison/Mathematica/TipSheets/Packages.pdf"], None}, ButtonStyle->"Hyperlink"] }], "Text"], Cell[TextData[{ "Michael A. Morrison's ", ButtonBox["Mathematica Tips, Tricks, and Techniques: Syntax", ButtonData:>{ URL[ "http://www.nhn.ou.edu/~morrison/Mathematica/TipSheets/Syntax.pdf"], None}, ButtonStyle->"Hyperlink"] }], "Text"] }, Closed]] }, Closed]] }, Closed]] }, Open ]] }, FrontEndVersion->"5.1 for Microsoft Windows", ScreenRectangle->{{0, 1280}, {0, 951}}, WindowToolbars->"EditBar", WindowSize->{795, 681}, WindowMargins->{{Automatic, -9}, {Automatic, 101}}, ShowSelection->True, StyleDefinitions -> "Report.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->{ "UsingPackages"->{ Cell[8640, 249, 132, 3, 41, "Section", CellTags->"UsingPackages"]}, "Messages"->{ Cell[39510, 1321, 52, 1, 33, "Subtitle", CellTags->"Messages"]}, "Info3332076394-1177643"->{ Cell[46398, 1531, 195, 3, 59, "Print", CellTags->"Info3332076394-1177643"]}, "Exceptions"->{ Cell[54969, 1800, 139, 5, 34, "Subtitle", CellTags->"Exceptions"]} } *) (*CellTagsIndex CellTagsIndex->{ {"UsingPackages", 115495, 4055}, {"Messages", 115589, 4058}, {"Info3332076394-1177643", 115694, 4061}, {"Exceptions", 115799, 4064} } *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[1776, 53, 89, 2, 81, "Title"], Cell[1868, 57, 27, 0, 29, "Text"], Cell[1898, 59, 735, 16, 114, "Text"], Cell[CellGroupData[{ Cell[2658, 79, 26, 0, 41, "Subsection"], Cell[2687, 81, 199, 5, 63, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[2923, 91, 101, 4, 33, "Subtitle"], Cell[3027, 97, 1443, 44, 148, "Text"], Cell[4473, 143, 16, 0, 29, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[4526, 148, 83, 1, 33, "Subtitle"], Cell[4612, 151, 36, 0, 29, "Text"], Cell[4651, 153, 1655, 25, 284, "Text"], Cell[CellGroupData[{ Cell[6331, 182, 40, 0, 67, "Section"], Cell[6374, 184, 339, 8, 46, "Text"], Cell[6716, 194, 182, 4, 46, "Text"], Cell[6901, 200, 444, 11, 114, "Text"], Cell[7348, 213, 845, 16, 114, "Text"], Cell[8196, 231, 141, 4, 63, "Text"], Cell[8340, 237, 263, 7, 80, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[8640, 249, 132, 3, 41, "Section", CellTags->"UsingPackages"], Cell[8775, 254, 276, 8, 29, "Text"], Cell[9054, 264, 5236, 165, 65, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[14327, 434, 101, 4, 41, "Section"], Cell[14431, 440, 287, 5, 63, "Text"], Cell[14721, 447, 411, 10, 46, "Text"], Cell[CellGroupData[{ Cell[15157, 461, 36, 0, 41, "Subsection"], Cell[15196, 463, 319, 7, 27, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[15552, 475, 84, 2, 25, "Subsection", Evaluatable->False], Cell[15639, 479, 791, 22, 97, "Text", Evaluatable->False] }, Closed]], Cell[CellGroupData[{ Cell[16467, 506, 93, 2, 25, "Subsection", Evaluatable->False], Cell[16563, 510, 135, 4, 29, "Text", Evaluatable->False], Cell[16701, 516, 80, 1, 35, "Input"], Cell[16784, 519, 138, 4, 29, "Text", Evaluatable->False], Cell[16925, 525, 101, 1, 35, "Input"], Cell[17029, 528, 94, 2, 29, "Text", Evaluatable->False], Cell[17126, 532, 63, 1, 35, "Input"], Cell[17192, 535, 114, 2, 29, "Text", Evaluatable->False], Cell[17309, 539, 84, 1, 35, "Input"], Cell[17396, 542, 71, 1, 35, "Input"], Cell[17470, 545, 48, 1, 35, "Input"], Cell[17521, 548, 313, 11, 30, "Text", Evaluatable->False], Cell[17837, 561, 55, 1, 35, "Input"], Cell[17895, 564, 112, 3, 29, "Text", Evaluatable->False], Cell[18010, 569, 121, 2, 29, "Text", Evaluatable->False], Cell[18134, 573, 51, 1, 35, "Input"], Cell[18188, 576, 106, 2, 29, "Text", Evaluatable->False], Cell[CellGroupData[{ Cell[18319, 582, 58, 1, 35, "Input"], Cell[18380, 585, 95, 2, 40, "Print", Evaluatable->False] }, Closed]], Cell[18490, 590, 98, 2, 27, "Text", Evaluatable->False], Cell[CellGroupData[{ Cell[18613, 596, 55, 1, 35, "Input"], Cell[18671, 599, 119, 2, 30, "Message", Evaluatable->False] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[18839, 607, 97, 2, 25, "Subsection", Evaluatable->False], Cell[18939, 611, 1954, 73, 30, "Text", Evaluatable->False], Cell[CellGroupData[{ Cell[20918, 688, 151, 9, 143, "Input"], Cell[21072, 699, 84, 2, 40, "Print", Evaluatable->False] }, Closed]], Cell[21171, 704, 138, 8, 111, "Input", Evaluatable->False], Cell[21312, 714, 130, 8, 107, "Input", Evaluatable->False], Cell[21445, 724, 615, 22, 47, "Text", Evaluatable->False], Cell[22063, 748, 136, 4, 29, "Text", Evaluatable->False, PageBreakBelow->False], Cell[CellGroupData[{ Cell[22224, 756, 156, 9, 143, "Input"], Cell[22383, 767, 111, 3, 40, "Print", Evaluatable->False, PageBreakAbove->False] }, Closed]], Cell[CellGroupData[{ Cell[22531, 775, 156, 9, 147, "Input"], Cell[22690, 786, 111, 3, 40, "Print", Evaluatable->False, PageBreakAbove->False] }, Closed]], Cell[CellGroupData[{ Cell[22838, 794, 52, 1, 39, "Input"], Cell[22893, 797, 186, 6, 47, "Output", Evaluatable->False] }, Closed]], Cell[CellGroupData[{ Cell[23116, 808, 55, 1, 39, "Input"], Cell[23174, 811, 174, 6, 47, "Output", Evaluatable->False] }, Closed]], Cell[23363, 820, 481, 15, 45, "Text", Evaluatable->False] }, Closed]] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[23905, 842, 66, 0, 33, "Subtitle"], Cell[23974, 844, 162, 3, 29, "Text"], Cell[CellGroupData[{ Cell[24161, 851, 277, 6, 75, "Input"], Cell[24441, 859, 45, 1, 49, "Output"] }, Closed]], Cell[CellGroupData[{ Cell[24523, 865, 49, 1, 39, "Input"], Cell[24575, 868, 47, 1, 49, "Output"] }, Closed]], Cell[CellGroupData[{ Cell[24659, 874, 58, 1, 39, "Input"], Cell[24720, 877, 79, 1, 49, "Output"] }, Closed]], Cell[24814, 881, 291, 9, 27, "Text"], Cell[25108, 892, 185, 5, 29, "Text"], Cell[25296, 899, 207, 4, 75, "Input"], Cell[CellGroupData[{ Cell[25528, 907, 63, 1, 35, "Input"], Cell[25594, 910, 12880, 356, 194, 3202, 232, "GraphicsData", "PostScript", \ "Graphics"], Cell[38477, 1268, 130, 3, 49, "Output"] }, Closed]], Cell[38622, 1274, 166, 8, 27, "Text"], Cell[38791, 1284, 78, 1, 35, "Input"], Cell[38872, 1287, 38, 0, 29, "Text"], Cell[CellGroupData[{ Cell[38935, 1291, 48, 1, 35, "Input"], Cell[38986, 1294, 49, 1, 49, "Output"] }, Open ]], Cell[39050, 1298, 45, 0, 29, "Text"], Cell[CellGroupData[{ Cell[39120, 1302, 50, 1, 35, "Input"], Cell[39173, 1305, 40, 1, 49, "Output"] }, Open ]], Cell[39228, 1309, 245, 7, 29, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[39510, 1321, 52, 1, 33, "Subtitle", CellTags->"Messages"], Cell[39565, 1324, 399, 11, 46, "Text"], Cell[39967, 1337, 204, 7, 29, "Text"], Cell[40174, 1346, 301, 8, 46, "Text"], Cell[40478, 1356, 541, 9, 80, "Text"], Cell[CellGroupData[{ Cell[41044, 1369, 70, 0, 41, "Subsection"], Cell[CellGroupData[{ Cell[41139, 1373, 48, 1, 35, "Input"], Cell[41190, 1376, 301, 4, 30, "Message"], Cell[41494, 1382, 49, 1, 49, "Output"] }, Closed]], Cell[41558, 1386, 123, 3, 27, "Text"], Cell[41684, 1391, 201, 3, 95, "Input"], Cell[CellGroupData[{ Cell[41910, 1398, 53, 1, 35, "Input"], Cell[41966, 1401, 41, 1, 49, "Output"] }, Closed]], Cell[CellGroupData[{ Cell[42044, 1407, 123, 2, 39, "Input"], Cell[42170, 1411, 92, 1, 49, "Output"] }, Closed]], Cell[CellGroupData[{ Cell[42299, 1417, 69, 1, 39, "Input"], Cell[42371, 1420, 315, 5, 30, "Message"] }, Closed]], Cell[42701, 1428, 637, 10, 95, "Text"], Cell[43341, 1440, 172, 3, 55, "Input"], Cell[43516, 1445, 164, 3, 29, "Text"], Cell[43683, 1450, 129, 3, 29, "Text"], Cell[CellGroupData[{ Cell[43837, 1457, 56, 1, 35, "Input"], Cell[43896, 1460, 321, 5, 30, "Message"], Cell[44220, 1467, 57, 1, 49, "Output"] }, Closed]], Cell[44292, 1471, 67, 0, 27, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[44396, 1476, 68, 0, 25, "Subsection"], Cell[44467, 1478, 751, 11, 114, "Text"], Cell[45221, 1491, 480, 11, 29, "Text"], Cell[45704, 1504, 262, 6, 63, "Text"], Cell[45969, 1512, 129, 3, 29, "Text"], Cell[CellGroupData[{ Cell[46123, 1519, 39, 0, 31, "Subsubsection"], Cell[46165, 1521, 153, 3, 29, "Text"], Cell[CellGroupData[{ Cell[46343, 1528, 52, 1, 35, "Input"], Cell[46398, 1531, 195, 3, 59, "Print", CellTags->"Info3332076394-1177643"] }, Open ]], Cell[46608, 1537, 117, 3, 29, "Text"], Cell[46728, 1542, 68, 1, 35, "Input"], Cell[46799, 1545, 243, 4, 95, "Input"], Cell[47045, 1551, 103, 3, 29, "Text"], Cell[CellGroupData[{ Cell[47173, 1558, 56, 1, 35, "Input"], Cell[47232, 1561, 332, 5, 30, "Message"], Cell[47567, 1568, 57, 1, 49, "Output"] }, Open ]], Cell[47639, 1572, 75, 0, 29, "Text"], Cell[CellGroupData[{ Cell[47739, 1576, 53, 1, 35, "Input"], Cell[47795, 1579, 41, 1, 49, "Output"] }, Open ]] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[47897, 1587, 46, 0, 25, "Subsection"], Cell[47946, 1589, 588, 14, 80, "Text"], Cell[48537, 1605, 262, 7, 46, "Text"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[48848, 1618, 75, 0, 33, "Subtitle"], Cell[48926, 1620, 622, 11, 80, "Text"], Cell[CellGroupData[{ Cell[49573, 1635, 35, 0, 67, "Section"], Cell[49611, 1637, 49, 1, 35, "Input"], Cell[CellGroupData[{ Cell[49685, 1642, 804, 12, 175, "Input"], Cell[50492, 1656, 557, 10, 125, "Output"] }, Closed]], Cell[51064, 1669, 37, 0, 27, "Text"], Cell[CellGroupData[{ Cell[51126, 1673, 80, 1, 35, "Input"], Cell[51209, 1676, 146, 2, 49, "Output"] }, Closed]], Cell[51370, 1681, 72, 0, 27, "Text"], Cell[CellGroupData[{ Cell[51467, 1685, 115, 3, 35, "Input"], Cell[51585, 1690, 129, 2, 49, "Output"] }, Closed]], Cell[CellGroupData[{ Cell[51751, 1697, 295, 5, 63, "Subsection"], Cell[52049, 1704, 278, 7, 46, "Text"], Cell[52330, 1713, 94, 2, 29, "Text"], Cell[52427, 1717, 113, 2, 35, "Input"], Cell[52543, 1721, 123, 3, 29, "Text"], Cell[52669, 1726, 206, 4, 55, "Input"], Cell[52878, 1732, 158, 3, 29, "Text"], Cell[CellGroupData[{ Cell[53061, 1739, 40, 1, 35, "Input"], Cell[53104, 1742, 54, 1, 49, "Output"] }, Open ]], Cell[53173, 1746, 665, 10, 97, "Text"], Cell[53841, 1758, 365, 7, 46, "Text"], Cell[54209, 1767, 117, 3, 29, "Text"], Cell[54329, 1772, 261, 5, 55, "Input"], Cell[CellGroupData[{ Cell[54615, 1781, 40, 1, 35, "Input"], Cell[54658, 1784, 46, 1, 49, "Output"] }, Open ]], Cell[54719, 1788, 189, 5, 29, "Text"] }, Closed]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell[54969, 1800, 139, 5, 34, "Subtitle", CellTags->"Exceptions"], Cell[55111, 1807, 602, 11, 80, "Text"], Cell[CellGroupData[{ Cell[55738, 1822, 62, 0, 67, "Section"], Cell[55803, 1824, 192, 4, 46, "Text"], Cell[CellGroupData[{ Cell[56020, 1832, 61, 1, 35, "Input"], Cell[56084, 1835, 40, 1, 49, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[56161, 1841, 61, 1, 35, "Input"], Cell[56225, 1844, 40, 1, 49, "Output"] }, Open ]], Cell[56280, 1848, 23, 0, 29, "Text"], Cell[56306, 1850, 299, 6, 55, "Input"], Cell[CellGroupData[{ Cell[56630, 1860, 48, 1, 35, "Input"], Cell[56681, 1863, 40, 1, 50, "Output"] }, Open ]], Cell[56736, 1867, 29, 0, 29, "Text"], Cell[56768, 1869, 295, 6, 55, "Input"], Cell[CellGroupData[{ Cell[57088, 1879, 51, 1, 35, "Input"], Cell[57142, 1882, 40, 1, 50, "Output"] }, Open ]], Cell[57197, 1886, 240, 4, 55, "Input"], Cell[CellGroupData[{ Cell[57462, 1894, 303, 5, 79, "Subsection"], Cell[57768, 1901, 69, 0, 29, "Text"], Cell[57840, 1903, 184, 3, 75, "Input"], Cell[58027, 1908, 125, 3, 29, "Text"], Cell[58155, 1913, 186, 4, 55, "Input"], Cell[58344, 1919, 174, 4, 46, "Text"], Cell[CellGroupData[{ Cell[58543, 1927, 42, 1, 35, "Input"], Cell[58588, 1930, 110, 2, 40, "Print"] }, Closed]], Cell[58713, 1935, 638, 9, 95, "Text"], Cell[59354, 1946, 117, 3, 29, "Text"], Cell[59474, 1951, 212, 4, 55, "Input"], Cell[CellGroupData[{ Cell[59711, 1959, 42, 1, 35, "Input"], Cell[59756, 1962, 91, 1, 40, "Print"] }, Closed]], Cell[59862, 1966, 181, 5, 27, "Text"] }, Closed]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell[60104, 1978, 83, 1, 35, "Subtitle"], Cell[60190, 1981, 25, 0, 29, "Text"], Cell[60218, 1983, 247, 6, 29, "Text"], Cell[60468, 1991, 340, 10, 114, "Text"], Cell[CellGroupData[{ Cell[60833, 2005, 315, 9, 90, "Section", Evaluatable->False], Cell[61151, 2016, 310, 8, 63, "Text", Evaluatable->False], Cell[61464, 2026, 1102, 29, 78, "Text", Evaluatable->False], Cell[62569, 2057, 1141, 41, 63, "Text", Evaluatable->False], Cell[CellGroupData[{ Cell[63735, 2102, 95, 2, 41, "Subsection", Evaluatable->False], Cell[63833, 2106, 139, 3, 29, "Text", Evaluatable->False], Cell[63975, 2111, 130, 3, 29, "Text", Evaluatable->False], Cell[64108, 2116, 132, 3, 29, "Text", Evaluatable->False], Cell[64243, 2121, 140, 3, 29, "Text", Evaluatable->False] }, Closed]], Cell[CellGroupData[{ Cell[64420, 2129, 98, 2, 25, "Subsection", Evaluatable->False], Cell[64521, 2133, 309, 7, 63, "Text", Evaluatable->False], Cell[64833, 2142, 301, 7, 63, "Text", Evaluatable->False], Cell[65137, 2151, 242, 7, 63, "Text", Evaluatable->False], Cell[65382, 2160, 1414, 44, 115, "Text", Evaluatable->False], Cell[66799, 2206, 232, 7, 63, "Text", Evaluatable->False], Cell[67034, 2215, 469, 19, 35, "Input", Evaluatable->False], Cell[67506, 2236, 155, 3, 29, "Text", Evaluatable->False], Cell[67664, 2241, 145, 3, 29, "Text", Evaluatable->False] }, Closed]], Cell[CellGroupData[{ Cell[67846, 2249, 80, 2, 25, "Subsection", Evaluatable->False], Cell[67929, 2253, 104, 2, 29, "Text", Evaluatable->False], Cell[68036, 2257, 102, 3, 29, "Text", Evaluatable->False], Cell[68141, 2262, 297, 11, 30, "Text", Evaluatable->False], Cell[68441, 2275, 286, 11, 30, "Text", Evaluatable->False], Cell[68730, 2288, 292, 11, 30, "Text", Evaluatable->False], Cell[69025, 2301, 288, 11, 30, "Text", Evaluatable->False], Cell[69316, 2314, 296, 11, 30, "Text", Evaluatable->False], Cell[69615, 2327, 580, 22, 30, "Text", Evaluatable->False], Cell[70198, 2351, 110, 3, 29, "Text", Evaluatable->False], Cell[70311, 2356, 81, 1, 35, "Input"], Cell[70395, 2359, 62, 1, 35, "Input"], Cell[70460, 2362, 158, 4, 53, "Input"], Cell[70621, 2368, 460, 14, 46, "Text", Evaluatable->False], Cell[71084, 2384, 126, 4, 29, "Text", Evaluatable->False, PageBreakBelow->False], Cell[71213, 2390, 149, 3, 29, "Text", Evaluatable->False, PageBreakBelow->False], Cell[71365, 2395, 49, 1, 35, "Input"], Cell[71417, 2398, 593, 23, 30, "Text", Evaluatable->False], Cell[72013, 2423, 76, 1, 35, "Input"], Cell[72092, 2426, 90, 2, 29, "Text", Evaluatable->False], Cell[CellGroupData[{ Cell[72207, 2432, 50, 1, 35, "Input"], Cell[72260, 2435, 114, 6, 47, "Output", Evaluatable->False] }, Closed]], Cell[72389, 2444, 94, 2, 27, "Text", Evaluatable->False], Cell[CellGroupData[{ Cell[72508, 2450, 48, 1, 35, "Input"], Cell[72559, 2453, 114, 6, 47, "Output", Evaluatable->False] }, Closed]] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[72734, 2466, 22, 0, 41, "Section"], Cell[72759, 2468, 112, 3, 29, "Text"], Cell[72874, 2473, 137, 3, 29, "Text"], Cell[73014, 2478, 57, 0, 29, "Text"], Cell[CellGroupData[{ Cell[73096, 2482, 51, 0, 41, "Subsection"], Cell[73150, 2484, 375, 14, 31, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[73562, 2503, 332, 10, 60, "Subsection", Evaluatable->False], Cell[73897, 2515, 432, 10, 97, "Text", Evaluatable->False], Cell[74332, 2527, 743, 26, 64, "Text", Evaluatable->False], Cell[CellGroupData[{ Cell[75100, 2557, 92, 2, 31, "Subsubsection", Evaluatable->False], Cell[75195, 2561, 315, 7, 80, "Text", Evaluatable->False], Cell[75513, 2570, 730, 26, 29, "Text", Evaluatable->False], Cell[76246, 2598, 463, 15, 46, "Text", Evaluatable->False] }, Closed]], Cell[CellGroupData[{ Cell[76746, 2618, 88, 2, 25, "Subsubsection", Evaluatable->False], Cell[76837, 2622, 614, 16, 80, "Text", Evaluatable->False] }, Closed]], Cell[CellGroupData[{ Cell[77488, 2643, 84, 2, 25, "Subsubsection", Evaluatable->False], Cell[77575, 2647, 572, 12, 131, "Text", Evaluatable->False], Cell[78150, 2661, 315, 7, 80, "Text", Evaluatable->False] }, Closed]], Cell[CellGroupData[{ Cell[78502, 2673, 83, 2, 25, "Subsubsection", Evaluatable->False], Cell[78588, 2677, 1185, 43, 64, "Text", Evaluatable->False], Cell[79776, 2722, 62, 1, 35, "Input"], Cell[79841, 2725, 88, 2, 29, "Text", Evaluatable->False], Cell[79932, 2729, 603, 24, 35, "Input"], Cell[80538, 2755, 217, 5, 46, "Text", Evaluatable->False], Cell[80758, 2762, 337, 11, 179, "Input"], Cell[CellGroupData[{ Cell[81120, 2777, 65, 1, 35, "Input"], Cell[81188, 2780, 137, 3, 49, "Output"] }, Closed]], Cell[81340, 2786, 193, 5, 44, "Text", Evaluatable->False], Cell[CellGroupData[{ Cell[81558, 2795, 61, 1, 35, "Input"], Cell[81622, 2798, 37, 1, 49, "Output"] }, Closed]], Cell[CellGroupData[{ Cell[81696, 2804, 62, 1, 39, "Input"], Cell[81761, 2807, 42, 1, 49, "Output"] }, Closed]], Cell[81818, 2811, 943, 31, 80, "Text", Evaluatable->False], Cell[82764, 2844, 268, 8, 125, "Input"], Cell[CellGroupData[{ Cell[83057, 2856, 74, 1, 35, "Input"], Cell[83134, 2859, 153, 3, 49, "Output"] }, Closed]], Cell[CellGroupData[{ Cell[83324, 2867, 62, 1, 39, "Input"], Cell[83389, 2870, 37, 1, 49, "Output"] }, Closed]], Cell[CellGroupData[{ Cell[83463, 2876, 62, 1, 39, "Input"], Cell[83528, 2879, 159, 3, 40, "Print"] }, Closed]], Cell[CellGroupData[{ Cell[83724, 2887, 55, 1, 39, "Input"], Cell[83782, 2890, 37, 1, 49, "Output"] }, Closed]] }, Closed]] }, Open ]] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[83904, 2900, 82, 1, 35, "Subtitle"], Cell[83989, 2903, 997, 15, 148, "Text"], Cell[84989, 2920, 353, 8, 46, "Text"], Cell[CellGroupData[{ Cell[85367, 2932, 243, 7, 67, "Section"], Cell[85613, 2941, 266, 7, 29, "Text"], Cell[85882, 2950, 414, 10, 63, "Text"], Cell[86299, 2962, 184, 8, 29, "Text"], Cell[86486, 2972, 191, 8, 46, "Text"], Cell[86680, 2982, 75, 0, 29, "Text"], Cell[86758, 2984, 246, 12, 35, "Input", Evaluatable->False], Cell[87007, 2998, 204, 7, 30, "Text"], Cell[CellGroupData[{ Cell[87236, 3009, 44, 0, 41, "Subsection"], Cell[87283, 3011, 107, 5, 30, "Text"], Cell[87393, 3018, 296, 15, 35, "Input", Evaluatable->False], Cell[87692, 3035, 386, 16, 30, "Text"], Cell[88081, 3053, 55, 0, 29, "Text"], Cell[88139, 3055, 110, 6, 35, "Input", Evaluatable->False], Cell[88252, 3063, 106, 5, 30, "Text"], Cell[88361, 3070, 231, 12, 35, "Input", Evaluatable->False], Cell[88595, 3084, 308, 11, 30, "Text"], Cell[88906, 3097, 70, 0, 29, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[89013, 3102, 36, 0, 25, "Subsection"], Cell[89052, 3104, 225, 9, 53, "Input", Evaluatable->False], Cell[89280, 3115, 537, 21, 71, "Input", Evaluatable->False], Cell[89820, 3138, 169, 6, 35, "Input", Evaluatable->False], Cell[89992, 3146, 412, 16, 30, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[90441, 3167, 30, 0, 25, "Subsection"], Cell[90474, 3169, 321, 11, 29, "Text"], Cell[90798, 3182, 57, 1, 35, "Input"], Cell[CellGroupData[{ Cell[90880, 3187, 50, 1, 35, "Input"], Cell[90933, 3190, 2747, 67, 72, "Print"] }, Closed]], Cell[93695, 3260, 27, 0, 27, "Text"], Cell[93725, 3262, 258, 5, 115, "Input"], Cell[CellGroupData[{ Cell[94008, 3271, 109, 2, 35, "Input"], Cell[94120, 3275, 41, 1, 49, "Output"] }, Closed]], Cell[94176, 3279, 120, 3, 27, "Text"], Cell[94299, 3284, 111, 2, 35, "Input"], Cell[CellGroupData[{ Cell[94435, 3290, 102, 2, 35, "Input"], Cell[94540, 3294, 38, 1, 62, "Output"] }, Closed]], Cell[CellGroupData[{ Cell[94615, 3300, 106, 2, 39, "Input"], Cell[94724, 3304, 45, 1, 49, "Output"] }, Closed]], Cell[94784, 3308, 71, 0, 27, "Text"], Cell[CellGroupData[{ Cell[94880, 3312, 92, 1, 35, "Input"], Cell[94975, 3315, 163, 3, 40, "Print"] }, Closed]], Cell[95153, 3321, 32, 0, 27, "Text"], Cell[CellGroupData[{ Cell[95210, 3325, 41, 1, 35, "Input"], Cell[95254, 3328, 124, 2, 30, "Message"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[95427, 3336, 130, 5, 26, "Subsection"], Cell[95560, 3343, 57, 1, 35, "Input"], Cell[CellGroupData[{ Cell[95642, 3348, 36, 1, 35, "Input"], Cell[95681, 3351, 278, 4, 43, "Message"], Cell[95962, 3357, 49, 1, 49, "Output"] }, Closed]], Cell[CellGroupData[{ Cell[96048, 3363, 46, 1, 39, "Input"], Cell[96097, 3366, 100, 3, 49, "Output"] }, Closed]], Cell[96212, 3372, 75, 1, 39, "Input"], Cell[CellGroupData[{ Cell[96312, 3377, 76, 1, 35, "Input"], Cell[96391, 3380, 45, 1, 49, "Output"] }, Closed]], Cell[CellGroupData[{ Cell[96473, 3386, 45, 1, 39, "Input"], Cell[96521, 3389, 36, 1, 49, "Output"] }, Closed]], Cell[96572, 3393, 68, 0, 27, "Text"], Cell[96643, 3395, 75, 1, 35, "Input"], Cell[CellGroupData[{ Cell[96743, 3400, 104, 2, 35, "Input"], Cell[96850, 3404, 41, 1, 49, "Output"] }, Open ]], Cell[96906, 3408, 160, 3, 29, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[97103, 3416, 59, 0, 25, "Subsection"], Cell[97165, 3418, 94, 1, 29, "Text"], Cell[97262, 3421, 142, 5, 29, "Text"] }, Closed]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell[97465, 3433, 29, 0, 33, "Subtitle"], Cell[97497, 3435, 1323, 26, 148, "Text"], Cell[98823, 3463, 554, 13, 63, "Text"], Cell[99380, 3478, 1193, 24, 131, "Text"], Cell[CellGroupData[{ Cell[100598, 3506, 25, 0, 67, "Section"], Cell[CellGroupData[{ Cell[100648, 3510, 32, 0, 41, "Subsection"], Cell[100683, 3512, 1175, 21, 182, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[101895, 3538, 36, 0, 25, "Subsection"], Cell[101934, 3540, 102, 3, 29, "Text"], Cell[102039, 3545, 96, 2, 35, "Input", Evaluatable->False], Cell[102138, 3549, 817, 14, 315, "Input", Evaluatable->False], Cell[102958, 3565, 203, 4, 55, "Input", Evaluatable->False] }, Closed]], Cell[CellGroupData[{ Cell[103198, 3574, 30, 0, 25, "Subsection"], Cell[103231, 3576, 245, 7, 29, "Text"], Cell[103479, 3585, 186, 6, 29, "Text"], Cell[103668, 3593, 49, 1, 35, "Input"], Cell[CellGroupData[{ Cell[103742, 3598, 46, 1, 35, "Input"], Cell[103791, 3601, 1499, 39, 72, "Print"] }, Closed]], Cell[CellGroupData[{ Cell[105327, 3645, 36, 0, 25, "Subsubsection"], Cell[CellGroupData[{ Cell[105388, 3649, 75, 1, 35, "Input"], Cell[105466, 3652, 64, 1, 49, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[105567, 3658, 71, 1, 35, "Input"], Cell[105641, 3661, 160, 3, 30, "Message"], Cell[105804, 3666, 114, 2, 30, "Message"] }, Open ]], Cell[CellGroupData[{ Cell[105955, 3673, 101, 2, 35, "Input"], Cell[106059, 3677, 217, 4, 30, "Message"], Cell[106279, 3683, 114, 2, 30, "Message"] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell[106442, 3691, 65, 0, 25, "Subsubsection"], Cell[106510, 3693, 47, 0, 29, "Text"], Cell[106560, 3695, 65, 1, 35, "Input"], Cell[CellGroupData[{ Cell[106650, 3700, 122, 3, 35, "Input"], Cell[106775, 3705, 211, 4, 45, "Message"], Cell[106989, 3711, 114, 2, 30, "Message"] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell[107152, 3719, 124, 3, 25, "Subsubsection"], Cell[107279, 3724, 71, 0, 29, "Text"], Cell[107353, 3726, 81, 1, 35, "Input"], Cell[107437, 3729, 116, 2, 35, "Input"], Cell[107556, 3733, 29, 0, 29, "Text"], Cell[107588, 3735, 75, 1, 35, "Input"], Cell[107666, 3738, 54, 0, 29, "Text"], Cell[CellGroupData[{ Cell[107745, 3742, 101, 2, 35, "Input"], Cell[107849, 3746, 217, 4, 30, "Message"], Cell[108069, 3752, 114, 2, 30, "Message"] }, Open ]], Cell[108198, 3757, 43, 0, 29, "Text"], Cell[CellGroupData[{ Cell[108266, 3761, 43, 1, 35, "Input"], Cell[108312, 3764, 117, 3, 40, "Print"] }, Open ]], Cell[108444, 3770, 49, 1, 35, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[108530, 3776, 70, 0, 25, "Subsubsection"], Cell[108603, 3778, 153, 4, 46, "Text"], Cell[108759, 3784, 135, 4, 29, "Text", Evaluatable->False], Cell[CellGroupData[{ Cell[108919, 3792, 79, 1, 35, "Input"], Cell[109001, 3795, 41, 1, 49, "Output"] }, Open ]], Cell[109057, 3799, 138, 4, 29, "Text", Evaluatable->False], Cell[CellGroupData[{ Cell[109220, 3807, 88, 1, 35, "Input"], Cell[109311, 3810, 53, 1, 49, "Output"] }, Open ]], Cell[109379, 3814, 94, 2, 29, "Text", Evaluatable->False], Cell[CellGroupData[{ Cell[109498, 3820, 63, 1, 35, "Input"], Cell[109564, 3823, 49, 1, 49, "Output"] }, Open ]], Cell[109628, 3827, 87, 1, 35, "Input"], Cell[109718, 3830, 167, 4, 35, "Input"], Cell[CellGroupData[{ Cell[109910, 3838, 38, 1, 35, "Input"], Cell[109951, 3841, 49, 1, 49, "Output"] }, Open ]], Cell[110015, 3845, 45, 1, 35, "Input"], Cell[110063, 3848, 112, 3, 29, "Text"], Cell[CellGroupData[{ Cell[110200, 3855, 55, 1, 35, "Input"], Cell[110258, 3858, 235, 4, 45, "Message"], Cell[110496, 3864, 114, 2, 30, "Message"] }, Open ]], Cell[110625, 3869, 244, 4, 46, "Text"] }, Closed]] }, Closed]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell[110942, 3881, 30, 0, 33, "Subtitle"], Cell[110975, 3883, 204, 6, 29, "Text"], Cell[111182, 3891, 213, 6, 29, "Text"], Cell[111398, 3899, 211, 6, 29, "Text"], Cell[111612, 3907, 228, 6, 29, "Text"], Cell[111843, 3915, 348, 12, 29, "Text"], Cell[112194, 3929, 275, 8, 29, "Text"], Cell[112472, 3939, 271, 8, 29, "Text"], Cell[CellGroupData[{ Cell[112768, 3951, 48, 0, 41, "Subsection"], Cell[CellGroupData[{ Cell[112841, 3955, 34, 0, 31, "Subsubsection"], Cell[112878, 3957, 208, 6, 29, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[113123, 3968, 34, 0, 25, "Subsubsection"], Cell[113160, 3970, 210, 6, 29, "Text"], Cell[113373, 3978, 225, 6, 29, "Text"], Cell[113601, 3986, 345, 12, 29, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[113983, 4003, 29, 0, 25, "Subsubsection"], Cell[114015, 4005, 201, 6, 29, "Text"], Cell[114219, 4013, 272, 8, 29, "Text"], Cell[114494, 4023, 268, 8, 29, "Text"] }, Closed]] }, Closed]] }, Closed]] }, Open ]] } ] *) (******************************************************************* End of Mathematica Notebook file. *******************************************************************)