Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 1605
1
'''
2
This file assumes that the conjecturing spkg is installed and that 'conjecturing.py'
3
and 'numbertheory.py' is loaded.
4
'''
5
6
def automatedSearch(objects, invariants, mainInvariant, universe, upperBound=True, steps=10, verbose=False):
7
if verbose:
8
print("Starting with these objects:")
9
for i in objects:
10
print(" {}".format(i))
11
print("")
12
print("Available invariants:")
13
for pos, invariant in enumerate(invariants):
14
if type(invariant) == tuple:
15
name, _ = invariant
16
elif hasattr(invariant, '__name__'):
17
name = invariant.__name__
18
else:
19
name = 'invariant_{}'.format(pos)
20
if pos + 1 == mainInvariant:
21
print(" * {}".format(name))
22
else:
23
print(" {}".format(name))
24
print("")
25
for step in range(steps):
26
l = conjecture(objects, invariants, mainInvariant, upperBound=upperBound)
27
if verbose:
28
print("Found the following conjectures:")
29
for c in l:
30
print(" {}".format(c))
31
print("")
32
noCounterExample = True
33
for i in universe:
34
if any([not c.evaluate(Integer(i)) for c in l]):
35
print "Step {}: Adding {}".format(step+1, i)
36
objects.append(i)
37
universe.remove(i)
38
noCounterExample = False
39
break
40
if noCounterExample:
41
print "No counterexample found"
42
break
43
return l
44
45
objects = [Integer(4)]
46
universe = [Integer(n) for n in range(4, 1000001, 2)]
47
48
for n in objects:
49
universe.remove(n)
50
51
mainInvariant = invariants.index(goldbach)
52
53
conjectures = automatedSearch(objects, invariants, mainInvariant, universe, steps=200, verbose=True, upperBound=False)
54
55
print("The conjectures are stored in the variable conjectures.")
56
57