Monday, November 5, 2007

Unicode printing

One very cool feature of SymPy, that Kirill recently committed, is a unicode printing. Start isympy and see for yourself:

$ 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]: sqrt((sqrt(x+1))+1)
Out[1]:
⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽
╱ ⎽⎽⎽⎽⎽⎽⎽
╲╱ 1 + ╲╱ 1 + x

In [2]: th, ph = Symbol("theta"), Symbol("phi")

In [3]: Integral(sin(th)/cos(ph), (th,0,pi), (ph, 0, 2*pi))
Out[3]:
2*π π
⌠ ⌠
⎮ ⎮ sin(θ)
⎮ ⎮ ────── dθ dφ
⎮ ⎮ cos(φ)
⌡ ⌡
0 0


More examples can be found on the wiki page PrettyPrinting.

Fredrik also played with the idea of ascii plotting. I am a huge fan of a terminal, because this is very versatile - I can use it over ssh, I can copy & paste, save the results to a file etc. I can easily script it. And the most important - I just prefer to write my programs in vim and execute them as a simple script. Any GUI, even the best one (or in the browser), is not giving me such a power. So I like the idea of making the terminal experience as pleasant as possible.

No comments: