A Primer on Scientific Programming with Python (5th ed.)

 While teaching, computers have become a very useful tool. For mathematics in particular, the analysis is often used and illustrated by actually computing something, an equation that can be solved analytically or numerically, integrals and derivatives can be evaluated, models for physical, chemical, or biological systems are used for simulations, etc. Popular languages for symbolic computing are maple and mathematica, and when it it becomes numerical, certainly matlab, and for more advanced problems one may use fortran, C, or any of its variants and there are many other languages around that are used for a first course in computer programming, although to all of them are equally suitable for mathematical applications. There is a fuzzy boundary between the use of such a program just for the illustration of a mathematical definition or algorithm on one side and on the other side learning to program, i.e., where the computer science aspect rather than the mathematics is the main goal. The latter does not need mathematics and can be illustrated with typical computer science algorithms like sorting, or string manipulation, or searching in a list, etc. In a mathematics educational context, it is clearly most efficient to combine both and illustrate the programming aspects with familiar mathematical examples and at the same time illustrate how programming can push the mathematical simulation beyond the limit of computation with pen and paper. That combination is the choice made in this book. And of course in the background there is the pure technical aspect of learning the semantics and the syntax of the language too, which in this case is Python.

Python is certainly one of these languages which, besides of allowing to program the solution of mathematical problems, is also fit for use as a first introduction to computer science aspects. It is particularly popular because it is freely available, it can be used interactively (style matlab, maple and the likes) as a scripting language and it has all the advanced features that one would expect from a modern computer language. An extra advantage is that it can easily be linked with software written in other languages.

The latter is in important aspect because computer programs to perform standard tasks or solve numerical problems are around since the middle of the 20th century and many powerful packages are available. Part of the success of a (new) computer language will depend on the fact that it runs for free on many different platforms, that the learning curve is not too steep, and that existing software can still be used. Python obviously is a language satisfying these criterions and moreover it has native constructs like objects and classes, so that also from a computer science viewpoint, it is interesting to introduce the student to something more than just while or for loops and if-then-else constructions.

This is already the fifth edition of the book, so it has been polished for a number of years. Although Python 3 has been around for a while, Lantangen has chosen to still keep his 2.7 version, basically to keep the large amount of software what is already available for version 2. One has to check every line of the existing software to migrate to version 3 because some features behave differently in Python 2 and Python 3. There is however an automatic tool to convert from Python 2.7 to Python 3.5. Hence the choice that Lantangen made here is not a strong restriction, but I am sure the migration will be made in a future edition.

It is a textbook with many examples and many exercises, printed on 945 glossy pages. It requires a table or a desk to read because 2.2 kg is not easily manageable in your hands or on your lap. It is not intended to be a first course in programming, nor is it a first course in numerical mathematics. The reader should at least be familiar with the basics of programming. As Lantangen states in the introduction, it is the main intention to learn the student to think as a programmer should so that he or she can produce programs in a quicker and more reliable way. What Lantangen does not mention, perhaps because it is obvious, is that most effort will go into learning the syntax and the behavior of the computer language Python, or Python 2.7 to be more precise, but remarks usually indicate when there is a difference with Python 3.

When this is used in the context of a course, all the necessary software will have been installed, but a technical appendix explains how to do it on your own machine if necessary, whether it is Linux, Mac, or Windows. Packages like IPython (for interactive use), NumPy (numerics), MatplotLib (matlab-style plotting), sciPython (scientific computing), and possibly Cython (C-expressions) are also used and should be installed too (although Cython is only used in an appendix). The software is absolutely necessary because you can only learn a language by using it. Since there is a lot of software in the examples of this book it is only reasonable that also this code can be downloaded. It is available from the author's github site http://hplgit.github.io/scipro-primer/.

The contents of the book follows the usual steps from elementary operations and formulas, to loops, branching, and input-output operations, meanwhile introducing the different data types (scalars, lists, objects, functions, arrays, dictionaries, strings). Plotting is not so elementary, but some knowledge of plotting with matlab will make it easy by using the MatplotLib package. Classes and working with them (object oriented programming) are less elementary but have now become standard in computer science so this is introduced in the last chapter.

All the concepts are illustrated using relatively simple examples that are mostly mathematical. An exception to that is the chapter on random numbers, stochastic processes and games. It precedes the last chapter on object oriented programming but does not introduce new programming ideas. It is more applied, rounding up and illustrating all that has been introduced so far. It consists mainly of a collection of less elementary examples. This "rounding up" idea is a feature also used at the end of each chapter, summarizing all the new concepts of the chapter. Following the last chapter is and extensive list of appendices where the mathematical concepts are more important than the software concepts, although still elementary in view of the target readership: Newton iteration, differential equations, even a whole project of a mass-spring oscillator. This project includes everything from modelling the physics till plotting of the result. Another appendix illustrates the use of classes to design an extensive ODE package. There is another appendix on debugging and one on exporting Python code to Cython.

This book gives a thorough course to learn Python, and yet it is all brought at the level of a first year at the university. The fact that each concept is introduced with an example is essential. It is not a description of the language, it is a description of how the language is used, which is a very natural approach. Of course how well and how quick the student will be mastering Python will mainly depend on how much experimenting she will do. And that is where the many exercises will help to push the student to just do that and learn to avoid the pitfalls of the semantic and syntactic idiosyncrasies of a new programming language.

Adhemar Bultheel
Book details

This is a fairly complete treatment the Python programming language. It discusses the different constructs by example, which are typically (numerical) mathematical examples that would perfectly fit into a first years calculus course.

Author:  Publisher: 
978-3-662-49886-6 (hbk)
74.19 € (hbk)