(***********************************************************************
Mathematica-Compatible Notebook
This notebook can be used on any computer system with Mathematica 4.0,
MathReader 4.0, or any compatible application. 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[ 67092, 2227]*)
(*NotebookOutlinePosition[ 68180, 2262]*)
(* CellTagsIndexPosition[ 68136, 2258]*)
(*WindowFrame->Normal*)
Notebook[{
Cell[CellGroupData[{
Cell[TextData["5. Lists I: Definitions and Examples "], "Title",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Last revision: January 26 1998", "SmallText",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData[
"In this section we introduce a particular programming paradigm (list-based \
programming), briefly contrast it with other programming paradigms we have \
encountered or will consider, and continue with our survey of functions which \
support list-oriented programming. We do so in the context of manipulating \
the roster of a class in school."], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData[{
StyleBox["Mathematica",
Evaluatable->False,
AspectRatioFixed->True,
FontSlant->"Italic"],
StyleBox[" operations/structures introduced: \n",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox[
" Factorial[]\n Range[]\n Apply[]\n Do[]\n Module[]\n \
Part[]\n Position[]\n Sort[]\n Reverse[]\n Attributes[]\n \
Map[]\n Union[]\n Append[]\n Prepend[]\n First[]\n \
Last[]\n Transpose[]\n Table[]\n Take[]\n Partition[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"]
}], "SmallText",
Evaluatable->False,
AspectRatioFixed->True],
Cell[CellGroupData[{
Cell[TextData["List-Based Programming"], "Section",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData[
"Congratulations! You have completed the introductory section of this \
course. We now consider a particular programming paradigm: list-based \
programming. This style of programming privileges lists over other types of \
data; nearly every function takes a list as a parameter or argument and \
returns a list as its output. In this mode, we must consider how we may \
accomplish our programming tasks by using functions which apply to entire \
lists, not how we might use each element of a list separately. In some \
situations, when for instance data is written in a formatted way to a laser \
printer, data will not be strictly in the form of a list, but for the bulk of \
computing in list-based programming, data will be primarily, if not \
exclusively, represented and manipulated in the form of a list."], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell[CellGroupData[{
Cell[TextData["Repetition and Programming Paradigms"], "Subsection",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData[
"Before we spend several sections on this particular paradigm, it is useful \
to have an idea of what several progamming paradigms are---and how similar \
operations may be carried out in each. First, it is important to realize \
that programming paradigms are only structures for programming, perspectives \
with which to view the programming task. By themselves, programming \
paradigms do not offer any particular functions or abilities. In fact, any \
programming task should be solvable in any programming paradigm. We study \
programmig paradigms primarily because knowing particular paradigms allows \
one to solve certain programming problems more efficiently. While we may be \
comfortable, for instance, manipulating elements of lists instead of entire \
lists, it may be the case for a particular problem that we may reach a \
solution which is much shorter (in lines of code), or simpler (in method), or \
faster (in time to execute it on a machine), if we consider how we could \
accomplish similar actions, operating only on entire lists. "], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData[{
"To illustrate this difference, let's consider the notion of repetition. \
The idea that some operations should be carried out over and over again on \
different data is a notion central to computing, for that is precisely what \
computer can do better (or at least faster) than we can. Therefore, \
considering how different paradigms provide for the repetition of an \
operation is a useful way to distinguish between the paradigms. In what \
follows we will examine the various ways we can instruct ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" to evaluate factorials, which are products of consecutive integers, \
beginning with some integer and continuing down to the integer ",
StyleBox["1", "Input",
FontWeight->"Plain"],
", such as ",
StyleBox["9*8*7*6*5*4*3*2*1", "Input",
FontWeight->"Plain"],
". Please note that you are not expected to understand each line of every \
input cell, but instead to have a first look at the difference in programming \
styles. We will take up the particular details of other programming \
paradigms later in the course."
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell[CellGroupData[{
Cell[TextData["Paradigm 1: Pre-Definition"], "Subsubsection",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData[{
StyleBox[
"One extremely restricted programming paradigm is pre-definition, which \
incorporates two guiding ideas: first, that any operation we wish to \
accomplish should have a named function which performs the operation, and, \
second, that no combination of these functions should be allowed. One \
example of a computer which operates under this programming paradigm would be \
an old, scientific calculator which does not provide the capability to \
program in the traditional sense---the user is allowed only to use individual \
functions on the calculator, one at a time, but not to put several together \
into a new function. This is not to say that such a calculator cannot be \
used to accomplish many operations---it can---but the ability of a programmer \
to affect the versatility or even the number of functions on the machine is \
limited. In order to provide a new function, the machine itself would have to \
be changed---buttons added, extra chips installed, and so on---which would \
certainly be a real burden to any programmer! In ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Mathematica",
Evaluatable->False,
AspectRatioFixed->True,
FontSlant->"Italic"],
StyleBox[", the analogy would be to use single functions in ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Mathematica",
Evaluatable->False,
AspectRatioFixed->True,
FontSlant->"Italic"],
StyleBox[", never in combination. It so happens that ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Mathematica",
Evaluatable->False,
AspectRatioFixed->True,
FontSlant->"Italic"],
StyleBox[" has a command to compute factorials, called \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Factorial[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[
"\". (The operator form of the function is the exclamation point: \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["9!",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\")",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Factorial[9]", "Input",
AspectRatioFixed->True],
Cell["9!", "Input",
AspectRatioFixed->True]
}, Closed]],
Cell[CellGroupData[{
Cell[TextData["Paradigm 2: List-based programming"], "Subsubsection",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData[{
StyleBox[
"How would we think of accomplishing the same task in list-based \
programming? We know that we must instruct the computer to operate on entire \
lists, so we might wish to begin by finding the list of all integers 1 \
through 9. At that point, we would use a list-based function which takes a \
list, multiplies together all of its elements, and returns the result. (The \
result, although a number, might be placed in a list by itself.) We follow \
this plan. We generate a list of the first 9 integers by using \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Range[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\":",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Range[9]", "Input",
AspectRatioFixed->True],
Cell[TextData[{
StyleBox["Then we tell ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Mathematica",
Evaluatable->False,
AspectRatioFixed->True,
FontSlant->"Italic"],
StyleBox[" to apply the function \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Times[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" to all of the elements of the list:",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Apply[Times,Range[9]]", "Input",
AspectRatioFixed->True],
Cell[TextData[
"We may even define a function to do exactly these operations for any given \
integer:"], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["listFac[n_] := Apply[Times,Range[n]]", "Input",
AspectRatioFixed->True],
Cell[TextData["Let's see that it works:"], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["listFac[9]", "Input",
AspectRatioFixed->True]
}, Closed]],
Cell[CellGroupData[{
Cell[TextData["Paradigm 3: Recursion"], "Subsubsection",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData[{
StyleBox[
"Recursion is a more advanced paradigm than list-based programming and \
incorporates a clever way of organizing repetition. The guiding idea of \
recursion is that a function should be designed with two characteristics: \
first, the function should perform only one instance of the operation to be \
repeated, so that the programming task has one small part accomplished, and, \
second, that the rest of the programming task should be accomplished by \
having the function use the result of invoking the same function with \
different initial parameters. Admittedly, this paradigm seems complicated at \
first blush; we will consider recursion in much more detail later in the \
course. Here we show how our factorial task may be implemented using a \
recursive function.\n\nOur function will take an integer as an input value, \
invoke itself with the input value one smaller, and multiply the result by \
the original integer. What will happen? When the original integer is 9, the \
function will execute itself with ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["8",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[" as input and multiply the result by ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["9",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[". If the function returned ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["8*7*6*5*4*3*2*1", "Input",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier",
FontWeight->"Plain"],
StyleBox[" when ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["8", "Input",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier",
FontWeight->"Plain"],
StyleBox[
" was placed inside, then clearly our factorial function will work. Let's \
examine what will happen when the function receives ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["8",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[" as the input value. Then it will call itself with ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["7",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[" as input and multiplies the result by ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["8",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[". Again, we hope that when the function receives ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["7",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[" as input it will return ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["7*6*5*4*3*2*1",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[
". If we continue analyzing the function in this manner, we realize that \
if the integer ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["1",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[
" is the input value, we should make sure the function returns a ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["1",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["; otherwise, it might return the result of ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["1*0*-1*...",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[
", which is certainly not desired. If the function returns the integer ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["1",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[" when the integer ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["1",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[
" is the input value, we can convince ourselves that the function, thus \
defined, will actually produce the correct factorials. Here is the code:",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["\<\
recurFac[n_] := n * recurFac[n-1]
recurFac[1] = 1\
\>", "Input",
AspectRatioFixed->True],
Cell[TextData[{
StyleBox["(We will see later that ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Mathematica",
Evaluatable->False,
AspectRatioFixed->True,
FontSlant->"Italic"],
StyleBox[
" first checks the input value against a list of special cases; in our \
case, it will check first of the input value is a ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["1",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[", returning a ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["1",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[" if so and otherwise using the definition given above.)",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["recurFac[9]", "Input",
AspectRatioFixed->True]
}, Closed]],
Cell[CellGroupData[{
Cell[TextData[
"Paradigm 4: Procedural programming (using loops)"], "Subsubsection",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData[{
StyleBox[
"Finally, we consider procedural programming, a less advanced paradigm than \
list-based recursion. Procedural programming is, in one sense, at the \
oppostite extreme from list-based programming; in procedural programming we \
focus on individual items of data. In order to repeat an operation, we set \
up what is called a loop, which is programming code instructing the computer \
to execute the same lines of code over and over. Inside the loop we write \
the instructions which will be repeated. In order to have the loop stop \
executing when it is finished, a loop usually contains a stopping condition. \
When the computer encounters a loop, it executes each of the instructions \
inside the loop and tests whether or not the stopping condition is true. If \
the condition is not true, it begins again at the start of the loop, \
executing the instructions and testing the stopping condition again. When \
the stopping condition finally is true, the computer moves on to the next \
instruction. Frequenly loops use a special variable, called an iterator, \
which counts the number of times the loop's instructions have been executed \
and which can be used to decide when the loop should stop. The iterator \
might begin with a value of 1, and the instructions inside the loop say to \
increment the iterator by 1. In this way the stopping condition can look at \
the value of the iterator, and for instance test whether or not the loop has \
been executed enough times.\n\nIn our case we could begin with 1 and multiply \
each integer consectively until we reach the final value, 9. We implement \
this plan as follows. We declare a variable \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["sofar",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[
"\" which is initialized to 1 and which keeps track of the product thus \
far. We perform a loop with an iterator \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["i",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[
"\" which begins at 2, has 1 added to it each loop, and stops at 9, and \
inside the loop we instruct the computer to multiply \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["sofar",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" by \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["i",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" and place the result back inside \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["sofar",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\". One way to do this in ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Mathematica",
Evaluatable->False,
AspectRatioFixed->True,
FontSlant->"Italic"],
StyleBox[" is to use the \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Do[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[
"\" function, which performs the operation given by the first argument over \
and over, with the iterator, the beginning iterator value, and the ending \
iterator value given as a list as the second argument:",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["\<\
sofar = 1;
Do[
sofar = sofar * i,
{i,2,9}];
sofar\
\>", "Input",
AspectRatioFixed->True],
Cell[TextData[{
StyleBox[
"Another way to accomplish the same operation in procedural programming in \
",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Mathematica",
Evaluatable->False,
AspectRatioFixed->True,
FontSlant->"Italic"],
StyleBox[
" is to define a function which executes each of these statements for us, \
and specifies that \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["sofar",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[
"\" should be forgotten once we're done finding the factorial. Here is the \
",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Mathematica",
Evaluatable->False,
AspectRatioFixed->True,
FontSlant->"Italic"],
StyleBox[" code:",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["\<\
loopFac[n_] := Module[ {sofar},
sofar = 1;
Do[
sofar = sofar * i,
{i,2,n}];
sofar
]\
\>", "Input",
AspectRatioFixed->True],
Cell["loopFac[9]", "Input",
AspectRatioFixed->True]
}, Closed]]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[TextData["A Class Roster"], "Section",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData[
"Here is a list of names of people in a class, with some additions."], "Text",\
Evaluatable->False,
AspectRatioFixed->True],
Cell["\<\
roster =
{{\"Jimmy\", \"Carr\"}, {\"Charles\", \"Babbage\"}, {\"Toby\", \"Crabtree\"}, \
{\"Where's\", \"Waldo\"}, {\"Parker\", \"Dixon\"}, {\"BJ\", \"Herbert\"}, \
{\"Denny\", \"Jones\"}, {\"North\", \"Moore\"}, {\"David\", \"Moskowitz\"}, {\
\"Marc\", \"Naples\"}, {\"Matt\", \"Phillips\"}, {\"Austin\", \
\"Rice-Stitt\"}, {\"Matthew\", \"Schenk\"}, {\"Ryan\", \"Seifert\"}, \
{\"Alan\", \"Turing\"}, {\"Todd\", \"Slaby\"}, {\"Mike\", \"Tarver\"}, \
{\"Wilhelm\", \"Schickard\"}, {\"Ada\", \"Byron\"}, {\"John\", \
\"Atanasoff\"}, {\"Where's\", \"Waldo\"}, {\"Konrad\", \"Zuse\"}, \
{\"Claude\", \"Shannon\"}};\
\>", "Input",
AspectRatioFixed->True],
Cell["\<\
(Note to instructor: Define a \"random\" roster with names placed \
in positions 10 and 2 as below, add Alan Turing in position 15 and two \
\"Where's Waldo\"'s.)\
\>", "SmallText",
Evaluatable->False,
AspectRatioFixed->True],
Cell[CellGroupData[{
Cell[TextData["Part and Parcel (Part, Position)"], "Subsection",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData[
"It is a stretch to call this a roster since the names are not in \
alphabetical order. We can fish out the first two last names by counting to \
see that they are the 10th and 2nd names in the list."], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["roster[[10]]", "Input",
AspectRatioFixed->True],
Cell["roster[[2]]", "Input",
AspectRatioFixed->True],
Cell[TextData[
"Rather than stringing the names down the page, let's keep them gathered in a \
list."], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["{roster[[10]], roster[[2]]}", "Input",
AspectRatioFixed->True],
Cell[TextData[{
StyleBox["Aside",
FontVariations->{"Underline"->True}],
": Experiment with the appearance of the preceding output cell in ",
StyleBox["OutputForm",
FontFamily->"Chicago"],
", ",
StyleBox["StandardForm",
FontFamily->"Chicago"],
", and ",
StyleBox["TraditionalForm",
FontFamily->"Chicago"],
"."
}], "SmallText"],
Cell[TextData[{
"Now we do not have to keep typing \"",
StyleBox["roster", "Input",
FontWeight->"Plain"],
"\"; we can instruct ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" to select out each of several elements of the list. For the parameter in \
double-brackets, we place a list containing, in order, the positions of the \
elements which we would like."
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["roster[[ {10,2} ]]", "Input",
AspectRatioFixed->True],
Cell[TextData[{
"If, however, we do not use a list, ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" will perform another operation: it will find the element whose position \
we specify as the first argument, and then inside that element find the \
element whose position we specify as the second argument, and so on. Examine \
closely what ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" does to the following expression."
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["roster[[10,2]]", "Input",
AspectRatioFixed->True],
Cell[TextData[
"This code did not give us the 10th and 2nd names; instead it took the 10th \
element of the list and gave us the 2nd part of that list."], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData[{
StyleBox[
"This operation of indexing into a list has the functional name \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Part[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\". The command \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["list[[positionNumber(s)]]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" is just shorthand for \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Part[list, positionNumber(s)]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[
"\". This notation can be helpful if you get dizzy with multiple \
brackets.",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Part[roster, {10, 2}]", "Input",
AspectRatioFixed->True],
Cell["Part[roster, 10, 2]", "Input",
AspectRatioFixed->True],
Cell[TextData[{
StyleBox["Now \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Part[list, positionNumber(s)]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[
"\" takes position number(s) and returns the item(s); we may wish to do the \
opposite, determine where inside the list a particular element lies. This \
opposite operation is performed by \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Position[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[
"\". This function enables us to find where in the list is the name \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Turing", "Input",
Evaluatable->False,
AspectRatioFixed->True,
FontWeight->"Plain"],
StyleBox["\".",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Position[roster, \"Turing\"]", "Input",
AspectRatioFixed->True],
Cell[TextData[{
StyleBox["{\"Alan\", \"Turing\"}", "Input",
FontWeight->"Plain"],
" is in the 15th slot of the roster, and \"",
StyleBox["Turing", "Input",
FontWeight->"Plain"],
"\" is in the second position of the list ",
StyleBox["{\"Alan\", \"Turing\"}", "Input",
FontWeight->"Plain"],
"."
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["roster[[15,2]]", "Input",
AspectRatioFixed->True],
Cell[TextData[
"It checks. (By the way, Alan Turing is not actually in the class. He is a \
founding father of computer science who proposed the theoretical Turing \
machine in a work entitled \"On Computable Numbers\" in 1937.)"], "Text",
Evaluatable->False,
AspectRatioFixed->True]
}, Closed]],
Cell[CellGroupData[{
Cell[TextData["Roster Sorting (Map, Reverse)"], "Subsection",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData[{
StyleBox[
"We could attempt to alphabetize our list by hand, or we could use the \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Sort[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" command. We attempt to do so:",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Sort[roster]", "Input",
AspectRatioFixed->True],
Cell[TextData[
"This result, however, is probably not what we wanted; instead, we would like \
to sort the list by last names."], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData[{
StyleBox[
"When we sort a list of lists, it is the first element of each sublist that \
is ranked, or ordered. To sort by last names, our plan should be to reverse \
the order of the elements inside the sublists so that, for example, ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["{FirstName, LastName}", "Input",
Evaluatable->False,
AspectRatioFixed->True,
FontWeight->"Plain"],
StyleBox[" becomes ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["{LastName, FirstName}", "Input",
Evaluatable->False,
AspectRatioFixed->True,
FontWeight->"Plain"],
StyleBox["; afterwards, \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Sort[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[
"\" will sort the elements in the correct fashion. If the tutorial ended \
right here and you were wondering how to reverse the elements of a list, then \
we hope you would enter:",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["?Reverse", "Input",
AspectRatioFixed->True],
Cell[TextData[
"Excellent! Just what we need. Let's try it out on three simple examples."],
"Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["{Reverse[{1,2}], Reverse[{1,2,3}], Reverse[{a,b,c,d}] }", "Input",
AspectRatioFixed->True],
Cell[TextData["Now let's try to reverse the names on the roster."], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Reverse[ roster ]", "Input",
AspectRatioFixed->True],
Cell[TextData[{
"What happened? Each element is still in the form ",
StyleBox["{FirstName, LastName}", "Input",
FontWeight->"Plain"],
". This operation reversed the whole list instead of each sublist."
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData[{
StyleBox[
"The situation we have just encountered is common to list-based \
programmers. Sometimes when we apply a function to a list, the function \
automatically \"enters inside\" and is applied to each element in the list, \
which may be a list itself. The ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Mathematica",
Evaluatable->False,
AspectRatioFixed->True,
FontSlant->"Italic"],
StyleBox[
" terminology for this behavior is that the function is mapped onto the \
list. For example, the \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Sin[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" function is automatically mapped onto lists.",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Sin[{1,2,3}]", "Input",
AspectRatioFixed->True],
Cell[TextData[{
StyleBox["Now why wasn't the \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Reverse[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[
"\" function mapped onto the list of names? To see why we may not want \
that behavior, let's suppose we wanted to transform the list ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["{{1,2},{a,b}}", "Input",
Evaluatable->False,
AspectRatioFixed->True,
FontWeight->"Plain"],
StyleBox[" into ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["{{a,b},{1,2}}", "Input",
Evaluatable->False,
AspectRatioFixed->True,
FontWeight->"Plain"],
StyleBox[". ",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Reverse[{ {1,2},{a,b} } ]", "Input",
AspectRatioFixed->True],
Cell[TextData[{
StyleBox["In this instance we would be very annoyed if \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Reverse[{{1,2},{a,b}}]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" was mapped inside to give us \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["{{2,1},{b,a}}",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\". Sometimes, then, we may want \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Reverse[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" to \"go inside\" and sometimes not. Consequently, as the ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Mathematica",
Evaluatable->False,
AspectRatioFixed->True,
FontSlant->"Italic"],
StyleBox[" developers agreed, it is better not to have \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Reverse[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" mapped onto a list unless we specifically ask for it.",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData[{
StyleBox["Functions like \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Sin[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[
"\" that do automatically go inside a list are called \"Listable\" \
functions. You can find out whether a function is \"Listable\" by asking for \
its \"Attributes\".",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["{Attributes[Sin],Attributes[Reverse]}", "Input",
AspectRatioFixed->True],
Cell[TextData[{
StyleBox[
"Both functions are \"Protected\" so that you cannot accidentally redefine \
them, but \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Sin[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[
"\" is also Listable. At this point we are clear on how to tell if a \
function has the \"Listable\" behavior, but we need to know how to force such \
behavior when ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Mathematica",
Evaluatable->False,
AspectRatioFixed->True,
FontSlant->"Italic"],
StyleBox[
" will not do so automatically. To map a function that is not \
\"Listable\", we use the \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Map[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" function. Let's look at an example.",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["\<\
Clear[f]
f[{1,2,3}]\
\>", "Input",
AspectRatioFixed->True],
Cell[TextData[{
StyleBox["We see that the function \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["f",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" is not Listable, but we can map it onto a list using \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Map[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\":",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Map[f,{1,2,3}]", "Input",
AspectRatioFixed->True],
Cell[TextData[{
StyleBox["\"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Map[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[
"\" takes two arguments, a function and a list. (Note that we need only \
give the name of the function, not any brackets with it.) Think of \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Map[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[
"\" whenever you want to apply a non-\"Listable\" function to every element \
in a list. Let's try mapping \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Reverse[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" onto \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["roster", "Input",
Evaluatable->False,
AspectRatioFixed->True,
FontWeight->"Plain"],
StyleBox["\".",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Map[Reverse,roster]", "Input",
AspectRatioFixed->True],
Cell[TextData[{
StyleBox["Yes! All elements are now in the form ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["{LastName, FirstName}", "Input",
Evaluatable->False,
AspectRatioFixed->True,
FontWeight->"Plain"],
StyleBox[". Using \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Sort[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" should now do exactly what we want.",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Sort[ % ]", "Input",
AspectRatioFixed->True],
Cell[TextData[
"Let's check that we are on the right track, and determine the answer to \
\"Who's the first person on the roster?\""], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["roster[[1]]", "Input",
AspectRatioFixed->True],
Cell[TextData[{
StyleBox[
"What? But we just sorted the roster! \n\nThe problem here is that we \
never indicated that we wanted to change the roster. The first person on the \
original roster is still the first person on \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["roster", "Input",
Evaluatable->False,
AspectRatioFixed->True,
FontWeight->"Plain"],
StyleBox["\". To change \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["roster", "Input",
Evaluatable->False,
AspectRatioFixed->True,
FontWeight->"Plain"],
StyleBox["\" we need to use the assignment operator \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["=", "Input",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier",
FontWeight->"Plain"],
StyleBox["\". Let's put the whole thing together here.",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["roster = Sort[ Map[Reverse,roster] ]", "Input",
AspectRatioFixed->True],
Cell[TextData[{
"Now, we've sorted the roster and recorded the new ordering. As a last \
step let's return to the friendlier ",
StyleBox["{FirstName,LastName}", "Input",
FontWeight->"Plain"],
" form."
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["roster = Map[ Reverse, roster]", "Input",
AspectRatioFixed->True]
}, Closed]],
Cell[CellGroupData[{
Cell[TextData["More List Functions (Transpose)"], "Subsection",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData["Now where in the list is Waldo?"], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Position[ roster, \"Waldo\"]", "Input",
AspectRatioFixed->True],
Cell[TextData[{
StyleBox[
"This tells us that Waldo's name appears twice. To get rid of multiple \
copies in a list we can use \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Union[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\".",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["{ Union[{1,1,1,1,1}], Union[{c,b,a,b}], Union[{5,5,4,5}] }", "Input",
AspectRatioFixed->True],
Cell["roster = Union[roster]", "Input",
AspectRatioFixed->True],
Cell[TextData[{
StyleBox["The \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Union[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[
"\" function also sorts the remaining elements, so the list has been sorted \
by first names again.",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData[
"Now that the list is duplicate-free, let's ask how many people are on the \
roster."], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Length[roster]", "Input",
AspectRatioFixed->True],
Cell[TextData[{
StyleBox[
"Let's have someone join the class. Since we have Alan Turing a founding \
father, we add Grace Hopper a founding mother. (Grace Hopper headed a team \
that developed one of the first languages widely used in business, COBOL. It \
is said that she found \"the first computer bug\" in 1945.) We use the \
function \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Append[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\".",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["roster = Append[ roster, {\"Grace\", \"Hopper\"} ]", "Input",
AspectRatioFixed->True],
Cell[TextData[{
StyleBox["The \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Append[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[
"\" function takes two arguments, the first a list and the second what we \
want to add to the end of the list. \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Prepend[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[
"\" works the same way, except that the new element is added to the start \
of the list. Let's re-sort the list according to last names..",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["roster = Map[ Reverse, Sort[ Map[Reverse,roster] ] ]", "Input",
AspectRatioFixed->True],
Cell[TextData[
"Note that we just carried out a rather complicated operation. Make sure \
that you understand exactly what happened---and how we instructed the \
computer to perform that operation---before scrolling on. If you cannot \
decipher something, then scroll back up for a review, and if that does not \
help, then signal your instructor for some help!"], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData[{
StyleBox[
"Now let's find a list of everybody's first names. To get the first \
element of a list we use \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["First[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\". ",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["{ First[{1,2,3}], First[{\"paper\",\"rock\",\"scissors\"}] }", "Input",
AspectRatioFixed->True],
Cell[TextData[{
StyleBox[
"Think for a moment about how we can produce a list of the first names of \
everyone in the class. We want to apply \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["First[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" to each element in the list \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["roster",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\". Think ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Map",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["!",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Map[First,roster]", "Input",
AspectRatioFixed->True],
Cell[TextData["How about a list of last names?"], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["?Last", "Input",
AspectRatioFixed->True],
Cell[TextData["Looks good."], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Map[Last,roster]", "Input",
AspectRatioFixed->True],
Cell[TextData[
"Now there is another, somewhat sneaky, but very useful, way to separate out \
the first and last names of our list. We can use Tranpose whenever we have a \
list of pairs, such as { {x1,y1}, {x2,y2},...,{xn,yn} } and you want to \
produce the list { {x1,x2,...,xn}, {y1,y2,...yn} }. Let's see a specific \
example."], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Transpose[{ {\"a\",1},{\"b\",2},{\"c\",3},{\"d\",4} } ]", "Input",
AspectRatioFixed->True],
Cell[TextData[{
StyleBox["On the other hand, the function \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Transpose[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[
"\" can take a list containing a list of x's and a list of y's and produce \
a list of {x,y} pairs. Thus, applying \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Transpose[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[
"\" to the last output from above should return us to the list of pairs, \
instead of the pair of lists.",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Transpose[%]", "Input",
AspectRatioFixed->True],
Cell[TextData[
"Now let's try this sneaky way of separating the first and last names."],
"Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Transpose[roster]", "Input",
AspectRatioFixed->True],
Cell[TextData[
"Looks good. Now here's a puzzle. We want to sort the first and last names \
independently and then pair them back together so that the first first name \
and the first last name get paired up. The second first name and second last \
name should be paired up, and so on. "], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData[{
StyleBox["We know that \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Transpose[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[
"\" will split the roster into first and last names. We'd like to sort \
each sublist separately (the same thing to each sublist sounds like a job for \
",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Map",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[
") and then recombine the two sorted lists. To understand that the next \
command will really do all this, you need to read it from inside out. First \
we transpose, then sort each sublist, then transpose back.",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Transpose[ Map[Sort, Transpose[roster] ] ]", "Input",
AspectRatioFixed->True],
Cell[TextData[
"If you're having trouble understanding what a complicated command is doing, \
then copy out small sections of the innards to see what they are doing. Then \
think about what effect each additional layer of the command has."], "Text",
Evaluatable->False,
AspectRatioFixed->True]
}, Closed]],
Cell[CellGroupData[{
Cell[TextData["Making Lists (Table)"], "Subsection",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData[{
StyleBox[
"Let's take a break from the roster for a moment. How can you create a \
list of your own?\nThere are two basic ways: enter one in by hand, or use \
\"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Table[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\". Here are some examples:",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell[CellGroupData[{
Cell[TextData["Create a list of your favorite colors."], "Subsubsection",
Evaluatable->False,
AspectRatioFixed->True],
Cell["{\"Blue\",\"Green\",\"Azure\"}", "Input",
AspectRatioFixed->True],
Cell[TextData[
"There's no pattern to these favorite colors so all we can do is list them by \
hand. "], "Text",
Evaluatable->False,
AspectRatioFixed->True]
}, Closed]],
Cell[CellGroupData[{
Cell["Create a list of the squares of the integers from 1 to 5. ",
"Subsubsection",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData[{
StyleBox["We could enter this by hand, but it's easier to use the \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Table[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" function.",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Table[i^2,{i,1,5}]", "Input",
AspectRatioFixed->True],
Cell[TextData[{
StyleBox["Recall that the \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["i",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" in \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["{i,1,5}",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" is called an ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["iterator",
Evaluatable->False,
AspectRatioFixed->True,
FontSlant->"Italic"],
StyleBox[". Each value of \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["i",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" from 1 to 5 will be squared and put in the list.",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True]
}, Closed]],
Cell[CellGroupData[{
Cell[TextData[
"Create a list showing the squares and cubes of the integers from 1 to 5. "],
"Subsubsection",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Table[{i^2,i^3},{i,1,5}]", "Input",
AspectRatioFixed->True],
Cell[TextData[{
StyleBox["Here ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["{i^2,i^3}",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[" gets recorded for each value of the iterator \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["i",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" from 1 to 5.",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True]
}, Closed]],
Cell[CellGroupData[{
Cell[TextData[
"Create a list of five lists, where the first list is {1}, the second list \
{1,2}, the third list {1,2,3}, and so on. "], "Subsubsection",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Table[ Table[i,{i,1,j}], {j,1,5}]", "Input",
AspectRatioFixed->True],
Cell[TextData[{
StyleBox["The outside \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Table[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" command asks for a list of five things as \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["j",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[
"\" steps from 1 to 5. These five things happen to be lists themselves, \
generated by \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Table[i,{i,1,j}]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\". For example, when ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["j",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["=1 the element is produced by \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Table[i,{i,1,1}]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\", which gives ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["{1}",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[". Consider what happens when ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["j",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["=2.",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[TextData["Shuffling and Matching (Partition)"], "Subsection",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData[{
StyleBox[
"Let's create a list of 10 random Real numbers between 0 and 1. The \
function \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Random[type, {smallest, largest}]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[
"\" returns a random number of data type \"type\" which lies between \
\"smallest\" and \"largest\". Hence we wish to invoke \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Random[Real,{0,1}]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\". (In fact, the default arguments of \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Random[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" are exactly these, so that \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Random[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" performs the same function.)",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["rand10 = Table[ Random[Real,{0,1}], {i,1,10}]", "Input",
AspectRatioFixed->True],
Cell[TextData[
"Now let's return to the roster and work on getting a random ordering of the \
first ten people on the roster. We start by getting the first 10 names of \
the roster."], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["first10 = Take[ roster,10]", "Input",
AspectRatioFixed->True],
Cell[TextData[{
StyleBox["This takes the first 10 elements from the roster list. \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Take[roster,-10]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" would take the last 10 elements.",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData[
"To mix the order of the names we can pair the names with the 10 random \
numbers in \"rand10\" and sort the list. The names will tag along with the \
numbers as the numbers are rearranged. Finally we will get rid of the \
numbers, to leave a random ordering of the ten names. Here's a command \
incorporating each of these steps."], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Map[ Last, Sort[ Transpose[rand10,first10]] ]", "Input",
AspectRatioFixed->True],
Cell[TextData[{
"The command, however, ",
StyleBox["does not work",
FontWeight->"Bold",
FontColor->RGBColor[1, 0, 0]],
". And, to be honest, it is not easy to figure out what went wrong. One \
problem with our approach is that we tried to do too much all at once. It is \
not a good idea to try to write down a long sequence of commands in one go; \
much better to build up the command slowly, using bottom-up analysis and \
testing as one goes along. We follow this plan."
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData["Step 1: Pair a random number with each name. "], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData[{
StyleBox[
"If we think of the numbers as x's and the names as y's, then we have a \
list of x's and a list of y's and want a list of {x,y} pairs. This is a job \
for \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Transpose[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\".",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Transpose[rand10,first10]", "Input",
AspectRatioFixed->True],
Cell[TextData[{
StyleBox["What went wrong here is that \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Transpose[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox[
"\" takes a list as input, and we have given it two separate lists, \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["rand10", "Input",
Evaluatable->False,
AspectRatioFixed->True,
FontWeight->"Plain"],
StyleBox["\" and \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["first10", "Input",
Evaluatable->False,
AspectRatioFixed->True,
FontWeight->"Plain"],
StyleBox[
"\". We need to group these two lists together into the single list \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["{rand10,first10}", "Input",
Evaluatable->False,
AspectRatioFixed->True,
FontWeight->"Plain"],
StyleBox[
"\". We correct our mistake now, before we have a chance to compound it \
with subsequent commands.",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Transpose[{rand10,first10}]", "Input",
AspectRatioFixed->True],
Cell[TextData["Step 2: Sort the list. "], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Sort[%]", "Input",
AspectRatioFixed->True],
Cell[TextData[
"Note that the first elements of the sublists, namely the random numbers, \
were sorted---the names just came along for the ride. "], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData["Step 3: Get rid of the random numbers. "], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData[{
StyleBox["We have a list of sublists. Each sublist looks like \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["{randomNumber, {firstName, lastName}}", "Input",
Evaluatable->False,
AspectRatioFixed->True,
FontWeight->"Plain"],
StyleBox["\", and we want to keep just \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["{firstName, lastName}", "Input",
Evaluatable->False,
AspectRatioFixed->True,
FontWeight->"Plain"],
StyleBox[
"\". We should then take the last part of each sublist. We try \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Last[]", "Input",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier",
FontWeight->"Plain"],
StyleBox["\":",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Map[Last,%]", "Input",
AspectRatioFixed->True],
Cell[TextData["Putting it all together."], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Map[ Last, Sort[ Transpose[{rand10,first10}] ] ]", "Input",
AspectRatioFixed->True],
Cell[TextData[{
"Try to do all of your ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" programming this way. Start small, test as you go, and then add \
additional layers to the command."
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell[TextData[{
StyleBox[
"We are now able randomly to order the roster, as in the command below. \
We've written the command in a format which is simpler to grasp than leaving \
it all on one line; let's take a look at what we've done. First, the command \
is split onto several lines and, within this framework, arguments to \
functions have been indented by two spaces and the closing bracket \"]\" for \
each function appears below the first letter of the function. We can tell, \
for instance, that the final bracket is for the \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Map[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" function, the one above it with \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Sort[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\", and the one above that one with \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Transpose[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\". We notice also that \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Map[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" has two arguments: the function \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Last[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\", and the results of the \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Sort[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" function.",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["\<\
Map[
Last,
Sort[
Transpose[
{Table[Random[],{i,1,Length[roster]}], roster}
]
]
]\
\>", "Input",
AspectRatioFixed->True],
Cell[TextData[
"This still may look unclear, and another programming method is to define \
functions to perform specific subtasks, then placing them together at the \
end. We define functions to do specific parts of the task to a generic list. \
The usefulness of the intermediate functions is debatable, but the final \
product is definitely a great reusable function: we will have created a \
\"shuffle\" function. Let's break it into sub-steps: (a) creating \
corresponding random numbers we will call \"tags\", (b) pairing up with tags, \
(c) sorting by tags, and (d) removing tags."], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["randTags[someList_] := Table[Random[], {Length[someList]}]", "Input",
AspectRatioFixed->True],
Cell["randTags[{1,2,3,4,5}]", "Input",
AspectRatioFixed->True],
Cell["\<\
attachTags[someList_] := Transpose[{randTags[someList], \
someList}]\
\>", "Input",
AspectRatioFixed->True],
Cell["attachTags[{1,2,3,4,5,6}]", "Input",
AspectRatioFixed->True],
Cell[TextData[{
StyleBox["Use \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Range[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" to avoid typing (or using \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Table[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\") for simple lists formed by uniform steps.",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["test = attachTags[Range[8]]", "Input",
AspectRatioFixed->True],
Cell["removeTags[taggedList_] := Map[Last, taggedList]", "Input",
AspectRatioFixed->True],
Cell["removeTags[test]", "Input",
AspectRatioFixed->True],
Cell["Sort[test]", "Input",
AspectRatioFixed->True],
Cell["shuffle[someList_] := removeTags[Sort[attachTags[someList]]]", "Input",
AspectRatioFixed->True],
Cell["shuffle[Range[52]]", "Input",
AspectRatioFixed->True],
Cell["shuffle[roster]", "Input",
AspectRatioFixed->True],
Cell[TextData[{
StyleBox[
"Finally, we consider how we might randomly match partners from the roster. \
This task consists of two steps: (1) randomly order the roster and (2) \
break this list up into pairs. Thankfully, \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["shuffle[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" performs (1) and the ",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Mathematica",
Evaluatable->False,
AspectRatioFixed->True,
FontSlant->"Italic"],
StyleBox[" function \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Partition[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" performs step (2). Check \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["?Partition",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" for information on \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Partition[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\".",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["Partition[{\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\"},2]", "Input",
AspectRatioFixed->True],
Cell["Partition[{\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\"},3]", "Input",
AspectRatioFixed->True],
Cell[TextData[{
StyleBox["Pause a moment and convince yourself how \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Partition[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" works. What if we use \"",
Evaluatable->False,
AspectRatioFixed->True],
StyleBox["Partition[]",
Evaluatable->False,
AspectRatioFixed->True,
FontFamily->"Courier"],
StyleBox["\" on a list of odd length and partition by 2? ",
Evaluatable->False,
AspectRatioFixed->True]
}], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["pairs = Partition[shuffle[roster],2]", "Input",
AspectRatioFixed->True],
Cell[TextData[
"Although the nesting of braces can be confusing, we have produced a list of \
pairs of names. Who's the third pair?"], "Text",
Evaluatable->False,
AspectRatioFixed->True],
Cell["pairs[[3]]", "Input",
AspectRatioFixed->True]
}, Closed]]
}, Closed]]
}, Open ]]
},
FrontEndVersion->"4.0 for Macintosh",
ScreenRectangle->{{0, 1152}, {0, 850}},
WindowToolbars->{},
WindowSize->{552, 473},
WindowMargins->{{4, Automatic}, {Automatic, 1}},
PrintingCopies->1,
PrintingPageRange->{1, Automatic},
PrivateNotebookOptions->{"ColorPalette"->{RGBColor, -1}},
ShowCellLabel->True,
ShowCellTags->False,
RenderingOptions->{"ObjectDithering"->True,
"RasterDithering"->False},
MacintoshSystemPageSetup->"\<\
00<0004/0B`000003809T?o>old"
]
(***********************************************************************
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->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[CellGroupData[{
Cell[1739, 51, 113, 2, 136, "Title",
Evaluatable->False],
Cell[1855, 55, 99, 2, 26, "SmallText",
Evaluatable->False],
Cell[1957, 59, 419, 7, 78, "Text",
Evaluatable->False],
Cell[2379, 68, 687, 18, 306, "SmallText",
Evaluatable->False],
Cell[CellGroupData[{
Cell[3091, 90, 99, 2, 50, "Section",
Evaluatable->False],
Cell[3193, 94, 891, 13, 142, "Text",
Evaluatable->False],
Cell[CellGroupData[{
Cell[4109, 111, 116, 2, 46, "Subsection",
Evaluatable->False],
Cell[4228, 115, 1132, 16, 190, "Text",
Evaluatable->False],
Cell[5363, 133, 1172, 23, 160, "Text",
Evaluatable->False],
Cell[CellGroupData[{
Cell[6560, 160, 109, 2, 42, "Subsubsection",
Evaluatable->False],
Cell[6672, 164, 2263, 56, 226, "Text",
Evaluatable->False],
Cell[8938, 222, 55, 1, 27, "Input"],
Cell[8996, 225, 45, 1, 27, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[9078, 231, 117, 2, 42, "Subsubsection",
Evaluatable->False],
Cell[9198, 235, 838, 20, 110, "Text",
Evaluatable->False],
Cell[10039, 257, 51, 1, 27, "Input"],
Cell[10093, 260, 560, 20, 32, "Text",
Evaluatable->False],
Cell[10656, 282, 64, 1, 27, "Input"],
Cell[10723, 285, 160, 4, 30, "Text",
Evaluatable->False],
Cell[10886, 291, 79, 1, 27, "Input"],
Cell[10968, 294, 98, 2, 30, "Text",
Evaluatable->False],
Cell[11069, 298, 53, 1, 27, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[11159, 304, 104, 2, 42, "Subsubsection",
Evaluatable->False],
Cell[11266, 308, 4380, 128, 334, "Text",
Evaluatable->False],
Cell[15649, 438, 101, 4, 42, "Input"],
Cell[15753, 444, 860, 29, 64, "Text",
Evaluatable->False],
Cell[16616, 475, 54, 1, 27, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[16707, 481, 132, 3, 42, "Subsubsection",
Evaluatable->False],
Cell[16842, 486, 3528, 84, 402, "Text",
Evaluatable->False],
Cell[20373, 572, 107, 7, 87, "Input"],
Cell[20483, 581, 918, 33, 66, "Text",
Evaluatable->False],
Cell[21404, 616, 157, 9, 117, "Input"],
Cell[21564, 627, 53, 1, 27, "Input"]
}, Closed]]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[21678, 635, 91, 2, 30, "Section",
Evaluatable->False],
Cell[21772, 639, 143, 4, 30, "Text",
Evaluatable->False],
Cell[21918, 645, 664, 12, 177, "Input"],
Cell[22585, 659, 240, 6, 40, "SmallText",
Evaluatable->False],
Cell[CellGroupData[{
Cell[22850, 669, 112, 2, 46, "Subsection",
Evaluatable->False],
Cell[22965, 673, 275, 5, 46, "Text",
Evaluatable->False],
Cell[23243, 680, 55, 1, 27, "Input"],
Cell[23301, 683, 54, 1, 27, "Input"],
Cell[23358, 686, 159, 4, 30, "Text",
Evaluatable->False],
Cell[23520, 692, 70, 1, 27, "Input"],
Cell[23593, 695, 357, 13, 42, "SmallText"],
Cell[23953, 710, 440, 12, 64, "Text",
Evaluatable->False],
Cell[24396, 724, 61, 1, 27, "Input"],
Cell[24460, 727, 508, 13, 82, "Text",
Evaluatable->False],
Cell[24971, 742, 57, 1, 27, "Input"],
Cell[25031, 745, 210, 4, 46, "Text",
Evaluatable->False],
Cell[25244, 751, 884, 30, 62, "Text",
Evaluatable->False],
Cell[26131, 783, 64, 1, 27, "Input"],
Cell[26198, 786, 62, 1, 27, "Input"],
Cell[26263, 789, 959, 31, 78, "Text",
Evaluatable->False],
Cell[27225, 822, 71, 1, 27, "Input"],
Cell[27299, 825, 376, 12, 46, "Text",
Evaluatable->False],
Cell[27678, 839, 57, 1, 27, "Input"],
Cell[27738, 842, 289, 5, 62, "Text",
Evaluatable->False]
}, Closed]],
Cell[CellGroupData[{
Cell[28064, 852, 110, 2, 46, "Subsection",
Evaluatable->False],
Cell[28177, 856, 419, 14, 46, "Text",
Evaluatable->False],
Cell[28599, 872, 55, 1, 27, "Input"],
Cell[28657, 875, 185, 4, 46, "Text",
Evaluatable->False],
Cell[28845, 881, 1128, 33, 94, "Text",
Evaluatable->False],
Cell[29976, 916, 51, 1, 27, "Input"],
Cell[30030, 919, 152, 4, 30, "Text",
Evaluatable->False],
Cell[30185, 925, 98, 1, 27, "Input"],
Cell[30286, 928, 123, 2, 30, "Text",
Evaluatable->False],
Cell[30412, 932, 60, 1, 27, "Input"],
Cell[30475, 935, 272, 7, 46, "Text",
Evaluatable->False],
Cell[30750, 944, 884, 26, 80, "Text",
Evaluatable->False],
Cell[31637, 972, 55, 1, 27, "Input"],
Cell[31695, 975, 846, 29, 62, "Text",
Evaluatable->False],
Cell[32544, 1006, 68, 1, 27, "Input"],
Cell[32615, 1009, 1299, 41, 80, "Text",
Evaluatable->False],
Cell[33917, 1052, 497, 16, 46, "Text",
Evaluatable->False],
Cell[34417, 1070, 80, 1, 27, "Input"],
Cell[34500, 1073, 1043, 34, 80, "Text",
Evaluatable->False],
Cell[35546, 1109, 70, 4, 42, "Input"],
Cell[35619, 1115, 562, 20, 30, "Text",
Evaluatable->False],
Cell[36184, 1137, 57, 1, 27, "Input"],
Cell[36244, 1140, 1100, 38, 62, "Text",
Evaluatable->False],
Cell[37347, 1180, 62, 1, 27, "Input"],
Cell[37412, 1183, 590, 20, 46, "Text",
Evaluatable->False],
Cell[38005, 1205, 52, 1, 27, "Input"],
Cell[38060, 1208, 190, 4, 46, "Text",
Evaluatable->False],
Cell[38253, 1214, 54, 1, 27, "Input"],
Cell[38310, 1217, 1004, 31, 94, "Text",
Evaluatable->False],
Cell[39317, 1250, 79, 1, 27, "Input"],
Cell[39399, 1253, 271, 8, 46, "Text",
Evaluatable->False],
Cell[39673, 1263, 73, 1, 27, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[39783, 1269, 112, 2, 46, "Subsection",
Evaluatable->False],
Cell[39898, 1273, 105, 2, 30, "Text",
Evaluatable->False],
Cell[40006, 1277, 71, 1, 27, "Input"],
Cell[40080, 1280, 421, 15, 46, "Text",
Evaluatable->False],
Cell[40504, 1297, 102, 1, 42, "Input"],
Cell[40609, 1300, 65, 1, 27, "Input"],
Cell[40677, 1303, 419, 15, 46, "Text",
Evaluatable->False],
Cell[41099, 1320, 158, 4, 30, "Text",
Evaluatable->False],
Cell[41260, 1326, 57, 1, 27, "Input"],
Cell[41320, 1329, 637, 18, 78, "Text",
Evaluatable->False],
Cell[41960, 1349, 93, 1, 27, "Input"],
Cell[42056, 1352, 748, 24, 62, "Text",
Evaluatable->False],
Cell[42807, 1378, 95, 1, 27, "Input"],
Cell[42905, 1381, 422, 7, 78, "Text",
Evaluatable->False],
Cell[43330, 1390, 417, 15, 30, "Text",
Evaluatable->False],
Cell[43750, 1407, 103, 1, 27, "Input"],
Cell[43856, 1410, 814, 29, 46, "Text",
Evaluatable->False],
Cell[44673, 1441, 60, 1, 27, "Input"],
Cell[44736, 1444, 105, 2, 30, "Text",
Evaluatable->False],
Cell[44844, 1448, 48, 1, 27, "Input"],
Cell[44895, 1451, 85, 2, 30, "Text",
Evaluatable->False],
Cell[44983, 1455, 59, 1, 27, "Input"],
Cell[45045, 1458, 391, 7, 78, "Text",
Evaluatable->False],
Cell[45439, 1467, 98, 1, 27, "Input"],
Cell[45540, 1470, 751, 24, 62, "Text",
Evaluatable->False],
Cell[46294, 1496, 55, 1, 27, "Input"],
Cell[46352, 1499, 147, 4, 30, "Text",
Evaluatable->False],
Cell[46502, 1505, 60, 1, 27, "Input"],
Cell[46565, 1508, 349, 6, 62, "Text",
Evaluatable->False],
Cell[46917, 1516, 867, 26, 78, "Text",
Evaluatable->False],
Cell[47787, 1544, 85, 1, 27, "Input"],
Cell[47875, 1547, 298, 5, 62, "Text",
Evaluatable->False]
}, Closed]],
Cell[CellGroupData[{
Cell[48210, 1557, 100, 2, 46, "Subsection",
Evaluatable->False],
Cell[48313, 1561, 496, 16, 46, "Text",
Evaluatable->False],
Cell[CellGroupData[{
Cell[48834, 1581, 121, 2, 42, "Subsubsection",
Evaluatable->False],
Cell[48958, 1585, 73, 1, 27, "Input"],
Cell[49034, 1588, 160, 4, 30, "Text",
Evaluatable->False]
}, Closed]],
Cell[CellGroupData[{
Cell[49231, 1597, 136, 3, 42, "Subsubsection",
Evaluatable->False],
Cell[49370, 1602, 382, 13, 30, "Text",
Evaluatable->False],
Cell[49755, 1617, 61, 1, 27, "Input"],
Cell[49819, 1620, 922, 34, 48, "Text",
Evaluatable->False]
}, Closed]],
Cell[CellGroupData[{
Cell[50778, 1659, 160, 4, 42, "Subsubsection",
Evaluatable->False],
Cell[50941, 1665, 67, 1, 27, "Input"],
Cell[51011, 1668, 546, 20, 30, "Text",
Evaluatable->False]
}, Closed]],
Cell[CellGroupData[{
Cell[51594, 1693, 202, 4, 58, "Subsubsection",
Evaluatable->False],
Cell[51799, 1699, 76, 1, 27, "Input"],
Cell[51878, 1702, 1586, 57, 78, "Text",
Evaluatable->False]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[53513, 1765, 114, 2, 46, "Subsection",
Evaluatable->False],
Cell[53630, 1769, 1180, 38, 78, "Text",
Evaluatable->False],
Cell[54813, 1809, 88, 1, 27, "Input"],
Cell[54904, 1812, 241, 5, 46, "Text",
Evaluatable->False],
Cell[55148, 1819, 69, 1, 27, "Input"],
Cell[55220, 1822, 414, 13, 46, "Text",
Evaluatable->False],
Cell[55637, 1837, 407, 7, 78, "Text",
Evaluatable->False],
Cell[56047, 1846, 88, 1, 27, "Input"],
Cell[56138, 1849, 552, 12, 80, "Text",
Evaluatable->False],
Cell[56693, 1863, 121, 2, 30, "Text",
Evaluatable->False],
Cell[56817, 1867, 480, 16, 46, "Text",
Evaluatable->False],
Cell[57300, 1885, 68, 1, 27, "Input"],
Cell[57371, 1888, 1142, 38, 78, "Text",
Evaluatable->False],
Cell[58516, 1928, 70, 1, 27, "Input"],
Cell[58589, 1931, 99, 2, 30, "Text",
Evaluatable->False],
Cell[58691, 1935, 50, 1, 27, "Input"],
Cell[58744, 1938, 205, 4, 46, "Text",
Evaluatable->False],
Cell[58952, 1944, 115, 2, 30, "Text",
Evaluatable->False],
Cell[59070, 1948, 901, 29, 62, "Text",
Evaluatable->False],
Cell[59974, 1979, 54, 1, 27, "Input"],
Cell[60031, 1982, 98, 2, 30, "Text",
Evaluatable->False],
Cell[60132, 1986, 91, 1, 27, "Input"],
Cell[60226, 1989, 261, 8, 48, "Text",
Evaluatable->False],
Cell[60490, 1999, 1852, 55, 126, "Text",
Evaluatable->False],
Cell[62345, 2056, 153, 10, 132, "Input"],
Cell[62501, 2068, 651, 10, 110, "Text",
Evaluatable->False],
Cell[63155, 2080, 101, 1, 42, "Input"],
Cell[63259, 2083, 64, 1, 27, "Input"],
Cell[63326, 2086, 119, 4, 42, "Input"],
Cell[63448, 2092, 68, 1, 27, "Input"],
Cell[63519, 2095, 564, 20, 30, "Text",
Evaluatable->False],
Cell[64086, 2117, 70, 1, 27, "Input"],
Cell[64159, 2120, 91, 1, 27, "Input"],
Cell[64253, 2123, 59, 1, 27, "Input"],
Cell[64315, 2126, 53, 1, 27, "Input"],
Cell[64371, 2129, 103, 1, 42, "Input"],
Cell[64477, 2132, 61, 1, 27, "Input"],
Cell[64541, 2135, 58, 1, 27, "Input"],
Cell[64602, 2138, 1303, 44, 80, "Text",
Evaluatable->False],
Cell[65908, 2184, 99, 1, 27, "Input"],
Cell[66010, 2187, 99, 1, 27, "Input"],
Cell[66112, 2190, 608, 20, 46, "Text",
Evaluatable->False],
Cell[66723, 2212, 79, 1, 27, "Input"],
Cell[66805, 2215, 191, 4, 46, "Text",
Evaluatable->False],
Cell[66999, 2221, 53, 1, 27, "Input"]
}, Closed]]
}, Closed]]
}, Open ]]
}
]
*)
(***********************************************************************
End of Mathematica Notebook file.
***********************************************************************)