| 531 | | def is_Gamma0(x): |
|---|
| 532 | | """ |
|---|
| 533 | | Return True if x is a congruence subgroup of type Gamma0. |
|---|
| 534 | | |
|---|
| 535 | | EXAMPLES: |
|---|
| 536 | | sage: from sage.modular.congroup import is_Gamma0 |
|---|
| 537 | | sage: is_Gamma0(SL2Z) |
|---|
| 538 | | True |
|---|
| 539 | | sage: is_Gamma0(Gamma0(13)) |
|---|
| 540 | | True |
|---|
| 541 | | sage: is_Gamma0(Gamma1(6)) |
|---|
| 542 | | False |
|---|
| 543 | | """ |
|---|
| 544 | | return isinstance(x, Gamma0_class) |
|---|
| 545 | | |
|---|
| 546 | | _gamma0_cache = {} |
|---|
| 547 | | def Gamma0(N): |
|---|
| 548 | | """ |
|---|
| 549 | | Return the congruence subgroup Gamma0(N). |
|---|
| 550 | | |
|---|
| 551 | | EXAMPLES: |
|---|
| 552 | | sage: G = Gamma0(51) ; G |
|---|
| 553 | | Congruence Subgroup Gamma0(51) |
|---|
| 554 | | sage: G == Gamma0(51) |
|---|
| 555 | | True |
|---|
| 556 | | sage: G is Gamma0(51) |
|---|
| 557 | | True |
|---|
| 558 | | """ |
|---|
| 559 | | try: |
|---|
| 560 | | return _gamma0_cache[N] |
|---|
| 561 | | except KeyError: |
|---|
| 562 | | _gamma0_cache[N] = Gamma0_class(N) |
|---|
| 563 | | return _gamma0_cache[N] |
|---|
| 564 | | |
|---|
| 565 | | class Gamma0_class(CongruenceSubgroup): |
|---|
| 566 | | def __init__(self, level): |
|---|
| 567 | | r""" |
|---|
| 568 | | The congruence subgroup $\Gamma_0(N)$. |
|---|
| 569 | | |
|---|
| 570 | | EXAMPLES: |
|---|
| 571 | | sage: G = Gamma0(11); G |
|---|
| 572 | | Congruence Subgroup Gamma0(11) |
|---|
| 573 | | sage: loads(G.dumps()) == G |
|---|
| 574 | | True |
|---|
| 575 | | """ |
|---|
| 576 | | CongruenceSubgroup.__init__(self, level) |
|---|
| 577 | | |
|---|
| 578 | | def _repr_(self): |
|---|
| 579 | | """ |
|---|
| 580 | | Return the string representation of self. |
|---|
| 581 | | |
|---|
| 582 | | EXAMPLES: |
|---|
| 583 | | sage: Gamma0(98)._repr_() |
|---|
| 584 | | 'Congruence Subgroup Gamma0(98)' |
|---|
| 585 | | """ |
|---|
| 586 | | return "Congruence Subgroup Gamma0(%s)"%self.level() |
|---|
| 587 | | |
|---|
| 588 | | def __reduce__(self): |
|---|
| 589 | | """ |
|---|
| 590 | | Used for pickling self. |
|---|
| 591 | | |
|---|
| 592 | | EXAMPLES: |
|---|
| 593 | | sage: Gamma0(22).__reduce__() |
|---|
| 594 | | (<function Gamma0 at ...>, (22,)) |
|---|
| 595 | | """ |
|---|
| 596 | | return Gamma0, (self.level(),) |
|---|
| 597 | | |
|---|
| 598 | | def _latex_(self): |
|---|
| 599 | | r""" |
|---|
| 600 | | Return the \LaTeX representation of self. |
|---|
| 601 | | |
|---|
| 602 | | EXAMPLES: |
|---|
| 603 | | sage: Gamma0(20)._latex_() |
|---|
| 604 | | '\\Gamma_0(20)' |
|---|
| 605 | | sage: latex(Gamma0(20)) |
|---|
| 606 | | \Gamma_0(20) |
|---|
| 607 | | """ |
|---|
| 608 | | return "\\Gamma_0(%s)"%self.level() |
|---|
| 609 | | |
|---|
| 610 | | def _generators_for_H(self): |
|---|
| 611 | | """ |
|---|
| 612 | | Return generators for the subgroup H of the units mod |
|---|
| 613 | | self.level() that defines self. |
|---|
| 614 | | |
|---|
| 615 | | EXAMPLES: |
|---|
| 616 | | sage: Gamma0(15)._generators_for_H() |
|---|
| 617 | | [11, 7] |
|---|
| 618 | | """ |
|---|
| 619 | | try: |
|---|
| 620 | | return self.__generators_for_H |
|---|
| 621 | | except AttributeError: |
|---|
| 622 | | self.__generators_for_H = [int(x) for x in IntegerModRing(self.level()).unit_gens()] |
|---|
| 623 | | return self.__generators_for_H |
|---|
| 624 | | |
|---|
| 625 | | def _list_of_elements_in_H(self): |
|---|
| 626 | | """ |
|---|
| 627 | | Returns a sorted list of Python ints that are representatives |
|---|
| 628 | | between 0 and N-1 of the elements of H. |
|---|
| 629 | | |
|---|
| 630 | | EXAMPLES: |
|---|
| 631 | | sage: G = Gamma0(11) |
|---|
| 632 | | sage: G._list_of_elements_in_H() |
|---|
| 633 | | [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] |
|---|
| 634 | | |
|---|
| 635 | | sage: G = Gamma0(6) |
|---|
| 636 | | sage: G._list_of_elements_in_H() |
|---|
| 637 | | [1, 5] |
|---|
| 638 | | |
|---|
| 639 | | sage: G = Gamma0(1) |
|---|
| 640 | | sage: G._list_of_elements_in_H() |
|---|
| 641 | | [1] |
|---|
| 642 | | """ |
|---|
| 643 | | N = self.level() |
|---|
| 644 | | if N != 1: |
|---|
| 645 | | gcd = arith.gcd |
|---|
| 646 | | return [ x for x in range(1, N) if gcd(x, N) == 1 ] |
|---|
| 647 | | else: |
|---|
| 648 | | return [1] |
|---|
| 649 | | |
|---|
| 650 | | def __cmp__(self, right): |
|---|
| 651 | | """ |
|---|
| 652 | | Compare self to right. |
|---|
| 653 | | |
|---|
| 654 | | EXAMPLES: |
|---|
| 655 | | sage: Gamma0(21).__cmp__(Gamma0(21)) |
|---|
| 656 | | 0 |
|---|
| 657 | | sage: Gamma0(21) < Gamma0(32) |
|---|
| 658 | | True |
|---|
| 659 | | """ |
|---|
| 660 | | if not is_Gamma0(right): |
|---|
| 661 | | if is_CongruenceSubgroup(right): |
|---|
| 662 | | c = cmp(self.level(), right.level()) |
|---|
| 663 | | if c: return c |
|---|
| 664 | | return cmp(type(self), type(right)) |
|---|
| 665 | | return cmp(self.level(), right.level()) |
|---|
| 666 | | |
|---|
| 667 | | def is_even(self): |
|---|
| 668 | | """ |
|---|
| 669 | | Return True precisely if this subgroup contains the matrix -1. |
|---|
| 670 | | |
|---|
| 671 | | Since Gamma0(N) always, contains the matrix -1, this always |
|---|
| 672 | | returns True. |
|---|
| 673 | | |
|---|
| 674 | | EXAMPLES: |
|---|
| 675 | | sage: Gamma0(12).is_even() |
|---|
| 676 | | True |
|---|
| 677 | | sage: SL2Z.is_even() |
|---|
| 678 | | True |
|---|
| 679 | | """ |
|---|
| 680 | | return True |
|---|
| 681 | | |
|---|
| 682 | | def is_subgroup(self, right): |
|---|
| 683 | | """ |
|---|
| 684 | | Return True if self is a subgroup of right. |
|---|
| 685 | | |
|---|
| 686 | | EXAMPLES: |
|---|
| 687 | | sage: G = Gamma0(20) |
|---|
| 688 | | sage: G.is_subgroup(SL2Z) |
|---|
| 689 | | True |
|---|
| 690 | | sage: G.is_subgroup(Gamma0(4)) |
|---|
| 691 | | True |
|---|
| 692 | | sage: G.is_subgroup(Gamma0(20)) |
|---|
| 693 | | True |
|---|
| 694 | | sage: G.is_subgroup(Gamma0(7)) |
|---|
| 695 | | False |
|---|
| 696 | | sage: Gamma0(2).is_subgroup(Gamma1(2)) |
|---|
| 697 | | True |
|---|
| 698 | | """ |
|---|
| 699 | | if right.level() == 1: |
|---|
| 700 | | return True |
|---|
| 701 | | if is_Gamma0(right): |
|---|
| 702 | | return self.level() % right.level() == 0 |
|---|
| 703 | | if is_Gamma1(right): |
|---|
| 704 | | if right.level() >= 3: |
|---|
| 705 | | return False |
|---|
| 706 | | elif right.level() == 2: |
|---|
| 707 | | return self.level() == 2 |
|---|
| 708 | | # case level 1 dealt with above |
|---|
| 709 | | raise NotImplementedError |
|---|
| 710 | | |
|---|
| 711 | | def coset_reps(self): |
|---|
| 712 | | r""" |
|---|
| 713 | | Return representatives for the right cosets of this congruence |
|---|
| 714 | | subgroup in ${\rm SL}_2(\Z)$ as a generator object. |
|---|
| 715 | | |
|---|
| 716 | | Use \code{list(self.coset_reps())} to obtain coset reps as a |
|---|
| 717 | | list. |
|---|
| 718 | | |
|---|
| 719 | | EXAMPLES: |
|---|
| 720 | | sage: list(Gamma0(5).coset_reps()) |
|---|
| 721 | | [[1, 0, 0, 1], |
|---|
| 722 | | [0, -1, 1, 0], |
|---|
| 723 | | [1, 0, 1, 1], |
|---|
| 724 | | [1, 1, 1, 2], |
|---|
| 725 | | [1, 2, 1, 3], |
|---|
| 726 | | [1, 3, 1, 4]] |
|---|
| 727 | | sage: list(Gamma0(4).coset_reps()) |
|---|
| 728 | | [[1, 0, 0, 1], |
|---|
| 729 | | [0, -1, 1, 0], |
|---|
| 730 | | [1, 0, 1, 1], |
|---|
| 731 | | [1, 1, 1, 2], |
|---|
| 732 | | [1, 2, 1, 3], |
|---|
| 733 | | [-1, -1, 2, 1]] |
|---|
| 734 | | sage: list(Gamma0(1).coset_reps()) |
|---|
| 735 | | [[1, 0, 0, 1]] |
|---|
| 736 | | """ |
|---|
| 737 | | N = self.level() |
|---|
| 738 | | for z in sage.modular.modsym.p1list.P1List(N): |
|---|
| 739 | | yield lift_to_sl2z(z[0], z[1], N) |
|---|
| 740 | | |
|---|
| 741 | | def generators(self): |
|---|
| 742 | | r""" |
|---|
| 743 | | Return generators for this congruence subgroup. |
|---|
| 744 | | |
|---|
| 745 | | The result is cached. |
|---|
| 746 | | |
|---|
| 747 | | EXAMPLE: |
|---|
| 748 | | sage: for g in Gamma0(3).generators(): |
|---|
| 749 | | ... print g |
|---|
| 750 | | ... print '---' |
|---|
| 751 | | [1 1] |
|---|
| 752 | | [0 1] |
|---|
| 753 | | --- |
|---|
| 754 | | [-1 0] |
|---|
| 755 | | [ 0 -1] |
|---|
| 756 | | --- |
|---|
| 757 | | ... |
|---|
| 758 | | --- |
|---|
| 759 | | [-2 1] |
|---|
| 760 | | [-3 1] |
|---|
| 761 | | --- |
|---|
| 762 | | |
|---|
| 763 | | """ |
|---|
| 764 | | try: |
|---|
| 765 | | return self.__gens |
|---|
| 766 | | except AttributeError: |
|---|
| 767 | | from sage.modular.modsym.p1list import P1List |
|---|
| 768 | | from congroup_pyx import generators_helper |
|---|
| 769 | | level = self.level() |
|---|
| 770 | | gen_list = generators_helper(P1List(level), level, Mat2Z) |
|---|
| 771 | | self.__gens = [self(g, check=False) for g in gen_list] |
|---|
| 772 | | return self.__gens |
|---|
| 773 | | |
|---|
| 774 | | def gamma_h_subgroups(self): |
|---|
| 775 | | r""" |
|---|
| 776 | | Return the subgroups of the form $\Gamma_H(N)$ contained |
|---|
| 777 | | in self, where $N$ is the level of self. |
|---|
| 778 | | |
|---|
| 779 | | EXAMPLES: |
|---|
| 780 | | sage: G = Gamma0(11) |
|---|
| 781 | | sage: G.gamma_h_subgroups() |
|---|
| 782 | | [Congruence Subgroup Gamma_H(11) with H generated by [2], Congruence Subgroup Gamma_H(11) with H generated by [4], Congruence Subgroup Gamma_H(11) with H generated by [10], Congruence Subgroup Gamma_H(11) with H generated by []] |
|---|
| 783 | | sage: G = Gamma0(12) |
|---|
| 784 | | sage: G.gamma_h_subgroups() |
|---|
| 785 | | [Congruence Subgroup Gamma_H(12) with H generated by [5, 7], Congruence Subgroup Gamma_H(12) with H generated by [7], Congruence Subgroup Gamma_H(12) with H generated by [5], Congruence Subgroup Gamma_H(12) with H generated by []] |
|---|
| 786 | | """ |
|---|
| 787 | | N = self.level() |
|---|
| 788 | | R = IntegerModRing(N) |
|---|
| 789 | | return [GammaH(N, H) for H in R.multiplicative_subgroups()] |
|---|
| 790 | | |
|---|
| 791 | | def __call__(self, x, check=True): |
|---|
| 792 | | r""" |
|---|
| 793 | | Create an element of this congruence subgroup from x. |
|---|
| 794 | | |
|---|
| 795 | | If the optional flag check is True (default), check whether |
|---|
| 796 | | x actually gives an element of self. |
|---|
| 797 | | |
|---|
| 798 | | EXAMPLES: |
|---|
| 799 | | sage: G = Gamma0(12) |
|---|
| 800 | | sage: G([1, 0, 24, 1]) |
|---|
| 801 | | [ 1 0] |
|---|
| 802 | | [24 1] |
|---|
| 803 | | sage: G(matrix(ZZ, 2, [1, 1, -12, -11])) |
|---|
| 804 | | [ 1 1] |
|---|
| 805 | | [-12 -11] |
|---|
| 806 | | sage: G([1, 0, 23, 1]) |
|---|
| 807 | | Traceback (most recent call last): |
|---|
| 808 | | ... |
|---|
| 809 | | TypeError: matrix must have lower left entry (=23) divisible by 12 |
|---|
| 810 | | """ |
|---|
| 811 | | if isinstance(x, CongruenceSubgroupElement) and x.parent() == self: |
|---|
| 812 | | return x |
|---|
| 813 | | x = CongruenceSubgroupElement(self, x, check=check) |
|---|
| 814 | | if not check: |
|---|
| 815 | | return x |
|---|
| 816 | | |
|---|
| 817 | | c = x.c() |
|---|
| 818 | | N = self.level() |
|---|
| 819 | | if c%N == 0: |
|---|
| 820 | | return x |
|---|
| 821 | | else: |
|---|
| 822 | | raise TypeError, "matrix must have lower left entry (=%s) divisible by %s" %(c, N) |
|---|
| 823 | | |
|---|
| 824 | | def is_SL2Z(x): |
|---|
| 825 | | """ |
|---|
| 826 | | Return True if x is the modular group ${\rm SL}_2(\Z)$. |
|---|
| 827 | | |
|---|
| 828 | | EXAMPLES: |
|---|
| 829 | | sage: from sage.modular.congroup import is_SL2Z |
|---|
| 830 | | sage: is_SL2Z(SL2Z) |
|---|
| 831 | | True |
|---|
| 832 | | sage: is_SL2Z(Gamma0(6)) |
|---|
| 833 | | False |
|---|
| 834 | | """ |
|---|
| 835 | | return isinstance(x, SL2Z_class) |
|---|
| 836 | | |
|---|
| 837 | | class SL2Z_class(Gamma0_class): |
|---|
| 838 | | def __init__(self): |
|---|
| 839 | | r""" |
|---|
| 840 | | The modular group ${\rm SL}_2(\Z)$. |
|---|
| 841 | | |
|---|
| 842 | | EXAMPLES: |
|---|
| 843 | | sage: G = SL2Z; G |
|---|
| 844 | | Modular Group SL(2,Z) |
|---|
| 845 | | sage: G.gens() |
|---|
| 846 | | ([ 0 -1] |
|---|
| 847 | | [ 1 0], [1 1] |
|---|
| 848 | | [0 1]) |
|---|
| 849 | | sage: G.0 |
|---|
| 850 | | [ 0 -1] |
|---|
| 851 | | [ 1 0] |
|---|
| 852 | | sage: G.1 |
|---|
| 853 | | [1 1] |
|---|
| 854 | | [0 1] |
|---|
| 855 | | sage: latex(G) |
|---|
| 856 | | \mbox{\rm SL}_2(\mathbf{Z}) |
|---|
| 857 | | sage: G([1,-1,0,1]) |
|---|
| 858 | | [ 1 -1] |
|---|
| 859 | | [ 0 1] |
|---|
| 860 | | sage: loads(G.dumps()) == G |
|---|
| 861 | | True |
|---|
| 862 | | sage: SL2Z.0 * SL2Z.1 |
|---|
| 863 | | [ 0 -1] |
|---|
| 864 | | [ 1 1] |
|---|
| 865 | | |
|---|
| 866 | | sage: SL2Z == loads(dumps(SL2Z)) |
|---|
| 867 | | True |
|---|
| 868 | | sage: SL2Z is loads(dumps(SL2Z)) |
|---|
| 869 | | True |
|---|
| 870 | | """ |
|---|
| 871 | | Gamma0_class.__init__(self, 1) |
|---|
| 872 | | |
|---|
| 873 | | def __reduce__(self): |
|---|
| 874 | | """ |
|---|
| 875 | | Used for pickling self. |
|---|
| 876 | | |
|---|
| 877 | | EXAMPLES: |
|---|
| 878 | | sage: SL2Z.__reduce__() |
|---|
| 879 | | (<function _SL2Z_ref at ...>, ()) |
|---|
| 880 | | """ |
|---|
| 881 | | return _SL2Z_ref, () |
|---|
| 882 | | |
|---|
| 883 | | def _repr_(self): |
|---|
| 884 | | """ |
|---|
| 885 | | Return the string representation of self. |
|---|
| 886 | | |
|---|
| 887 | | EXAMPLES: |
|---|
| 888 | | sage: SL2Z._repr_() |
|---|
| 889 | | 'Modular Group SL(2,Z)' |
|---|
| 890 | | """ |
|---|
| 891 | | return "Modular Group SL(2,Z)" |
|---|
| 892 | | |
|---|
| 893 | | def _latex_(self): |
|---|
| 894 | | r""" |
|---|
| 895 | | Return the \LaTeX representation of self. |
|---|
| 896 | | |
|---|
| 897 | | EXAMPLES: |
|---|
| 898 | | sage: SL2Z._latex_() |
|---|
| 899 | | '\\mbox{\\rm SL}_2(\\mathbf{Z})' |
|---|
| 900 | | sage: latex(SL2Z) |
|---|
| 901 | | \mbox{\rm SL}_2(\mathbf{Z}) |
|---|
| 902 | | """ |
|---|
| 903 | | return "\\mbox{\\rm SL}_2(%s)"%(ZZ._latex_()) |
|---|
| 904 | | |
|---|
| 905 | | def is_subgroup(self, right): |
|---|
| 906 | | """ |
|---|
| 907 | | Return True if self is a subgroup of right. |
|---|
| 908 | | |
|---|
| 909 | | EXAMPLES: |
|---|
| 910 | | sage: SL2Z.is_subgroup(SL2Z) |
|---|
| 911 | | True |
|---|
| 912 | | sage: SL2Z.is_subgroup(Gamma1(1)) |
|---|
| 913 | | True |
|---|
| 914 | | sage: SL2Z.is_subgroup(Gamma0(6)) |
|---|
| 915 | | False |
|---|
| 916 | | """ |
|---|
| 917 | | return right.level() == 1 |
|---|
| 918 | | |
|---|
| 919 | | SL2Z = SL2Z_class() |
|---|
| 920 | | |
|---|
| 921 | | def _SL2Z_ref(): |
|---|
| 922 | | """ |
|---|
| 923 | | Return SL2Z. (Used for pickling SL2Z.) |
|---|
| 924 | | |
|---|
| 925 | | EXAMPLES: |
|---|
| 926 | | sage: sage.modular.congroup._SL2Z_ref() |
|---|
| 927 | | Modular Group SL(2,Z) |
|---|
| 928 | | sage: sage.modular.congroup._SL2Z_ref() is SL2Z |
|---|
| 929 | | True |
|---|
| 930 | | """ |
|---|
| 931 | | return SL2Z |
|---|
| 932 | | |
|---|
| 933 | | def is_Gamma1(x): |
|---|
| 934 | | """ |
|---|
| 935 | | Return True if x is a congruence subgroup of type Gamma1. |
|---|
| 936 | | |
|---|
| 937 | | EXAMPLES: |
|---|
| 938 | | sage: from sage.modular.congroup import is_Gamma1 |
|---|
| 939 | | sage: is_Gamma1(SL2Z) |
|---|
| 940 | | True |
|---|
| 941 | | sage: is_Gamma1(Gamma1(13)) |
|---|
| 942 | | True |
|---|
| 943 | | sage: is_Gamma1(Gamma0(6)) |
|---|
| 944 | | False |
|---|
| 945 | | """ |
|---|
| 946 | | return (isinstance(x, Gamma1_class) or is_SL2Z(x)) |
|---|
| 947 | | |
|---|
| 948 | | _gamma1_cache = {} |
|---|
| 949 | | def Gamma1(N): |
|---|
| 950 | | r""" |
|---|
| 951 | | Return the congruence subgroup $\Gamma_1(N)$. |
|---|
| 952 | | |
|---|
| 953 | | EXAMPLES: |
|---|
| 954 | | sage: Gamma1(5) |
|---|
| 955 | | Congruence Subgroup Gamma1(5) |
|---|
| 956 | | sage: G = Gamma1(23) |
|---|
| 957 | | sage: G is Gamma1(23) |
|---|
| 958 | | True |
|---|
| 959 | | sage: G == loads(dumps(G)) |
|---|
| 960 | | True |
|---|
| 961 | | sage: G is loads(dumps(G)) |
|---|
| 962 | | True |
|---|
| 963 | | """ |
|---|
| 964 | | try: |
|---|
| 965 | | return _gamma1_cache[N] |
|---|
| 966 | | except KeyError: |
|---|
| 967 | | _gamma1_cache[N] = Gamma1_class(N) |
|---|
| 968 | | return _gamma1_cache[N] |
|---|
| 969 | | |
|---|
| 970 | | class Gamma1_class(CongruenceSubgroup): |
|---|
| 971 | | def __init__(self, level): |
|---|
| 972 | | r""" |
|---|
| 973 | | The congruence subgroup $\Gamma_1(N)$. |
|---|
| 974 | | |
|---|
| 975 | | EXAMPLES: |
|---|
| 976 | | sage: G = Gamma1(11); G |
|---|
| 977 | | Congruence Subgroup Gamma1(11) |
|---|
| 978 | | sage: loads(G.dumps()) == G |
|---|
| 979 | | True |
|---|
| 980 | | """ |
|---|
| 981 | | CongruenceSubgroup.__init__(self, level) |
|---|
| 982 | | |
|---|
| 983 | | def _repr_(self): |
|---|
| 984 | | """ |
|---|
| 985 | | Return the string representation of self. |
|---|
| 986 | | |
|---|
| 987 | | EXAMPLES: |
|---|
| 988 | | sage: Gamma1(133)._repr_() |
|---|
| 989 | | 'Congruence Subgroup Gamma1(133)' |
|---|
| 990 | | """ |
|---|
| 991 | | return "Congruence Subgroup Gamma1(%s)"%self.level() |
|---|
| 992 | | |
|---|
| 993 | | def __reduce__(self): |
|---|
| 994 | | """ |
|---|
| 995 | | Used for pickling self. |
|---|
| 996 | | |
|---|
| 997 | | EXAMPLES: |
|---|
| 998 | | sage: Gamma1(82).__reduce__() |
|---|
| 999 | | (<function Gamma1 at ...>, (82,)) |
|---|
| 1000 | | """ |
|---|
| 1001 | | return Gamma1, (self.level(),) |
|---|
| 1002 | | |
|---|
| 1003 | | def _latex_(self): |
|---|
| 1004 | | r""" |
|---|
| 1005 | | Return the \LaTeX representation of self. |
|---|
| 1006 | | |
|---|
| 1007 | | EXAMPLES: |
|---|
| 1008 | | sage: Gamma1(3)._latex_() |
|---|
| 1009 | | '\\Gamma_1(3)' |
|---|
| 1010 | | sage: latex(Gamma1(3)) |
|---|
| 1011 | | \Gamma_1(3) |
|---|
| 1012 | | """ |
|---|
| 1013 | | return "\\Gamma_1(%s)"%self.level() |
|---|
| 1014 | | |
|---|
| 1015 | | def __cmp__(self, right): |
|---|
| 1016 | | """ |
|---|
| 1017 | | Compare self to right. |
|---|
| 1018 | | |
|---|
| 1019 | | EXAMPLES: |
|---|
| 1020 | | sage: G = Gamma1(111) |
|---|
| 1021 | | sage: G.__cmp__(Gamma1(111)) |
|---|
| 1022 | | 0 |
|---|
| 1023 | | sage: G.__cmp__(135) is not 0 |
|---|
| 1024 | | True |
|---|
| 1025 | | """ |
|---|
| 1026 | | if not is_Gamma1(right): |
|---|
| 1027 | | if is_CongruenceSubgroup(right): |
|---|
| 1028 | | c = cmp(self.level(), right.level()) |
|---|
| 1029 | | if c: return c |
|---|
| 1030 | | return cmp(type(self), type(right)) |
|---|
| 1031 | | return cmp(self.level(), right.level()) |
|---|
| 1032 | | |
|---|
| 1033 | | def is_even(self): |
|---|
| 1034 | | """ |
|---|
| 1035 | | Return True precisely if this subgroup contains the matrix -1. |
|---|
| 1036 | | |
|---|
| 1037 | | EXAMPLES: |
|---|
| 1038 | | sage: Gamma1(1).is_even() |
|---|
| 1039 | | True |
|---|
| 1040 | | sage: Gamma1(2).is_even() |
|---|
| 1041 | | True |
|---|
| 1042 | | sage: Gamma1(15).is_even() |
|---|
| 1043 | | False |
|---|
| 1044 | | """ |
|---|
| 1045 | | return self.level() in [1,2] |
|---|
| 1046 | | |
|---|
| 1047 | | def is_subgroup(self, right): |
|---|
| 1048 | | """ |
|---|
| 1049 | | Return True if self is a subgroup of right. |
|---|
| 1050 | | |
|---|
| 1051 | | EXAMPLES: |
|---|
| 1052 | | sage: Gamma1(3).is_subgroup(SL2Z) |
|---|
| 1053 | | True |
|---|
| 1054 | | sage: Gamma1(3).is_subgroup(Gamma1(5)) |
|---|
| 1055 | | False |
|---|
| 1056 | | sage: Gamma1(3).is_subgroup(Gamma1(6)) |
|---|
| 1057 | | False |
|---|
| 1058 | | sage: Gamma1(6).is_subgroup(Gamma1(3)) |
|---|
| 1059 | | True |
|---|
| 1060 | | sage: Gamma1(6).is_subgroup(Gamma0(2)) |
|---|
| 1061 | | True |
|---|
| 1062 | | """ |
|---|
| 1063 | | if right.level() == 1: |
|---|
| 1064 | | return True |
|---|
| 1065 | | if is_Gamma0(right) or is_Gamma1(right): |
|---|
| 1066 | | return self.level() % right.level() == 0 |
|---|
| 1067 | | raise NotImplementedError |
|---|
| 1068 | | |
|---|
| 1069 | | def generators(self): |
|---|
| 1070 | | r""" |
|---|
| 1071 | | Return generators for this congruence subgroup. |
|---|
| 1072 | | |
|---|
| 1073 | | The result is cached. |
|---|
| 1074 | | |
|---|
| 1075 | | EXAMPLE: |
|---|
| 1076 | | sage: for g in Gamma1(3).generators(): |
|---|
| 1077 | | ... print g |
|---|
| 1078 | | ... print '---' |
|---|
| 1079 | | [1 1] |
|---|
| 1080 | | [0 1] |
|---|
| 1081 | | --- |
|---|
| 1082 | | [ 31 -14] |
|---|
| 1083 | | [ 51 -23] |
|---|
| 1084 | | --- |
|---|
| 1085 | | [-5 4] |
|---|
| 1086 | | [-9 7] |
|---|
| 1087 | | --- |
|---|
| 1088 | | ... |
|---|
| 1089 | | --- |
|---|
| 1090 | | [4 3] |
|---|
| 1091 | | [9 7] |
|---|
| 1092 | | --- |
|---|
| 1093 | | [ -5 -2] |
|---|
| 1094 | | [-12 -5] |
|---|
| 1095 | | --- |
|---|
| 1096 | | |
|---|
| 1097 | | """ |
|---|
| 1098 | | try: |
|---|
| 1099 | | return self.__gens |
|---|
| 1100 | | except AttributeError: |
|---|
| 1101 | | from sage.modular.modsym.g1list import G1list |
|---|
| 1102 | | from congroup_pyx import generators_helper |
|---|
| 1103 | | level = self.level() |
|---|
| 1104 | | gen_list = generators_helper(G1list(level), level, Mat2Z) |
|---|
| 1105 | | self.__gens = [self(g, check=False) for g in gen_list] |
|---|
| 1106 | | return self.__gens |
|---|
| 1107 | | |
|---|
| 1108 | | def __call__(self, x, check=True): |
|---|
| 1109 | | r""" |
|---|
| 1110 | | Create an element of this congruence subgroup from x. |
|---|
| 1111 | | |
|---|
| 1112 | | If the optional flag check is True (default), check whether |
|---|
| 1113 | | x actually gives an element of self. |
|---|
| 1114 | | |
|---|
| 1115 | | EXAMPLES: |
|---|
| 1116 | | sage: G = Gamma1(5) |
|---|
| 1117 | | sage: G([1, 0, -10, 1]) |
|---|
| 1118 | | [ 1 0] |
|---|
| 1119 | | [-10 1] |
|---|
| 1120 | | sage: G(matrix(ZZ, 2, [6, 1, 5, 1])) |
|---|
| 1121 | | [6 1] |
|---|
| 1122 | | [5 1] |
|---|
| 1123 | | sage: G([1, 1, 6, 7]) |
|---|
| 1124 | | Traceback (most recent call last): |
|---|
| 1125 | | ... |
|---|
| 1126 | | TypeError: matrix must have diagonal entries (=1, 7) congruent to 1 modulo 5, and lower left entry (=6) divisible by 5 |
|---|
| 1127 | | """ |
|---|
| 1128 | | if isinstance(x, CongruenceSubgroupElement) and x.parent() == self: |
|---|
| 1129 | | return x |
|---|
| 1130 | | x = CongruenceSubgroupElement(self, x, check=check) |
|---|
| 1131 | | if not check: |
|---|
| 1132 | | return x |
|---|
| 1133 | | |
|---|
| 1134 | | a = x.a() |
|---|
| 1135 | | c = x.c() |
|---|
| 1136 | | d = x.d() |
|---|
| 1137 | | N = self.level() |
|---|
| 1138 | | if (a%N == 1) and (c%N == 0) and (d%N == 1): |
|---|
| 1139 | | return x |
|---|
| 1140 | | else: |
|---|
| 1141 | | raise TypeError, "matrix must have diagonal entries (=%s, %s) congruent to 1 modulo %s, and lower left entry (=%s) divisible by %s" %(a, d, N, c, N) |
|---|
| 1142 | | |
|---|
| | 1332 | def is_Gamma0(x): |
|---|
| | 1333 | """ |
|---|
| | 1334 | Return True if x is a congruence subgroup of type Gamma0. |
|---|
| | 1335 | |
|---|
| | 1336 | EXAMPLES: |
|---|
| | 1337 | sage: from sage.modular.congroup import is_Gamma0 |
|---|
| | 1338 | sage: is_Gamma0(SL2Z) |
|---|
| | 1339 | True |
|---|
| | 1340 | sage: is_Gamma0(Gamma0(13)) |
|---|
| | 1341 | True |
|---|
| | 1342 | sage: is_Gamma0(Gamma1(6)) |
|---|
| | 1343 | False |
|---|
| | 1344 | """ |
|---|
| | 1345 | return isinstance(x, Gamma0_class) |
|---|
| | 1346 | |
|---|
| | 1347 | _gamma0_cache = {} |
|---|
| | 1348 | def Gamma0(N): |
|---|
| | 1349 | """ |
|---|
| | 1350 | Return the congruence subgroup Gamma0(N). |
|---|
| | 1351 | |
|---|
| | 1352 | EXAMPLES: |
|---|
| | 1353 | sage: G = Gamma0(51) ; G |
|---|
| | 1354 | Congruence Subgroup Gamma0(51) |
|---|
| | 1355 | sage: G == Gamma0(51) |
|---|
| | 1356 | True |
|---|
| | 1357 | sage: G is Gamma0(51) |
|---|
| | 1358 | True |
|---|
| | 1359 | """ |
|---|
| | 1360 | try: |
|---|
| | 1361 | return _gamma0_cache[N] |
|---|
| | 1362 | except KeyError: |
|---|
| | 1363 | _gamma0_cache[N] = Gamma0_class(N) |
|---|
| | 1364 | return _gamma0_cache[N] |
|---|
| | 1365 | |
|---|
| | 1366 | class Gamma0_class(GammaH_class): |
|---|
| | 1367 | def __init__(self, level): |
|---|
| | 1368 | r""" |
|---|
| | 1369 | The congruence subgroup $\Gamma_0(N)$. |
|---|
| | 1370 | |
|---|
| | 1371 | EXAMPLES: |
|---|
| | 1372 | sage: G = Gamma0(11); G |
|---|
| | 1373 | Congruence Subgroup Gamma0(11) |
|---|
| | 1374 | sage: loads(G.dumps()) == G |
|---|
| | 1375 | True |
|---|
| | 1376 | """ |
|---|
| | 1377 | GammaH_class.__init__(self, level, [int(x) for x in IntegerModRing(level).unit_gens()]) |
|---|
| | 1378 | |
|---|
| | 1379 | def _repr_(self): |
|---|
| | 1380 | """ |
|---|
| | 1381 | Return the string representation of self. |
|---|
| | 1382 | |
|---|
| | 1383 | EXAMPLES: |
|---|
| | 1384 | sage: Gamma0(98)._repr_() |
|---|
| | 1385 | 'Congruence Subgroup Gamma0(98)' |
|---|
| | 1386 | """ |
|---|
| | 1387 | return "Congruence Subgroup Gamma0(%s)"%self.level() |
|---|
| | 1388 | |
|---|
| | 1389 | def __reduce__(self): |
|---|
| | 1390 | """ |
|---|
| | 1391 | Used for pickling self. |
|---|
| | 1392 | |
|---|
| | 1393 | EXAMPLES: |
|---|
| | 1394 | sage: Gamma0(22).__reduce__() |
|---|
| | 1395 | (<function Gamma0 at ...>, (22,)) |
|---|
| | 1396 | """ |
|---|
| | 1397 | return Gamma0, (self.level(),) |
|---|
| | 1398 | |
|---|
| | 1399 | def _latex_(self): |
|---|
| | 1400 | r""" |
|---|
| | 1401 | Return the \LaTeX representation of self. |
|---|
| | 1402 | |
|---|
| | 1403 | EXAMPLES: |
|---|
| | 1404 | sage: Gamma0(20)._latex_() |
|---|
| | 1405 | '\\Gamma_0(20)' |
|---|
| | 1406 | sage: latex(Gamma0(20)) |
|---|
| | 1407 | \Gamma_0(20) |
|---|
| | 1408 | """ |
|---|
| | 1409 | return "\\Gamma_0(%s)"%self.level() |
|---|
| | 1410 | |
|---|
| | 1411 | def _generators_for_H(self): |
|---|
| | 1412 | """ |
|---|
| | 1413 | Return generators for the subgroup H of the units mod |
|---|
| | 1414 | self.level() that defines self. |
|---|
| | 1415 | |
|---|
| | 1416 | EXAMPLES: |
|---|
| | 1417 | sage: Gamma0(15)._generators_for_H() |
|---|
| | 1418 | [11, 7] |
|---|
| | 1419 | """ |
|---|
| | 1420 | try: |
|---|
| | 1421 | return self.__generators_for_H |
|---|
| | 1422 | except AttributeError: |
|---|
| | 1423 | self.__generators_for_H = [int(x) for x in IntegerModRing(self.level()).unit_gens()] |
|---|
| | 1424 | return self.__generators_for_H |
|---|
| | 1425 | |
|---|
| | 1426 | def _list_of_elements_in_H(self): |
|---|
| | 1427 | """ |
|---|
| | 1428 | Returns a sorted list of Python ints that are representatives |
|---|
| | 1429 | between 0 and N-1 of the elements of H. |
|---|
| | 1430 | |
|---|
| | 1431 | EXAMPLES: |
|---|
| | 1432 | sage: G = Gamma0(11) |
|---|
| | 1433 | sage: G._list_of_elements_in_H() |
|---|
| | 1434 | [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] |
|---|
| | 1435 | |
|---|
| | 1436 | sage: G = Gamma0(6) |
|---|
| | 1437 | sage: G._list_of_elements_in_H() |
|---|
| | 1438 | [1, 5] |
|---|
| | 1439 | |
|---|
| | 1440 | sage: G = Gamma0(1) |
|---|
| | 1441 | sage: G._list_of_elements_in_H() |
|---|
| | 1442 | [1] |
|---|
| | 1443 | """ |
|---|
| | 1444 | N = self.level() |
|---|
| | 1445 | if N != 1: |
|---|
| | 1446 | gcd = arith.gcd |
|---|
| | 1447 | return [ x for x in range(1, N) if gcd(x, N) == 1 ] |
|---|
| | 1448 | else: |
|---|
| | 1449 | return [1] |
|---|
| | 1450 | |
|---|
| | 1451 | def is_even(self): |
|---|
| | 1452 | """ |
|---|
| | 1453 | Return True precisely if this subgroup contains the matrix -1. |
|---|
| | 1454 | |
|---|
| | 1455 | Since Gamma0(N) always contains the matrix -1, this always |
|---|
| | 1456 | returns True. |
|---|
| | 1457 | |
|---|
| | 1458 | EXAMPLES: |
|---|
| | 1459 | sage: Gamma0(12).is_even() |
|---|
| | 1460 | True |
|---|
| | 1461 | sage: SL2Z.is_even() |
|---|
| | 1462 | True |
|---|
| | 1463 | """ |
|---|
| | 1464 | return True |
|---|
| | 1465 | |
|---|
| | 1466 | def is_subgroup(self, right): |
|---|
| | 1467 | """ |
|---|
| | 1468 | Return True if self is a subgroup of right. |
|---|
| | 1469 | |
|---|
| | 1470 | EXAMPLES: |
|---|
| | 1471 |
|---|