relation_list.py¶
from pymwp import RelationList
RelationList
¶
Relation list holds a list of Relations
.
It provides methods for performing operations collectively on all relations in the list.
Source code in pymwp/relation_list.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
|
first
property
¶
Gets the first relation in relation list.
__init__(variables=None, relation_list=None)
¶
Create relation list.
When creating a relations list, specify either variables
or
relation_list
.
Specifying a relation_list
argument, whose value is a list of
Relations
, will initialize a RelationList
containing the provided
relations.
If no relation_list
argument is provided, the constructor will
create a relation list with 1 relation, using the provided variables
to initialize that relation.
See RelationList.identity()
for creating a relation list containing an
identity relation.
Example:
Create relation list using specific variables
rel_list = RelationList(['X0', 'X1', 'X2'])
# Generates a list with 1 relation:
#
# 1: X0 | +o +o +o
# X1 | +o +o +o
# X2 | +o +o +o
Create relation list by providing relations
rel_list = RelationList(relation_list = [Relation(['X0', 'X1']),
Relation(['X0'])])
# 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:
#
# 1: ε
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
|
Source code in pymwp/relation_list.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
composition(other)
¶
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 |
Source code in pymwp/relation_list.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
contains_matrix(search_in, matrix)
staticmethod
¶
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
|
|
Source code in pymwp/relation_list.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|
fixpoint()
¶
Apply fixpoint to all relations in relation list.
Source code in pymwp/relation_list.py
205 206 207 208 |
|
identity(variables)
staticmethod
¶
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:
#
# 1: X0 | +m +o +o
# X1 | +o +m +o
# X2 | +o +o +m
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variables |
List[str]
|
list of variables |
required |
Returns:
Type | Description |
---|---|
RelationList
|
RelationList that contains identity relation generated using the provided variables. |
Source code in pymwp/relation_list.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
one_composition(relation)
¶
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 |
Source code in pymwp/relation_list.py
193 194 195 196 197 198 199 200 201 202 203 |
|
replace_column(vector, variable)
¶
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. |
Source code in pymwp/relation_list.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
show()
¶
Display relation list.
Source code in pymwp/relation_list.py
210 211 212 |
|
while_correction(dg)
¶
Apply while_correction()
to all relations in a relation list.
Source code in pymwp/relation_list.py
214 215 216 217 218 |
|