This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
commutative_dga.py
2805 lines (2261 loc) · 95.9 KB
/
commutative_dga.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
"""
Commutative Differential Graded Algebras
An algebra is said to be *graded commutative* if it is endowed with a
grading and its multiplication satisfies the Koszul sign convention:
`yx = (-1)^{ij} xy` if `x` and `y` are homogeneous of degrees `i` and
`j`, respectively. Thus the multiplication is anticommutative for odd
degree elements, commutative otherwise. *Commutative differential
graded algebras* are graded commutative algebras endowed with a graded
differential of degree 1. These algebras can be graded over the
integers or they can be multi-graded (i.e., graded over a finite rank
free abelian group `\ZZ^n`); if multi-graded, the total degree is used
in the Koszul sign convention, and the differential must have total
degree 1.
EXAMPLES:
All of these algebras may be constructed with the function
:func:`GradedCommutativeAlgebra`. For most users, that will be the
main function of interest. See its documentation for many more
examples.
We start by constructing some graded commutative algebras. Generators
have degree 1 by default::
sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ)
sage: x.degree()
1
sage: x^2
0
sage: y*x
-x*y
sage: B.<a,b> = GradedCommutativeAlgebra(QQ, degrees = (2,3))
sage: a.degree()
2
sage: b.degree()
3
Once we have defined a graded commutative algebra, it is easy to
define a differential on it using the :meth:`GCAlgebra.cdg_algebra` method::
sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,1,2))
sage: B = A.cdg_algebra({x: x*y, y: -x*y})
sage: B
Commutative Differential Graded Algebra with generators ('x', 'y', 'z') in degrees (1, 1, 2) over Rational Field with differential:
x --> x*y
y --> -x*y
z --> 0
sage: B.cohomology(3)
Free module generated by {[x*z + y*z]} over Rational Field
sage: B.cohomology(4)
Free module generated by {[z^2]} over Rational Field
We can also compute algebra generators for the cohomology in a range
of degrees, and in this case we compute up to degree 10::
sage: B.cohomology_generators(10)
{1: [x + y], 2: [z]}
AUTHORS:
- Miguel Marco, John Palmieri (2014-07): initial version
"""
#*****************************************************************************
# Copyright (C) 2014 Miguel Marco <mmarco@unizar.es>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
from __future__ import print_function, absolute_import
from six import string_types
from sage.structure.unique_representation import (
InheritComparisonUniqueRepresentation, UniqueRepresentation)
from sage.structure.sage_object import SageObject
from sage.misc.cachefunc import cached_method
from sage.misc.functional import is_odd, is_even
from sage.misc.misc_c import prod
from sage.categories.algebras import Algebras
from sage.categories.morphism import Morphism
from sage.categories.modules import Modules
from sage.categories.homset import Hom
from sage.algebras.free_algebra import FreeAlgebra
from sage.combinat.free_module import CombinatorialFreeModule
from sage.combinat.integer_vector_weighted import WeightedIntegerVectors
from sage.groups.additive_abelian.additive_abelian_group import AdditiveAbelianGroup
from sage.matrix.constructor import matrix
from sage.modules.free_module import VectorSpace
from sage.modules.free_module_element import vector
from sage.rings.all import ZZ
from sage.rings.polynomial.term_order import TermOrder
from sage.rings.quotient_ring import QuotientRing_nc
from sage.rings.quotient_ring_element import QuotientRingElement
class Differential(InheritComparisonUniqueRepresentation, Morphism):
r"""
Differential of a commutative graded algebra.
INPUT:
- ``A`` -- algebra where the differential is defined
- ``im_gens`` -- tuple containing the image of each generator
EXAMPLES::
sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees=(1,1,2,3))
sage: B = A.cdg_algebra({x: x*y, y: -x*y , z: t})
sage: B
Commutative Differential Graded Algebra with generators ('x', 'y', 'z', 't') in degrees (1, 1, 2, 3) over Rational Field with differential:
x --> x*y
y --> -x*y
z --> t
t --> 0
sage: B.differential()(x)
x*y
"""
@staticmethod
def __classcall__(cls, A, im_gens):
r"""
Normalize input to ensure a unique representation.
TESTS::
sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees=(1,1,2,3))
sage: d1 = A.cdg_algebra({x: x*y, y: -x*y, z: t}).differential()
sage: d2 = A.cdg_algebra({x: x*y, z: t, y: -x*y, t: 0}).differential()
sage: d1 is d2
True
"""
if isinstance(im_gens, (list, tuple)):
im_gens = {A.gen(i): x for i,x in enumerate(im_gens)}
R = A.cover_ring()
I = A.defining_ideal()
if A.base_ring().characteristic() != 2:
squares = R.ideal([R.gen(i)**2 for i,d in enumerate(A._degrees)
if is_odd(d)], side='twosided')
else:
squares = R.ideal(0, side='twosided')
if I != squares:
A_free = GCAlgebra(A.base(), names=A._names, degrees=A._degrees)
free_diff = {A_free(a): A_free(im_gens[a]) for a in im_gens}
B = A_free.cdg_algebra(free_diff)
IB = B.ideal([B(g) for g in I.gens()])
BQ = GCAlgebra.quotient(B, IB)
# We check that the differential respects the
# relations in the quotient method, but we also have
# to check this here, in case a GCAlgebra with
# relations is defined first, and then a differential
# imposed on it.
for g in IB.gens():
if not BQ(g.differential()).is_zero():
raise ValueError("The differential does not preserve the ideal")
im_gens = {A(a): A(im_gens[a]) for a in im_gens}
for i in im_gens:
x = im_gens[i]
if (not x.is_zero()
and (not x.is_homogeneous() or
total_degree(x.degree()) != total_degree(i.degree())+1)):
raise ValueError("The given dictionary does not determine a degree 1 map")
im_gens = tuple(im_gens.get(x, A.zero()) for x in A.gens())
return super(Differential, cls).__classcall__(cls, A, im_gens)
def __init__(self, A, im_gens):
r"""
Initialize ``self``.
INPUT:
- ``A`` -- algebra where the differential is defined
- ``im_gens`` -- tuple containing the image of each generator
EXAMPLES::
sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ)
sage: B = A.cdg_algebra({x: x*y, y: x*y, z: z*t, t: t*z})
sage: [B.cohomology(i).dimension() for i in range(6)]
[1, 2, 1, 0, 0, 0]
sage: d = B.differential()
We skip the category test because homsets/morphisms aren't
proper parents/elements yet::
sage: TestSuite(d).run(skip="_test_category")
An error is raised if the differential `d` does not have
degree 1 or if `d \circ d` is not zero::
sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=(1,2,3))
sage: A.cdg_algebra({a:b, b:c})
Traceback (most recent call last):
...
ValueError: The given dictionary does not determine a valid differential
"""
self._dic_ = {A.gen(i): x for i,x in enumerate(im_gens)}
Morphism.__init__(self, Hom(A, A, category=Modules(A.base_ring())))
for i in A.gens():
if not self(self(i)).is_zero():
raise ValueError("The given dictionary does not determine a valid differential")
def _call_(self, x):
r"""
Apply the differential to ``x``.
INPUT:
- ``x`` -- an element of the domain of this differential
EXAMPLES::
sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ)
sage: B = A.cdg_algebra({x: x*y, y: x*y, z: z*t, t: t*z})
sage: D = B.differential()
sage: D(x*t+1/2*t*x*y) # indirect doctest
-1/2*x*y*z*t + x*y*t + x*z*t
Test positive characteristic::
sage: A.<x,y> = GradedCommutativeAlgebra(GF(17), degrees=(2,3))
sage: B = A.cdg_algebra(differential={x:y})
sage: B.differential()(x^17)
0
"""
if x.is_zero():
return self.codomain().zero()
res = self.codomain().zero()
dic = x.dict()
for key in dic:
keyl = list(key)
coef = dic[key]
idx = 0
while keyl:
exp = keyl.pop(0)
if exp > 0:
v1 = (exp * self._dic_[x.parent().gen(idx)]
* x.parent().gen(idx)**(exp-1))
v2 = prod(x.parent().gen(i+idx+1)**keyl[i] for i in
range(len(keyl)))
res += coef*v1*v2
coef *= ((-1) ** total_degree(x.parent()._degrees[idx])
* x.parent().gen(idx)**exp)
idx += 1
return res
def _repr_defn(self):
"""
Return a string showing where ``self`` sends each generator.
EXAMPLES::
sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ)
sage: B = A.cdg_algebra({x: x*y, y: x*y, z: z*t, t: t*z})
sage: D = B.differential()
sage: print(D._repr_defn())
x --> x*y
y --> x*y
z --> z*t
t --> -z*t
"""
return '\n'.join("{} --> {}".format(i, self(i)) for i in self.domain().gens())
def _repr_(self):
r"""
Return a string representation of ``self``.
EXAMPLES::
sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ)
sage: D = A.differential({x: x*y, y: x*y, z: z*t, t: t*z})
sage: D
Differential of Graded Commutative Algebra with generators ('x', 'y', 'z', 't') in degrees (1, 1, 1, 1) over Rational Field
Defn: x --> x*y
y --> x*y
z --> z*t
t --> -z*t
"""
if self.domain() is None:
return "Defunct morphism"
s = "Differential of {}".format(self.domain()._base_repr())
s += "\n Defn: " + '\n '.join(self._repr_defn().split('\n'))
return s
@cached_method
def differential_matrix(self, n):
r"""
The matrix that gives the differential in degree ``n``.
INPUT:
- ``n`` -- degree
EXAMPLES::
sage: A.<x,y,z,t> = GradedCommutativeAlgebra(GF(5), degrees=(2, 3, 2, 4))
sage: d = A.differential({t: x*y, x: y, z: y})
sage: d.differential_matrix(4)
[0 1]
[2 0]
[1 1]
[0 2]
sage: A.inject_variables()
Defining x, y, z, t
sage: d(t)
x*y
sage: d(z^2)
2*y*z
sage: d(x*z)
x*y + y*z
sage: d(x^2)
2*x*y
"""
A = self.domain()
dom = A.basis(n)
cod = A.basis(n + 1)
cokeys = [next(iter(a.lift().dict().keys())) for a in cod]
m = matrix(A.base_ring(), len(dom), len(cod))
for i in range(len(dom)):
im = self(dom[i])
dic = im.lift().dict()
for j in dic.keys():
k = cokeys.index(j)
m[i,k] = dic[j]
m.set_immutable()
return m
def coboundaries(self, n):
r"""
The ``n``-th coboundary group of the algebra.
This is a vector space over the base field `F`, and it is
returned as a subspace of the vector space `F^d`, where the
``n``-th homogeneous component has dimension `d`.
INPUT:
- ``n`` -- degree
EXAMPLES::
sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,1,2))
sage: d = A.differential({z: x*z})
sage: d.coboundaries(2)
Vector space of degree 2 and dimension 0 over Rational Field
Basis matrix:
[]
sage: d.coboundaries(3)
Vector space of degree 2 and dimension 1 over Rational Field
Basis matrix:
[0 1]
"""
A = self.domain()
F = A.base_ring()
if n == 0:
return VectorSpace(F, 0)
if n == 1:
return VectorSpace(F, 0)
M = self.differential_matrix(n-1)
V0 = VectorSpace(F, M.nrows())
V1 = VectorSpace(F, M.ncols())
mor = V0.Hom(V1)(M)
return mor.image()
def cocycles(self, n):
r"""
The ``n``-th cocycle group of the algebra.
This is a vector space over the base field `F`, and it is
returned as a subspace of the vector space `F^d`, where the
``n``-th homogeneous component has dimension `d`.
INPUT:
- ``n`` -- degree
EXAMPLES::
sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,1,2))
sage: d = A.differential({z: x*z})
sage: d.cocycles(2)
Vector space of degree 2 and dimension 1 over Rational Field
Basis matrix:
[1 0]
"""
A = self.domain()
F = A.base_ring()
if n == 0:
return VectorSpace(F, 1)
M = self.differential_matrix(n)
V0 = VectorSpace(F, M.nrows())
V1 = VectorSpace(F, M.ncols())
mor = V0.Hom(V1)(M)
return mor.kernel()
def cohomology_raw(self, n):
r"""
The ``n``-th cohomology group of ``self``.
This is a vector space over the base ring, and it is returned
as the quotient cocycles/coboundaries.
INPUT:
- ``n`` -- degree
.. SEEALSO::
:meth:`cohomology`
EXAMPLES::
sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees=(2,3,2,4))
sage: d = A.differential({t: x*y, x: y, z: y})
sage: d.cohomology_raw(4)
Vector space quotient V/W of dimension 2 over Rational Field where
V: Vector space of degree 4 and dimension 2 over Rational Field
Basis matrix:
[ 1 0 0 -1/2]
[ 0 1 -2 1]
W: Vector space of degree 4 and dimension 0 over Rational Field
Basis matrix:
[]
Compare to :meth:`cohomology`::
sage: d.cohomology(4)
Free module generated by {[-1/2*x^2 + t], [x^2 - 2*x*z + z^2]} over Rational Field
"""
return self.cocycles(n).quotient(self.coboundaries(n))
def cohomology(self, n):
r"""
The ``n``-th cohomology group of ``self``.
This is a vector space over the base ring, defined as the
quotient cocycles/coboundaries. The elements of the quotient
are lifted to the vector space of cocycles, and this is
described in terms of those lifts.
INPUT:
- ``n`` -- degree
.. SEEALSO::
:meth:`cohomology_raw`
EXAMPLES::
sage: A.<a,b,c,d,e> = GradedCommutativeAlgebra(QQ, degrees=(1,1,1,1,1))
sage: d = A.differential({d: a*b, e: b*c})
sage: d.cohomology(2)
Free module generated by {[c*e], [c*d - a*e], [b*e], [b*d], [a*d], [a*c]} over Rational Field
Compare to :meth:`cohomology_raw`::
sage: d.cohomology_raw(2)
Vector space quotient V/W of dimension 6 over Rational Field where
V: Vector space of degree 10 and dimension 8 over Rational Field
Basis matrix:
[ 0 1 0 0 0 0 0 0 0 0]
[ 0 0 1 0 0 0 -1 0 0 0]
[ 0 0 0 1 0 0 0 0 0 0]
[ 0 0 0 0 1 0 0 0 0 0]
[ 0 0 0 0 0 1 0 0 0 0]
[ 0 0 0 0 0 0 0 1 0 0]
[ 0 0 0 0 0 0 0 0 1 0]
[ 0 0 0 0 0 0 0 0 0 1]
W: Vector space of degree 10 and dimension 2 over Rational Field
Basis matrix:
[0 0 0 0 0 1 0 0 0 0]
[0 0 0 0 0 0 0 0 0 1]
"""
H = self.cohomology_raw(n)
H_basis_raw = [H.lift(H.basis()[i]) for i in range(H.dimension())]
A = self.domain()
B = A.basis(n)
H_basis = [sum([c*b for (c,b) in zip(coeffs, B)]) for coeffs in H_basis_raw]
# Put brackets around classes.
H_basis_brackets = [CohomologyClass(b) for b in H_basis]
return CombinatorialFreeModule(A.base_ring(), H_basis_brackets)
class Differential_multigraded(Differential):
"""
Differential of a commutative multi-graded algebra.
"""
def __init__(self, A, im_gens):
"""
Initialize ``self``.
EXAMPLES::
sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=((1,0), (0, 1), (0,2)))
sage: d = A.differential({a: c})
We skip the category test because homsets/morphisms aren't
proper parents/elements yet::
sage: TestSuite(d).run(skip="_test_category")
"""
Differential.__init__(self, A, im_gens)
# Check that the differential has a well-defined degree.
# diff_deg = [self(x).degree() - x.degree() for x in A.gens()]
diff_deg = []
for x in A.gens():
y = self(x)
if y != 0:
diff_deg.append(y.degree() - x.degree())
if len(set(diff_deg)) > 1:
raise ValueError("The differential does not have a well-defined degree")
self._degree_of_differential = diff_deg[0]
@cached_method
def differential_matrix_multigraded(self, n, total=False):
"""
The matrix that gives the differential in degree ``n``.
.. TODO::
Rename this to ``differential_matrix`` once inheritance,
overriding, and cached methods work together better. See
:trac:`17201`.
INPUT:
- ``n`` -- degree
- ``total`` -- (default: ``False``) if ``True``,
return the matrix corresponding to total degree ``n``
If ``n`` is an integer rather than a multi-index, then the
total degree is used in that case as well.
EXAMPLES::
sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=((1,0), (0, 1), (0,2)))
sage: d = A.differential({a: c})
sage: d.differential_matrix_multigraded((1,0))
[1]
sage: d.differential_matrix_multigraded(1, total=True)
[0 0]
[0 1]
sage: d.differential_matrix_multigraded((1,0), total=True)
[0 0]
[0 1]
sage: d.differential_matrix_multigraded(1)
[0 0]
[0 1]
"""
if total or n in ZZ:
return Differential.differential_matrix(self, total_degree(n))
A = self.domain()
G = AdditiveAbelianGroup([0] * A._grading_rank)
n = G(vector(n))
dom = A.basis(n)
cod = A.basis(n+self._degree_of_differential)
cokeys = [next(iter(a.lift().dict().keys())) for a in cod]
m = matrix(self.base_ring(), len(dom), len(cod))
for i in range(len(dom)):
im = self(dom[i])
dic = im.lift().dict()
for j in dic.keys():
k = cokeys.index(j)
m[i,k] = dic[j]
m.set_immutable()
return m
def coboundaries(self, n, total=False):
"""
The ``n``-th coboundary group of the algebra.
This is a vector space over the base field `F`, and it is
returned as a subspace of the vector space `F^d`, where the
``n``-th homogeneous component has dimension `d`.
INPUT:
- ``n`` -- degree
- ``total`` (default ``False``) -- if ``True``, return the
coboundaries in total degree ``n``
If ``n`` is an integer rather than a multi-index, then the
total degree is used in that case as well.
EXAMPLES::
sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=((1,0), (0, 1), (0,2)))
sage: d = A.differential({a: c})
sage: d.coboundaries((0,2))
Vector space of degree 1 and dimension 1 over Rational Field
Basis matrix:
[1]
sage: d.coboundaries(2)
Vector space of degree 2 and dimension 1 over Rational Field
Basis matrix:
[0 1]
"""
if total or n in ZZ:
return Differential.coboundaries(self, total_degree(n))
A = self.domain()
G = AdditiveAbelianGroup([0] * A._grading_rank)
n = G(vector(n))
F = A.base_ring()
if total_degree(n) == 0:
return VectorSpace(F, 0)
if total_degree(n) == 1:
return VectorSpace(F, 0)
M = self.differential_matrix_multigraded(n-self._degree_of_differential)
V0 = VectorSpace(F, M.nrows())
V1 = VectorSpace(F, M.ncols())
mor = V0.Hom(V1)(M)
return mor.image()
def cocycles(self, n, total=False):
r"""
The ``n``-th cocycle group of the algebra.
This is a vector space over the base field `F`, and it is
returned as a subspace of the vector space `F^d`, where the
``n``-th homogeneous component has dimension `d`.
INPUT:
- ``n`` -- degree
- ``total`` -- (default: ``False``) if ``True``, return the
cocycles in total degree ``n``
If ``n`` is an integer rather than a multi-index, then the
total degree is used in that case as well.
EXAMPLES::
sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=((1,0), (0, 1), (0,2)))
sage: d = A.differential({a: c})
sage: d.cocycles((0,1))
Vector space of degree 1 and dimension 1 over Rational Field
Basis matrix:
[1]
sage: d.cocycles((0,1), total=True)
Vector space of degree 2 and dimension 1 over Rational Field
Basis matrix:
[1 0]
"""
if total or n in ZZ:
return Differential.cocycles(self, total_degree(n))
A = self.domain()
G = AdditiveAbelianGroup([0] * A._grading_rank)
n = G(vector(n))
F = A.base_ring()
if total_degree(n) == 0:
return VectorSpace(F, 1)
M = self.differential_matrix_multigraded(n)
V0 = VectorSpace(F, M.nrows())
V1 = VectorSpace(F, M.ncols())
mor = V0.Hom(V1)(M)
return mor.kernel()
def cohomology_raw(self, n, total=False):
r"""
The ``n``-th cohomology group of the algebra.
This is a vector space over the base ring, and it is returned
as the quotient cocycles/coboundaries.
INPUT:
- ``n`` -- degree
- ``total`` -- (default: ``False``) if ``True``, return the
cohomology in total degree ``n``
If ``n`` is an integer rather than a multi-index, then the
total degree is used in that case as well.
.. SEEALSO::
:meth:`cohomology`
EXAMPLES::
sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=((1,0), (0, 1), (0,2)))
sage: d = A.differential({a: c})
sage: d.cohomology_raw((0,2))
Vector space quotient V/W of dimension 0 over Rational Field where
V: Vector space of degree 1 and dimension 1 over Rational Field
Basis matrix:
[1]
W: Vector space of degree 1 and dimension 1 over Rational Field
Basis matrix:
[1]
sage: d.cohomology_raw(1)
Vector space quotient V/W of dimension 1 over Rational Field where
V: Vector space of degree 2 and dimension 1 over Rational Field
Basis matrix:
[1 0]
W: Vector space of degree 2 and dimension 0 over Rational Field
Basis matrix:
[]
"""
return self.cocycles(n, total).quotient(self.coboundaries(n, total))
def cohomology(self, n, total=False):
r"""
The ``n``-th cohomology group of the algebra.
This is a vector space over the base ring, defined as the
quotient cocycles/coboundaries. The elements of the quotient
are lifted to the vector space of cocycles, and this is
described in terms of those lifts.
INPUT:
- ``n`` -- degree
- ``total`` -- (default: ``False``) if ``True``, return the
cohomology in total degree ``n``
If ``n`` is an integer rather than a multi-index, then the
total degree is used in that case as well.
.. SEEALSO::
:meth:`cohomology_raw`
EXAMPLES::
sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=((1,0), (0, 1), (0,2)))
sage: d = A.differential({a: c})
sage: d.cohomology((0,2))
Free module generated by {} over Rational Field
sage: d.cohomology(1)
Free module generated by {[b]} over Rational Field
"""
H = self.cohomology_raw(n, total)
H_basis_raw = [H.lift(H.basis()[i]) for i in range(H.dimension())]
A = self.domain()
B = A.basis(n, total)
H_basis = [sum([c*b for (c,b) in zip(coeffs, B)]) for coeffs in H_basis_raw]
# Put brackets around classes.
H_basis_brackets = [CohomologyClass(b) for b in H_basis]
return CombinatorialFreeModule(A.base_ring(), H_basis_brackets)
###########################################################
## Commutative graded algebras
class GCAlgebra(UniqueRepresentation, QuotientRing_nc):
r"""
A graded commutative algebra.
INPUT:
- ``base`` -- the base field
- ``names`` -- (optional) names of the generators: a list of
strings or a single string with the names separated by
commas. If not specified, the generators are named "x0", "x1",
...
- ``degrees`` -- (optional) a tuple or list specifying the degrees
of the generators; if omitted, each generator is given degree
1, and if both ``names`` and ``degrees`` are omitted, an error is
raised.
- ``R`` (optional, default None) -- the ring over which the
algebra is defined: if this is specified, the algebra is defined
to be ``R/I``.
- ``I`` (optional, default None) -- an ideal in ``R``. It is
should include, among other relations, the squares of the
generators of odd degree
As described in the module-level documentation, these are graded
algebras for which oddly graded elements anticommute and evenly
graded elements commute.
The arguments ``R`` and ``I`` are primarily for use by the
:meth:`quotient` method.
These algebras should be graded over the integers; multi-graded
algebras should be constructed using
:class:`GCAlgebra_multigraded` instead.
EXAMPLES::
sage: A.<a,b> = GradedCommutativeAlgebra(QQ, degrees = (2,3))
sage: a.degree()
2
sage: B = A.quotient(A.ideal(a**2*b))
sage: B
Graded Commutative Algebra with generators ('a', 'b') in degrees (2, 3) with relations [a^2*b] over Rational Field
sage: A.basis(7)
[a^2*b]
sage: B.basis(7)
[]
Note that the function :func:`GradedCommutativeAlgebra` can also be used to
construct these algebras.
"""
# TODO: This should be a __classcall_private__?
@staticmethod
def __classcall__(cls, base, names=None, degrees=None, R=None, I=None):
r"""
Normalize the input for the :meth:`__init__` method and the
unique representation.
INPUT:
- ``base`` -- the base ring of the algebra
- ``names`` -- the names of the variables; by default, set to ``x1``,
``x2``, etc.
- ``degrees`` -- the degrees of the generators; by default, set to 1
- ``R`` -- an underlying `g`-algebra; only meant to be used by the
quotient method
- ``I`` -- a two-sided ideal in ``R``, with the desired relations;
Only meant to be used by the quotient method
TESTS::
sage: A1 = GradedCommutativeAlgebra(GF(2), 'x,y', (3, 6))
sage: A2 = GradedCommutativeAlgebra(GF(2), ['x', 'y'], [3, 6])
sage: A1 is A2
True
"""
if names is None:
if degrees is None:
raise ValueError("You must specify names or degrees")
else:
n = len(degrees)
names = tuple('x{}'.format(i) for i in range(n))
elif isinstance(names, string_types):
names = tuple(names.split(','))
n = len(names)
else:
n = len(names)
names = tuple(names)
if degrees is None:
degrees = tuple([1 for i in range(n)])
else:
# Deal with multigrading: convert lists and tuples to elements
# of an additive abelian group.
if len(degrees) > 0:
try:
rank = len(list(degrees[0]))
G = AdditiveAbelianGroup([0]*rank)
degrees = [G(vector(d)) for d in degrees]
except TypeError:
# The entries of degrees are not iterables, so
# treat as singly-graded.
pass
degrees = tuple(degrees)
if not R or not I:
F = FreeAlgebra(base, n, names)
gens = F.gens()
rels = {}
tot_degs = [total_degree(d) for d in degrees]
for i in range(len(gens)-1):
for j in range(i+1, len(gens)):
rels[gens[j]*gens[i]] = ((-1) ** (tot_degs[i] * tot_degs[j])
* gens[i] * gens[j])
R = F.g_algebra(rels, order = TermOrder('wdegrevlex', tot_degs))
if base.characteristic() == 2:
I = R.ideal(0, side='twosided')
else:
I = R.ideal([R.gen(i)**2 for i in range(n) if is_odd(tot_degs[i])],
side='twosided')
return super(GCAlgebra, cls).__classcall__(cls, base=base, names=names,
degrees=degrees, R=R, I=I)
def __init__(self, base, R=None, I=None, names=None, degrees=None):
"""
Initialize ``self``.
INPUT:
- ``base`` -- the base field
- ``R`` -- (optional) the ring over which the algebra is defined
- ``I`` -- (optional) an ideal over the corresponding `g`-algebra;
it is meant to include, among other relations, the squares of the
generators of odd degree
- ``names`` -- (optional) the names of the generators; if omitted,
this uses the names ``x0``, ``x1``, ...
- ``degrees`` -- (optional) the degrees of the generators; if
omitted, they are given degree 1
EXAMPLES::
sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ)
sage: TestSuite(A).run()
sage: A = GradedCommutativeAlgebra(QQ, ('x','y','z'), [3,4,2])
sage: TestSuite(A).run()
sage: A = GradedCommutativeAlgebra(QQ, ('x','y','z','t'), [3, 4, 2, 1])
sage: TestSuite(A).run()
"""
self._degrees = tuple(degrees)
cat = Algebras(R.base_ring()).Graded()
QuotientRing_nc.__init__(self, R, I, names, category=cat)
def _repr_(self):
"""
Print representation.
EXAMPLES::
sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees=[3, 4, 2, 1])
sage: A
Graded Commutative Algebra with generators ('x', 'y', 'z', 't') in degrees (3, 4, 2, 1) over Rational Field
sage: A.quotient(A.ideal(3*x*z - 2*y*t))
Graded Commutative Algebra with generators ('x', 'y', 'z', 't') in degrees (3, 4, 2, 1) with relations [3*x*z - 2*y*t] over Rational Field
"""
s = "Graded Commutative Algebra with generators {} in degrees {}".format(self._names, self._degrees)
# Find any nontrivial relations.
I = self.defining_ideal()
R = self.cover_ring()
degrees = self._degrees
if self.base().characteristic() != 2:
squares = [R.gen(i)**2 for i in range(len(degrees)) if is_odd(degrees[i])]
else:
squares = [R.zero()]
relns = [g for g in I.gens() if g not in squares]
if relns:
s = s + " with relations {}".format(relns)
return s + " over {}".format(self.base_ring())
_base_repr = _repr_
@cached_method
def _basis_for_free_alg(self, n):
r"""
Basis of the associated free commutative DGA in degree ``n``.
That is, ignore the relations when computing the basis:
compute the basis of the free commutative DGA with generators
in degrees given by ``self._degrees``.
INPUT:
- ``n`` -- integer
OUTPUT:
Tuple of basis elements in degree ``n``, as tuples of exponents.
EXAMPLES::
sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=(1,2,3))
sage: A._basis_for_free_alg(3)
[(0, 0, 1), (1, 1, 0)]
sage: B = A.quotient(A.ideal(a*b, b**2+a*c))
sage: B._basis_for_free_alg(3)
[(0, 0, 1), (1, 1, 0)]
sage: GradedCommutativeAlgebra(QQ, degrees=(1,1))._basis_for_free_alg(3)
[]
sage: GradedCommutativeAlgebra(GF(2), degrees=(1,1))._basis_for_free_alg(3)
[(0, 3), (1, 2), (2, 1), (3, 0)]
sage: A = GradedCommutativeAlgebra(GF(2), degrees=(4,8,12))
sage: A._basis_for_free_alg(399)
[]
"""
if n == 0:
return ((0,)*len(self._degrees),)
if self.base_ring().characteristic() == 2:
return [tuple(_) for _ in WeightedIntegerVectors(n, self._degrees)]
even_degrees = []
odd_degrees = []
for a in self._degrees:
if is_even(a):
even_degrees.append(a)
else:
odd_degrees.append(a)
if not even_degrees: # No even generators.