SymPy

for smartphones & tablets :

Android, iOS, Maemo 4 & 5, MeeGo Harmattan and Symbian

SymPy is a a Computer Algebra System (CAS) written in pure Python, with no external dependencies (just optional dependencies). So, besides running on desktop OS (Linux, Mac OS and Windows), SymPy also runs in any mobile OS with Python (2.5 onwards) : Android, iOS, Maemo 4 (Diablo), Maemo 5 (Fremantle), MeeGo 1.2 Harmattan and Symbian.

Here I want to summarize the instructions to install & run SymPy on mobile OS and compare which mobile OS give a better SymPy user experience, etc.

The table below compares SymPy running on desktop and mobile OS :
Features / Operating System
Desktop OS - Linux 64 bits (Asus 1215B, AMD C-50 @ 1.0 GHz)
Android (Asus Transformer, NVidia Tegra 2 Cortex A9 @ 1.0 GHz)
iOS (iPad, Apple A4 Cortex A8 @ 1.0 GHz. iPad 2, Apple A5 Cortex A9 @ 1.0 GHz) Maemo 4 (Nokia N810, TI OMAP 2420 ARM11 @ 400 MHz)
Maemo 5 (Nokia N900, TI OMAP 3430 Cortex A8 @ 600 MHz)
MeeGo Harmattan  (Nokia N9, TI OMAP 3630 Cortex A8 @ 1.0 GHz)
Symbian (Nokia E71, Freescale MXC300 ARM 11 @ 369 MHz)
Installation type
Simple, using repositories
Complex, with many steps to install SL4A, Python and then SymPy manually
Simple, by installing 'Python Math' (free) or 'Python for iOS' (US$2.99) from App Store Simple, using repositories Simple, using repositories Not so simple, with manual download of SymPy package
Complex, with many steps to install PyS60 2.0 and then SymPy manually
SymPy version
0.7.1
0.7.1
0.6.7 ('Python Math')
0.7.1 ('Python for iOS')
0.7.1
0.7.1
0.7.1
0.7.1
Time to load
0.58 s
2.22 s
8.89 s ('Python Math' @ iPad), 6.33 s ('Python for iOS' @ iPad 2)
7.52 s
2.76 s
1.66 s
52.6 s
Time to run "integrate (x**5/(alpha*x**2+beta)**2,x)" 1.83 s
2.79 s
3.75 s ('Python Math' @ iPad), 3.16 s ('Python for iOS' @ iPad 2) 34.2 s
10.8 s
5.60 s
22.8 s
Easy of interactive use : Command history, full completion, object information, etc. Yes -
Command history.
Object information (only in 'Python for iOS').
Yes
Yes Yes Only limited command history
isympy (using IPython) availability Yes
-
-
Yes, with IPython 0.10.2 Yes, with IPython 0.10.2 Yes, with IPython 0.10.2
-
Easy of editing SymPy/Python (source-code editors with color highlighting, command completion, object information, etc)
Yes
Few editors with some features
Few editors with some features
Few editors with some features Few editors with some features Few editors with some features 'PED' (works only with PyS60 1.4.5)
'Plot()' for 2D and 3D graphics
Yes
-
-
-
Yes
-
-
Colors rating: Green (Good), Yellow (Average), Red (Low).

My opinion and interpretation of the above table :

Installing & Running SymPy

Android

Python is available as part of SL4A (Scripting Layer for Android). So look at Scripting Layer for Android (SL4A) web site and installing interpreters section to install SL4A and Python. I suggest SL4A_r5x (for smartphones) or SL4A Tablet Remix (for tablets) because they have some UI bugs fixed.

To install pure Python modules on Android, it is very symple, just put the directory/files in "/sdcard/com.googlecode.pythonforandroid/extras/python/".
So, to install SymPy, download 'sympy_0.7.1-android.zip' and unzip it, copying its 'sympy' directory and 'isympy.py' file to "/sdcard/com.googlecode.pythonforandroid/extras/python/".

To use SymPy interactively, open 'SL4A', then select 'View > Interpreters > Python 2.6.2'. To load SymPy, type "from isympy import *". "from sympy.abc import *" is useful because it defines a lot of extras variables.

iOS

From App Store :
  • 'Python Math' is free and includes SymPy v0.6.7. The loading of SymPy is slow possibly due to lack of compiled Python (.pyc) files. Interactive use is limited to command history. There is an optional (US$0.99) Python-specific keyboard extension on top of the virtual keyboard.
  • 'Python for iOS' costs US$4.99, including SymPy v0.7.1 and a keyboard extension on top of the virtual keyboard. 'Python for iOS' allows good interactive use with command history, object help, magic commands, etc.
After opening 'Python Math' or 'Python for iOS', just type "from sympy import *" to load SymPy. "from sympy.abc import *" is useful because it defines a lot of extras variables.

Maemo 4 Diablo and Maemo 5 Fremantle

Follow the SymPy (Computer Algebra System) for Maemo 4 & 5 & 6 topic in Talk Maemo.org, i.e., enable extras repository, search for SymPy in the application manager and install "SymPy Interactive Shell", it will install SymPy and IPython (if not installed before). Tap the SymPy icon to launch IPython interactive shell loading SymPy with some initialization (of variables and output type).

MeeGo 1.2 Harmattan

Follow the SymPy (Computer Algebra System) for Maemo 4 & 5 & 6 topic in Talk Maemo.org, i.e. :
To use, open the Terminal and type :
  • $ isympy
  • if (a large) output is badly not aligned, type 'init_printing(use_unicode=False)'.
I am the maintainer of SymPy for MeeGo Harmattan and I will submit a new version of SymPy (with an icon and depending on IPython) to Nokia Store, so it will be easier to install and run. I was waiting for IPython being available on Nokia's repositories, which happened in December 2011.

Symbian

SymPy needs PyS60 v2.0.0 (which runs Python 2.5.4), but PyS60 1.4.5 (which has Python 2.2.2) is also useful because there are many PyS60 softwares incompatible with PyS60 v2.0.0. For example, PED, the best Python source code editor for Symbian, needs PyS60 1.4.5. To install PyS60 1.4.5, download from the PyS60 project the files 'PythonForS60_1_4_5_3rdEd.sis' and 'PythonScriptShell_1_4_5_3rdEd.sis' (assuming that you have a Symbian S60v3 or newer smartphone) and install them. It is recommended to install PyS60 1.4.5 in drive "E:", before installing PyS60 v2.0.0.

Install PyS60 v2.0.0 following the 'Getting Started' section of the 1st chapter of 'Python on Symbian' book. Install PyS60 in drive "E:".
SymPy needs to be installed manually in "E:\Python\Lib\", so, on "E:" drive, create a "Python" directory with subdirectory "Lib", if they don't exist.
Download 'sympy_0.7.1-symbian.zip' and unzip it, copying its 'sympy' directory, 'isympy.py' and 'timeit.pyc' files to "E:\Python\Lib\".

To use SymPy interactively, open 'Python 2.0.0', then 'Options > Interactive console'. To load SymPy, type "from isympy import *". "from sympy.abc import *" is useful because it defines a lot of extras variables.
To edit SymPy/Python scripts, use PED. But to run scripts using SymPy, use Python 2.0.0.

SymPy Links


SymPy 'Plot' on Maemo 5 OS

SymPy 'Plot()' makes 2D and 3D graphics using PyGlet (OpenGL). PyGlet is an optional dependency for SymPy. Among mobile OS, only on Maemo 5 OS PyGlet works (but not with 100% of its features) : see the PyGlet for Maemo 5 OS site about how to install it on Nokia N900.

How to learn to use 'Plot()' inside SymPy :
On Nokia N900, there are additional keyboard mappings. Stylus also controls translation for 2D graphics and rotation for 3D graphics :
    Plot Window Keyboard Controls
    =============================
   
    Screen Rotation:
        X,Y axis      Arrow Keys, A,S,D,W, Numpad 4,6,8,2
        Z axis        Q,E, Numpad 7,9
   
    Model Rotation:
        Z axis        Z,C, Numpad 1,3
   
    Zoom:             R,F, PgUp,PgDn, Numpad +,-
   
    Reset Camera:     X, Numpad 5
   
    Camera Presets:
        XY            F1, G
        XZ            F2, H
        YZ            F3, J
        Perspective   F4, K
   
    Sensitivity Modifier: SHIFT
   
    Axes Toggle:
        Visible       F5, T
        Colors        F6, Y
   
    Close Window:     ESCAPE
    Screenshot:       F8, I
    =============================
Also, the sensitivity of keyboard and mouse/stylus control was increased on Maemo 5 OS, with or without the 'SHIFT' modifier for smooth 3D movements.

Examples, hints & tips about 'Plot()' :
  1. on Maemo 5 labels on axes and axes tick marks don't work (so, don't use "axes='label_ticks=true; label_axes=true'");
  2. the 'width=800' option is useful to better use the N900 screen (800 x 480 pixels) to show the graphics;
  3. to export the graphics, besides a screenshot (typing 'I' or Ctrl+Shift+P on Maemo 5), it is possible to assign the Plot to a variable, e.g. "p=Plot(sin(x))", and use the 'saveimage' command to save in the current directory, e.g. "p.saveimage('sin.png')", or, with more options, e.g. "p.saveimage('sin.jpg', size=(800, 480))";
  4. boolean values can be 'True'='true'='t'='T' and 'False'='false'='f'='F';
  5. the axes aren't colored by default, but the option "axes='colored=true'" (or typing 'Y' on Maemo 5) shows axes x as red, y as green and z as blue;
  6. 3D plots can have as style : wireframe, solid or both. The default is both, but if the number of steps for some axis is > 40 then a solid style is automatically chosen;
  7. the 'color' option can be 'rainbow' (default), 'zfade', 'zfade3' and 'zfade4' or an user defined scheme;
  8. the default number of steps is 100 for 2D plots and parametric 3D curves, 40 for cartesian 3D plots and parametric 3D surfaces, (40, 20) for cylindrical (theta=t, z=h) 3D plots, (40, 20) for spherical (theta=t, phi=p) 3D plots;
  9. the screenshot examples below show that 2D/3D plots with large number of steps (segments) are slow, while 3D surfaces without wireframe are faster.

Screenshots on Nokia N900 (Maemo 5 OS)

SymPy Plot of a function of 1 variable
SymPy Plot of a function of 1 variable, y = f(x), a dumped harmonic oscillator :
"Plot(2.5*exp(-1.0*x/2)*cos(pi*x), [0,10,150], width=800, caption='Dumped harmonic oscillator')". Timing : 12s / 2s (repeated).
SymPy Plot of a 2D parametric function of 1 variable
SymPy Plot of a 2D parametric function of 1 variable, x = f(t), y = g(t), an explosion : "Plot(t*sin(8*t)*cos(8*t)*cos(t), t*sin(8*t)*cos(8*t)*sin(t), [0,4*pi,1600], width=800, caption='Parametric Explosion', axes='stride=1.0')". Timing : 57s / 17s (repeated).
SymPy Plot of a polar function
SymPy Plot of a polar function, r = f(theta=t), a rose with 8 petals : "Plot(cos(4*t), [200], 'mode=polar', width=800, caption='Polar Rose', axes='tick_length=0.02; stride=0.1')". Timing : 15s / 4s (repeated).
SymPy Plot of a 3D curve of 1 variable
SymPy Plot of a 3D parametric curve of 1 variable, x = f(t), y = g(t), z = h(t), a wire 3D curve : "Plot((2+cos(16*t))*cos(t), (2+cos(16*t))*sin(t), sin(16*t), [800], axes='colored=true', width=800, caption='Wire 3D curve')". Timing : 51s / 9s (repeated).
SymPy Plot of a 3D surface of cartesian coordinates
SymPy Plot of a 3D surface in cartesian coordinates, z = f(x,y), a surface z colored : "Plot(5*x*y*exp(-x**2-y**2), [-2,2,100], [-2,2,100], 'color=zfade4', axes='colored=true', width=800, caption='Surface z colored')". Timing : 36s / 30s (repeated).
SymPy Plot of a 3D surface in cylindrical coordeinates
SymPy Plot of a 3D surface in cylindrical coordinates, r = f(theta=t,z=h), a wormhole : "Plot(z**2/4+1, [], [z,-3,3], 'mode=cylindrical; style=both; color=zfade4', axes='colored=true', width=800, caption='Wormhole surface')". Timing : 25s / 16s (repeated).
SymPy Plot of a 3D surface in spherical coordinates
SymPy Plot of a 3D surface in spherical coordinates, r = f(theta=t,phi=p), an oscillating spherical surface : "Plot(1 + sin(5*t)*sin(10*phi)/10, [t,0,2*pi,80], [phi,0,pi,80], 'mode=spherical; color=zfade4', axes='colored=true', width=800, caption='Oscillating spherical surface')". Timing : 34s / 22s (repeated).
SymPy Plot of a 3D surface of 2 variables
SymPy Plot of a 3D parametric surface of 2 variables, x = f(u,v), y = g(u,v), z = h(u,v), a moebius strip : "Plot((2+(v/2)*cos(u/2))*cos(u), (2+(v/2)*cos(u/2))*sin(u), (v/2)*sin(u/2), [u,0,2*pi,80], [v,-1,1,20], 'color=zfade4', axes='colored=true', width=800, caption='Moebius strip')". Timing : 19s / 7s (repeated).

Comparison with MatPlotLib :

Author : Roberto Colistete Júnior (replace the " arroba " by "@")
Thanks for iPad timings : Jonathan Hosmer, Renato Perim Colistete, Vinicius M. Lube.

Last updates : 26/12 (more editors for MeeGo Harmattan), 15/04 (Maemo 4 & 5 extras repository), 22/02 (updates on Maemo 4 & 5), 18/02 (changes about 'Python for iOS'), 05/02, 04/02, 03/02/2012.

doteasy.com - free web hosting. Free hosting with no banners.
Doteasy Web Hosting