Pretty printing

Thanks to a patch by Jurjen Bos (with some additions & modifications by me) we now got pretty printing in sympy. To see some examples, running it from isympy (you need sympy from svn):

In [1]: pprint x**2 +x +1 ——> pprint(x**2 +x +1) 2 1+x+x In [2]: pprint limit(x, x, oo, evaluate=False) ——> pprint(limit(x, x, oo, evaluate=False)) lim x x->oo In [3]: pprint sqrt(2) ——> pprint(sqrt(2)) ___ \/ 2

Still nesting doesn’t work well and it certainly needs some polishing , but at least it works for simple things.

note that pprint is just a function defined in sympy.modules.printing.pretty , and there’s nothing specific about isympy, only that you can call it without the parenthesis because that’s a feature of ipython.

For the implementation details: following SAGE, we have agreed to put the code for creating a pretty picture into a classmethod called __pretty__(), and pretty, pprint is just a wrapper around that method.

I also commited initial latex support, this time using the same principle as __pretty__ (called __latex__), instead of using xsl on the mathml.

More things: we moved the hash algorithm to use MD5 hashes so that we get the same hashes in different platforms. Now all tests should pass ok in all architectures

5 Responses to “Pretty printing”

  1. Ondrej Says:

    Looks really good. Could you please put some info about prettyprinting into the tutorial?

    Just a suggestion:

    In [9]: pprint limit((5**x+3**x)**(1/x), x, oo, evaluate = False)
    ——> pprint(limit((5**x+3**x)**(1/x), x, oo, evaluate = False))
    lim / -1\
    x->oo \x /
    / x x\
    \5 +3 /

    Maybe the “lim” should be on the same base line as 5^x+3^x (and not at 1/x).

  2. Ondrej Says:

    Well, the formatting got wrong. :)

  3. fabian Says:

    yes, that’s a bug. You’re right, i’ll try to fix it in the afternoon.

  4. Jason Says:

    Hey Fabian, I uploaded a patch for the nested square roots on the issues page, if you haven’t already fixed it!

  5. fabian Says:

    cool. Thanks, it’s commited. The print thing is also fixed now

Leave a Reply