Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
1 contributor

Users who have contributed to this file

303 lines (262 sloc) 11.2 KB
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.
#
#
# The maximum base that the script can handle is 2*3*5*7*11*13*17=510510. Higher bases
# would need tweaking done to allow for more modulos for k's with trivial factors.
#----------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------
# The following 5 lines control what is tested and are the only lines that should be
# changed. Type is 1 for Sierp and -1 for Riesel. The rest should be self explanatory.
#----------------------------------------------------------------------------------------
DIM base, 3
DIM type, -1
DIM min_k, 2
DIM max_k, 1000
DIM max_n, 1000
#----------------------------------------------------------------------------------------
# Variables ending in _wrt are write switches.
# They are needed to prevent empty files from being written.
#----------------------------------------------------------------------------------------
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 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_r
IF (k % 2 == 1) THEN GOTO next_k
LABEL calc_trivial_r
IF (type == 1) THEN GOTO calc_trivial_s
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
GOTO calc_gfn
LABEL calc_trivial_s
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
#-----------------------------------------------------------------------------------------
# Exclude Generallized Fermat k's for even Sierp bases.
#-----------------------------------------------------------------------------------------
LABEL calc_gfn
IF (type == -1) THEN GOTO calc_mob
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 NOT prime, 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 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
#----------------------------------------------------------------------------------------
# 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.
#----------------------------------------------------------------------------------------
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