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

doctests

parent 1e6579e7
No related branches found
No related tags found
No related merge requests found
...@@ -54,6 +54,19 @@ def _init_(): ...@@ -54,6 +54,19 @@ def _init_():
@OneOfKind @OneOfKind
class EdgeColoring(SimpleParameterBase): class EdgeColoring(SimpleParameterBase):
"""Edge coloring of gadget.
Colors have identity.
>>> from .sequences import Necklace
>>> Necklace.graph(1).eval(EdgeColoring(2))
0
>>> Necklace.graph(1).eval(EdgeColoring(3))
6
>>> Necklace.graph(2).eval(EdgeColoring(3))
12
"""
def __init__(self, k): def __init__(self, k):
self.k = k self.k = k
self.FREE_EDGE = [ Boundary((i, i), 1) for i in range(k) ] self.FREE_EDGE = [ Boundary((i, i), 1) for i in range(k) ]
...@@ -211,6 +224,18 @@ def _init_(): ...@@ -211,6 +224,18 @@ def _init_():
yield Boundary(ret_b, prod( b.value for b in x )) yield Boundary(ret_b, prod( b.value for b in x ))
def join_edges(self, b, e1, e2): def join_edges(self, b, e1, e2):
"""
>>> from .definitions import Boundary as B
>>> def test(*args): return list(CircuitDoubleCover.join_edges(*args))
>>> test(B(((1,2), (2,3), (1,3), None), 1), 1, 2)
[]
>>> test(B(((1,2), (2,3), (1,4), (3,4), None), 1), 1, 2)
[Boundary(boundary=((3, 2), (2, 3), (3, 2), (3, 2), None), value=1)]
>>> test(B(((1,2), (2,3), (1,4), (3,4), None, (1,3)), 1), 1, 2)
[]
>>> len(test(B(((1,2), (2,3), (4,5), (1,3), (4,5), None), 1), 1, 2))
2
"""
assert len(b.boundary[e1]) == len(b.boundary[e2]) assert len(b.boundary[e1]) == len(b.boundary[e2])
def do_join(uf): def do_join(uf):
...@@ -272,6 +297,17 @@ def _init_(): ...@@ -272,6 +297,17 @@ def _init_():
return b[0].value return b[0].value
def enumerate_boundaries(self, n): def enumerate_boundaries(self, n):
"""Enumerate all possible boundaries on cut of size `n`.
>>> list(CircuitDoubleCover.enumerate_boundaries(2))
[((1, 2), (1, 2), None)]
>>> list(CircuitDoubleCover.enumerate_boundaries(3))
[((1, 2), (1, 3), (2, 3), None)]
>>> sum( 1 for _ in CircuitDoubleCover.enumerate_boundaries(4) )
60
>>> sum( 1 for _ in CircuitDoubleCover.enumerate_boundaries(5) )
1024
"""
if n == 0: yield (None,) if n == 0: yield (None,)
if n <= 1: return if n <= 1: return
... ...
......
...@@ -7,14 +7,35 @@ so we put them here instead. ...@@ -7,14 +7,35 @@ so we put them here instead.
>>> from .all import * >>> from .all import *
>>> from sage.all import * >>> from sage.all import *
>>> graphs.CompleteGraph(4).is_isomorphic(Necklace.graph(1).eval(UnderlayingGraph)) >>> is_isomorphic = lambda g, gadget: g.is_isomorphic(gadget.eval(UnderlayingGraph))
>>> assert is_isomorphic(graphs.CompleteGraph(4), Necklace.graph(1))
>>> all( Necklace.graph(i).eval(CircuitDoubleCover) == 2 * 4**(i-1) for i in range(1, 10) ) >>> assert is_isomorphic(graphs.PetersenGraph(), Petersen)
>>> cdc_count = lambda gadget: gadget.eval(CircuitDoubleCover)
>>> cdc_count(Petersen)
52
>>> cdc_count(GeneralizedPetersen(2).graph(5))
52
>>> cdc_count(FlowerSnark.graph(3))
104
>>> all( cdc_count(Necklace.graph(i)) == 2 * 4**(i-1) for i in range(1, 100) )
True True
>>> GeneralizedPetersen(2).graph(5).eval(CircuitDoubleCover) == 52 >>> all( cdc_count(Flower.graph(k)) == (2**(k-1) + (-1)**k) // 3 + 1 for k in range(3, 20) )
True True
>>> FlowerSnark.graph(3).eval(CircuitDoubleCover) >>> Necklace.stabilize(CircuitDoubleCover)
104 Loop 1 done - 1 boundaries (0 new)
{'variables': [((1, 2), (1, 2), None)], 'step_matrix': [4], 'initial_vector': [2], 'finalize': [1]}
>>> sun_cdc = lambda n: sum( v for _, v in sun(n).eval_gadget(CircuitDoubleCover) )
>>> all( sun_cdc(n) == 2**n - 2*n for n in range(3, 10) )
True
>>> d = [ list(range(5)), list(range(5, 10)) ]
>>> graph_to_gadget(graphs.PetersenGraph(), d).eval(GroupFlow(Integers(3), False))
729
>>> graph_to_gadget(graphs.PetersenGraph(), d).eval(GroupFlow(Integers(4), True))
0
>>> graph_to_gadget(graphs.PetersenGraph(), d).eval(GroupFlow(Integers(5), True))
240
""" """
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment