modelparameters.sympy.printing.pretty package¶
Submodules¶
modelparameters.sympy.printing.pretty.pretty module¶
- class modelparameters.sympy.printing.pretty.pretty.PrettyPrinter(settings=None)[source]¶
Bases:
Printer
Printer, which converts an expression into 2D ASCII-art figure.
- printmethod = '_pretty'¶
- modelparameters.sympy.printing.pretty.pretty.pager_print(expr, **settings)[source]¶
Prints expr using the pager, in pretty form.
This invokes a pager command using pydoc. Lines are not wrapped automatically. This routine is meant to be used with a pager that allows sideways scrolling, like
less -S
.Parameters are the same as for
pretty_print
. If you wish to wrap lines, passnum_columns=None
to auto-detect the width of the terminal.
- modelparameters.sympy.printing.pretty.pretty.pprint(expr, **settings)¶
Prints expr in pretty form.
pprint is just a shortcut for this function.
- Parameters:
expr (expression) – the expression to print
wrap_line (bool, optional) – line wrapping enabled/disabled, defaults to True
num_columns (int or None, optional) – number of columns before line breaking (default to None which reads the terminal width), useful when using SymPy without terminal.
use_unicode (bool or None, optional) – use unicode characters, such as the Greek letter pi instead of the string pi.
full_prec (bool or string, optional) – use full precision. Default to “auto”
order (bool or string, optional) – set to ‘none’ for long expressions if slow; default is None
use_unicode_sqrt_char (bool, optional) – use compact single-character square root symbol (when unambiguous); default is True.
- modelparameters.sympy.printing.pretty.pretty.pretty(expr, **settings)[source]¶
Returns a string containing the prettified form of expr.
For information on keyword arguments see pretty_print function.
- modelparameters.sympy.printing.pretty.pretty.pretty_print(expr, **settings)[source]¶
Prints expr in pretty form.
pprint is just a shortcut for this function.
- Parameters:
expr (expression) – the expression to print
wrap_line (bool, optional) – line wrapping enabled/disabled, defaults to True
num_columns (int or None, optional) – number of columns before line breaking (default to None which reads the terminal width), useful when using SymPy without terminal.
use_unicode (bool or None, optional) – use unicode characters, such as the Greek letter pi instead of the string pi.
full_prec (bool or string, optional) – use full precision. Default to “auto”
order (bool or string, optional) – set to ‘none’ for long expressions if slow; default is None
use_unicode_sqrt_char (bool, optional) – use compact single-character square root symbol (when unambiguous); default is True.
modelparameters.sympy.printing.pretty.pretty_symbology module¶
Symbolic primitives + unicode/ASCII abstraction for pretty.py
- modelparameters.sympy.printing.pretty.pretty_symbology.annotated(letter)[source]¶
Return a stylised drawing of the letter
letter
, together with information on how to put annotations (super- and subscripts to the left and to the right) on it.See pretty.py functions _print_meijerg, _print_hyper on how to use this information.
- modelparameters.sympy.printing.pretty.pretty_symbology.hobj(symb, width)[source]¶
Construct horizontal object of a given width
see: xobj
- modelparameters.sympy.printing.pretty.pretty_symbology.pretty_symbol(symb_name)[source]¶
return pretty representation of a symbol
modelparameters.sympy.printing.pretty.stringpict module¶
Prettyprinter by Jurjen Bos. (I hate spammers: mail me at pietjepuk314 at the reverse of ku.oc.oohay). All objects have a method that create a “stringPict”, that can be used in the str method for pretty printing.
- Updates by Jason Gedge (email <my last name> at cs mun ca)
terminal_string() method
minor fixes and changes (mostly to prettyForm)
- class modelparameters.sympy.printing.pretty.stringpict.prettyForm(s, baseline=0, binding=0, unicode=None)[source]¶
Bases:
stringPict
Extension of the stringPict class that knows about basic math applications, optimizing double minus signs.
“Binding” is interpreted as follows:
ATOM this is an atom: never needs to be parenthesized FUNC this is a function application: parenthesize if added (?) DIV this is a division: make wider division if divided POW this is a power: only parenthesize if exponent MUL this is a multiplication: parenthesize if powered ADD this is an addition: parenthesize if multiplied or powered NEG this is a negative number: optimize if added, parenthesize if multiplied or powered OPEN this is an open object: parenthesize if added, multiplied, or powered (example: Piecewise)
- ADD = 5¶
- ATOM = 0¶
- DIV = 2¶
- FUNC = 1¶
- MUL = 4¶
- NEG = 6¶
- OPEN = 7¶
- POW = 3¶
- simpleFunctions = ['sin', 'cos', 'tan']¶
- class modelparameters.sympy.printing.pretty.stringpict.stringPict(s, baseline=0)[source]¶
Bases:
object
An ASCII picture. The pictures are represented as a list of equal length strings.
- LINE = 'line'¶
- above(*args)[source]¶
Put pictures above this picture. Returns string, baseline arguments for stringPict. Baseline is baseline of bottom picture.
- below(*args)[source]¶
Put pictures under this picture. Returns string, baseline arguments for stringPict. Baseline is baseline of top picture
Examples
>>> from .stringpict import stringPict >>> print(stringPict("x+3").below( ... stringPict.LINE, '3')[0]) x+3 --- 3
- left(*args)[source]¶
Put pictures (left to right) at left. Returns string, baseline arguments for stringPict.
- static next(*args)[source]¶
Put a string of stringPicts next to each other. Returns string, baseline arguments for stringPict.
- parens(left='(', right=')', ifascii_nougly=False)[source]¶
Put parentheses around self. Returns string, baseline arguments for stringPict.
left or right can be None or empty string which means ‘no paren from that side’
- render(*args, **kwargs)[source]¶
Return the string form of self.
Unless the argument line_break is set to False, it will break the expression in a form that can be printed on the terminal without being broken up.
- right(*args)[source]¶
Put pictures next to this one. Returns string, baseline arguments for stringPict. (Multiline) strings are allowed, and are given a baseline of 0.
Examples
>>> from .stringpict import stringPict >>> print(stringPict("10").right(" + ",stringPict("1\r-\r2",1))[0]) 1 10 + - 2
- static stack(*args)[source]¶
Put pictures on top of each other, from top to bottom. Returns string, baseline arguments for stringPict. The baseline is the baseline of the second picture. Everything is centered. Baseline is the baseline of the second picture. Strings are allowed. The special value stringPict.LINE is a row of ‘-’ extended to the width.
Module contents¶
ASCII-ART 2D pretty-printer