Issue #2 new

Add Operator.format_plaintext method

Erik Bray
repo owner created an issue

Operators already have a format_latex method that returns a LaTeX representation of that operator in one or more possible representations (for example just their names, or their matrix representations, etc.). The Operator._repr_latex_ method just calls Operator.format_latex(...) with the most appropriate "default" representation for that operator when displaying it in IPython notebook.

There ought to be a similar format_plaintext that is used internally for Operator.__repr__.

Along those lines, there really needs to be a better default representation for operator expressions. For example right now repr(o | p) looks something like:

>>> o = Operator([[1, 2], [3, 4]], name='O')
>>> p = Operator([[5, 6], [7, 8]], name='P')
>>> o | p
Operator([[ 1.  2.]
          [ 3.  4.]],
         name='O') | Operator([[ 5.  6.]
          [ 7.  8.]],

This is virtually unreadable. A better default repr for operator expressions might be just to use their names, like:

>>> o | p
O | P

Of course that won't quite work for unnamed operators, in which case it might be necessary to use their matrix formatting. But that can still be done better I'm sure.

This should also include an option for enabling/disabling use of unicode characters in the plaintext repr.

Comments (3)

  1. Log in to comment