monomial.py¶
from pymwp import Monomial
Monomial
¶
Monomial(
scalar: str = UNIT_MWP,
deltas: Optional[Union[List[DELTA], DELTA]] = None,
*args: Optional[DELTA]
)
A monomial is a pair made of:
scalar
- a value in the semi-ring- a sorted list of
deltas
, where an index occurs at most once.
Deltas are coded as pairs \((i,j)\) with:
- \(i\) the value and
- \(j\) the index in the domain (infinite product)
We will have that \((i,j)\) will be equal to the unit of the semi-ring iff the \(j^{th}\) input is equal to \(i\) (so, the \(j^{th}\) choice is \(i\)).
We will make the assumption that the deltas of delta is sorted and no two deltas can have the same index.
Attributes:
Name | Type | Description |
---|---|---|
scalar |
str
|
Monomial scalar. |
deltas |
List[DELTA]
|
List of deltas. |
Create a monomial.
Example
Create a monomial.
mono = Monomial()
Create monomial with scalar \(m\) explicitly.
mono = Monomial('m')
Create monomial with scalar \(w\) and two deltas.
mono = Monomial('w', (0, 0), (1, 1))
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scalar |
str
|
Monomial scalar. |
UNIT_MWP
|
deltas |
Optional[Union[List[DELTA], DELTA]]
|
A delta or a list of deltas. |
None
|
*args |
Optional[DELTA]
|
Arbitrary number of subsequent deltas. |
()
|
choice_scalar
¶
choice_scalar(*choices: int) -> Optional[str]
Determine if given sequence of choices matches monomial.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
choices |
int
|
Tuple of choices. |
()
|
Returns:
Type | Description |
---|---|
Optional[str]
|
Monomial's scalar if structure matches choices and None otherwise. |
contains
¶
contains(m: Monomial) -> bool
Check if all deltas of m are in deltas of self.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
m |
Monomial
|
A monomial to search for intersection. |
required |
Returns:
Type | Description |
---|---|
bool
|
False if one delta of m not in self, True otherwise. |
inclusion
¶
inclusion(monomial: Monomial) -> SetInclusion
Gives info about inclusion of self monomial with monomial.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
monomial |
Monomial
|
A monomial to see inclusion. |
required |
Returns:
Type | Description |
---|---|
SetInclusion
|
CONTAINS if self contains monomial, INCLUDED if self is included in monomial, and EMPTY none of them. |
insert_delta
staticmethod
¶
Takes as input a sorted list of deltas and a delta.
Check if two deltas have the same index:
If they do, and if they:
- disagree on the value expected, returns
[]
(empty list) - agree on the value expected, returns the original deltas
If they don't:
- add the new delta in the deltas "at the right position".
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sorted_deltas |
List[DELTA]
|
List of deltas where to perform insert. |
required |
delta |
DELTA
|
The delta value to be inserted. |
required |
Returns:
Type | Description |
---|---|
List[DELTA]
|
updated list of deltas. |
insert_deltas
staticmethod
¶
prod
¶
Prod combines two monomials where one is this monomial (self) and the second is an argument.
The attributes of the resulting monomial are determined as follows:
- output scalar is a product of the input scalars
- two lists of deltas are merged according to rules of insert_delta
Parameters:
Name | Type | Description | Default |
---|---|---|---|
monomial |
Monomial
|
The second monomial. |
required |
Returns:
Type | Description |
---|---|
Monomial
|
A new Monomial that is a product of two monomials. |