monomial.py¶
from pymwp import Monomial
DELTA = Tuple[int, int]
module-attribute
¶
delta type is tuple of two int values.
Monomial
¶
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.
Source code in pymwp/monomial.py
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 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
|
__init__(scalar=UNIT_MWP, deltas=None, *args)
¶
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]]
|
list of deltas - either a syntactic list, or sequence of tuples that represent deltas. |
None
|
Source code in pymwp/monomial.py
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 |
|
choice_scalar(*choices)
¶
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. |
Source code in pymwp/monomial.py
170 171 172 173 174 175 176 177 178 179 180 181 182 |
|
contains(m)
¶
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 |
bool
|
True otherwise |
Source code in pymwp/monomial.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
copy()
¶
Make a deep copy of a monomial.
Source code in pymwp/monomial.py
184 185 186 |
|
inclusion(monomial)
¶
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 |
SetInclusion
|
INCLUDED if self is included in monomial |
SetInclusion
|
EMPTY none of them |
Source code in pymwp/monomial.py
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 |
|
insert_delta(sorted_deltas, 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. |
Source code in pymwp/monomial.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
|
insert_deltas(monomial, deltas)
staticmethod
¶
Insert new deltas into monomial list of deltas.
Arguments:
monomial: the monomial into whose list of
deltas values will be inserted
deltas: list of deltas to insert into monomial
Source code in pymwp/monomial.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
|
prod(monomial)
¶
prod operation combines two monomials where one is this monomial (self) and the second is provided as 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 |
Source code in pymwp/monomial.py
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 |
|
show()
¶
Display scalar and the list of deltas.
Source code in pymwp/monomial.py
188 189 190 |
|
to_dict()
¶
Get dictionary representation of a monomial.
Source code in pymwp/monomial.py
192 193 194 195 196 197 |
|