Skip to content
Snippets Groups Projects
Commit 722a9bc3 authored by Radek Hušek's avatar Radek Hušek
Browse files

bump

parent 2ceddc8d
No related branches found
No related tags found
No related merge requests found
......@@ -223,9 +223,87 @@ Petersen = join_gadgets(
[]
)
#print(join_gadgets([CUBIC_VERTEX]*2, [((1,1), (2,1))], []))
#for i in range(1, 10):
# print(i, necklace(i))
def stabilize(base_gadget, operation, finalize = None):
from sage.all import SR, matrix, ZZ
boundaries = set()
new_boundaries = set(base_gadget.keys())
i = 0
while True:
i += 1
new_boundaries.update(boundaries)
if new_boundaries == boundaries: break
boundaries = new_boundaries
gadget = { k: SR.symbol() for k in boundaries }
out = operation(gadget)
new_boundaries = set(out.keys())
print("Loop %i done - %i boundaries (%i new)" % \
(i, len(new_boundaries), len(new_boundaries.difference(boundaries))))
sorted_gadget = tuple(gadget.items())
out = { k: v.expand() for k, v in out.items() }
rename = { v: i for i, (_, v) in enumerate(sorted_gadget) }
m = matrix(ZZ, len(gadget), len(gadget), {
(rename[gadget[row]], rename[col]): formula.coefficient(col)
for row, formula in out.items()
for col in formula.free_variables()
})
iv = matrix(ZZ, len(gadget), 1, {
(rename[gadget[row]], 0): v for row, v in base_gadget.items()
})
if finalize is not None:
fin = finalize(gadget)
assert(len(fin) == 1 and (None,) in fin)
fin = next(iter(fin.values())).expand()
fin = matrix(ZZ, 1, len(gadget), {
(0, rename[col]): fin.coefficient(col) for col in fin.free_variables()
})
else:
fin = None
return {
'variables': sorted_gadget,
'step_matrix': m,
'initial_vector': iv,
'finalize': fin
}
def flower_matrix():
return stabilize(flower_gadget(1),
lambda x: flower_snark_join(x, FLOWER_SNARK_BASIC_GADGET),
lambda gadget: join_gadgets(
[ gadget ],
[
((1, 2), (1, 1)),
((1, 4), (1, 3)),
((1, 6), (1, 5)),
],
[]
)
)
def count_cdc_naive(G):
assert(G.degree() == [3]*G.num_verts())
vert_map = { v: i for i, v in enumerate(G.vertices()) }
vert_used = [ 1 ] * len(vert_map)
joins = []
for u, v, _ in G.edges():
u = vert_map[u]
v = vert_map[v]
joins.append(((u+1, vert_used[u]), (v+1, vert_used[v])))
vert_used[u] += 1
vert_used[v] += 1
b = join_gadgets([ CUBIC_VERTEX ] * G.num_verts(), joins, [])
assert(list(b.keys()) == [(None,)])
return (b[(None,)], 2**(G.num_verts() // 2) // 2)
assert(K4 == {(None,): 2})
for i in range(2, 10):
......@@ -233,6 +311,7 @@ for i in range(2, 10):
assert(Petersen == {(None,): 52})
assert(flower_snark(3) == {(None,): 104})
if False:
print(flower_snark(5))
print("basic", len(FLOWER_SNARK_BASIC_GADGET))
......
......@@ -29,3 +29,15 @@ def select(pat, l):
def prod(iterable):
return reduce(operator.mul, iterable, 1)
def arg_min(fn, it):
ret = next(it)
v = fn(ret)
for i in it:
v_ = fn(i)
if v_ < v:
v = v_
ret = i
return ret
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment