old wiki Pretty Printing - gxyd/sympy GitHub Wiki

old wiki Pretty Printing

This page is obsoleted by http://wiki.sympy.org/wiki/Pretty_Printing


= Introduction =

!SymPy is able to display nice-looking formulas on a pure terminal using ascii-art. Even more -- when unicode is available, it uses special better-looking symbols for drawing.

To try it, run isympy in a unicode-capable terminal such as uxterm or gnome-terminal.

= Example =

{{{ $ ./bin/isympy Python 2.4.4 console for SymPy 0.5.6-hg. These commands were executed:

from future import division from sympy import * x, y, z = symbols('xyz') k, m, n = symbols('kmn', integer=True) Basic.set_repr_level(2) # 2D output pprint_try_use_unicode() # try to setup unicode pprint

In [1]: f = Function('f')

In [2]: f(x/(y+1), y) Out[2]: āŽ› x āŽž fāŽœā”€ā”€ā”€ā”€ā”€, yāŽŸ āŽ1 + y āŽ 

In [3]: sqrt((sqrt(x+1))+1) Out[3]: āŽ½āŽ½āŽ½āŽ½āŽ½āŽ½āŽ½āŽ½āŽ½āŽ½āŽ½āŽ½āŽ½āŽ½āŽ½ ╱ āŽ½āŽ½āŽ½āŽ½āŽ½āŽ½āŽ½ ╲╱ 1 + ╲╱ 1 + x

In [4]: th=Symbol('theta'); ph=Symbol('phi')

In [5]: Integral(sin(th)/cos(ph), (th,0,pi), (ph, 0, 2pi)) Out[5]: 2π π
⌠ ⌠
āŽ® āŽ® sin(Īø)
āŽ® āŽ® ────── dĪø dφ āŽ® āŽ® cos(φ)
⌔ ⌔
0 0

In [6]: Integral(x**2*sin(y), (x,0,1), (y,0,pi)) Out[6]: π 1
⌠ ⌠
āŽ® āŽ® 2
āŽ® āŽ® x *sin(y) dx dy ⌔ ⌔
0 0

In [7]: Mul([Symbol('theta%i' %i) for i in range(1,5)]) Out[7]: Īøā‚Īøā‚‚Īøā‚ƒĪøā‚„

In [8]: Symbol('Y_00')(th,ph)**2 == 1/(4pi) Out[8]: 2 1 Y₀₀ (Īø, φ) = ─── 4Ļ€

In [9]: Matrix([ ...: [1/(4pi), 1], ...: [1, f(x)] ...: ]) Out[9]: āŽ” āŽ¤ āŽ¢ 1 āŽ„ āŽ¢ ─── 1āŽ„ āŽ¢ 4Ļ€ āŽ„ āŽ¢ āŽ„ āŽ¢ āŽ„ āŽ£ 1 f(x)āŽ¦

}}}

= This is how it looks like =

in uxterm:

http://sympy.googlecode.com/svn/materials/web/screenshots/uterm-isympy-unicode.png

and gnome-terminal:

http://sympy.googlecode.com/svn/materials/web/screenshots/gnome-terminal-unicode.png