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
/
invariant.py
515 lines (426 loc) · 20.7 KB
/
invariant.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
r"""
Invariant modules
"""
# ****************************************************************************
# Copyright (C) 2021 Trevor K. Karn <karnx018 at umn.edu>
#
# 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.
# https://www.gnu.org/licenses/
# ****************************************************************************
## TODO: COMB THORUGH TO MAKE SURE ALL STUFF IS HAPPENING IN REPN NOT IN MODULE
from sage.modules.with_basis.subquotient import SubmoduleWithBasis
from sage.categories.finitely_generated_semigroups import FinitelyGeneratedSemigroups
from sage.categories.finite_dimensional_modules_with_basis import FiniteDimensionalModulesWithBasis
from sage.categories.groups import Groups
from sage.sets.family import Family
class FiniteDimensionalInvariantModule(SubmoduleWithBasis):
r"""
Construct the `S`-invariant submodule of `M`. When a semigroup `S` acts on a module
`M`, the invariant module is the collection of elements `m` in `M` such that
`s \cdot m = m` for all `s \in S.
.. MATH::
M^S = \{m \in M : s\cdot m = m,\, \forall s \in S \}
INPUTS:
- ``R`` -- an instance of a ``Representation`` of a semigroup `S`
acting on the module `M`.
OUTPUTS:
- ``MS`` -- the invariant algebra of the semigroup action of `S` on `M`, or
equivalently, the isotypic component of the representation of
`S` carried by `M` corresponding to the trivial character.
EXAMPLES::
sage: G = CyclicPermutationGroup(3)
sage: M = CombinatorialFreeModule(QQ, [1,2,3], prefix='M')
sage: from sage.modules.with_basis.representation import Representation
sage: action = lambda g, m: M.term(g(m)) #cyclically permute coordinates
sage: R = Representation(G, M, action)
sage: from sage.modules.with_basis.invariant import FiniteDimensionalInvariantModule
sage: I = FiniteDimensionalInvariantModule(R)
sage: [I.lift(b) for b in I.basis()]
[M[1] + M[2] + M[3]]
sage: G = CyclicPermutationGroup(3)
sage: M = CombinatorialFreeModule(QQ, [1,2,3], prefix='M')
sage: from sage.modules.with_basis.representation import Representation
sage: action = lambda g, m: M.term(g(m)) #cyclically permute coordinates
sage: R = Representation(G, M, action, side='right') #same as last but on right
sage: from sage.modules.with_basis.invariant import FiniteDimensionalInvariantModule
sage: g = G.an_element(); g
(1,2,3)
sage: r = R.an_element(); r
2*M[1] + 2*M[2] + 3*M[3]
sage: R.side()
'right'
sage: r*g
3*M[1] + 2*M[2] + 2*M[3]
sage: I = FiniteDimensionalInvariantModule(R)
sage: [I.lift(b) for b in I.basis()]
[M[1] + M[2] + M[3]]
sage: G = SymmetricGroup(3)
sage: R = G.regular_representation(QQ)
sage: from sage.modules.with_basis.invariant import FiniteDimensionalInvariantModule
sage: I = FiniteDimensionalInvariantModule(R)
sage: [I.lift(b).to_vector() for b in I.basis()]
[(1, 1, 1, 1, 1, 1)]
sage: [I.lift(3*b).to_vector() for b in I.basis()]
[(3, 3, 3, 3, 3, 3)]
sage: G = CyclicPermutationGroup(3)
sage: M = algebras.Exterior(QQ, 'x', 3)
sage: from sage.modules.with_basis.representation import Representation
sage: on_basis = lambda g,m: M.prod([M.monomial((g(j+1)-1,)) for j in m]) #cyclically permute generators
sage: from sage.categories.algebras import Algebras
sage: R = Representation(G, M, on_basis, category=Algebras(QQ).WithBasis().FiniteDimensional())
sage: I = FiniteDimensionalInvariantModule(R)
sage: [I.lift(b) for b in I.basis()]
[1, x0 + x1 + x2, x0*x1 - x0*x2 + x1*x2, x0*x1*x2]
sage: B = I.basis()
sage: m = 3*B[0] + 2*B[1] + 7*B[3]
sage: I.lift(m)
3 + 2*x0 + 7*x0*x1*x2 + 2*x1 + 2*x2
sage: m^2
9*B[0] + 12*B[1] + 42*B[3]
sage: m+m
6*B[0] + 4*B[1] + 14*B[3]
sage: I.lift(m+m)
6 + 4*x0 + 14*x0*x1*x2 + 4*x1 + 4*x2
sage: 7*m
21*B[0] + 14*B[1] + 49*B[3]
sage: I.lift(7*m)
21 + 14*x0 + 49*x0*x1*x2 + 14*x1 + 14*x2
.. NOTE::
The current implementation works when `S` is a finitely-generated semigroup,
and when `M` is a finite-dimensional free module with a distinguished basis.
.. TODO::
Extend when `M` does not have a basis and `S` is a permutation group using:
- https://arxiv.org/abs/0812.3082
- https://www.dmtcs.org/pdfpapers/dmAA0123.pdf
"""
def __init__(self, R, *args, **kwargs):
"""
TESTS::
sage: G = GroupExp()(QQ) # a group that is not finitely generated
sage: M = CombinatorialFreeModule(QQ, [1,2,3])
sage: on_basis = lambda g,m: M.term(m) # trivial rep'n
sage: from sage.modules.with_basis.representation import Representation
sage: R = Representation(G, M, on_basis)
sage: from sage.modules.with_basis.invariant import FiniteDimensionalInvariantModule
sage: I = FiniteDimensionalInvariantModule(R)
Traceback (most recent call last):
...
ValueError: Multiplicative form of Rational Field is not finitely generated
"""
self._semigroup_representation = R
self._semigroup = R.semigroup()
# A check for self._semigroup_representation._module not in FiniteDimensionalModulesWithBasis
# is not required, because a ``Representation`` cannot be built without a basis
if self._semigroup not in FinitelyGeneratedSemigroups:
raise ValueError(f'{self._semigroup} is not finitely generated')
# The left/right multiplication is taken care of
# by self._semigroup_representation, so here
# we can just pass the left multiplication.
# This means that the side argument of annihilator_basis
# (see below) will always be side = 'left'
if self._semigroup_representation.side() == 'left':
def _invariant_map(g, x):
return g*x - x
elif self._semigroup_representation.side() == 'right':
def _invariant_map(g, x):
return x*g - x
self._invariant_map = _invariant_map
category = kwargs.pop('category', R.category().Subobjects())
# Give the intersection of kernels of the map `s*x-x` to determine when
# `s*x = x` for all generators `s` of `S`
basis = self._semigroup_representation.annihilator_basis(
self._semigroup.gens(),
action = self._invariant_map,
side = 'left')
super().__init__(Family(basis),
support_order = self._semigroup_representation._compute_support_order(basis),
ambient = self._semigroup_representation,
unitriangular = False,#is this right?
category = category,
*args, **kwargs)
def _repr_(self):
"""
EXAMPLES::
sage: M = CombinatorialFreeModule(QQ,[1,2,3])
sage: G = CyclicPermutationGroup(3)
sage: from sage.modules.with_basis.representation import Representation
sage: from sage.modules.with_basis.invariant import FiniteDimensionalInvariantModule
sage: R = Representation(G,M,lambda g,x: M.monomial(g(x)))
sage: FiniteDimensionalInvariantModule(R)
(Cyclic group of order 3 as a permutation group)-invariant submodule of
Free module generated by {1, 2, 3} over Rational Field
"""
return f"({self._semigroup})-invariant submodule of {self._semigroup_representation._module}"
def semigroup(self):
"""
Return the semigroup `S` whose action ``self`` is invariant under.
EXAMPLES::
sage: G = SymmetricGroup(3)
sage: M = CombinatorialFreeModule(QQ, [1,2,3], prefix='M')
sage: action = lambda g,x: M.term(g(x))
sage: from sage.modules.with_basis.representation import Representation
sage: R = Representation(G, M, action)
sage: from sage.modules.with_basis.invariant import FiniteDimensionalInvariantModule
sage: I = FiniteDimensionalInvariantModule(R)
sage: I.semigroup()
Symmetric group of order 3! as a permutation group
"""
return self._semigroup
def semigroup_representation(self):
"""
Return the underlying representation of the invariant module.
EXAMPLES::
sage: G = SymmetricGroup(3)
sage: M = CombinatorialFreeModule(QQ, [1,2,3], prefix='M')
sage: action = lambda g,x: M.term(g(x))
sage: from sage.modules.with_basis.representation import Representation
sage: R = Representation(G, M, action); R
Representation of Symmetric group of order 3! as a permutation group indexed by {1, 2, 3} over Rational Field
sage: from sage.modules.with_basis.invariant import FiniteDimensionalInvariantModule
sage: I = FiniteDimensionalInvariantModule(R)
sage: I.semigroup_representation()
Representation of Symmetric group of order 3! as a permutation group indexed by {1, 2, 3} over Rational Field
"""
return self._semigroup_representation
#def _test_
class Element(SubmoduleWithBasis.Element):
def _mul_(self, other):
"""
EXAMPLES::
sage: M = CombinatorialFreeModule(QQ,[1,2,3],prefix='M');
sage: G = CyclicPermutationGroup(3); G.rename('G')
sage: g = G.an_element(); g
(1,2,3)
sage: from sage.modules.with_basis.representation import Representation
sage: from sage.modules.with_basis.invariant import FiniteDimensionalInvariantModule
sage: R = Representation(G,M,lambda g,x:M.monomial(g(x))); R.rename('R')
sage: I = FiniteDimensionalInvariantModule(R)
sage: B = I.basis()
sage: [I.lift(b) for b in B]
[M[1] + M[2] + M[3]]
sage: v = B[0]
sage: v*v
Traceback (most recent call last):
...
TypeError: unsupported operand parent(s) for *: 'R' and 'R'
sage: (1/2)*v
1/2*B[0]
sage: v*(1/2)
1/2*B[0]
sage: G = CyclicPermutationGroup(3); G.rename('G')
sage: M = algebras.Exterior(QQ, 'x', 3)
sage: from sage.modules.with_basis.representation import Representation
sage: on_basis = lambda g,m: M.prod([M.monomial((g(j+1)-1,)) for j in m]) #cyclically permute generators
sage: from sage.categories.algebras import Algebras
sage: R = Representation(G, M, on_basis, category=Algebras(QQ).WithBasis().FiniteDimensional(), side = 'right')
sage: I = FiniteDimensionalInvariantModule(R); I.rename('I')
sage: B = I.basis()
sage: v = B[0] + 2*B[1]; I.lift(v)
1 + 2*x0 + 2*x1 + 2*x2
sage: w = B[2]; I.lift(w)
x0*x1 - x0*x2 + x1*x2
sage: v*w
B[2] + 6*B[3]
sage: I.lift(v*w)
x0*x1 + 6*x0*x1*x2 - x0*x2 + x1*x2
sage: w*v
B[2] + 6*B[3]
sage: (1/2)*v
1/2*B[0] + B[1]
sage: w*(1/2)
1/2*B[2]
sage: g = G((1,3,2))
sage: v*g
B[0] + 2*B[1]
sage: w*g
B[2]
sage: g*v
Traceback (most recent call last):
...
TypeError: unsupported operand parent(s) for *: 'G' and 'I'
sage: R = Representation(G, M, on_basis, category=Algebras(QQ).WithBasis().FiniteDimensional())
sage: I = FiniteDimensionalInvariantModule(R); I.rename('I')
sage: B = I.basis()
sage: v = B[0] + 2*B[1]; I.lift(v)
1 + 2*x0 + 2*x1 + 2*x2
sage: w = B[2]; I.lift(w)
x0*x1 - x0*x2 + x1*x2
sage: v*w
B[2] + 6*B[3]
sage: I.lift(v*w)
x0*x1 + 6*x0*x1*x2 - x0*x2 + x1*x2
sage: w*v
B[2] + 6*B[3]
sage: (1/2)*v
1/2*B[0] + B[1]
sage: w*(1/2)
1/2*B[2]
sage: g = G((1,3,2))
sage: v*v
B[0] + 4*B[1]
sage: g*w
B[2]
sage: v*g
Traceback (most recent call last):
...
TypeError: unsupported operand parent(s) for *: 'I' and 'G'
"""
P = self.parent()
try:
return P.retract(P.lift(self) * P.lift(other))
except:
return P.retract(P.lift(self)*other)
def _lmul_(self, right):
"""
Give the product of ``self*right``
EXAMPLES::
sage: M = CombinatorialFreeModule(QQ,[1,2,3])
sage: G = CyclicPermutationGroup(3)
sage: g = G.an_element(); g
(1,2,3)
sage: from sage.modules.with_basis.representation import Representation
sage: from sage.modules.with_basis.invariant import FiniteDimensionalInvariantModule
sage: R = Representation(G,M,lambda g,x: M.monomial(g(x)), side = 'right')
sage: I = FiniteDimensionalInvariantModule(R)
sage: v = I.an_element(); v
2*B[0]
sage: v*g
2*B[0]
sage: [v*g for g in G.list()]
[2*B[0], 2*B[0], 2*B[0]]
sage: G = CyclicPermutationGroup(3)
sage: M = algebras.Exterior(QQ, 'x', 3)
sage: from sage.modules.with_basis.representation import Representation
sage: on_basis = lambda g,m: M.prod([M.monomial((g(j+1)-1,)) for j in m]) #cyclically permute generators
sage: from sage.categories.algebras import Algebras
sage: R = Representation(G, M, on_basis, category=Algebras(QQ).WithBasis().FiniteDimensional(), side = 'right')
sage: I = FiniteDimensionalInvariantModule(R)
sage: B = I.basis()
sage: [I.lift(b) for b in B]
[1, x0 + x1 + x2, x0*x1 - x0*x2 + x1*x2, x0*x1*x2]
sage: [[b*g for g in G] for b in B]
[[B[0], B[0], B[0]],
[B[1], B[1], B[1]],
[B[2], B[2], B[2]],
[B[3], B[3], B[3]]]
sage: 3*I.basis()[0]
3*B[0]
sage: 3*B[0] + B[1]*2
3*B[0] + 2*B[1]
"""
if right in self.parent()._semigroup and self.parent()._semigroup_representation.side() == 'right':
return self
elif right in self.parent()._semigroup_representation._module.base_ring():
# This preserves the structure of the invariant as a
# ``.base_ring()``-module
return self._mul_(right)
return super()._lmul_(right)
def _rmul_(self, left):
"""
Give the product of ``left * self``
EXAMPLES::
sage: M = CombinatorialFreeModule(QQ,[1,2,3])
sage: G = CyclicPermutationGroup(3)
sage: g = G.an_element(); g
(1,2,3)
sage: from sage.modules.with_basis.representation import Representation
sage: from sage.modules.with_basis.invariant import FiniteDimensionalInvariantModule
sage: R = Representation(G,M,lambda g,x: M.monomial(g(x)))
sage: I = FiniteDimensionalInvariantModule(R)
sage: v = I.an_element(); v
2*B[0]
sage: g*v
2*B[0]
sage: [g*v for g in G.list()]
[2*B[0], 2*B[0], 2*B[0]]
sage: G = CyclicPermutationGroup(3)
sage: M = algebras.Exterior(QQ, 'x', 3)
sage: on_basis = lambda g,m: M.prod([M.monomial((g(j+1)-1,)) for j in m]) #cyclically permute generators
sage: from sage.categories.algebras import Algebras
sage: R = Representation(G, M, on_basis, category=Algebras(QQ).WithBasis().FiniteDimensional())
sage: I = FiniteDimensionalInvariantModule(R)
sage: B = I.basis()
sage: [I.lift(b) for b in B]
[1, x0 + x1 + x2, x0*x1 - x0*x2 + x1*x2, x0*x1*x2]
sage: [[g*b for g in G] for b in B]
[[B[0], B[0], B[0]],
[B[1], B[1], B[1]],
[B[2], B[2], B[2]],
[B[3], B[3], B[3]]]
sage: 3*I.basis()[0]
3*B[0]
sage: 3*B[0] + B[1]*2
3*B[0] + 2*B[1]
"""
if left in self.parent()._semigroup and self.parent()._semigroup_representation.side() == 'left':
return self
elif left in self.parent()._semigroup_representation._module.base_ring():
return self._mul_(left)
return super()._rmul_(left)
def _acted_upon_(self, scalar, self_on_left = False):
"""
EXAMPLES::
sage: G = CyclicPermutationGroup(3)
sage: M = CombinatorialFreeModule(QQ,[1,2,3])
sage: from sage.modules.with_basis.representation import Representation
sage: R = Representation(G, M, lambda g,x: M.monomial(g(x)))
sage: from sage.modules.with_basis.invariant import FiniteDimensionalInvariantModule
sage: I = FiniteDimensionalInvariantModule(R)
sage: B = I.basis()
sage: [b._acted_upon_(G((1,3,2))) for b in B]
[B[0]]
sage: R = Representation(G, M, lambda g,x: M.monomial(g(x)), side = 'right')
sage: I = FiniteDimensionalInvariantModule(R)
sage: B = I.basis()
sage: [b._acted_upon_(G((1,3,2)), self_on_left = True) for b in B]
[B[0]]
sage: R = G.regular_representation(QQ)
sage: I = FiniteDimensionalInvariantModule(R)
sage: B = I.basis()
sage: [I.lift(b) for b in B]
[() + (1,2,3) + (1,3,2)]
sage: B[0]._acted_upon_(G((1,3,2)))
B[0]
sage: B[0]._acted_upon_(G((1,3,2)), self_on_left=True) == None
True
sage: R = G.regular_representation(QQ, side = 'right')
sage: I = FiniteDimensionalInvariantModule(R)
sage: B = I.basis()
sage: [I.lift(b) for b in B]
[() + (1,2,3) + (1,3,2)]
sage: g = G((1,3,2))
sage: B[0]._acted_upon_(g, self_on_left = True)
B[0]
sage: B[0]._acted_upon_(g, self_on_left = False) == None
True
"""
if scalar in self.parent()._semigroup and self_on_left == (self.parent()._semigroup_representation.side() == 'right'):
return self
return None
# Group action should be lifted on the module because????
# Confused about the representatoin vs lift to module business.
class FiniteDimensionalTwistedInvariantModule(SubmoduleWithBasis):
r"""
Construct the `\chi`-twisted invariant submodule of `M`. When a semigroup `S` acts on a module
`M`, the `\chi`-twisted invariant submodule of `M` is the isotypic component of the representation
`M` corresponding to the irreducible character `\chi`.
.. NOTE:
The current implementation works when `S` is a finitely-generated semigroup,
and when `M` is a finite-dimensional free module with a distinguished basis.
# """
# def __init__(self, R, character = 'trivial'):
# super.__init__(R)
# if character != 'trivial':
# pass
# def projection(self, element):
# """
# Give the projection of element (in `self.module()`) onto self
# """
# pass
# # class Element
# # _lmul_
# # _rmul_
# # _acted_upon_