-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompute.sage
51 lines (41 loc) · 1.16 KB
/
compute.sage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
prec = 30
cvars = []
def cvar(u,x):
return cvars[u-1][x]
def c1(x):
return cvar(1,x)
def c2(x):
return cvar(2,x)
def c3(x):
return cvar(3,x)
def c4(x):
return cvar(4,x)
def c5(x):
return cvar(5,x)
def c6(x):
return cvar(6,x)
def compute_complexity(N, x,
generate_variables,
get_boundary_conditions,
generate_equations,
ticks=False, start=None, return_kb=False):
global cvars
cvars = generate_variables(N)
# Knowledge base -- dynamic programming memory
KB = get_boundary_conditions(N)
if ticks:
print 'x log(guesses)'
print '-' * 30
if start is None:
start = N-1
for i in range(start, x-1, -1):
equations, variables = generate_equations(N, i, KB)
solutions = solve(equations, variables, solution_dict=True)[0]
# add computed values
for v in variables:
KB[v] = solutions[v]
if ticks:
print '{:3d} {:10.2f}'.format(i, float(log(KB[c1(i)], 2).n(prec)))
if return_kb:
return KB
return KB[cvar(1, x)]