@@ -196,23 +196,23 @@ key.
196
196
We consider the smallest poset describing a class hierarchy admitting
197
197
no MRO whatsoever::
198
198
199
- sage: P = Poset({10: [9,8,7], 9: [6,1], 8: [5,2], 7: [4,3], # needs sage.combinat sage. graphs
199
+ sage: P = Poset({10: [9,8,7], 9: [6,1], 8: [5,2], 7: [4,3], # needs sage.graphs
200
200
....: 6: [3,2], 5: [3,1], 4: [2,1]},
201
201
....: linear_extension=True, facade=True)
202
202
203
203
And build a :class:`HierarchyElement` from it::
204
204
205
205
sage: from sage.misc.c3_controlled import HierarchyElement
206
- sage: x = HierarchyElement(10, P) # needs sage.combinat sage. graphs
206
+ sage: x = HierarchyElement(10, P) # needs sage.graphs
207
207
208
208
Here are its bases::
209
209
210
- sage: HierarchyElement(10, P)._bases # needs sage.combinat sage. graphs
210
+ sage: HierarchyElement(10, P)._bases # needs sage.graphs
211
211
[9, 8, 7]
212
212
213
213
Using the standard ``C3`` algorithm fails::
214
214
215
- sage: x.mro_standard # needs sage.combinat sage. graphs
215
+ sage: x.mro_standard # needs sage.graphs
216
216
Traceback (most recent call last):
217
217
...
218
218
ValueError: Cannot merge the items 3, 3, 2.
@@ -222,13 +222,13 @@ extension. For easy relabelling, we first need to set an appropriate
222
222
default linear extension for `P`::
223
223
224
224
sage: linear_extension = list(reversed(IntegerRange(1, 11)))
225
- sage: P = P.with_linear_extension(linear_extension) # needs sage.combinat sage. graphs
226
- sage: list(P) # needs sage.combinat sage. graphs
225
+ sage: P = P.with_linear_extension(linear_extension) # needs sage.graphs
226
+ sage: list(P) # needs sage.graphs
227
227
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
228
228
229
229
Now we play with a specific linear extension of `P`::
230
230
231
- sage: # needs sage.combinat sage. graphs
231
+ sage: # needs sage.graphs
232
232
sage: Q = P.linear_extension([10, 9, 8, 7, 6, 5, 4, 1, 2, 3]).to_poset()
233
233
sage: Q.cover_relations()
234
234
[[10, 9], [10, 8], [10, 7], [9, 6], [9, 3], [8, 5], [8, 2], [7, 4],
@@ -242,43 +242,43 @@ Now we play with a specific linear extension of `P`::
242
242
On the other hand, both the instrumented ``C3`` algorithm, and the
243
243
controlled ``C3`` algorithm give the desired MRO::
244
244
245
- sage: x.mro # needs sage.combinat sage. graphs
245
+ sage: x.mro # needs sage.graphs
246
246
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
247
- sage: x.mro_controlled # needs sage.combinat sage. graphs
247
+ sage: x.mro_controlled # needs sage.graphs
248
248
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
249
249
250
250
The above checks, and more, can be run with::
251
251
252
- sage: x._test_mro() # needs sage.combinat sage. graphs
252
+ sage: x._test_mro() # needs sage.graphs
253
253
254
254
In practice, the control was achieved by adding the following bases::
255
255
256
- sage: x._bases # needs sage.combinat sage. graphs
256
+ sage: x._bases # needs sage.graphs
257
257
[9, 8, 7]
258
- sage: x._bases_controlled # needs sage.combinat sage. graphs
258
+ sage: x._bases_controlled # needs sage.graphs
259
259
[9, 8, 7, 6, 5]
260
260
261
261
Altogether, four bases were added for control::
262
262
263
- sage: sum(len(HierarchyElement(q, Q)._bases) for q in Q) # needs sage.combinat sage. graphs
263
+ sage: sum(len(HierarchyElement(q, Q)._bases) for q in Q) # needs sage.graphs
264
264
15
265
- sage: sum(len(HierarchyElement(q, Q)._bases_controlled) for q in Q) # needs sage.combinat sage. graphs
265
+ sage: sum(len(HierarchyElement(q, Q)._bases_controlled) for q in Q) # needs sage.graphs
266
266
19
267
267
268
268
This information can also be recovered with::
269
269
270
- sage: x.all_bases_len() # needs sage.combinat sage. graphs
270
+ sage: x.all_bases_len() # needs sage.graphs
271
271
15
272
- sage: x.all_bases_controlled_len() # needs sage.combinat sage. graphs
272
+ sage: x.all_bases_controlled_len() # needs sage.graphs
273
273
19
274
274
275
275
We now check that the ``C3`` algorithm fails for all linear extensions
276
276
`l` of this poset, whereas both the instrumented and controlled ``C3``
277
277
algorithms succeed; along the way, we collect some statistics::
278
278
279
- sage: L = P.linear_extensions() # needs sage.combinat sage. graphs
279
+ sage: L = P.linear_extensions() # needs sage.graphs
280
280
sage: stats = []
281
- sage: for l in L: # needs sage.combinat sage. graphs sage.modules sage.ring.finite_rings
281
+ sage: for l in L: # needs sage.graphs sage.modules
282
282
....: x = HierarchyElement(10, l.to_poset())
283
283
....: try: # Check that x.mro_standard always fails with a ValueError
284
284
....: x.mro_standard
@@ -295,7 +295,7 @@ Depending on the linear extension `l` it was necessary to add between
295
295
one and five bases for control; for example, `216` linear extensions
296
296
required the addition of four bases::
297
297
298
- sage: sorted(Word(stats).evaluation_sparse()) # needs sage.combinat sage. graphs sage.modules sage.ring.finite_rings
298
+ sage: sorted(Word(stats).evaluation_sparse()) # needs sage.graphs sage.modules
299
299
[(1, 36), (2, 108), (3, 180), (4, 216), (5, 180)]
300
300
301
301
We now consider a hierarchy of categories::
@@ -1118,9 +1118,9 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass):
1118
1118
The ``_from_value`` attribute is a function that can be used
1119
1119
to reconstruct an element of the hierarchy from its value::
1120
1120
1121
- sage: x._from_value # needs sage.combinat sage. graphs
1121
+ sage: x._from_value # needs sage.graphs
1122
1122
Cached version of <cyfunction HierarchyElement.__classcall__.<locals>.f at ...>
1123
- sage: x._from_value(x.value) is x # needs sage.combinat sage. graphs
1123
+ sage: x._from_value(x.value) is x # needs sage.graphs
1124
1124
True
1125
1125
"""
1126
1126
self .value = value
@@ -1135,9 +1135,9 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass):
1135
1135
EXAMPLES::
1136
1136
1137
1137
sage: from sage.misc.c3_controlled import HierarchyElement
1138
- sage: P = Poset((divisors(30), lambda x, y: y.divides(x)), facade=True) # needs sage.combinat sage. graphs
1139
- sage: x = HierarchyElement(10, P) # needs sage.combinat sage. graphs
1140
- sage: x # needs sage.combinat sage. graphs
1138
+ sage: P = Poset((divisors(30), lambda x, y: y.divides(x)), facade=True) # needs sage.graphs
1139
+ sage: x = HierarchyElement(10, P) # needs sage.graphs
1140
+ sage: x # needs sage.graphs
1141
1141
10
1142
1142
"""
1143
1143
return repr (self .value)
@@ -1175,7 +1175,7 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass):
1175
1175
1176
1176
EXAMPLES::
1177
1177
1178
- sage: # needs sage.combinat sage. graphs
1178
+ sage: # needs sage.graphs
1179
1179
sage: from sage.misc.c3_controlled import HierarchyElement, C3_sorted_merge, identity
1180
1180
sage: P = Poset({7: [5, 6], 5: [1, 2], 6: [3, 4]}, facade=True)
1181
1181
sage: x = HierarchyElement(5, P)
@@ -1188,12 +1188,12 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass):
1188
1188
sage: x.mro
1189
1189
[7, 6, 5, 4, 3, 2, 1]
1190
1190
1191
- sage: C3_sorted_merge([[6, 4, 3], [5, 2, 1], [6, 5]], identity) # needs sage.combinat sage. graphs
1191
+ sage: C3_sorted_merge([[6, 4, 3], [5, 2, 1], [6, 5]], identity) # needs sage.graphs
1192
1192
([6, 5, 4, 3, 2, 1], [6, 5, 4])
1193
1193
1194
1194
TESTS::
1195
1195
1196
- sage: assert all(isinstance(v, Integer) for v in x.mro) # needs sage.combinat sage. graphs
1196
+ sage: assert all(isinstance(v, Integer) for v in x.mro) # needs sage.graphs
1197
1197
"""
1198
1198
bases = self ._bases
1199
1199
result, suggestion = C3_sorted_merge([base.mro for base in bases]+ [[base.value for base in bases]], key = self ._key)
@@ -1212,7 +1212,7 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass):
1212
1212
1213
1213
EXAMPLES::
1214
1214
1215
- sage: # needs sage.combinat sage. graphs
1215
+ sage: # needs sage.graphs
1216
1216
sage: from sage.misc.c3_controlled import HierarchyElement
1217
1217
sage: P = Poset({7: [5, 6], 5: [1, 2], 6: [3, 4]}, facade=True)
1218
1218
sage: x = HierarchyElement(7, P)
@@ -1232,22 +1232,25 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass):
1232
1232
EXAMPLES::
1233
1233
1234
1234
sage: from sage.misc.c3_controlled import HierarchyElement, C3_merge
1235
- sage: P = Poset({7: [5, 6], 5: [1, 2], 6: [3, 4]}, facade=True) # needs sage.combinat sage.graphs
1236
- sage: x = HierarchyElement(5, P) # needs sage.combinat sage.graphs
1237
- sage: x.mro_standard # needs sage.combinat sage.graphs
1235
+
1236
+ sage: # needs sage.graphs
1237
+ sage: P = Poset({7: [5, 6], 5: [1, 2], 6: [3, 4]}, facade=True)
1238
+ sage: x = HierarchyElement(5, P)
1239
+ sage: x.mro_standard
1238
1240
[5, 2, 1]
1239
- sage: x = HierarchyElement(6, P) # needs sage.combinat sage.graphs
1240
- sage: x.mro_standard # needs sage.combinat sage.graphs
1241
+ sage: x = HierarchyElement(6, P)
1242
+ sage: x.mro_standard
1241
1243
[6, 4, 3]
1242
- sage: x = HierarchyElement(7, P) # needs sage.combinat sage.graphs
1243
- sage: x.mro_standard # needs sage.combinat sage.graphs
1244
+ sage: x = HierarchyElement(7, P)
1245
+ sage: x.mro_standard
1244
1246
[7, 6, 4, 3, 5, 2, 1]
1247
+
1245
1248
sage: C3_merge([[6, 4, 3], [5, 2, 1], [6, 5]])
1246
1249
[6, 4, 3, 5, 2, 1]
1247
1250
1248
1251
TESTS::
1249
1252
1250
- sage: assert all(isinstance(v, Integer) for v in x.mro_standard) # needs sage.combinat sage. graphs
1253
+ sage: assert all(isinstance(v, Integer) for v in x.mro_standard) # needs sage.graphs
1251
1254
"""
1252
1255
bases = self ._bases
1253
1256
return [self .value] + C3_merge([base.mro_standard for base in bases]+ [[base.value for base in bases]])
@@ -1261,28 +1264,31 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass):
1261
1264
EXAMPLES::
1262
1265
1263
1266
sage: from sage.misc.c3_controlled import HierarchyElement, C3_merge
1264
- sage: P = Poset({7: [5, 6], 5: [1, 2], 6: [3, 4]}, facade=True) # needs sage.combinat sage.graphs
1265
- sage: x = HierarchyElement(5, P) # needs sage.combinat sage.graphs
1266
- sage: x.mro_controlled # needs sage.combinat sage.graphs
1267
+
1268
+ sage: # needs sage.graphs
1269
+ sage: P = Poset({7: [5, 6], 5: [1, 2], 6: [3, 4]}, facade=True)
1270
+ sage: x = HierarchyElement(5, P)
1271
+ sage: x.mro_controlled
1267
1272
[5, 2, 1]
1268
- sage: x = HierarchyElement(6, P) # needs sage.combinat sage.graphs
1269
- sage: x.mro_controlled # needs sage.combinat sage.graphs
1273
+ sage: x = HierarchyElement(6, P)
1274
+ sage: x.mro_controlled
1270
1275
[6, 4, 3]
1271
- sage: x = HierarchyElement(7, P) # needs sage.combinat sage.graphs
1272
- sage: x.mro_controlled # needs sage.combinat sage.graphs
1276
+ sage: x = HierarchyElement(7, P)
1277
+ sage: x.mro_controlled
1273
1278
[7, 6, 5, 4, 3, 2, 1]
1274
- sage: x._bases # needs sage.combinat sage.graphs
1279
+ sage: x._bases
1275
1280
[6, 5]
1276
- sage: x._bases_controlled # needs sage.combinat sage.graphs
1281
+ sage: x._bases_controlled
1277
1282
[6, 5, 4]
1283
+
1278
1284
sage: C3_merge([[6, 4, 3], [5, 2, 1], [6, 5]])
1279
1285
[6, 4, 3, 5, 2, 1]
1280
1286
sage: C3_merge([[6, 4, 3], [5, 2, 1], [6, 5, 4]])
1281
1287
[6, 5, 4, 3, 2, 1]
1282
1288
1283
1289
TESTS::
1284
1290
1285
- sage: assert all(isinstance(v, Integer) for v in x.mro_controlled) # needs sage.combinat sage. graphs
1291
+ sage: assert all(isinstance(v, Integer) for v in x.mro_controlled) # needs sage.graphs
1286
1292
"""
1287
1293
return [self .value] + C3_merge([base.mro_controlled for base in self ._bases]+ [self ._bases_controlled])
1288
1294
@@ -1304,9 +1310,9 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass):
1304
1310
EXAMPLES::
1305
1311
1306
1312
sage: from sage. misc. c3_controlled import HierarchyElement
1307
- sage: P = Poset( {7: [5, 6 ], 5: [1, 2 ], 6: [3, 4 ]}, facade=True) # needs sage. combinat sage . graphs
1308
- sage: x = HierarchyElement( 7, P) # needs sage. combinat sage . graphs
1309
- sage: x. _test_mro( ) # needs sage. combinat sage . graphs
1313
+ sage: P = Poset( {7: [5, 6 ], 5: [1, 2 ], 6: [3, 4 ]}, facade=True) # needs sage. graphs
1314
+ sage: x = HierarchyElement( 7, P) # needs sage. graphs
1315
+ sage: x. _test_mro( ) # needs sage. graphs
1310
1316
"""
1311
1317
for b in self ._bases:
1312
1318
b._test_mro()
@@ -1328,7 +1334,7 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass):
1328
1334
1329
1335
EXAMPLES::
1330
1336
1331
- sage: # needs sage.combinat sage. graphs
1337
+ sage: # needs sage.graphs
1332
1338
sage: from sage.misc.c3_controlled import HierarchyElement
1333
1339
sage: P = Poset((divisors(30), lambda x, y: y.divides(x)), facade=True)
1334
1340
sage: x = HierarchyElement(1, P)
@@ -1356,7 +1362,7 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass):
1356
1362
1357
1363
EXAMPLES::
1358
1364
1359
- sage: # needs sage.combinat sage. graphs
1365
+ sage: # needs sage.graphs
1360
1366
sage: from sage.misc.c3_controlled import HierarchyElement
1361
1367
sage: P = Poset((divisors(30), lambda x, y: y.divides(x)), facade=True)
1362
1368
sage: HierarchyElement(1, P).all_bases()
@@ -1375,8 +1381,8 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass):
1375
1381
EXAMPLES::
1376
1382
1377
1383
sage: from sage.misc.c3_controlled import HierarchyElement
1378
- sage: P = Poset((divisors(30), lambda x, y: y.divides(x)), facade=True) # needs sage.combinat sage. graphs
1379
- sage: HierarchyElement(30, P).all_bases_len() # needs sage.combinat sage. graphs
1384
+ sage: P = Poset((divisors(30), lambda x, y: y.divides(x)), facade=True) # needs sage.graphs
1385
+ sage: HierarchyElement(30, P).all_bases_len() # needs sage.graphs
1380
1386
12
1381
1387
"""
1382
1388
return sum ( len (x._bases) for x in self .all_bases())
@@ -1388,8 +1394,8 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass):
1388
1394
EXAMPLES::
1389
1395
1390
1396
sage: from sage.misc.c3_controlled import HierarchyElement
1391
- sage: P = Poset((divisors(30), lambda x, y: y.divides(x)), facade=True) # needs sage.combinat sage. graphs
1392
- sage: HierarchyElement(30, P).all_bases_controlled_len() # needs sage.combinat sage. graphs
1397
+ sage: P = Poset((divisors(30), lambda x, y: y.divides(x)), facade=True) # needs sage.graphs
1398
+ sage: HierarchyElement(30, P).all_bases_controlled_len() # needs sage.graphs
1393
1399
13
1394
1400
"""
1395
1401
return sum ( len (x._bases_controlled) for x in self .all_bases())
0 commit comments