forked from gheber/kenzo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresolutions.lisp
1352 lines (1133 loc) · 46 KB
/
resolutions.lisp
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
;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*
;; RESOLUTIONS RESOLUTIONS RESOLUTIONS RESOLUTIONS RESOLUTIONS RESOLUTIONS
;; RESOLUTIONS RESOLUTIONS RESOLUTIONS RESOLUTIONS RESOLUTIONS RESOLUTIONS
;; RESOLUTIONS RESOLUTIONS RESOLUTIONS RESOLUTIONS RESOLUTIONS RESOLUTIONS
(IN-PACKAGE #:cat)
(provide "resolutions")
;; CLASSES AND TYPES
(DEFUN ZGGNRT-P (object)
(declare (type any object))
(the boolean
(and (consp object)
(eql :ZGgnrt (car object))
(consp (cdr object))
(typep (cadr object) 'gnrt)
(typep (cddr object) 'gnrt)
)))
(DEFTYPE ZGGNRT () '(satisfies zggnrt-p))
(DEFUN ZGTERM-P (object)
(declare (type any object))
(the boolean
(and (consp object)
(typep (car object) 'fixnum)
(typep (cdr object) 'zggnrt))))
(DEFTYPE ZGTERM () '(satisfies zgterm-p))
;; IZGCMBN = Internal-ZGCoMBiNation
(DEFUN IZGCMBN-P (object)
;; IZGCMBN = Internal ZGCoMBiNation,
;; without the keyword and the degree
(declare (type any object))
(the boolean
(and (listp object)
(every #'zgterm-p object))))
(DEFTYPE IZGCMBN () '(satisfies izgcmbn-p))
;; ZGCMBN = ZGCoMBiNation
(DEFUN ZGCMBN-P (object)
(declare (type any object))
(the boolean
(and (consp object)
(eql (car object) :cmbn)
(consp (cdr object))
(typep (second object) 'fixnum)
(typep (cddr object) 'izgcmbn))))
(DEFTYPE ZGCMBN () '(satisfies zgcmbn-p))
(DEFTYPE GROUP-BASIS () '(or list (eql :locally-effective)))
;;(DEFCLASS GROUP-MRPH () ()) ;; to be redefined later
(DEFCLASS GROUP ()
((elements :type group-basis :initarg :elements :reader elements)
(cmpr :type cmprf :initarg :cmpr :reader cmpr1)
(mult :type function :initarg :mult :reader mult1)
(inv :type function :initarg :inv :reader inv1)
(nullel :type gnrt :initarg :nullel :reader nullel)
(idnm :type fixnum :initform (incf *idnm-counter*) :reader idnm)
(orgn :type list :initarg :orgn :reader orgn)
(resolution :type reduction :initarg :resolution :reader resolution))
)
(DEFMETHOD INITIALIZE-INSTANCE :after ((group group) &rest rest)
(set (intern (format nil "K~D" (idnm group))) group))
(DEFCLASS AB-GROUP (GROUP)
())
(DEFCLASS GROUP-MRPH ()
;; SOuRCe
((sorc :type group :initarg :sorc :reader sorc)
;; TaRGeT
(trgt :type group :initarg :trgt :reader trgt)
;; INTeRnal
(intr :type function :initarg :intr :reader intr)
;; IDentification NuMber
(idnm :type fixnum :initform (incf *idnm-counter*) :reader idnm)
;; ORiGiN
(orgn :type list :initarg :orgn :reader orgn)))
(DEFMETHOD INITIALIZE-INSTANCE :after ((group-mrph group-mrph) &rest rest)
(set (intern (format nil "K~D" (idnm group-mrph))) group-mrph))
(DEFVAR *GROUP-LIST*
"The variable *GROUP-LIST* is bound to a list of user created groups.")
(SETF *GROUP-LIST* +EMPTY-LIST+)
(PUSHNEW '*GROUP-LIST* *LIST-LIST*)
(DEFVAR *AB-GROUP-LIST*
"The variable *AB-GROUP-LIST* is bound to a list of user created abelian groups.")
(SETF *AB-GROUP-LIST* +EMPTY-LIST+)
(PUSHNEW '*AB-GROUP-LIST* *LIST-LIST*)
(DEFVAR *GROUP-MRPH-LIST*
"The variable *GROUP-MRPH-LIST* is bound to a list of user created group morphisms.")
(SETF *GROUP-MRPH-LIST* +EMPTY-LIST+)
(PUSHNEW '*GROUP-MRPH-LIST* *LIST-LIST*)
#+clisp(eval-when (:compile-toplevel :load-toplevel :execute)
(setf (ext:package-lock :clos) nil))
(DEFMETHOD PRINT-OBJECT ((group group) stream)
(the group
(progn
(format stream "[K~D Group]" (idnm group))
group)))
(DEFMETHOD PRINT-OBJECT ((group ab-group) stream)
(the ab-group
(progn
(format stream "[K~D Abelian-Group]" (idnm group))
group)))
(DEFMETHOD PRINT-OBJECT ((group-mrph group-mrph) stream)
(the group-mrph
(progn
(format stream "[K~D Group-morphism]" (idnm group-mrph))
group-mrph)))
#+clisp(eval-when (:compile-toplevel :load-toplevel :execute)
(setf (ext:package-lock :clos) t))
(DEFUN GROUP (idnm)
(declare (type fixnum idnm))
(the (or group null)
(find idnm *group-list* :key #'idnm)))
(DEFUN AB-GROUP (idnm)
(declare (type fixnum idnm))
(the (or ab-group null)
(find idnm *ab-group-list* :key #'idnm)))
(DEFUN GROUP-MRPH (idnm)
(declare (type fixnum idnm))
(the (or group-mrph null)
(find idnm *group-mrph-list* :key #'idnm)))
;;(DEFCLASS ZG-MORPHISM () ()) ;; will be redefined later.
(DEFCLASS ZG-CHAIN-COMPLEX (chain-complex)
((group :type group :initarg :group :reader group1)
(zgcmpr :type cmprf :initarg :zgcmpr :reader zgcmpr1)
(zgbasis :type basis :initarg :zgbasis :reader zgbasis1)
(zgbsgn :type gnrt :initarg :zgbsgn :reader zgbsgn)
(zgbndr :type ZG-morphism :initarg :zgbndr :reader zgbndr1)
))
(DEFVAR *ZGCC-LIST*
"The variable *ZGCC-LIST* is bound to a list of user created zg-chain complexes.")
(SETF *ZGCC-LIST* +empty-list+)
(PUSHNEW '*ZGCC-LIST* *LIST-LIST*)
#+clisp(eval-when (:compile-toplevel :load-toplevel :execute)
(setf (ext:package-lock :clos) nil))
(DEFMETHOD PRINT-OBJECT ((zgcm ZG-CHAIN-COMPLEX) stream)
(the ZG-CHAIN-COMPLEX
(progn
(format stream "[K~D ZG-Chain-Complex]" (idnm zgcm))
zgcm)))
#+clisp(eval-when (:compile-toplevel :load-toplevel :execute)
(setf (ext:package-lock :clos) t))
(DEFUN ZGCC (idnm)
(declare (type fixnum idnm))
(the (or zg-chain-complex null)
(find idnm *zgcc-list* :key #'idnm)))
;; ZGSTRT = ZGSTRaTegy
(DEFTYPE ZGSTRT () '(member :gnrt :zggnrt :zgcmbn))
;; INTR-ZGMRPH = INTeRnal-ZGMoRPHism
(DEFTYPE INTR-ZGMRPH () 'function)
;; (or (function (degr gnrt) zgcmbn) ;; if :gnrt strategy
;; (function (degr zggnrt) zgcmbn) ;; if :zggnrt strategy
;; (function (zgcmbn) zgcmbn) ;; if :zgcmbn strategy
(DEFCLASS ZG-MORPHISM (morphism)
((zgintr :type intr-zgmrph :initarg :zg-intr :reader intr-zgmrph)
(zgstrt :type zgstrt :initarg :zgstrt :reader zgstrt)
))
(DEFVAR *zgmrph-list*
"The variable *ZGMRPH-LIST* is bound to a list of user created morphisms of zg-chain complexes.")
(SETF *zgmrph-list* +empty-list+)
(PUSHNEW '*zgmrph-list* *list-list*)
#+clisp(eval-when (:compile-toplevel :load-toplevel :execute)
(setf (ext:package-lock :clos) nil))
(DEFMETHOD PRINT-OBJECT ((mrph ZG-MORPHISM) stream)
(the ZG-MORPHISM
(progn
(format stream "[K~D ZG-Morphism (degree ~D): K~D -> K~D]"
(idnm mrph) (degr mrph)
(idnm (sorc mrph)) (idnm (trgt mrph)))
mrph)))
#+clisp(eval-when (:compile-toplevel :load-toplevel :execute)
(setf (ext:package-lock :clos) t))
(DEFUN ZGMRPH (idnm)
(declare (type fixnum idnm))
(the (or zg-morphism null)
(find idnm *zgmrph-list* :key #'idnm)))
;; MACROS
(DEFMACRO ZGGNRT (gnrt1 gnrt2)
`(cons :zggnrt
(cons ,gnrt1 ,gnrt2)))
(DEFMACRO ZGGNRT1 (ZGgnrt)
`(car (cdr ,zggnrt)))
(DEFMACRO ZGGNRT2 (ZGgnrt)
`(cddr ,zggnrt))
(DEFMACRO WITH-ZGGNRT ((zggnrt1 zggnrt2) zggnrt . body)
`(let (,@(if zggnrt1 `((,zggnrt1 (zggnrt1 ,zggnrt))) nil)
,@(if zggnrt2 `((,zggnrt2 (zggnrt2 ,zggnrt))) nil))
(declare
(type gnrt ,@(if zggnrt1 `(,zggnrt1) nil) ,@(if zggnrt2 `(,zggnrt2) nil)))
,@body))
(DEFMACRO ZGTERM (cffc zggnrt)
`(cons ,cffc ,zggnrt))
(DEFMACRO WITH-ZGTERM ((cffc zggnrt) zgterm . body)
`(let (,@(if cffc `((,cffc (cffc ,zgterm))) nil)
,@(if zggnrt `((,zggnrt (gnrt ,zgterm))) nil))
(declare
(fixnum ,@(if cffc `(,cffc) nil))
(type zggnrt ,@(if zggnrt `(,zggnrt) nil)))
,@body))
(DEFUN BUILD-GROUP
(&key elements cmpr mult inv nullel orgn)
(declare
(type group-basis elements)
(type cmprf cmpr)
(type function mult)
(type function inv)
(type gnrt nullel)
(list orgn))
(the group
(progn
(let ((already (find orgn *group-list* :test #'equal :key #'orgn)))
(declare (type (or group null) already))
(when already
(return-from build-group already)))
(unless elements
(setf elements :locally-effective))
(let ((group (make-instance 'group
:cmpr cmpr
:elements elements
:mult mult
:inv inv
:nullel nullel
:orgn orgn)))
(declare (type group group))
(push group *group-list*)
group))))
(DEFUN BUILD-GRMR (&key sorc trgt intr orgn)
(declare
(type group sorc trgt)
(type (or intr-mrph null) intr)
(list orgn))
(the group-mrph
(progn
(let ((already (find orgn *group-mrph-list* :test #'equal :key #'orgn)))
(declare (type (or group-mrph null) already))
(when already
(return-from build-grmr already)))
(let ((mrph (make-instance 'group-mrph
:sorc sorc :trgt trgt
:intr intr
:orgn orgn)))
(declare (type group-mrph mrph))
(push mrph *group-mrph-list*)
mrph))))
(DEFMACRO BUILD-AB-GROUP (&rest rest)
`(change-class (build-group ,@rest) 'ab-group))
(DEFMETHOD ?2 ((grmrph group-mrph) grelt)
(declare (type gnrt grelt))
(the gnrt
(with-slots (intr) grmrph
(funcall intr grelt))))
(DEFMETHOD ?3 ((group group) g1 g2)
(declare
(type gnrt g1 g2))
(the gnrt
(with-slots (mult) group
(funcall mult g1 g2))))
(DEFUN ZGGNRT-CMPR (grcmpr zgcmpr)
(declare (type cmprf grcmpr zgcmpr))
(flet ((rslt (gnrt1 gnrt2)
(declare (type zggnrt gnrt1 gnrt2))
(the cmpr
(let ((gnrt12 (zggnrt2 gnrt1))
(gnrt22 (zggnrt2 gnrt2)))
(declare (type gnrt gnrt12 gnrt22))
(lexico
(funcall zgcmpr gnrt12 gnrt22)
(let ((gnrt11 (zggnrt1 gnrt1))
(gnrt21 (zggnrt1 gnrt2)))
(declare (type gnrt gnrt11 gnrt21))
(funcall grcmpr gnrt11 gnrt21)))))))
(the cmprf #'rslt)))
(DEFUN ZGCHCM-BASIS (grbasis zgbasis)
(declare (type group-basis grbasis)
(type basis zgbasis))
(when (or (eq grbasis :locally-effective)
(eq zgbasis :locally-effective))
(return-from ZGCHCM-BASIS :locally-effective))
(flet ((rslt (degr)
(declare (fixnum degr))
(the list
(progn
(when (minusp degr)
(return-from rslt +empty-list+))
(the list
(mapcan
#'(lambda (gnrt2)
(declare (type gnrt gnrt2))
(the list
(mapcar
#'(lambda (gnrt1)
(declare (type gnrt gnrt1))
(the zggnrt
(zggnrt gnrt1 gnrt2)))
grbasis)))
(funcall zgbasis degr)))))))
(the basis #'rslt)))
(DEFUN ZGMRPH-GNRT-GNRT (intr degr gnrt)
(declare
(type intr-zgmrph intr)
(fixnum degr)
(type gnrt gnrt))
(funcall intr degr gnrt))
(DEFUN ZGMRPH-GNRT-ZGGNRT (grcmpr zgcmpr grmult intr degr zggnrt)
(declare
(type cmprf grcmpr zgcmpr)
(type function grmult)
(type intr-zgmrph intr)
(fixnum degr)
(type zggnrt zggnrt))
(let* ((zggnrt1 (zggnrt1 zggnrt))
(zggnrt2 (zggnrt2 zggnrt))
(zgcmbn (ZGMRPH-GNRT-GNRT intr degr zggnrt2))
(degr (cmbn-degr zgcmbn))
(list (cmbn-list zgcmbn))
(n-cmbn-list +empty-list+))
(declare (list n-cmbn-list))
(if list
(progn
(mapcar #'(lambda (zgterm)
(declare (type zgterm zgterm))
(with-zgterm (cffc gnrt) zgterm
(declare (type fixnum cffc)
(type zggnrt gnrt))
(with-zggnrt (gnrt1 gnrt2) gnrt
(declare (type gnrt gnrt1 gnrt2))
(push (cons 1
(term-cmbn degr cffc (zggnrt (funcall grmult zggnrt1 gnrt1) gnrt2)))
n-cmbn-list))))
list)
(cmbn-cmbn (zggnrt-cmpr grcmpr zgcmpr) n-cmbn-list))
(zero-cmbn degr))))
(DEFUN ZGMRPH-GNRT-ZGCMBN (grcmpr zgcmpr grmult intr zgcmbn)
(declare
(type cmprf grcmpr zgcmpr)
(type function grmult)
(type intr-zgmrph intr)
;;(type zgcmbn zgcmbn)
)
(the cmbn
(with-cmbn (degr list) zgcmbn
(if list
(let ((n-cmbn-list +empty-list+))
(declare (list n-cmbn-list))
(do ((mark list (cdr mark)))
((endp mark))
(declare (list mark))
(with-term (cffc gnrt) (car mark)
(push
(cons cffc
(zgmrph-gnrt-zggnrt grcmpr zgcmpr grmult intr degr gnrt))
n-cmbn-list)))
(cmbn-cmbn (zggnrt-cmpr grcmpr zgcmpr) n-cmbn-list))
(cmbn degr)))))
(DEFUN ZGMRPH-ZGGNRT-ZGGNRT (intr degr zggnrt)
(declare
(type intr-zgmrph intr)
(fixnum degr)
(type zggnrt zggnrt))
(funcall intr degr zggnrt))
(DEFUN ZGMRPH-ZGGNRT-ZGCMBN (grcmpr zgcmpr intr zgcmbn)
(declare
(type intr-zgmrph intr)
(type cmprf grcmpr zgcmpr)
;;(type zgcmbn zgcmbn)
)
(the cmbn
(with-cmbn (degr list) zgcmbn
(let ((n-cmbn-list +empty-list+))
(declare (list n-cmbn-list))
(do ((mark list (cdr mark)))
((endp mark))
(declare (list mark))
(with-term (cffc gnrt) (car mark)
(push
(cons cffc
(zgmrph-zggnrt-zggnrt intr degr gnrt))
n-cmbn-list)))
(cmbn-cmbn (zggnrt-cmpr grcmpr zgcmpr) n-cmbn-list)))))
(DEFUN ZGMRPH-GNRT-? (ZGmrph degr gnrt)
(declare
(type zg-morphism ZGmrph)
(fixnum degr)
(type gnrt gnrt))
(the cmbn
(with-slots (zgintr zgstrt trgt) zgmrph
(declare
(type zg-chain-complex trgt)
(type intr-zgmrph zgintr)
(type zgstrt zgstrt))
(with-slots (group) trgt
(declare
(type group group))
(with-slots (nullel) group
(declare
(type gnrt nullel))
(prog1
(ecase zgstrt
(:gnrt
(zgmrph-gnrt-gnrt zgintr degr gnrt))
(:zggnrt
(funcall zgintr degr (zggnrt nullel gnrt)))
(:cmbn
(funcall zgintr (term-cmbn degr 1 (zggnrt nullel gnrt)))))
))))))
(DEFUN ZGMRPH-ZGGNRT-? (ZGmrph degr zggnrt)
(declare
(type ZG-morphism ZGmrph)
(fixnum degr)
(type zggnrt zggnrt))
(the cmbn
(with-slots (trgt zgintr zgstrt ) zgmrph
(declare
(type zg-chain-complex trgt)
(type intr-zgmrph zgintr)
(type zgstrt zgstrt))
(with-slots (group) trgt
(declare
(type group group))
(with-slots ((grcmpr cmpr) mult nullel) group
(declare (type cmprf grcmpr))
(with-slots (zgcmpr) trgt
(declare (type cmprf zgcmpr))
(prog1
(ecase zgstrt
(:gnrt
(zgmrph-gnrt-zggnrt grcmpr zgcmpr mult zgintr degr zggnrt))
(:zggnrt
(funcall zgintr degr zggnrt))
(:cmbn
(funcall zgintr (term-cmbn degr 1 zggnrt)))))))))))
(DEFUN ZGMRPH-ZGCMBN-? (ZGmrph zgcmbn)
(declare
(type zg-morphism zgmrph)
;;(type zgcmbn zgcmbn)
)
(the cmbn
(with-slots (trgt zgintr zgstrt ) zgmrph
(declare
(type zg-chain-complex trgt)
(type intr-zgmrph zgintr)
(type zgstrt zgstrt))
(with-slots (group zgcmpr) trgt
(declare
(type group group)
(type cmprf zgcmpr))
(with-slots ((grcmpr cmpr) mult nullel) group
(declare
(type cmprf grcmpr)
(type function mult)
(type gnrt nullel))
(prog1
(ecase zgstrt
(:gnrt
(zgmrph-gnrt-zgcmbn grcmpr zgcmpr mult zgintr zgcmbn))
(:zggnrt
(zgmrph-zggnrt-zgcmbn grcmpr zgcmpr zgintr zgcmbn))
(:cmbn
(funcall zgintr zgcmbn)))
))))))
(DEFUN IZGMRPH-IMRPH (grcmpr zgcmpr mult intr strt)
(declare (type intr-zgmrph intr)
(type zgstrt strt))
(flet ((rslt (degr zggnrt)
(declare
(fixnum degr)
(type zggnrt zggnrt))
(ecase strt
(:gnrt
(zgmrph-gnrt-zggnrt grcmpr zgcmpr mult intr degr zggnrt))
(:zggnrt
(funcall intr degr zggnrt))
(:cmbn
(funcall intr (term-cmbn degr 1 zggnrt))))))
(the intr-mrph #'rslt)))
(DEFUN INTR-ZGCHCM-MRPH (zgmrph)
(declare (type zg-morphism zgmrph))
(flet ((rslt (degr zggnrt)
(declare
(fixnum degr)
(type zggnrt zggnrt))
(zgmrph-zggnrt-? zgmrph degr zggnrt)))
(the intr-mrph #'rslt)))
(DEFUN BUILD-ZGCHCM
(&key group zgcmpr zgbasis zgbsgn intr-zgbndr zgbndr-strt orgn)
(declare
(type group group)
(type cmprf zgcmpr)
(type basis zgbasis)
(type gnrt zgbsgn)
(type intr-zgmrph intr-zgbndr)
(type zgstrt zgbndr-strt)
(list orgn))
(let ((already (find orgn *zgcc-list* :test #'equal :key #'orgn)))
(declare (type (or zg-chain-complex null) already))
(when already
(return-from build-zgchcm already)))
(if intr-zgbndr
(unless zgbndr-strt
(error "In BUILD-ZGCHCM, an intr-zgbndr is given but not its strategy."))
)
(the zg-chain-complex
(with-slots ((grcmpr cmpr) (grbasis elements) mult nullel) group
(let* ((cmpr (zggnrt-cmpr grcmpr zgcmpr))
(basis (ZGCHCM-BASIS grbasis zgbasis))
(bsgn (zggnrt nullel zgbsgn))
(intr-dffr (izgmrph-imrph grcmpr zgcmpr mult intr-zgbndr zgbndr-strt))
(rslt (build-chcm :cmpr cmpr :basis basis :bsgn bsgn
:intr-dffr intr-dffr :strt :gnrt :orgn orgn)))
(change-class rslt 'zg-chain-complex)
(setf (slot-value rslt 'group) group)
(setf (slot-value rslt 'zgcmpr) zgcmpr)
(setf (slot-value rslt 'zgbasis) zgbasis)
(setf (slot-value rslt 'zgbsgn) zgbsgn)
(setf (slot-value rslt 'zgbndr) (build-zgmrph :sorc rslt :trgt rslt :degr -1
:zgintr intr-zgbndr :zgstrt zgbndr-strt :orgn `(zgbndr ,rslt)))
(push rslt *zgcc-list*)
rslt))))
(DEFUN BUILD-ZGMRPH (&key sorc trgt degr zgintr zgstrt orgn)
(declare
(type zg-chain-complex sorc trgt)
(fixnum degr)
(type intr-zgmrph zgintr)
(type zgstrt zgstrt)
(list orgn))
(the zg-morphism
(with-slots (group zgcmpr) trgt
(with-slots ((grcmpr cmpr) (grbasis elements) mult nullel ) group
(let* ((intr (izgmrph-imrph grcmpr zgcmpr mult zgintr zgstrt))
(rslt (build-mrph :sorc sorc :trgt trgt :degr degr
:intr intr :strt :gnrt :orgn orgn)))
(change-class rslt 'zg-morphism)
(setf (slot-value rslt 'zgintr) zgintr)
(setf (slot-value rslt 'zgstrt) zgstrt)
(push rslt *zgcc-list*)
rslt)))))
;; TENSOR WITH INTEGERS
(DEFUN ZGCMBN-TWI (zgcmpr zgcmbn)
;;(declare (type zgcmbn zgcmbn))
(with-cmbn (degr list) zgcmbn
(if list
(let* ((cmbn-list +empty-list+))
(mapcar #'(lambda (zgterm)
(with-zgterm (cffc zggnrt) zgterm
(let ((gnrt2 (zggnrt2 zggnrt)))
(push (cons 1
(term-cmbn degr cffc gnrt2))
cmbn-list))))
list)
(cmbn-cmbn zgcmpr cmbn-list))
(zero-cmbn degr))))
(DEFUN ZGMRPH-TWI-INTR (mrph)
(declare (type zg-morphism mrph))
(flet ((rslt (degr gnrt)
(declare
(fixnum degr)
(type gnrt gnrt))
(with-slots (trgt) mrph
(with-slots (zgcmpr) trgt
(zgcmbn-twi zgcmpr (zgmrph-gnrt-? mrph degr gnrt))))))
(the intr-mrph #'rslt)))
(DEFUN ZGMRPH-TWI (mrph)
(declare (type zg-morphism mrph))
(the morphism
(with-slots (sorc trgt degr zgintr zgstrt orgn) mrph
(build-mrph :sorc (chcm-twi sorc) :trgt (chcm-twi trgt) :degr degr
:intr (zgmrph-twi-intr mrph) :strt :gnrt :orgn `(tensor-with-integers ,orgn))
)))
(DEFUN CHCM-TWI (chcm)
(declare (type zg-chain-complex chcm))
(the chain-complex
(if (string= (car (orgn chcm)) 'bar-zgchcm)
(with-slots (group) chcm
(k-g-1 group))
(with-slots (zgcmpr zgbasis zgbsgn zgbndr orgn) chcm
(build-chcm :cmpr zgcmpr :basis zgbasis :bsgn zgbsgn :intr-dffr (zgmrph-twi-intr zgbndr)
:strt :gnrt :orgn `(tensor-with-integers ,orgn))))))
(DEFUN CYCLICGROUP (n)
(declare (fixnum n))
(build-ab-group :elements (<a-b> 0 (1- n)) :cmpr #'f-cmpr :mult #'(lambda (g1 g2)
(mod (+ g1 g2) n))
:inv #'(lambda (g)
(mod (- n g) n)) :nullel 0 :orgn `(Cyclic-group of order ,n)))
(DEFUN Z-GROUP ()
(build-ab-group :elements :locally-effective :cmpr #'f-cmpr :mult #'(lambda (g1 g2)
(+ g1 g2) )
:inv #'(lambda (g)
(- g)) :nullel 0 :orgn `(z-group)))
(DEFMETHOD SLOT-UNBOUND (class (group group) (slot-name (eql 'resolution)))
(declare (ignore class))
(the reduction
(let ((rsltn (search-resolution group (first (orgn group)))))
(setf (slot-value group 'resolution)
(or rsltn
(error "I don't know how to determine ~
a resolution for
~A (Origin: ~A)." group (orgn group)))))))
(DEFGENERIC SEARCH-RESOLUTION (group orgn))
(DEFMETHOD SEARCH-RESOLUTION (group orgn)
(declare (ignore group orgn))
nil)
(DEFUN CYCLICGROUP-ZGCHCM (n)
(let* ((orgn `(Cyclic-group of order ,n))
(already (find orgn *group-list* :test #'equal :key #'orgn))
(group (or already (cyclicgroup n)))
(zgbasis #'(lambda (degr) (list degr)))
(zgcmpr #'f-cmpr)
(intr #'(lambda(degr gnrt)
(let ((degr- (1- degr)))
(if (and gnrt (zerop degr)) (zero-cmbn -1)
(if (oddp degr)
(cmbn degr- -1 (zggnrt 0 degr-) 1 (zggnrt 1 degr-))
(let ((list +empty-list+))
(mapcar #'(lambda (i)
(push (cons 1 (zggnrt (- n i) degr-)) list))
(<a-b> 1 n))
(make-cmbn :degr degr- :list list))))))))
(BUILD-ZGCHCM
:group group :zgcmpr zgcmpr :zgbasis zgbasis :zgbsgn 0
:intr-zgbndr intr :zgbndr-strt :gnrt :orgn `(ZG-Chain complex for ,group))))
(DEFUN CYCLICGROUP-RSLTN (n)
(let* ((orgn `(Cyclic-group of order ,n))
(already (find orgn *group-list* :test #'equal :key #'orgn))
(group (or already (cyclicgroup n)))
(zgchcm (cyclicgroup-zgchcm n))
(f-intr #'(lambda (degr zggnrt)
(with-zggnrt (gnrt1 gnrt2) zggnrt
(declare (ignore gnrt1 gnrt2))
(if (zerop degr) (cmbn degr 1 :zgnrt) (zero-cmbn degr)))))
(g-intr #'(lambda (degr gnrt)
(declare (ignore gnrt))
(if (zerop degr) (cmbn degr 1 (zggnrt 0 0)) (zero-cmbn degr))))
(h-intr #'(lambda (degr zggnrt)
(with-zggnrt (gnrt1 gnrt2) zggnrt
(declare (ignore gnrt2))
(if (oddp degr)
(if (= gnrt1 (1- n)) (cmbn (1+ degr) 1 (zggnrt 0 (1+ degr)))
(zero-cmbn (1+ degr)))
(let ((list +empty-list+))
(dotimes (i gnrt1)
(push (cons 1 (zggnrt i (1+ degr))) list ))
(make-cmbn :degr (1+ degr) :list (nreverse list)))))))
(f (build-mrph :sorc zgchcm :trgt (z-chcm) :degr 0 :intr f-intr :strt :gnrt :orgn `(f-mrph for ,group)))
(g (build-mrph :sorc (z-chcm) :trgt zgchcm :degr 0 :intr g-intr :strt :gnrt :orgn `(g-mrph for ,group)))
(h (build-mrph :sorc zgchcm :trgt zgchcm :degr 1 :intr h-intr :strt :gnrt :orgn `(h-mrph for ,group))))
(build-rdct :f f :g g :h h :orgn `(Resolution of ,group))))
(DEFMETHOD SEARCH-RESOLUTION (group (orgn (eql 'Cyclic-group)))
(declare
(type group group))
(the reduction
(with-slots (elements) group
(let ((n (length elements)))
(cyclicgroup-rsltn n)))))
(DEFMETHOD GROUP-HOMOLOGY ((group group) degr1 &optional (degr2 (1+ degr1)))
(declare (fixnum degr1 degr2))
(with-slots (resolution) group
(let ((chcm (chcm-twi (tcc resolution))))
(homology chcm degr1 degr2))))
;;;; BAR RESOLUTION
(DEFUN BAR-ZGCMPR (grcmpr)
(declare (type cmprf grcmpr))
(labels ((rslt (gnrt1 gnrt2)
(declare (list gnrt1 gnrt2))
(unless gnrt1
(return-from rslt (if gnrt2 :less :equal)))
(unless gnrt2
(return-from rslt :greater))
(lexico
(funcall grcmpr (first gnrt1) (first gnrt2))
(rslt (rest gnrt1) (rest gnrt2)))
))
(the cmprf #'rslt)))
(DEFUN BAR-ZGBASIS (elements nullel)
(declare (type group-basis elements)
(type gnrt nullel))
(when (eq elements :locally-effective)
(return-from bar-zgbasis :locally-effective))
(labels ((rslt (degr)
(declare (fixnum degr))
;;(the list
(progn
(when (minusp degr)
(return-from rslt +empty-list+))
(when (zerop degr)
(return-from rslt (list (list))))
(let ((basis-1 (rslt (1- degr)))
(elements-0 (remove nullel elements)))
(mapcan #'(lambda (gbar)
(mapcar #'(lambda (g)
(append gbar (list g)))
elements-0))
basis-1)))))
;;)
(the basis #'rslt)))
(DEFUN BAR-BNDR-I (grmult nullel indx degr gnrt)
(declare
(fixnum indx degr)
(list gnrt))
(the cmbn
(cond ((zerop indx) (cmbn (1- degr) 1 (zggnrt (car gnrt) (rest gnrt))))
((= indx degr) (cmbn (1- degr) 1 (zggnrt nullel (butlast gnrt))))
(t
(do ((rslt +empty-list+ (cons (car mark) rslt))
(mark gnrt (cdr mark))
(i 1 (1+ i)))
((= i indx) (let ((new-k (funcall grmult (car mark) (cadr mark))))
(declare (type gnrt new-k))
(if (equal nullel new-k)
(zero-cmbn (1- degr))
(cmbn (1- degr) 1 (zggnrt nullel (nreconc rslt (cons new-k (cddr mark))))))))
(declare
(list rslt mark)
(fixnum i)))))))
(DEFUN BAR-BNDR-INTR (grcmpr grmult nullel)
#'(lambda (degr gnrt)
(if (zerop degr)
(zero-cmbn -1)
(let ((cmbn-list
(mapcar #'(lambda (indx)
(let ((cmbn (bar-bndr-i grmult nullel indx degr gnrt)))
(if (oddp indx)
(cons -1 cmbn)
(cons 1 cmbn))))
(<a-b> 0 degr))))
(cmbn-cmbn (zggnrt-cmpr grcmpr (bar-zgcmpr grcmpr)) cmbn-list)))))
(DEFUN BAR-ZGCHCM (group)
(declare (type group group))
(the zg-chain-complex
(with-slots (elements cmpr mult nullel) group
(build-zgchcm
:group group
:zgcmpr (bar-zgcmpr cmpr)
:zgbasis (bar-zgbasis elements nullel)
:zgbsgn +empty-list+
:intr-zgbndr (bar-bndr-intr cmpr mult nullel)
:zgbndr-strt :gnrt
:orgn `(bar-zgchcm ,group)))))
(DEFUN BAR-CNTRHMTP-INTR (grcmpr grmult nullel)
#'(lambda (degr zggnrt)
(declare (ignore grcmpr grmult))
(with-zggnrt (gnrt1 gnrt2) zggnrt
(if (equal nullel gnrt1)
(zero-cmbn (1+ degr))
(if (zerop degr)
(cmbn 1 1 (zggnrt nullel (list gnrt1)))
(cmbn (1+ degr) 1 (zggnrt nullel (cons gnrt1 gnrt2))))))))
(DEFUN BAR-F-INTR ()
#'(lambda (degr zggnrt)
(declare (ignore zggnrt))
(if (zerop degr) (cmbn degr 1 :zgnrt) (zero-cmbn degr))))
(DEFUN BAR-G-INTR (nullel)
#'(lambda (degr gnrt)
(declare (ignore gnrt))
(if (zerop degr) (cmbn degr 1 (zggnrt nullel +empty-list+)) (zero-cmbn degr))))
(DEFUN BAR-RSLTN (group)
(declare (type group group))
(the reduction
(with-slots (cmpr mult nullel) group
(let* ((zgchcm (bar-zgchcm group))
(f (build-mrph :sorc zgchcm :trgt (z-chcm) :degr 0 :intr (bar-f-intr) :strt :gnrt :orgn `(f-mrph in bar-resolution for ,group)))
(g (build-mrph :sorc (z-chcm) :trgt zgchcm :degr 0 :intr (bar-g-intr nullel) :strt :gnrt :orgn `(g-mrph in bar-resolution for ,group)))
(h (build-mrph :sorc zgchcm :trgt zgchcm :degr 1 :intr (bar-cntrhmtp-intr cmpr mult nullel)
:strt :gnrt :orgn `(h-mrph in bar-resolution for ,group))))
(build-rdct :f f :g g :h h :orgn `(Bar-resolution of ,group))))))
(DEFUN K-G-1-CMPR (grcmpr)
(declare (type cmprf grcmpr))
(labels ((rslt (gnrt1 gnrt2)
(declare (list gnrt1 gnrt2))
(unless gnrt1
(return-from rslt (if gnrt2 :less :equal)))
(unless gnrt2
(return-from rslt :greater))
(lexico
(funcall grcmpr (first gnrt1) (first gnrt2))
(rslt (rest gnrt1) (rest gnrt2)))))
(the cmprf #'rslt)))
(DEFUN K-G-1-BASIS (elements nullel)
(declare (type group-basis elements)
(type gnrt nullel))
(when (eq elements :locally-effective)
(return-from K-G-1-basis :locally-effective))
(labels ((rslt (degr)
(declare (fixnum degr))
;;(the list
(progn
(when (minusp degr)
(return-from rslt +empty-list+))
(when (zerop degr)
(return-from rslt (list (list))))
(let ((basis-1 (rslt (1- degr)))
(elements-0
(do ((indx 0 (1+ indx))
(aux +empty-list+))
((>= indx (length elements)) (nreverse aux))
(if (not (equal nullel (nth indx elements)))
(push (nth indx elements) aux)))))
(mapcan #'(lambda (gbar)
(mapcar #'(lambda (g)
(append gbar (list g)))
elements-0))
basis-1)))))
;;)
(the basis #'rslt)))
(DEFUN K-G-1-FACE (grmult nullel)
(flet ((face (indx dmns gmsm)
(declare
(fixnum indx dmns)
(list gmsm))
(the absm
(cond ((zerop indx) (absm 0 (rest gmsm)))
((= indx dmns) (absm 0 (butlast gmsm)))
(t
(do ((rslt +empty-list+ (cons (car mark) rslt))
(mark gmsm (cdr mark))
(i 1 (1+ i)))
((= i indx) (let ((new-k (funcall grmult (car mark) (cadr mark))))
(declare (type gnrt new-k))
(if (equal nullel new-k)
(absm (2-exp (1- indx)) (nreconc rslt (cddr mark)))
(absm 0 (nreconc rslt (cons new-k (cddr mark)))))))
(declare
(list rslt mark)
(fixnum i))))))))
(the face #'face)))
(DEFUN G-ABSM-BAR (nullel absm)
(declare (type absm absm))
(the list
(with-absm (dgop bar1) absm
(do ((dgop dgop (ash dgop -1))
(rslt +empty-list+))
((and (zerop dgop) (endp bar1)) (nreverse rslt))
(declare
(fixnum dgop)
(list rslt))
(push (if (oddp dgop)