relation_list.py¶
from pymwp import RelationList
RelationList
¶
RelationList(
variables: Optional[List[str]] = None,
relation_list: Optional[List[Relation]] = None,
)
Relation list holds a list of Relations
.
It provides methods for performing operations collectively on all
relations in the list.
Attributes:
Name | Type | Description |
---|---|---|
relations |
List[Relation]
|
List of relations. |
To create a relations list, specify either variables
or
relation_list
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variables |
Optional[List[str]]
|
List of variables used to initialize a relation on relation list. |
None
|
relation_list |
Optional[List[Relation]]
|
List of relations for initializing relation list. |
None
|
Specifying a relation_list
argument of a list of Relations
,
initializes a RelationList
containing the provided relations.
If no relation_list
argument is provided, the constructor will
create a relation list with one relation, using the provided
variables
to initialize that relation.
Example
Create relation list using specific variables
rel_list = RelationList(['X0', 'X1', 'X2'])
Generates a list with 1 relation:
X0 | +o +o +o
X1 | +o +o +o
X2 | +o +o +o
Create relation list by providing relations
relations = [Relation(['X0', 'X1']), Relation(['X0'])]
rel_list = RelationList(relation_list=relations)
Generates a list with 2 relations:
1: X0 | +o +o
X1 | +o +o
2: X0 | +o
If no arguments are provided, the result is a relation list with an empty relation.
rel_list = RelationList()
Generates a list with 1 empty relation.
composition
¶
composition(other: RelationList) -> None
Apply composition to all relations in two relation lists.
This method takes as argument other
relation list, then composes the
product of self
and other
by computing the product of each
relation, for all combinations.
Composition occurs in place. After composition self
will contain all
unique relations obtained during composition.
To compose RelationList
and a single Relation
, see
one_composition()
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
RelationList
|
RelationList to compose with |
required |
contains_matrix
staticmethod
¶
contains_matrix(search_in: List[Relation], matrix: List[List]) -> bool
Check if a list of relations contains the provided matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
search_in |
List[Relation]
|
list of relations to search |
required |
matrix |
List[List]
|
search value to look for |
required |
Returns:
Type | Description |
---|---|
bool
|
|
identity
staticmethod
¶
identity(variables: List[str]) -> RelationList
Create relation list that contains 1 identity relation.
This is an alternative way to construct a relation list.
Example
Create relation list containing an identity relation
rel_list = RelationList.identity(['X0', 'X1', 'X2'])
Generates a list with 1 identity relation:
X0 | +m +o +o
X1 | +o +m +o
X2 | +o +o +m
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variables |
List[str]
|
A list of variables. |
required |
Returns:
Type | Description |
---|---|
RelationList
|
RelationList that contains identity relation generated using the provided variables. |
one_composition
¶
one_composition(relation: Relation) -> None
Compose each relation in a relation list × relation.
This method iterates current relation list and applies
composition()
to
each of its relations, using argument relation
as the other operand.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
relation |
Relation
|
relation to compose with relations in current list. |
required |
replace_column
¶
replace_column(vector: list, variable: str) -> None
For each relation in a relation list, replace column with a provided vector, in place.
This method takes as input a variable, then finds the index of that variable based on its name, then applies the column replacement at the discovered index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vector |
list
|
vector that will replace a column |
required |
variable |
str
|
variable value; replace will occur at the index of this variable. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
if variable does not exists some relation belonging to this relation list. |
while_correction
¶
while_correction(dg: DeltaGraph) -> None
Apply while_correction()
to all relations in a relation list.