Package sympycore :: Module expr :: Class Expr
[hide private]
[frames] | no frames]

Class Expr

source code


Represents an symbolic expression in a pair form: (head, data)

The pair (head, data) is saved in an attribute ``pair``. The parts of a pair, head and data, can be also accessed via ``head`` and ``data`` attributes, respectively. All three attributes are read-only.

The head part is assumed to be an immutable object. The data part can be either an immutable object or Python dictionary. In the former case, the hash value of Expr instance is defined as:
   hash((<Expr>.head, <Expr>.
Otherwise, if ``data`` contains a Python dictionary, then the hash value is defined as:
   hash((<Expr>.head, frozenset(<Expr>.data.items())
WARNING: the hash value of an Expr instance is computed (and cached) when it is used as a key to Python dictionary. This means that the instance content MUST NOT be changed after the hash is computed. To check if it is safe to change the ``data`` dictionary, use ``is_writable`` attribute that returns True when the hash value has not been computed:
   <Expr>.is_writable -> True or False                         
There are two ways to access the parts of a Expr instance from Python:
   a = Expr(<head>, <data>)                                    
   head, data = a.head, a.data     - for backward compatibility        
   head, data = a.pair             - fastest way                       

When Expr constructor is called with one argument, say ``x``, then ``<Expr subclass>.convert(x)`` will be returned.

This is Python version of Expr type.

Instance Methods [hide private]
 
__eq__(self, other) source code
call graph 
 
__ge__(self, other) source code
 
__gt__(self, other) source code
 
__hash__(self)
Compute hash value.
source code
call graph 
 
__init__(self, head, data=None)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
call graph 
 
__le__(self, other) source code
 
__lt__(self, other) source code
call graph 
 
__ne__(self, other) source code
call graph 
 
__nonzero__(self) source code
 
__reduce__(self)
helper for pickle
source code
 
__repr__(self)
repr(x)
source code
 
_sethash(self, hashvalue)
Set hash value for the object.
source code
call graph 
 
as_lowlevel(self)
Return self as low-level object instance that will be used in comparison and in hash computation.
source code
call graph 

Inherited from object: __delattr__, __getattribute__, __new__, __reduce_ex__, __setattr__, __str__

Properties [hide private]
  _hash
  data
  head
  is_writable
  pair

Inherited from object: __class__

Method Details [hide private]

__hash__(self)
(Hashing function)

source code 
call graph 

Compute hash value.

Different from expr_ext.Expr, an exception is raised when data dictionary values contain dictionaries.
Overrides: object.__hash__

__init__(self, head, data=None)
(Constructor)

source code 
call graph 
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
Overrides: object.__init__
(inherited documentation)

__reduce__(self)

source code 
helper for pickle
Overrides: object.__reduce__
(inherited documentation)

__repr__(self)
(Representation operator)

source code 
repr(x)
Overrides: object.__repr__
(inherited documentation)

_sethash(self, hashvalue)

source code 
call graph 

Set hash value for the object.

If hashvalue==-1, then the hash value will be reset.

Used by pickle support in sympycore.core._reconstruct. DO NOT use this method directly.

as_lowlevel(self)

source code 
call graph 

Return self as low-level object instance that will be used in comparison and in hash computation.

By default. as_lowlevel returns ``data`` part if the ``head`` part is ``SYMBOL`` or ``NUMBER``. Otherwise it returns ``pair`` tuple. Note that returning a copy of the tuple will disable using ``frozenset`` hash algorithm for dictionaries.

Property Details [hide private]

data

Get Method:
unreachable.data(self)

head

Get Method:
unreachable.head(self)

is_writable

Get Method:
unreachable.is_writable(self)