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
/
steenrod_algebra_misc.py
1143 lines (941 loc) · 38.9 KB
/
steenrod_algebra_misc.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
"""
Miscellaneous functions for the Steenrod algebra and its elements
AUTHORS:
- John H. Palmieri (2008-07-30): initial version (as the file
steenrod_algebra_element.py)
- John H. Palmieri (2010-06-30): initial version of steenrod_misc.py.
Implemented profile functions. Moved most of the methods for
elements to the ``Element`` subclass of
:class:`sage.algebras.steenrod.steenrod_algebra.SteenrodAlgebra_generic`.
The main functions here are
- :func:`get_basis_name`. This function takes a string as input and
attempts to interpret it as the name of a basis for the Steenrod
algebra; it returns the canonical name attached to that basis. This
allows for the use of synonyms when defining bases, while the
resulting algebras will be identical.
- :func:`normalize_profile`. This function returns the canonical (and
hashable) description of any profile function. See
:mod:`sage.algebras.steenrod.steenrod_algebra` and
:func:`SteenrodAlgebra <sage.algebras.steenrod.steenrod_algebra.SteenrodAlgebra>`
for information on profile functions.
- functions named ``*_mono_to_string`` where ``*`` is a basis name
(:func:`milnor_mono_to_string`, etc.). These convert tuples
representing basis elements to strings, for _repr_ and _latex_
methods.
"""
#*****************************************************************************
# Copyright (C) 2008-2010 John H. Palmieri <palmieri@math.washington.edu>
# Distributed under the terms of the GNU General Public License (GPL)
#*****************************************************************************
######################################################
# basis names
_steenrod_milnor_basis_names = ['milnor']
_steenrod_serre_cartan_basis_names = ['serre_cartan', 'serre-cartan', 'sc',
'adem', 'admissible']
def get_basis_name(basis, p, generic=None):
"""
Return canonical basis named by string basis at the prime p.
INPUT:
- ``basis`` - string
- ``p`` - positive prime number
- ``generic`` - boolean, optional, default to 'None'
OUTPUT:
- ``basis_name`` - string
Specify the names of the implemented bases. The input is
converted to lower-case, then processed to return the canonical
name for the basis.
For the Milnor and Serre-Cartan bases, use the list of synonyms
defined by the variables :data:`_steenrod_milnor_basis_names` and
:data:`_steenrod_serre_cartan_basis_names`. Their canonical names
are 'milnor' and 'serre-cartan', respectively.
For the other bases, use pattern-matching rather than a list of
synonyms:
- Search for 'wood' and 'y' or 'wood' and 'z' to get the Wood
bases. Canonical names 'woody', 'woodz'.
- Search for 'arnon' and 'c' for the Arnon C basis. Canonical
name: 'arnonc'.
- Search for 'arnon' (and no 'c') for the Arnon A basis. Also see
if 'long' is present, for the long form of the basis. Canonical
names: 'arnona', 'arnona_long'.
- Search for 'wall' for the Wall basis. Also see if 'long' is
present. Canonical names: 'wall', 'wall_long'.
- Search for 'pst' for P^s_t bases, then search for the order
type: 'rlex', 'llex', 'deg', 'revz'. Canonical names:
'pst_rlex', 'pst_llex', 'pst_deg', 'pst_revz'.
- For commutator types, search for 'comm', an order type, and also
check to see if 'long' is present. Canonical names:
'comm_rlex', 'comm_llex', 'comm_deg', 'comm_revz',
'comm_rlex_long', 'comm_llex_long', 'comm_deg_long',
'comm_revz_long'.
EXAMPLES::
sage: from sage.algebras.steenrod.steenrod_algebra_misc import get_basis_name
sage: get_basis_name('adem', 2)
'serre-cartan'
sage: get_basis_name('milnor', 2)
'milnor'
sage: get_basis_name('MiLNoR', 5)
'milnor'
sage: get_basis_name('pst-llex', 2)
'pst_llex'
sage: get_basis_name('wood_abcdedfg_y', 2)
'woody'
sage: get_basis_name('wood', 2)
Traceback (most recent call last):
...
ValueError: wood is not a recognized basis at the prime 2.
sage: get_basis_name('arnon--hello--long', 2)
'arnona_long'
sage: get_basis_name('arnona_long', p=5)
Traceback (most recent call last):
...
ValueError: arnona_long is not a recognized basis at the prime 5.
sage: get_basis_name('NOT_A_BASIS', 2)
Traceback (most recent call last):
...
ValueError: not_a_basis is not a recognized basis at the prime 2.
sage: get_basis_name('woody', 2, generic=True)
Traceback (most recent call last):
...
ValueError: woody is not a recognized basis for the generic Steenrod algebra at the prime 2.
"""
if generic is None:
generic = False if p==2 else True
basis = basis.lower()
if basis in _steenrod_milnor_basis_names:
result = 'milnor'
elif basis in _steenrod_serre_cartan_basis_names:
result = 'serre-cartan'
elif basis.find('pst') >= 0:
if basis.find('rlex') >= 0:
result = 'pst_rlex'
elif basis.find('llex') >= 0:
result = 'pst_llex'
elif basis.find('deg') >= 0:
result = 'pst_deg'
elif basis.find('revz') >= 0:
result = 'pst_revz'
else:
result = 'pst_revz'
elif basis.find('comm') >= 0:
if basis.find('rlex') >= 0:
result = 'comm_rlex'
elif basis.find('llex') >= 0:
result = 'comm_llex'
elif basis.find('deg') >= 0:
result = 'comm_deg'
elif basis.find('revz') >= 0:
result = 'comm_revz'
else:
result = 'comm_revz'
if basis.find('long') >= 0:
result = result + '_long'
elif not generic and basis.find('wood') >= 0:
if basis.find('y') >= 0:
result = 'woody'
elif basis.find('z') >= 0:
result = 'woodz'
else:
raise ValueError("%s is not a recognized basis at the prime %s." % (basis, p))
elif not generic and basis.find('arnon') >= 0:
if basis.find('c') >= 0:
result = 'arnonc'
else:
result = 'arnona'
if basis.find('long') >= 0:
result = result + '_long'
elif not generic and basis.find('wall') >= 0:
result = 'wall'
if basis.find('long') >= 0:
result = result + '_long'
else:
gencase = " for the generic Steenrod algebra" if p==2 and generic else ""
raise ValueError("%s is not a recognized basis%s at the prime %s." % (basis, gencase, p))
return result
######################################################
# profile functions
def is_valid_profile(profile, truncation_type, p=2, generic=None):
r"""
True if ``profile``, together with ``truncation_type``, is a valid
profile at the prime `p`.
INPUT:
- ``profile`` - when `p=2`, a tuple or list of numbers; when `p`
is odd, a pair of such lists
- ``truncation_type`` - either 0 or `\infty`
- `p` - prime number, optional, default 2
- `generic` - boolean, optional, default None
OUTPUT: True if the profile function is valid, False otherwise.
See the documentation for :mod:`sage.algebras.steenrod.steenrod_algebra`
for descriptions of profile functions and how they correspond to
sub-Hopf algebras of the Steenrod algebra. Briefly: at the prime
2, a profile function `e` is valid if it satisfies the condition
- `e(r) \geq \min( e(r-i) - i, e(i))` for all `0 < i < r`.
At odd primes, a pair of profile functions `e` and `k` are valid
if they satisfy
- `e(r) \geq \min( e(r-i) - i, e(i))` for all `0 < i < r`.
- if `k(i+j) = 1`, then either `e(i) \leq j` or `k(j) = 1` for all
`i \geq 1`, `j \geq 0`.
In this function, profile functions are lists or tuples, and
``truncation_type`` is appended as the last element of the list
`e` before testing.
EXAMPLES:
`p=2`::
sage: from sage.algebras.steenrod.steenrod_algebra_misc import is_valid_profile
sage: is_valid_profile([3,2,1], 0)
True
sage: is_valid_profile([3,2,1], Infinity)
True
sage: is_valid_profile([1,2,3], 0)
False
sage: is_valid_profile([6,2,0], Infinity)
False
sage: is_valid_profile([0,3], 0)
False
sage: is_valid_profile([0,0,4], 0)
False
sage: is_valid_profile([0,0,0,4,0], 0)
True
Odd primes::
sage: is_valid_profile(([0,0,0], [2,1,1,1,2,2]), 0, p=3)
True
sage: is_valid_profile(([1], [2,2]), 0, p=3)
True
sage: is_valid_profile(([1], [2]), 0, p=7)
False
sage: is_valid_profile(([1,2,1], []), 0, p=7)
True
sage: is_valid_profile(([0,0,0], [2,1,1,1,2,2]), 0, p=2, generic=True)
True
"""
from sage.rings.infinity import Infinity
if generic is None:
generic = False if p==2 else True
if not generic:
pro = list(profile) + [truncation_type]*len(profile)
r = 0
for pro_r in pro:
r += 1 # index of pro_r
if pro_r < Infinity:
for i in range(1,r):
if pro_r < min(pro[r-i-1] - i, pro[i-1]):
return False
else:
# p odd:
e = list(profile[0]) + [truncation_type]*len(profile[0])
k = list(profile[1])
if not set(k).issubset(set([1,2])):
return False
if truncation_type > 0:
k = k + [2]
else:
k = k + [1]*len(profile[0])
if len(k) > len(e):
e = e + [truncation_type] * (len(k) - len(e))
r = 0
for e_r in e:
r += 1 # index of e_r
if e_r < Infinity:
for i in range(1,r):
if e_r < min(e[r-i-1] - i, e[i-1]):
return False
r = -1
for k_r in k:
r += 1 # index of k_r
if k_r == 1:
for j in range(r):
i = r-j
if e[i-1] > j and k[j] == 2:
return False
return True
def normalize_profile(profile, precision=None, truncation_type='auto', p=2, generic=None):
r"""
Given a profile function and related data, return it in a standard form,
suitable for hashing and caching as data defining a sub-Hopf
algebra of the Steenrod algebra.
INPUT:
- ``profile`` - a profile function in form specified below
- ``precision`` - integer or ``None``, optional, default ``None``
- ``truncation_type`` - 0 or `\infty` or 'auto', optional, default 'auto'
- `p` - prime, optional, default 2
- `generic` - boolean, optional, default ``None``
OUTPUT: a triple ``profile, precision, truncation_type``, in
standard form as described below.
The "standard form" is as follows: ``profile`` should be a tuple
of integers (or `\infty`) with no trailing zeroes when `p=2`, or a
pair of such when `p` is odd or `generic` is ``True``. ``precision``
should be a positive integer. ``truncation_type`` should be 0 or `\infty`.
Furthermore, this must be a valid profile, as determined by the
function :func:`is_valid_profile`. See also the documentation for
the module :mod:`sage.algebras.steenrod.steenrod_algebra` for information
about profile functions.
For the inputs: when `p=2`, ``profile`` should be a valid profile
function, and it may be entered in any of the following forms:
- a list or tuple, e.g., ``[3,2,1,1]``
- a function from positive integers to non-negative integers (and
`\infty`), e.g., ``lambda n: n+2``. This corresponds to the
list ``[3, 4, 5, ...]``.
- ``None`` or ``Infinity`` - use this for the profile function for
the whole Steenrod algebra. This corresponds to the list
``[Infinity, Infinity, Infinity, ...]``
To make this hashable, it gets turned into a tuple. In the first
case it is clear how to do this; also in this case, ``precision``
is set to be one more than the length of this tuple. In the
second case, construct a tuple of length one less than
``precision`` (default value 100). In the last case, the empty
tuple is returned and ``precision`` is set to 1.
Once a sub-Hopf algebra of the Steenrod algebra has been defined
using such a profile function, if the code requires any remaining
terms (say, terms after the 100th), then they are given by
``truncation_type`` if that is 0 or `\infty`. If
``truncation_type`` is 'auto', then in the case of a tuple, it
gets set to 0, while for the other cases it gets set to `\infty`.
See the examples below.
When `p` is odd, ``profile`` is a pair of "functions", so it may
have the following forms:
- a pair of lists or tuples, the second of which takes values in
the set `\{1,2\}`, e.g., ``([3,2,1,1], [1,1,2,2,1])``.
- a pair of functions, one (called `e`) from positive integers to
non-negative integers (and `\infty`), one (called `k`) from
non-negative integers to the set `\{1,2\}`, e.g.,
``(lambda n: n+2, lambda n: 1)``. This corresponds to the
pair ``([3, 4, 5, ...], [1, 1, 1, ...])``.
- ``None`` or ``Infinity`` - use this for the profile function for
the whole Steenrod algebra. This corresponds to the pair
``([Infinity, Infinity, Infinity, ...], [2, 2, 2, ...])``.
You can also mix and match the first two, passing a pair with
first entry a list and second entry a function, for instance. The
values of ``precision`` and ``truncation_type`` are determined by
the first entry.
EXAMPLES:
`p=2`::
sage: from sage.algebras.steenrod.steenrod_algebra_misc import normalize_profile
sage: normalize_profile([1,2,1,0,0])
((1, 2, 1), 0)
The full mod 2 Steenrod algebra::
sage: normalize_profile(Infinity)
((), +Infinity)
sage: normalize_profile(None)
((), +Infinity)
sage: normalize_profile(lambda n: Infinity)
((), +Infinity)
The ``precision`` argument has no effect when the first argument
is a list or tuple::
sage: normalize_profile([1,2,1,0,0], precision=12)
((1, 2, 1), 0)
If the first argument is a function, then construct a list of
length one less than ``precision``, by plugging in the numbers 1,
2, ..., ``precision`` - 1::
sage: normalize_profile(lambda n: 4-n, precision=4)
((3, 2, 1), +Infinity)
sage: normalize_profile(lambda n: 4-n, precision=4, truncation_type=0)
((3, 2, 1), 0)
Negative numbers in profile functions are turned into zeroes::
sage: normalize_profile(lambda n: 4-n, precision=6)
((3, 2, 1, 0, 0), +Infinity)
If it doesn't give a valid profile, an error is raised::
sage: normalize_profile(lambda n: 3, precision=4, truncation_type=0)
Traceback (most recent call last):
...
ValueError: Invalid profile
sage: normalize_profile(lambda n: 3, precision=4, truncation_type = Infinity)
((3, 3, 3), +Infinity)
When `p` is odd, the behavior is similar::
sage: normalize_profile(([2,1], [2,2,2]), p=13)
(((2, 1), (2, 2, 2)), 0)
The full mod `p` Steenrod algebra::
sage: normalize_profile(None, p=7)
(((), ()), +Infinity)
sage: normalize_profile(Infinity, p=11)
(((), ()), +Infinity)
sage: normalize_profile((lambda n: Infinity, lambda n: 2), p=17)
(((), ()), +Infinity)
Note that as at the prime 2, the ``precision`` argument has no
effect on a list or tuple in either entry of ``profile``. If
``truncation_type`` is 'auto', then it gets converted to either
``0`` or ``+Infinity`` depending on the *first* entry of
``profile``::
sage: normalize_profile(([2,1], [2,2,2]), precision=84, p=13)
(((2, 1), (2, 2, 2)), 0)
sage: normalize_profile((lambda n: 0, lambda n: 2), precision=4, p=11)
(((0, 0, 0), ()), +Infinity)
sage: normalize_profile((lambda n: 0, (1,1,1,1,1,1,1)), precision=4, p=11)
(((0, 0, 0), (1, 1, 1, 1, 1, 1, 1)), +Infinity)
sage: normalize_profile(((4,3,2,1), lambda n: 2), precision=6, p=11)
(((4, 3, 2, 1), (2, 2, 2, 2, 2)), 0)
sage: normalize_profile(((4,3,2,1), lambda n: 1), precision=3, p=11, truncation_type=Infinity)
(((4, 3, 2, 1), (1, 1)), +Infinity)
As at the prime 2, negative numbers in the first component are
converted to zeroes. Numbers in the second component must be
either 1 and 2, or else an error is raised::
sage: normalize_profile((lambda n: -n, lambda n: 1), precision=4, p=11)
(((0, 0, 0), (1, 1, 1)), +Infinity)
sage: normalize_profile([[0,0,0], [1,2,3,2,1]], p=11)
Traceback (most recent call last):
...
ValueError: Invalid profile
"""
from inspect import isfunction
from sage.rings.infinity import Infinity
if truncation_type == 'zero':
truncation_type = 0
if truncation_type == 'infinity':
truncation_type = Infinity
if generic is None:
generic = False if p==2 else True
if not generic:
if profile is None or profile == Infinity:
# no specified profile or infinite profile: return profile
# for the entire Steenrod algebra
new_profile = ()
truncation_type = Infinity
elif isinstance(profile, (list, tuple)):
# profile is a list or tuple: use it as is. if
# truncation_type not specified, set it to 'zero'. remove
# trailing zeroes if truncation_type is 'auto' or 'zero'.
if truncation_type == 'auto':
truncation_type = 0
# remove trailing zeroes or Infinitys
while len(profile) > 0 and profile[-1] == truncation_type:
profile = profile[:-1]
new_profile = tuple(profile)
elif isfunction(profile):
# profile is a function: turn it into a tuple. if
# truncation_type not specified, set it to 'infinity' if
# the function is ever infinite; otherwise set it to
# 0. remove trailing zeroes if truncation_type is
# 0, trailing Infinitys if truncation_type is oo.
if precision is None:
precision = 100
if truncation_type == 'auto':
truncation_type = Infinity
new_profile = [max(0, profile(i)) for i in range(1, precision)]
# remove trailing zeroes or Infinitys:
while len(new_profile) > 0 and new_profile[-1] == truncation_type:
del new_profile[-1]
new_profile = tuple(new_profile)
if is_valid_profile(new_profile, truncation_type, p):
return new_profile, truncation_type
else:
raise ValueError("Invalid profile")
else: # p odd
if profile is None or profile == Infinity:
# no specified profile or infinite profile: return profile
# for the entire Steenrod algebra
new_profile = ((), ())
truncation_type = Infinity
else: # profile should be a list or tuple of length 2
assert isinstance(profile, (list, tuple)) and len(profile) == 2, \
"Invalid form for profile"
e = profile[0]
k = profile[1]
if isinstance(e, (list, tuple)):
# e is a list or tuple: use it as is. if
# truncation_type not specified, set it to 0. remove
# appropriate trailing terms.
if truncation_type == 'auto':
truncation_type = 0
# remove trailing terms
while len(e) > 0 and e[-1] == truncation_type:
e = e[:-1]
e = tuple(e)
elif isfunction(e):
# e is a function: turn it into a tuple. if
# truncation_type not specified, set it to 'infinity'
# if the function is ever infinite; otherwise set it
# to 0. remove appropriate trailing terms.
if precision is None:
e_precision = 100
else:
e_precision = precision
if truncation_type == 'auto':
truncation_type = Infinity
e = [max(0, e(i)) for i in range(1, e_precision)]
# remove trailing terms
while len(e) > 0 and e[-1] == truncation_type:
del e[-1]
e = tuple(e)
if isinstance(k, (list, tuple)):
# k is a list or tuple: use it as is.
k = tuple(k)
elif isfunction(k):
# k is a function: turn it into a tuple.
if precision is None:
k_precision = 100
else:
k_precision = precision
k = tuple([k(i) for i in range(k_precision-1)])
# Remove trailing ones from k if truncation_type is 'zero',
# remove trailing twos if truncation_type is 'Infinity'.
if truncation_type == 0:
while len(k) > 0 and k[-1] == 1:
k = k[:-1]
else:
while len(k) > 0 and k[-1] == 2:
k = k[:-1]
new_profile = (e, k)
if is_valid_profile(new_profile, truncation_type, p, generic=True):
return new_profile, truncation_type
else:
raise ValueError("Invalid profile")
######################################################
# string representations for elements
def milnor_mono_to_string(mono, latex=False, generic=False):
"""
String representation of element of the Milnor basis.
This is used by the _repr_ and _latex_ methods.
INPUT:
- ``mono`` - if `generic=False`, tuple of non-negative integers (a,b,c,...);
if `generic=True`, pair of tuples of non-negative integers ((e0, e1, e2,
...), (r1, r2, ...))
- ``latex`` - boolean (optional, default False), if true, output
LaTeX string
- ``generic`` - whether to format generically, or for the prime 2 (default)
OUTPUT: ``rep`` - string
This returns a string like ``Sq(a,b,c,...)`` when `generic=False`, or a string
like ``Q_e0 Q_e1 Q_e2 ... P(r1, r2, ...)`` when `generic=True`.
EXAMPLES::
sage: from sage.algebras.steenrod.steenrod_algebra_misc import milnor_mono_to_string
sage: milnor_mono_to_string((1,2,3,4))
'Sq(1,2,3,4)'
sage: milnor_mono_to_string((1,2,3,4),latex=True)
'\\text{Sq}(1,2,3,4)'
sage: milnor_mono_to_string(((1,0), (2,3,1)), generic=True)
'Q_{1} Q_{0} P(2,3,1)'
sage: milnor_mono_to_string(((1,0), (2,3,1)), latex=True, generic=True)
'Q_{1} Q_{0} \\mathcal{P}(2,3,1)'
The empty tuple represents the unit element::
sage: milnor_mono_to_string(())
'1'
sage: milnor_mono_to_string((), generic=True)
'1'
"""
if latex:
if not generic:
sq = "\\text{Sq}"
P = "\\text{Sq}"
else:
P = "\\mathcal{P}"
else:
if not generic:
sq = "Sq"
P = "Sq"
else:
P = "P"
if mono == () or mono == (0,) or (generic and len(mono[0]) + len(mono[1]) == 0):
return "1"
else:
if not generic:
string = sq + "(" + str(mono[0])
for n in mono[1:]:
string = string + "," + str(n)
string = string + ")"
else:
string = ""
if len(mono[0]) > 0:
for e in mono[0]:
string = string + "Q_{" + str(e) + "} "
if len(mono[1]) > 0:
string = string + P + "(" + str(mono[1][0])
for n in mono[1][1:]:
string = string + "," + str(n)
string = string + ")"
return string.strip(" ")
def serre_cartan_mono_to_string(mono, latex=False, generic=False):
r"""
String representation of element of the Serre-Cartan basis.
This is used by the _repr_ and _latex_ methods.
INPUT:
- ``mono`` - tuple of positive integers (a,b,c,...) when `generic=False`,
or tuple (e0, n1, e1, n2, ...) when `generic=True`, where each ei is 0 or
1, and each ni is positive
- ``latex`` - boolean (optional, default False), if true, output
LaTeX string
- ``generic`` - whether to format generically, or for the prime 2 (default)
OUTPUT: ``rep`` - string
This returns a string like ``Sq^{a} Sq^{b} Sq^{c} ...`` when
`generic=False`, or a string like
``\beta^{e0} P^{n1} \beta^{e1} P^{n2} ...`` when `generic=True`.
is odd.
EXAMPLES::
sage: from sage.algebras.steenrod.steenrod_algebra_misc import serre_cartan_mono_to_string
sage: serre_cartan_mono_to_string((1,2,3,4))
'Sq^{1} Sq^{2} Sq^{3} Sq^{4}'
sage: serre_cartan_mono_to_string((1,2,3,4),latex=True)
'\\text{Sq}^{1} \\text{Sq}^{2} \\text{Sq}^{3} \\text{Sq}^{4}'
sage: serre_cartan_mono_to_string((0,5,1,1,0), generic=True)
'P^{5} beta P^{1}'
sage: serre_cartan_mono_to_string((0,5,1,1,0), generic=True, latex=True)
'\\mathcal{P}^{5} \\beta \\mathcal{P}^{1}'
The empty tuple represents the unit element 1::
sage: serre_cartan_mono_to_string(())
'1'
sage: serre_cartan_mono_to_string((), generic=True)
'1'
"""
if latex:
if not generic:
sq = "\\text{Sq}"
P = "\\text{Sq}"
else:
P = "\\mathcal{P}"
else:
if not generic:
sq = "Sq"
P = "Sq"
else:
P = "P"
if len(mono) == 0 or mono == (0,):
return "1"
else:
if not generic:
string = ""
for n in mono:
string = string + sq + "^{" + str(n) + "} "
else:
string = ""
index = 0
for n in mono:
from sage.misc.functional import is_even
if is_even(index):
if n == 1:
if latex:
string = string + "\\beta "
else:
string = string + "beta "
else:
string = string + P + "^{" + str(n) + "} "
index += 1
return string.strip(" ")
def wood_mono_to_string(mono, latex=False):
"""
String representation of element of Wood's Y and Z bases.
This is used by the _repr_ and _latex_ methods.
INPUT:
- ``mono`` - tuple of pairs of non-negative integers (s,t)
- ``latex`` - boolean (optional, default False), if true, output
LaTeX string
OUTPUT: ``string`` - concatenation of strings of the form
``Sq^{2^s (2^{t+1}-1)}`` for each pair (s,t)
EXAMPLES::
sage: from sage.algebras.steenrod.steenrod_algebra_misc import wood_mono_to_string
sage: wood_mono_to_string(((1,2),(3,0)))
'Sq^{14} Sq^{8}'
sage: wood_mono_to_string(((1,2),(3,0)),latex=True)
'\\text{Sq}^{14} \\text{Sq}^{8}'
The empty tuple represents the unit element::
sage: wood_mono_to_string(())
'1'
"""
if latex:
sq = "\\text{Sq}"
else:
sq = "Sq"
if len(mono) == 0:
return "1"
else:
string = ""
for (s,t) in mono:
string = string + sq + "^{" + \
str(2**s * (2**(t+1)-1)) + "} "
return string.strip(" ")
def wall_mono_to_string(mono, latex=False):
"""
String representation of element of Wall's basis.
This is used by the _repr_ and _latex_ methods.
INPUT:
- ``mono`` - tuple of pairs of non-negative integers (m,k) with `m
>= k`
- ``latex`` - boolean (optional, default False), if true, output
LaTeX string
OUTPUT: ``string`` - concatenation of strings ``Q^{m}_{k}`` for
each pair (m,k)
EXAMPLES::
sage: from sage.algebras.steenrod.steenrod_algebra_misc import wall_mono_to_string
sage: wall_mono_to_string(((1,2),(3,0)))
'Q^{1}_{2} Q^{3}_{0}'
sage: wall_mono_to_string(((1,2),(3,0)),latex=True)
'Q^{1}_{2} Q^{3}_{0}'
The empty tuple represents the unit element::
sage: wall_mono_to_string(())
'1'
"""
if len(mono) == 0:
return "1"
else:
string = ""
for (m,k) in mono:
string = string + "Q^{" + str(m) + "}_{" \
+ str(k) + "} "
return string.strip(" ")
def wall_long_mono_to_string(mono, latex=False):
"""
Alternate string representation of element of Wall's basis.
This is used by the _repr_ and _latex_ methods.
INPUT:
- ``mono`` - tuple of pairs of non-negative integers (m,k) with `m
>= k`
- ``latex`` - boolean (optional, default False), if true, output
LaTeX string
OUTPUT: ``string`` - concatenation of strings of the form
``Sq^(2^m)``
EXAMPLES::
sage: from sage.algebras.steenrod.steenrod_algebra_misc import wall_long_mono_to_string
sage: wall_long_mono_to_string(((1,2),(3,0)))
'Sq^{1} Sq^{2} Sq^{4} Sq^{8}'
sage: wall_long_mono_to_string(((1,2),(3,0)),latex=True)
'\\text{Sq}^{1} \\text{Sq}^{2} \\text{Sq}^{4} \\text{Sq}^{8}'
The empty tuple represents the unit element::
sage: wall_long_mono_to_string(())
'1'
"""
if latex:
sq = "\\text{Sq}"
else:
sq = "Sq"
if len(mono) == 0:
return "1"
else:
string = ""
for (m,k) in mono:
for i in range(k,m+1):
string = string + sq + "^{" + str(2**i) + "} "
return string.strip(" ")
def arnonA_mono_to_string(mono, latex=False, p=2):
"""
String representation of element of Arnon's A basis.
This is used by the _repr_ and _latex_ methods.
INPUT:
- ``mono`` - tuple of pairs of non-negative integers
(m,k) with `m >= k`
- ``latex`` - boolean (optional, default False), if true, output
LaTeX string
OUTPUT: ``string`` - concatenation of strings of the form
``X^{m}_{k}`` for each pair (m,k)
EXAMPLES::
sage: from sage.algebras.steenrod.steenrod_algebra_misc import arnonA_mono_to_string
sage: arnonA_mono_to_string(((1,2),(3,0)))
'X^{1}_{2} X^{3}_{0}'
sage: arnonA_mono_to_string(((1,2),(3,0)),latex=True)
'X^{1}_{2} X^{3}_{0}'
The empty tuple represents the unit element::
sage: arnonA_mono_to_string(())
'1'
"""
if len(mono) == 0:
return "1"
else:
string = ""
for (m,k) in mono:
string = string + "X^{" + str(m) + "}_{" \
+ str(k) + "} "
return string.strip(" ")
def arnonA_long_mono_to_string(mono, latex=False, p=2):
"""
Alternate string representation of element of Arnon's A basis.
This is used by the _repr_ and _latex_ methods.
INPUT:
- ``mono`` - tuple of pairs of non-negative integers (m,k) with `m
>= k`
- ``latex`` - boolean (optional, default False), if true, output
LaTeX string
OUTPUT: ``string`` - concatenation of strings of the form
``Sq(2^m)``
EXAMPLES::
sage: from sage.algebras.steenrod.steenrod_algebra_misc import arnonA_long_mono_to_string
sage: arnonA_long_mono_to_string(((1,2),(3,0)))
'Sq^{8} Sq^{4} Sq^{2} Sq^{1}'
sage: arnonA_long_mono_to_string(((1,2),(3,0)),latex=True)
'\\text{Sq}^{8} \\text{Sq}^{4} \\text{Sq}^{2} \\text{Sq}^{1}'
The empty tuple represents the unit element::
sage: arnonA_long_mono_to_string(())
'1'
"""
if latex:
sq = "\\text{Sq}"
else:
sq = "Sq"
if len(mono) == 0:
return "1"
else:
string = ""
for (m,k) in mono:
for i in range(m,k-1,-1):
string = string + sq + "^{" + str(2**i) + "} "
return string.strip(" ")
def pst_mono_to_string(mono, latex=False, generic=False):
r"""
String representation of element of a `P^s_t`-basis.
This is used by the _repr_ and _latex_ methods.
INPUT:
- ``mono`` - tuple of pairs of integers (s,t) with `s >= 0`, `t >
0`
- ``latex`` - boolean (optional, default False), if true, output
LaTeX string
- ``generic`` - whether to format generically, or for the prime 2 (default)
OUTPUT: ``string`` - concatenation of strings of the form
``P^{s}_{t}`` for each pair (s,t)
EXAMPLES::
sage: from sage.algebras.steenrod.steenrod_algebra_misc import pst_mono_to_string
sage: pst_mono_to_string(((1,2),(0,3)), generic=False)
'P^{1}_{2} P^{0}_{3}'
sage: pst_mono_to_string(((1,2),(0,3)),latex=True, generic=False)
'P^{1}_{2} P^{0}_{3}'
sage: pst_mono_to_string(((1,4), (((1,2), 1),((0,3), 2))), generic=True)
'Q_{1} Q_{4} P^{1}_{2} (P^{0}_{3})^2'
sage: pst_mono_to_string(((1,4), (((1,2), 1),((0,3), 2))), latex=True, generic=True)
'Q_{1} Q_{4} P^{1}_{2} (P^{0}_{3})^{2}'
The empty tuple represents the unit element::
sage: pst_mono_to_string(())
'1'
"""
if len(mono) == 0:
return "1"
else:
string = ""
if not generic:
for (s,t) in mono:
string = string + "P^{" + str(s) + "}_{" \
+ str(t) + "} "
else:
for e in mono[0]:
string = string + "Q_{" + str(e) + "} "
for ((s,t), n) in mono[1]:
if n == 1:
string = string + "P^{" + str(s) + "}_{" \
+ str(t) + "} "
else:
if latex:
pow = "{%s}" % n
else:
pow = str(n)
string = string + "(P^{" + str(s) + "}_{" \
+ str(t) + "})^" + pow + " "
return string.strip(" ")
def comm_mono_to_string(mono, latex=False, generic=False):
r"""
String representation of element of a commutator basis.
This is used by the _repr_ and _latex_ methods.
INPUT:
- ``mono`` - tuple of pairs of integers (s,t) with `s >= 0`, `t >
0`
- ``latex`` - boolean (optional, default False), if true, output
LaTeX string
- ``generic`` - whether to format generically, or for the prime 2 (default)