Path: blob/master/src/sage/modular/arithgroup/congroup_gamma.py
8820 views
r"""1Congruence Subgroup `\Gamma(N)`2"""34################################################################################5#6# Copyright (C) 2009, The Sage Group -- http://www.sagemath.org/7#8# Distributed under the terms of the GNU General Public License (GPL)9#10# The full text of the GPL is available at:11#12# http://www.gnu.org/licenses/13#14################################################################################1516from congroup_generic import CongruenceSubgroup17from sage.misc.misc import prod18from sage.rings.all import ZZ, Zmod, gcd, QQ19from sage.rings.integer import GCD_list20from sage.groups.matrix_gps.finitely_generated import MatrixGroup21from sage.matrix.constructor import matrix22from sage.modular.cusps import Cusp2324from congroup_sl2z import SL2Z2526_gamma_cache = {}27def Gamma_constructor(N):28r"""29Return the congruence subgroup `\Gamma(N)`.3031EXAMPLES::3233sage: Gamma(5) # indirect doctest34Congruence Subgroup Gamma(5)35sage: G = Gamma(23)36sage: G is Gamma(23)37True38sage: TestSuite(G).run()3940Test global uniqueness::4142sage: G = Gamma(17)43sage: G is loads(dumps(G))44True45sage: G2 = sage.modular.arithgroup.congroup_gamma.Gamma_class(17)46sage: G == G247True48sage: G is G249False50"""51if N == 1: return SL2Z52try:53return _gamma_cache[N]54except KeyError:55_gamma_cache[N] = Gamma_class(N)56return _gamma_cache[N]5758class Gamma_class(CongruenceSubgroup):59r"""60The principal congruence subgroup `\Gamma(N)`.61"""626364def _repr_(self):65"""66Return the string representation of self.6768EXAMPLES::6970sage: Gamma(133)._repr_()71'Congruence Subgroup Gamma(133)'72"""73return "Congruence Subgroup Gamma(%s)"%self.level()7475def _latex_(self):76r"""77Return the \LaTeX representation of self.7879EXAMPLES::8081sage: Gamma(20)._latex_()82'\\Gamma(20)'83sage: latex(Gamma(20))84\Gamma(20)85"""86return "\\Gamma(%s)"%self.level()8788def __reduce__(self):89"""90Used for pickling self.9192EXAMPLES::9394sage: Gamma(5).__reduce__()95(<function Gamma_constructor at ...>, (5,))96"""97return Gamma_constructor, (self.level(),)9899def __cmp__(self, other):100r"""101Compare self to other.102103EXAMPLES::104105sage: Gamma(3) == SymmetricGroup(8)106False107sage: Gamma(3) == Gamma1(3)108False109sage: Gamma(5) < Gamma(6)110True111sage: Gamma(5) == Gamma(5)112True113sage: Gamma(3) == Gamma(3).as_permutation_group()114True115"""116if is_Gamma(other):117return cmp(self.level(), other.level())118else:119return CongruenceSubgroup.__cmp__(self, other)120121def index(self):122r"""123Return the index of self in the full modular group. This is given by124125.. math::126127\prod_{\substack{p \mid N \\ \text{$p$ prime}}}\left(p^{3e}-p^{3e-2}\right).128129EXAMPLE::130sage: [Gamma(n).index() for n in [1..19]]131[1, 6, 24, 48, 120, 144, 336, 384, 648, 720, 1320, 1152, 2184, 2016, 2880, 3072, 4896, 3888, 6840]132sage: Gamma(32041).index()13332893086819240134"""135return prod([p**(3*e-2)*(p*p-1) for (p,e) in self.level().factor()])136137def _contains_sl2(self, a,b,c,d):138r"""139EXAMPLES::140141sage: G = Gamma(5)142sage: [1, 0, -10, 1] in G143True144sage: 1 in G145True146sage: SL2Z([26, 5, 5, 1]) in G147True148sage: SL2Z([1, 1, 6, 7]) in G149False150"""151N = self.level()152# don't need to check d == 1 as this is automatic from det153return ((a%N == 1) and (b%N == 0) and (c%N == 0))154155def ncusps(self):156r"""157Return the number of cusps of this subgroup `\Gamma(N)`.158159EXAMPLES::160161sage: [Gamma(n).ncusps() for n in [1..19]]162[1, 3, 4, 6, 12, 12, 24, 24, 36, 36, 60, 48, 84, 72, 96, 96, 144, 108, 180]163sage: Gamma(30030).ncusps()164278691840165sage: Gamma(2^30).ncusps()166432345564227567616167"""168n = self.level()169if n==1:170return ZZ(1)171if n==2:172return ZZ(3)173return prod([p**(2*e) - p**(2*e-2) for (p,e) in n.factor()])//2174175def nirregcusps(self):176r"""177Return the number of irregular cusps of self. For principal congruence subgroups this is always 0.178179EXAMPLE::180181sage: Gamma(17).nirregcusps()1820183"""184return 0185186def _find_cusps(self):187r"""188Calculate the reduced representatives of the equivalence classes of189cusps for this group. Adapted from code by Ron Evans.190191EXAMPLE::192193sage: Gamma(8).cusps() # indirect doctest194[0, 1/4, 1/3, 3/8, 1/2, 2/3, 3/4, 1, 4/3, 3/2, 5/3, 2, 7/3, 5/2, 8/3, 3, 7/2, 11/3, 4, 14/3, 5, 6, 7, Infinity]195"""196n = self.level()197C=[QQ(x) for x in xrange(n)]198199n0=n//2200n1=(n+1)//2201202for r in xrange(1, n1):203if r > 1 and gcd(r,n)==1:204C.append(ZZ(r)/ZZ(n))205if n0==n/2 and gcd(r,n0)==1:206C.append(ZZ(r)/ZZ(n0))207208for s in xrange(2,n1):209for r in xrange(1, 1+n):210if GCD_list([s,r,n])==1:211# GCD_list is ~40x faster than gcd, since gcd wastes loads212# of time initialising a Sequence type.213u,v = _lift_pair(r,s,n)214C.append(ZZ(u)/ZZ(v))215216return [Cusp(x) for x in sorted(C)] + [Cusp(1,0)]217218def reduce_cusp(self, c):219r"""220Calculate the unique reduced representative of the equivalence of the221cusp `c` modulo this group. The reduced representative of an222equivalence class is the unique cusp in the class of the form `u/v`223with `u, v \ge 0` coprime, `v` minimal, and `u` minimal for that `v`.224225EXAMPLES::226227sage: Gamma(5).reduce_cusp(1/5)228Infinity229sage: Gamma(5).reduce_cusp(7/8)2303/2231sage: Gamma(6).reduce_cusp(4/3)2322/3233234TESTS::235236sage: G = Gamma(50); all([c == G.reduce_cusp(c) for c in G.cusps()])237True238"""239N = self.level()240c = Cusp(c)241u,v = c.numerator() % N, c.denominator() % N242if (v > N//2) or (2*v == N and u > N//2):243u,v = -u,-v244u,v = _lift_pair(u,v,N)245return Cusp(u,v)246247def are_equivalent(self, x, y, trans=False):248r"""249Check if the cusps `x` and `y` are equivalent under the action of this group.250251ALGORITHM: The cusps `u_1 / v_1` and `u_2 / v_2` are equivalent modulo252`\Gamma(N)` if and only if `(u_1, v_1) = \pm (u_2, v_2) \bmod N`.253254EXAMPLE::255256sage: Gamma(7).are_equivalent(Cusp(2/3), Cusp(5/4))257True258"""259if trans:260return CongruenceSubgroup.are_equivalent(self, x,y,trans=trans)261N = self.level()262u1,v1 = (x.numerator() % N, x.denominator() % N)263u2,v2 = (y.numerator(), y.denominator())264265return ((u1,v1) == (u2 % N, v2 % N)) or ((u1,v1) == (-u2 % N, -v2 % N))266267def nu3(self):268r"""269Return the number of elliptic points of order 3 for this arithmetic270subgroup. Since this subgroup is `\Gamma(N)` for `N \ge 2`, there are271no such points, so we return 0.272273EXAMPLE::274275sage: Gamma(89).nu3()2760277"""278return 0279280# We don't need to override nu2, since the default nu2 implementation knows281# that nu2 = 0 for odd subgroups.282283def image_mod_n(self):284r"""285Return the image of this group modulo `N`, as a subgroup of `SL(2, \ZZ286/ N\ZZ)`. This is just the trivial subgroup.287288EXAMPLE::289290sage: Gamma(3).image_mod_n()291Matrix group over Ring of integers modulo 3 with 1 generators (292[1 0]293[0 1]294)295"""296return MatrixGroup([matrix(Zmod(self.level()), 2, 2, 1)])297298299def is_Gamma(x):300r"""301Return True if x is a congruence subgroup of type Gamma.302303EXAMPLES::304305sage: from sage.modular.arithgroup.all import is_Gamma306sage: is_Gamma(Gamma0(13))307False308sage: is_Gamma(Gamma(4))309True310"""311312return isinstance(x, Gamma_class)313314def _lift_pair(U,V,N):315r"""316Utility function. Given integers ``U, V, N``, with `N \ge 1` and `{\rm317gcd}(U, V, N) = 1`, return a pair `(u, v)` congruent to `(U, V) \bmod N`,318such that `{\rm gcd}(u,v) = 1`, `u, v \ge 0`, `v` is as small as possible,319and `u` is as small as possible for that `v`.320321*Warning*: As this function is for internal use, it does not do a322preliminary sanity check on its input, for efficiency. It will recover323reasonably gracefully if ``(U, V, N)`` are not coprime, but only after324wasting quite a lot of cycles!325326EXAMPLE::327328sage: from sage.modular.arithgroup.congroup_gamma import _lift_pair329sage: _lift_pair(2,4,7)330(9, 4)331sage: _lift_pair(2,4,8) # don't do this332Traceback (most recent call last):333...334ValueError: (U, V, N) must be coprime335"""336u = U % N337v = V % N338if v == 0:339if u == 1:340return (1,0)341else:342v = N343while gcd(u, v) > 1:344u = u+N345if u > N*v: raise ValueError, "(U, V, N) must be coprime"346return (u, v)347348349