Home | Python | IPython | * IPython: Math Processor 2: Installation 3: Getting Started 4: Equation Processing 5: Equation Solving 6: Normal Distribution 7: Differential Equations 8: Fourier Transforms 9: Tips & Tricks  Share This Page
IPython: Math Processor
A tool that manipulates mathematics as a word processor manipulates words

(double-click any word to see its definition)

Introduction

NOTE: Be sure to read my article about Jupyter, IPython's evolutionary successor.

Much has been written about the difference between mathematics and other intellectual disciplines — how mathematics is less accessible, more difficult, more esoteric. But modern computers are closing the gap between mathematics and activities that have a lower threshold for productive activity, like word processing.

We're seeing a rapid change in the role of computers in society and in education, driven by the fact that computer power is increasing as quickly as computer costs decline. This should allow something I call "math processing" to take its place alongside word processing in the personal toolkit of the modern computer user.

When I wrote the first version of Apple Writer in 1979, my target platform (the original Apple ][) had a primitive display — 40 characters wide, uppercase only — but when people found out about my program, they couldn't get it quickly enough. The reason? It increased the efficiency with which people processed words.

A few math programs enable fast, efficient math processing, but at a high cost (examples Mathematica, Maple). The high cost of these programs results from the sometimes complex programming required to produce useful mathematics, but over time open-source projects like Sage, written and maintained by volunteers, have brought costs down (my Sage tutorial).

Internally, Sage relies to a large extent on the math resources of a programming language named Python. Python was chosen because it has a large, and increasing, number of math-oriented features and libraries, including the important ability to solve equations symbolically.

Although Python began as a classic computer language in which source files are written and then tested, a relatively new Python project named IPython supports user interactions (IPython = interactive Python). This article introduces and explores IPython, with special emphasis on the symbolic math features of Python.

Command-Line Interface

The simplest IPython interaction takes place at the command line or "shell". Here's an IPython command-line example that produces and displays a symbolic solution to the quadratic equation $a x^2 + b x + c = 0$:

In : from sympy import *
In : init_printing()
In : a,b,c,x = symbols('a b c x')
In : solve(a*x**2+b*x+c,x)

Out:
⎡        _____________   ⎛       _____________⎞⎤
⎢       ╱           2    ⎜      ╱           2 ⎟⎥
⎢-b + ╲╱  -4⋅a⋅c + b    -⎝b + ╲╱  -4⋅a⋅c + b  ⎠⎥
⎢─────────────────────, ───────────────────────⎥
⎣         2⋅a                     2⋅a          ⎦


Notes:

• Entry  imports Python's symbolic math library "sympy" (symbolic Python).
• Entry  initializes pretty-printing, which allows math results to be rendered "nicely", i.e. nicer than the default format:
Out:
[(-b + sqrt(-4*a*c + b**2))/(2*a), -(b + sqrt(-4*a*c + b**2))/(2*a)]

• Entry  formally declares the algebraic symbols to be used in the solution.
• Entry  calls sympy's "solve()" function with an equation to be solved and the variable to be solved for.
• The output cell  renders the result using fonts to simulate mathematical notation.
Notebook Interface

The above command-line interface can produce useful results in an environment with limited resources and minimal display abilities, but it has some drawbacks. One drawback is that the user's entries aren't preserved. Another is that the display quality is limited. These issues are addressed by IPython's notebook interface. Here's an example:

The notebook interface saves user sessions as plain-text files that can be archived, edited, and refined over time. The notebook supports Latex rendering so the quality of the equation rendering is better, and the notebook interface also supports advanced graphics that can be placed inline with the notebook cells:

The notebook interface allows a high degree of control over editing and revision, and has a number of productivity aids.

Summary

In my view, the IPython notebook is to date the closest thing to a mathematical "word processor", and much of the credit for this accomplishment, as well as for IPython itself, belongs to the IPython project's principal organizer, Fernando Perez. For his work on IPython, Perez received the Free Software Foundation's 2012 award for the advancement of free software.

Compared to Mathematica or Maple, IPython has the advantage that it's free and has many of the most-often-used features of these expensive programs. Compared to Sage, IPython requires less storage space and setup time. For a student or a professional who requires mathematical results but who would prefer not to spend thousands of dollars on proprietary software, IPython may be the best choice of the math programs presently available.

This article set covers IPython installation and use, with many practical examples of math processing in diverse fields.

To navigate this article set, use the arrows and drop-down lists at the top and bottom of each page.

 Home | Python | IPython | * IPython: Math Processor 2: Installation 3: Getting Started 4: Equation Processing 5: Equation Solving 6: Normal Distribution 7: Differential Equations 8: Fourier Transforms 9: Tips & Tricks  Share This Page