-
Notifications
You must be signed in to change notification settings - Fork 1
/
btquotient.py
3803 lines (3115 loc) · 123 KB
/
btquotient.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
#########################################################################
# Copyright (C) 2011 Cameron Franc and Marc Masdeu
#
# Distributed under the terms of the GNU General Public License (GPL)
#
# http://www.gnu.org/licenses/
#########################################################################
r"""
Compute arithmetic quotients of the Bruhat-Tits tree
"""
from sage.rings.integer import Integer
from sage.matrix.constructor import Matrix
from sage.matrix.matrix_space import MatrixSpace
from sage.structure.sage_object import SageObject
from sage.rings.all import ZZ, Zmod, QQ
from sage.misc.latex import latex
from sage.rings.padics.precision_error import PrecisionError
import collections
from sage.misc.misc_c import prod
from sage.structure.unique_representation import UniqueRepresentation
from sage.misc.cachefunc import cached_method
from sage.rings.arith import gcd, xgcd, kronecker_symbol
from sage.rings.padics.all import Qp, Zp
from sage.rings.finite_rings.constructor import GF
from sage.algebras.quatalg.all import QuaternionAlgebra
from sage.quadratic_forms.all import QuadraticForm
from sage.graphs.all import Graph
from sage.libs.all import pari
from sage.interfaces.all import magma
from copy import copy
from sage.plot.colors import rainbow
from sage.rings.number_field.all import NumberField
from sage.modular.arithgroup.all import Gamma0
from sage.misc.lazy_attribute import lazy_attribute
from sage.modular.dirichlet import DirichletGroup
from sage.modular.arithgroup.congroup_gammaH import GammaH_class
from sage.rings.arith import fundamental_discriminant
from sage.misc.misc import verbose
def enumerate_words(v, n=None):
r"""
A useful function used to write words in the generators
"""
if n is None:
n = []
while True:
add_new = True
for jj in range(len(n)):
n[jj] += 1
if n[jj] != len(v):
add_new = False
break
else:
n[jj] = 0
if add_new:
n.append(0)
yield [v[x] for x in n]
class DoubleCosetReduction(SageObject):
r"""
Edges in the Bruhat-Tits tree are represented by cosets of
matrices in `\GL_2`. Given a matrix `x` in `\GL_2`, this
class computes and stores the data corresponding to the
double coset representation of `x` in terms of a fundamental
domain of edges for the action of the arithmetic group `\Gamma'.
More precisely:
Initialized with an element `x` of `\GL_2(\ZZ)`, finds elements
`\gamma` in `\Gamma`, `t` and an edge `e` such that `get=x`. It
stores these values as members ``gamma``, ``label`` and functions
``self.sign()``, ``self.t()`` and ``self.igamma()``, satisfying:
if ``self.sign() == +1``:
``igamma() * edge_list[label].rep * t() == x``
if ``self.sign() == -1``:
``igamma() * edge_list[label].opposite.rep * t() == x``
It also stores a member called power so that:
``p**(2*power) = gamma.reduced_norm()``
The usual decomposition ``get=x`` would be:
g = gamma / (p ** power)
e = edge_list[label]
t' = t * p ** power
Here usual denotes that we have rescaled gamma to have unit
determinant, and so that the result is honestly an element
of the arithmetic quarternion group under consideration. In
practice we store integral multiples and keep track of the
powers of `p`.
INPUT:
- ``Y`` - BTQuotient object in which to work
- ``x`` - Something coercible into a matrix in `\GL_2(\ZZ)`. In
principle we should allow elements in `\GL_2(\QQ_p)`, but it is
enough to work with integral entries
- ``extrapow`` - gets added to the power attribute, and it is
used for the Hecke action.
EXAMPLES::
sage: from sage.modular.btquotients.btquotient import DoubleCosetReduction
sage: Y = BTQuotient(5, 13)
sage: x = Matrix(ZZ,2,2,[123,153,1231,1231])
sage: d = DoubleCosetReduction(Y,x)
sage: d.sign()
-1
sage: d.igamma()*Y._edge_list[d.label - len(Y.get_edge_list())].opposite.rep*d.t() == x
True
sage: x = Matrix(ZZ,2,2,[1423,113553,11231,12313])
sage: d = DoubleCosetReduction(Y,x)
sage: d.sign()
1
sage: d.igamma()*Y._edge_list[d.label].rep*d.t() == x
True
AUTHORS:
- Cameron Franc (2012-02-20)
- Marc Masdeu
"""
def __init__(self, Y, x, extrapow=0):
r"""
Initializes and computes the reduction as a double coset.
EXAMPLES::
sage: Y = BTQuotient(5, 13)
sage: x = Matrix(ZZ,2,2,[123,153,1231,1231])
sage: d = DoubleCosetReduction(Y,x)
sage: TestSuite(d).run()
"""
e1 = Y._BT.edge(x)
try:
g, label, parity = Y._cached_decomps[e1]
except KeyError:
valuation = e1.determinant().valuation(Y._p)
parity = valuation % 2
v1 = Y._BT.target(e1)
v = Y.fundom_rep(v1)
g, e = Y._find_equivalent_edge(e1, v.entering_edges,
valuation=valuation)
label = e.label
Y._cached_decomps[e1] = (g, label, parity)
self._parent = Y
self.parity = parity
self._num_edges = len(Y.get_edge_list())
self.label = label + parity * self._num_edges
# The label will encode whether it is an edge or its opposite !
self.gamma = g[0]
self.x = x
self.power = g[1] + extrapow
self._t_prec = -1
self._igamma_prec = -1
def _repr_(self):
r"""
Returns the representation of self as a string.
EXAMPLES::
sage: Y = BTQuotient(5, 13)
sage: x = Matrix(ZZ,2,2,[123,153,1231,1231])
sage: DoubleCosetReduction(Y,x)
DoubleCosetReduction
"""
return "DoubleCosetReduction"
def __cmp__(self, other):
"""
Return self == other
TESTS::
sage: Y = BTQuotient(5, 13)
sage: x = Matrix(ZZ,2,2,[123,153,1231,1231])
sage: d1 = DoubleCosetReduction(Y,x)
sage: d1 == d1
True
"""
c = cmp(self._parent, other._parent)
if c:
return c
c = cmp(self.parity, other.parity)
if c:
return c
c = cmp(self._num_edges, other._num_edges)
if c:
return c
c = cmp(self.label, other.label)
if c:
return c
c = cmp(self.gamma, other.gamma)
if c:
return c
c = cmp(self.x, other.x)
if c:
return c
c = cmp(self.power, other.power)
if c:
return c
c = cmp(self._t_prec, other._t_prec)
if c:
return c
c = cmp(self._igamma_prec, other._igamma_prec)
if c:
return c
return 0
def sign(self):
r"""
The direction of the edge.
The BT quotients are directed graphs but we only store
half the edges (we treat them more like unordered graphs).
The sign tells whether the matrix self.x is equivalent to the
representative in the quotient (sign = +1), or to the
opposite of one of the representatives (sign = -1).
OUTPUT :
an int that is +1 or -1 according to the sign of self
EXAMPLES::
sage: Y = BTQuotient(3, 11)
sage: x = Matrix(ZZ,2,2,[123,153,1231,1231])
sage: d = DoubleCosetReduction(Y,x)
sage: d.sign()
-1
sage: d.igamma()*Y._edge_list[d.label - len(Y.get_edge_list())].opposite.rep*d.t() == x
True
sage: x = Matrix(ZZ,2,2,[1423,113553,11231,12313])
sage: d = DoubleCosetReduction(Y,x)
sage: d.sign()
1
sage: d.igamma()*Y._edge_list[d.label].rep*d.t() == x
True
"""
if self.parity == 0:
return 1
else:
return -1
def igamma(self, embedding=None, scale=1):
r"""
Image under gamma.
Elements of the arithmetic group can be regarded as elements
of the global quarterion order, and hence may be represented
exactly. This function computes the image of such an element
under the local splitting and returns the corresponding p-adic
approximation.
INPUT:
- ``embedding`` - an integer, or a function (Default:
none). If ``embedding`` is None, then the image of
``self.gamma`` under the local splitting associated to
``self.Y`` is used. If ``embedding`` is an integer, then
the precision of the local splitting of self.Y is raised
(if necessary) to be larger than this integer, and this
new local splitting is used. If a function is passed, then
map ``self.gamma`` under ``embedding``.
OUTPUT:
a 2x2 matrix with p-adic entries encoding the image of ``self``
under the local splitting
EXAMPLES::
sage: from sage.modular.btquotients.btquotient import DoubleCosetReduction
sage: Y = BTQuotient(7, 11)
sage: d = DoubleCosetReduction(Y,Matrix(ZZ,2,2,[123,45,88,1]))
sage: d.igamma()
[6 + 6*7 + 6*7^2 + 6*7^3 + 6*7^4 + O(7^5) O(7^5)]
[ O(7^5) 6 + 6*7 + 6*7^2 + 6*7^3 + 6*7^4 + O(7^5)]
sage: d.igamma(embedding = 7)
[6 + 6*7 + 6*7^2 + 6*7^3 + 6*7^4 + 6*7^5 + 6*7^6 + O(7^7) O(7^7)]
[ O(7^7) 6 + 6*7 + 6*7^2 + 6*7^3 + 6*7^4 + 6*7^5 + 6*7^6 + O(7^7)]
"""
Y = self._parent
if embedding is None:
prec = Y._prec
else:
try:
# The user wants higher precision
prec = ZZ(embedding)
except TypeError:
# The user knows what she is doing, so let it go
return embedding(self.gamma)
if prec > self._igamma_prec:
self._igamma_prec = prec
self._cached_igamma = Y.embed_quaternion(self.gamma, exact=False,
prec=prec)
return scale * self._cached_igamma
def t(self, prec=None):
r"""
Return the 't part' of the decomposition using the rest of the data.
INPUT:
- ``prec`` - a p-adic precision that t will be computed
to. Default is the default working precision of self
OUTPUT:
- ``cached_t`` - a 2x2 p-adic matrix with entries of
precision 'prec' that is the 't-part' of the decomposition of
self
EXAMPLES::
sage: from sage.modular.btquotients.btquotient import DoubleCosetReduction
sage: Y = BTQuotient(5, 13)
sage: x = Matrix(ZZ,2,2,[123,153,1231,1232])
sage: d = DoubleCosetReduction(Y,x)
sage: t = d.t(20)
sage: t[1,0].valuation() > 0
True
"""
Y = self._parent
if prec is None:
prec = max([5, Y._prec])
if self._t_prec >= prec:
return self._cached_t
e = Y._edge_list[self.label % self._num_edges]
tmp_prec = prec
while self._t_prec < prec:
if self.parity == 0:
self._cached_t = (self.igamma(tmp_prec) * e.rep).inverse() * self.x
# assert self._cached_t[1, 0].valuation()>self._cached_t[1,1].valuation()
else:
self._cached_t = (self.igamma(tmp_prec) * e.opposite.rep).inverse() * self.x
# assert self._cached_t[1, 0].valuation()>self._cached_t[1,1].valuation()
tmp_prec += 1
self._t_prec = min([xx.precision_absolute()
for xx in self._cached_t.list()])
return self._cached_t
class BruhatTitsTree(SageObject, UniqueRepresentation):
r"""
An implementation of the Bruhat-Tits tree for `\GL_2(\QQ_p)`.
INPUT:
- ``p`` - a prime number. The corresponding tree is then p+1 regular
EXAMPLES:
We create the tree for `\GL_2(\QQ_5)`::
sage: from sage.modular.btquotients.btquotient import BruhatTitsTree
sage: p = 5
sage: T = BruhatTitsTree(p)
sage: m = Matrix(ZZ,2,2,[p**5,p**2,p**3,1+p+p*3])
sage: e = T.edge(m); e
[ 0 25]
[625 21]
sage: v0 = T.origin(e); v0
[ 25 0]
[ 21 125]
sage: v1 = T.target(e); v1
[ 25 0]
[ 21 625]
sage: T.origin(T.opposite(e)) == v1
True
sage: T.target(T.opposite(e)) == v0
True
A value error is raised if a prime is not passed::
sage: T = BruhatTitsTree(4)
Traceback (most recent call last):
...
ValueError: Input (4) must be prime
AUTHORS:
- Marc Masdeu (2012-02-20)
"""
def __init__(self, p):
"""
Initializes a BruhatTitsTree object for a given prime p
EXAMPLES::
sage: from sage.modular.btquotients.btquotient import BruhatTitsTree
sage: T = BruhatTitsTree(17)
sage: TestSuite(T).run()
"""
if not(ZZ(p).is_prime()):
raise ValueError('Input (%s) must be prime' % p)
self._p = ZZ(p)
self._Mat_22 = MatrixSpace(ZZ, 2, 2)
self._mat_p001 = self._Mat_22([self._p, 0, 0, 1])
def target(self, e, normalized=False):
r"""
Returns the target vertex of the edge represented by the
input matrix e.
INPUT:
- ``e`` - a 2x2 matrix with integer entries
- ``normalized`` - boolean (default: false). If true
then the input matrix is assumed to be normalized.
OUPUT:
- ``e`` - 2x2 integer matrix representing the target of
the input edge
EXAMPLES::
sage: from sage.modular.btquotients.btquotient import BruhatTitsTree
sage: T = BruhatTitsTree(7)
sage: T.target(Matrix(ZZ,2,2,[1,5,8,9]))
[1 0]
[0 1]
"""
if normalized:
#then the normalized target vertex is also M and we save some
#row reductions with a simple return
return e
else:
#must normalize the target vertex representative
return self.vertex(e)
def origin(self, e, normalized=False):
r"""
Returns the origin vertex of the edge represented by the
input matrix e.
INPUT:
- ``e`` - a 2x2 matrix with integer entries
- ``normalized`` - boolean (default: false). If true
then the input matrix M is assumed to be normalized
OUTPUT:
- ``e`` - A 2x2 integer matrix
EXAMPLES::
sage: from sage.modular.btquotients.btquotient import BruhatTitsTree
sage: T = BruhatTitsTree(7)
sage: T.origin(Matrix(ZZ,2,2,[1,5,8,9]))
[1 0]
[1 7]
"""
if not normalized:
#then normalize
x = copy(self.edge(e))
else:
x = copy(e)
x.swap_columns(0, 1)
x.rescale_col(0, self._p)
return self.vertex(x)
def edge(self, M):
r"""
Normalizes a matrix to the correct normalized edge
representative.
INPUT:
- ``M`` - a 2x2 integer matrix
OUTPUT:
- ``newM`` - a 2x2 integer matrix
EXAMPLES::
sage: from sage.modular.btquotients.btquotient import BruhatTitsTree
sage: T = BruhatTitsTree(3)
sage: T.edge( Matrix(ZZ,2,2,[0,-1,3,0]) )
[0 1]
[3 0]
"""
p = self._p
# M_orig = M
def lift(a):
"""
Naively approximates a p-adic integer by a positive integer.
INPUT:
- ``a`` - a p-adic integer.
OUTPUT:
An integer.
EXAMPLES::
sage: x = Zp(3)(-17)
sage: lift(x)
3486784384
"""
try:
return ZZ(a.lift())
except AttributeError:
return ZZ(a)
if M.base_ring() is not ZZ:
M = M.apply_map(lift, R=ZZ)
v = min([M[i, j].valuation(p) for i in range(2) for j in range(2)])
if v != 0:
M = p ** (-v) * M
m00 = M[0, 0].valuation(p)
m01 = M[0, 1].valuation(p)
if m00 <= m01:
tmp = M.determinant().valuation(p) - m00
bigpower = p ** (1 + tmp)
r = M[0, 0]
if r != 0:
r /= p ** m00
g, s, _ = xgcd(r, bigpower)
r = (M[1, 0] * s) % bigpower
newM = self._Mat_22([p ** m00, 0, r, bigpower / p])
else:
tmp = M.determinant().valuation(p) - m01
bigpower = p ** tmp
r = M[0, 1]
if r != 0:
r /= p ** m01
g, s, _ = xgcd(r, bigpower)
r = (ZZ(M[1, 1]) * s) % bigpower
newM = self._Mat_22([0, p ** m01, bigpower, r])
newM.set_immutable()
# assert self.is_in_group(M_orig.inverse()*newM, as_edge = True)
return newM
def vertex(self, M):
r"""
Normalizes a matrix to the corresponding normalized
vertex representative
INPUT:
- ``M`` - 2x2 integer matrix
OUTPUT:
- a 2x2 integer matrix
EXAMPLES::
sage: from sage.modular.btquotients.btquotient import BruhatTitsTree
sage: p = 5
sage: T = BruhatTitsTree(p)
sage: m = Matrix(ZZ,2,2,[p**5,p**2,p**3,1+p+p*3])
sage: e = T.edge(m)
sage: t = m.inverse()*e
sage: scaling = Qp(p,20)(t.determinant()).sqrt()
sage: t = 1/scaling * t
sage: min([t[ii,jj].valuation(p) for ii in range(2) for jj in range(2)]) >= 0
True
sage: t[1,0].valuation(p) > 0
True
"""
p = self._p
# M_orig = M
def lift(a):
try:
return ZZ(a.lift())
except AttributeError:
return ZZ(a)
if M.base_ring() is not ZZ:
M = M.apply_map(lift, R=ZZ)
v = min([M[i, j].valuation(p) for i in range(2) for j in range(2)])
if v != 0:
M = p ** (-v) * M
m00 = M[0, 0].valuation(p)
m01 = M[0, 1].valuation(p)
if m01 < m00:
M = copy(M)
M.swap_columns(0, 1)
m00 = m01
m10 = M[1, 0].valuation(p)
tmp = M.determinant().valuation(p) - m00
bigpower = p ** tmp
r = M[0, 0]
if r != 0:
r /= p ** m00
# r = ZZ(r) % bigpower
g, s, _ = xgcd(r, bigpower)
m10 = M[1, 0] % bigpower
r = (m10 * s) % bigpower
newM = self._Mat_22([p ** m00, 0, r, bigpower])
newM.set_immutable()
# assert self.is_in_group(M_orig.inverse()*newM, as_edge=False)
return newM
def edges_leaving_origin(self):
r"""
Find normalized representatives for the `p+1` edges
leaving the origin vertex corresponding to the homothety class
of `\ZZ_p^2`. These are cached.
OUTPUT:
- A list of size `p+1` of 2x2 integer matrices
EXAMPLES::
sage: from sage.modular.btquotients.btquotient import BruhatTitsTree
sage: T = BruhatTitsTree(3)
sage: T.edges_leaving_origin()
[
[0 1] [3 0] [0 1] [0 1]
[3 0], [0 1], [3 1], [3 2]
]
"""
try:
return self._edges_leaving_origin
except:
p = self._p
self._edges_leaving_origin = [self.edge(self._Mat_22([0, -1, p, 0]))]
self._edges_leaving_origin.extend([self.edge(self._Mat_22([p, i, 0, 1])) for i in range(p)])
return self._edges_leaving_origin
def edge_between_vertices(self, v1, v2, normalized=False):
r"""
Computes the normalized matrix rep. for the edge
passing between two vertices.
INPUT:
- ``v1`` - 2x2 integer matrix
- ``v2`` - 2x2 integer matrix
- ``normalized`` - boolean (Default: False) Whether the
vertices are normalized.
OUTPUT:
- 2x2 integer matrix, representing the edge from ``v1`` to
``v2``. If ``v1`` and ``v2`` are not at distance `1`, raise
a ``ValueError``.
EXAMPLES::
sage: from sage.modular.btquotients.btquotient import BruhatTitsTree
sage: p = 7
sage: T = BruhatTitsTree(p)
sage: v1 = T.vertex(Matrix(ZZ,2,2,[p,0,0,1])); v1
[7 0]
[0 1]
sage: v2 = T.vertex(Matrix(ZZ,2,2,[p,1,0,1])); v2
[1 0]
[1 7]
sage: T.edge_between_vertices(v1,v2)
Traceback (most recent call last):
...
ValueError: Vertices are not adjacent.
sage: v3 = T.vertex(Matrix(ZZ,2,2,[1,0,0,1])); v3
[1 0]
[0 1]
sage: T.edge_between_vertices(v1,v3)
[0 1]
[1 0]
"""
if normalized:
v22 = v2
else:
v22 = self.vertex(v2)
for e in self.leaving_edges(v1):
if self.target(e) == v22:
return e
raise ValueError('Vertices are not adjacent.')
def leaving_edges(self, M):
r"""
Return edges leaving a vertex
INPUT:
- ``M`` - 2x2 integer matrix
OUTPUT:
List of size p+1 of 2x2 integer matrices
EXAMPLES::
sage: from sage.modular.btquotients.btquotient import BruhatTitsTree
sage: p = 7
sage: T = BruhatTitsTree(p)
sage: T.leaving_edges(Matrix(ZZ,2,2,[1,0,0,1]))
[
[0 1] [7 0] [0 1] [0 1] [0 1] [0 1] [0 1] [0 1]
[7 0], [0 1], [7 1], [7 4], [7 5], [7 2], [7 3], [7 6]
]
"""
return [self.edge(M * A) for A in self.edges_leaving_origin()]
def opposite(self, e):
r"""
This function returns the edge oriented oppositely to a
given edge.
INPUT:
- ``e`` - 2x2 integer matrix
OUPUT:
2x2 integer matrix
EXAMPLES::
sage: from sage.modular.btquotients.btquotient import BruhatTitsTree
sage: p = 7
sage: T = BruhatTitsTree(p)
sage: e = Matrix(ZZ,2,2,[1,0,0,1])
sage: T.opposite(e)
[0 1]
[7 0]
sage: T.opposite(T.opposite(e)) == e
True
"""
x = copy(e)
x.swap_columns(0, 1)
x.rescale_col(0, self._p)
return self.edge(x)
def entering_edges(self, v):
r"""
This function returns the edges entering a given vertex.
INPUT:
- ``v`` - 2x2 integer matrix
OUTPUT:
A list of size p+1 of 2x2 integer matrices
EXAMPLES::
sage: from sage.modular.btquotients.btquotient import BruhatTitsTree
sage: p = 7
sage: T = BruhatTitsTree(p)
sage: T.entering_edges(Matrix(ZZ,2,2,[1,0,0,1]))
[
[1 0] [0 1] [1 0] [1 0] [1 0] [1 0] [1 0] [1 0]
[0 1], [1 0], [1 1], [4 1], [5 1], [2 1], [3 1], [6 1]
]
"""
return [self.opposite(e) for e in self.leaving_edges(v)]
def subdivide(self, edgelist, level):
r"""
(Ordered) edges of self may be regarded as open balls in
P_1(Qp). Given a list of edges, this function return a list
of edges corresponding to the level-th subdivision of the
corresponding opens. That is, each open ball of the input is
broken up into `p^\mbox{level}` subballs of equal radius.
INPUT:
- ``edgelist`` - a list of edges
- ``level`` - an integer
OUTPUT:
A list of 2x2 integer matrices
EXAMPLES::
sage: from sage.modular.btquotients.btquotient import BruhatTitsTree
sage: p = 3
sage: T = BruhatTitsTree(p)
sage: T.subdivide([Matrix(ZZ,2,2,[p,0,0,1])],2)
[
[27 0] [0 9] [0 9] [0 3] [0 3] [0 3] [0 3] [0 3] [0 3]
[ 0 1], [3 1], [3 2], [9 1], [9 4], [9 7], [9 2], [9 5], [9 8]
]
"""
if level < 0:
return []
if level == 0:
return [self._Mat_22(edge) for edge in edgelist]
else:
newEgood = []
for edge in edgelist:
edge = self._Mat_22(edge)
origin = self.origin(edge)
newE = self.leaving_edges(self.target(edge))
newEgood.extend([e for e in newE if self.target(e) != origin])
return self.subdivide(newEgood, level - 1)
def get_balls(self, center=1, level=1):
r"""
Returns a decomposition of `\PP^1(\QQ_p)` into compact
open balls.
Each vertex in the Bruhat-Tits tree gives a decomposition of
`\PP^1(\QQ_p)` into `p+1` open balls. Each of these balls may
be further subdivided, to get a finer decomposition.
This function returns the decompostion of `\PP^1(\QQ_p)`
corresponding to ``center`` into `(p+1)p^\mbox{level}` balls.
EXAMPLES::
sage: from sage.modular.btquotients.btquotient import BruhatTitsTree
sage: p = 2
sage: T = BruhatTitsTree(p)
sage: T.get_balls(Matrix(ZZ,2,2,[p,0,0,1]),1)
[
[0 1] [0 1] [8 0] [0 4] [0 2] [0 2]
[2 0], [2 1], [0 1], [2 1], [4 1], [4 3]
]
"""
return self.subdivide(self.leaving_edges(center), level)
def find_path(self, v, boundary=None):
r"""
Computes a path from a vertex to a given set of so-called
boundary vertices, whose interior must contain the origin
vertex. In the case that the boundary is not specified, it
computes the geodesic between the given vertex and the origin.
In the case that the boundary contains more than one vertex,
it computes the geodesic to some point of the boundary.
INPUT:
- ``v`` - a 2x2 matrix representing a vertex ``boundary`` -
- a list of matrices (default: None). If ommitted, finds the
geodesic from ``v`` to the central vertex.
OUTPUT:
An ordered list of vertices describing the geodesic from
``v`` to ``boundary``, followed by the vertex in the boundary
that is closest to ``v``.
EXAMPLES::
sage: from sage.modular.btquotients.btquotient import BruhatTitsTree
sage: p = 3
sage: T = BruhatTitsTree(p)
sage: T.find_path( Matrix(ZZ,2,2,[p^4,0,0,1]) )
(
[[81 0]
[ 0 1], [27 0]
[ 0 1], [9 0]
[0 1], [3 0] [1 0]
[0 1]] , [0 1]
)
sage: T.find_path( Matrix(ZZ,2,2,[p^3,0,134,p^2]) )
(
[[27 0]
[ 8 9], [27 0]
[ 2 3], [27 0]
[ 0 1], [9 0]
[0 1], [3 0] [1 0]
[0 1]] , [0 1]
)
"""
if boundary is None:
m = self._Mat_22(1)
m.set_immutable()
boundary = {m: m}
m = self._mat_p001
new_v = self.vertex(v)
chain = []
while new_v[1, 0] != 0 or new_v[0, 0].valuation(self._p) < new_v[1, 1].valuation(self._p):
if new_v in boundary:
return chain, boundary[new_v]
chain.append(new_v)
new_v = self.vertex(new_v * m)
if new_v in boundary:
return chain, boundary[new_v]
while True:
if new_v in boundary:
return chain, boundary[new_v]
chain.append(new_v)
new_v = self._Mat_22([new_v[0, 0] / self._p, 0, 0, 1])
new_v.set_immutable()
raise RuntimeError
def find_containing_affinoid(self, z):
r"""
Returns the vertex corresponding to the affinoid in the
`p`-adic upper half plane that a given (unramified!) point
reduces to.
INPUT:
- ``z`` - an element of an unramified extension of `\QQ_p`
that is not contained in `\QQ_p`.
OUTPUT:
A 2x2 integer matrix representing a vertex of ``self``.
EXAMPLES::
sage: from sage.modular.btquotients.btquotient import BruhatTitsTree
sage: T = BruhatTitsTree(5)
sage: K.<a> = Qq(5^2,20)
sage: T.find_containing_affinoid(a)
[1 0]
[0 1]
sage: z = 5*a+3
sage: v = T.find_containing_affinoid(z).inverse(); v
[ 1 0]
[-2/5 1/5]
Note that the translate of ``z`` belongs to the standard
affinoid. That is, it is a `p`-adic unit and its reduction
modulo `p` is not in `\FF_p`::
sage: gz = (v[0,0]*z+v[0,1])/(v[1,0]*z+v[1,1]); gz
(a + 1) + O(5^19)
sage: gz.valuation() == 0
True
"""
#Assume z belongs to some extension of QQp.
p = self._p
if z.valuation() < 0:
return self.vertex(self._Mat_22([0, 1, p, 0]) * self.find_containing_affinoid(1 / (p * z)))
a = 0
pn = 1
val = z.valuation()
L = []
for ii in range(val):
L.append(0)
L.extend(z.list())
for n in range(len(L)):
if L[n] != 0:
if len(L[n]) > 1:
break
if len(L[n]) > 0:
a += pn * L[n][0]
pn *= p
return self.vertex(self._Mat_22([pn, a, 0, 1]))
def find_geodesic(self, v1, v2, normalized=True):
r"""
This function computes the geodesic between two vertices
INPUT:
- ``v1`` - 2x2 integer matrix representing a vertex
- ``v2`` - 2x2 integer matrix representing a vertex
- ``normalized`` - boolean (Default: True)
OUTPUT:
An ordered list of 2x2 integer matrices representing the vertices
of the paths joining ``v1`` and ``v2``.
EXAMPLES::
sage: from sage.modular.btquotients.btquotient import BruhatTitsTree
sage: p = 3
sage: T = BruhatTitsTree(p)
sage: v1 = T.vertex( Matrix(ZZ,2,2,[p^3, 0, 1, p^1]) ); v1
[27 0]
[ 1 3]
sage: v2 = T.vertex( Matrix(ZZ,2,2,[p,2,0,p]) ); v2
[1 0]