-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminrv1.py
2232 lines (1781 loc) · 74.8 KB
/
minrv1.py
1
2
3
4
5
6
7
8
9
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
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Proof-of-concept of minimal resolutions over the Steenrod Algebra.
# Copyright (c) 2024 Andrés Morán
# Licensed under the terms of the MIT License (see ./LICENSE).
# TODO: improve notation
# TODO: improve performance: remove SageMath dependencies
import _pickle as cPickle
import os
import sys # ~unused, sys.maxsize
import time
# from sage.all import * # WARNING (BAD PERFORMANCE)
from sage.rings.finite_rings.finite_field_constructor import (
GF,
) # WARNING (BAD PERFORMANCE)
# WARNING (BAD PERFORMANCE)
from sage.matrix.constructor import matrix as Matrix
from sage.algebras.steenrod.steenrod_algebra import (
SteenrodAlgebra,
) # WARNING (BAD PERFORMANCE)
import plotly.graph_objects as go
import jsons
import multiprocessing
from functools import cache
# Global parameters
BOOL_COMPUTE_ONLY_ADDITIVE_STRUCTURE = False
FIXED_PRIME_NUMBER = 2
MAX_NUMBER_OF_RELATIVE_DEGREES = 30 # 100 ## 130
MAX_NUMBER_OF_MODULES = MAX_NUMBER_OF_RELATIVE_DEGREES
NUMBER_OF_THREADS = 5 # 40 # 100
DEFAULT_YONEDA_PRODUCT_MAX_DEG = 20 # DEPRECATED. TODO: remove from src
UI_SHIFT_MULTIPLE_GENERATORS = 0.1
# UTILS
def DBG(*var):
print("-" * 120)
print(f"{var=}")
print("-" * 120)
def printl(list):
for item in list:
print(item)
def print_banner():
print_header(
"[[ MinimalResolution v1 - [email protected] ]]", "#", True)
def print_header(str_txt, char_delim, bool_print_lateral):
number_of_characters = 120
padding_length = (number_of_characters - len(str_txt)) // 2 - 1
padding_tweak = (number_of_characters - len(str_txt)) % 2
print(char_delim * number_of_characters)
char_delim_lateral = char_delim
if not bool_print_lateral:
char_delim_lateral = " "
print(
char_delim_lateral
+ " " * padding_length
+ str_txt
+ " " * (padding_length + padding_tweak)
+ char_delim_lateral
)
print(char_delim * number_of_characters)
def log(str_event):
str_log_file = "log.txt"
with open(str_log_file, "a") as file_log:
file_log.write(f"{str_event}\n")
def dump_object(obj, str_name):
str_save_path = f"minimal_resolution_{str_name}.obj"
if not os.path.exists(str_save_path):
with open(str_save_path, "wb") as file_minimalresolution:
cPickle.dump(obj, file_minimalresolution)
print("#" * 120)
print(f"[*] Minimal resolution object dumped to ./{str_save_path}.")
print("#" * 120)
def load_object(str_name):
str_loaded_path = f"minimal_resolution_{str_name}.obj"
if os.path.exists(str_loaded_path):
with open(str_loaded_path, "rb") as file_minimalresolution:
r = cPickle.load(file_minimalresolution)
print("#" * 120)
print(
f"[*] Minimal resolution object loaded from ./{str_loaded_path}.")
print("#" * 120)
else:
r = False
return r
@cache
def factorial(n):
r = 1
if n > 1:
for i in range(2, n + 1):
r = r * i
else:
r = 1
return r
@cache
def bin_coeff(n, k):
if (n, k) == (0, 0):
return 1
if k > n:
return 0
if k < 0:
return 0
return factorial(n) // (factorial(k) * factorial(n - k))
# CLASSES
class FPModule:
def __init__(self, str_name, callback_generators, callback_relations, max_deg):
self.str_name = str_name
self.callback_generators = lambda x, y: callback_generators(
x, y, max_deg)
self.callback_relations = lambda x, y: callback_relations(
x, y, max_deg)
class FPMap:
def __init__(
self,
list_domain_generators,
list_list_images,
list_tuple_domain,
list_tuple_codomain,
): # ordered
self.list_domain_generators = list_domain_generators
self.list_list_images = list_list_images
self.list_tuple_domain = list_tuple_domain
self.list_tuple_codomain = list_tuple_codomain
def eval(self, linear_comb):
output_linear_comb = []
for summand in linear_comb:
for i in range(0, len(self.list_domain_generators)):
if summand.generator == self.list_domain_generators[i].generator:
for element_img in self.list_list_images[i]:
output_linear_comb.append(
Element(
summand.cohomology_operation
* element_img.cohomology_operation,
element_img.generator,
)
)
return output_linear_comb
def __repr__(self):
return f"{self.list_domain_generators} -> {self.list_list_images}"
def __str__(self):
return f"{self.list_domain_generators} -> {self.list_list_images}"
class YonedaProduct:
def __init__(
self, external_generator, internal_generator, linear_comb_output_generators
):
self.external_generator = external_generator
self.internal_generator = internal_generator
self.linear_comb_output_generators = linear_comb_output_generators
def __str__(self):
return self.__repr__()
def __repr__(self):
return f"({self.external_generator})*({self.internal_generator}) == ({self.linear_comb_output_generators})"
class GradedMorphism:
def __init__(self, list_morphisms):
self.list_morphisms = list_morphisms
def get_morphism_from_bigraded_domain(self, tuple_dom):
for morphism in self.list_morphisms:
if morphism.tuple_dom == tuple_dom:
return morphism
return -1
def eval_linear_comb(self, list_list_linear_comb, tuple_dom):
morphism = self.get_morphism_from_bigraded_domain(tuple_dom)
if morphism == -1:
return -1
return [morphism.eval_linear_comb(list_list_linear_comb), morphism.tuple_cod]
def eval_element(self, element, tuple_dom):
morphism = self.get_morphism_from_bigraded_domain(tuple_dom)
if morphism == -1:
return -1
return [morphism.eval_element(element), morphism.tuple_cod]
def eval_vector(self, list_vector, tuple_dom):
morphism = self.get_morphism_from_bigraded_domain(tuple_dom)
if morphism == -1:
return [[], -1]
return [morphism.eval_vector(list_vector), morphism.tuple_cod]
def __repr__(self):
s = ""
for morphism in self.list_morphisms:
s += str(morphism) + "\n"
return s
def __str__(self):
s = ""
for morphism in self.list_morphisms:
s += str(morphism) + "\n"
return s
class AlgebraGeneratorRelation:
def __init__(self, module_element, steenrod_operation, list_sum_output):
self.module_element = module_element
self.steenrod_operation = steenrod_operation
self.list_sum_output = list_sum_output
def __eq__(self, other):
return (
self.module_element == other.module_element
and self.steenrod_operation == other.steenrod_operation
and self.list_sum_output == other.list_sum_output
)
def __repr__(self):
return f"{self.steenrod_operation} (({self.module_element})) = {self.list_sum_output}"
def __str__(self):
return f"{self.steenrod_operation} (({self.module_element})) = {self.list_sum_output}"
class ExtendedAlgebraGenerator: # TODO: merge
def __init__(self, module_index, deg, index, bool_is_free, str_alias):
self.module_index = module_index
self.deg = deg
self.index = index
self.bool_is_free = bool_is_free
self.str_alias = str_alias
def __eq__(self, other):
return (
self.module_index == other.module_index
and self.deg == other.deg
and self.index == other.index
)
def __repr__(self):
return f"{self.module_index}, {self.deg}, {self.index};; is_free: {self.bool_is_free}\t @ str_alias: {self.str_alias}"
def __str__(self):
return f"{self.module_index}, {self.deg}, {self.index};; is_free: {self.bool_is_free}\t@ str_alias: {self.str_alias}"
class AlgebraGenerator: # TODO: merge
def __init__(self, module_index, deg, index):
self.module_index = module_index
self.deg = deg
self.index = index
def __eq__(self, other):
return (
self.module_index == other.module_index
and self.deg == other.deg
and self.index == other.index
)
def __repr__(self):
return f"{self.module_index}, {self.deg}, {self.index}"
def __str__(self):
return f"{self.module_index}, {self.deg}, {self.index}"
def __hash__(self):
return hash(str(self))
class Element:
def __init__(self, cohomology_operation, generator):
self.cohomology_operation = cohomology_operation
self.generator = generator
def deg(self):
if self.cohomology_operation == 0:
return -1
return self.cohomology_operation.degree() + self.generator.deg
def __eq__(self, other):
if (
not self.cohomology_operation.is_zero()
and not other.cohomology_operation.is_zero()
):
if (
self.cohomology_operation.degree() == 0
and other.cohomology_operation.degree() == 0
):
if self.generator == other.generator:
if (
self.cohomology_operation.leading_coefficient()
== other.cohomology_operation.leading_coefficient()
):
return True
return (
self.cohomology_operation == other.cohomology_operation
and self.generator == other.generator
)
def __str__(self):
return f"{self.cohomology_operation}; {self.generator}"
def __repr__(self):
return f"{self.cohomology_operation}; {self.generator}"
def __add__(self, other):
if self.generator == other.generator:
return Element(
self.cohomology_operation + other.cohomology_operation, self.generator
)
else:
return [self.cohomology_operation, other.cohomology_operation]
def __hash__(self):
return hash(str(self))
def encode(self):
return self.__dict__
class MTEntry:
def __init__(self, src, list_dst):
self.src = src
self.list_dst = list_dst
def __repr__(self):
return f"src: {self.src}, dst: {self.list_dst}"
class Morphism:
def __init__(
self,
fixed_prime,
list_dom_basis,
list_cod_basis,
list_list_images,
tuple_dom=(-1, -1),
tuple_cod=(-1, -1),
):
self.list_dom_basis = self.sanitizeRedundant(list_dom_basis)
self.list_cod_basis = self.sanitizeRedundant(list_cod_basis)
self.list_list_images = list_list_images
self.fixed_prime = fixed_prime
self.matrix = Matrix(
GF(fixed_prime),
self.getListListMatrix(
list_dom_basis, list_cod_basis, list_list_images),
sparse=True,
)
self.tuple_dom = tuple_dom
self.tuple_cod = tuple_cod
def eval_element(self, element):
return self.eval_vector(self.domainLinearCombToVector([[element]]))
def eval_vector(self, list_vector):
return self.matrix * Matrix(GF(self.fixed_prime), list_vector, sparse=True)
def eval_linear_comb(self, list_list_linear_comb): # TODO:unimplemented
element_as_vector = self.convertElementToVector(
[list_list_linear_comb], self.list_dom_basis
)
return self.matrix * Matrix(
GF(self.fixed_prime), element_as_vector, sparse=True
)
def convertLinearCombToVector(self, list_list_linear_comb, list_basis):
return self.getListListMatrix([0], list_basis, list_list_linear_comb)[0]
def domainLinearCombToVector(self, list_list_linear_comb):
return self.getListListMatrix([0], self.list_dom_basis, list_list_linear_comb)
def codomainLinearCombToVector(self, list_list_linear_comb):
return self.getListListMatrix([0], self.list_cod_basis, list_list_linear_comb)[
0
]
def __repr__(self):
str_matrix = str(self.matrix)
return f"{[self.tuple_dom, self.tuple_cod]} MATRIX: \n{str_matrix}\n"
def sanitizeRedundant(self, list_basis):
return [
element for element in list_basis if not element.cohomology_operation == 0
]
def getListListMatrix(self, list_dom_basis, list_cod_basis, list_list_images):
dim_cod = len(list_cod_basis)
dim_dom = len(list_dom_basis) # = len(list_list_images)
list_list_matrix = [[0] * max(1, dim_dom)
for k in range(0, max(1, dim_cod))]
for i in range(0, dim_dom):
for j in range(0, dim_cod):
cod_basis_trailing_support = list_cod_basis[
j
].cohomology_operation.trailing_support()
cod_basis_leading_coeff = list_cod_basis[
j
].cohomology_operation.leading_coefficient()
for k in range(0, len(list_list_images[i])):
image_cohomology_operation = list_list_images[i][
k
].cohomology_operation
dict_image_cohomology_operation_support = (
image_cohomology_operation.support()._mapping
)
list_keys_dict_image_cohomology_operation_support = list(
dict_image_cohomology_operation_support.keys()
)
for monomial_index in range(
0, len(list_keys_dict_image_cohomology_operation_support)
):
monomial_support = (
list_keys_dict_image_cohomology_operation_support[
monomial_index
]
)
monomial_coefficient = dict_image_cohomology_operation_support[
monomial_support
]
if (
list_list_images[i][k].generator
== list_cod_basis[j].generator
):
bool_monomial_patch = False
if monomial_support in [
tuple([]),
(0,),
] and cod_basis_trailing_support in [tuple([]), (0,)]:
bool_monomial_patch = True
if (
monomial_support == cod_basis_trailing_support
or bool_monomial_patch
):
list_list_matrix[j][i] += (
monomial_coefficient / cod_basis_leading_coeff
) # 1, ..., p-1
return list_list_matrix
def convertKernelBasisToListOfVectors(
self, sage_matrix_kernel_basis
): # TODO: possible bottleneck (SageMath routines...)
list_kernel_generators = []
if len(self.list_dom_basis) > 0:
list_kernel_raw = list(sage_matrix_kernel_basis)
for list_basis_linear_comb in list_kernel_raw:
list_kernel_img_fixed_element = []
for i in range(0, len(list_basis_linear_comb)):
if not list_basis_linear_comb[i] == 0:
list_kernel_img_fixed_element.append(
Element(
list_basis_linear_comb[i]
* self.list_dom_basis[i].cohomology_operation,
self.list_dom_basis[i].generator,
)
)
list_kernel_generators.append(list_kernel_img_fixed_element)
return list_kernel_generators
def getKernelAsVect(self):
return self.convertKernelBasisToListOfVectors(
self.matrix.right_kernel().basis()
)
def convertDomVectorToLinearComb(self, list_list_matrix_vector):
list_output_linear_cl = []
if len(self.list_dom_basis) == 0:
return -1
for i in range(0, len(list(list_list_matrix_vector))):
entry = list_list_matrix_vector[i][0]
list_output_linear_cl.append(
Element(
entry * self.list_dom_basis[i].cohomology_operation,
self.list_dom_basis[i].generator,
)
)
return list_output_linear_cl
class MinimalResolution:
def __init__(
self, str_name, fixed_prime, number_of_modules, number_of_relative_degrees
):
self.str_name = str_name
self.fixed_prime = fixed_prime
self.number_of_modules = number_of_modules
self.number_of_relative_degrees = number_of_relative_degrees
self.A = SteenrodAlgebra(fixed_prime, basis="adem")
self.A_unit = self.A.monomial((0,))
self.list_list_mapping_table = []
self.list_list_found_generators = []
self.list_differentials = []
self.differential = 0
self.list_list_expanded_minimal_resolution = []
# Finitely presented module
self.list_module_to_resolve_relations = []
self.list_module_to_resolve_ev_gen = []
# Yoneda/Massey products
self.list_lifted_maps = [] # [[params, morph], ...]
self.list_lift_processes = []
self.number_of_threads = NUMBER_OF_THREADS
self.list_processes = []
self.list_yoneda_products = [] # [ YonedaProduct, ... ]
self.list_e_2_massey_products = [] # [ MasseyProduct, ... ], under construction
def createModule(self, fp_module):
list_mapping_table = []
list_found_generators = []
self.list_module_to_resolve_ev_gen = fp_module.callback_generators(
self.A, self.fixed_prime
)
for ev_module_generator in self.list_module_to_resolve_ev_gen:
if ev_module_generator.generator.bool_is_free:
lifted_generator_info = ExtendedAlgebraGenerator(
0,
ev_module_generator.generator.deg,
ev_module_generator.generator.index,
ev_module_generator.generator.bool_is_free,
ev_module_generator.generator.str_alias,
)
lift_ev_module_free_generator = Element(
self.A_unit, lifted_generator_info
)
list_found_generators.append(
lift_ev_module_free_generator.generator
) # we don't need the extra structure for generators
list_mapping_table.append(
MTEntry(lift_ev_module_free_generator,
[ev_module_generator])
)
self.list_list_mapping_table.append(list_mapping_table)
self.list_list_found_generators.append(list_found_generators)
print_header(
f"Table of generators ({self.str_name}) [JSON]", "=", False)
list_json_generators = [
f'\t"{generator_element.generator.str_alias.replace("\\", "\\\\").replace(" ", "_")}": {
generator_element.generator.deg}'
for generator_element in self.list_module_to_resolve_ev_gen
]
print("{\n" + ",\n".join(list_json_generators) + "\n}")
self.list_module_to_resolve_relations = fp_module.callback_relations(
self.A, self.fixed_prime
)
print_header(
f"Table of relations ({self.str_name}) [JSON]", "=", False)
if len(self.list_module_to_resolve_relations) == 0:
print("(There are no extra relations)")
print()
for relation in self.list_module_to_resolve_relations:
bool_found = False
for element_generator in self.list_module_to_resolve_ev_gen:
if element_generator.generator == relation.list_sum_output[0].generator:
bool_found = True
if bool_found:
print(
f'"{str(relation.steenrod_operation).replace("^", "").replace("beta", "b")} {relation.module_element.generator.str_alias.replace(
"\\", "\\\\").replace(" ", "_")} = {relation.list_sum_output[0].generator.str_alias.replace("\\", "\\\\").replace(" ", "_")}",'
)
return
def split_support(self, support):
r = []
len_support = len(support)
support_prefix = (0,)
if self.fixed_prime == 2:
if len_support > 1:
r = [(support[0],), support[1:]]
elif len_support == 1:
r = [(0,), support]
else:
r = [(0,), (0,)]
else:
if len_support == 1:
r = [(0,), support]
elif len_support >= 2:
if support[-1] == 1: # bockstein morphism
r = [support[:-1] + (0,), (1,)]
else:
if len(support[:-2]) == 0:
support_prefix = (0,)
else:
support_prefix = support[:-2]
r = [support_prefix, (0,) + support[-2:]]
elif len_support == 0:
r = [support_prefix, support]
return r
def non_free_eval(self, list_elements): # TODO: BETA
r = []
for element in list_elements:
if element.cohomology_operation == 0:
r.append([element])
continue
element_r = [] # zero output value when there aren't more relations
# A = SteenrodAlgebra(p=3, basis='adem')
# (A.P(9)*A.P(1)*A.Q(0)).support() # right-to-left: 0 = Power. 1 = Bockstein.
# A.monomial( (A.Q(0)*A.P(1)*A.Q(0)).leading_support())
trailing_support = element.cohomology_operation.trailing_support()
coh_operation_coeff = (
element.cohomology_operation.trailing_coefficient()
)
list_splitted_support = self.split_support(trailing_support)
support_prefix = list_splitted_support[0]
support_coh_operation = list_splitted_support[1]
coh_operation = self.A.monomial(support_coh_operation)
if (
support_prefix == (0,)
and len(trailing_support) > 0
and not support_coh_operation == (0,)
): # and len(trailing_support) > 0
for relation in self.list_module_to_resolve_relations:
if (
relation.steenrod_operation == coh_operation
and relation.module_element.generator == element.generator
):
element_r += relation.list_sum_output
r.append(
[
Element(
coh_operation_coeff * element.cohomology_operation,
element.generator,
)
for element in self.sum(element_r)
]
)
elif not support_prefix == (0,):
coh_operation_prefix = coh_operation_coeff * self.A.monomial(
support_prefix
)
coh_operation_to_eval = self.A.monomial(support_coh_operation)
element_r = []
list_list_evals = self.non_free_eval(
[Element(coh_operation_to_eval, element.generator)]
)
for list_evals in list_list_evals:
element_r += self.non_free_eval(
[
Element(
coh_operation_prefix
* output_element.cohomology_operation,
output_element.generator,
)
for output_element in list_evals
]
)
for i in range(0, len(element_r)):
element_r[i] = self.sum(element_r[i])
r += element_r
else:
r.append([element])
return r
@cache
def getSteenrodAlgebraBasis(self, deg):
return self.A.basis(deg)
def getElementsByDeg(self, resolution_module_subindex, deg):
return self.getElementsByRelativeDeg(
resolution_module_subindex, deg - resolution_module_subindex
)
def getElementsByRelativeDeg(self, resolution_module_subindex, module_relative_deg):
list_found_elements = []
if resolution_module_subindex >= 0:
abs_deg = module_relative_deg + resolution_module_subindex
if len(self.list_list_found_generators) > resolution_module_subindex:
for found_generators in self.list_list_found_generators[
resolution_module_subindex
]:
if found_generators.deg <= abs_deg:
for found_element in self.getSteenrodAlgebraBasis(
abs_deg - found_generators.deg
):
list_found_elements.append(
Element(found_element, found_generators)
)
else:
for element in self.list_module_to_resolve_ev_gen:
if element.deg() == module_relative_deg:
list_found_elements.append(element)
return list_found_elements
def sum(self, list_elements):
list_elements_arranged = []
list_elements_added_generators = []
trivial_element = Element(
self.A_unit, AlgebraGenerator(-2, 0, 0)
) # change degree convention
for element_1 in list_elements:
element_added_partially = trivial_element
list_elements_last_checked_generator = trivial_element
if element_1.generator in list_elements_added_generators:
continue
for element_2 in list_elements:
if element_2.generator in list_elements_added_generators:
continue
if element_1 == element_2:
first_sum_element = element_1
list_elements_last_checked_generator = element_1.generator
if element_added_partially == trivial_element:
element_added_partially = first_sum_element # not unbound
else:
if element_added_partially.generator == element_2.generator:
element_added_partially += element_2
if element_added_partially == trivial_element:
continue
list_elements_arranged.append(element_added_partially)
list_elements_added_generators.append(
list_elements_last_checked_generator)
return list_elements_arranged
def eval(self, module_basis_element): # this method depends on the mapping table
list_img_elements = []
for list_mapping_table in self.list_list_mapping_table:
for mt_entry in list_mapping_table:
if mt_entry.src.generator == module_basis_element.generator:
parsed_list_dst = [
Element(
module_basis_element.cohomology_operation
* element_dst.cohomology_operation,
element_dst.generator,
)
for element_dst in mt_entry.list_dst
]
list_img_elements += parsed_list_dst
return self.sum(
list_img_elements
)
def raw_eval(
self, module_basis_element
): # this method depends on the mapping table
list_img_elements = []
for list_mapping_table in self.list_list_mapping_table:
for mt_entry in list_mapping_table:
if mt_entry.src == module_basis_element:
list_img_elements += mt_entry.list_dst
return self.sum(list_img_elements) # move src
def diff(self, resolution_module_subindex, module_relative_deg):
if resolution_module_subindex > 0:
list_list_images = [
self.eval(element)
for element in self.getElementsByRelativeDeg(
resolution_module_subindex, module_relative_deg
)
]
list_cod_basis = self.getElementsByRelativeDeg(
resolution_module_subindex - 1, module_relative_deg + 1
)
else:
list_raw_eval_images = [
self.eval(element)
for element in self.getElementsByRelativeDeg(
resolution_module_subindex, module_relative_deg
)
]
list_list_list_images = [
self.non_free_eval(raw_eval_image)
for raw_eval_image in list_raw_eval_images
]
list_list_images = []
for list_list_basis_img_substituted in list_list_list_images:
list_rearranged_sum = self.sum(
[
basis_img
for list_basis_img in list_list_basis_img_substituted
for basis_img in list_basis_img
]
)
list_list_images.append(list_rearranged_sum)
list_cod_basis = self.getElementsByRelativeDeg(
resolution_module_subindex - 1, module_relative_deg
) # absolute degree
list_dom_basis = self.getElementsByRelativeDeg(
resolution_module_subindex, module_relative_deg
)
d = Morphism(
self.fixed_prime,
list_dom_basis,
list_cod_basis,
list_list_images,
tuple_dom=(resolution_module_subindex, module_relative_deg),
tuple_cod=(
resolution_module_subindex - 1,
module_relative_deg + 1,
), # TODO: fix column notation
)
self.list_differentials.append(d)
list_d_kernel = d.getKernelAsVect()
dim_d_kernel = len(list_d_kernel)
if dim_d_kernel > 0 and len(list_dom_basis) > 0:
if (
len(
self.getElementsByRelativeDeg(
resolution_module_subindex + 1, module_relative_deg - 1
)
)
== 0
): # append a new A_p_module
if (
len(self.list_list_mapping_table) - 1
< resolution_module_subindex + 1
):
self.list_list_mapping_table.append([])
self.list_list_found_generators.append([])
list_quot_ker_img = list_d_kernel
dim_quot_ker_img = len(list_d_kernel)
else:
# Quotient with image
list_dom_higher_deg = self.getElementsByRelativeDeg(
resolution_module_subindex + 1, module_relative_deg - 1
)
list_list_images_higher_deg = [
self.eval(element) for element in list_dom_higher_deg
]
d_higher_degree = Morphism(
self.fixed_prime,
list_dom_higher_deg,
list_dom_basis,
list_list_images_higher_deg,
tuple_dom=(resolution_module_subindex +
1, module_relative_deg - 1),
tuple_cod=(resolution_module_subindex,
module_relative_deg),
)
if d_higher_degree.matrix.column_space().dimension() > 0:
quot_ker_img = d.matrix.right_kernel().quotient(
d_higher_degree.matrix.column_space()
)
else:
quot_ker_img = d.matrix.right_kernel()
list_quot_ker_img = list(
[
quot_ker_img.lift(item)
for item in quot_ker_img.basis()
if not item == 0
]
)
dim_quot_ker_img = len(list_quot_ker_img)
list_quot_ker_img = d.convertKernelBasisToListOfVectors(
list_quot_ker_img
)
for i in range(0, dim_quot_ker_img):
element_new_generator = Element(
self.A_unit,
AlgebraGenerator(
resolution_module_subindex + 1,
module_relative_deg + resolution_module_subindex,
i + 1,
),
)
self.list_list_mapping_table[resolution_module_subindex + 1].append(
MTEntry(element_new_generator,
self.sum(list_quot_ker_img[i]))
)
self.list_list_found_generators[resolution_module_subindex + 1].append(
element_new_generator.generator
)