Foreword

Foreword: On Computers and Python in Physics

Studies in many areas of science and engineering make use of a number of support tools, with mathematics being one of the prime tools, frequently providing a very precise way to express our concepts and their relationships in science. In the last half century, a new and powerful tool has been added in the form of computers.

In many areas computers have allowed the implementation of schemes to take the mathematical description of physical systems beyond the formal symbolic level, often using numerical techniques to model more realistic physical systems than we could hope to do simply with formal mathematics. This has allowed the construction of more realistic models of physical phenomena, leading to virtual experiments that have significantly increased our understanding.

Modern electronics combined with computers has led to significant improvements in data acquisition, from the smallest elementary laboratory experiments to the largest scale experiments, such as the Large Hadron Collider.

As our experimental and observational techniques and instrumentation have expanded exponentially, we are faced with huge amounts of data, far beyond that which can be analyzed manually. Here as well, computers have provided much of the solution, allowing the establishment of large coherent databases that can be accessed by many users for a variety of purposes.

In both the building of more realistic models and the acquisition of large amounts of increasingly precise data, the computer has provided an important additional tool, that of "visualization" of both model-based and experimental data. Being able to easily examine the data in an interactive on-screen visual manner contributes to advances in many ways, but one of the most important is that it allows one to develop intuition about a system, possibly beyond the initial formal description, that then leads to the "leap" that will move the science forward to the next important discovery.

The emergence of the Python computer language and environment is significant, in that it is a real departure from the usual approach of the last four decades. In the past, most computer languages have been developed with a fairly specific computational task in mind. For example, FORTRAN was initially developed to program computers to evaluate algebraic expressions to produce numerical results. Of course FORTRAN was enhanced over the decades to improve its capabilities in handling other computational tasks, but still somewhat constrained by its original, limited, design priorities. A language such as LISP was developed to handle data that is most conveniently represented as linked lists. The language C was originally designed as a reasonably general programming language, but also with capabilities oriented toward the implementation of "low-level" functionality on specific hardware, such as an operating system like UNIX / LINUX. Languages oriented toward the manipulation formal mathematical expressions, such as Maple or Mathematica, or languages such as MATLAB largely for handling applications in linear algebra, all perform their intended tasks reasonably well, but with limited areas of application.

Since many of the languages mentioned above, and others, have limited realms of application, and each has its own particular syntax, the student is presented with what is close to the "Tower of Babel" when faced with computational tasks across the spectrum of courses in the physical sciences. To add to the difficulties, most of these languages were designed "to get the job done", often with little or no attention to the task of the human who has to master the language and its peculiarities.

Python moves forward on a number of the issues raised above, in part because advantage could be taken of the knowledge gained from experience with older languages. Further, from the outset, it was designed as a teaching language. This aspect is supported by many features, but one of the most basic advantages over some earlier languages is that it can be used interactively, with essentially immediate feedback on syntax errors. It also imposes a certain discipline in programming style, such as in the need to the program text to reflect the program structure through the mandatory use of indentation. While the computer reads the program in a rather "slavish" way, not requiring a conceptual understanding, the programmer and her/his colleagues need to read the program with maximal understanding in order to verify that it reflects their intentions, and then possibly to extend the program in a useful way.

Python provides both a programming language and an environment in which to program, and does so in an easily extensible manner. It provides a large variety of data representations, essentially providing all that all the languages mentioned above provide, but in the one Python environment. Thus one does not have to change computer languages to represent the data differently. This provides huge economies in the learning path for the student programmer. Python also provides the facility for users to provide enhancements to Python to provide specialized packages to handle all the areas mentioned above and many more. From the point of view of the user, these enhanced features are available in essentially the same environment and with syntax consistent with the rest of the Python environment. Thus adding new capabilities, either on your own, or based on the shared work of others, is far easier than most other computer languages. In the distributions provided here, you will have available a number of enhancements, such as VPython or PyLab, but there are many more available now, and more being developed by interested groups all the time. To get some idea of what is available, you can visit some of the web-sites referenced on this website. At this point, there is little capability in the older languages mentioned above, and many other specialized languages, such as IDL, that is not available in Python or a publicly available package for Python.

One important feature of Python and its community is the open nature of the development and the open sharing of software. This far more parallels the approach in the academic community than does the approach of most commercial software packages, and makes Python a much more accessible community for the student. Similarly, Python is available for all the principal operating systems, from Windows, to Linux/Unix, to Mac OS-X, and beyond. This means that the investment in developing software will retain its value for much longer.

Python provides much, both itself and through its community of interest, but beyond that, Python is a relatively easy to learn language, and after the first few lines to get started, it is a lot of fun. Much can learned quickly from simple experimentation, and the "errors" you might come across are not really "errors", but just misunderstandings!