My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for

This wiki has moved to https://github.com/sympy/sympy/wiki/. If you are looking for a page that was here, it should be there. It should be under the same name, or a similar one (all pages there are listed at https://github.com/sympy/sympy/wiki/_pages).

Please do not use this wiki any more. All new wiki content should go on the wiki at GitHub.

PrettyPrinting  
Pretty-printing information and examples
Deprecated
Updated Jun 30, 2009 by rwnobrega

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, 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 like

in uxterm:

and gnome-terminal:

Comment by matteo.a...@gmail.com, Nov 19, 2007

Very nice, hope we'll have this soon on Debian! :-) Thanks for your work! -- Matteo

Comment by project member ondrej.c...@gmail.com, Dec 6, 2007

Upgrade your Debian unstable and enjoy. Version 0.5.8 was my first upload as a Debian Maintainer. :)


Sign in to add a comment
Powered by Google Project Hosting