an advanced introduction - Mathematica programming

Feb 4, 2009 - advanced introduction. Leonid Shifrin. Part I: The core language. Version 1.01. Page 2. 2. Mathematica programming: an advanced introduction.
MathematicaÒ programming: an advanced introduction Leonid

Shifrin

Part I: The core language

Version 1.01

2

MathematicaTM is a registered trademark of Wolfram Research Inc. Other symbols, where used, respective owners.

Leonid Shifrin

Digitally signed by Leonid Shifrin DN: cn=Leonid Shifrin, o=Brunel University, ou, [email protected] ming-intro.org, c=GB Date: 2009.02.04 11:30:22 -08'00'

3

To my parents

4

Contents Preface.......................................................................................18 I. Introduction..............................................................................26  1.1

First principle: everything is an expression................................................................26

 1.1.1

Atoms and the built-in AtomQ predicate......................................................................26

 1.1.2

Mathematica normal (composite) expressions............................................................26

 1.1.3

Literal equivalents of built-in functions, and FullForm command................................26

 1.1.4.

All normal expressions are trees - TreeForm command............................................ .27

 1.1.5.

 1.1.6

Accessing individual parts of expressions through indexing ......................................28

 1.1.7

Levels of expressions and the Level command...........................................................28

 1.2

Second principle: pattern-matching and rule substitution...........................................30

 1.2.1

Rewrite Rules..............................................................................................................30

 1.2.2

An example of a simple pattern-defined function........................................................30

 1.2.3

Functions are really rules : DownValues command....................................................31

 1.2.4

Example of a function based on a restricted pattern...................................................31

 1.2.5

 1.2.6

Patterns allow for multiple definitions of the same function.........................................31

 1.2.7

Non - commutativity of rules substitution.....................................................................32

 1.2.8

Automatic rule reordering.............................................................................................32

 1.3

Third principle: expression evaluation........................................................................33

 Summary...............................................................................................................................33

II. Elementary operations..............................................................34  2.1

Introduction........................