Gray Codes from Antimatroids Gara Pruesse ? Department of Computer Science University of Toronto , Toronto , Ontario , M5S 1A1 , Canada Frank Ruskey y Department of Computer Science University of Victoria , Victoria , B.C. , V8W 2Y2 , Canada May 27 , 1993 Abstract We show three main results concerning Hamiltonicity of graphs derived from antimatroids . These results provide Gray codes for the feasible sets and basic words of antimatroids . For antimatroid -LRB- E ; F -RRB- , let J -LRB- F -RRB- denote the graph whose vertices are the sets of F , where two vertices are adjacent if the corresponding sets differ by one element . Define J -LRB- F ; k -RRB- to be the subgraph of J -LRB- F -RRB- 2 induced by the sets in F with exactly k elements . Both graphs J -LRB- F -RRB- and J -LRB- F ; k -RRB- are connected , and the former is bipartite . We show that there is a Hamiltonian cycle in J -LRB- F -RRB- ? K2 . As a consequence , the ideals of any poset P may be listed in such a way that successive ideals differ by at most two elements . We also show that J -LRB- F ; k -RRB- has a Hamilton path if -LRB- E ; F -RRB- is the poset antimatroid of a series-parallel poset . Similarly , we show that G -LRB- L -RRB- ? K2 is Hamiltonian , where G -LRB- L -RRB- is the \ basic word graph '' of a language antimatroid -LRB- E ; L -RRB- . This result was known previously for poset antimatroids . AMS Classification : 05C45 , 06A05 , 06A06 . ? Research supported in part by NSERC . yResearch supported in part by the Natural Sciences and Engineering Research Council of Canada under Grant A3379 . 1 Introduction Antimatroids provide a very general setting in which to consider problems of generating combinatorial objects . In the context of ordering and listing the feasible sets or feasible words of antimatroids , Hamiltonicity questions naturally arise in graphs that have these feasible objects as vertices . The purpose of this paper is to raise and answer some of these Hamiltonicity questions . A motivation for studying Hamiltonicity properties is their connections with combinatorial Gray Codes , that is , lists of combinatorial objects in which successive objects differ by a small amount . Such Gray Codes often form the basis of efficient algorithms for generating the objects . Some proofs rely on the connectedness of distributive lattices to prove statements of the form \ for every pair of objects x and y -LRB- lattice elements -RRB- , there is a sequence of elementary transformations -LRB- cover relations -RRB- that transform x into y '' . For example , Propp -LSB- 13 -RSB- uses such a technique to prove that any perfect matching in a planar graph -LRB- subject to a mild condition -RRB- may be transformed into any other by a sequence of \ face rotations '' . Using our results , any such statement implies a statement of the form \ there is a sequence of all the objects so that successive objects differ by one or two elementary transformations '' . Antimatroids lend themselves to two different representations , ordered and unordered . The ordered version is a kind of language , and the unordered version is a kind of set system . A set system over a finite ground set E is a pair -LRB- E ; F -RRB- where F ? 2E . A set system is an antimatroid if the following axioms hold . -LRB- A1 -RRB- If F 2 F with F < > ; , then there exists an x 2 F such that F n fxg 2 F . -LRB- A2 -RRB- If A ; B 2 F , then A -LSB- B 2 F . A set system satisfying -LRB- A1 -RRB- is said to be accessible . A language over a finite alphabet E is a pair -LRB- E ; L -RRB- with L ? E ? , where E ? is the free monoid of words in the alphabet E . The length of 2 L -LRB- i.e. , the number of not necessarily distinct letters in -RRB- is denoted j j . The support ~ of is the set of letters of . A word is simple if it contains no repeated letter -LRB- i.e. , if j j = j ~ j -RRB- . By E -LRB- ? -RRB- we denote the set of words in E ? which are simple . A language -LRB- E ; L -RRB- is simple if every word in L is simple -LRB- i.e. , if each word of L is in E -LRB- ? -RRB- -RRB- . A simple language is a language antimatroid if the following axioms hold . -LRB- L1 -RRB- If 2 L , then 2 L. -LRB- L2 -RRB- If ff ; 2 L with ~ 6 ? ~ , then there is an x 2 ~ with x 2 L . The basic words , Basic -LRB- L -RRB- , of a language antimatroid are the words 2 L of maximal length . There is a one-to-one correspondence between antimatroid set systems and antimatroid languages . Given an antimatroid set system F , let L -LRB- F -RRB- be the language given by L -LRB- F -RRB- def = fx1x2 ? ? ? xk : fx1 ; x2 ; : : : ; xig 2 F 8i ; 1 < = i < = kg : Given the antimatroid language L , let F -LRB- L -RRB- = f ~ : 2 Lg . It is easy to see that F -LRB- L -LRB- F -RRB- -RRB- = F , and L -LRB- F -LRB- L -RRB- -RRB- = L. Thus we may switch from one representation to the other when convenient . Every antimatroid is both a set system and a language , so in order to avoid confusion over which representation we are referring to , we will most often use F or L when we wish to treat the antimatroid as a set system or language , respectively . There are several alternate characterizations of antimatroids ; one that is quite useful is in terms of \ alternative precedences '' . Let E be a finite set and H be a mapping that associates with each x 2 E a set system H -LRB- x -RRB- ? 2Enfxg . The language LH def = fx1x2 ? ? ? xk 2 E -LRB- ? -RRB- : 8i ; 1 < = i < = k ; 9 A 2 H -LRB- xi -RRB- s.t. . A ? fx1 ; x2 ; : : : ; xi ? 1gg is called an alternative precedence language . A finite simple language is a language antimatroid if and only if it is an alternative precedence language -LRB- -LSB- 11 -RSB- , -LSB- 4 -RSB- -RRB- . An element a is an atom if fag 2 F ; or , equivalently , if a 2 L ; or , equivalently , if H -LRB- a -RRB- = f ; g . In order to simplify the notation we sometimes use F to denote the antimatroid -LRB- E ; F -RRB- , with the understanding that E = -LSB- F , where the union is over all F 2 F . Similarly , we will use L to denote the language antimatroid -LRB- E ; L -RRB- , with the understanding that E = -LSB- ~ , where the union is over all 2 L . If F is an antimatroid and A 2 F , then we may obtain two new antimatroids by contraction and deletion as follows . F = A def = fF : F \ A = ; and F -LSB- A 2 Fg : F n A def = fF 2 F : F \ A = ; g : Note that these two antimatroids induce a partition of the feasible sets of F if jAj = 1 . Perhaps the most important class of antimatroids are the poset antimatroids . The set system -LRB- E ; F -RRB- is a poset antimatroid if E is the set of elements of a poset P and F is the set of ideals of P . The basic words of the corresponding language antimatroid are the linear extensions of P . There are two standard \ sums '' of antimatroids . Let -LRB- E1 ; F1 -RRB- and -LRB- E2 ; F2 -RRB- be antimatroids on distinct ground sets . The direct sum F1 + F2 is the antimatroid F1 + F2 def = fX1 -LSB- X2 : X1 2 F1 and X2 2 F2g : The ordinal sum F1 ? F2 is the antimatroid F1 ? F2 def = F1 -LSB- fE1 -LSB- X2 : X2 2 F2g : Observe that starting with isolated elements and then applying the operations of direct and ordinal sum results in poset antimatroids of series-parallel posets . We now define the graphs whose Hamiltonicity properties are investigated in the following sections . For antimatroid -LRB- E ; F -RRB- , let J -LRB- F -RRB- denote the undirected covering graph of the sets of F ordered by inclusion . The square of a graph G , is the graph G2 whose vertex set is the same as G and such that two vertices are adjacent in G2 if they are of distance one or two in G. Define J -LRB- F ; k -RRB- to be the subgraph of J -LRB- F -RRB- 2 induced by the sets in F with exactly k elements . Both graphs J -LRB- F -RRB- and J -LRB- F ; k -RRB- are connected , and the former is bipartite . For some F , J -LRB- F -RRB- does not have a Hamilton path , even when the partite sets of J -LRB- F -RRB- are of the same cardinality ; for example , consider the lattice of ideals of the seriesparallel poset 1 ? -LRB- 1 +1 -RRB- ? 1 ? -LRB- 1 +1 -RRB- ? 1 . The graph J -LRB- F ; k -RRB- can fail to have Hamilton cycle but we know of no example where J -LRB- F ; k -RRB- fails to have a Hamilton path . In fact , J -LRB- F ; k -RRB- can be a path . If F is the poset antimatroid of a poset consisting of two disjoint chains , both containing n ? 1 elements , then J -LRB- F ; n -RRB- is a path of length n . A classic result of Ehrlich -LSB- 5 -RSB- and Bitner , Ehrlich and Reingold -LSB- 2 -RSB- is that J -LRB- P ; k -RRB- is Hamiltonian if P is the poset antimatroid of an antichain . We extend this result to series-parallel posets . The basic word graph G -LRB- L -RRB- of the antimatroid L is the graph whose vertex set is Basic -LRB- L -RRB- , and such that two basic words are adjacent if they differ by the transposition of two adjacent elements . We show that G -LRB- L -RRB- ? K2 is Hamiltonian and thus the existence of a Gray Code for basic words , where each word differs from the previous one in the listing by one or two adjacent transpositions . We give an algorithm for generating the basic words which , for some antimatroids , runs in constant amortized time . Similar questions for the graph of linear extensions were considered by Pruesse and/or Ruskey -LSB- 18 -RSB- , -LSB- 15 -RSB- , -LSB- 16 -RSB- , -LSB- 14 -RSB- and Stachowiak -LSB- 21 -RSB- . The diameter of G -LRB- L -RRB- was investigated in -LSB- 10 -RSB- and -LSB- 27 -RSB- . In Section 2 we show that there is a Hamiltonian cycle in J -LRB- F -RRB- ? K2 . As a consequence , the ideals of any poset P may be listed in such a way that successive ideals differ by at most two elements . In section 3 we show that J -LRB- F ; k -RRB- has a Hamilton path if -LRB- E ; F -RRB- is the poset antimatroid of a series-parallel poset . In Section 4 we show that G -LRB- L -RRB- ? K2 is Hamiltonian . 2 The graph J -LRB- F -RRB- ? K2 is Hamiltonian We consider graphs of the form G ? K2 ; that is , the product of a graph G with an edge . In other words , there are two copies of G , which we denote as + G and ? G , with edges joining corresponding vertices in the two copies . Given a vertex v in G , denote the corresponding vertices in G?K2 as + v and ? v . If w is a vertex of G?K2 then by w we denote the corresponding vertex in the other copy of G . The following lemma was proven in -LSB- 16 -RSB- . Lemma 1 If G is bipartite and G ? K2 is Hamiltonian , then G2 is Hamiltonian . Theorem 1 For every antimatroid F and any atom x of F , the graph J -LRB- F -RRB- ? K2 has a Hamilton cycle that includes the edges -LSB- + ; ; ? ;] and -LSB- + ; ; + x -RSB- . Proof : Our proof is by induction on n = jEj . If n = 1 then J -LRB- F -RRB- ? K2 is the 4-cycle + ; ; + fxg ; ? fxg ; ? ; , where E = fxg . If n > 1 , then let fxg 2 F and consider the antimatroid F = x . We consider two cases depending upon the number of singleton sets in F . If x is the only atom of F , then inductively we may assume that there is a Hamilton cycle + ; = X1 ; X2 ; : : : ; Xp = ? ; in J -LRB- F = x -RRB- . This may be extended to the Hamilton cycle + ; ; X1 -LSB- fxg ; X2 -LSB- fxg ; : : : ; Xp -LSB- fxg ; ? ; in J -LRB- F -RRB- . Clearly , this cycle contains the edges -LSB- + ; ; ? ;] and -LSB- + ; ; + fxg -RSB- . If there are at least two distinct elements x ; y 2 E such that fxg ; fyg 2 F , then inductively there are Hamilton cycles + ; = X1 ; X2 ; : : : ; Xp = ? ; in J -LRB- F = x -RRB- and + ; = Y1 ; Y2 ; : : : ; Yq = ? ; in J -LRB- F n x -RRB- ; where X2 = Y2 = fyg . The following is thus a Hamilton cycle in G -LRB- F -RRB- . Y1 ; X1 -LSB- fxg ; Xp -LSB- fxg ; Xp ? 1 -LSB- fxg ; : : : ; X2 -LSB- fxg ; Y2 ; Y3 ; : : : ; Yq ? 1 ; Yq This cycle contains the edges -LSB- + ; ; ? ;] and -LSB- + ; ; + fxg -RSB- . 2 Observe that the preceeding proof maintains the following invariant : The Hamilton path in J -LRB- F -RRB- ? K2 has the property that any feasible set I between two signed feasible sets ? F and ? F on the path satisfies F ae I. Thus the list of feasible sets has the structure of a well-formed parentheses string with jF j types of parentheses . Corollary 1 For every antimatroid -LRB- E ; F -RRB- , there is a listing X1 ; X2 ; : : : ; XjFj of the feasible sets F such that successive sets -LRB- including the first and last -RRB- differ by at most two elements . Proof : Since J -LRB- F -RRB- is bipartite , we may apply Lemma 1 to conclude that J -LRB- F -RRB- 2 is Hamiltonian . 2 3 Feasible sets of fixed size Recall that the Hamming distance between two bitstrings is the number of positions in which they differ . Regarding the bitstrings as the characteristic vectors of a set the Hamming distance D between two sets is D -LRB- A ; B -RRB- = j -LRB- A -LSB- B -RRB- \ -LRB- A -LSB- B -RRB- j . In other words , the Hamming distance of two sets is the number of elements which are in one set but not in the other . We defined J -LRB- P ; k -RRB- to be the subgraph of J -LRB- P -RRB- 2 induced by those vertices -LRB- feasible sets -RRB- with exactly k elements . In other words , J -LRB- P ; k -RRB- = -LRB- V ; E -RRB- where V = fA 2 F : jAj = kg and E = ffA ; Bg : A ; B 2 V and D -LRB- A ; B -RRB- = 2g . The graph J -LRB- F ; k -RRB- is not bipartite in general -LRB- for example , the graph J -LRB- 2f1 ; 2 ; : : : ; ng ; 1 -RRB- is the complete graph Kn -RRB- , but it is always connected . Lemma 2 For every antimatroid -LRB- E ; F -RRB- , the graph J -LRB- F ; k -RRB- is connected . Proof : Our proof is by induction on jEj . The lemma is clearly true if k = ; 1 or if jEj = ; 1 . So assume that jEj > 1 and k > 1 . Let x be an atom of F . Inductively , J -LRB- F n x ; k -RRB- and J -LRB- F = x ; k ? 1 -RRB- are connected . Thus , the vertices of J -LRB- F ; k -RRB- which contain x are connected , as are those which do not contain x . If F 2 F n x with jF j = k , then there is a y 2 E n fxg such that F nfyg 2 F nx . By closure under union F = F nfyg -LSB- fxg 2 F ; i.e. , F nfyg 2 F = x . Since F and F are adjacent in J -LRB- F ; k -RRB- , all vertices in J -LRB- F ; k -RRB- are connected . 2 If H is a Hamilton path , then first -LRB- H -RRB- and last -LRB- H -RRB- have the obvious meanings of the first and last vertices of H , respectively . Definition 1 The sequence H0 -LRB- P -RRB- ; H1 -LRB- P -RRB- ; : : : ; Hn -LRB- P -RRB- is a complete set of Hamilton paths for the poset P if 1 . Each Hk -LRB- P -RRB- is a Hamilton path in J -LRB- P ; k -RRB- for k = 1 ; 2 ; : : : ; n. 2 . D -LRB- first -LRB- Hi -RRB- ; first -LRB- Hi +1 -RRB- -RRB- = 1 for i = ; 1 ; : : : ; n ? 1 . 3 . D -LRB- last -LRB- Hi -RRB- ; last -LRB- Hi +1 -RRB- -RRB- = 1 for i = ; 1 ; : : : ; n ? 1 . Theorem 2 If Q and R both have complete sets of Hamilton paths then P = Q?R has a complete set of Hamilton paths . Theorem 3 If Q and R both have complete sets of Hamilton paths then P = Q+R has a complete set of Hamilton paths . Corollary 2 Series-parallel posets have complete sets of Hamilton paths . Corollary 3 Forest posets have complete sets of Hamilton paths . Proof -LRB- of Theorem 2 -RRB- : Let p = jS -LRB- P -RRB- j , q = jS -LRB- Q -RRB- j , r = jS -LRB- R -RRB- j , and thus p = q + r. Given the complete sets of Hamilton paths Hk -LRB- Q -RRB- -LRB- for k = ; 1 ; : : : ; q -RRB- and Hk -LRB- R -RRB- -LRB- for k = ; 1 ; : : : ; r -RRB- , we need to show a complete set of Hamilton paths Hk -LRB- P -RRB- -LRB- for k = ; 1 ; : : : ; p -RRB- . For k < = q set Hk -LRB- P -RRB- = Hk -LRB- Q -RRB- . For k > q set Hk -LRB- P -RRB- = S -LRB- Q -RRB- -LSB- Hk?q -LRB- R -RRB- , where the union is taken componentwise . 2 Proof -LRB- of Theorem 3 -RRB- : Let p = jS -LRB- P -RRB- j , q = jS -LRB- Q -RRB- j , r = jS -LRB- R -RRB- j , and assume without loss of generality that < r < = q < p . The complete set of Hamilton paths for Q is denoted Hk -LRB- Q -RRB- -LRB- for k = ; 1 ; : : : ; q -RRB- , and similarly Hk -LRB- R -RRB- for R . We will show how to construct a complete set of Hamilton paths Hk -LRB- P -RRB- -LRB- for k = ; 1 ; : : : ; p -RRB- . The global structure of the path for Hk -LRB- P -RRB- consists of , for increasing values of i , Hamilton paths pi ; k?i in the subgraph Hi -LRB- Q -RRB- ? Hk?i -LRB- R -RRB- of J -LRB- P ; k -RRB- . In the forward direction , the -LRB- i ; k ? i -RRB- path starts with first -LRB- Hi -LRB- Q -RRB- -RRB- -LSB- first -LRB- Hk?i -LRB- R -RRB- -RRB- or first -LRB- Hi -LRB- Q -RRB- -RRB- -LSB- last -LRB- Hk?i -LRB- R -RRB- -RRB- ; -LRB- 1 -RRB- and ends at last -LRB- Hi -LRB- Q -RRB- -RRB- -LSB- first -LRB- Hk?i -LRB- R -RRB- -RRB- or last -LRB- Hi -LRB- Q -RRB- -RRB- -LSB- last -LRB- Hk?i -LRB- R -RRB- -RRB- : -LRB- 2 -RRB- To be specific , let Hi -LRB- Q -RRB- = a1 ; a2 ; : : : ; aM and Hk?i -LRB- R -RRB- = b1 ; b2 ; : : : ; bN Starting in the forward direction from -LRB- 1 -RRB- , the Hamilton path in the subgraph J -LRB- Q ; i -RRB- ? J -LRB- R ; k ? i -RRB- starts out a1b1 ; a1b2 ; : : : ; a1bN ; a1bN ; a1bN ? 1 ; : : : ; a1b1 ; a2bN ; : : : ; a2b2 ; a2b1 ; a2b1 ; : : : ; a2bN ? 1 ; a2bN ; a3b1 ; a3b2 ; : : : ; a3bN ; or a3bN ; a3bN ? 1 ; : : : ; a3b1 ; a4bN ; : : : ; a4b2 ; a4b1 ; a4b1 ; : : : ; a4bN ? 1 ; a4bN ; : : : : : : and if M is odd ends at aMb1 ; aMb2 ; : : : ; aMbN or aMbN ; aMbN ? 1 ; : : : ; aMb1 ; and if M is even ends at aMbN ; : : : ; aMb2 ; aMb1 or aMb1 ; a1b2 ; : : : ; aMbN : On this list successive feasible sets have the form asbt ; asbt +1 or asbt ; as +1 bt and thus have Hamming distance 2 . Thus for given values of i and k , there are two alternative lists . These two lists can be distinguished by their first elements . A -LRB- i ; k ? i -RRB- - list pi ; k?i is first-first if it begins at a1b1 -LRB- i.e. , first -LRB- Hi -LRB- Q -RRB- -RRB- -LSB- first -LRB- Hk?i -LRB- R -RRB- -RRB- ; it is firstlast if it begins at a1bN . The lists can also be distinguished by their last elements . A -LRB- i ; k ? i -RRB- - list is last-last if it ends at aMbN ; it is last-first if it ends at aMb1 . If M is odd , a first-first path is also last-last ; otherwise , it is last-first . We form the path Hk -LRB- P -RRB- by stringing together paths pi ; k?i for all valid values of i , where each pi ; k?i is a path of one of the two types described above , and may appear either in the forward direction or in reverse ; the reverse direction will be denoted with the superscript R. For example , when k < = r < = q , Hk -LRB- P -RRB- = -LRB- pk ; 0 ; -LRB- pk ? 1 ; 1 -RRB- R ; : : : ; p0 ; k if k even , pk ; 0 ; -LRB- pk ? 1 ; 1 -RRB- R ; : : : ; -LRB- p0 ; k -RRB- R if k odd . In order for Hk -LRB- P -RRB- to be a path in J -LRB- P ; k -RRB- , the type of each pi ; k?i -LRB- i.e. , first-first or first-last -RRB- must be selected so that there is Hamming distance 2 in going from one path to the next . For example if pi ; k?i is a first-first path and appears in reverse order in Hk -LRB- P -RRB- , then pi ? 1 ; k?i +1 must be a first-first path . Note that the pi ; k?i 's are not necessarily all of the same type for a given k , because the number M of ideals of size i of Q may be even for some values of i , odd for others . Observe that for any k and i , the type of pi ; k?i can be selected , and that selection determines the type of pj ; k?j for all other valid values of j. Thus we have shown how to construct a set of paths Hk -LRB- P -RRB- with Property 1 ; i.e. , such that each Hk -LRB- P -RRB- is a Hamilton path in J -LRB- P ; k -RRB- for k = ; 1 ; : : : ; n . We now show inductively how to select the types for the paths pi ; k?i in Hk -LRB- P -RRB- so that Properties 2 and 3 are maintained . Initially , H0 -LRB- P -RRB- is the path on one vertex , the empty set . Suppose the paths H0 -LRB- P -RRB- ; H1 -LRB- P -RRB- ; : : : ; Hk -LRB- P -RRB- have been constructed so as to satisfy all three properties . Then Hk +1 -LRB- P -RRB- can be constructed so as to have Properties 2 and 3 in the following way . -LSB- Case where k < r < = q :] Assume for the sake of illustration that k is even ; similar arguments hold when k is odd . Then Hk -LRB- P -RRB- = pk ; 0 ; -LRB- pk ? 1 ; 1 -RRB- R ; : : : ; p0 ; k ; Hk +1 -LRB- P -RRB- = pk +1 ; 0 ; -LRB- pk ; 1 -RRB- R ; : : : ; -LRB- p0 ; k +1 -RRB- R : Note that , regardless of type , D -LRB- first -LRB- pk ; 0 -RRB- ; first -LRB- pk +1 ; 0 -RRB- -RRB- = 1 . If the type of p0 ; k is last-last , then set the type of p0 ; k +1 to be first-last ; otherwise , set it to be first-first . H0 -LRB- Q -RRB- just contains the empty set , so a1 = aM , and D -LRB- first -LRB- H0 -LRB- Q -RRB- -RRB- ; last -LRB- H0 -LRB- Q -RRB- -RRB- -RRB- = : By definition , D -LRB- last -LRB- Hk -LRB- R -RRB- -RRB- ; last -LRB- Hk +1 -LRB- R -RRB- -RRB- -RRB- = 1 : Therefore D -LRB- last -LRB- Hk -LRB- P -RRB- -RRB- ; last -LRB- Hk +1 -LRB- P -RRB- -RRB- -RRB- = 1 : -LSB- Case where r < = k < q :] In this case , the number of paths strung together is r + 1 . Suppose r is even . Then Hk -LRB- P -RRB- = pk ; 0 ; -LRB- pk ? 1 ; 1 -RRB- R ; : : : ; pk?r ; r ; Hk +1 -LRB- P -RRB- = pk +1 ; 0 ; -LRB- pk ; 1 -RRB- R ; : : : ; pk +1 ? r ; r : By a similar argument as given in the first case , D -LRB- first -LRB- Hk -LRB- P -RRB- -RRB- ; first -LRB- Hk +1 -LRB- P -RRB- -RRB- -RRB- = D -LRB- last -LRB- Hk -LRB- P -RRB- -RRB- ; last -LRB- Hk +1 -LRB- P -RRB- -RRB- -RRB- = 1 ; regardless of type . A similar argument holds when r is odd . -LSB- Case r < = q < k :] For q + r ? k even , Hk -LRB- P -RRB- = pq ; k?q ; -LRB- pq ? 1 ; k +1 ? q -RRB- R ; : : : ; pk?r ; r ; Hk +1 -LRB- P -RRB- = -LRB- pq ; k +1 ? q -RRB- R ; pq ? 1 ; k +2 ? r ; : : : ; pk +1 ? r ; r : If pq ; k?q is first-first , set pq ; k +1 ? q to be last-first . It is easy to confirm that Properties 2 and 3 are upheld . A similar argument holds when q + r ? k is odd . This completes the proof . 2 4 The graph G -LRB- L -RRB- ? K2 is Hamiltonian In this section , we show the existence of a certain kind of Gray code for the basic words of an antimatroid . We begin with a definition and two lemmas . Definition 2 For a word , let ? x be the word , where = xfl , or ? x = , if x 62 . Note that if x is an atom that L = fxg = f ? x : 2 Lg . Lemma 3 Let -LRB- E ; L -RRB- be an antimatroid in which the elements of E are fa ; x1 ; x2 ; : : : ; xng where a is an atom . For all 1 < = i < = j < n , if ss = x1 ? ? ? xixi +1 ? ? ? xjaxj +1 ? ? ? xn 2 L ; then ss0 = x1 ? ? ? xiaxi +1 ? ? ? xjxj +1 ? ? ? xn 2 L : Proof : Let H be a alternative precedence mapping for L . Since a is an atom , H -LRB- a -RRB- = f ; g and so a needs no precedent set . For the xl -LRB- 1 < = l < = n -RRB- elements , it is clear that the same precedent constraints met in ss are also met in ss0 . 2 Definition 3 A B-poset is a poset P whose elements can be partitioned into two disjoint chains , x1 OE x2 OE ? ? ? OE xn and y1 OE y2 OE ? ? ? OE ym , such that yj 6 ? xi for all i and j , where 1 < = i < = n and 1 < = j < = m . The following lemma was proved in -LSB- 15 -RSB- . Lemma 4 Let P be a B-poset as defined above and denote < = = x1x2 ? ? ? xny1y2 ? ? ? ym . There is a Hamiltonian cycle in G -LRB- P -RRB- ? K2 which uses the edge -LSB- + < = ; ? <=] . We now give the main theorem of this section . The theorem and proof given here are generalizations of the main theorem and proof in -LSB- 16 -RSB- , which showed the following result for poset antimatroids . Theorem 4 For every antimatroid L , the graph G -LRB- L -RRB- ? K2 is Hamiltonian . Proof : The proof of the theorem is by induction on jEj . For the base cases of the induction , L is the antimatroid on zero or one elements ; in these cases G -LRB- F -RRB- ? K2 is an edge . Suppose jEj > 1 . If L has exactly one atom a , then G -LRB- L -RRB- ? = G -LRB- L = fag -RRB- , and by the inductive hypothesis G -LRB- L = fag -RRB- ? K2 is Hamiltonian . Otherwise , let L have two atoms a and b. By the inductive hypothesis , the graph G -LRB- L = fa ; bg -RRB- ? K2 has a Hamiltonian cycle H1 . Replace each signed basic word + i on H1 with abffi ; replace each basic word ? i with baffi . Call the resulting sequence H2 . By Lemma 3 , both abffi and baffi are basic words of L ; therefore H2 is a cycle 1 ; 2 ; : : : ; M , where M = 2 ? e -LRB- L = fa ; bg -RRB- , in G -LRB- L -RRB- , which visits exactly those basic words in L in which have the prefix ab or ba . For each i = xiyi?i , where fxi ; yig = fa ; bg , let Bi be the poset which consists of the two chains , xiyi and ? i , plus the relations given -LRB- directly or transitively -RRB- by the following rule . For z 2 ~ ? i , where oe and ae are such that ? i = oezae , if xioezyiae 62 L then yi < Bi z ; similarly , if oezxiyiae 62 L then xi < Bi z. Consider a linear extension ! = ffixi yi ffl of Bi . By the construction of Bi , xiffi yiffl 2 L , and ffixiyi ffl 2 L. By Lemma 3 , ! 2 L. Therefore every linear extension of Bi is a basic word of L . We observe also that Bi is a B-poset . Therefore by Lemma 4 , there is a Hamiltonian path through G -LRB- Bi -RRB- ? K2 from + i to ? i . We substitute the occurrence of i with this path in H2 , for each odd i. For each even i , we substitute the reverse of this path for the occurrence of i. Call the resulting walk H. For each Bi , every linear extension of Bi is a basic word of L ; therefore H is a closed walk in G -LRB- L -RRB- ? K2 . To prove that H is a Hamiltonian cycle through G -LRB- L -RRB- ? K2 , it is necessary to show that for each basic word of L , + and ? both occur exactly once on H. Let ? = ? a ? b. Suppose induces the order xy on fa ; bg and the order ? on S -LRB- L -RRB- nfa ; bg . Then xy ? is a basic word of L , and therefore xy ? = i is on the cycle H2 of G -LRB- L -RRB- . Therefore is a linear extension of the Bi , and so both + and ? are on the cycle H. Also , for every other B-poset Bj generated , where j < > i , one of xy or ? is not a subword of Bj , as in that case i = j , which contradicts the construction of H2 . Therefore , each of + and ? are generated exactly once . 2 We call a pair a ; b of elements of E siblings in a language L if for all basic words in L , transposing a and b yields another word in L. Let L + ab denote the language consisting of the words of L in which a precedes b . If L is an antimatroid , then so is L + ab : we may simply add a to each A 2 H -LRB- b -RRB- where H is the alternative precedence function of L , yielding an alternative precedence representation for L + ab . Let G0 -LRB- L -RRB- be the graph with the basic words of L as the vertex set , and such that two basic words are adjacent in G0 -LRB- L -RRB- if they differ by the transposition of two -LRB- not necessarily adjacent -RRB- elements . Thus G0 -LRB- L -RRB- is a supergraph of G -LRB- L -RRB- , on the same vertex set . Corollary 4 If L is an antimatroid with a pair of siblings , then G0 -LRB- L -RRB- is Hamiltonian . Proof : Suppose L has a pair of siblings a ; b. By Theorem 4 , G -LRB- L + ab -RRB- ? K2 is Hamiltonian ; therefore G0 -LRB- L + ab -RRB- ? K2 is Hamiltonian . Note that G0 -LRB- L -RRB- ? = G0 -LRB- L + ab -RRB- ? K2 . Therefore G0 -LRB- L -RRB- is Hamiltonian . 2 It is an open problem to determine whether G -LRB- L -RRB- is Hamiltonian , where L is an antimatroid with a pair of siblings . The graph G -LRB- L -RRB- is bipartite ; therefore applying Theorem 4 and Lemma 1 , we conclude the following corollary , which establishes a Gray Code for basic words of an antimatroid . Corollary 5 For any antimatroid L , there is a listing of the basic words of L such that each word differs from it predecessor in the list by one or two adjacent transpositions . This is the best possible , in that not all antimatroids admit a listing of the basic words such that each differs from its predecessor by one transposition . The seriesparallel poset antimatroid -LRB- 1 ? 1 -RRB- + -LRB- 1 -RRB- ? 1 -RRB- provides such an example . In that case , the difference in the cardinality of the two partite sets of G -LRB- L -RRB- , which quantity we will call the parity difference of L , exceeds one -LRB- i.e. , there are two more odd basic words than even -RRB- , so there can exist no Hamiltonian path or cycle in the basic word graph . The following conjecture of Ruskey -LSB- 19 -RSB- suggests a characterization of the posets which are generable by transpositions . Conjecture 1 For a poset P , if the parity difference of P does not exceed one , then G -LRB- P -RRB- has a Hamilton path ; if the parity difference is zero and G -LRB- P -RRB- has no vertex of degree one , then G -LRB- P -RRB- is Hamiltonian . This conjecture can not be extended to all antimatroids ; an antimatroid with zero parity difference for which G -LRB- L -RRB- has no Hamilton path is shown in Figure 1 . A generation algorithm runs in constant amortized time if its running time is O -LRB- e -RRB- , where e is the number of objects generated . An O -LRB- f -LRB- n -RRB- -RRB- transposition oracle of an antimatroid is an oracle which determines in time O -LRB- f -LRB- n -RRB- -RRB- whether ffxy is a basic word of L , given that ffyxfi is a basic word of L . The algorithm GenLE and the proof of its correctness given in -LSB- 16 -RSB- to generate linear extensions uses only those properties of posets that are shared by all antimatroid languages . The queries to the antimatroid are of the type , \ Is ffxy in L ? '' , where ffyxfi is in L. Therefore , given an antimatroid with an O -LRB- f -LRB- n -RRB- -RRB- transposition oracle , GenLE is a O -LRB- f -LRB- n -RRB- -RRB- amortized time generation algorithm . In particular , we have the following result . s s s s 1 2 3 4 1423 1243 1234 4123 1432 4132 4312 4321 ? ? ? ? @@ @@ Figure 1 : The path P4 , and G -LRB- L -RRB- , where L is the leaf shelling antimatroid for P4 . Theorem 5 Let L be an antimatroid with an O -LRB- 1 -RRB- transposition oracle . Then the basic words of an antimatroid can be generated in constant amortized time , such that each word differs from the next by no more than two transpositions . Clearly poset antimatroids have O -LRB- 1 -RRB- transposition oracles . Another example of an antimatroid with an O -LRB- 1 -RRB- transposition oracle is given below . For a tree G , the leaf shelling sequence of G is a sequence v1 ; v2 ; : : : ; vl , where vi 2 V -LRB- G -RRB- , for all 1 < = i < = l , and vi is a leaf of the subgraph of G which remains when the vertices fv1 ; v2 ; : : : ; vi ? 1g are removed . I.e. , these are ways of removing the vertices of G such that we only ever remove a leaf from the current tree . It is easy to verify that leaf shelling sequences form an antimatroid language . Suppose that ffxy is a leaf shelling sequence of G . If is empty , or if x and y are non-adjacent , then ffyxfi is also a leaf shelling sequence ; otherwise x and y are adjacent , and x and y are not that last two vertices to be removed , so removing y before removing x will disconnect x from the rest of the tree . Therefore ffyxfi is not a shelling sequence . Testing these conditions can be done in time O -LRB- 1 -RRB- , so by Theorem 5 , the complete shelling sequences of a tree -LRB- i.e. , the shelling sequences which contain all the vertices of G -RRB- can be generated in consant amortized time . Chordal graphs admit a decomposition sequence ; i.e. , a sequence vi ; v2 ; : : : ; vn , where for each vi , its neighbourhood in the graph G induced on vi +1 ; vi +2 ; : : : ; vn is a clique . The decomposition sequences of a chordal graph form an antimatroid language . However , a constant time transposition oracle is not known to exist for this language . 5 Final Remarks The remarks at the end of the last section show that there are efficient -LRB- constant amortized time -RRB- algorithms for generating the basic words of an antimatroid ; but what about the efficient generation of feasible sets and , in particular , the ideals of a poset ? Algorithms for generating the ideals of a poset were given by Schrage and Baker -LSB- 20 -RSB- , Lawler -LSB- 12 -RSB- , Ball and Provan -LSB- 1 -RSB- , and Steiner -LSB- 22 -RSB- . The best of these algorithms appears to be that of Steiner , whose running time is O -LRB- n ? i -LRB- P -RRB- -RRB- , where n is the number of elements of the poset and i -LRB- P -RRB- is the number of ideals of P . We have developed an algorithm based on the results of Section 2 whose running time is O -LRB- i -LRB- P -RRB- -RRB- , but only on certain posets ; in the worst case it is also O -LRB- n ? i -LRB- P -RRB- -RRB- , so it remains an open problem to develop a constant amortized time algorithm for generating the ideals of a general poset . Beyer and Ruskey -LSB- 3 -RSB- and Koda and Ruskey -LSB- 9 -RSB- have shown that the ideals of a forest poset could be generated in time O -LRB- i -LRB- P -RRB- -RRB- ; the latter paper contains a \ loopfree '' algorithm . To end the paper we propose two conjectures . Conjecture 2 Let P be a poset and consider the subgraph G of J -LRB- P -RRB- induced by the vertices of J -LRB- P ; k -RRB- -LSB- J -LRB- P ; k +1 -RRB- . The graph G is bipartite , say with bipartition -LRB- A ; B -RRB- . If jAj = jBj then is there a Hamilton cycle in G ? If jAj = jBj + 1 then is there a Hamilton path in G ? We conjecture that the answer is yes in both cases . Note that this conjecture contains the famous \ middle two levels of the boolean algebra lattice problem '' as a special case and so is most likely very difficult -LRB- e.g. , Kierstead and Trotter -LSB- 8 -RSB- or Hurlbert -LSB- 6 -RSB- -RRB- , if indeed it is true . Conjecture 3 For every antimatroid -LRB- E ; F -RRB- and every k , the graph J -LRB- F ; k -RRB- has a Hamilton path . This can not be strengthened to Hamilton cycle since J -LRB- F ; k -RRB- is a path if F is the poset antimatroid of a poset consisting of two disjoint chains . References -LSB- 1 -RSB- M.O. Ball and J.S. Provan , \ Calculating bounds on reachability and connectedness in stochastic networks '' , Networks , 13 -LRB- 1983 -RRB- 253-278 . -LSB- 2 -RSB- J. Bitner , G. Ehrlich , and E. Reingold , \ Efficient Generation of the Binary Reflected Gray Code and its Applications , '' Communications of the ACM , 19 -LRB- 1976 -RRB- 517-521 . -LSB- 3 -RSB- T. Beyer and F. Ruskey , \ Constant Average Time Generation of Subtrees of Bounded Size , '' unpublished manuscript , May , 1989 . -LSB- 4 -RSB- A. Bj?orner and G.M. Ziegler , \ Introduction to Greedoids '' , in Matroid Applications -LRB- ed . N. White -RRB- , Cambridge University Press , 1992 . -LSB- 5 -RSB- G. Ehrlich , \ Loopless Algorithms for Generating Permutations , Combinations , and Other Combinatorial Configurations , '' JACM , 20 -LRB- 1973 -RRB- 500-513 . -LSB- 6 -RSB- G. Hurlbert , \ The antipodal layers problem '' , Discrete Math. , to appear . -LSB- 7 -RSB- J.T. Joichi , D.E. White , and S.G. Willamson , \ Combinatorial Gray Codes , '' SIAM J. Computing , 9 -LRB- 1980 -RRB- 130-141 . -LSB- 8 -RSB- H.A. Kierstead and W.T. Trotter , \ Explicit matchings in the middle levels of the Boolean lattice '' , Order 5 -LRB- 1988 -RRB- 163-171 . -LSB- 9 -RSB- Y. Koda and F. Ruskey , \ A Gray Code for the Ideals of a Forest Poset '' , J. Algorithms , to appear . -LSB- 10 -RSB- B. Korte and L. Lovasz , \ Basis graphs of greedoids and two-connectivity '' , Mathematical Programming Study , 24 -LRB- 1985 -RRB- 158-165 . -LSB- 11 -RSB- B. Korte , L. Lovasz , R. Schrader , Greedoids , Springer-Verlay , 1991 . -LSB- 12 -RSB- E.L. Lawler , \ Eficient implementation of dynamic programming algorithms for sequencing problems '' , Report BW106/79 , Stichting Mathematisch Centrum , Amsterdam , 1979 . -LSB- 13 -RSB- J. Propp , \ Partial Ordering for Matchings of Bipartite Planar Graphs '' , 23rd S.E. Intl. . Conference on Combinatorics , Graph Theory and Computing , 1992 . -LSB- 14 -RSB- G. Pruesse , \ Generating Linear Extensions of Series-Parallel Posets by Transpositions '' , manuscript . -LSB- 15 -RSB- G. Pruesse and F. Ruskey , \ Generating the Linear Extensions of Certain Posets by Transpositions '' , SIAM J. Discrete Math. , 4 -LRB- 1991 -RRB- 413-422 . -LSB- 16 -RSB- G. Pruesse and F. Ruskey , \ Generating Linear Extensions Fast '' , to appear in SIAM J. Computing . -LSB- 17 -RSB- Reingold , Nievergelt , and Deo , Combinatorial Algorithms : Theory and Practice , Prentice Hall , 1977 . -LSB- 18 -RSB- F. Ruskey , \ Generating Linear Extensions of Posets by Transpositions '' , J. Combinatorial Theory -LRB- B -RRB- , 54 -LRB- 1992 -RRB- 77-101 . -LSB- 19 -RSB- F. Ruskey , \ Research Problem 90 '' , Discrete Math. , 70 -LRB- 1988 -RRB- 111-112 . -LSB- 20 -RSB- L. Schrage and K.R. Baker , \ Dynamic programming solution for sequencing problems with precedence constraints '' , Operations Research , 26 -LRB- 1978 -RRB- 444-449 . -LSB- 21 -RSB- G. Stachowiak , \ Hamilton Paths in Graphs of Linear Extensions for Unions of Posets '' , SIAM J. Discrete Math. , 5 -LRB- 1992 -RRB- 199-206 . -LSB- 22 -RSB- G. Steiner , \ An Algorithm to Generate the Ideals of a Partial Order , '' Operations Research Letters , 5 -LRB- 1986 -RRB- 317-320 . -LSB- 23 -RSB- F. Ruskey , \ Listing and Counting Subtrees of a Tree , '' SIAM J. Computing , 10 -LRB- 1981 -RRB- 141-150 . -LSB- 24 -RSB- F. Ruskey , \ Generating Linear Extensions of Posets , '' J. Combinatorial Theory -LRB- B -RRB- , 54 -LRB- 1992 -RRB- 77-101 . -LSB- 25 -RSB- R.P. Stanley , Enumerative Combinatorics , Vol . I. , Wadsworth , 1986 . -LSB- 26 -RSB- H.S. Wilf , Combinatorial Algorithms : An Update , SIAM , CBMS 55 . -LSB- 27 -RSB- G.M. Ziegler , \ Branchings in rooted graphs and the diameter of greedoids '' , Combinatorica , 8 -LRB- 1988 -RRB- 217-234 .

O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O B O O O B O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O B I I O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O B O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O B O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O

antimatroid
basic word graph
hamiltonicity

combinatorial gray code
joindistributive lattice


Report R96 :04 ISRN : SICS-R -- 96/04-SE ISSN : 0283-3638 Compensating for Bias in the SDM Fast Activation Mechanism Roland Karlsson -LRB- roland@sics.se -RRB- RWCP1 Neuro SICS2 Laboratory Box 1263 , S-164 28 Kista , Sweden May 1996 Abstract T he Kanerva Sparse Distributed Memory -LRB- SDM -RRB- is a mechanism for implementing a memory with a huge address space . The physical memory consists of substantially fewer locations than the virtual address space . The plain Kanerva SDM memory assumes address and data to be random bit vectors with equal probability for and 1 . To compensate for any bias in address or data , several more or less elaborate methods can be used . In this paper we describe one simple method for achieving this compensation within the framework of the \ Fast activation Mechanism '' for SDM . Contents 1 Introduction 1 2 Addressing 2 3 Data retrieval 2 4 Compensating for bias in data -LRB- and address -RRB- 3 5 Parallelization 4 6 Conclusions 4 1Real World Computing Partnership 2Swedish Institute of Computer Science 1 Introduction T he Kanerva Sparse Distributed Memory -LRB- SDM -RRB- -LSB- 4 , 5 -RSB- is a clever mechanism for storing/retrieving data in/from a memory with a huge address space . The memory addresses , also called input addresses , are N-bit vectors -LRB- N is generally large -RRB- . The actual memory contains substantially fewer memory locations -LRB- called hard locations -RRB- than there are possible input addresses . When accessing the memory , a number of hard locations \ close to '' the input address are activated . In the basic SDM , each hard location has an N-bit address , and the activation criterion is : \ close '' according to Hamming distance -LRB- i.e. , the number of mismatched address bits -RRB- between the input address and the location 's address . Briefly , the write and read operations work as follow : The contents of a hard location is a vector of integers where each integer corresponds to one bit in the input data . When writing to the memory , the data bits -LRB- from the input data vector -RRB- are added -LRB- adding ? 1 when the data bit is and adding +1 when the data bit is 1 -RRB- to the contents of all activated hard locations . When reading , the content vectors of the activated hard locations are summed and the sum is converted to the output data by some threshold mechanism . The key idea is that data written sufficiently \ far away '' -LRB- i.e. , having few common activated hard locations -RRB- from the address can be considered as noise that will more or less cancel out . Several activation mechanisms have been used , e.g. , Hamming distance or the Jaeckel Selected-Coordinates Design -LSB- 1 , 2 -RSB- . Two papers -LSB- 6 , 7 -RSB- introduced and tested an efficient mechanism for finding the hard locations that are \ close to '' the input address . The proposed mechanism may be viewed as a fast implementation of a restricted Jaeckel design . The plain Kanerva SDM memory performs best if address and data are random bit vectors with equal probability for and 1 . To compensate for any bias in address or data , several more or less elaborate methods can be used . One implementation based on statistical methods is described in -LSB- 3 -RSB- . In this paper we describe one simple method for achieving similar results . 2 Addressing - Input address Activation pattern k 4 , 23 , 37 7 , 12 , 64 ... A aeaeaeae > ???? : ... Table Hard locations 2k M = A ? 2k - oe Data Figure 1 : The fast Selected-Coordinates Design . A table is used in the fast Selected-Coordinates Design -LRB- see Figure 1 -RRB- . The number of entries -LRB- A -RRB- in the table equals the number of desired activations when accessing the memory with an input address . Each entry in the table specifies a subset of k address bits . In the example in Figure 1 the selected address bits for the first table location are 4 , 23 , 37 . On access , the specified bits -LRB- in the input address -RRB- are used as an index to a block of 2k hard locations . In the example this means that 3 bits in the address are used as an index to one of 8 positions in a block . The hard-location memory consists of A such blocks , i.e. , the size of the hard-location memory is therefore M = A ? 2k . 3 Data retrieval Briefly , the write and read operations work as follow : The contents of a hard location is a vector of integers where each integer corresponds to one bit in the input data . When writing to the memory , the data bits -LRB- from the input data vector -RRB- are added -LRB- adding ? 1 when the data bit is and adding +1 when the data bit is 1 -RRB- to the contents of all activated hard locations . When reading , the content vectors of the activated hard locations are summed and the sum is converted to the output data by some threshold mechanism . The key idea is that data written sufficiently \ far away '' -LRB- i.e. , having few common activated hard locations -RRB- from the address can be considered as noise that will more or less cancel out . 4 Compensating for bias in data -LRB- and address -RRB- Input address - Activation pattern k 1 , 4 , 23 , 37 3 , 7 , 12 , 64 ... A Table HHHHj aeaeaeae > Hard locations M = 2k - oe xor bits A - oe Data Figure 2 : The modified Design , compensating for bias in data . If there is some bias in the data -LRB- e.g. , the probability for in data bit 27 is higher than 0.5 -RRB- , then the mean value of the noise -LRB- adding -1 for zeroes and 1 for ones -RRB- will not be zero . Using elaborate statistical methods -LRB- like those in -LSB- 3 -RSB- -RRB- another threshold -LRB- than 0 -RRB- can be found and used . Another possibility is to store the data in the SDM memory without any bias . One obvious method for doing so is to convert data with bias to unbiased data before storing it . This method is somewhat tricky as the converted data must preserve the \ nearness '' property -LRB- similar data must still be similar -RRB- and the conversion may also be required to be reversible . We propose a simpler and more general mechanism , removing the bias when storing in the SDM . The method is based on inverting the data -LRB- when writing and reading -RRB- in such a way that noise -LRB- and only the noise -RRB- is -LRB- with a probability 0.5 -RRB- \ randomly '' inverted . Instead of dividing the hard locations into A blocks , only one block is used . In order to get the same size of the hard location memory , log -LRB- A -RRB- more bits are therefore needed in the activation table . Figure 2 shows the modified implementation . All A activations use the same block -LRB- and some more activation bits -RRB- . For half of the activations , writing/reading to/from the memory is inverted -LRB- all bits in data XOR-ed with or 1 , according to the bit in the XOR table -RRB- . Input address - xor bitmaps A - Activation pattern k 1 , 4 , 23 , 37 3 , 7 , 12 , 64 ... A Table HHHHj aeaeaeae > Hard locations M = 2k - oe xor bits A - oe Data Figure 3 : The modified design , also compenasting for bias in the address . It is possible to further modify this implementation to compensate for bias -LRB- i.e. , clustering -RRB- in the input address . Figure 3 shows how this can be made . The nonuni - form usage of the memory due to clustering is decreased by xoring the input address with random XOR-masks -LRB- one per activation -RRB- before using it . 5 Parallelization The possibility of parallelization of this modified implementation is somewhat constrained . In the original proposal for the fast activation mechanism , the memory could be divided into the activation blocks . This is not a severe problem as it is still possible to parallelize bitwise , which might be to prefer even in the original implementation . 6 Conclusions T he new proposed version of the Kanerva SDM memory is designed to be a simple solution to the problem of biased indata . It is not tested , but there is no reason why it should perform any worse than the original fast SDM implementation . It is somewhat slower , due to the fact that more activation bits are used and inverting of data and address is needed . References -LSB- 1 -RSB- Jaeckel L. A . An Alternative Design for a Sparse Distributed Memory . Technical report , Research Institute for Advanced Computer Science , NASA Ames Research Center , 1989 . -LSB- 2 -RSB- Jaekel L. A . A Class of Designs for a Sparse Distributed Memory . Technical report , Research Institute for Advanced Computer Science , NASA Ames Research Center , 1989 . -LSB- 3 -RSB- Sj?odin G. Improving the Capacity and Capabilities of SDM . SICS Research Report R95 :12 , Swedish Institute of Computer Science , 1995 . -LSB- 4 -RSB- Kanerva P. Sparse Distributed Memory . The MIT Press , 1988 . -LSB- 5 -RSB- Kanerva P. Sparse distributed memory and related models . In Mohamad H. Hassoun , editor , Associative Neural Memories . Oxford University Press , 1993 . -LSB- 6 -RSB- Karlsson R . A Fast Activation Mechanism for the Kanerva SDM Memory . In the Proceedings of the 95 RWC Symposium , RWC Technical Report -LRB- TR-95001 -RRB- , pages 69 -LCB- 70 , Tokyo , June 1995 . -LSB- 7 -RSB- Karlsson R. Evaluation of a Fast Activation Mechanism for the Kanerva SDM Memory . SICS Research Report R95 :10 , Swedish Institute of Computer Science , December 1995 .

O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O