Changeset 7673:a5be33abd723


Ignore:
Timestamp:
11/08/07 08:57:43 (6 years ago)
Author:
Martin Albrecht <malb@…>
Branch:
default
Message:

EllipticCurve?(GF(2n),...).random element() works now

Location:
sage
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sage/rings/finite_field.py

    r7155 r7673  
    193193        if name is None: 
    194194            raise TypeError, "you must specify the generator name" 
    195         if order < 2**16 
     195        if order < zech_log_bound 
    196196            # DO *NOT* use for prime subfield, since that would lead to 
    197197            # a circular reference in the call to ParentWithGens in the 
     
    437437        """ 
    438438        return 1 
     439 
     440zech_log_bound = 2**16 
  • sage/schemes/elliptic_curves/ell_finite_field.py

    r7366 r7673  
    185185            sage: type(P) 
    186186            <class 'sage.schemes.elliptic_curves.ell_point.EllipticCurvePoint_finite_field'> 
     187            sage: P in E 
     188            True 
    187189 
    188190            sage: k.<a> = GF(7^5) 
     
    191193            sage: type(P) 
    192194            <class 'sage.schemes.elliptic_curves.ell_point.EllipticCurvePoint_finite_field'> 
     195            sage: P in E 
     196            True 
     197 
     198            sage: k.<a> = GF(2^5) 
     199            sage: E = EllipticCurve(k,[a^2,a,1,a+1,1]) 
     200            sage: P = E.random_element() 
     201            sage: type(P) 
     202            <class 'sage.schemes.elliptic_curves.ell_point.EllipticCurvePoint_finite_field'> 
     203            sage: P in E 
     204            True 
    193205 
    194206        """ 
     
    197209            return self(0) 
    198210        a1, a2, a3, a4, a6 = self.ainvs() 
    199         while True: 
    200             x = k.random_element() 
    201             d = 4*x**3 + (a1**2 + 4*a2)*x**2 + (2*a3*a1 + 4*a4)*x + (a3**2 + 4*a6) 
    202             try: 
    203                 m = d.sqrt(extend=False) 
    204                 y = (-(a1*x + a3) + m) / k(2) 
     211 
     212        if k.characteristic() == 2: 
     213            P = PolynomialRing(k,'y') 
     214            y = P.gen() 
     215            while True: 
     216                x = k.random_element() 
     217                f = y**2 + a1*x*y + a3*y - x**3 + a2*x**2 + a4*x + a6 
     218                roots = f.roots() 
     219                if roots == []: 
     220                    continue 
     221                if random.random() < 0.5: 
     222                    y = roots[0][0] 
     223                else: 
     224                    y = roots[1][0] 
    205225                return self([x,y]) 
    206             except ValueError: 
    207                 pass 
     226        else: 
     227            while True: 
     228                x = k.random_element() 
     229                d = 4*x**3 + (a1**2 + 4*a2)*x**2 + (2*a3*a1 + 4*a4)*x + (a3**2 + 4*a6) 
     230                try: 
     231                    m = d.sqrt(extend=False) 
     232                    y = (-(a1*x + a3) + m) / k(2) 
     233                    return self([x,y]) 
     234                except ValueError: 
     235                    pass 
    208236 
    209237    def trace_of_frobenius(self): 
  • sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py

    r7000 r7673  
    179179            122 
    180180        """ 
     181        from sage.rings.finite_field import zech_log_bound 
    181182        try: 
    182183            return self.__points 
     
    186187            self.__points = self._points_cache_sqrt() 
    187188        else: 
    188             self.__points = self._points_fast_sqrt() 
     189            if self.base_ring().order() < zech_log_bound: 
     190                self.__points = self._points_fast_sqrt() # this is fast using Zech logarithms 
     191            else: 
     192                self.__points = self._points_cache_sqrt() 
    189193             
    190194        return self.__points 
Note: See TracChangeset for help on using the changeset viewer.