esys.escriptcore.symbolic.pretty Package

Classes

class esys.escriptcore.symbolic.pretty.EscriptPrettyPrinter(profile=None)

Bases: sympy.printing.pretty.pretty.PrettyPrinter

doprint(expr)
emptyPrinter

alias of str

join(delimiter, args)
order
printmethod = '_pretty'
classmethod set_global_settings(**settings)

Set system-wide printing settings.

class esys.escriptcore.symbolic.pretty.PrettyPrinter(settings=None)

Bases: sympy.printing.printer.Printer

Printer, which converts an expression into 2D ASCII-art figure.

doprint(expr)
emptyPrinter

alias of str

join(delimiter, args)
order
printmethod = '_pretty'
classmethod set_global_settings(**settings)

Set system-wide printing settings.

class esys.escriptcore.symbolic.pretty.Symbol(*args, **kwargs)

Bases: object

Symbol objects are placeholders for a single mathematical symbol, such as ‘x’, or for arbitrarily complex mathematical expressions such as ‘c*x**4+alpha*exp(x)-2*sin(beta*x)’, where ‘alpha’, ‘beta’, ‘c’, and ‘x’ are also Symbols (the symbolic ‘atoms’ of the expression).

With the help of the ‘Evaluator’ class these symbols and expressions can be resolved by substituting numeric values and/or escript Data objects for the atoms. To facilitate the use of Data objects a Symbol has a shape (and thus a rank) as well as a dimension (see constructor). Symbols are useful to perform mathematical simplifications, compute derivatives and as coefficients for nonlinear PDEs which can be solved by the NonlinearPDE class.

applyfunc(f, on_type=None)

Applies the function f to all elements (if on_type is None) or to all elements of type on_type.

atoms(*types)

Returns the atoms that form the current Symbol.

By default, only objects that are truly atomic and cannot be divided into smaller pieces are returned: symbols, numbers, and number symbols like I and pi. It is possible to request atoms of any type, however.

Note that if this symbol contains components such as [x]_i_j then only their main symbol ‘x’ is returned.

Parameters:types – types to restrict result to
Returns:list of atoms of specified type
Return type:set
coeff(x, expand=True)

Returns the coefficient of the term “x” or 0 if there is no “x”.

If “x” is a scalar symbol then “x” is searched in all components of this symbol. Otherwise the shapes must match and the coefficients are checked component by component.

Example:

x=Symbol('x', (2,2))
y=3*x
print y.coeff(x)
print y.coeff(x[1,1])

will print:

[[3 3]
 [3 3]]

[[0 0]
 [0 3]]
Parameters:x (Symbol, numpy.ndarray, list) – the term whose coefficients are to be found
Returns:the coefficient(s) of the term
Return type:Symbol
diff(*symbols, **assumptions)
evalf()

Applies the sympy.evalf operation on all elements in this symbol

expand()

Applies the sympy.expand operation on all elements in this symbol

getDataSubstitutions()

Returns a dictionary of symbol names and the escript Data objects they represent within this Symbol.

Returns:the dictionary of substituted Data objects
Return type:dict
getDim()

Returns the spatial dimensionality of this symbol.

Returns:the symbol’s spatial dimensionality, or -1 if undefined
Return type:int
getRank()

Returns the rank of this symbol.

Returns:the symbol’s rank which is equal to the length of the shape.
Return type:int
getShape()

Returns the shape of this symbol.

Returns:the symbol’s shape
Return type:tuple of int
grad(where=None)

Returns a symbol which represents the gradient of this symbol. :type where: Symbol, FunctionSpace

inverse()
is_Add = False
is_Float = False
item(*args)

Returns an element of this symbol. This method behaves like the item() method of numpy.ndarray. If this is a scalar Symbol, no arguments are allowed and the only element in this Symbol is returned. Otherwise, ‘args’ specifies a flat or nd-index and the element at that index is returned.

Parameters:args – index of item to be returned
Returns:the requested element
Return type:sympy.Symbol, int, or float
lambdarepr()
simplify()

Applies the sympy.simplify operation on all elements in this symbol

subs(old, new)

Substitutes an expression.

swap_axes(axis0, axis1)
tensorProduct(other, axis_offset)
tensorTransposedProduct(other, axis_offset)
trace(axis_offset)

Returns the trace of this Symbol.

transpose(axis_offset)

Returns the transpose of this Symbol.

transposedTensorProduct(other, axis_offset)
class esys.escriptcore.symbolic.pretty.ValueMatrix(content)

Bases: object

class esys.escriptcore.symbolic.pretty.prettyForm(s, baseline=0, binding=0, unicode=None)

Bases: sympy.printing.pretty.stringpict.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
LINE = 'line'
MUL = 4
NEG = 6
OPEN = 7
POW = 3
above(*args)

Put pictures above this picture. Returns string, baseline arguments for stringPict. Baseline is baseline of bottom picture.

static apply(function, *args)

Functions of one or more variables.

below(*args)

Put pictures under this picture. Returns string, baseline arguments for stringPict. Baseline is baseline of top picture

>>> from sympy.printing.pretty.stringpict import stringPict
>>> print(stringPict("x+3").below(
...       stringPict.LINE, '3')[0]) 
x+3
---
 3
static equalLengths(lines)
height()

The height of the picture in characters.

left(*args)

Put pictures (left to right) at left. Returns string, baseline arguments for stringPict.

leftslash()

Precede object by a slash of the proper size.

static next(*args)

Put a string of stringPicts next to each other. Returns string, baseline arguments for stringPict.

parens(left='(', right=')', ifascii_nougly=False)

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)

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)

Put pictures next to this one. Returns string, baseline arguments for stringPict. (Multiline) strings are allowed, and are given a baseline of 0.

>>> from sympy.printing.pretty.stringpict import stringPict
>>> print(stringPict("10").right(" + ",stringPict("1\r-\r2",1))[0])
     1
10 + -
     2
root(n=None)

Produce a nice root symbol. Produces ugly results for big n inserts.

simpleFunctions = ['sin', 'cos', 'tan']
static stack(*args)

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.

terminal_width()

Return the terminal width if possible, otherwise return 0.

width()

The width of the picture in characters.

Functions

esys.escriptcore.symbolic.pretty.pprint(expr, use_unicode=None)

Prints expr in pretty form.

pprint is just a shortcut for this function

esys.escriptcore.symbolic.pretty.pretty(expr, profile=None, **kargs)

Returns a string containing the prettified form of expr.

Supported arguments:
expr
the expression to print
wrap_line
line wrapping enabled/disabled, should be a boolean value (default to True)
use_unicode
use unicode characters, such as the Greek letter pi instead of the string pi. Values should be boolean or None
full_prec
use full precision. Default to “auto”
esys.escriptcore.symbolic.pretty.pretty_print(expr, use_unicode=None)

Prints expr in pretty form.

pprint is just a shortcut for this function

esys.escriptcore.symbolic.pretty.pretty_symbol(symb_name)

return pretty representation of a symbol

Others

  • __author__
  • __builtins__
  • __copyright__
  • __doc__
  • __file__
  • __license__
  • __name__
  • __package__
  • __url__