|
PrettyPrinting
Pretty-printing information and examples
Deprecated This page is obsoleted by http://wiki.sympy.org/wiki/Pretty_Printing IntroductionSymPy 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, 2*pi))
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/(4*pi)
Out[8]:
2 1
Y₀₀ (θ, φ) = ───
4*π
In [9]: Matrix([
...: [1/(4*pi), 1],
...: [1, f(x)]
...: ])
Out[9]:
⎡ ⎤
⎢ 1 ⎥
⎢ ─── 1⎥
⎢ 4*π ⎥
⎢ ⎥
⎢ ⎥
⎣ 1 f(x)⎦
This is how it looks likein uxterm:
and gnome-terminal:
| |
► Sign in to add a comment
Very nice, hope we'll have this soon on Debian! :-) Thanks for your work! -- Matteo
Upgrade your Debian unstable and enjoy. Version 0.5.8 was my first upload as a Debian Maintainer. :)