# Ticket #8745: trac_8745.patch

File trac_8745.patch, 4.6 KB (added by ncohen, 11 years ago)
• ## sage/combinat/designs/block_design.py

# HG changeset patch
# User Nathann Cohen <nathann.cohen@gmail.com>
# Date 1271939620 -7200
# Node ID 55cebde63cda7cda76aa9b175c88dc33d24b6bee
# Parent  ef74a6ed21179df343f658c015d7b068bb28c0f3
trac 8745 : Steiner Triple Systems in BlockDesign

diff -r ef74a6ed2117 -r 55cebde63cda sage/combinat/designs/block_design.py
 a # A is the incidence matrix of the block design return IncidenceStructureFromMatrix(A,name="HadamardDesign") def steiner_triple_system(n): r""" Returns a Steiner Triple System A Steiner Triple System (STS) of a set \{0,...,n-1\} is a family S of 3-sets such that for any i \not = j there exists exactly one set of S in which they are both contained. It can alternatively be thought of as a factorization of the complete graph K_n with triangles. A Steiner Triple System of a n-set exists if and only if n \equiv 1 mod 6 or n \equiv 3 mod 6, in which case one can be found through Bose's and Skolem's constructions, respectively [AndHon97]_. INPUT: - n returns a Steiner Triple System of \{0,...,n-1\} EXAMPLE: A Steiner Triple System on 9 elements :: sage: from sage.combinat.designs.block_design import steiner_triple_system sage: sts = steiner_triple_system(9) sage: sts Incidence structure with 9 points and 12 blocks sage: list(sts) [[0, 1, 5], [0, 2, 4], [0, 3, 6], [0, 7, 8], [1, 2, 3], [1, 4, 7], [1, 6, 8], [2, 5, 8], [2, 6, 7], [3, 4, 8], [3, 5, 7], [4, 5, 6]] As any pair of vertices is covered once, its parameters are :: sage: sts.parameters() (2, 9, 3, 1) An exception is raised for invalid values of n :: sage: steiner_triple_system(10) Traceback (most recent call last): ... ValueError: Steiner triple systems only exist for n = 1 mod 6 or n = 3 mod 6 REFERENCE: .. [AndHon97] A short course in Combinatorial Designs, Ian Anderson, Iiro Honkala, Internet Editions, Spring 1997, http://www.utu.fi/~honkala/designs.ps """ name = "Steiner Triple System on "+str(n)+" elements" if n%6 == 3: t = (n-3)/6 Z = range(2*t+1) T = lambda (x,y) : x + (2*t+1)*y sts = [[(i,0),(i,1),(i,2)] for i in Z] + \ [[(i,k),(j,k),(((t+1)*(i+j)) % (2*t+1),(k+1)%3)] for k in range(3) for i in Z for j in Z if i != j] elif n%6 == 1: t = (n-1)/6 N = range(2*t) T = lambda (x,y) : x+y*t*2 if (x,y) != (-1,-1) else n-1 L1 = lambda i,j : (i+j) % (int((n-1)/3)) L = lambda i,j : L1(i,j)/2 if L1(i,j)%2 == 0 else t+(L1(i,j)-1)/2 sts = [[(i,0),(i,1),(i,2)] for i in range(t)] + \ [[(-1,-1),(i,k),(i-t,(k+1) % 3)] for i in range(t,2*t) for k in [0,1,2]] + \ [[(i,k),(j,k),(L(i,j),(k+1) % 3)] for k in [0,1,2] for i in N for j in N if i < j] else: raise ValueError("Steiner triple systems only exist for n = 1 mod 6 or n = 3 mod 6") from sage.sets.set import Set sts = Set(map(lambda x: Set(map(T,x)),sts)) return BlockDesign(n, sts, name=name) def BlockDesign(max_pt, blks, name=None, test=True): """ Returns an instance of the IncidenceStructure class. Requires each
• ## sage/combinat/designs/incidence_structures.py

diff -r ef74a6ed2117 -r 55cebde63cda sage/combinat/designs/incidence_structures.py
 a self.name = name self._incidence_matrix = inc_mat def __iter__(self): """ Iterator over the blocks. EXAMPLE:: sage: sts = sage.combinat.designs.block_design.steiner_triple_system(9) sage: list(sts) [[0, 1, 5], [0, 2, 4], [0, 3, 6], [0, 7, 8], [1, 2, 3], [1, 4, 7], [1, 6, 8], [2, 5, 8], [2, 6, 7], [3, 4, 8], [3, 5, 7], [4, 5, 6]] """ return iter(self.blcks) def __repr__(self): """ A print method. sage: BD.block_sizes() [3, 3, 3, 3, 3, 3, 3] """ bs = [] for b in self.blocks(): bs.append(len(b)) self._block_sizes = bs return bs self._block_sizes = map(len,self.blocks()) return self._block_sizes def _gap_(self): """