old wiki Pretty Printing

Alexey U. Gudchenko edited this page Dec 2, 2011 · 2 revisions
Clone this wiki locally

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