You are previewing Programming with Mathematica-: An Introduction.
O'Reilly logo
Programming with Mathematica-: An Introduction

Book Description

Starting from first principles, this book covers all of the foundational material needed to develop a clear understanding of the Mathematica language, with a practical emphasis on solving problems. Concrete examples strewn throughout the text demonstrate how the language can be used to solve problems in science, engineering, economics/finance, computational linguistics, geoscience, bioinformatics and a range of other fields. The book will appeal to students, researchers and programmers wishing to further their understanding of Mathematica. Designed to suit users of any ability, it assumes no formal knowledge of programming so it is ideal for self-study. Over 275 exercises are provided to challenge the reader's understanding of the material covered and these provide ample opportunity to practise using the language. Mathematica notebooks containing examples, programs and solutions to exercises are available from www.cambridge.org/9781107009462.

Table of Contents

  1. Cover
  2. Half title
  3. Title
  4. Copyright
  5. Contents
  6. Preface
  7. 1 An introduction to Mathematica
    1. 1.1 Overview of basic operations
      1. Numerical and symbolic computation
      2. Graphics and visualization
      3. Working with data
      4. Dynamic interactivity
      5. Programming
    2. 1.2 Getting started
      1. Starting up Mathematica
      2. The notebook interface
      3. Entering input
      4. Mathematical expressions
      5. Syntax of functions
      6. Lists
      7. Semicolons
      8. Alternative input syntax
      9. Comments
      10. Errors
      11. Getting out of trouble
      12. The front end and the kernel
    3. 1.3 Getting help
      1. Function information
      2. The Documentation Center
  8. 2 The Mathematica language
    1. 2.1 Expressions
      1. Types of expressions
      2. Atoms
      3. Structure of expressions
      4. Evaluation of expressions
      5. Exercises
    2. 2.2 Definitions
      1. Defining variables and functions
      2. Immediate vs. delayed assignments
      3. Term rewriting
      4. Functions with multiple definitions
      5. Exercises
    3. 2.3 Predicates and Boolean operations
      1. Predicates
      2. Relational and logical operators
      3. Exercises
    4. 2.4 Attributes
      1. Exercises
  9. 3 Lists
    1. 3.1 Creating and displaying lists
      1. List structure and syntax
      2. List construction
      3. Displaying lists
      4. Arrays
      5. Exercises
    2. 3.2 The structure of lists
      1. Testing a list
      2. Measuring lists
      3. Exercises
    3. 3.3 Operations on lists
      1. Extracting elements
      2. Rearranging lists
      3. List component assignment
      4. Multiple lists
      5. Exercises
  10. 4 Patterns and rules
    1. 4.1 Patterns
      1. Blanks
      2. Pattern matching by type
      3. Structured patterns
      4. Sequence pattern matching
      5. Conditional pattern matching
      6. Alternatives
      7. Repeated patterns
      8. Functions that use patterns
      9. Exercises
    2. 4.2 Transformation rules
      1. Creating and using replacement rules
      2. Example: counting coins
      3. Example: closed paths
      4. Example: finding maxima
      5. Exercises
    3. 4.3 Examples and applications
      1. Finding subsequences
      2. Sorting a list
      3. Exercises
  11. 5 Functional programming
    1. 5.1 Introduction
    2. 5.2 Functions for manipulating expressions
      1. Map
      2. Apply
      3. Thread and MapThread
      4. The Listable attribute
      5. Inner and Outer
      6. Select and Pick
      7. Exercises
    3. 5.3 Iterating functions
      1. Nest
      2. FixedPoint
      3. NestWhile
      4. Fold
      5. Exercises
    4. 5.4 Programs as functions
      1. Building up programs
      2. Example: shuffling cards
      3. Compound functions
      4. Exercises
    5. 5.5 Scoping constructs
      1. Localizing names: Module
      2. Localizing values: Block
      3. Localizing constants: With
      4. Example: matrix manipulation
      5. Exercises
    6. 5.6 Pure functions
      1. Syntax of pure functions
      2. Using pure functions
      3. Example: searching for attributes and options
      4. Exercises ·
    7. 5.7 Options and messages
      1. Options
      2. Messages
      3. Exercises
    8. 5.8 Examples and applications
      1. Hamming distance
      2. The Josephus problem
      3. Regular graphs/polygons
      4. Protein interaction networks
      5. Palettes for project files
      6. Operating on arrays
      7. Exercises
  12. 6 Procedural programming
    1. 6.1 Loops and iteration
      1. Newton’s method
      2. Do loops and For loops
      3. Example: random permutations
      4. While loops
      5. NestWhile and NestWhileList
      6. Exercises
    2. 6.2 Flow control
      1. Conditional functions
      2. Piecewise-defined functions
      3. Which and Switch
      4. Argument checking
      5. Exercises
    3. 6.3 Examples and applications
      1. Classifying points
      2. Sieve of Eratosthenes
      3. Sorting algorithms
      4. Exercises
  13. 7 Recursion
    1. 7.1 Fibonacci numbers
      1. Exercises
    2. 7.2 Thinking recursively
      1. Length of a list
      2. Recursion with multiple arguments
      3. Multiplying pairwise elements
      4. Dealing cards, recursively
      5. Finding maxima
      6. Higher-order functions
      7. Exercises
    3. 7.3 Dynamic programming
      1. Exercises
    4. 7.4 Classical examples
      1. Merge sort
      2. Run-length encoding
      3. Exercises
  14. 8 Numerics
    1. 8.1 Numbers in Mathematica
      1. Types of numbers
      2. Digits and number bases
      3. Random numbers
      4. Exercises
    2. 8.2 Numerical computation
      1. Precision and accuracy
      2. Representation of approximate numbers
      3. Exact vs. approximate numbers
      4. High precision vs. machine precision
      5. Computations with mixed number types
      6. Working with precision and accuracy
      7. Exercises
    3. 8.3 Arrays of numbers
      1. Sparse arrays
      2. Packed arrays
      3. Exercises
    4. 8.4 Examples and applications
      1. Newton’s method revisited
      2. Radius of gyration of a random walk
      3. Statistical tests
      4. Exercises
  15. 9 Strings
    1. 9.1 Structure and syntax
      1. Character codes
      2. Sorting lists of characters
      3. Ordered words
      4. Exercises
    2. 9.2 Operations on strings
      1. Basic string operations
      2. Strings vs. lists
      3. Encoding text
      4. Indexed symbols
      5. Anagrams
      6. Exercises
    3. 9.3 String patterns
      1. Finding subsequences with strings
      2. Alternatives
      3. Exercises
    4. 9.4 Regular expressions
      1. Word stemming
      2. Exercises
    5. 9.5 Examples and applications
      1. Random strings
      2. Partitioning strings
      3. Adler checksum
      4. Search for substrings
      5. DNA sequence analysis
      6. Displaying DNA sequences
      7. Blanagrams
      8. Exercises
  16. 10 Graphics and visualization
    1. 10.1 Structure of graphics
      1. Graphics primitives
      2. Graphics directives
      3. Graphics options
      4. Combining graphics elements
      5. Structure of builtin graphics functions
      6. Example: Bézier curves
      7. Example: hypocycloids
      8. Exercises
    2. 10.2 Efficient structures
      1. Multi-objects
      2. GraphicsComplex
      3. Numeric vs. symbolic expressions
      4. Exercises
    3. 10.3 Sound
      1. The sound of mathematics
      2. Sound primitives and directives
      3. Exercises
    4. 10.4 Examples and applications
      1. Space filling plots
      2. Plotting lines in space
      3. Simple closed paths
      4. Points in a polygon
      5. Visualizing standard deviations
      6. Root plotting
      7. Trend plots
      8. Brownian music
      9. Exercises
  17. 11 Dynamic expressions
    1. 11.1 Manipulating expressions
      1. Control objects
      2. Control wrapper
      3. Viewers
      4. Animating the hypocycloid
      5. Visualizing logical operators
      6. Exercises
    2. 11.2 The structure of dynamic expressions
      1. Dynamic
      2. DynamicModule
      3. Dynamic tips
      4. Exercises
    3. 11.3 Examples and applications
      1. Creating interfaces for visualizing data
      2. File openers
      3. Dynamic random walks
      4. Apollonius’ circle
      5. Exercises
  18. 12 Optimizing Mathematica programs
    1. 12.1 Measuring efficiency
      1. Evaluation time
      2. Memory storage
    2. 12.2 Efficient programs
      1. Low-level vs. high-level functions
      2. Pattern matching
      3. Reducing size of computation
      4. Symbolic vs. numeric computation
      5. Listability
      6. Pure functions
      7. Packed arrays
      8. Exercises
    3. 12.3 Parallel processing
      1. Basic examples
      2. Distributing definitions across subkernels
      3. Profiling
      4. Exercises
    4. 12.4 Compiling
      1. Compile
      2. Compiling to C
      3. Exercises
  19. 13 Applications and packages
    1. 13.1 Random walk application
      1. Lattice walks
      2. Off-lattice walks
      3. RandomWalk
      4. Error and usage messages
      5. Visualization
      6. Animation
      7. Exercises
    2. 13.2 Overview of packages
      1. Working with packages
      2. Package location
    3. 13.3 Contexts
    4. 13.4 Creating packages
      1. Package framework
      2. Creating and installing the package
      3. RandomWalks package
      4. Running the package
      5. Exercises
  20. Solutions to exercises
    1. 2 The Mathematica language
    2. 3 Lists
    3. 4 Patterns and rules
    4. 5 Functional programming
    5. 6 Procedural programming
    6. 7 Recursion
    7. 8 Numerics
    8. 9 Strings
    9. 10 Graphics and visualization
    10. 11 Dynamic expressions
    11. 12 Optimizing Mathematica programs
    12. 13 Applications and packages
  21. Bibliography
  22. Index