Home > Store

Programming in Mathematica, 3rd Edition

Register your product to gain access to bonus material or receive a coupon.

Programming in Mathematica, 3rd Edition

Book

  • Sorry, this book is no longer in print.
Not for Sale

Description

  • Copyright 1997
  • Dimensions: 7-15/16" x 9-3/16"
  • Pages: 384
  • Edition: 3rd
  • Book
  • ISBN-10: 0-201-85449-X
  • ISBN-13: 978-0-201-85449-7

This revised and expanded edition of the standard reference on programming in Mathematica addresses all the new features in the latest Version 3 of the software. The support for developing larger applications has been improved, and the book now discusses the software engineering issues related to writing and using larger programs in Mathematica. As before, Roman Maeder, one of the original authors of the Mathematica system, explains how to take advantage of its powerful built-in programming language.

New topics in this edition include:

  • The programmable front-end;
  • The language for typesetting mathematical expressions and the treatment of exact numerical quantities;
  • A completely developed larger application, iterated function systems. This code allows readers to explore the fascinating world of chaos and fractals with Mathematica.

Current users of Mathematica, Version 2, and new users of Version 3 will benefit alike from this up-to-date reference to Mathematica programming.



020185449XB04062001

Sample Content

Table of Contents



Preface.


About this Book.

Chapter Overview.

About the Examples.

Notation and Terminology.

The Programming in Mathematica Web Site.

Teaching Mathematica Programming.



1. Introduction.

From Calculations to Programs.

Basic Ingredients of a Package.

A Second Function in the Package.

Options.

Defaults for Positional Arguments.

Parameter Type Checking.



2. Packages.

Contexts.

Packages that Use Other Packages.

Protection of Symbols in a Package.

Package Framework and Documentation.

Loading Packages.

Large Projects.



3. Defaults and Options.

Default Values.

Options for Your Functions.

Setting Options of Several Commands.



4. Functional and Procedural Programming.

Procedures and Local Variables.

Loops.

Structured Iteration.

Iterated Function Application.

Map and Apply.

Application: The Platonic Solids.

Operations on Lists and Matrices.



5. Evaluation.

Evaluation of the Body of a Rule.

Pure Functions.

Nonstandard Evaluation.

Nonlocal Flow of Control.

Definitions.

Advanced Topic: Scopes of Names.



6. Transformation Rules.

Simplification Rules and Normal Forms.

Application: Trigonometric Simplifications.

Globally Defined Rules.

Pattern Matching for Rules.

Traversing Expressions.



7. Numerical Computations.

Numbers.

Numerical Evaluation.

Numeric Quantities.

Application: Differential Equations.



8. Interaction with Built-In Rules.

Modifying the Main Evaluation Loop.

User-Defined Rules Take Precedence.

Modifying System Function.

Advanced Topic: A New Mathematical Function.



9. Input and Output.

Input and Output Formatting.

Input from Files and Programs.

Running Mathematica Unattended.

Session Logging.

Advanced Topic: Typesetting Mathematics.



10. Graphics Programming.

Graphics Packages.

Animated Graphics.

The Chapter Pictures.



11. Notebooks.

Packages and Notebooks.

The Structure of Notebooks.

Frontend Programming.



12. Application: Iterated Function Systems.

Affine Maps.

Iterated Function Systems.

Examples of Invariant Sets.

Documentation: Help Notebooks and Manuals.



Appendix A. Exercises.

Programming Exercises.

Solutions.



Appendix B. Bibliography.

Background Information and Further Reading.



References.


Index.

Programs.

Subjects and Names. 020185449XT04062001

Preface

Mathematica was officially announced in June of 1988. Since then it has found many uses in very diverse fields. While it is useful to do a few calculations interactively, its real strength lies in the programming language it offers. Writing programs, one extends Mathematica with specialized new functions in one's own field of interest.

Mathematica's programming language is unlike any you have encountered before. The language's manual explains all its features and gives some very basic examples of their use. For writing good programs, however, this is not enough: there is clearly a need for a book explaining all the many features in context and giving more extensive examples of their use. The first edition of this book filled this gap for version 1.2 of Mathematica. Like the second edition, this third edition was prompted by a major new version of Mathematica, Version 3.0.

I have been in contact with many early users of Mathematica and I have also given students at the University of Illinois and the Swiss Federal Institute of Technology an opportunity to learn about it. I have seen many programs written in Mathematica, good ones and bad ones. The bad ones invariably solve a particular problem in an unnecessarily complicated way, perhaps because the programmers were unaware of the elegant constructs available in Mathematica. Let me point out these constructs and show you how they can be used to write concise, elegant, and efficient programs.

The best way to teach these Mathematica-specific programming methods is to look at examples of complete programs that solve some nontrivial problem. Even if the example chosen does not lie in the particular field of application that you are interested in, you will be able to use similar ideas for your own programs. Many of the examples presented here deal with graphics. Graphics applications are especially suited for learning programming, because it is easy to see whether your code is correct simply by looking at the picture it produces. Advanced graphics applications are also sufficiently challenging to require advanced programming methods. Other examples come from symbolic computation, geometry, dynamics, and numerical mathematics. Along the way, we also develop many short pieces of code that can be used as parts of larger programs or that help to customize Mathematica to your particular needs. Many of these found their way into the standard Mathematica distribution and are now available to all users.

Because there exists an excellent manual, this book does not explain everything from scratch, but assumes some familiarity with Mathematica. I assume also that you have access to a computer on which to try out the examples. In this book I want to tell you how you can use Mathematica for more than just typing in single commands. If you are using Mathematica for your work, teaching, or solving homework assignments, sooner or later you will encounter more advanced problems requiring many commands to solve, or you will be faced with doing the same calculation steps over and over again with different input. This is the point at which you want to start writing programs. Mathematica includes a rich and powerful programming language. Unlike the usual languages such as BASIC and C, it is not restricted to a small number of data types, but allows you to perform all its symbolic computations. The Mathematica manual can only hint at the possibilities. It explains all the features but does not show you which ones to use for a particular problem or how to fit things together into larger programs.

Through design and tradition, each programming language has developed a certain preferred style of good programming. It is possible to solve the same problem in many different ways, but there is usually some idea about what is a good or a bad program. In this book, I want to present examples of what the designers of Mathematica think is good programming style and show you why this is so. Even if you write your programs strictly for personal use, you will benefit from following a good style. For developing programs for others to use, adhering to this style is indispensable.

The programming examples in this book serve two purposes. First, they help explain concepts and show how things fit together to make up complete programs. Second, they are designed to be more than mere toy programs and should prove useful in their own right. In developing an example we always use the same method. We start out with a few commands or definitions that could be entered directly into Mathematica. We then extract the parts of the computation that are the same regardless of the input and define some functions or procedures that automate these steps. Then we apply standard techniques to these functions to make them into a package, adding documentation and certain programming constructs that make such a package easier to use. The goal is to write a program that would be useful not only to its author, who knows how it works, but also to other people. Finally, we might add a few more functions to the package or look at alternatives to what we did so far. In Chapter 1 these steps are described in full detail. Later on, when we concentrate on other aspects, we assume that you are familiar with these basic concepts and we shall not mention all the steps in detail. All the programs developed in this book are either part of the standard Mathematica distribution from Wolfram Research, or they are available free in electronic form.

Version 3.0 brings major new features. The programming language itself has not changed all that much, but many problems that required elaborate workarounds and many inconsistencies have been remedied. As a consequence, it is now possible to present the material on packages in a more logical fashion. The support for developing larger applications has been improved, and this edition discusses the software engineering issues of writing and using larger programs in Mathematica. The treatment of exact numeric quantities is another area of improvement, and the way numerical code should be written has changed. All programs have been revised to take advantage of the many new built-in functions. I added more material about functional and structural programming. These techniques are fundamental to writing good Mathematica code, but they are not available in most other programming languages and therefore need an expanded treatment.

The most important addition to Version 3.0 is, of course, the new frontend and the typesetting capabilities. The fact that notebooks and typeset formulae are represented as ordinary Mathematica expressions means that they can be manipulated easily with programs. This capability leads to some fascinating applications, and the new material on the frontend and typesetting teaches you how to develop such applications.

A complete, larger application (iterated function systems), more exercises, and an updated bibliography complete this expanded and revised edition.

This book is no replacement for the Mathematica manual The Mathematica Book. I do not expect that you have read everything in the manual, but you should have some basic experience with Mathematica before reading this book. Single commands are usually used without detailed explanation. You can use the index in The Mathematica Book to look up a description of a command that you did not know about. We also give references to places in The Mathematica Book where you can find explanations of concepts that are particularly relevant to a topic in this book. You should always turn to The Mathematica Book for explanations of features that are assumed known here, but that you have not used yet. The place to look for an explanation of all variants, defaults, or options for a particular command is the Reference Guide in the back of the book. All this information is also available in electronic form and can be accessed through the Help Browser of Mathematica.

All explanations about how Mathematica works are based on Version 3.0. The first edition of this book was about Version 1.2. Many things have changed in the new version. I added a few sections called "Changes from Earlier Editions"for the benefit of readers familiar with earlier versions of Mathematica or the first and second edition of this book.

I am grateful to many people who have contributed to this book. My thanks go first to the other developers of Mathematica. The language was shaped through countless discussions and many heated arguments. Trying to explain to each other why we think a certain feature should be done in a certain way has deepened our understanding of the matters involved and has given the language its overall consistency, despite the fact that it contains hundreds of commands and unifies many diverse programming paradigms.

Helpful ideas for this book came from Jim Feagin, Theodore Gray, Dan Grayson, Jerry Keiper, Silvio Levy, Troels Petersen, Will Self, Bruce Smith, Ilan Vardi, Ferrell Wheeler, and Stephen Wolfram. Some of the examples I used were inspired by Henry Cejtin, John Gray, Lee Rubel, William Thurston, Ilan Vardi, Jnrg Waldvogel, and Dave Withoff.

Help with the typographical side of producing this book came from Peter Altenberg, John Bonadies, Joe Kaiping, Daniel Lee, Cameron Smith, and Gregg Snyder, as well as from many other people at Wolfram Research, Inc. and the staff of Addison-Wesley. My past and present publishers, Allan Wylde and Peter Gordon, encouraged me to get started on this book and this new edition.

Roman Maeder
Programming In Mathematica
Herrliberg, Switzerland
August 1996



020185449XP04062001

Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020