<<

faculty of science MATH 895-4 Fall 2010 department of Course Schedule LECTURE 8 Lexicographic generation Lexicographic generation Week Date Sections Part/ References Topic/Sections Notes/Speaker from FS2009

Contents1 Sept 7 I.1, I.2, I.3 Combinatorial Symbolic methods Structures 2 14 I.4, I.5, I.6 FS: Part A.1, A.2 Unlabelled structures 1 Introduction to generationComtet74 and random generation 1 3 21 II.1, II.2, II.3 Labelled structures I 1.1 Features we mightHandout want#1 in an exhaustive generation ...... 1 4 1.228 WhatII.4, aboutII.5, II.6 random(self study) generation?Labelled . structures . . . . II ...... 1 Combinatorial Combinatorial 5 Oct 5 III.1, III.2 Asst #1 Due 2 Lexicographic rankingparameters and unrankingParameters 2 FS A.III 6 2.112 BinaryIV.1, IV.2 strings(self-study) ...... Multivariable . . . . .GFs ...... 3 2.2 Bijection to ...... 3 7 19 IV.3, IV.4 Analytic Methods Complex Analysis 2.3 k-subsets . .FS: . .Part . B: . IV, . .V, VI ...... 3 8 26 Appendix B4 Singularity Analysis IV.5 V.1 Stanley 99: Ch. 6 9 Nov 2 Asst #2 Due Handout #1 Asymptotic methods 1 Introduction9 VI.1 (self-study) to generation andSophie random generation 10 12 A.3/ C Introduction to Prob. Mariolys Two things we might want to do given a combinatorial class A would be to generate all elements of An or to generate18 IX.1 a random element of AnLimit. Laws and Comb Marni 11 What20 doesIX.2 it meanRandom to generate Structures somethingDiscrete Limit Laws at random?Sophie For a combinatorial class A, we want to describe a process (e.g.and algorithm) Limit Laws that takes as input n, and outputs an object α from A such that any FS: Part C Combinatorial 23 IX.3 1 Mariolys (rotating element12 has probability A of being generated.instances of discrete We call this Uniform generation. presentations)n 25 IX.4 Continuous Limit Laws Marni

1.1 Features we might wantQuasi-Powers in an and exhaustive generation algorithm 13 30 IX.5 Sophie Gaussian limit laws • We might want to be able to generate the elements of An sequentially, so that we can step from 14 Dec 10 Presentations Asst #3 Due one to the next. That is we might want a successor function which takes one element of An and gives the next one in the order. This is useful if we want to iterate through all elements of An and do something with each one.

• Given an object in An we might want to be able to determine the position of this object in the order, that is we might want a ranking function. We also might want to be able to determine the element in position i, that is we might want an unranking function

We would want to be able to do these things efficiently.

Dr. Marni MISHNA, Department of Mathematics, SIMON FRASER UNIVERSITY Definition.Version of: 11-Dec-09Let S be a finite . A rank function is a bijection rank : S → {0, 1,..., |S| − 1}

The corresponding unrank function is the inverse bijection

unrank : {0, 1,..., |S| − 1} → S

So rank(s) = i if and only if unrank(i) = s. If we have a good unranking function we can generate a random element by first generating a random element of {0,..., kS| − 1} and then unranking. If we have a good ranking and unranking function we can generate a successor function by successor(c) = unrank(rank(c) + 1). In both cases other approaches might be more efficient.

1.2 What about random generation? Why would we want to do random generation? • To get a sense of what the objects in a given class “look” like on average: estimate parameters like average depth of a ; average number of cycles in a etc. • To test a hypothesis about the class using an experimental method;

MARNI MISHNA,SPRING 2011; KAREN YEATS,SPRING 2013 MATH343:APPLIED DISCRETE MATHEMATICS PAGE 1/5 faculty of science MATH 895-4 Fall 2010 department of mathematics Course Schedule LECTURE 8 Lexicographic generation

Week Date Sections Part/ References Topic/Sections Notes/Speaker • To feedfrom as FS2009 input into an algorithm to test the algorithm.

1 A randomSept 7 I.1,labelled I.2, I.3 Combinatorial binary tree on 200Symbolic nodes: methods Structures 2 14 I.4, I.5, I.6 FS: Part A.1, A.2 Unlabelled structures Comtet74 3 21 II.1, II.2, II.3 Labelled structures I Handout #1 4 28 II.4, II.5, II.6 (self study) Labelled structures II

Combinatorial Combinatorial 5 Oct 5 III.1, III.2 Asst #1 Due parameters Parameters FS A.III 6 12 IV.1, IV.2 (self-study) Multivariable GFs

7 19 IV.3, IV.4 Analytic Methods Complex Analysis FS: Part B: IV, V, VI 8 26 Appendix B4 Singularity Analysis IV.5 V.1 Stanley 99: Ch. 6 9 Nov 2 Asst #2 Due Handout #1 Asymptotic methods 9 VI.1 (self-study) Sophie Hallmarks10 of a good random generation scheme 12 A.3/ C Introduction to Prob. Mariolys Correct Each element of size n is generated with equal probability. 18 IX.1 Limit Laws and Comb Marni 11 Efficient20 HowIX.2 long doesRandom it Structures take to generateDiscrete Limit an Laws elementSophie of size n as a function of n? and Limit Laws FS: Part C Combinatorial Space23 EfficiencyIX.3 How much space does it take to generateMariolys an element (rotating 12 instances of discrete presentations) Ease of25 implementationIX.4 How long wouldContinuous it Limit take Laws toMarni actually code the algorithm?

Quasi-Powers and Re-usability13 30 IX.5 Are there optimizations possible if I amSophie going to run the algorithm multiple times? Gaussian limit laws

Generalizability14 Dec 10 Is this partPresentations of a wider framework, orAsst simply #3 Due an adhoc solution applicable to a single problem?

Strategies 1. Consider simple models like binary strings, and make a direct argument; 2. Reduce the random generation to a very simple model via a bijection; 3. Surjective method: Find a simpler class that is in a k to one correspondence– uniform generation is still preserved; Dr. Marni MISHNA, Department of Mathematics, SIMON FRASER UNIVERSITY Version of: 11-Dec-09 4. Ranking/unranking: Order all An elements. Generate uniformly a random number k between 1 and An, and determine the k-th element. 5. Rejection method: Generate a larger set and then filter the output; 6. Recursive method: Decompose the object by the counting probabilities 7. Markov method: use Markov chains; 8. ...

2 Lexicographic ranking and unranking

(see Donald Kreher and Douglas Stinson, Combinatorial , chapter 2 for a reference on this material)

Definition. Let A = (a1, a2, . . . , an) and B = (b1, b2, . . . , bm) be distinct lists of integers. A < B in lexicographic order, if a1 = b1, . . . , ak−1 = bk−1 and either ak < bk or n = k − 1 and m ≥ k. For example (1, 2, 2) < (2, 1), (1, 2, 2) < (1, 3, 1), (1, 2, 2) < (1, 2, 2, 1). This is the usual dictionary ordering on words using on the letters (hence the name). If we can represent our combinatorial objects as lists, then we can use lexicographic order to order them, and from that get successor, rank, and unrank functions.

MARNI MISHNA,SPRING 2011; KAREN YEATS,SPRING 2013 MATH343:APPLIED DISCRETE MATHEMATICS PAGE 2/5 faculty of science MATH 895-4 Fall 2010 department of mathematics Course Schedule LECTURE 8 Lexicographic generation

Week Date Sections Part/ References Topic/Sections Notes/Speaker 2.1 Binaryfrom FS2009 strings

Binary1 Sept strings 7 I.1, I.2, are I.3 simpleCombinatorial enough to directlySymbolic methods do random generation. Let us represent a binary string of Structures length2 14n by anI.4, I.5, array I.6 ofFS: length Part A.1, A.2n with entriesUnlabelled structures 0 or 1. Assume we have a random number generator. Comtet74 Maple 3 21 II.1, II.2, II.3 Labelled structures I > R:=rand(0..1); #Handout picks #1 a random integer in the range 0..1, i.e. picks 0 or 1 >4 Bin:=28 proc(n)II.4, II.5, II.6 (self study) Labelled structures II > for i from 1 toCombinatorial n do : Combinatorial 5 Oct 5 III.1, III.2 Asst #1 Due > A[i]:= R();parameters Parameters FS A.III >6 12 od; IV.1, IV.2 (self-study) Multivariable GFs > return (seq(A[i], i=1..10)); >7 end19 proc;IV.3, IV.4 Analytic Methods Complex Analysis FS: Part B: IV, V, VI 8 26 Appendix B4 Singularity Analysis IV.5 V.1 Stanley 99: Ch. 6 n 9 EachNov 2 string has probability (0.5) of being generated,Asst #2 soDue it is uniform. There is one call made for Handout #1 Asymptotic methods each n9, so weVI.1 say that(self-study) it is linear in n. It is quite easySophie to implement, as we see. 10Binary strings can also be lexicographically ordered since they are lists of 0s and 1s. It will be handiest12 if weA.3/ C do reverse lexicographicIntroduction order to (so Prob. startMariolys at the right), because then lexicographic order corresponds18 IX.1 exactly to the order givenLimit by interpretingLaws and Comb Marni the binary string as a binary number. Conceptu- 11 ally ranking20 IX.2 and unrankingRandom Structures is just convertingDiscrete Limit from Laws a binarySophie string to a binary number and back. and Limit Laws So we have FS: Part C Combinatorial 23 IX.3 Mariolys (rotating Algorithm: RankBin 12 instances of discrete input: n (length ofpresentations) word), w (word) r = 025 IX.4 Continuous Limit Laws Marni for i from 1 to n Quasi-Powers and 13 30 IX.5 Sophie if w(i) = 1 Gaussian limit laws 14 rDec = 10 r+2ˆi Presentations Asst #3 Due output: r Algorithm: UnrankBin input: n (length of word), r (rank) for i from 1 to n if r is congruent to 1 mod 2 b(i) = 1 r = floor(r/2) output: b

Dr. Marni MISHNA, Department of Mathematics, SIMON FRASER UNIVERSITY Version of: 11-Dec-09 2.2 Bijection to subsets Now, let us apply a bijection. Let S be a set of size n. Imagine we want to generate a of S such that every subset is equally probable. How do we do it? Let us use a bijection to binary strings:

1. Order all elements: S = {s1, s2, . . . , sn};

2. Generate a random binary string β = (β1, β2, . . . , βn)

3. Create the subset {si : βi = 1}.

2.3 k-subsets In the language of subsets it is natural to ask about ranking/unranking/randomly generating subsets of size k of {1, . . . , n}. We can also give these a lexicographic order, for example, list the elements of the subset from smallest to largest, and then use lexicographic order on these lists. For example the subsets of size 3 of {1, 2, 3, 4, 5} in this order are

{1, 2, 3}, {1, 2, 4}, {1, 2, 5},{1, 3, 4}, {1, 3, 5}, {1, 4, 5} {2, 3, 4}, {2, 3, 5},{2, 4, 5}, {3, 4, 5}

Using this we can get a successor function

MARNI MISHNA,SPRING 2011; KAREN YEATS,SPRING 2013 MATH343:APPLIED DISCRETE MATHEMATICS PAGE 3/5 faculty of science MATH 895-4 Fall 2010 department of mathematics Course Schedule LECTURE 8 Lexicographic generation

Week Date Sections Part/ References Topic/Sections Notes/Speaker from FS2009 Algorithm: SuccessorkSubset input: L (current k subset as a list in increasing order), k, n 1 Sept 7 I.1, I.2, I.3 Symbolic methods Lnew = L Combinatorial Structures i2 = k14 I.4, I.5, I.6 FS: Part A.1, A.2 Unlabelled structures Comtet74 while3 21 (i >=II.1, II.2, 1) II.3 and (L(i) = n-k+i)Labelled structures I Handout #1 i=i-1 4 28 II.4, II.5, II.6 (self study) Labelled structures II if i=0 Combinatorial Combinatorial 5returnOct 5 noIII.1, successorIII.2 (L was the last in the order)Asst #1 Due parameters Parameters else FS A.III 6for12 j fromIV.1, IV.2 i to k(self-study) Multivariable GFs Lnew(j) = L(i) + 1 + j - i 7 19 IV.3, IV.4 Analytic Methods Complex Analysis return Lnew FS: Part B: IV, V, VI 8 26 Appendix B4 Singularity Analysis IV.5 V.1 Stanley 99: Ch. 6 9 Nov 2 Asst #2 Due To rank and unrankHandout we need#1 to countAsymptotic how methods many elements preceed a given one. Namely we need 9 VI.1 (self-study) Sophie 10 Proposition.12 A.3/ CLet {n1, . . . , nk} ⊆ {1, 2,Introduction . . . , n} with to Prob.n1

18 IX.1 Limit Laws and Comb Marni k ni−1   11 X X n − j 20 IX.2 Random Structures rankDiscrete(L) Limit = Laws Sophie and Limit Laws k − i i=1 j=n +1 FS: Part C Combinatorial i−1 23 IX.3 Mariolys (rotating 12 instances of discrete n−(npresentations)i+`) Proof.25ThereIX.4 are k−i−1 k-subsetsContinuous (as lists Limit in Laws increasingMarni order) beginning with n1, n2, . . . ni, `. For ` < ni+1 all such subsets preceed L in lexicographic order. Summing these completes the proof. Quasi-Powers and 13 30 IX.5 Sophie Gaussian limit laws From this we have 14 Dec 10 Presentations Algorithm: RankkSubsetAsst #3 Due input: L (current k subset as a list in increasing order), k, n r = 0 L(0) = 0 for i from 1 to k if L(i-1)+1 <= L(i)-1 for j from L(i-1)+1 to L(i)-1 r = r + binom(n-j,k-i) output: r Algorithm: UnrankkSubset Dr. Marni MISHNA, Department of Mathematics, SIMON FRASER UNIVERSITY Versioninput: of: 11-Dec-09 r (rank), k, n j = 1 for i from 1 to k while binom(n-j,k-i) <= r r = r - binom(n-j,k-i) j = j+1 T(i) = j j = j+1 output: T

Successor is O(k) in the worst case, and the other two algorithms are each O(n) in the worst case. We can do better and rank in O(k). What we need to do is use the reverse lexicographic order again. Call this the corank, and apply it to lists in decreading order

Proposition. Let {n1, . . . , nk} ⊆ {1, 2, . . . , n} with n1 < n2 < ··· < nk. Write L = (nk, . . . , n1). Then

k   X nk−i+1 − 1 corank(L) = k − i + 1 i=1

nk−i+1−1 Proof. There are k−i+1 lists which begin with nk, nk−1, . . . , nk−i+2 and have all remaining elements less than nk−i+1. All of these lists comes before L in the order, and so summing we get the result.

MARNI MISHNA,SPRING 2011; KAREN YEATS,SPRING 2013 MATH343:APPLIED DISCRETE MATHEMATICS PAGE 4/5 faculty of science MATH 895-4 Fall 2010 department of mathematics Course Schedule LECTURE 8 Lexicographic generation

Week Date Sections Part/ References Topic/Sections Notes/Speaker Proposition.fromLet FS2009{n1, . . . , nk} ⊆ {1, 2, . . . , n} with n1 < n2 < ··· < nk. Let L = (n1, n2, . . . , nk) and L˜ = (n + 1 − n1, n + 1 − n2, . . . , n + 1 − nk). Then 1 Sept 7 I.1, I.2, I.3 Combinatorial Symbolic methods Structures 2 14 I.4, I.5, I.6 FS: Part A.1, A.2 Unlabelled structures n Comtet74 rank(L) + corank(L˜) = − 1 3 21 II.1, II.2, II.3 Labelled structures I Handout #1 k 4 28 II.4, II.5, II.6 (self study) Labelled structures II Proof. Suppose (n1, n2, . . . , nk) < (m1, m2, . . . , mk) in lexicographic order, then (n+1−n1, . . . , n+1−nk) > Combinatorial Combinatorial 5 Oct 5 III.1, III.2 Asst #1 Due (n + 1 − m1, . . . , n + 1 −parametersmk) in lexicographicParameters order. So given L, for every other k-subset M either L > M or L˜ > M˜ . Therefore rankFS A.III(L) + corank(L˜) equals the number of k-subsets other than L itself. 6 12 IV.1, IV.2 (self-study) Multivariable GFs

7 From19 thisIV.3, we IV.4 can buildAnalytic Methods Complex Analysis FS: Part B: IV, V, VI Algorithm: Rank2kSubset 8 26 Appendix B4 Singularity Analysis input: L (currentIV.5 V.1 k subset as a list in increasing order), k, n Stanley 99: Ch. 6 9 Nov 2 Asst #2 Due r = 0 Handout #1 Asymptotic methods L(0)9 = 0 VI.1 (self-study) Sophie for10 i from 1 to k r =12 r +A.3/ binom(n-L(i), C k+1-i) Introduction to Prob. Mariolys output:18 binom(n,k)IX.1 - 1 - r Limit Laws and Comb Marni 11 20 IX.2 Random Structures Discrete Limit Laws Sophie and Limit Laws FS: Part C Combinatorial This23 algorithmIX.3 is O(k). Mariolys (rotating 12 instances of discrete presentations) Exercise.25 CanIX.4 you make a similar Unrank2kSubsetContinuous Limit Laws Marni? What is its runtime?

Quasi-Powers and 13 30 IX.5 Sophie Gaussian limit laws

14 Dec 10 Presentations Asst #3 Due

Dr. Marni MISHNA, Department of Mathematics, SIMON FRASER UNIVERSITY Version of: 11-Dec-09

MARNI MISHNA,SPRING 2011; KAREN YEATS,SPRING 2013 MATH343:APPLIED DISCRETE MATHEMATICS PAGE 5/5