Tues. Sep. 18
Wed. Sept. 19
This lecture was an introduction to the computer langauge Perl.
Example 1. Carrying out the computation in the Birthday
Problem. We need to compute (364/365)(363/365)...(341/365). This can be
painful. We write a computer program using perl:
Birthday Computation program for 50 people
If you want to post something on the web, where on your computer do you
put it? The answer depends on how the computer was set-up.
On mail.sas, eniac.seas and the class computer johnny.sas files you have go
in the directory named html, a subdirectory of your
"home" directory. They can also go in sub-directories of this directory.
Although most computers do not allow you to have programs on the
web, our class does allow this. However, for security, they can only
be in the directory html/cgi-bin/ (or its sub-directories).
Any programs on the web must allow anyone to execute them. On a
Unix computer this usually means
chmod 755 [program_name]
Programs not intended for the web can be located in any of your
directories. You may wish to make a directory 210 for our class stuff:
mkdir $HOME/210
Although we will primarily use Perl in class, please feel free to use
any other computer language you may prefer. Just don't assume that I
will be able to help you with it.
Example 2.
A simple Perl example. This will also run on mail.sas or eniac.seas,
except that you may need to change the location of perl. [To
find the location just type which perl.]
Example 3.
A
Web form that collects input for
an addition Perl program. This is essentially identical to the previous
line, except using the Web for input.
Example 3a.
Another example using the Web for input
Example 3b.A similar script, only using JavaScript instead of Perl. This is
entirely self-contained. View the Page Source to see the details.
adding,
using JavaScript.
Example 4.See Voting on
the Web for a sequence of Perl examples I wrote for this class.
See also
Math 210 Bibliography for some useful online Perl references.
Thurs. Sept. 20
Day of the Week: Given a month, day, and year, how do you
compute the day of the week? Pick a reference day, say Jan. 1, 2001
which was a Monday. Find how many days have elapsed between then and
your target date. Thus, if 14 or 700 days have elapsed, then since
these numbers are divisible by 7, the given date is also a Monday. If
702 days have elapsed it is a Wednesday.
Example: June 1, 2001 We need to observe that June 1 is the
152nd day in 2001 (since 31+28+31+30+31+1 = 152) so it is 152-1 = 151
days after Jan. 1. Because 151 = 21*7 + 4, we know the day is 4 days
later, a Friday.
Example: June 1, 2017 We know that 16 full years have
elapsed making 16*365 days, to which we need to add 4 days for the leap
years 2004, 2008, 20012, and 2016. Finally, as above we add 152-1=151
to compute that N = 16*365 + 4 + 151 days have elapsed since Jan. 1,
2001. To determine the day of the week we need only the remainder when
dividing N by 7. It is 3 so the day is three days after Monday: a
Thursday.
To check these computations, on a Unix computer the command
cal 2017 gives a calendar for the year 2017, while
cal 6 2017 gives a calendar for June 2017.
Conditional Probabilities
See The Legacy of
the Reverend Bayes (this is the example we did in class) and
Grinstead and Snell, Chapter 4 (pdf)
Baysean Inference -- Tutorials and Resources
A newspaper article (Feb. 2, 2001).
- Tues. Sep. 25
-