Wednesday, October 06, 2004

Physics 20 Reading List for the week of 10/4/2004-10/8/2004

For some of you, last week marked your first encounter with Mathematica. I think you have gotten a good feeling for the power of this tool, but you might also have been puzzled by its sometimes inconsistent or counterintuitive behavior, and you might have wondered what is the best way to achieve certain things.

1.

Part of your confusion must arise from the fact that Mathematica allows several different programming styles, listed in the Mathematica manual (this link leads you to your first, short reading for this week). You might not be familiar with some of the styles, which I repeat below (I add links to interesting webpages about various languages, when I know of any; the links are there for your curiosity, but are not required or suggested reading).

- Procedural (or imperative) programming requires you to distill your purpose into a series of operations on data objects, to be executed consecutively (but according to flow-control statements such as ''if'' and ''for''). Operations are organized at various levels in modules. Think C.

- List-based programming formulates most operations as manipulations of lists, which may contain eterogeneous data, and sometimes commands (seen as a special type of data that defines an operation). Think LISP, or Scheme.

- Functional programming organizes tasks around the definition and application of expressions (i.e., functions) rather than the execution of commands. It discourages side effects (as the assignment of permanent values to variables) and encourages the reuse and composition of functions. Haskell is a standard model functional language, but the various LISP dialects are also considered functional.

- Rule-based (or logic) programming uses rules to create statements about our knowledge of a system or problem; the rules are then applied recursively to produce a result. Typical applications are to expert systems and to the automated proving of theorems. The canonical language is Prolog.

- Object-oriented programming endows data structures (i.e., objects) with properties (attributes) and behaviors (methods). The same method can be defined in different ways for different objects (polymorphism), and objects can sit in a hierarchy united by inheritance relationships. Think C++.

- String-based programming. Fuhgettabotit.

At the end of the page suggested for your reading, Wolfram technical writers show you how to define the factorial function in twelve different ways. What power! What confusion!

2.

Your second reading: a 1993 interview of Stephen Wolfram, Mathematica's creator. He recounts why the software was created, and how it gained widespread acceptance in the industrial and educational community by appearing at the time when workstations (as opposed to mainframes) powerful enough to run it were beginning to be available.

I agree with Wolfram when he points out that Mathematica contains a much broader variety of programming notions and constructs than most other languages, and therefore can be very useful to teach computation to beginners. As I hinted above, the price for this is a lack of elegance and beauty. In this lab we care about beauty as a defense from complexity! With Mathematica, it can be very easy to build byzantine structures that encode very sophisticated mathematics and numerical analysis, but debugging them can be very troublesome.

Wolfram makes another good point about the blending of mathematics and computation in Mathematica, allowing a ''gentle start'', and harking back to the times when computer science was being developed by eminent mathematicians such as von Neumann and Turing. Again, I agree. It is not by chance that this computational physics laboratory begins with Mathematica.

3.

Let's close this reading session with a few places where you can learn to understand Mathematica's puzzling behavior.

- You may occasionally wonder what is the difference between set (=) and set-delayed (:=)? Read up to and excluding ''A warning about...'' Many other useful tricks can be found on the same website.

- An by the way, why do Plot[], FindRoot[], et similia occasionally require Hold[] or Evaluate[] around their first argument? Learn about the evaluation process in Mathematica, and then go on to the nonstandard evaluation of commands like Plot[].

- (Optional) Functional programming, mentioned above, is an especially efficient way to program in Mathematica, and perhaps the way that is most faithful to the Mathematica spirit of blending mathematics and computer science. The relevant Mathematica commands are Function[], Map[], Apply[], Fold[], Nest[], and others. Read the chapter on functional programming in the Mathematica manual. Stop when you feel that your incremental learning function has flattened out.

- (Optional) Richard Gaylord has an interesting tutorial on the Fundamentals of Mathematica Programming. This material is not elementary: check it out if you are interested in the internal organization of Mathematica.

0 Comments:

Post a Comment

<< Home