Ticket #10951: trac_10951.patch

File trac_10951.patch, 2.7 KB (added by zimmerma, 11 years ago)
  • sage/libs/libecm.pyx

    # HG changeset patch
    # User Paul Zimmermann <zimmerma@loria.fr>
    # Date 1306092209 -7200
    # Node ID 6c8fd09f277917182759e682a17b9357d68c9d95
    # Parent  361a4ad7d52c69b64ae2e658ffd0820af0d87e93
    #10951: added optional input of sigma, and return lucky sigma
    
    diff -r 361a4ad7d52c -r 6c8fd09f2779 sage/libs/libecm.pyx
    a b  
    88
    99AUTHOR:
    1010    Robert L Miller (2008-01-21) -- library interface (clone of ecmfactor.c)
     11    Paul Zimmermann (2011-05-22) -- added input/output of sigma
    1112
    1213EXAMPLE:
    1314
    1415    sage: import sage.libs.libecm
    1516    sage: from sage.libs.libecm import ecmfactor
    1617    sage: result = ecmfactor(999, 0.00)
    17     sage: result in [(True, 27), (True, 37), (True, 999)]
     18    sage: result[0] == True and result[1] in [27, 37, 999]
    1819    True
    1920    sage: result = ecmfactor(999, 0.00, verbose=True)
    2021    Performing one curve with B1=0
    2122    Found factor in step 1: ...
    22     sage: result in [(True, 27), (True, 37), (True, 999)]
     23    sage: result[0] == True and result[1] in [27, 37, 999]
    2324    True
     25    sage: ecmfactor(2^128+1,1000,sigma=227140902)
     26    (True, 5704689200685129054721, 227140902)
    2427
    2528"""
    2629
     
    3033
    3134cdef extern from "ecm.h":
    3235    ctypedef struct __ecm_param_struct:
    33         pass
     36        int method
     37        mpz_t x
     38        mpz_t sigma
    3439    ctypedef __ecm_param_struct ecm_params[1]
    3540    int ecm_factor (mpz_t, mpz_t, double, ecm_params)
     41    void ecm_init (ecm_params)
     42    void ecm_clear (ecm_params)
    3643    int ECM_NO_FACTOR_FOUND
    3744
    38 def ecmfactor(number, py_B1, verbose=False):
     45def ecmfactor(number, py_B1, verbose=False, sigma=0):
    3946    cdef mpz_t n, f
    4047    cdef int res
    4148    cdef double B1
    42     cdef Integer sage_int_f, sage_int_number
     49    cdef Integer sage_int_f, sage_int_number, sage_int_sigma
     50    cdef ecm_params q
    4351   
    4452    sage_int_f = Integer(0)
    4553    sage_int_number = Integer(number)
     54    sage_int_sigma = Integer(sigma)
    4655    B1 = py_B1
    4756
    4857    mpz_init(n)
    4958    mpz_set(n, sage_int_number.value)
    5059    mpz_init(f) # For potential factor
     60    ecm_init(q)
     61    mpz_set(q.sigma,sage_int_sigma.value)
    5162
    5263    if verbose:
    5364        print "Performing one curve with B1=%1.0f"%B1
    5465
    55     res = ecm_factor(f, n, B1, NULL)
     66    res = ecm_factor(f, n, B1, q)
    5667
    5768    if res > 0:
    5869        mpz_set(sage_int_f.value, f)
     70        mpz_set(sage_int_sigma.value, q.sigma)
    5971
    6072    mpz_clear(f)
    6173    mpz_clear(n)
     74    ecm_clear(q)
    6275
    6376    if res > 0:
    6477        if verbose:
    6578            print "Found factor in step %d: %d"%(res,sage_int_f)
    66         return (True, sage_int_f)
     79        return (True, sage_int_f, sage_int_sigma)
    6780    elif res == ECM_NO_FACTOR_FOUND:
    6881        if verbose:
    6982            print "Found no factor."