Modules

These numeric and mathematical modules from the Python Standard Library are included in Python Math:

Module Description
numbers Numeric abstract base classes
math Mathematical functions
cmath Mathematical functions for complex numbers
decimal Decimal fixed point and floating point arithmetic
fractions Rational numbers
random Generate pseudo-random numbers
itertools Functions creating iterators for efficient looping
functools Higher order functions and operations on callable objects
operator Standard operators as functions

These third party math modules are included in Python Math:

Module Description
SymPy symbolic mathematics; sample code:

>>> from sympy import Symbol, cos
>>> x = Symbol('x')
>>> e = 1/cos(x)
>>> print e.series(x, 0, 10)
1 + (1/2)*x**2 + (5/24)*x**4 + (61/720)*x**6 + (277/8064)*x**8 + O(x**10)

Command History

The Python Math shell implements command history in three ways:

  • Tap the up or down arrow in the lower right of the shell window to recall commands.
  • Scroll the shell window up or down to any line you previously entered. Edit the line and press the Go button. The edited line will be submitted to the interpreter just as if you had typed it.
  • Use command history inspired by tcsh: !! recalls the previous command, !history displays a numbered history of all commands, !N recalls the Nth command in the history (example: !2), !-N recalls the Nth command previous to the current command.

Managing Scripts

At Apple’s request, we had to remove the capability to load scripts from outside the app via iTunes file sharing and “Open in…” in version 1.5. We’re partially sympathetic to their concerns. After all, there really is no 100% reliable way to assure a given script isn’t malicious. At least they didn’t ban executing Python scripts totally.

Coming soon to make up for this is a built-in editor. Since the iPhone and iPad support paste universally, paste into the editor will become the primary way to get scripts into Python Math.

You can load your own scripts into Python Math in these ways:

  • iTunes File Sharing — iTunes provides the capability to load Python Math scripts (file extension .py) via the iTunes Apps tab. Once loaded, you can execute these scripts with either import or execfile(). See this Apple KB article for details about how to use iTunes file sharing.
  • Email — Python Math recognizes .py email attachments. If you open the attachment with Python Math, it will copy the script into Python Math and execute the script with execfile().
  • Dropbox — Since .py files are registerd as a file format that Python Math recognizes, you can execute them from Dropbox and other apps that store and sync documents. As with email attachments, Python Math copies the script into its own storage and then executes it with execfile().

Executing Scripts

Execute this Python command to view a list of scripts you’ve accumulated using these methods:

os.listdir(".")

Execute any of these scripts with either the import or
execfile() Python command. Examples:

import hpm
execfile("hpm.py")

(The script hpm.pywas preloaded into your scripts folder by Python Math.)

Start-Up Script

If a script named PYTHONSTARTUP.py exists, it will be executed using execfile() upon starting Python Math and restarting the interpreter.

In-App Purchase

On the main window toolbar, click on the price tag icon to purchase the following items:

  • Custom Keyboard is a Python-specific keyboard above the standard keyboard. With this keyboard you don’t have to use the shift keys as often to enter common Python statements and expressions. (For those who previously purchased Remove Ad Banner: Custom Keyboard replaces Remove Ad Banner. If you already purchased Remove Ad Banner, it will automatically convert to Custom Keyboard.)

Limitations

Besides implementing only a small subset of Python modules, Python Math has the following limitations.

  • Can’t get input via input(). Please use raw_input()
  • Prints string expressions without escaping quotes (like the print command).
  • Does not implement any of the several ways you can span string literals over multiple lines.
  • Supports the use of future division (from __future__ import division) in scripts, but not in the interactive shell.

Support

To report problems, get support, complain that I left out your favorite module, or to castigate me for other limitations, please email me using the form below.

Submit

Roadmap

These features have the highest priority:

  • Scripts directory and editor
  • Modules numpy and scipy

These are other features we’re considering in the future:

  • Modules: matplotlib
  • Improved editor with syntax highlighting and auto-completion
  • Snippets

Some of these will be free and others will be available via in-app purchase.

Version History

2011-Nov-30, Version 1.5

NOTICE: At Apple’s request, removed capability to load scripts from outside the app via iTunes file sharing and “Open in”.

New Features

  • VGA output via dock connector for those of you who don’t have AirPlay mirroring
  • Added modules: re, getopt, shutil, pickle, shlex, select
  • Swipe to left/right to show/hide custom keyboard
  • Wrench button shows/hides the toolbar to provide a little more space for the shell window
  • Use up/down arrow buttons in shell window for command history recall

Bug Fixes

  • Fixed: indentation error
  • Fixed: print is a no-op after import
  • Fixed: raw_input
  • Fixed: shell window adapted poorly to iPad split keyboard

2011-Sep-02, Version 1.4.1

  • Fixed: the custom keyboard was not integrated with command history: if you scrolled up to a previous line and edited it with the custom keyboard, the entered characters always appeared on the bottom line.

2011-Aug-24, Version 1.4

  • Revised the Remove Ad Banner in-app purchase to add a Python-specific custom keyboard and renamed it to Custom Keyboard
  • Added command history similar to bash shell

2011-Jul-26, Version 1.3.2

  • Fixed a bug that prematurely exposed unfinished custom keyboard

2011-Jul-21, Version 1.3.1

  • Fixed a nasty bug that prevented entering anything at an indented prompt (…)

2011-Jul-20, Version 1.3

  • Implemented raw_input(); Example:
    >>> s = raw_input('--> ')
    --> hello, world
    >>> print s
    hello, world
  • Added support for all screen orientations on both iPhone and iPad
  • Fixed a bug that allows user to accidentally wipe out the command prompt by backspacing over it

2011-Jun-6, Version 1.2

  • Added execution of a script named PYTHONSTARTUP.py at startup, if present
  • Added capability to load scripts from any app that provides an action menu to open files. Examples are email attachments and Dropbox.

2011-May-6, Version 1.1

  • Added module base64
  • Added support for iTunes file sharing so you can sync scripts between your computer and Python Math
  • Added capability to save console commands as a script (Toolbar Action menu)
  • Added a “Hello World” sample script, “hpm.py,” which can be executed with the command “import hpm”

2011-Apr-27, Version 1.0

  • First time available in the app store

Attributions

Python Math is a better app thanks to these fine open source libraries: