Public Member Functions | |
def | debug |
def | __init__ |
def | type |
def | search |
def | a200 |
def | a500 |
def | a600 |
def | a700 |
def | a701 |
def | a800 |
def | testConflict |
def | is_repeated_state |
def | update_states_seen |
def | save |
Public Attributes | |
state_seen |
Definition at line 56 of file MPNG.py.
def MPNG::MPNG::__init__ | ( | self, | ||
alb, | ||||
filename = None | ||||
) |
Definition at line 64 of file MPNG.py.
00064 : 00065 self._owner = alb 00066 self._mp_cnt = 0 00067 self._trace_cycle = 0 00068 self._n_cur = None 00069 self._n_rdr = None 00070 00071 global isr 00072 if isr: 00073 self.state_seen = set( ) 00074 self._reduce_max = 1000 00075 00076 if filename != None: 00077 self.load( filename ) 00078 def type( self ):
def MPNG::MPNG::a200 | ( | self | ) |
Definition at line 149 of file MPNG.py.
00149 : 00150 00151 if globals.printState: 00152 print self._indent, "MPNG.a200..." 00153 00154 # A23400 00155 00156 # A200 - Reduce Num and Den lists 00157 00158 ndm = self._o_ndm.copy() 00159 ndm.reduce( ) 00160 00161 ( ndm, updated_max ) = ndm.quick_reduce( self._reduce_max ) 00162 00163 if self._reduce_max < updated_max: 00164 # numerator duplicates value in denominator 00165 # raise reduction threshold & restart the cycle 00166 self._reduce_max = updated_max 00167 return MPNG.a200 00168 00169 # self._o_ndm = ndm.copy( ) 00170 prv = self._o_ndm.copy( ) 00171 00172 if globals.testDebug: 00173 print self._indent, "MPNG.a200: lvl: %s" % self._level 00174 print "%s" % self._o_ndm.mul( ) 00175 00176 self._o_ndm.verifyUnusedExponentSum( ) 00177 00178 num = self._o_ndm.num( ) 00179 last = num.last( ) 00180 if not last: 00181 # 07/15/07 - nothing to do 00182 pydb.debugger( ) 00183 print "lvl %d, last %s" % ( self._level + 1, last ) 00184 print "prv %s" % prv 00185 print "ndm %s" % self._o_ndm 00186 00187 self._o_ndm.rdr( last ) 00188 self._n_rdr = last 00189 00190 # "A300:" 00191 # "Increment level and check for multi-perfect." 00192 # "If one found, save it." 00193 00194 self._o_fs.append( self._o_ndm ) 00195 00196 self._n_cur = self._o_ndm.cur( ) 00197 stage = MPNG_STAGE( self._o_ndm, self._n_cur, self._n_rdr ) 00198 self._n_fs.append( stage ) 00199 00200 self._level += 1 00201 self._indent = " " * self._level 00202 00203 if len( self._o_ndm.den( ) ) == 0 and not self._o_ndm.isInteger( ): 00204 print "zero %s" % self._o_ndm 00205 self.debug( ) 00206 00207 if self._o_ndm.isInteger( ): 00208 00209 if self._owner: 00210 self._owner.saveMultiperfect( self._o_ndm ) 00211 else: 00212 print "%s -> %s -> %s" % ( self._seed, self._o_ndm.order( ), self._o_ndm.mul( ) ) 00213 00214 # "A400:" 00215 # "Scan Num and Mul for primes in Num, but not in Mul," 00216 # "adding up their exponents." 00217 00218 sum = self._o_ndm.sum( ) 00219 # assert_sum( self._o_ndm, self._n_ndm ) 00220 00221 # "A401" 00222 00223 if sum == 0: 00224 return MPNG.a800 00225 else: 00226 return MPNG.a500 # NEXT 00227 def a500( self ):
def MPNG::MPNG::a500 | ( | self | ) |
Definition at line 228 of file MPNG.py.
00228 : 00229 00230 if globals.printState: 00231 print self._indent, "MPNG.a500..." 00232 00233 # "Find avail prime (in Num and not in Mul)" 00234 # "to 701 if cur already used (flag set)" 00235 # "to 700 if cur already used (in Mul)" 00236 # "to 600 if one found" 00237 00238 rdr = self._o_ndm.rdr( ) 00239 if rdr.used( ): 00240 if globals.printState and globals.quiet < 2: 00241 print self._indent, "MPNG.a500 -> a701 -- 1 -- %s" % rdr.prime( ) 00242 return MPNG.a701 # NEXT 00243 self._o_ndm.cur( rdr ) 00244 self._n_cur = rdr 00245 00246 if not self._o_ndm.mul( ).detectPrime( rdr.prime( )): 00247 return MPNG.a600 # NEXT 00248 else: 00249 rdr.used( True ) 00250 if globals.printState and globals.quiet < 2: 00251 print self._indent, "MPNG.a500 -> a701 -- 3 -- %s" % rdr.asUString( ) 00252 return MPNG.a701 # NEXT 00253 def a600( self ):
def MPNG::MPNG::a600 | ( | self | ) |
Add new factor to Num, Den, and Mul lists.
Definition at line 254 of file MPNG.py.
00254 : 00255 """ 00256 Add new factor to Num, Den, and Mul lists. 00257 """ 00258 00259 cur = self._o_ndm.cur( ) 00260 00261 if cur.power( ) < 0: 00262 pydb.debugger( ) 00263 00264 self._o_ndm = self._o_ndm * cur 00265 00266 if globals.ndm_flag and globals.qvs_flag > 1: 00267 print " %s" % cur 00268 00269 if globals.printState: 00270 print self._indent, "MPNG.a600: %s -> %s" % ( cur, self._o_ndm.mul( ).asUString( ) ) 00271 00272 return MPNG.a200 00273 def a700( self ):
def MPNG::MPNG::a700 | ( | self | ) |
Definition at line 274 of file MPNG.py.
00274 : 00275 00276 if globals.printState: 00277 print self._indent, "MPNG.a700..." 00278 00279 rdr = self._o_ndm.rdr( ) 00280 if rdr.decrementPower( ): 00281 # process lesser power 00282 # if globals.printState: 00283 # print self._indent, "MPNG.a700 -> a600 -- r: %s" % rdr.asUString( ) 00284 return MPNG.a600 # NEXT 00285 else: 00286 # mark as used 00287 rdr.used( True ) 00288 # if globals.printState: 00289 # print self._indent, "MPNG.a700 -> a701 -- r: %s" % rdr.asUString( ) 00290 return MPNG.a701 # NEXT 00291 def a701( self ):
def MPNG::MPNG::a701 | ( | self | ) |
Definition at line 292 of file MPNG.py.
00292 : 00293 00294 if globals.printState: 00295 print self._indent, "MPNG.a701..." 00296 00297 lst = self._o_ndm.selectNumLessThanReader_old( ) 00298 if len( lst ) != 0: 00299 rdr = self._o_ndm.rdr( lst.last( ) ) 00300 self._n_rdr = lst.last( ) 00301 00302 if self._n_rdr >= self._o_ndm.num( ).first( ): 00303 # if globals.printState: 00304 # print self._indent, "MPNG.a701 -> a500 -- r: %s" % rdr.asUString( ) 00305 return MPNG.a500 00306 00307 # if globals.printState: 00308 # print self._indent, "MPNG.a701 -> a800..." 00309 00310 return MPNG.a800 00311 def a800( self ):
def MPNG::MPNG::a800 | ( | self | ) |
Back-up level and check for more to do (cur_s != 0). If so, decrement cur_q and cur_s.
Definition at line 312 of file MPNG.py.
00312 : 00313 """ 00314 Back-up level and check for more to do (cur_s != 0). 00315 If so, decrement cur_q and cur_s. 00316 """ 00317 00318 if globals.printState: 00319 print self._indent, "MPNG.a800..." 00320 00321 if self._level == 0: 00322 return None 00323 00324 result_state = None 00325 00326 while result_state == None: 00327 00328 done = self._level == 0 00329 self._indent = "" 00330 00331 while not done: 00332 00333 # remember ndm for is_repeated_state 00334 self.update_states_seen( ) 00335 00336 # decrement level 00337 self._level -= 1 00338 self._indent = " " * self._level 00339 00340 if self._level == 0: 00341 return None # FINI 00342 00343 # pop stack 00344 self._o_fs.pop( ) 00345 self._o_ndm = self._o_fs[ self._level - 1 ] 00346 00347 # pop stack 00348 self._n_fs.pop( ) 00349 stage = self._n_fs[ self._level - 1 ] 00350 ( self._n_ndm, self._n_cur, self._n_rdr ) = stage.value ( ) 00351 # assert_ndm( self._n_ndm, self._o_ndm ) 00352 # assert_cur( self._n_cur, self._o_cur ) 00353 # assert_rdr( self._n_rdr, self._o_ndm.rdr( ) ) 00354 00355 sum = self._o_ndm.sum( ) 00356 # assert_sum( self._o_ndm, self._n_ndm ) 00357 00358 # 071707 00359 # done = sum != 0 00360 # 0 indicates all done 00361 # 1 indicates only value has been tried 00362 done = sum > 1 00363 00364 q = self._o_ndm.power( ) 00365 if q == 1: 00366 continue 00367 00368 # ndm::decrementPower has supportive logic 00369 self._o_ndm.decrementPower( ) 00370 00371 if self._o_ndm.power( ) != 0: 00372 # if globals.printState: 00373 # print self._indent, "MPNG.a800 -> MPNG.a600" 00374 if globals.testDebug: self.debug( ) 00375 result_state = MPNG.a600 00376 00377 if self._o_ndm.sum( ) != 0: 00378 # if globals.printState: 00379 # print self._indent, "MPNG.a800 -> MPNG.a700" 00380 if globals.testDebug: self.debug( ) 00381 result_state = MPNG.a700 00382 00383 return result_state 00384 def testConflict( self ):
def MPNG::MPNG::debug | ( | self | ) |
def MPNG::MPNG::is_repeated_state | ( | self, | ||
beg_cnt, | ||||
net_cnt | ||||
) |
Definition at line 394 of file MPNG.py.
00394 : 00395 00396 rpt = False 00397 00398 if globals.ndm_flag: 00399 key = self._o_ndm.asString( ) # 03/16 13:45 00400 if key in self.state_seen: 00401 msg = "d" 00402 rpt = True 00403 else: 00404 msg = "n" 00405 00406 if globals.qvs_flag > 1: 00407 print "%5s %s" % ( msg, key ) 00408 00409 if globals.testDebug and globals.quiet < 2: 00410 print "MPNG.next: b %d, t %d" % ( beg_cnt, net_cnt ), 00411 print "%s" % self._o_ndm.mul( ) 00412 self.debug( ) 00413 00414 if globals.printCycle or globals.testDebug: 00415 00416 if globals.printState: 00417 print self._o_ndm.asUString( ) 00418 if self._o_ndm.cur( ).power( ) < 0: 00419 print " power: %d" % self._o_ndm.cur( ).power( ) 00420 00421 return rpt 00422 def update_states_seen( self ):
def MPNG::MPNG::save | ( | self, | ||
filename | ||||
) |
def MPNG::MPNG::search | ( | self, | ||
max, | ||||
seed, | ||||
ndm = None | ||||
) |
Definition at line 83 of file MPNG.py.
00083 : 00084 00085 global isr, t600 00086 00087 self._o_fs = [ ] # list 00088 self._n_fs = [ ] # list 00089 self._level = 0 00090 self._indent = "" 00091 00092 beg_cnt = 0 00093 net_cnt = 0 00094 ndm_dup = 0 00095 ndm_con = 0 00096 00097 state = MPNG.a200 00098 00099 if ndm == None: 00100 ndm = NumDenMul.new( seed ) 00101 00102 self._o_ndm = ndm.copy( ) 00103 self._n_ndm = ndm.copy( ) 00104 self._seed = seed 00105 00106 while state != None and net_cnt < 100000: 00107 net_cnt += 1 00108 00109 if self._trace_cycle != 0 and self._trace_cycle == net_cnt: 00110 self.debug( ) 00111 00112 if state == MPNG.a200: 00113 beg_cnt += 1 00114 00115 if self.testConflict( ): 00116 ndm_con += 1 00117 if globals.quiet < 2: 00118 print "MPNG::conflict -- A200 --> A800" 00119 state = MPNG.a800 00120 00121 if isr: 00122 rpt = self.is_repeated_state( beg_cnt, net_cnt ) 00123 if rpt: 00124 ndm_dup += 1 00125 state = MPNG.a800 # dup, skip lower levels # 03/16 10:30 00126 if globals.quiet < 2: 00127 print "MPNG::ndm_dup -- A200 --> A800" 00128 state = MPNG.a800 00129 00130 if t600: 00131 cur = self._o_ndm.cur( ) 00132 if rpt: 00133 print "%2d %s %6s r %s" % ( self._level, "" * self._level, cur, self._o_ndm.mul( ) ) 00134 else: 00135 print "%2d %s %6s %s" % ( self._level, "" * self._level, cur, self._o_ndm.num( ) ) 00136 print "%2s %s %6s %s" % ( "" , "" * self._level, "" , self._o_ndm.den( ) ) 00137 print "%2s %s %6s %s" % ( "" , "" * self._level, "" , self._o_ndm.mul( ) ) 00138 00139 if max != 0 and beg_cnt >= max: 00140 break 00141 00142 state = state( self ) 00143 00144 if globals.printState: 00145 sys.stdout.flush() 00146 00147 return ( beg_cnt, net_cnt, ndm_dup, ndm_con ) 00148 def a200( self ):
def MPNG::MPNG::testConflict | ( | self | ) |
def MPNG::MPNG::type | ( | self | ) |
def MPNG::MPNG::update_states_seen | ( | self | ) |