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.
|
| Call Graph |
Compute hash value.
Different from expr_ext.Expr, an exception is raised when data
dictionary values contain dictionaries.
- Overrides:
object.__hash__
|
|
| Call Graph |
x.__init__(...) initializes x; see x.__class__.__doc__ for
signature
- Overrides:
object.__init__
- (inherited documentation)
|
helper for pickle
- Overrides:
object.__reduce__
- (inherited documentation)
|
repr(x)
- Overrides:
object.__repr__
- (inherited documentation)
|
|
| 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.
|
|
| 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.
|
data
- Get Method:
- unreachable.data(self)
|
head
- Get Method:
- unreachable.head(self)
|
is_writable
- Get Method:
- unreachable.is_writable(self)
|