SCRIPT #---------------------------------------------------------------------------------------- # This script is used to start new bases. It is a version brought together from many # other's efforts. More recent versions automatically calculate and create files that # account for all k's. A file will only be written if there are k's applicable to the # file except for the primes file, which is written even when empty. # # Version 1.0 - Original script Written by Micha (Michaf) and Karsten (Kar_bon). # version 2.0 - Changes by Willem (Siemelink) to manually calculate k's that are MOB # that do not need to be tested and k's eliminated by trivial factors. # Version 3.0 - Changes by Ian (MyDogBuster) to write out new files for k's eliminated # by trivial factors, k's eliminated due to MOB, and remaining k's. # Version 4.0 - Changes by Gary (gd_barnes) to allow the flexibility of testing both # Riesel and Sierp tests, automatically calculate k's with a trivial # factor or that are a GFN, add a GFN file, and strip out manual code # related to the starting k in the base. # Version 4.1 - Changes by Gary to correct the GFN calculation from a power of the # (PFGW 3.2.3 base to a power of a root of the base. # and prior) Changes by Mark (Rogue) incorported by Gary to display and/or write # out tests in k*b^n+/-1 instead of decimal format in the GUI or at # the command prompt and in the pfgw.log and pfgw-prime.log files. # Version only works with PFGW versions 3.2.3 and prior. # version 4.2 - Changes by Gary to prove PRPs with the use of the PRIMEM and PRIMEP # (PFGW 3.2.7 commands, to not write out empty files, and to add a new composite PRP # and later) file. This incorporates scripting language changes beginning with PFGW # version 3.2.7. # version 4.3 - Changes by Gary to correct proof of PRPs. In some cases primarily when # trial factoring is set to < 100%, PRIMEM and PRIMEP would still come # back with PRP (not composite). Now if they subsequently come back as # PRP, 100% of normal factorization is attempted and if still no proof, a # combined test using PRIMEC is attempted. If composite, as before, it # will be written to the composite PRP file. If still PRP, it is assumed # prime and written to a new PRP file as well as the primes file. # version 5.0 - Changes by Gary to allow the exclusion of squared k's on Riesel bases # where algebraic factors make a full covering set. # version 5.1 - Changes by Gary to correct multiple of the base primality checks # on large k-values. # # The maximum base that the script can handle is 2*3*5*7*11*13*17=510510. Higher bases # would need changes to allow for more modulos for k's with trivial factors. # The maximum k-value that the script can handle is 10^16. Larger k-values would need # changes to do additional factorization on multiple of the base primality checks. #---------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------- # The following 11 lines control what is tested and are the only lines that should be # changed. Type is 1 for Sierp and -1 for Riesel. Alg_mod1 & alg_mod2 are the modulos # for k's that contain partial algebraic factors to make a full covering set on Riesel # bases. The alg_remxx vars. are the remainder in said modulos. # # Example for k's that are eliminated where k=m^2 and m==(2 or 3 mod 5): # alg_mod1 = 5, alg_rem1a = 2, and alg_rem1b = 3. # # To prevent the elimination of algebraic factors when none are present, set alg_mod1 # to 9999. For Riesel squared bases, set alg_mod1 to 1 and alg_rem1a to 0 to prevent # all squared k's from being searched. # # Only Riesel bases will be checked for algebraic factors. #---------------------------------------------------------------------------------------- DIM base, 2 DIM type, -1 DIM min_k, 1 DIM max_k, 509202 DIM max_n, 2500 DIM alg_mod1, 9999 DIM alg_rem1a, 9999 DIM alg_rem1b, 9999 DIM alg_mod2, 9999 DIM alg_rem2a, 9999 DIM alg_rem2b, 9999 #---------------------------------------------------------------------------------------- # Variables ending in _wrt are write switches. # They are needed to prevent empty files from being written. #---------------------------------------------------------------------------------------- DIM a_wrt, 0 DIM c_wrt, 0 DIM g_wrt, 0 DIM m_wrt, 0 DIM p_wrt, 0 DIM r_wrt, 0 DIM t_wrt, 0 DIM k, min_k - 1 DIM gfn_k, 1 DIM n DIM base_root, base DIM root, 1 DIM root_mult DIM max_root DIM k_div, 1 DIM k_mult DIM cofact, base - 1 DIM fact, cofact DIM prev_fact, 1 DIM fact_cnt, 0 DIM facta, -1 DIM factb, -1 DIM factc, -1 DIM factd, -1 DIM facte, -1 DIM factf, -1 DIMS tmpstr DIMS type_str DIMS test_str OPENFILEAPP p_file,pl_prime.txt IF (type == 1) THEN SETS type_str,+ ELSE SETS type_str,- #----------------------------------------------------------------------------------------- # Calculate unique prime factors for base - 1. These will be used as modulos # to determine k's that contain trivial factors and can be eliminated. #----------------------------------------------------------------------------------------- LABEL fact_base_1 FACTORIZE cofact IF (FACTORFOUND > 1) THEN SET fact, FACTORFOUND ELSE SET fact, cofact IF (fact == prev_fact) THEN GOTO factdup_base_1 SET fact_cnt, fact_cnt + 1 IF (fact_cnt == 1) THEN SET facta, fact IF (fact_cnt == 2) THEN SET factb, fact IF (fact_cnt == 3) THEN SET factc, fact IF (fact_cnt == 4) THEN SET factd, fact IF (fact_cnt == 5) THEN SET facte, fact IF (fact_cnt == 6) THEN SET factf, fact LABEL factdup_base_1 IF (FACTORFOUND == 1) THEN GOTO find_root SET cofact, cofact / fact SET prev_fact, fact GOTO fact_base_1 #----------------------------------------------------------------------------------------- # Determine smallest root of base for use in excluding # Generallized Fermat k's from even Sierp bases. #----------------------------------------------------------------------------------------- LABEL find_root IF (type == -1) THEN GOTO next_k IF (base % 2 == 1) THEN GOTO next_k LABEL root_loop SET root, root + 1 SET root_mult, 1 SET max_root, base / root IF root > max_root THEN GOTO next_k LABEL root_cont SET root_mult, root_mult * root IF (root_mult > base) THEN GOTO root_loop IF (root_mult < base) THEN GOTO root_cont SET base_root, root #----------------------------------------------------------------------------------------- # Major looping process on k-value. #----------------------------------------------------------------------------------------- LABEL next_k SET k, k + 1 IF (k > max_k) THEN GOTO END #----------------------------------------------------------------------------------------- # Check to see if the k contains trivial factors. If so, the k is bypassed. # Odd k's are not written for odd bases. #----------------------------------------------------------------------------------------- LABEL calc_trivial IF (facta != 2) THEN GOTO calc_trivial_s IF (k % 2 == 1) THEN GOTO next_k LABEL calc_trivial_s IF (type == -1) THEN GOTO calc_trivial_r IF (k % facta == facta - 1) THEN GOTO trivial_fact IF (k % factb == factb - 1) THEN GOTO trivial_fact IF (k % factc == factc - 1) THEN GOTO trivial_fact IF (k % factd == factd - 1) THEN GOTO trivial_fact IF (k % facte == facte - 1) THEN GOTO trivial_fact IF (k % factf == factf - 1) THEN GOTO trivial_fact GOTO calc_gfn LABEL calc_trivial_r IF (k % facta == 1) THEN GOTO trivial_fact IF (k % factb == 1) THEN GOTO trivial_fact IF (k % factc == 1) THEN GOTO trivial_fact IF (k % factd == 1) THEN GOTO trivial_fact IF (k % facte == 1) THEN GOTO trivial_fact IF (k % factf == 1) THEN GOTO trivial_fact #----------------------------------------------------------------------------------------- # Exclude squared k's on Riesel bases where algebraic factors make a full covering set. #----------------------------------------------------------------------------------------- IF (alg_mod1 == 9999) THEN GOTO calc_mob SET k_div, k_div - 1 LABEL squarek_loop SET k_div, k_div + 1 SET k_mult, k_div ^ 2 IF (k_mult < k) THEN GOTO squarek_loop IF (k_mult > k) THEN GOTO calc_mob IF (k_div % alg_mod1 == alg_rem1a) THEN GOTO algeb IF (k_div % alg_mod1 == alg_rem1b) THEN GOTO algeb IF (k_div % alg_mod2 == alg_rem2a) THEN GOTO algeb IF (k_div % alg_mod2 == alg_rem2b) THEN GOTO algeb GOTO calc_mob #----------------------------------------------------------------------------------------- # Exclude Generallized Fermat k's for even Sierp bases. #----------------------------------------------------------------------------------------- LABEL calc_gfn IF (base % 2 == 1) THEN GOTO calc_mob LABEL gfn_loop IF (k < gfn_k) THEN GOTO calc_mob IF (k == gfn_k) THEN GOTO GFN SET gfn_k, gfn_k * base_root GOTO gfn_loop #----------------------------------------------------------------------------------------- # Test for multiples of the base (MOB). If the k is evenly divisible by the base, then # add the type (Riesel or Sierp) and primality test the answer. If it is composite, it # is a MOB and will be written to the MOB file. If it is prime, it continues as usual. #----------------------------------------------------------------------------------------- LABEL calc_mob IF (k % base > 0) THEN GOTO Do_n SETS test_str,%d%s1;k;type_str PRIMEC test_str IF (ISPRIME) THEN GOTO Do_n IF !(ISPRP) THEN GOTO MOB IF (k > 100000000) THEN SET MAXF, 100000000 ELSE SET MAXF, k FACTORIZE k + type IF !(ISPRIME) THEN GOTO MOB LABEL Do_n SET n, 0 #----------------------------------------------------------------------------------------- # Minor looping process on n-value. #----------------------------------------------------------------------------------------- LABEL next_n SET n, n + 1 IF (n > max_n) THEN GOTO rem_k #---------------------------------------------------------------------------------------- # PRP test #---------------------------------------------------------------------------------------- SETS test_str,%d*%d^%d%s1;k;base;n;type_str PRP k * base ^ n + type, test_str IF (ISPRIME) THEN GOTO prime_fnd IF !(ISPRP) THEN GOTO next_n #---------------------------------------------------------------------------------------- # primality test unproven PRP #---------------------------------------------------------------------------------------- IF (type == 1) THEN GOTO prove_sierp PRIMEP test_str GOTO check_PRP LABEL prove_sierp PRIMEM test_str LABEL check_PRP IF (ISPRIME) THEN GOTO prime_fnd #---------------------------------------------------------------------------------------- # If unable to prove a PRP, attempt to find a factor. #---------------------------------------------------------------------------------------- SET MAXF, k * base ^ (n/2) IF (MAXF > 100000000) THEN SET MAXF, 100000000 FACTORIZE k * base ^ n + type IF (ISPRIME) THEN GOTO prime_fnd #---------------------------------------------------------------------------------------- # If still unable to prove a PRP, attempt a combined test. #---------------------------------------------------------------------------------------- PRIMEC test_str IF (ISPRIME) THEN GOTO prime_fnd IF (ISPRP) THEN GOTO prp_fnd GOTO cpPRP #---------------------------------------------------------------------------------------- # If unable to prove a PRP but it still holds up as an unproven PRP, assume it is prime # and write to the PRP and prime files. If it comes back as composite, write to the # compPRP file. The user will need to check primality of both the compPRP and PRP files # by other means. #---------------------------------------------------------------------------------------- LABEL algeb IF (a_wrt == 1) THEN GOTO algeb_cont OPENFILEAPP a_file,pl_algeb.txt SET a_wrt, 1 LABEL algeb_cont SETS tmpstr,%d;k WRITE a_file,tmpstr GOTO next_k LABEL cpPRP IF (c_wrt == 1) THEN GOTO cpPRP_cont OPENFILEAPP c_file,pl_compPRP.txt SET c_wrt, 1 LABEL cpPRP_cont SETS tmpstr,%d*%d^%d%s1;k;base;n;type_str WRITE c_file,tmpstr GOTO next_n LABEL GFN IF (g_wrt == 1) THEN GOTO GFN_cont OPENFILEAPP g_file,pl_GFN.txt SET g_wrt, 1 LABEL GFN_cont SETS tmpstr,%d;k WRITE g_file,tmpstr GOTO next_k LABEL MOB IF (m_wrt == 1) THEN GOTO MOB_cont OPENFILEAPP m_file,pl_MOB.txt SET m_wrt, 1 LABEL MOB_cont SETS tmpstr,%d;k WRITE m_file,tmpstr GOTO next_k LABEL prp_fnd IF (p_wrt == 1) THEN GOTO prp_cont OPENFILEAPP pp_file,pl_prp.txt SET p_wrt, 1 LABEL prp_cont SETS tmpstr,%d*%d^%d%s1;k;base;n;type_str WRITE pp_file,tmpstr LABEL prime_fnd SETS tmpstr,%d*%d^%d%s1;k;base;n;type_str WRITE p_file,tmpstr GOTO next_k LABEL rem_k IF (r_wrt == 1) THEN GOTO rem_k_cont OPENFILEAPP r_file,pl_remain.txt SET r_wrt, 1 LABEL rem_k_cont SETS tmpstr,%d*%d^n%s1;k;base;type_str WRITE r_file,tmpstr GOTO next_k LABEL trivial_fact IF (t_wrt == 1) THEN GOTO trivial_fact_cont OPENFILEAPP t_file,pl_trivial.txt SET t_wrt, 1 LABEL trivial_fact_cont SETS tmpstr,%d;k WRITE t_file,tmpstr GOTO next_k LABEL END END