Path: blob/master/sage/modular/arithgroup/congroup_gamma.py
4079 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 arithgroup_element import ArithmeticSubgroupElement18from sage.misc.misc import prod19from sage.rings.all import ZZ, Zmod, gcd, QQ20from sage.rings.integer import GCD_list21from sage.groups.matrix_gps.matrix_group import MatrixGroup22from sage.matrix.constructor import matrix23from sage.modular.cusps import Cusp2425_gamma_cache = {}26def Gamma_constructor(N):27r"""28Return the congruence subgroup `\Gamma(N)`.2930EXAMPLES::3132sage: Gamma(5) # indirect doctest33Congruence Subgroup Gamma(5)34sage: G = Gamma(23)35sage: G is Gamma(23)36True37sage: G == loads(dumps(G))38True39sage: G is loads(dumps(G))40True41"""42from all import SL2Z43if N == 1: return SL2Z44try:45return _gamma_cache[N]46except KeyError:47_gamma_cache[N] = Gamma_class(N)48return _gamma_cache[N]4950class Gamma_class(CongruenceSubgroup):51r"""52The principal congruence subgroup `\Gamma(N)`.53"""545556def _repr_(self):57"""58Return the string representation of self.5960EXAMPLES::6162sage: Gamma(133)._repr_()63'Congruence Subgroup Gamma(133)'64"""65return "Congruence Subgroup Gamma(%s)"%self.level()6667def __reduce__(self):68"""69Used for pickling self.7071EXAMPLES::7273sage: Gamma(5).__reduce__()74(<function Gamma_constructor at ...>, (5,))75"""76return Gamma_constructor, (self.level(),)7778def __cmp__(self, other):79r"""80Compare self to other.8182EXAMPLES::8384sage: Gamma(3) == SymmetricGroup(8)85False86sage: Gamma(3) == Gamma1(3)87False88sage: Gamma(5) < Gamma(6)89True90sage: Gamma(5) == Gamma(5)91True92"""93if not is_Gamma(other):94return cmp(type(self), type(other))95else:96return cmp(self.level(), other.level())9798def index(self):99r"""100Return the index of self in the full modular group. This is given by101102.. math::103104\prod_{\substack{p \mid N \\ \text{$p$ prime}}}\left(p^{3e}-p^{3e-2}\right).105106EXAMPLE::107sage: [Gamma(n).index() for n in [1..19]]108[1, 6, 24, 48, 120, 144, 336, 384, 648, 720, 1320, 1152, 2184, 2016, 2880, 3072, 4896, 3888, 6840]109sage: Gamma(32041).index()11032893086819240111"""112return prod([p**(3*e-2)*(p*p-1) for (p,e) in self.level().factor()])113114def __call__(self, x, check=True):115r"""116Create an element of this congruence subgroup from x.117118If the optional flag check is True (default), check whether119x actually gives an element of self.120121EXAMPLES::122123sage: G = Gamma(5)124sage: G([1, 0, -10, 1])125[ 1 0]126[-10 1]127sage: G(matrix(ZZ, 2, [26, 5, 5, 1]))128[26 5]129[ 5 1]130sage: G([1, 1, 6, 7])131Traceback (most recent call last):132...133TypeError: matrix must have diagonal entries (=1, 7) congruent to 1134modulo 5, and off-diagonal entries (=1,6) divisible by 5135"""136from all import SL2Z137x = SL2Z(x, check)138if not check:139return x140141a = x.a()142b = x.b()143c = x.c()144d = x.d()145N = self.level()146if (a%N == 1) and (c%N == 0) and (d%N == 1) and (b%N == 0):147return x148else:149raise TypeError, "matrix must have diagonal entries (=%s, %s)\150congruent to 1 modulo %s, and off-diagonal entries (=%s,%s)\151divisible by %s" %(a, d, N, b, c, N)152153def ncusps(self):154r"""155Return the number of cusps of this subgroup `\Gamma(N)`.156157EXAMPLES::158159sage: [Gamma(n).ncusps() for n in [1..19]]160[1, 3, 4, 6, 12, 12, 24, 24, 36, 36, 60, 48, 84, 72, 96, 96, 144, 108, 180]161sage: Gamma(30030).ncusps()162278691840163sage: Gamma(2^30).ncusps()164432345564227567616165"""166n = self.level()167if n==1:168return ZZ(1)169if n==2:170return ZZ(3)171return prod([p**(2*e) - p**(2*e-2) for (p,e) in n.factor()])//2172173def nirregcusps(self):174r"""175Return the number of irregular cusps of self. For principal congruence subgroups this is always 0.176177EXAMPLE::178179sage: Gamma(17).nirregcusps()1800181"""182return 0183184def _find_cusps(self):185r"""186Calculate the reduced representatives of the equivalence classes of187cusps for this group. Adapted from code by Ron Evans.188189EXAMPLE::190191sage: Gamma(8).cusps() # indirect doctest192[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]193"""194n = self.level()195C=[QQ(x) for x in xrange(n)]196197n0=n//2198n1=(n+1)//2199200for r in xrange(1, n1):201if r > 1 and gcd(r,n)==1:202C.append(ZZ(r)/ZZ(n))203if n0==n/2 and gcd(r,n0)==1:204C.append(ZZ(r)/ZZ(n0))205206for s in xrange(2,n1):207for r in xrange(1, 1+n):208if GCD_list([s,r,n])==1:209# GCD_list is ~40x faster than gcd, since gcd wastes loads210# of time initialising a Sequence type.211u,v = _lift_pair(r,s,n)212C.append(ZZ(u)/ZZ(v))213214return [Cusp(x) for x in sorted(C)] + [Cusp(1,0)]215216def reduce_cusp(self, c):217r"""218Calculate the unique reduced representative of the equivalence of the219cusp `c` modulo this group. The reduced representative of an220equivalence class is the unique cusp in the class of the form `u/v`221with `u, v \ge 0` coprime, `v` minimal, and `u` minimal for that `v`.222223EXAMPLES::224225sage: Gamma(5).reduce_cusp(1/5)226Infinity227sage: Gamma(5).reduce_cusp(7/8)2283/2229sage: Gamma(6).reduce_cusp(4/3)2302/3231232TESTS::233234sage: G = Gamma(50); all([c == G.reduce_cusp(c) for c in G.cusps()])235True236"""237N = self.level()238c = Cusp(c)239u,v = c.numerator() % N, c.denominator() % N240if (v > N//2) or (2*v == N and u > N//2):241u,v = -u,-v242u,v = _lift_pair(u,v,N)243return Cusp(u,v)244245def are_equivalent(self, x, y, trans=False):246r"""247Check if the cusps `x` and `y` are equivalent under the action of this group.248249ALGORITHM: The cusps `u_1 / v_1` and `u_2 / v_2` are equivalent modulo250`\Gamma(N)` if and only if `(u_1, v_1) = \pm (u_2, v_2) \bmod N`.251252EXAMPLE::253254sage: Gamma(7).are_equivalent(Cusp(2/3), Cusp(5/4))255True256"""257if trans:258return CongruenceSubgroup.are_equivalent(self, x,y,trans=trans)259N = self.level()260u1,v1 = (x.numerator() % N, x.denominator() % N)261u2,v2 = (y.numerator(), y.denominator())262263return ((u1,v1) == (u2 % N, v2 % N)) or ((u1,v1) == (-u2 % N, -v2 % N))264265def nu3(self):266r"""267Return the number of elliptic points of order 3 for this arithmetic268subgroup. Since this subgroup is `\Gamma(N)` for `N \ge 2`, there are269no such points, so we return 0.270271EXAMPLE::272273sage: Gamma(89).nu3()2740275"""276return 0277278# We don't need to override nu2, since the default nu2 implementation knows279# that nu2 = 0 for odd subgroups.280281def image_mod_n(self):282r"""283Return the image of this group modulo `N`, as a subgroup of `SL(2, \ZZ284/ N\ZZ)`. This is just the trivial subgroup.285286EXAMPLE::287288sage: Gamma(3).image_mod_n()289Matrix group over Ring of integers modulo 3 with 1 generators:290[[[1, 0], [0, 1]]]291"""292return MatrixGroup([matrix(Zmod(self.level()), 2, 2, 1)])293294295def is_Gamma(x):296r"""297Return True if x is a congruence subgroup of type Gamma.298299EXAMPLES::300301sage: from sage.modular.arithgroup.all import is_Gamma302sage: is_Gamma(Gamma0(13))303False304sage: is_Gamma(Gamma(4))305True306"""307308return isinstance(x, Gamma_class)309310def _lift_pair(U,V,N):311r"""312Utility function. Given integers ``U, V, N``, with `N \ge 1` and `{\rm313gcd}(U, V, N) = 1`, return a pair `(u, v)` congruent to `(U, V) \bmod N`,314such that `{\rm gcd}(u,v) = 1`, `u, v \ge 0`, `v` is as small as possible,315and `u` is as small as possible for that `v`.316317*Warning*: As this function is for internal use, it does not do a318preliminary sanity check on its input, for efficiency. It will recover319reasonably gracefully if ``(U, V, N)`` are not coprime, but only after320wasting quite a lot of cycles!321322EXAMPLE::323324sage: from sage.modular.arithgroup.congroup_gamma import _lift_pair325sage: _lift_pair(2,4,7)326(9, 4)327sage: _lift_pair(2,4,8) # don't do this328Traceback (most recent call last):329...330ValueError: (U, V, N) must be coprime331"""332u = U % N333v = V % N334if v == 0:335if u == 1:336return (1,0)337else:338v = N339while gcd(u, v) > 1:340u = u+N341if u > N*v: raise ValueError, "(U, V, N) must be coprime"342return (u, v)343344345