Computer Science @ Marlboro  

An Introduction to Programming
(with Mathematica)

Info | Syllabus | Assignments | Lecture Notes | Resources | Roster

Info
 
WhenTuesday / Thursday 11:30 - 12:50
WhereSci 217
FacultyJim Mahoney (mahoney@marlboro.edu)
Credits 4 ( i.e. 12 hours/week including class )
Level Introductory
Prereq None
Textbook Computer Science with Mathematica, Roman E. Maeder
Website http://cs.marlboro.edu/term/fall04/mathematica/home.html

An exploration of the ideas behind computer programming, including function calls, object oriented programming, data structures, and lots of other cool stuff. The Mathematica language is quite versatile, allowing for a variety of programming styles - and its easy to draw lots of pretty pictures. This course (or any of the similar ones offered each fall in languages like Java, Perl, or C++) serves as a foundation for further work in computer science or any related field.

The parenthesis so common in both computer science and mathematics should perhaps be inserted into the title of this course so reads "An Intro to Programming (with Mathematica)" rather than "An Intro to (Programming with Mathematica)".

In other words, my intention is to have the focus of the course on programming - what it is, how it works, why one might want to do it, and so on - rather than Mathematica itself. However, programming isn't a subject that is easily studied in the abstract; instead, you need to climb in and get your hands dirty by actually doing it - which is exactly what we're going to do.

Depending on your level of math comfort, I expect that many of you will find the textbook intimidating; the author uses calculus and other higher math freely, and is writing prose generally aimed at a mathematically literate audience. It is my intention, however, to extract out the parts related to the goals of this course, without requiring the calculus bits. So you shouldn't need an extensive math background. However, you will need to be able read and explore mathematical ideas, including being able to learn new notations and syntax - but then, all programming languages require that, really.

Grading will be based on weekly assignments, a final project, and two take home tests along the way, as well as a class participation grade. I plan to drop the lowest of those five scores and average the other four for your final grade.

This webpage will continue to change throughout the semester as assignments and resources are added.


Tentative Syllabus

 
 date             week                      topic
 ---------------------------------------------------------------------------
 Sep        3     0
       7,   9     1                         intro
      14,  16     2                         functions, ...
      21,  23     3                         variables, operators, ...
      28,  30     4                         control flow
 Oct   5,   7     5   mid-term grades       I/O
      12,  14     6                         practice
           21,    7   Hendrick's days       sorting
      26,  28     8                         computability
  Nov  2,   4     9                         databases
       9,  11    10                         object oriented programming
      16,  18    11                         lists and recursion
      23              Thanksgiving          functional programmin
      29,   2    12                          
 Dec   7         13

 == details ================================================================

 week  topic                                                     textbook
---------------------------------------------------------------------------
I) intro
  1    a) general "how-to" for using the mathematica system       chap 1
       b) general intro to programming                             and my notes
  
II) programming notions
 *2    functions, programs, subroutines, comments (API), debug    chap  2
  3    atoms, operators, boolean expressions, variables, lists     and my notes
  4    conditionals and loops                                      .
  5    I/O Import, Export                                          .
  6    practice; packages                                          .

III) classic CS ideas
  7    sorting                                                    chap  6
  8    computability                                              chap 12
  9    databases                                                  chap 13

IV) styles of programming
 10    object oriented programm  (Java, C++)                      chap 14
 11    lists and recursion       (Lisp)                           chap  9
 12    functional programming    (Haskell)                        chap 11

 13    we'll see


Assignments
  1. for Tues September 7
    1. Send me (mahoney@marlboro.edu) an email telling me you're registering for this class.
    2. Try out Mathematica on one of the lab machines. In particular, browse through the online Help system, and
      • read the "Tour",
      • look at "Getting Started", especially "Working with Notebooks",
      • start working through "A Practical Introduction..." in "The Mathematica Book".
      Be ready to bring any questions up in class.
    3. If you have access to the text, browse the first chapter in the text; I'll talk more about the computer science background in class.

  2. for Tues September 14
    1. Read chapter 1 in "Feynman Lectures on Computation", in Sci 217
    2. Read (and explore any topics that catch your attention) the "Computer" entry in the wikipedia at en.wikipedia.org/wiki/Computer.
    3. Read the "Tutorial" (23 screens) in Mathematica's Help menu.
    4. Read James Kelly's "Getting Started" Mathematica notebook. Skip the parts that feel too mathematical, but do look at and work through at least the "Using a notebook interface", "Help!", "Input conventions", and "Using functions" sections.
    5. Do the following exercises in Mathematica; most are from the Getting Started notebook.
      1. Express the number of seconds in a year in hexadecimal form. [Hint: use Help to find functions which manipulate bases and note that hexadecimal form describes a number represented in base 16.]
      2. Display the first 20 powers of 2, i.e. {2, 4, 8, ...}.
      3. Revelation 13.18: "Let him that hath understanding count the number of the beast, for it is the number of a man and his number is 666." Show that the sum of the squares of the first seven primes is the beast number. (Hint: see the Prime and Total functions.)
      4. Create a notebook which presents a simple problem in your field of interest, or perhaps reproduces some recent lecture you heard, or some section of a textbook. Your notebook should have title, author information, sections, text presenting the problem and some background information, and references if appropriate. If you already possess enough Mathematica tools, include the solution also.
      5. Explain in English what this Mathematica expression says.
        !(a && b) == (!a || !b) /. {a -> True, b -> False}

  3. for Tues September 21
    This is a practice programming week: time to dive in.
    1. Do the exercises in the hiddenTurtle.nb notebook.
    2. Write, document, and test an isEven[] function that returns True for an even number, and False for and odd one.
    3. I'm not quite sure where your skills are at this point, so I'm going to suggest several posssible programming projects. Pick at least one (preferably two) to try out. Whichever ones you look at, organize your thinking by answering these questions first.
      • How can I break this problem into smaller pieces?
      • What kinds of data (number, strings, lists, ...) do I need to pass around for these pieces?
      • Does Mathematica have any built in functions that might help?
      • How do I want to display the answer?
      • What do I need to ask the user?
      So here are some possible problems. If something else similar is bubbling in the back of your head that you'd rather try, or these seem beyond you, talk to me about doing something else instead. The point is to pick some kind of numeric search or puzzle or game that can be done as a text input/ouput thing, or as a drawing thing in the Turtle world.
      • Perfect numbers ... we did this in class.
      • A "magic square" is a rectangular grid of numbers whose rows, columns, and diagonals add up to the same number. Can you write a program to find one? More than one? How big are they?
      • Rearrange 1..9 to find fractions such that 1/23 + 4/56 + 7/89 = 1
      • Write a program that simulates one of the state lottery games (you'll have to look up some rules online), letting the user pick a number, generating a winning number, and looking for a win with payoffs.
      • Write a program that simulates a dice game like craps (find rules online, e.g. here) or Cosmic Wimpout (http://www.cosmicwimpout.com/cwrules.htm), or a simplified version of one of these.
      • Play the classic "Mine sweep" game.
      • Play hangman. (You'll have to pick a random word from a list of possible words, and count letters - look for string manipulation functions.

  4. for Tues September 28
    1. More practice - pick another of the many projects from last week, and try again.
    2. Read (if you havne't already) chapters 1 and 2 in the text.
    3. We'll be moving into chapter 6 - searching - next week.

  5. for Tues October 5
    1. Read chapter 6 in the text, on searching and sorting. The author's style is fairly technical, but don't let that scare you away - most of what's in there is pretty cool once you see how it works.
    2. Browse through Sort algorithms on the Wikipedia to see the range of what's out there.
    3. Pick any two of the sorting algorithms listed on the wikipedia site, above. Describe in words how the algorithm proceeds, and work out (by hand) what each would do on a short list like {6,4,1,7,1}. (I call your attention to the "Stupid sort" for a particularly simple one, and the "bogosort" for a particluarly amusing one.")
    4. See my version of Mathematica code to do this stuff in code/search_and_sort
    5. Of those two, pick one to implement in Mathematica. (Get help, if need be, or start with implementations in the wikipedia.) Test your routine on various kinds of initial scrambled lists (at least random and reverse order) and see how they work as the size of the list gets big. While it may be hard to distinguish Mathematica's behavior from the algorithm's behavior, it'd be great if you could measure the O(n) behavior as n gets larger.
    6. Pick any one of the exercises on pg 138 and following to do.

  6. for Tues October 12
    1. An extra week to finish last week's assingnment.
    2. Check out my example of a binary tree dictionary, complete with random words : code/dictionary.

  7. for Thurs October 21 (Tues is Hendrick's days)
    This is a practice with file input/output and data manipulation week.
    1. Read the Mathematica documentation on the commands Directory[], SetDirectory[], Import[], and Export[], BarChart[] (in the Graphics`Graphics` Add-on Package) and ListPlot[].
    2. A .csv file with survey data from a statistics course last year is here. Download it, import it into mathematica, and create a histogram of the women's heights as a bar chart. That is, for each of a number of ranges of heights (5 ft, 5 ft 1 in, 5 ft 2 in, ...) count how many women fall in that range.
    3. With the same data, make plots that shows each woman's height as a function of (a) her mother's height, (b) her father's height, and (c) the average of her parent's height. Does your intuition lead you to any conclusions?
    4. Again with that data, create a new file that has the ages and heights of the black haired men.
    5. Here is a link to the text of Moby Dick. Read it in one line at a time, and make a list of the 50 most frequently used words. Do you think these numbers are representative of the English language, or of this author? (You can find other public texts at the Gutenberg project, http://promo.net/pg/.)

  8. for Tues October 26
    1. Finish up at least the .csv stuff from last time.
    2. Read online about Conway's Game of Life; there are many good online sources.
    3. Submit a preliminary proposal for your final project. This is your only written assignment for this week - so put some thought in. I want more than one sentence here - tell me some thought on how you're going to go about the project, what readings (if any) you've found on the topic, and how you think it might work in Mathematica.

  9. for Tues November 2
    1. Read about computer graphics and how they work in Mathematica :
      • Check out the blurbs on raster graphics and "vector graphics" in the wikipedia. There are links there to human vision, as well, that make interesting reading.
      • Explore my mathmatica notebooks in code/graphics/ and code/oct_28/
      • Read the parts of the online Mathematica documentation that discuss the Graphics object, the Graphics3D object, as well as some of the more general discussions of graphics : "Tour/Visualization" and especially the section "The Mathematica Book / Principles of Mathematica / The Structure of Graphics and Sound". (You can read this in the big hardcopy version of the book on the shelf in 217.)
    2. Look over the code/TurtleGraphics.nb notebook we did earlier this semester, and see how I did the graphics stuff in it.
    3. Please do more thinking about your project, and report what you've done, either some research, or create an initial specification for your project code : what Mathematica functions do you want, and what should they do?
    4. Play around with some kind of graphics in Mathematica. What exactly is up to you. You're welcome to start with some of my code, but I would like to see evidence that you've looked at the documentation and added some new features. Draw a pattern, or animate some random shapes, or rotate a raster image, or create (or even solve) a random maze...

  10. for Tues November 9
    1. Read about buttons and mathematica notebooks, both (a) in the help file, and (b) looking at the examples in the buttons/ directory, including the "LightsOut" game I showed in class.
    2. Continue work on your term projects, including brief a progress report as to what you got done this week.
    3. Create a mathematica notebook that has three buttons, which change what is displayed below them. The idea is something like this, where the picture depends on which button is pushed.
       button1 | button2 | button3
       ---------------------------
       |  picture                |
       ---------------------------
      

  11. for Thurs Nov 11 and Tues Nov 16
    1. Be ready to discuss and look at in class your project.

  12. for Tues Nov 30 - optional
    1. Last weekly assignment.
    2. Read the beginning of chapter 14 in the text
    3. Write a short mathematica program in an object oriented style. See object_oriented. Either convert one of the programs you've written earlier this semester, or follow the assignment in the objects.nb file.


Lecture Notes

Resources

Jim Mahoney (mahoney@marlboro.edu)
<% &lastmodified %>