Fast Algorithms to Generate Necklaces, Unlabeled Necklaces, and Irreducible Polynomials Over GF(2)

Total Page:16

File Type:pdf, Size:1020Kb

Fast Algorithms to Generate Necklaces, Unlabeled Necklaces, and Irreducible Polynomials Over GF(2) Journal of Algorithms 37, 267᎐282Ž. 2000 doi:10.1006rjagm.2000.1108, available online at http:rrwww.idealibrary.com on Fast Algorithms to Generate Necklaces, Unlabeled Necklaces, and Irreducible Polynomials over GFŽ. 2 1 Kevin Cattell HP Research Labs, Santa Rosa, California E-mail: kevin᎐ [email protected] Frank Ruskey, Joe Sawada, and Micaela Serra Department of Computer Science, Uni¨ersity of Victoria, Victoria, British Columbia, Canada E-mail: [email protected]; [email protected], [email protected] and C. Robert Miers Department of Mathematics and Statistics, Uni¨ersity of Victoria, Victoria, British Columbia, Canada E-mail: [email protected] Received August 22, 1998 Many applications call for exhaustive lists of strings subject to various con- straints, such as inequivalence under group actions. A k-ary necklace is an equivalence class of k-ary strings under rotationŽ. the cyclic group . A k-ary unlabeled necklace is an equivalence class of k-ary strings under rotation and permutation of alphabet symbols. We present new, fast, simple, recursive algo- rithms for generatingŽ. i.e., listing all necklaces and binary unlabeled necklaces. These algorithms have optimal running times in the sense that their running times are proportional to the number of necklaces produced. The algorithm for generat- ing necklaces can be used as the basis for efficiently generating many other equivalence classes of strings under rotation and has been applied to generating bracelets, fixed density necklaces, and chord diagrams. As another application, we describe the implementation of a fast algorithm for listing all degree n irreducible and primitive polynomials over GFŽ. 2 . ᮊ 2000 Academic Press 1 Research supported by NSERC. 267 0196-6774r00 $35.00 Copyright ᮊ 2000 by Academic Press All rights of reproduction in any form reserved. 268 CATTELL ET AL. 1. INTRODUCTION Four of the most natural group actions on strings over a fixed alphabet are:Ž. a leaving the string unchanged, Ž. b reversing the string, Ž. c rotating the string, andŽ. d permuting the symbols of the string by a permutation of the alphabet symbols. The four groups giving rise to these actions areŽ. a ޚ ޚ ރ 12,bŽ.acting on the indices Ž reversal .Ž. , c the cyclic n acting on the ޓ indices, andŽ. d the symmetric group k acting on the alphabet, assuming the alphabet consists of k symbols. Each group action, or composition of group actions, partitions the set of k-ary strings into equivalence classes, namely the orbits of the action. Many applications call for exhaustive lists of representatives of these equivalence classes. To generate such equivalence classes, it is natural to choose as representative the lexicographically smallest string. With this representation, efficient algorithms are known for generating the equiva- lence classes of each of the actionsŽ.Ž.Ž. a , b , c , and Ž. d . By ‘‘efficient’’ we mean that the amount of computation used in generating the objects is proportional to the number of objects generated. Such algorithms are said to be CAT, for constant amortized time. ForŽ. a we are simply counting in base k which is known to be efficient for k G 2. ForŽ. b efficient algorithms are easily developed. In case Ž. c the equivalence classes are usually called necklaces. Efficient algorithms for generating necklaces were developed by Fredricksen and Kesslerwx 5 and Fredricksen and Maioranawx 6 ; these algorithms were proven to be efficient by Ruskey et al wx20 . Closely related algorithms for generating Lyndon wordsŽ. aperiodic necklaces were developed by Duvalwx 3 and shown to be efficient by Berstel and Pocchiolawx 1 . In caseŽ. d the representative strings are usually called restricted growth functions and efficient algorithms for generating them have been developed by Erwx 4 , Kaye w 12 x , and others. In addition to these four natural group actions considered in isolation, interesting equivalence classes also emerge by composing two or more of the group actions. For example, composingŽ. b and Ž. c results in the dihedral groups, with the resulting equivalence classes often called bracelets. Only recentlyŽ. using the framework outlined in this paper Sawadawx 23 developed an algorithm to generate k-ary bracelets in constant amortized time. Proskurowski et al.wx 17 show that the orbits of the composition ofŽ. b and Ž. d can be generated in amortized Ok Ž' .time, which is CAT if k is fixed. It remains an interesting challenge to develop efficient algorithms for the other compositions. In this paper we present a new recursive framework for necklace generation. We then use this framework to develop a CAT algorithm to generate equivalence classes of the complemented cycling registerŽ which GENERATING UNLABELED NECKLACES 269 are in one-to-one correspondence with vortex-free tournaments. We also use this framework to develop a CAT algorithm for generating unlabeled binary necklacesŽ. and Lyndon words , i.e., the composition of Ž.Ž. c and d for k s 2. This algorithm was used in the implementation of a fast algorithm for listing all degree n irreducible polynomials over GFŽ. 2 . The framework has also been used to efficiently generate other classes of strings as summarized below. Undoubtedly, other applications of the framework will also be discovered. ⅷ Necklaces: Done in this paper, CAT algorithm. ⅷ Vortex-free tournaments: Done in this paper, CAT algorithm. ⅷ Binary unlabeled necklaces: Done in this paper, CAT algorithm. ⅷ Irreducible polynomials over GFŽ. 2 : Done in this paper. ⅷ Fixed density necklaces: Done in Ruskey and Sawadawx 21 , CAT algorithm. ⅷ Bracelets: Done in Sawadawx 23 , a CAT algorithm. ⅷ Chord diagramsŽ i.e., 2n points on an oriented circle embedded in the plane joined pairwise by chords. : to appear. ⅷ Necklaces with forbidden substrings: Done in Ruskey and Sawada wx22 , CAT algorithm if the forbidden substring is a Lyndon word. ⅷ A basis for the nth homogeneous component of the free Lie algebra: to appear. The combinatorial objects which we are listing are fundamental and there is considerable interest in having efficient algorithms to generate them. This interest comes from mathematicians, computer scientists, electrical engineers, and scientists in other disciplines. Our algorithms have all been implemented and are used in the Combinatorial Object ServerŽ. COS at http:rr www.theory.csc.uvic.car˜cos in the sections on Necklaces and Irre- ducible Polynomials over GFŽ. 2 . 1.1. Background and Definitions def ⌺ s y ⌺n Defining the alphabet kkÄ40, 1, . , k 1 , the set consists of all ; ⌺U k-ary strings of length n. Define an equivalence relation on k by ␣ ; ␤ ¨ g ⌺q ␣ s ¨ ␤ s ¨ if and only if there exist u, k such that u and u. The equivalence classes of ; are called necklaces and we identify each necklace with the lexicographically least representative in its equivalence class. The set of all necklaces of length n over a k-ary alphabet is denoted NkŽ.n . def s ␣ g ⌺n < ␣ F ␤ ␣ ; ␤ NkkŽ.n Ä4for all Ž.1 270 CATTELL ET AL. s For example N2Ž.4 Ä40000, 0001, 0011, 0101, 0111, 1111 . The cardinality ␣ s иии ␴␣ of NkkŽ.n is denoted Nn Ž.. For a string aa12 an, let Ž .denote a ␣ ␴ иии s иии left shift of by one position: Ž.aa12 an a2 aan 1. In an unlabeled necklace we do not care about which color a bead has, but only about whether two beads have different colors. Unlabeled neck- laces 0001 and 0111 are identical since one can be transformed into the other by interchanging 0 and 1 at every position of the string. Formally, the set NkŽ.n of all k-ary length n unlabeled necklaces is defined as follows: def s ␣ g ¬ ␣ F ␴␲␣i ᭙␲ g ޓ - - Nˆ kkŽ.n Ä4N Ž.n Ž. Ž . kand 0 i n .2 Ž. s For example, Nˆˆ2Ž.4 Ä40000, 0001, 0011, 0101 . As before,, we denote NnkŽ. s < < Nˆ kŽ.n . A string ␣ is periodic if ␣ s ␤ k where ␤ is nonempty and k ) 0. An aperiodic necklace is called a Lyndon word. The set of all k-ary Lyndon words of length n is denoted L kŽ.n . defs ␣ g ¬ ␣ L kkŽ.n Ä4N Ž.n is aperiodic s For example, L 2Ž.4 Ä40001, 0011, 0111 . The cardinality of L kŽ.n is de- noted LnkŽ.. An unlabeled Lyndon word is an aperiodic unlabeled necklace. The set of all k-ary length n unlabeled Lyndon words is denoted ˆL kŽ.n with s cardinality LnˆˆkŽ.. For example, L 2 Ž.4 Ä40001, 0011 . A word ␣ is called a prenecklace if it is the prefix of some necklace. The set of all k-ary prenecklaces of length n is denoted PkŽ.n . def s ␣ g ⌺nm¬ ␣␤ g q G ␤ g ⌺ PkkkŽ.n Ä4N Žn m .for some m 0 and k s j For example P22Ž.4 N Ž.4 Ä40010, 0110 . The cardinality of PkŽ.n is denoted PnkkŽ.. Let Wn Ž.denote the number of prenecklaces of length at most n. These numbers will prove useful in analyzing the algorithms developed below. Formally, n defs q WnkkŽ.1 Ý Pi Ž..3 Ž. is1 We denote unlabeled prenecklaces PˆˆkkŽ.n with cardinality Pn Ž.. def s ␣ g ⌺nm¬ ␣␤ g q G ␤ g ⌺ PˆˆkkkŽ.n Ä4N Žn m .for some m 0 and k GENERATING UNLABELED NECKLACES 271 THEOREM 1.1. The following formulae are ¨alid for all n G 1, k G 1: 11 s ␮ n r dnˆ s ␮ r d Lnk Ž.ÝÝ Ž.dk , Ln2 Ž. Ž.d 2, Ž. 4 n dn<<2n odd dn 11 s ␾ n r dnˆ s y ␾ r d Nnk Ž.ÝÝ Ž.dk , Nn22 Ž.Nn Ž. Ž.d 2,5 Ž. n dn<<2n odd dn nn s ˆˆs PnkkŽ .ÝÝLi Ž., Pn22 Ž .Li Ž..6 Ž.
Recommended publications
  • Polynomial Statistics, Necklace Polynomials, and the Arithmetic Dynamical Mordell-Lang Conjecture By
    Polynomial Statistics, Necklace Polynomials, and the Arithmetic Dynamical Mordell-Lang Conjecture by Trevor Hyde A dissertation submitted in partial fulfillment of the requirements for the degree of Doctor of Philosophy (Mathematics) in The University of Michigan 2019 Doctoral Committee: Professor Jeffrey Lagarias, Co-Chair Professor Michael Zieve, Co-Chair Professor Kartik Prasanna Professor John Schotland Professor John Stembridge Trevor Hyde [email protected] ORCID 0000-0002-9380-1928 © Trevor Hyde 2019 Dedication This thesis is dedicated to Aarthi and my parents Steve and Kathy. Thank you for all the years of unwavering love and support. ii Acknowledgments The author is grateful for the guidance and encouragement of his advisers Jeff Lagarias and Mike Zieve. I am also happy to thank Weiyan Chen, Benson Farb, Nir Gadish, Jonathan Gerhard, Ofir Gorodetsky, Rafe Jones, Bob Lutz, Andy Odesky, Karen Smith, Sheila Sundaram and Phil Tosteson for their help with and interest in my work over the past six years. The author was supported by NSF grant DMS-1162181 in the summer of 2017, the Rackham One-Term Dissertation Fellowship in the winter of 2017, the NSF grant DMS- 1701576 in the summer of 2018, and the Rackham Predoctoral Fellowship for the 2018-19 academic year. iii List of Figures 4.1 2-colorings of S3............................... 96 4.2 All primitive 2-colorings of S3........................ 96 iv List of Tables 2.1 Expected values of quadratic excess. 20 3.1 Low degree terms of M3;n¹qº......................... 35 3.2 First moments of linear factor statistic. 39 v Table of Contents Dedication . ii Acknowledgements .
    [Show full text]
  • APPLICATIONS of M¨OBIUS INVERSION on PARTIALLY ORDERED SETS Contents 1. Introduction 1 2. Basic Definitions for Partially Order
    APPLICATIONS OF MOBIUS¨ INVERSION ON PARTIALLY ORDERED SETS DAVID WU Abstract. In this paper, we discuss how the theory of partially ordered sets plays an important role in combinatorics. First, we outline definitions for partially ordered sets. Next, we introduce incidence algebra and M´obiusin- version. Then, we present three applications of partially ordered set theory: the Inclusion-Exclusion Principle, Euler's Totient function (or phi function), and P´olya's Enumeration Theorem. For P´olya's Enumeration Theorem, we assume prior knowledge of basic group theory. Contents 1. Introduction 1 2. Basic Definitions for Partially Ordered Sets (Posets) 2 3. Incidence Algebra 3 4. Applications of M¨obiusinversion 5 4.1. Inclusion-Exclusion Principle 6 4.2. Classical M¨obiusFunction 7 5. P´olya's Enumeration Theorem 9 5.1. A Galois connection between permutations and partitions 10 5.2. Generating Functions 11 5.3. Proof of P´olya's Enumeration Theorem 13 5.4. Examples with Necklaces 16 Acknowledgments 18 References 18 1. Introduction Many problems in combinatorics deal with counting a particular combinatorial object. A common strategy is to construct an algebraic object to do this counting (ex. generating functions). In this paper, the combinatorial object of interest is the partially ordered set, and the algebraic object we use is incidence algebra. In particular, we are most interested in the Kronker delta, zeta, and M¨obiusfunction in incidence algebra. These functions give rise to a technique called the M¨obius inversion formula, a counting tool with far-reaching applications. In section 2, we begin by introducing preliminary definitions for partially ordered sets.
    [Show full text]
  • Basic Counting
    CHAPTER 1 Basic Counting Introduction Before beginning, we must confront some matters of notation. Two words that we shall often use are set and list. Both words refer to collections of objects. There is no standard notation for lists. Some of those in use are apple banana pear peach a list of four items ... apple, banana, pear, peach commas added for clarity ... and (apple, banana, pear, peach) parentheses added. The notation for sets is standard: the items are separated by commas and surround by curly brackets as in {apple, banana, pear, peach}. The curly bracket notation for sets is so well established that you can normally assume it means a set—but beware, Mathematica R uses curly brackets for lists. What is the difference between a set and a list? Quite a bit, and nothing. “Set” means a collection of distinct objects in which the order doesn’t matter. Thus {apple, peach, pear} and {peach, apple, pear} are the same sets, and the set {apple, peach, apple} is the same as the set {apple, peach}. In other words, repeated elements are treated as if they occurred only once. Thus two sets are the same if and only if each element that is in one set is in both. In a list, order is important and repeated objects are usually allowed. Thus (apple, peach) (peach, apple) and (apple, peach, apple) are three different lists. Two lists are the same if and only if they have exactly the same items in exactly the same positions. Thus, sets and lists are different. On the other hand, people talk about things like “unordered lists,” “sets with repetition,” and so on.
    [Show full text]
  • Number of Necklaces Number of Bracelets Necklace Example
    From Wikipedia, the free encyclopedia In combinatorics, a k-ary necklace of length n is an equivalence class of n-character strings over an alphabet of size k, taking all rotations as equivalent. It represents a structure with n circularly connected beads of up to k different colors. A k-ary bracelet, also referred to as a turnover (or free) necklace, is a necklace such that strings may also be equivalent under reflection. That is, given two strings, if each is the reverse of the other then they belong to the same equivalence class. For this reason, a necklace might also be called a fixed necklace to distinguish it from a turnover necklace. Technically, one may classify a necklace as an orbit of the action of the cyclic group on n-character strings, and a bracelet as an orbit of the dihedral group's action. This enables application of Pólya enumeration theorem for enumeration of necklaces and bracelets. 1 Equivalence classes Possible patterns of bracelets of length n 1.1 Number of necklaces corresponding to the k-th integer partition 1.2 Number of bracelets 2 Examples (set partitions up to rotation and reflection) 2.1 Necklace example 2.2 Bracelet example 3 Aperiodic necklaces 4 Products of necklaces 5 See also 6 References 7 External links The 3 bracelets with 3 red and 3 green beads. The one in the middle is chiral, so there are 4 necklaces. Compare box(6,9) in the triangle. Number of necklaces There are different k-ary necklaces of length n, where φ is Euler's [1] totient function.
    [Show full text]
  • Witt Vectors and the Algebra of Necklaces*
    View metadata, citation and similar papers at core.ac.uk brought to you by CORE provided by Elsevier - Publisher Connector ADVANCES IN MATHEMATICS s&95-125 (1983) Witt Vectors and the Algebra of Necklaces* N. METROPOLIS Los Alamos National Laboratory, Los Alamos, New Mexico 87545 AND GIAN-CARLO ROTA+ Massachusetts Institute of Technology, Cambridge, Massachusetts 02139, and Los Alamos National Laboratory, Los Alamos, New Mexico 87545 Contents. 1. Introduction. 2. Words and primitive words. 3. Main results. 4. The Necklace ring. 5. Necklaces and placements. 6. Unital rational functions. 7. Carryless Witt vectors. 8. The Witt ring. 1. INTRODUCTION Given a set of a colors, a necklace is the result of placing n colored beads around a circle. A necklace which is asymmetric under rotation is said to be primitive. The number M(a, n) of primitive necklaces is computed by a formula that goes back to Col. Moreau of the French Army, to wit, where ,U is the classical Mobius function; M(a, n) is called a necklace polynomial. We shall be concerned with some remarkable identities satisfied by the polynomials M(a, n), which apparently have not been previously noticed. Specifically, we prove that M(a/?, n) can be expressed as a quadratic polynomial in M(a, i) and M&j), and generalized to more variables; that M(a’, n) can be expressed linearly and integrally in terms of M(a, i). The proofs given below of these identities are entirely combinatorial (Theorems l-6). * This work was performed under the auspices of the U.S. Department of Energy.
    [Show full text]
  • Circular and Necklace Permutations
    Circular and Necklace Permutations Hiroshi KAJIMOTO and Mai OSABE Department of Mathematical Science, Faculty of Education Nagasaki University, Nagasaki 852-8521, Japan e-mail: [email protected] (Received October 31, 2006) Abstract We enumerate circular and necklace permutations which have beads of several colors, and count the related combinatorial numbers. 0 Introduction Circular and necklace permutations are standard subjects of high school com- binatorics. On the other hand they serve a good introduction to more ad- vanced subject of combinatorics, that is the P´olya theory of counting under group action. In fact these enumerations were historically a precursor of the theory [2, 4, p.558]. In this article we give the enumeration of circular and necklace permuations according to the given number of beads for each colors, and of the related combinatorial numbers. A circular permutation is defined to be an equivalence class of sequences under the cyclic group Cn, i.e., two sequences a1a2 : : : an and b1b2 : : : bn are equivalent if one is a cyclic shift of the other. A necklace (or necklace permu- tation) is defined to be an equivalence class of sequences under the dihedral group Dn, i.e., two sequences a1a2 : : : an and b1b2 : : : bn are equivalent if one is a cyclic shift of the other or if circular permutaions of them are mutually reflective with respect to some diameter. We make full use of the counting theory and look back the classical ex- amples, and show how to use P´olya's cycle index efficiently. We use combi- natorial notation, especially relative to partitions, as in [4].
    [Show full text]