Prospectus A Mathematica Programming Primer Published by TELOS/Springer-Verlag Publishers Publication date: August 1993 ISBN: 0-387-94048-0 3-540-94048-0 (International) Authors: Richard J. Gaylord Department of Materials Science University of Illinois Urbana, IL 61801 gaylord@ux1.cso.uiuc.edu Samuel N. Kamin Department of Computer Science University of Illinois Urbana, IL 61801 kamin@cs.uiuc.edu Paul R. Wellin Department of Mathematics Sonoma State University Rohnert Park, CA 94928 wellin@sonoma.edu Overview Almost all universities and colleges require their undergraduate students in engineering, science and mathematics to study a programming language. While Fortran (and sometimes Pascal) is the language most often taught to these students, both they and their professors have been dissatisfied with that language. Mathematica, introduced four years ago as ``A System for Doing Mathematics'' has already gained rapid acceptance in academia and in industry. Additionally, an increasing number of mathematics, science and engineering courses are being taught using it. For example, at the University of Illinois, the numerical analysis course, which is taught every semester to approximately 100 students, uses Mathematica, as does the basic calculus course sequence. Moreover, universities are beginning to use Mathematica to teach programming to scientists, engineers and mathematicians. At the University of Illinois, the required introductory computer science course for engineering students, taken by approximately 800 students each year, is now using Mathematica to teach programming principles. Introduction to Programming with Mathematica is a text in the Mathematica language to be used in a first or second course in programming at the undergraduate level. There are two ``typical'' students who would take such a course --- computer science students, and math and science students who have a programming language requirement. The prerequisite knowledge for such courses is typically an introductory undergraduate math course, usually calculus. Content Introduction to Programming with Mathematica has an extensive bibliography and contains over 200 exercises varying in difficulty from elementary to research level, although most are aimed at the first or second year undergraduate level. A 3.5" high-density floppy diskette is included with the book and contains the code for most of the examples and exercises in the book. In addition, some extensions of certain concepts and hints and answers to exercises are also found on the floppy. Chapter 1: Preliminaries 1.1 Introduction 1.2 What is in This Book 1.3 Basics - getting into and out of Mathematica Syntax of inputs Internal forms of expressions Postfix forms Errors 1.4 Predicates and Boolean Operations Predicates Relational and logical operators 1.5 Evaluation of Expressions Trace and TracePrint Timing Attributes 1.6 The Mathematica Interface The Notebook Front End The command line interface Chapter 2: A Brief Overview of Mathematica 2.1 Numerical and Symbolic Computations 2.2 Functions Example - functions of number theory Random numbers Packages 2.3 Graphics 2-dimensional plots Parametric plots 3-dimensional plots 2.4 Representation of Data 2.5 Programming Example - harmonic numbers Example - perfect numbers Chapter 3: List Manipulation 3.1 Introduction 3.2 Creating and Measuring Lists List construction Dimensions of lists 3.3 Working with the Elements of a List 3.4 Working with Several Lists 3.5 Higher-Order Functions 3.6 Applying Functions to Lists Repeatedly 3.7 Strings and Characters Chapter 4: Functions 4.1 Introduction 4.2 Programs as Functions Nesting Function Calls Value names 4.3 User-Defined Functions 4.4 Auxiliary Functions Compound functions Localizing names 4.5 Anonymous Functions 4.6 One-Liners The Josephus problem Pocket change Chapter 5: Evaluation of Expressions 5.1 Introduction 5.2 Creating Rewrite rules The global rule base 5.3 Expressions Atoms 5.4 Patterns Blanks Expression pattern matching Sequence pattern matching Conditional pattern matching Alternatives 5.5 Term Rewriting 5.6 Transformation Rules Chapter 6: Conditional Function Definitions 6.1 Introduction 6.2 Conditional Functions 6.3 Summary of Conditionals 6.4 Example - Classifying Points in the Plane Chapter 7: Recursion 7.1 Fibonacci Numbers 7.2 List Functions 7.3 Thinking Recursively 7.4 Recursion and Symbolic Computations 7.5 Gaussian Elimination 7.6 Binary Trees Huffman encoding 7.7 Dynamic Programming 7.8 Higher-Order Functions and Recursion 7.9 Debugging Tracing evaluation Printing variables Common errors Chapter 8: Iteration 8.1 Newton's Method Do loops While loops 8.2 Vectors and Matrices List component assignment Finding prime numbers 8.3 Passing Arrays to Functions 8.4 Gaussian Elimination Revisited Chapter 9: Numerics 9.1 Types of Numbers Integers and rationals Real numbers Complex numbers Computing with different number types Digits and number bases 9.2 Random Numbers 9.3 Precision and Accuracy Roundoff errors 9.4 Numerical Computations Newton's method revisited Gaussian elimination revisited (again) Chapter 10: Graphics Programming 10.1 Graphics Primitives Two-dimensional graphics primitives Three-dimensional graphics primitives 10.2 Graphics Directives and Options 10.3 Built-In Graphics Functions The structure of built-in graphics Graphics anomalies Options for built-in graphics functions 10.4 Graphics Programming Simple closed paths Drawing trees 10.5 Sound The sound of mathematics White music, brownian music, and fractal noise Chapter 11: Contexts and Packages 11.1 Introduction 11.2 Using Packages 11.3 Contexts 11.4 The BaseConvert Package 11.5 Miscellaneous Topics Avoiding name collisions Finding out what's in a package Bibliography Index About the Authors Richard J. Gaylord, (Department of Materials Science and Engineering, University of Illinois, Urbana) is a professor working in the area of programming languages for scientific computing. He has written over 40 technical articles in the area of theoretical polymer physics. He teaches a course on Computer Simulations in Materials. He is on the editorial advisory board of The Mathematica Journal and is a contributing editor to the Mathematica in Education quarterly where he writes a regular column ``Simulating Experiences: Excursion in Programming.'' He gives lectures and tutorials on the Mathematica programming language. Samuel N. Kamin, (Department of Computer Science, University of Illinois at Champaign) specializes in the study of theoretical and applied issues in programming languages, and has published technical papers on functional and object-oriented programming, as well as program verification and compilation. He is the author of the textbook ``Programming Languages: An Interpreter-based Approach'' (Addison-Wesley, 1990). Paul R. Wellin, (Department of Mathematics, Sonoma State University) is currently the editor of Mathematica in Education, an international quarterly, multi-disciplinary publication that addresses issues in the usage of computer algebra systems such as Mathematica in the undergraduate (and secondary) curriculum. He has been piloting laboratory-based calculus courses at Sonoma State University using Mathematica for the past three years. In addition, he has given numerous talks at meetings such as the annual AMS-MAA meetings, math colloquia around the state of California, and NSF-sponsored conferences on the incorporation of technology in the mathematics curriculum.