Factors Namespace Reference


Classes

class  Factors

Functions

def new
def restart
def gcd
def rho_gcd
def egypt_gcd
def rho_status_display
def FromNumber
def FromString
def main

Variables

int verbose = 0
int one_min = 60
int one_hour = 3600
tuple one_meg = mpz( 1000000 )
tuple one_gig = mpz( 1000000000 )
tuple ten_gig = one_gig*mpz( 10 )
tuple hun_gig = one_gig*mpz( 100 )
tuple ten_pow_15 = mpz( 10 ** 15 )
tuple ten_pow_21 = mpz( 10 ** 21 )
string state_file = "Factor_Status.txt"
tuple y = mpz( 5 )
int r = 1
int q = 1
int g = 1
 x = y
int k = 0
 ys = y

Function Documentation

def Factors::egypt_gcd (   self,
  a,
  b 
)

Euclid's algorithm for integer greatest common divisors.

Definition at line 1023 of file Factors.py.

01023                               :
01024         """
01025         Euclid's algorithm for integer greatest common divisors.
01026         """
01027 
01028         while b:
01029             a, b = b, a % b
01030         return a
01031 
    def rho_status_display( self, val, numsteps, start, dis, intrvl ):

def Factors::FromNumber (   aNumber  ) 

Definition at line 1057 of file Factors.py.

01057                          :
01058 
01059     p = mpz( aNumber.prime( ) )
01060     q = mpz( aNumber.power( ) )
01061     n = Number.Number( p, q )
01062     
01063     result = Factors( None )
01064     result.add( n )
01065     return result
01066 
def FromString( aString ):

def Factors::FromString (   aString  ) 

Definition at line 1067 of file Factors.py.

01067                          :
01068 
01069     result = Factors( None )
01070     tokens = re.split( "[ ()]+", aString )
01071 
01072     for token in tokens:
01073         if len( token ) < 3:
01074             continue
01075         if token.find( "^" ) < 0:
01076             n = mpz( token )
01077             result = Factors( n )
01078         else:
01079             ( p, q ) = re.split( "[\^]", token )
01080             p = mpz( p )
01081             q = mpz( q )
01082             n = Number.Number( p, q )
01083             result.add( n )
01084 
01085     return result
01086 
def main( ):

def Factors::gcd (   self,
  a,
  b 
)

Definition at line 1010 of file Factors.py.

01010                          :
01011         return self.egypt_gcd( a, b )
01012 
    def rho_gcd( self, a, b ):

def Factors::main (  ) 

Definition at line 1087 of file Factors.py.

01087            :
01088 
01089     globals.quiet = 1
01090     globals.verbose = 0
01091 
01092     for arg in sys.argv[1:]:
01093 
01094         if arg[ 0 ].isdigit( ):
01095             f = FromString( arg )
01096             print "%s %s" % ( arg, f )
01097 
01098         if arg[ 0 ].isalpha( ):
01099             if arg == 'f':
01100                 state_file = arg[ 1: ]
01101                 restart( )
01102                 continue
01103 
01104             if arg == 'l':
01105                 globals.PROG.load( )
01106                 continue
01107 
01108             if arg == 's':
01109                 globals.PROG.save( )
01110                 continue
01111 
01112 # ./Factors.py l py=2607480390484525739   py=312145323578466047987495401
01113 # ./Factors.py l gmpy=2607480390484525739 gmpy=312145323578466047987495401
01114 
01115             f = None
01116             factors = None
01117             tokens = re.split( "[:=]", arg )
01118             r = None
01119             b = time.time( )
01120             if len( tokens ) < 0:
01121                 f = Factors( arg )
01122                 factors = f.factors( )
01123             elif tokens[ 0 ] == 'q':
01124                 globals.quiet += 1
01125             elif tokens[ 0 ] == 'sm':
01126                 f.sgmftr_with_max( 12 )
01127             elif tokens[ 0 ] == 'gcd':
01128                 f = Factors( None )
01129                 print f.rho_gcd(   mpz( tokens[ 1 ] ), mpz( tokens[ 2 ] ) ),
01130                 print f.egypt_gcd( mpz( tokens[ 1 ] ), mpz( tokens[ 2 ] ) )
01131             elif tokens[ 0 ] == 'er':
01132                 f = Factors( None )
01133                 v = mpz( tokens[ 1 ] )
01134                 r = f.egypt_rho( v )
01135             elif tokens[ 0 ] == 'ef':
01136                 if globals.quiet <= 1:
01137                     print tokens[1]
01138                 f = Factors( None )
01139                 v = mpz( tokens[ 1 ] )
01140                 r = f.egypt_factors( v )
01141 
01142             elif tokens[ 0 ] == 'r':
01143                 values = [ 12970571, 13209011, 17728931, 23845791,
01144                            12970571 * 13209011, 17728931 * 23845791,
01145                            12970571 * 13209011 * 17728931 * 23845791 ]
01146                 v1, v2, v3, v4 = 12970573, 13209011, 17728931,  23845791
01147                 v1, v2, v3, v4 = 131946889, 319020217, 412239473, 420778751
01148                 values = [ # v1, v2, v3, v4,
01149                            # v1 * v2, v3 * v4,
01150                            v1 * v2 * v3 * v4,
01151                            v1 * v2 * v3 * v4 * 1000 + 1 ]
01152 #                values = [ v1, v2, v3, v4 ]
01153                 for v in values:
01154                     f = Factors( None )
01155                     b = time.time( )
01156                     r = f.egypt_factors( mpz( v ) )
01157                     f = time.time( )
01158                     print "n %s, r %s, t %5.2f" % ( v, r, f - b )
01159             else:
01160                 f = Factors( None )
01161                 ( m, v ) = tokens
01162                 v = mpz( v )
01163                 if m == 'py' or m == 'python':
01164                     r = f.pollard_rho_factors_python( v )
01165                 if m == 'rho' or m == 'gmpy':
01166                     r = f.pollard_rho_factors_gmpy( v )
01167                 if m == 'br' or m == 'pollard_brent':
01168                     r = f.pollard_brent_factors( v )
01169 
01170             if r:
01171                 f.print_factors( v, r, time.time() - b )
01172 
if __name__ == '__main__':

def Factors::new (   s  ) 

Definition at line 41 of file Factors.py.

00041             :
00042 
00043     f = Factors( s )
00044     return f
00045 
def restart( ):

def Factors::restart (  ) 

Definition at line 46 of file Factors.py.

00046               :
00047 
00048     # read Factors_Status.txt and continue factoring (if needed)
00049     try:
00050         f = Factors( )
00051         ( val, pri ) = f.load_state( )
00052         val = mpz( val )
00053         pri = mpz( pri )
00054         fc = globals.FactorCache
00055         factors = fc.at( val )
00056         if factors == None:
00057             f.batchPrimeFactor( val, pri )
00058         else:
00059             pydb.debugger()
00060     except:
00061 #       print "Error reading %s" % state_file
00062         pass
00063 
class Factors:

def Factors::rho_gcd (   self,
  a,
  b 
)

gcd( a,b ) returns the greatest common divisor of the integers a and b.

Definition at line 1013 of file Factors.py.

01013                              :
01014 
01015         """
01016         gcd( a,b ) returns the greatest common divisor of the integers a and b.
01017         """
01018 
01019         if a == 0:
01020             return b
01021         return abs( self.gcd( b % a, a ) )
01022 
    def egypt_gcd( self, a, b):

def Factors::rho_status_display (   self,
  val,
  numsteps,
  start,
  dis,
  intrvl 
)

Definition at line 1032 of file Factors.py.

01032                                                                      :
01033 
01034         tim = TimeStamp.TimeStamp( )
01035         tim = "%s" % tim
01036 
01037         if dis == intrvl:
01038             print "%s %d %8.3e  %d %8.3e" % ( tim, long( val ), val, long( numsteps ), numsteps )
01039             tim = " " * len( tim )
01040 
01041         if dis < one_gig:
01042             str = "%8.2f Mb" % ( dis * 1.0 / one_meg )
01043         else:
01044             str = "%8.2f Gb" % ( dis * 1.0 / one_gig )
01045 
01046         print "%s %s %s %9.4f%%" % ( tim, start, str, dis * 100.0 / numsteps )
01047         sys.stdout.flush( )
01048 
01049         max_interval = 100 * 1000 * 1000
01050         if intrvl <= max_interval:
01051             dis += intrvl
01052         else:
01053             dis += max_interval
01054 
01055         return dis
01056 
def FromNumber( aNumber ):


Variable Documentation

tuple Factors::g = 1

Definition at line 962 of file Factors.py.

tuple Factors::hun_gig = one_gig*mpz( 100 )

Definition at line 36 of file Factors.py.

Definition at line 971 of file Factors.py.

tuple Factors::one_gig = mpz( 1000000000 )

Definition at line 34 of file Factors.py.

int Factors::one_hour = 3600

Definition at line 31 of file Factors.py.

tuple Factors::one_meg = mpz( 1000000 )

Definition at line 33 of file Factors.py.

int Factors::one_min = 60

Definition at line 30 of file Factors.py.

tuple Factors::q = 1

Definition at line 959 of file Factors.py.

int Factors::r = 1

Definition at line 958 of file Factors.py.

string Factors::state_file = "Factor_Status.txt"

Definition at line 39 of file Factors.py.

tuple Factors::ten_gig = one_gig*mpz( 10 )

Definition at line 35 of file Factors.py.

tuple Factors::ten_pow_15 = mpz( 10 ** 15 )

Definition at line 37 of file Factors.py.

tuple Factors::ten_pow_21 = mpz( 10 ** 21 )

Definition at line 38 of file Factors.py.

Definition at line 29 of file Factors.py.

Definition at line 965 of file Factors.py.

tuple Factors::y = mpz( 5 )

Definition at line 957 of file Factors.py.

tuple Factors::ys = y

Definition at line 976 of file Factors.py.


Generated on Sun Mar 22 09:59:14 2009 for Multiperfect Number Generator by  doxygen 1.5.8