-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonodromyGroupFunctions.sage
2016 lines (1497 loc) · 48.8 KB
/
MonodromyGroupFunctions.sage
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
#
#
# Auxiliar functions for braid monodromies and groups.
# Developed by:
#
#
# Enrique Artal Bartolo
# ...Departamento de Matematicas-IUMA
# Universidad de Zaragoza
#
# Last update: 23-11-2019
#
#
from sage.groups.finitely_presented import wrap_FpGroup
#
def LibreNorm(a):
r"""
Return the cyclic reduction of `a` as member of a free group.
INPUT:
- ``a`` -- word of a free group (default: None)
OUTPUT:
The cyclic reduction of the word
EXAMPLES:
This example illustrates a simple use of this function
::
sage: F=FreeGroup(3)
sage: a=F([1,2,-1])
sage: LibreNorm(a)
x1
"""
F=a.parent()
n=F.rank()
L=a.Tietze()
if len(L)<1:
return (F(1))
primero=(L[0]+L[-1]==0)
while primero:
L=L[1:-1]
primero=(L[0]+L[-1]==0)
return (F(L))
def LibreConj(a,b):
r"""
Checks if `a` and `b` are conjugate in their free group.
INPUT:
- ``a`` -- word of a free group (default: None)
- ``b`` -- word of a free group (default: None)
OUTPUT:
``True`` if the words are conjugate, ``False`` if not.
EXAMPLES:
This example illustrates a simple use of this function
::
sage: F=FreeGroup(3)
sage: a=F([2,1,-3,2])
sage: b=F([-3,2,2,1])
sage: LibreConj(a,b)
True
"""
F=a.parent()
n=F.rank()
g=LibreNorm(a)
h=LibreNorm(b)
L=list(g.Tietze())
M=list(h.Tietze())
l=len(L)
if l!=len(M):
return (False)
distintas=True
j=0
while distintas and j<l:
distintas=(L!=M)
L=L[1:]+[L[0]]
j=j+1
return (not distintas)
def revertirF(a):
r"""
Realizes the anti-automorphism $\\varphi:\\mathbb{F}_n\\to\\mathbb{F}_n$
such that $x_i\\mapsto x_{n-1-i}$, $i=0,1\\dots,n-1$.
INPUT:
- ``a`` -- word of a free group (default: None)
OUTPUT:
Reverts the image by $\\varphi$ of `a`.
EXAMPLES:
This example illustrates a simple use of this function
::
sage: F=FreeGroup(3)
sage: a=F([2,1,-3,2])
sage: revertirF(a)
x1*x2*x0^-1*x1
"""
F=a.parent()
n=F.rank()
L=a.Tietze()
L1=(v.sign()*(n+1-v.abs()) for v in L)
return (F(L1))
def revertirT(b):
r"""
Realizes the anti-automorphism $\\varphi:\\mathbb{B}_n\\to\\mathbb{B}_n$
such that $x_i\\mapsto x_{n-2-i}$, $i=0,1\\dots,n-2$.
INPUT:
- ``b`` -- a braid (default: None)
OUTPUT:
Returns the image of `b` by $\\varphi$.
EXAMPLES:
This example illustrates a simple use of this function
::
sage: F=BraidGroup(3)
sage: a=F([2,1,-2,1])
sage: revertirF(a)
s0*s1^-1*s0*s1
"""
B=b.parent()
n=B.strands()
L=b.Tietze()
L1=(v.sign()*(n-v.abs()) for v in L)
return (B(L1))
def LibreTrenza(libre,trenza):
r"""
It defines another left action of the braid group $\\mathbb{B}_n$ on the free group
$\\mathbb{F}_n$. Unlike the defined by ``x*s``, in this case, the image of $x_i$ and $s_i$
equals $x_{i+1}$ and the image of $x_{i+1}$ and $s_i$ equals $x_{i+1} x_i x_{i+1}^{-1}$.
INPUT:
- ``libre`` -- an element of the free group of some rank `n`
- ``trenza`` -- a braid in `n`of strands
OUTPUT:
Returns this differently normalized braid action.
EXAMPLES:
This example illustrates a simple use of this function
::
sage: F=FreeGroup(3)
sage: B=BraidGroup(3)
sage: a=F([2,1,-3,2])
sage: s=B([2])
sage: a*s
x1*x2*x1^-1*x0*x2*x1^-1
sage: LibreTrenza(a,s)
x2*x0*x2*x1^-1
"""
g=libre
s=trenza
return (revertirF(revertirF(g)*revertirT(s)))
def conjtrenza(lista,n):
r"""
It converts a list ``lista`` containing two lists of integers into a braid. Each sublist corresponds via Tietze
with a braid in ``n`` strands, say $t_1,t_2$. The result is the braid $t_1 t_2 t_1^{-1}$.
INPUT:
- ``lista`` -- a list of two sublists of non-zero integers coding two braids
- ``n`` -- the number of strands
OUTPUT:
The left conjugation of the first braid to the second one.
EXAMPLES:
This example illustrates a simple use of this function
::
sage: conjtrenza([[1,3,2],[2,1]],4)
s0*s2*s1^2*s0*s1^-1*s2^-1*s0^-1
"""
B=BraidGroup(n)
u0,v0=[B(a) for a in lista]
return (u0*v0/u0)
def relstrenzaconj(lista,n):
r"""
This function is to be used to compute a fundamental group from a braid monodromy. A list ``lista`` contains
Tietze lists of integers to produce two braids $t_1,t_2$. The central braid is positive and connected and involves,
$r$ strands from $i$ to $i+r-1$. The result is a list of words in the free group of the form
$(x_j^{-1} x_j^{t_2} )^{t_1^{-1}}$ for $j=i,\\dots,i+r-2$.
INPUT:
- ``lista`` -- a list of two sublists of non-zero integers coding two braids, the second one, positive and connected.
- ``n`` -- the number of strands
OUTPUT:
A list of words in the free group of rank `n`.
EXAMPLES:
This example illustrates a simple use of this function
::
sage: relstrenzaconj([[1,2],[3]],4)
[x0^-1*x3]
sage: relstrenza([[1,2],[3]],4)
[x0^-1*x3, x1^-1*x3*x0^-1*x1*x0*x3^-1, x2^-1*x3*x0^-1*x2*x0*x3^-1, x0*x3^-1]
"""
B=BraidGroup(n)
F=FreeGroup(n)
a,b=lista
t1=B(a)^-1
t0=B(b)
bv=[v.abs() for v in b]
m=min(bv)
M=max(bv)
rel0=[v^-1*LibreTrenza(v,t0) for v in F.gens()[m-1:M]]
return ([LibreTrenza(v,t1) for v in rel0])
def relstrenza(lista,n):
r"""
This function is to be used to compute a fundamental group from a braid monodromy. A list ``lista`` contains
Tietze lists of integers to produce two braids $t_1,t_2$. It returns the list of $x_j^{-1} x_j^{t_2 t_1 t_2^{-1}}$.
INPUT:
- ``lista`` -- a list of two sublists of non-zero integers coding two braids.
- ``n`` -- the number of strands
OUTPUT:
A list of `n` words in the free group of rank `n`.
EXAMPLES:
This example illustrates a simple use of this function
::
sage: relstrenzaconj([[1,2],[3]],4)
[x0^-1*x3]
sage: relstrenza([[1,2],[3]],4)
[x0^-1*x3, x1^-1*x3*x0^-1*x1*x0*x3^-1, x2^-1*x3*x0^-1*x2*x0*x3^-1, x0*x3^-1]
"""
F=FreeGroup(n)
t0=conjtrenza(lista,n)
rel0=[v^-1*LibreTrenza(v,t0) for v in F.gens()]
return (rel0)
def invertirlista(lista):
r"""
Given a Tietze list ``lista``, it provides the Tietze list of the inverse.
INPUT:
- ``lista`` -- a list of non-zero integers coding a word in a free group
OUTPUT:
The Tietze list of the inverse of ``lista``.
EXAMPLES:
This example illustrates a simple use of this function
::
sage: invertirlista([2,-1,3])
[-3, 1, -2]
"""
return ([-_ for _ in reversed(lista)])
def cambio_rel(lista,nuevo,elim):
r"""
Given two Tietze lists ``lista`` (representing a group word $w$), ``nuevo`` (representing another word $u$),
and a positive integer ``elim`` (representing a generator $x_i$), we replace each occurrence
of ``elim`` or its opposite in ``lista`` by the elements in ``nuevo`` (or its reversed opposite). The generator
$x_i$ equals the word $w$, where a new generator $y_i$ (or its inverse) appears exactly once.
INPUT:
- ``lista`` -- a list of non-zero integers
- ``nuevo`` -- a replacing list of non-zero integers
- ``elim`` -- the integer to be replaced.
OUTPUT:
A list representing the Tietze list of the word after the replacement of the generator.
EXAMPLES:
This example illustrates a simple use of this function
::
sage: cambio_rel([1,3,-5,2,6,5],[2,5,3,-6],5)
[1, 3, 6, -3, -5, -2, 2, 6, 2, 5, 3, -6]
"""
pal=[]
inv_nuevo=invertirlista(nuevo)
for i in lista:
if i.abs()!=elim:
pal+=[i]
elif i==elim:
pal+=nuevo
elif i==-elim:
pal+=inv_nuevo
return (pal)
def cambio(grupo,elim_nuevo,elim,lista=[]):
r"""
Given a group ``grupo``, a generator $x_i$ (represented by its index $i\\equiv$``elim``), the list
``nuevo`` represents a word to eliminate $x_i$ in terms of a new generator which will have the same index.
As an option one can add a list ``lista`` of Tietze words representing elements of the group.
INPUT:
- ``grupo`` -- a SAGE finitely presented group
- ``elim_nuevo`` -- a replacing list of non-zero integers
- ``elim`` -- the integer to be replaced.
- ``lista`` -- an optional list (default: ``[]``) of words to rewrite.
OUTPUT:
The finitely presented group in the new generators, and the translation
of the elements in ``lista``.
EXAMPLES:
This example illustrates a simple use of this function
::
sage: F=FreeGroup(3)
sage: rlk=[F.gen(0)^2,F([2,3])^2]
sage: G=F/rlk
sage: G1=cambio(G,[2,-3],2)[0]
sage: G1.relations()
(x0^2, x1^2)
"""
rels=[_.Tietze() for _ in grupo.relations()]
m=len(grupo.generators())
inv_elim_nuevo=invertirlista(elim_nuevo)
rlk=[cambio_rel(_,elim_nuevo,elim) for _ in rels]
listares=[cambio_rel(_,elim_nuevo,elim) for _ in lista]
F0=FreeGroup(m)
listares=[F0(_).Tietze() for _ in listares]
g=F0/rlk
P=g.gap().PresentationFpGroup()
P.TzSearch()
P.TzSearch()
P.TzSearch()
P.TzSearchEqual()
return ([wrap_FpGroup(P.FpGroupPresentation()),listares])
def cambio_elim(lista,pal,elim):
r"""
Given two Tietze lists ``lista`` (representing a group word $w$), ``pal`` (representing another word $u$),
where the generator $x_i$ (represented by the positive integer ``elim``), does not appear.
We replace each occurence of ``lista`` by the word $u$; we shift by $-1$ the indices
greater that $i$ since we deal with one less generator.
INPUT:
- ``lista`` -- a list of non-zero integers
- ``pal`` -- a replacing list of non-zero integers where $\\pm$``elim``does not appear.
- ``elim`` -- the integer to be replaced.
OUTPUT:
A list with the replacement of ``elim`` and the shifting of indices.
EXAMPLES:
This example illustrates a simple use of this function
::
sage: cambio_elim([2,1-3,4],[-2,1],3)
[2, -2, 3]
"""
p=[]
for i in lista:
if i.abs()<elim:
p.append(i)
elif i.abs()>elim:
p.append(i.sign()*(i.abs()-1 ))
elif i==elim:
p+=pal
elif i==-elim:
p+=palinv
return (p)
def eliminar(grupo,generador,lista=[]):
r"""
Given a group ``grupo``, a generator $x_i$ (represented by its index $i\\equiv$ ``generador``), the lista
``nuevo`` represents a word to eliminate $x_i$ in terms of a new generator which will have the same index.
As an option one can add a list ``lista`` of Tietze words representing elements of the group. If the generator
can be eliminated, it produces a new presentation with that generator erased; if not, the group remains unchanged.
INPUT:
- ``grupo`` -- a SAGE finitely presented group
- ``generador`` -- the integer representing the generator to be eliminated.
- ``lista`` -- an optional list (default: ``[]``) of words to rewrite.
OUTPUT:
The finitely presented group with, eventually, one less generator, and the translation
of the elements in ``lista``.
EXAMPLES:
This example illustrates a simple use of this function
::
sage: F=FreeGroup(3)
sage: rlk=[F.gen(0)^2,F([1])*F([2,3])^2]
sage: G=F/rlk
sage: G1=eliminar(G,1)[0]
sage: G1.relations()
((x1^-1*x0^-1)^4,)
"""
rels=[_.Tietze() for _ in grupo.relations()]
aux=[[i.abs() for i in _] for _ in rels]
ind=[j for j in range(len(rels)) if aux[j].count(generador)==1 ]
if ind==[]:
return (grupo)
cnt=[len(rels[j]) for j in ind]
m=min(cnt)
rel=rels[ind[cnt.index(m)]]
if generador in rel:
rel=invertirlista(rel)
j=rel.index(-generador)
pal0=rel[j+_sage_const_1 :]+rel[:j]
pal=[]
for i in pal0:
if i.abs()<generador:
pal.append(i)
elif i.abs()>generador:
pal.append(i.sign()*(i.abs()-1 ))
palinv=invertirlista(pal)
newrels=[cambio_elim(_,pal,generador) for _ in rels]
listares=[cambio_elim(_,pal,generador) for _ in lista]
n=len(grupo.generators())
F=FreeGroup(n-1 )
listares=[F(_).Tietze() for _ in listares]
rlk=[F(_) for _ in newrels]
g=F/rlk
P=g.gap().PresentationFpGroup()
P.TzSearch()
P.TzSearch()
P.TzSearchEqual()
return ([wrap_FpGroup(P.FpGroupPresentation()),listares])
def CyclicComm(lista):
r"""
The elements of the list ``lista`` belong to a group.
INPUT:
- ``lista`` -- a list of elements of a group.
OUTPUT:
The list of reduced commutators of all (but one) elements of the list with the product of all of them.
EXAMPLES:
This example illustrates a simple use of this function
::
sage: F=FreeGroup(4)
sage: L=F.gens()
sage: CyclicComm(L)
[x1*x0*x1*x2*x3*x1^-1*x3^-1*x2^-1*x1^-1*x0^-1,
x2*x0*x1*x2*x3*x2^-1*x3^-1*x2^-1*x1^-1*x0^-1,
x3*x0*x1*x2*x3^-1*x2^-1*x1^-1*x0^-1]
"""
n=len(lista)
if n<2:
return ([])
pr=prod(lista)
res=[]
for a in lista[1:]:
res.append(a*pr/a/pr)
return (res)
def GtoK(G,elto,K):
r"""
Given an element ``elto`` a group ``G``, and a quotient ``K`` of it, write down its image in $K$. This function writes
it as a word in the generators of $K$.
INPUT:
- ``G`` -- A finitely presented group of GAP.
- ``elto`` -- An element of `K` as word in `G.
- ``K`` -- A subgroup of `G`, element of GAP.
OUTPUT:
The element ``elto`` written in $K$.
EXAMPLES:
This example illustrates a simple use of this function
::
sage: F=FreeGroup(2)
sage: rel=[F([1,2])^3]
sage: G=F/rel
sage: a=G([2])^2
sage: g=G.gap()
sage: u=a.gap()
sage: K=g.FactorGroupFpGroupByRels([u])
sage: K=g.FactorGroupFpGroupByRels([u^2])
sage: GtoK(g,u,K)
x1^2
"""
epiG=G.EpimorphismFromFreeGroup()
epiK=K.EpimorphismFromFreeGroup()
pal=epiG.PreImagesRepresentative(elto)
num=pal.TietzeWordAbstractWord(epiG.Source().GeneratorsOfGroup())
return (epiK.Image(num.AbstractWordTietzeWord(epiK.Source().GeneratorsOfGroup())))
def GtoTietze(G,elto):
r"""
Given an element ``elto`` of a GAP group ``G`` this function provides a Tietze list.
INPUT:
- ``G`` -- A finitely presented group of GAP.
- ``elto`` -- An element of `G`.
OUTPUT:
A Tietze list.
EXAMPLES:
This example illustrates a simple use of this function
::
sage: F=FreeGroup(2); rel=[F([1,2])^3]; G=F/rel
sage: a=G([2])^2; g=G.gap(); u=a.gap()
sage: GtoTietze(g,u)
[ 2, 2 ]
"""
epiG=G.EpimorphismFromFreeGroup()
pal=epiG.PreImagesRepresentative(elto)
num=pal.TietzeWordAbstractWord(epiG.Source().GeneratorsOfGroup())
return (num.sage())
def abelianizar(tz,m):
r"""
Given an Tietze list ``tz`` from a free group of rank ``m``, it returns the abelianization vector.
INPUT:
- ``tz`` -- A Tietze list.
- ``m`` -- An integer.
OUTPUT:
An integer vector such that the $i$-entry is the algebraic sum
of the number of $\\pm i$ entries.
EXAMPLES:
This example illustrates a simple use of this function
::
sage: abelianizar([2,4,-1,2,1],4)
(0, 2, 0, 1)
"""
v=vector(ZZ,m)
L=FreeModule(ZZ,m)
B=L.basis()
for i in tz:
signo=i.sign()
absoluto=i.abs()
v=v+signo*B[absoluto-1]
return (v)
def MatrizAbel(grupo):
r"""
The matrix of the abelianization of the relations of a f.p. group.
INPUT:
- ``grupo`` -- A finitely presented group.
OUTPUT:
An integer valued matrix with as many rows as relations and as many columns
as generators. Each row represents the abelianization of the relation.
EXAMPLES:
This example illustrates a simple use of this function
::
sage: B=BraidGroup(4)
sage: MatrizAbel(B)
[ 1 -1 0]
[ 0 0 0]
[ 0 1 -1]
"""
m=len(grupo.gens())
TZ=map(lambda v:v.Tietze(),grupo.relations())
A=[]
for tz in TZ:
A.append(abelianizar(tz,m))
return (Matrix(A))
def CambioVarSmith(matriz,smith,tt):
r"""
The matrix ``matriz`` is an invertible matrix whose size $n$ is related to the number of generators
of a group. The matrix ``smith`` is a diagonal $m\\times n$ where $m$ is related to the number of generators.
The tuple ``tt`` is formed by the variables of a Laurent polynomial ring.
INPUT:
- ``matriz`` -- An $n\\times n$ invertible matrix over $\\mathbb{Z}$.
- ``smith`` -- An $m\\times n$ diagonal matrix over $\\mathbb{Z}$.
- ``tt`` -- Tuple of variables of a Laurent polynomial ring.
OUTPUT:
A dictionnary realizing the relations of the variables and an ideal generated by $t_i^{d_i}-1$ for the
diagonal terms $>1$.
EXAMPLES:
This example illustrates a simple use of this function
::
sage: R=LaurentPolynomialRing(QQ,'t',4)
sage: A=random_matrix(ZZ,3,4)
sage: S,U,V=A.smith_form()
sage: S
[1 0 0 0]
[0 1 0 0]
[0 0 2 0]
sage: CambioVarSmith(V,S,R.gens())
({t3: t3^357, t2: t2*t3^-86, t1: t3^53, t0: t2*t3^-2043}, [t2^2 - 1])
"""
A=matriz
Sm=smith
n=A.nrows()
n1=min(Sm.dimensions())
I=[]
for i in range(n):
if i<n1 and Sm[i,i]>1:
I.append(tt[i]^Sm[i,i]-1)
dic={}
for i in range(n):
T=1
for j in range(n):
if j<n1 and Sm[j,j]>0:
m=A[i,j].quo_rem(Sm[j,j])[1]
else:
m=A[i,j]
T=T*(tt[j]^m)
dic.update({tt[i]:T})
return (dic,I)
def caracter(x,R,cambio):
r"""
Given an element `x` in the group algebra of a free group, we apply to it a character
defined by a dictionnary ``cambio`` to obtain an element in a Laurent polynomial ring `R`.
INPUT:
- ``x`` -- An element in $\\mathbb{Z}[\\mathbb{F}_n]$.
- ``R`` -- A ring, usually polynomial or Laurent polynomial.
- ``cambio`` -- A dictionnary changing the variables.
OUTPUT:
The image by the character of the element $x$.
EXAMPLES:
This example illustrates a simple use of this function
::
sage: F=FreeGroup(2)
sage: A=F.algebra(QQ)
sage: a=A(F([1,2,-1,-2]))+3*A(F([2,1,2]))
sage: R.<t0,t1>=LaurentPolynomialRing(QQ)
sage: cambio={t1:t0,t0:t0^-2*t1}
sage: caracter(a,R,cambio)
3*t1 + 1
"""
tt=R.gens()
res=R(0)
for i in list(x):
res+=i[1]*prod([tt[abs(j)-1]^sign(j) for j in i[0].Tietze()])
return (res.subs(cambio))
def unidades(f,R):
r"""
If a Laurent polynomial ``f`` in a ring ``R`` is non zero, it can be written as a unit and
a polynomial divided by no variable.
INPUT:
- ``f`` -- A Laurent polynomial.
- ``R`` -- The ring of $f$.
OUTPUT:
Either zero or the maximal unit.
EXAMPLES:
This example illustrates a simple use of this function
::
sage: R=LaurentPolynomialRing(QQ,3,'t')
sage: f=random_vector(QQ,4)
sage: g1=random_vector(ZZ,4)
sage: g2
(0, 0, 2, 1)
sage: R=LaurentPolynomialRing(QQ,3,'t')
sage: f=random_vector(QQ,4)
sage: g1=random_vector(ZZ,4)
sage: g2=random_vector(ZZ,4)
sage: p=sum(i*R.gen(0)^j*R.gen(1)^k for (i,j,k) in zip(f,g1,g2))
sage: p
-3*t0^3*t1^8 - t0*t1^-1 - 9/2*t1^-13
sage: unidades(p,R)
t1^-13
"""
if f==f.parent(0):
return (0)
ex=f.exponents()
n=f.parent().ngens()
u=1
for j in range(n):
mx=min([v[j] for v in ex])
u=u*R.gen(j)^mx
return (u)
def unidadeslista(lista,R):
r"""
Given a list ``lista`` of Laurent polynomials in a ring ``R``, it extracts the maximal commun unit. To be used with
base ring of characteristic zero.
INPUT:
- ``lista`` -- A list of Laurent polynomials.
- ``R`` -- The ring of the elements in ``lista``.
OUTPUT:
Either zero or the maximal unit.
EXAMPLES:
This example illustrates a simple use of this function
::
sage: R=LaurentPolynomialRing(QQ,3,'t')
sage: F=[random_vector(QQ,4) for i in range(4)]
sage: G1=[random_vector(ZZ,4) for i in range(4)]
sage: G2=[random_vector(ZZ,4) for i in range(4)]
sage: P=[sum(i*R.gen(0)^j*R.gen(1)^k for (i,j,k) in zip(f,g1,g2)) for (f,g1,g2) in zip(F,G1,G2)]
sage: P
[t0^5*t1^-1 - t0^2 + 9*t0*t1 + 1/5*t0^-6*t1^-1,
3/8*t0^-1*t1^2 + 3*t0^-1*t1^-1 - 1/3*t0^-3*t1,
-2*t0*t1^3 + 16*t1^4,
-207/704*t1^-1 - 2*t0^-2]
sage: unidadeslista(P,R)
t0^-6*t1^-1
"""
monomios=sum([unidades(_,R) for _ in lista])
return (unidades(monomios,R))
def unidadesmatriz(matriz,R,O='R'):
r"""
This function extracts the maximal commun unit for each row (or column) of a matrix ``matriz``
of polynomials or Laurent polynomials in a ring ``R``. The default choice of ``O`` is ``R`` (rows); the column
choice follow if ``O='C'``.
INPUT:
- ``matrix`` -- A matrix of Laurent polynomials.
- ``R`` -- The ring of the elements in ``lista``.
- ``O`` -- A chain of one character, ``'R'`` (for rows), ``'C'`` (for columns) (default: 'R').
OUTPUT:
A matrix of polynomials with no variable as common divisor in the rows or columns.
EXAMPLES:
This example illustrates a simple use of this function
::
sage: R=LaurentPolynomialRing(QQ,3,'t')
sage: F=[random_vector(QQ,4) for i in range(6)]
sage: G1=[random_vector(ZZ,4) for i in range(6)]
sage: G2=[random_vector(ZZ,4) for i in range(6)]
sage: P=[sum(i*R.gen(0)^j*R.gen(1)^k for (i,j,k) in zip(f,g1,g2)) for (f,g1,g2) in zip(F,G1,G2)]
sage: A=Matrix(R,3,P)
sage: A
[ 39/2*t0^3*t1^-1 - 1/23*t0*t1^-1 - 12*t0^-2*t1 -3/2*t1^46 + 48*t0^4*t1^2 + 2*t0^-1*t1 + t0^-1*t1^-3]
[ -t0^10*t1^5 - 4*t0^6 - 4/221*t0*t1^-20 2*t0*t1^-1 - 6 + 1/63*t0^-2]
[ 49*t1^-1 -1/2 - 1/3*t0^-3*t1^3 - 3/8*t1^-1 + 9*t0^2*t1^-5]
sage: unidadesmatriz(unidadesmatriz(A,R),R,O='C')
[ 39/2*t0^5*t1^2 - 1/23*t0^3*t1^2 - 12*t1^4 -3/2*t0^2*t1^49 + 48*t0^6*t1^5 + 2*t0*t1^4 + t0]
[ -t0^12*t1^25 - 4*t0^8*t1^20 - 4/221*t0^3 2*t0^3*t1^19 - 6*t0^2*t1^20 + 1/63*t1^20]
[ 49*t0^3*t1^4 -1/2*t0^3*t1^5 - 1/3*t1^8 - 3/8*t0^3*t1^4 + 9*t0^5]
"""
if O=='C':
return (unidadesmatriz(matriz.transpose(),R).transpose())
A=matriz.change_ring(R)
n=A.nrows()
L=A.rows()
U=[unidadeslista(_,R) for _ in L]
for i in range(n):
if U[i]!=A.base_ring()(0):
L[i]=U[i]^-1*L[i]
return (Matrix(L))
def Hay_unidades(A,R,S,dividir=False):
r"""
This function checks if there is a unit in a matrix of polynomials or Laurent polynomials in a ring ``R``. There is an optional parameter ``dividir`` having as default value ``False``.
INPUT:
- ``A`` -- A matrix of polynomials or Laurent polynomials.
- ``R`` -- A ring of Laurent polynomials.
- ``S`` -- The associated ring of polynomials.
- ``dividir`` -- A boolean.
OUTPUT:
If there is no unit (over the integers if ``dividir`` is ``False``) the output is ``None``; if not, the position of the first unit.
EXAMPLES:
This example illustrates a simple use of this function
::
sage: R=LaurentPolynomialRing(QQ,1,'t')
sage: A=Matrix(R,2,2,[R.gen(0)^-1,2,R.gen(0),R.gen(0)-1])
sage: Hay_unidades(A,R,R.polynomial_ring())
(0,0)
sage: A.rescale_col(0,2*R.gen(0)^2)
sage: Hay_unidades(A,R,R.polynomial_ring())==None
(0,0)
"""
res=None
n,m=A.dimensions()
i=0
j=0
while res==None and j<m:
if R(A[i,j]).is_unit():
if not dividir and A[i,j].coefficients()[0]^2==1:
res=(i,j)
elif dividir:
res=(i,j)
i+=1
if i==n:
j+=1
i=0
return (res)
def reducir_matriz(A,R,S,ideal,dividir=False):
r"""This function performs standard matrix operations eliminating such that the new matrix represents the same module
INPUT: