171 | | |
| 173 | |
| 174 | def nirregcusps(self): |
| 175 | r""" |
| 176 | Return the number of irregular cusps of self. For principal congruence subgroups this is always 0. |
| 177 | |
| 178 | EXAMPLE:: |
| 179 | |
| 180 | sage: Gamma(17).nirregcusps() |
| 181 | 0 |
| 182 | """ |
| 183 | return 0 |
| 184 | |
| 185 | def _find_cusps(self): |
| 186 | r""" |
| 187 | Calculate the reduced representatives of the equivalence classes of |
| 188 | cusps for this group. Adapted from code by Ron Evans. |
| 189 | |
| 190 | EXAMPLE:: |
| 191 | |
| 192 | sage: Gamma(8).cusps() # indirect doctest |
| 193 | [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] |
| 194 | """ |
| 195 | n = self.level() |
| 196 | C=[QQ(x) for x in xrange(n)] |
| 197 | |
| 198 | n0=n//2 |
| 199 | n1=(n+1)//2 |
| 200 | |
| 201 | for r in xrange(1, n1): |
| 202 | if r > 1 and gcd(r,n)==1: |
| 203 | C.append(ZZ(r)/ZZ(n)) |
| 204 | if n0==n/2 and gcd(r,n0)==1: |
| 205 | C.append(ZZ(r)/ZZ(n0)) |
| 206 | |
| 207 | for s in xrange(2,n1): |
| 208 | for r in xrange(1, 1+n): |
| 209 | if GCD_list([s,r,n])==1: |
| 210 | # GCD_list is ~40x faster than gcd, since gcd wastes loads |
| 211 | # of time initialising a Sequence type. |
| 212 | u,v = _lift_pair(r,s,n) |
| 213 | C.append(ZZ(u)/ZZ(v)) |
| 214 | |
| 215 | return [Cusp(x) for x in sorted(C)] + [Cusp(1,0)] |
| 216 | |
| 217 | def reduce_cusp(self, c): |
| 218 | r""" |
| 219 | Calculate the unique reduced representative of the equivalence of the |
| 220 | cusp `c` modulo this group. The reduced representative of an |
| 221 | equivalence class is the unique cusp in the class of the form `u/v` |
| 222 | with `u, v \ge 0` coprime, `v` minimal, and `u` minimal for that `v`. |
| 223 | |
| 224 | EXAMPLES:: |
| 225 | |
| 226 | sage: Gamma(5).reduce_cusp(1/5) |
| 227 | Infinity |
| 228 | sage: Gamma(5).reduce_cusp(7/8) |
| 229 | 3/2 |
| 230 | sage: Gamma(6).reduce_cusp(4/3) |
| 231 | 2/3 |
| 232 | |
| 233 | TESTS:: |
| 234 | |
| 235 | sage: G = Gamma(50); all([c == G.reduce_cusp(c) for c in G.cusps()]) |
| 236 | True |
| 237 | """ |
| 238 | N = self.level() |
| 239 | c = Cusp(c) |
| 240 | u,v = c.numerator() % N, c.denominator() % N |
| 241 | if (v > N//2) or (2*v == N and u > N//2): |
| 242 | u,v = -u,-v |
| 243 | u,v = _lift_pair(u,v,N) |
| 244 | return Cusp(u,v) |
| 245 | |
| 246 | def are_equivalent(self, x, y, trans=False): |
| 247 | r""" |
| 248 | Check if the cusps `x` and `y` are equivalent under the action of this group. |
| 249 | |
| 250 | ALGORITHM: The cusps `u_1 / v_1` and `u_2 / v_2` are equivalent modulo |
| 251 | `\Gamma(N)` if and only if `(u_1, v_1) = \pm (u_2, v_2) \bmod N`. |
| 252 | |
| 253 | EXAMPLE:: |
| 254 | |
| 255 | sage: Gamma(7).are_equivalent(Cusp(2/3), Cusp(5/4)) |
| 256 | True |
| 257 | """ |
| 258 | if trans: |
| 259 | return CongruenceSubgroup.are_equivalent(self, x,y,trans=trans) |
| 260 | N = self.level() |
| 261 | u1,v1 = (x.numerator() % N, x.denominator() % N) |
| 262 | u2,v2 = (y.numerator(), y.denominator()) |
| 263 | |
| 264 | return ((u1,v1) == (u2 % N, v2 % N)) or ((u1,v1) == (-u2 % N, -v2 % N)) |
| 265 | |
| 311 | def _lift_pair(U,V,N): |
| 312 | r""" |
| 313 | Utility function. Given integers ``U, V, N``, with `N \ge 1` and `{\rm |
| 314 | gcd}(U, V, N) = 1`, return a pair `(u, v)` congruent to `(U, V) \bmod N`, |
| 315 | such that `{\rm gcd}(u,v) = 1`, `u, v \ge 0`, `v` is as small as possible, |
| 316 | and `u` is as small as possible for that `v`. |
| 317 | |
| 318 | *Warning*: As this function is for internal use, it does not do a |
| 319 | preliminary sanity check on its input, for efficiency. It will recover |
| 320 | reasonably gracefully if ``(U, V, N)`` are not coprime, but only after |
| 321 | wasting quite a lot of cycles! |
| 322 | |
| 323 | EXAMPLE:: |
| 324 | |
| 325 | sage: from sage.modular.arithgroup.congroup_gamma import _lift_pair |
| 326 | sage: _lift_pair(2,4,7) |
| 327 | (9, 4) |
| 328 | sage: _lift_pair(2,4,8) # don't do this |
| 329 | Traceback (most recent call last): |
| 330 | ... |
| 331 | ValueError: (U, V, N) must be coprime |
| 332 | """ |
| 333 | u = U % N |
| 334 | v = V % N |
| 335 | if v == 0: |
| 336 | if u == 1: |
| 337 | return (1,0) |
| 338 | else: |
| 339 | v = N |
| 340 | while gcd(u, v) > 1: |
| 341 | u = u+N |
| 342 | if u > N*v: raise ValueError, "(U, V, N) must be coprime" |
| 343 | return (u, v) |