"""
Given a totally real number field Q(d_1^(1/2), ...,d_t^(1/2)) this script searches for a which are p-rational. Final result is printed in file examples-
-.txt where p and t are to be replaced by their value.
"""
import itertools
load Schirokauer.sage
p = 97 # replace 97 with any other prime > 3
ds = [2, 3, 5, 7, 11, 13, 19, 23, 43,73] # found by search_example_2_12.sage
t = len(ds) + 1
print "searchind d_",t,"...",
gd=open("examples-"+str(p)+"-"+str(t)+".txt","w")
d = 0
found = false
while not found:
d -= 1
if gcd(d,prod(ds+[1])*p) != 1 or not d.is_squarefree():
continue # we must guarantee that Gal(K/Q) = (Z/2Z)^t
# and p is unramified
prop_2_10 = true
for sbset in itertools.product([0,1],repeat=t):
D=prod([ds[i]^sbset[i] for i in range(t-1)])*d
D=D.squarefree_part()
if QuadraticField(D).class_number() % p == 0:
print D
prop_2_10 = false
break
if prop_2_10:
ds.append(d)
print d
found = true
# at this point prop_2_10 == true so the Proposition 2.10 can be applied
# to prove that K is p-rational
gd.write(str(ds))
gd.close()