Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Merge branch 'seidelsw' into unitary
Browse files Browse the repository at this point in the history
  • Loading branch information
dimpase committed Aug 26, 2015
2 parents 5450f1e + 25eec1b commit 50a6efc
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 27 deletions.
45 changes: 37 additions & 8 deletions src/sage/combinat/designs/twographs.py
Expand Up @@ -55,7 +55,6 @@
"""
from sage.combinat.designs.incidence_structures import IncidenceStructure
from itertools import combinations
from sage.misc.functional import is_odd, is_even

class TwoGraph(IncidenceStructure):
r"""
Expand Down Expand Up @@ -176,21 +175,51 @@ def is_twograph(T):
- ``T`` -- an :class:`incidence structure <sage.combinat.designs.IncidenceStructure>`
EXAMPLES::
EXAMPLES:
a two-graph from a graph::
sage: from sage.combinat.designs.twographs import is_twograph
sage: p=graphs.PetersenGraph().twograph()
sage: is_twograph(p)
True
a non-regular 2-uniform hypergraph which is a two-graph::
sage: is_twograph(designs.TwoGraph([[1,2,3],[1,2,4]]))
True
TESTS:
wrong size of blocks::
sage: is_twograph(designs.projective_plane(3))
False
a triple system which is not a two-graph::
sage: is_twograph(designs.projective_plane(2))
False
"""
B = map(frozenset, T.blocks())
return T.is_t_design(k=3) and \
all(map(lambda f: is_even(sum(map(lambda x: frozenset(x) in B, combinations(f, 3)))),
combinations(T.ground_set(), 4)))
if not T.is_uniform(3):
return False

# A structure for a fast triple existence check
v_to_blocks = {v:set() for v in range(T.num_points())}
for B in T._blocks:
B = frozenset(B)
for x in B:
v_to_blocks[x].add(B)

has_triple = lambda (x,y,z) : bool(v_to_blocks[x]&v_to_blocks[y]&v_to_blocks[z])

# Check that every quadruple contains an even number of triples
from __builtin__ import sum
for quad in combinations(range(T.num_points()),4):
if sum(map(has_triple,combinations(quad,3))) % 2 == 1:
return False

return True

def twograph_descendant(G, v, name=None):
r"""
Expand All @@ -215,8 +244,8 @@ def twograph_descendant(G, v, name=None):
one of s.r.g.'s from the :mod:`database <sage.graphs.strongly_regular_db>`::
sage: from sage.combinat.designs.twographs import twograph_descendant
sage: A=graphs.strongly_regular_graph(280,135,70)
sage: twograph_descendant(A, 0).is_strongly_regular(parameters=True)
sage: A=graphs.strongly_regular_graph(280,135,70) # optional - gap_packages internet
sage: twograph_descendant(A, 0).is_strongly_regular(parameters=True) # optional - gap_packages internet
(279, 150, 85, 75)
TESTS::
Expand Down
2 changes: 1 addition & 1 deletion src/sage/graphs/generators/families.py
Expand Up @@ -486,7 +486,7 @@ def chang_graphs():
sage: s=[K8.subgraph_search(c8).edges(),
....: [(0,1,None),(2,3,None),(4,5,None),(6,7,None)],
....: K8.subgraph_search(c3c5).edges()]
sage: map(lambda x,G: T8.seidel_switching(x).is_isomorphic(G),
sage: map(lambda x,G: T8.seidel_switching(x, inplace=False).is_isomorphic(G),
....: s, chang_graphs)
[True, True, True]
Expand Down
32 changes: 15 additions & 17 deletions src/sage/graphs/graph.py
Expand Up @@ -5091,25 +5091,23 @@ def twograph(self):
-- ditto, but much faster.
"""
from sage.combinat.designs.twographs import TwoGraph
v = self.vertices()
G = self.relabel(inplace=False)
T = []
i = 0
for vi in v[:-2]: # add the triangles
i += 1
j = i
for vj in v[i:-1]:
j += 1
if self.has_edge(vi,vj):
for vk in v[j:]:
if self.has_edge(vi,vk) and self.has_edge(vj,vk):
T.append((vi,vj,vk))

for vi, vj, _ in self.edges(): # add triples with just 1 edge
for vk in v:
if (not self.has_edge(vi,vk)) and (not self.has_edge(vj,vk)):
T.append(tuple(sorted((vi,vj,vk))))
return TwoGraph(sorted(T))

# Triangles
for x,y,z in G.subgraph_search_iterator(Graph({1:[2,3],2:[3]})):
if x < y and y < z:
T.append([x,y,z])

# Triples with just one edge
for x,y,z in G.subgraph_search_iterator(Graph({1:[2],3:[]}),induced=True):
if x < y:
T.append([x,y,z])

T = TwoGraph(T)
T.relabel({i:v for i,v in enumerate(self.vertices())})

return T

### Visualization

Expand Down
2 changes: 1 addition & 1 deletion src/sage/graphs/strongly_regular_db.pyx
Expand Up @@ -604,7 +604,7 @@ def is_twograph_descendant_of_srg(int v, int k0, int l, int mu):
sage: graphs.strongly_regular_graph(279, 150, 85, 75, existence=True)
True
sage: graphs.strongly_regular_graph(279, 150, 85, 75).is_strongly_regular(parameters=True)
sage: graphs.strongly_regular_graph(279, 150, 85, 75).is_strongly_regular(parameters=True) # optional - gap_packages internet
(279, 150, 85, 75)
"""
cdef int b, k, s
Expand Down

0 comments on commit 50a6efc

Please sign in to comment.