Ticket #5048: trac_5048-sl2z_coercion.patch

File trac_5048-sl2z_coercion.patch, 8.8 KB (added by davidloeffler, 11 years ago)

patch against 4.6.1.alpha3

  • sage/modular/arithgroup/arithgroup_element.py

    # HG changeset patch
    # User David Loeffler <d.loeffler.01@cantab.net>
    # Date 1291927847 0
    # Node ID 51cbc47ed610df4731009565f595c6e732a81a92
    # Parent  1cb202e8a606dc2ab85489ff9df9cb4ea78c1aa1
    #5048: fix coercion issues with elements of congruence subgroups
    
    diff -r 1cb202e8a606 -r 51cbc47ed610 sage/modular/arithgroup/arithgroup_element.py
    a b  
    2525
    2626class ArithmeticSubgroupElement(MultiplicativeGroupElement):
    2727    r"""
    28     An element of an arithmetic subgroup of `{\rm SL}_2(\ZZ)`.
     28    An element of the group `{\rm SL}_2(\ZZ)`, i.e. a 2x2 integer matrix of
     29    determinant 1.
    2930    """
    3031
    3132    def __init__(self, parent, x, check=True):
     
    3334        Create an element of an arithmetic subgroup.
    3435
    3536        INPUT:
     37
    3638        - parent - an arithmetic subgroup
    3739
    3840        - x - data defining a 2x2 matrix over ZZ
     
    4244          is an arithmetic subgroup, and that
    4345          x defines a matrix of determinant 1
    4446
     47        We tend not to create elements of arithmetic subgroups that aren't
     48        SL2Z, in order to avoid coercion issues (that is, the other arithmetic
     49        subgroups are "facade parents").
     50
    4551        EXAMPLES::
    4652
    4753            sage: G = Gamma0(27)
     
    162168            [ 3  2]
    163169            [28 19]
    164170            sage: x.parent()
    165             Congruence Subgroup Gamma0(7)
     171            Modular Group SL(2,Z)
     172
     173        We check that #5048 is fixed::
     174
     175            sage: a = Gamma0(10).1 * Gamma0(5).2; a # random
     176            sage: a.parent()
     177            Modular Group SL(2,Z)
     178
    166179        """
    167180        return self.parent()(self.__x * right.__x, check=False)
    168181
  • sage/modular/arithgroup/arithgroup_generic.py

    diff -r 1cb202e8a606 -r 51cbc47ed610 sage/modular/arithgroup/arithgroup_generic.py
    a b  
    4646    assuming that it has a working element testing routine.
    4747    """
    4848
     49    def __init__(self):
     50        r"""
     51        Standard init routine.
     52
     53        EXAMPLE::
     54
     55            sage: G = Gamma1(7)
     56            sage: G.category() # indirect doctest
     57            Category of groups
     58        """
     59        group.Group.__init__(self)
     60
    4961    def _repr_(self):
    5062        r"""
    5163        Return the string representation of self.
  • sage/modular/arithgroup/arithgroup_perm.py

    diff -r 1cb202e8a606 -r 51cbc47ed610 sage/modular/arithgroup/arithgroup_perm.py
    a b  
    185185            [1 1]
    186186            [0 1]
    187187        """
    188         g = SL2Z(g)
     188        g = SL2Z(g, check=check)
    189189        if (not check) or (self.permutation_action(g)(1) == 1):
    190             g._parent = self
    191190            return g
    192191        else:
    193192            raise TypeError, "Not in group"
  • sage/modular/arithgroup/congroup_gamma.py

    diff -r 1cb202e8a606 -r 51cbc47ed610 sage/modular/arithgroup/congroup_gamma.py
    a b  
    129129            TypeError: matrix must have diagonal entries (=1, 7) congruent to 1
    130130            modulo 5, and off-diagonal entries (=1,6) divisible by 5
    131131        """
    132         if isinstance(x, ArithmeticSubgroupElement) and x.parent() == self:
    133             return x
    134         x = ArithmeticSubgroupElement(self, x, check=check)
     132        from all import SL2Z
     133        x = SL2Z(x, check)
    135134        if not check:
    136135            return x
    137136
  • sage/modular/arithgroup/congroup_gamma0.py

    diff -r 1cb202e8a606 -r 51cbc47ed610 sage/modular/arithgroup/congroup_gamma0.py
    a b  
    446446            ...
    447447            TypeError: matrix must have lower left entry (=23) divisible by 12
    448448        """
    449         if isinstance(x, ArithmeticSubgroupElement) and x.parent() == self:
    450             return x
    451         x = ArithmeticSubgroupElement(self, x, check=check)
     449        from all import SL2Z
     450        x = SL2Z(x, check)
    452451        if not check:
    453452            return x
    454453       
  • sage/modular/arithgroup/congroup_gamma1.py

    diff -r 1cb202e8a606 -r 51cbc47ed610 sage/modular/arithgroup/congroup_gamma1.py
    a b  
    288288            ...
    289289            TypeError: matrix must have diagonal entries (=1, 7) congruent to 1 modulo 5, and lower left entry (=6) divisible by 5
    290290        """
    291         if isinstance(x, ArithmeticSubgroupElement) and x.parent() == self:
    292             return x
    293         x = ArithmeticSubgroupElement(self, x, check=check)
     291        from all import SL2Z
     292        x = SL2Z(x, check)
    294293        if not check:
    295294            return x
    296295       
     
    298297        c = x.c()
    299298        d = x.d()
    300299        N = self.level()
    301         if (a%N == 1) and (c%N == 0) and (d%N == 1):
     300        if (a%N == 1) and (c%N == 0):
    302301            return x
     302            # don't need to check d == 1 mod N as this is automatic from det
    303303        else:
    304304            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)
    305305
  • sage/modular/arithgroup/congroup_gammaH.py

    diff -r 1cb202e8a606 -r 51cbc47ed610 sage/modular/arithgroup/congroup_gammaH.py
    a b  
    850850            ...
    851851            TypeError: matrix must have lower right entry (=3) congruent modulo 10 to some element of H
    852852        """
    853         if isinstance(x, ArithmeticSubgroupElement) and x.parent() == self:
    854             return x
    855         x = ArithmeticSubgroupElement(self, x, check=check)
     853        from all import SL2Z
     854        x = SL2Z(x, check)
    856855        if not check:
    857856            return x
    858857       
  • sage/modular/arithgroup/congroup_generic.py

    diff -r 1cb202e8a606 -r 51cbc47ed610 sage/modular/arithgroup/congroup_generic.py
    a b  
    6363        if level <= 0:
    6464            raise ArithmeticError, "Congruence groups only defined for positive levels."
    6565        self.__level = level
     66        ArithmeticSubgroup.__init__(self)
    6667
    6768    def _repr_(self):
    6869        """
     
    196197        else:
    197198            raise NotImplementedError
    198199
    199     def __call__(self, x, check=True):
    200         """
    201         Coerce x into self.
    202 
    203         NOTE: This function should be overridden by any subclass the
    204         user will interact with directly.
    205 
    206         EXAMPLES::
    207 
    208             sage: sage.modular.arithgroup.congroup_generic.CongruenceSubgroup(5).__call__(0)
    209             Traceback (most recent call last):
    210             ...
    211             NotImplementedError
    212         """
    213         if isinstance(x, ArithmeticSubgroupElement) and x.parent() == self:
    214             return x
    215         raise NotImplementedError
    216 
    217200
    218201    def sturm_bound(self, weight=2):
    219202        r"""
  • sage/modular/arithgroup/congroup_sl2z.py

    diff -r 1cb202e8a606 -r 51cbc47ed610 sage/modular/arithgroup/congroup_sl2z.py
    a b  
    2020################################################################################
    2121
    2222from congroup_gamma0 import Gamma0_class
     23from arithgroup_element import ArithmeticSubgroupElement
    2324from sage.rings.integer_ring import ZZ
    2425from sage.modular.cusps import Cusp
    2526from sage.rings.arith import gcd
     
    9293        """
    9394        return _SL2Z_ref, ()
    9495
     96    def __call__(self, x, check=True):
     97        r"""
     98        Create an element of self from x. If check=True (the default), check
     99        that x really defines a 2x2 integer matrix of det 1.
     100        """
     101        return ArithmeticSubgroupElement(self, x, check=check)
     102
    95103    def _repr_(self):
    96104        """
    97105        Return the string representation of self.
  • sage/modular/modform/constructor.py

    diff -r 1cb202e8a606 -r 51cbc47ed610 sage/modular/modform/constructor.py
    a b  
    8484        (5, Congruence Subgroup Gamma0(5), 7, Integer Ring)
    8585        sage: type(v[0]), type(v[1]), type(v[2]), type(v[3])
    8686        (<type 'sage.rings.integer.Integer'>,
    87          <class 'sage.modular.arithgroup.congroup_gamma0.Gamma0_class'>,
     87         <class 'sage.modular.arithgroup.congroup_gamma0.Gamma0_class_with_category'>,
    8888         <type 'sage.rings.integer.Integer'>,
    8989         <type 'sage.rings.integer_ring.IntegerRing_class'>)
    9090        sage: canonical_parameters( 5, 7, 7, ZZ )