Generating All Circular Shifts by Context-Free Grammars in Chomsky Normal Form

Similar documents
Generating All Circular Shifts by Context-Free Grammars in Greibach Normal Form

Generating All Permutations by Context-Free Grammars in Chomsky Normal Form

Generating All Permutations by Context-Free Grammars in Chomsky Normal Form

A Fuzzy Approach to Erroneous Inputs in Context-Free Language Recognition

Left-Forbidding Cooperating Distributed Grammar Systems

Math 324 Summer 2012 Elementary Number Theory Notes on Mathematical Induction

Congruence Classes of 2-adic Valuations of Stirling Numbers of the Second Kind

Isomorphisms between pattern classes

Definitions. Notations. Injective, Surjective and Bijective. Divides. Cartesian Product. Relations. Equivalence Relations

Spanning and Independence Properties of Finite Frames

Section 1 (closed-book) Total points 30

Blackhole Pushdown Automata

Basic counting techniques. Periklis A. Papakonstantinou Rutgers Business School

2 Lecture 2: Logical statements and proof by contradiction Lecture 10: More on Permutations, Group Homomorphisms 31

MINIMAL GENERATING SETS OF GROUPS, RINGS, AND FIELDS

Independence of certain quantities indicating subword occurrences

Parikh s theorem. Håkan Lindqvist

c 1998 Society for Industrial and Applied Mathematics Vol. 27, No. 4, pp , August

FINITE ABELIAN GROUPS Amin Witno

Aperiodic languages and generalizations

Topological groups with dense compactly generated subgroups

chapter 12 MORE MATRIX ALGEBRA 12.1 Systems of Linear Equations GOALS

Theory of Computation 1 Sets and Regular Expressions

2. Prime and Maximal Ideals

arxiv: v2 [math.nt] 4 Jun 2016

IMA Preprint Series # 2066

Solutions to odd-numbered exercises Peter J. Cameron, Introduction to Algebra, Chapter 3

Introduction to Kleene Algebras

Series of Error Terms for Rational Approximations of Irrational Numbers

NOTES ON FINITE FIELDS

and this makes M into an R-module by (1.2). 2

ALGEBRA. 1. Some elementary number theory 1.1. Primes and divisibility. We denote the collection of integers

Introduction to Metalogic 1

Permutation groups/1. 1 Automorphism groups, permutation groups, abstract

How to Pop a Deep PDA Matters

Lecture Notes 1 Basic Concepts of Mathematics MATH 352

Generalized Pigeonhole Properties of Graphs and Oriented Graphs

Grammars (part II) Prof. Dan A. Simovici UMB

THE ABSOLUTE MORDELL-LANG CONJECTURE IN POSITIVE CHARACTERISTIC. 1. Introduction

Boolean Algebras. Chapter 2

Part V. 17 Introduction: What are measures and why measurable sets. Lebesgue Integration Theory

arxiv:math/ v1 [math.co] 2 Oct 2002

ON HIGHLY PALINDROMIC WORDS

0 Sets and Induction. Sets

Continued fractions for complex numbers and values of binary quadratic forms

Languages, regular languages, finite automata

arxiv: v1 [math.co] 3 Nov 2014

CHAPTER 0 PRELIMINARY MATERIAL. Paul Vojta. University of California, Berkeley. 18 February 1998

Insertion operations: closure properties

Hanoi Graphs and Some Classical Numbers

CPS 220 Theory of Computation

Set theory and topology

Context-Free and Noncontext-Free Languages

Power of controlled insertion and deletion

Application of Logic to Generating Functions. Holonomic (P-recursive) Sequences

Linear conjunctive languages are closed under complement

A NOTE ON RETRACTS AND LATTICES (AFTER D. J. SALTMAN)

Context Free Grammars

Lecture Notes on Inductive Definitions

Algebras with finite descriptions

Topology Proceedings. COPYRIGHT c by Topology Proceedings. All rights reserved.

Computing the rank of configurations on Complete Graphs

Chapter 1. Measure Spaces. 1.1 Algebras and σ algebras of sets Notation and preliminaries

Some decision problems on integer matrices

Automorphism groups of wreath product digraphs

Pushdown Automata (2015/11/23)

Coloring k-trees with forbidden monochrome or rainbow triangles

NONABELIAN GROUPS WITH PERFECT ORDER SUBSETS

Theory of Computation

CS481F01 Prelim 2 Solutions

Löwenheim-Skolem Theorems, Countable Approximations, and L ω. David W. Kueker (Lecture Notes, Fall 2007)

Measures. 1 Introduction. These preliminary lecture notes are partly based on textbooks by Athreya and Lahiri, Capinski and Kopp, and Folland.

Notes on ordinals and cardinals

11 Division Mod n, Linear Integer Equations, Random Numbers, The Fundamental Theorem of Arithmetic

PALINDROMIC AND SŪDOKU QUASIGROUPS

GROUPS. Chapter-1 EXAMPLES 1.1. INTRODUCTION 1.2. BINARY OPERATION

Mathematical Logic (IX)

Ramsey Theory. May 24, 2015

A product of γ-sets which is not Menger.

ON PARTITIONS SEPARATING WORDS. Formal languages; finite automata; separation by closed sets.

Posets, homomorphisms and homogeneity

Finite Presentations of Pregroups and the Identity Problem

Prime and irreducible elements of the ring of integers modulo n

Supplementary Notes on Inductive Definitions

Yunhi Cho and Young-One Kim

Combinatorial Interpretations of a Generalization of the Genocchi Numbers

(1) A frac = b : a, b A, b 0. We can define addition and multiplication of fractions as we normally would. a b + c d

SUBLATTICES OF LATTICES OF ORDER-CONVEX SETS, III. THE CASE OF TOTALLY ORDERED SETS

A Hilton-Milner-type theorem and an intersection conjecture for signed sets

Continuity. Chapter 4

Chap. 7 Properties of Context-free Languages

The commutation with ternary sets of words

Definitions, Theorems and Exercises. Abstract Algebra Math 332. Ethan D. Bloch

Parity Versions of 2-Connectedness

Gaussian Random Fields

A LOWER BOUND FOR THE SIZE OF A MINKOWSKI SUM OF DILATES. 1. Introduction

Newton, Fermat, and Exactly Realizable Sequences

Isotropic matroids III: Connectivity

Discrete Mathematics: Lectures 6 and 7 Sets, Relations, Functions and Counting Instructor: Arijit Bishnu Date: August 4 and 6, 2009

MATH 324 Summer 2011 Elementary Number Theory. Notes on Mathematical Induction. Recall the following axiom for the set of integers.

Transcription:

Generating All Circular Shifts by Context-Free Grammars in Chomsky Normal Form Peter R.J. Asveld Department of Computer Science, Twente University of Technology P.O. Box 217, 7500 AE Enschede, the Netherlands e-mail: infprja@cs.utwente.nl Abstract Let {a 1,a 2,...,a n } be an alphabet of n symbols and let C n be the language of circular shifts of the word a 1 a 2 a n ; so C n = {a 1 a 2 a n 1 a n, a 2 a 3 a n a 1,...,a n a 1 a n 2 a n 1 }. We discuss a few families of context-free grammars G n (n 1) in Chomsky normal form such that G n generates C n. The grammars in these families are investigated with respect to their descriptional complexity, i.e., we determine the number of nonterminal symbols ν(n) and the number of rules π(n) of G n as functions of n. These ν and π happen to be functions bounded by low-degree polynomials, particularly when we focus our attention to unambiguous grammars. Finally, we introduce a family of minimal unambiguous grammars for which ν and π are linear. Keywords: context-free grammar, Chomsky normal form, permutation, circular shift, descriptional complexity, unambiguous grammar. 1 Introduction In [2] we considered context-free grammars G n (n 1) in Chomsky normal form that generate the finite language L n consisting of all permutations over the alphabet Σ n = {a 1, a 2,...,a n }. A few families {G n } n 1 of such grammars for {L n } n 1 have been studied in [2] with respect to their grammatical complexity; more precisely, the number of nonterminal symbols ν(n) and the number of production rules π(n) of G n have been determined as functions of n. In this paper we restrict ourselves to a subset of specific permutations over Σ n, viz. to the so-called circular or cyclic shifts. Assuming a linear order on Σ n, e.g., a 1 < a 2 < < a n, the set C n of circular shifts (also called cyclic shifts) over Σ n is

2 Peter R.J. Asveld C n = {a 1 a 2 a n 1 a n, a 2 a 3 a n a 1, a 3 a 4 a 1 a 2,...,a n a 1 a n 2 a n 1 }. So C n is obtained from the word a 1 a 2 a n by repetitively moving the first symbol to the right-hand end of the string. Clearly, C n contains n strings, which is much less than the n! elements of L n [7, 12]. Considered as a set of permutations of a 1 a 2 a n the set C n forms a cyclic subgroup of order n of the symmetric group S n over Σ n (i.e., the group of all permutations over the alphabet Σ n ). And there are (n 1)! of such isomorphic subgroups of order n of S n, each of which is induced by a linear order a 1 < a p(2) < a p(3) < < a p(n) on Σ n, where p is a permutation of 2, 3,..., n; cf. also the notion of circular successor in Section 2 below, and 6.1 of [7]. As in [2] we will discuss some families of grammars {G n } n 1 in Chomsky normal form for {C n } n 1 and investigate the descriptional complexity of these G n s in terms of the complexity measures ν(n) and π(n). Contrary to the families in [2] where the complexity measures ν(n) and π(n) were bounded by exponential functions, in this paper these measures are bounded by polynomial functions of low degree. The structure of this paper resembles the one of [2] to some extent. So firstly, in Section 2 we consider some preliminaries on notation and terminology. Section 3 is devoted to some elementary properties of grammars G n in Chomsky normal form that generate C n. Section 4 consists of a direct approach based on the set of (circularly) ordered strings over the terminal alphabet Σ n of G n. In Section 5 we consider a slight modification of this family which results in a family of context-free grammars in Chomsky normal form with less productions than the ones in Section 4 (provided n 3). Section 6 is devoted to unambiguous grammars (in Chomsky normal form) for C n ; these grammars turn out to be rather simple in terms of the descriptional complexity measures ν(n) and π(n). In Section 7 we consider a family of unambiguous grammars in Chomsky normal form that is minimal with respect to the descriptional complexity measures ν(n) and π(n) in an obvious sense. For this minimal family of grammars, these complexity measures turn out to be linear functions in n. Finally, Section 8 contains some concluding remarks. 2 Preliminaries We assume the reader to be familiar with the rudiments of discrete mathematics, especially with combinatorics; for standard texts on these subjects we refer to [7, 12]. For a finite set X, we denote the cardinality (the number of elements) of X by #X. Basic concepts, terminology and notation from formal language theory can be found in e.g. [9]. We will denote the empty word by λ. As usual, the length of the word x will be denoted by x. For each word w over Σ, we denote by A(w) the set of all symbols from Σ that really do occur in w. Formally, A(λ) =, and A(ax) = {a} A(x) for each a Σ and x Σ. This mapping is extended to languages L over Σ by A(L) = {A(w) w L}. Recall that a λ-free context-free grammar G = (V, Σ, P, S) is in Chomsky normal form if P N (N {S}) 2 N Σ where N = V Σ. For each context-free grammar G = (V, Σ, P, S), let L(G, A) be the language over Σ defined by L(G, A) = {w Σ A w}.

Generating All Circular Shifts 3 Thus for the language L(G) generated by G, we have L(G) = L(G, S). Note that, if G is in Chomsky normal form, then L(G, A) is a nonempty language for each A in N. Throughout this paper, we use Σ n to denote an alphabet of n different symbols a 1, a 2,...,a n (n 1) provided with the linear order a 1 < a 2 < < a n. In [2] subsets of Σ n and the power set of Σ n played a principal part in generating all permutations by context-free grammars in Chomsky normal form. However, in generating all circular shifts we need (sets of) subwords of a 1 a 2 a n a 1 a n 1. Intuitively, Fk n is the set of all subwords of length k (1 k n) that obey the circular succession relation on Σ n defined by: a i a j if and only if either (i) i < n and j = i + 1 or (ii) i = n and j = 1. Note that is not a transitive relation; as its name suggests it is rather a kind of successor relation. Returning to the definition of Fk n, we formally define for each k (1 k n), the set Fk n by F n k = {x Σ n u, v Σ n : uxv = a 1a 2 a n a 1 a 2 a k 1 ; x = k} and the partial unions Q n m by Q n m = m k=1 F n k (1 m n). Then we obviously have C n = F n n = Q n n Q n n 1, #F n k = n (1 k n), #Qn m = mn and #C n = #F n n = n; note that #Qn n #Qn n 1 = n2 (n 1)n = n as well. Example 2.1. For n = 3, we have Σ 3 = {a 1, a 2, a 3 }, F1 3 = Σ 3, F2 3 = {a 1 a 2, a 2 a 3, a 3 a 1 } and F3 3 = C 3 = {a 1 a 2 a 3, a 2 a 3 a 1, a 3 a 1 a 2 }. Clearly, L 3 C 3 = {a 1 a 3 a 2, a 2 a 1 a 3, a 3 a 2 a 1 }. Finally, we remark that C n can also be characterized in terms of the circular closure operator c on languages which is defined by c(l) = {w 2 w 1 w 1 w 2 L} for each language L [6]. Then C n can be written as C n = c({a 1 a 2 a n }). 3 Elementary Properties In this section we first recall some properties of grammars that generate L n (the finite language of all permutations over Σ n ). From [2] we quote the following results. Proposition 3.1. Let G n = (V n, Σ n, P n, S n ) is a context-free grammar in Chomsky normal form that generates L n, and let N n be defined by N n = V n Σ n. (1) For each nonterminal A in N n, the language L(G n, A) is a nonempty subset of an isomorphic copy M k of the language L k for some k (1 k n). Consequently, each string z in L(G n, A) has length k, z consists of k different symbols, and A(z) = A(L(G n, A)). (2) Let A and B be nonterminal symbols in N n. If L(G n, A) L(G n, B), then A(L(G n, A)) = A(L(G n, B)). (3) If A BC is a rule in G n, then A(L(G n, B)) A(L(G n, C)) = and A(L(G n, B)) A(L(G n, C)) = A(L(G n, A)). Proposition 3.1(2) suggested the following equivalence relation on N n : A and B from N n are called equivalent if x = y for some x L(G n, A) and some y L(G n, B). The corresponding equivalence classes are {E n,k } n k=1. Thus N n is the union of the n equivalence

4 Peter R.J. Asveld classes E n,1, E n,2,, E n,n with E n,i E n,j = for i j. The number of elements #E n,k of the equivalence class E n,k will be denoted by D(n, k) (1 k n) in the sequel. Example 3.2. Consider Σ 3 = {a 1, a 2, a 3 } and the grammar G P 3 = (V 3, Σ 3, P 3, A 123 ) with V 3 = {A 123, A 12, A 13, A 23, A 1, A 2, A 3 } and P 3 consists of A 123 A 1 A 23 A 2 A 13 A 13 A 2 A 23 A 1 A 3 A 12, A 12 A 1 A 2 A 2 A 1, A 13 A 1 A 3 A 3 A 1, A 23 A 2 A 3 A 3 A 2, A 1 a 1, A 2 a 2 and A 3 a 3. Then L(G P 3 ) = L 3, E 3,3 = {A 123 }, E 3,2 = {A 12, A 13, A 23 }, E 3,1 = {A 1, A 2, A 3 }, and hence D(3, 3) = 1 and D(3, 2) = D(3, 1) = 3. In the proof of Proposition 3.1 we only used the fact that each word in L(G n ) is a permutation [2]. So if we require that G n generates C n rather than L n, Proposition 3.1 still applies. Next we will see what happens when we restrict our attention to circular shifts rather than to arbitrary permutations over Σ n ; cf. Proposition 3.4 for which we need the following auxiliary result. Lemma 3.3. Let X be a nonempty proper subalphabet of Σ n with #X = l (1 l < n). Then there exists at most one word x with A(x) = X such that x satisfies the circular succession relation. And if X = {b 1, b 2,...,b l }, then x = b p(1) b p(2) b p(l) provided there exists a permutation p of {1, 2,..., l} such that b p(1) b p(2) b p(l). Proof. If X = {b}, then x = b and the statement holds trivially. In case X consists of l (2 l < n) elements we check whether we can find a permutation p of {1, 2,..., l} such that b p(1) b p(2) b p(l). If we succeed, then x = b p(1) b p(2) b p(l) is the only word that satisfies the circular succession relation, since l < n. If such a permutation does not exist, then there is no such x. Proposition 3.4. Let G n = (V n, Σ n, P n, S n ) be a context-free grammar in Chomsky normal form that generates C n, and let N n be defined by N n = V n Σ n. (1) For each A in N n {S n }, the language L(G n, A) is a singleton. (2) Let A and B be nonterminal symbols in N n {S n }. If L(G n, A) L(G n, B), then L(G n, A) = L(G n, B). (3) If A BC is a rule in G n, with L(G n, B) = {b 1 b 2 b k } and L(G n, C) = {c 1 c 2 c l }, then b k c 1. Consequently, if L(G n, B) Fk n and L(G n, C) Fl n, then L(G n, A) Fk+l n. Proof. (1) Since G n is in Chomsky normal form, each nonterminal A is useful: so there is a derivation S n ϕaψ + ϕx A ψ + x where x is a circular shift, ϕψ λ, A(x) = Σ n, and A(x A ) is a nonempty proper subalphabet of Σ n. Hence, by Lemma 3.3, L(G n, A) contains at most one word over Σ n, and as L(G n, A) is nonempty, L(G n, A) is a singleton. Now (2) is a direct consequence of (1), Proposition 3.1(2) and Lemma 3.3. Finally, (3) easily follows from Proposition 3.1(3) and Lemma 3.3. Example 3.5. Consider the context-free grammar G 3 = (V 3, Σ 3, P 3, S 3 ) with V 3 = {S 3, A 12, A 23, A 31, A 1, A 2, A 3 } and P 3 consists of S 3 A 12 A 3 A 23 A 1 A 31 A 2, A 12 A 1 A 2, A 13 A 1 A 3, A 23 A 2 A 3, A 1 a 1, A 2 a 2 and A 3 a 3.

Generating All Circular Shifts 5 Then L(G 3 ) = C 3, E 3,3 = {S 3 }, E 3,2 = {A 12, A 23, A 31 }, E 3,1 = {A 1, A 2, A 3 }, and hence D(3, 3) = 1 and D(3, 2) = D(3, 1) = 3. As S 3 A 23 A 1 is in P 3, L(G 3, A 23 ) = {a 2 a 3 }, L(G 3, A 1 ) = {a 1 } and a 3 a 1. For a context-free grammar G n we use as descriptional complexity measures the number ν(n) of nonterminal symbols and the number π(n) of production rules of G n ; so ν(n) = #N n and π(n) = #P n. As in [2] we will view both ν and π as functions of n. For a more general and thorough treatment of descriptional complexity issues in relation to contextfree grammars and their languages we refer to [8, 10, 11, 5, 3, 1, 4]. In [2] we also introduced another descriptional complexity measure, viz. the total number of left-most derivations δ(n), i.e., δ(n) = #{S n L x x L(G n)}, where L denotes the leftmost derivation relation. Clearly, this measure makes sense when we generate a finite language by means of a grammar with bounded ambiguity. Example 3.6. (1) For the grammar G P 3 of Example 3.2, we have ν P(3) = 7, π P (3) = 12 and δ P (3) = 3! = 6, since G P 3 is unambiguous [2]. (2) Similarly, for the unambiguous grammar G 3 of Example 3.5, we have ν(3) = 7, π(3) = 9 and δ(3) = 3. When we consider a family of grammars {G n } n 1 for {C n } n 1 in the sequel, we always assume that the first element G 1 = (V 1, Σ 1, P 1, S 1 ) satisfies N 1 = {S 1 } and P 1 = {S 1 a 1 }. Then ν(1) = π(1) = δ(1) = 1 whereas for n 2, ν(n) = n k=1 D(n, k) n+1, π(n) n+2 and δ(n) n. 4 A Straightforward Approach According to the previous section an obvious way to generate the language C n is to provide G n with nonterminal symbols A x such that if x = k < n, then L(G n, A x ) = {x} with x Q n n 1 and A x E n,k. The words from C n = Q n n Q n n 1 are treated differently: they should be derived from S n. So there are productions S n A x A y for all nonempty words x and y with xy C n, while E n,n = {S n }. Definition 4.1. The family {G 0 n } n 1 is given by {(V n, Σ n, P n, S n )} n 1 with for n 2, N n = V n Σ n = {S n } {A x x Q n n 1}, P n = {S n A x A y xy C n ; x, y Σ + n } {A xy A x A y xy Q n n 1; x, y Σ + n } {A a a a Σ n }. Of course, S n is the only nonterminal from G 0 n that generates more than a single string provided n 2. Viz. #L(G 0 n, S n) = #C n = n and #L(G 0 n, A) = 1 for each A in N n {S n }; cf. Proposition 3.4. In the sequel we will slightly change our notation in order to reduce the number of subscript levels: if x = a j a k, we will write A j k for A x instead of A aj a k ; cf. Examples 3.2 and 3.5 above. In this way the set of indices {1, 2,..., n} inherits the linear order of the alphabet Σ n ; a similar remark applies with respect to the -relation. Example 4.2. For n = 3, Definition 4.1 yields the grammar G 0 3 = (V 3, Σ 3, P 3, S 3 ) with

6 Peter R.J. Asveld N 3 = {S 3, A 12, A 23, A 31, A 1, A 2, A 3 } and P 3 = {S 3 A 1 A 23 A 12 A 3 A 2 A 31 A 23 A 1 A 3 A 12 A 31 A 2, A 12 A 1 A 2, A 23 A 2 A 3, A 31 A 3 A 1, A 1 a 1, A 2 a 2, A 3 a 3 }. Now E 3,3 = {S 3 }, E 3,2 = {A 12, A 23, A 31 }, E 3,1 = {A 1, A 2, A 3 }, D(3, 3) = 1 and D(3, 2) = D(3, 1) = 3. Thus ν 0 (3) = 7, π 0 (3) = 12 and δ 0 (3) = 6. Proposition 4.3. For the family {G 0 n} n 1 of Definition 4.1 we have (1) D(n, n) = 1 and D(n, k) = n with 1 k < n, (2) ν 0 (n) = n 2 n + 1, (3) π 0 (n) = 1 2 n3 1 2 n2 + n, (4) δ 0 (1) = 1 and for n 2, δ 0 (n) = n 2 n. Proof. The definitions of N n and P n in Definition 4.1 imply that for n 2, ν 0 (n) = #N n = 1 + #Q n n 1 = 1 + (n 1)n = n 2 n + 1, while π 0 (n) = h 0 (n) + h 1 (n) + h 2 (n) with h 0 (n) = #{S n A x A y xy C n ; x, y Σ + n }, h 1 (n) = #{A xy A x A y xy Q n n 1 ; x, y Σ+ n }, and h 2 (n) = #{A a a a Σ n }. Clearly, h 0 (n) = n(n 1) and h 2 (n) = n, whereas h 1 (n) = n 1 k=2 (k 1) n = 1n(n 1)(n 2). 2 Consequently, π 0 (n) = n(n 1) + 1n(n 1)(n 2) + n = 1 2 2 n3 1 2 n2 + n. G n generates n strings, each of which can be obtained (by a left-most derivation) in n 1 ways provided n 2; hence δ 0 (n) = n(n 1). 5 An Improvement The family {G 1 n} n 1 to be introduced in this section, is obtained from {G 0 n} n 1 by reducing the number of rules in the following way. If A BC is a production of G 1 n, then we restrict the form of this rule by requiring that L(G 1 n, B) = {x} with x = 1. This idea originates from generating L n by regular grammars; cf. [2] for details and examples. Definition 5.1. The family {G 1 n} n 1 is given by {(V n, Σ n, P n, S n )} n 1 with for n 2, N n = V n Σ n = {S n } {A x x Q n n 1 }, P n = {S n A x A y xy C n ; x Σ n } {A xy A x A y xy Q n n 1 ; x Σ n, y Σ + n } {A a a a Σ n }. Example 5.2. In case n = 3 we obtain from Definition 5.1 the grammar G 1 3 = (V 3, Σ 3, P 3, S 3 ) with N 3 = {S 3, A 12, A 23, A 31, A 1, A 2, A 3 } and P 3 = {S 3 A 1 A 23 A 2 A 31 A 3 A 12, A 12 A 1 A 2, A 23 A 2 A 3, A 31 A 3 A 1, A 1 a 1, A 2 a 2, A 3 a 3 }. Again we have E 3,3 = {S 3 }, E 3,2 = {A 12, A 23, A 31 }, E 3,1 = {A 1, A 2, A 3 }, D(3, 3) = 1, D(3, 2) = D(3, 1) = 3 and ν 1 (3) = 7. But now π 1 (3) = 9 and δ 1 (3) = 3. Proposition 5.3. For the family {G 1 n } n 1 of Definition 5.1 we have (1) D(n, n) = 1 and D(n, k) = n with 1 k < n, (2) ν 1 (n) = n 2 n + 1,

Generating All Circular Shifts 7 (3) π 1 (n) = n 2, (4) δ 1 (n) = n. Proof. As in the proof of Proposition 4.3 we still have for n 2, ν 1 (n) = n 2 n + 1. Again we write π 1 (n) for n 2 as π 1 (n) = h 0 (n) + h 1 (n) + h 2 (n) with h 0 (n) = #{S n A x A y xy C n ; x Σ n }, h 1 (n) = #{A xy A x A y xy Q n n 1 ; x Σ n, y Σ + n }, and h 2 (n) = #{A a a a Σ n }. Then still we have h 2 (n) = n, but now h 0 (n) = n and h 1 (n) = #(Q n n 1 F1 n ) = #Q n n 1 #F 1 n = n(n 1) n = n2 2n. Hence π 1 (n) = n + n 2 2n + n = n 2. Again, the grammars G 1 n generate n strings, but now there is only a single (left-most) derivation for each word in L(G 1 n ); therefore we have δ 1(n) = n. Although the number of nonterminal symbols did not change (viz. ν 1 (n) = ν 0 (n)), we have improved upon the number of production rules. In this regard the G 1 n s are superior to the G 0 n s of Definition 4.1, because for n 3, we have the strict inequality π 1 (n) = n 2 < 1 2 n3 1 2 n2 + n = π 0 (n). 6 Families of Unambiguous Grammars In the previous section we saw that the family {G 1 n} n 1 is a slight improvement upon {G 0 n } n 1; so it might be considered as a first step toward a family {G n } n 1 of minimal grammars. When we discuss minimality of grammars, the first question is: With respect to which measure are the G n s minimal? Obvious candidates are, of course, the measures ν, π or δ, but also combined measures as the sum or the product of ν and π (or any monotonically increasing function in ν and π) may be considered as well. Comparing Definitions 4.1 and 5.1 together with Propositions 4.3 and 5.3, suggests that the first step toward a family of minimal grammars is to avoid ambiguity or, equivalently, to require that δ(n) = n. Lemma 6.1. Let {G n } n 1 be a family of grammars in Chomsky normal form that generates the language family {C n } n 1. If δ(n) = n, then π(n) = ν(n) + n 1. Proof. As G n is in Chomsky normal form, each nonterminal is useful. Thus for each A in N n {S n } there is at least one production. By Proposition 3.4(1), we have #L(G n, A) = #{x A } = 1. So assuming that there is more than one rule for A in P n yields two or more left-most derivations for x A. Since these derivations of x A are used as left-most subderivations of some x in C n, there are two or more left-most derivations of x; hence δ(n) > n. Consequently, for each A in N n {S n }, there is exactly one rule in P n. For S n we have that n rules are necessary and sufficient to generate the n words of C n = L(G n, S n ) because δ(n) = n. Hence π(n) = ν(n) 1 + n. Note that this result applies to {G 1 n} n 1 but not to {G 0 n} n 1 ; cf. Propositions 4.3 and

8 Peter R.J. Asveld 5.3. However, {G 1 n} n 1 is not the only family satisfying this equality; viz. Definition 6.2. The family {G 2 n } n 1 is given by {(V n, Σ n, P n, S n )} n 1 with N 2 = V 2 Σ 2 = {S 2, A 1, A 2 } and P 2 = {S 2 A 1 A 2 A 2 A 1, A 1 a 1, A 2 a 2 }, and for n 3, N n = V n Σ n = {S n } {A a a Σ n } {A x x F n 2 } M n with for m 2, M 2m = {A x x F 2m 2m 2 F 2m 2m 4 F 2m 2 }, and M 2m 1 = {A x x F 2m 1 2m 3 F 2m 1 2m 5 F 2m 1 3 }, P n = {S n A x A y xy C n ; x F n 2 } {A xy A x A y A xy M n, x F n 2 } {A xy A x A y xy F n 2, x, y Σ n} {A a a a Σ n }. If A BC is a rule in G 1 n, then L(G 1 n, B) consists of a single string of length one; in G 2 n we have L(G2 n, B) = {w B} with w B = 2. Example 6.3. For the case n = 5 we obtain from Definition 6.2 the grammar G 2 5 = (V 5, Σ 5, P 5, S 5 ) with N 5 = {S 5, A 1, A 2, A 3, A 4, A 5, A 12, A 23, A 34, A 45, A 51 } M 5 with M 5 = {A 123, A 234, A 345, A 451, A 512 }, and P 5 = {S 5 A 12 A 345 A 23 A 451 A 34 A 512 A 45 A 123 A 51 A 234, A 123 A 12 A 3, A 234 A 23 A 4, A 345 A 34 A 5, A 451 A 45 A 1, A 512 A 51 A 2, A 12 A 1 A 2, A 23 A 2 A 3, A 34 A 3 A 4, A 45 A 4 A 5, A 51 A 5 A 1, A 1 a 1, A 2 a 2, A 3 a 3, A 4 a 4, A 5 a 5 }. The equivalence classes are E 5,5 = {S 5 }, E 5,4 =, E 5,3 = {A 123, A 234, A 345, A 451, A 512 }, E 5,2 = {A 12, A 23, A 34, A 45, A 51 } and E 5,1 = {A 1, A 2, A 3, A 4, A 5 }. Now we have ν 2 (5) = 16 < 21 = ν 1 (5) and π 2 (5) = 20 < 25 = π 1 (5) which indicates that {G 1 n } n 1 is not minimal. In order to show the next results concisely we need a function that indicates whether its argument is even or odd: we will use the binary mod-operation. This operation should not be confused with the congruence relation a b (mod m). Proposition 6.4. For the family {G 2 n } n 1 of Definition 6.2, we have (1) D(n, n) = 1, D(n, 1) = D(n, 2) = n, and for 3 k < n, D(n, k) = if k n (mod 2) then n else 0, (2) ν 2 (1) = 1 and for n 2, ν 2 (n) = 1 2 n2 + 1 n (n mod 2) + 1, 2 (3) π 2 (n) = 1 2 n2 + n + 1 n (n mod 2), 2 (4) δ 2 (n) = n. Proof. From Definition 6.2, Proposition 6.4(1) easily follows. Then for even n with n 3, we have ν 2 (n) = 1 + 2n + n 2 k=4 D(n, k) = 1 + 2n + 1(n 4)n = 1 2 2 n2 + 1. For odd n with n 3, this yields ν 2 (n) = 1 + 2n + n 2 k=3 D(n, k) = 1 + 2n + 1(n 3)n = 1 2 2 n2 + 1n + 1. 2

Generating All Circular Shifts 9 Combining these two cases results in ν 2 (n) = 1 2 n2 + 1 n (n mod 2) + 1 for n 3. Finally, 2 Lemma 6.1 implies Proposition 6.4(3). From Propositions 5.3 and 6.4 it follows that for n 4, we have ν 1 (n) > ν 2 (n) and, consequently, π 1 (n) > π 2 (n); for smaller values of n we have equality in both cases. Of course, we may proceed in this way by defining families {G k n} n 1 (k 3) with the property that if A BC is a rule of G k n, then L(Gk n, B) consists of a single word of length k. However, the definitions of such families become more complicated as k increases (cf. Definitions 6.2 and 5.1) and, in addition, we have to define the grammars G k 1, Gk 2,...,Gk k explicitly (e.g., in terms of G j i for some j < k). And probably we are still left with ν k(n) and π k (n) being functions in Θ(n 2 ). 7 A Family of Minimal Grammars Our quest for a family {G n } n 1 of minimal grammars that generate {C n } n 1 is directed by the following two observations. Firstly, as remarked earlier, results from Sections 4 and 5 suggest that avoiding ambiguity is a major contribution. Then δ reaches its minimum value (i.e., δ(n) = n) and by Lemma 6.1 and its proof we may concentrate on minimizing ν(n): as a consequence π(n) will reach its minimum value as well. The second observation concerns the definition of minimality in this context. From the last remark in Section 3 it follows that ν(n), π(n), δ(n) Ω(n). So the following definition is an obvious choice. Definition 7.1. Let {G n } n 1 be a family of context-free grammars in Chomsky normal form that generates {C n } n 1. Then the family {G n } n 1 is called minimal if (1) each G n (n 1) is an unambiguous grammar, and (2) the number ν(n) of nonterminal symbols of G n satisfies ν(n) Θ(n). Next we will show that there exists a family that meets these conditions. Definition 7.2. The family {G n } n 1 is given by {(V n, Σ n, P n, S n )} n 1 with for n 2, N n = V n Σ n = {S n, A 1, A 2,...,A n } {A 12 k 1 < k < n} {A k(k+1) n 1 < k < n}, P n = {S n A 1 A 23 n } {S n A k(k+1) n A 12 (k 1) 1 < k n} {A 12 k A 12 (k 1) A k 1 < k < n} {A k(k+1) n A k A (k+1) n 1 < k < n} {A k a k 1 k n}. Example 7.3. For n = 5, Definition 7.2 yields the grammar G 5 = (V 5, Σ 5, P 5, S 5 ) with N 5 = {S 5, A 1, A 2, A 3, A 4, A 5, A 12, A 123, A 1234, A 45, A 345, A 2345 } with P 5 = {S 5 A 1 A 2345 A 2345 A 1 A 345 A 12 A 45 A 123 A 5 A 1234, A 1234 A 123 A 4, A 123 A 12 A 3, A 12 A 1 A 2, A 2345 A 2 A 345, A 345 A 3 A 45, A 45 A 4 A 5, A 1 a 1, A 2 a 2, A 3 a 3, A 4 a 4, A 5 a 5 }. Now the equivalence classes are E 5,5 = {S 5 }, E 5,4 = {A 1234, A 2345 }, E 5,3 = {A 123, A 345 }, E 5,2 = {A 12, A 45 } and E 5,1 = {A 1, A 2, A 3, A 4, A 5 }.

10 Peter R.J. Asveld Consequently, we have ν (5) = 12 and π (5) = 16; the fact that G 5 is unambiguous implies that δ (5) = 5. Proposition 7.4. For the family {G n } n 1 of Definition 7.2 we have (1) D(n, n) = 1, D(n, 1) = n, and D(n, k) = 2 with 1 < k < n, (2) ν (1) = 1 and for n 2, ν (n) = 3n 3, (3) π (1) = 1 and for n 2, π (n) = 4n 4, (4) δ (n) = n. Proof. It is a routine matter to verify that L(G n) = C n and that G n is unambiguous for n 1. Definition 7.2 implies ν (n) = #N n = n + 1 + 2(n 2) = 3n 3 provided that n 2. The other statements follow from Lemma 6.1 and Definition 7.2. Corollary 7.5. The family {G n } n 1 of Definition 7.2 is minimal. Since both ν (n) and π (n) are linear in n, we have for i = 0, 1, 2 that ν (n) < ν i (n) and π (n) < π i (n) for all n 5. 8 Concluding Remarks In the previous sections we discussed a few ways of generating the languages {C n } n 1 of circular shifts by context-free grammars {G n } n 1 in Chomsky normal form. The family {G 0 n} n 1 is as straightforward as Definition 4.1 in [2]; {G 1 n} n 1 is inspired by Definition 5.4 in [2], whereas for {G 2 n } n 1 there is no immediate analogue in [2]. On the other hand the family {G n} n 1 reflects the main idea of Definition 7.1 of [2]: in that Definition a grammatical transformation is used to define the family inductively. The interested reader may compare G n and G n+1 and infer a transformation to define {G n } n 1 inductively. ν(n) π(n) δ(n) G 0 n n 2 n + 1 1 2 n3 1 2 n2 + n n 2 n G 1 n n 2 n + 1 n 2 n G 2 n 1 2 n2 + 1 n (n mod 2) + 1 1 2 2 n2 + n + 1 n (n mod 2) n 2 G n 3n 3 4n 4 n Table 1: Complexity measures. We compared these grammar families with respect to their descriptive complexity measures ν(n), π(n) and δ(n). These measures turned out to be bounded by low-degree polynomial functions. In case of unambiguous grammars, i.e., when δ(n) = n, there is a simple relation between ν(n) and π(n); cf. Lemma 6.1. A summary of our results for

Generating All Circular Shifts 11 n 2 is in Table 1. Going downwards in this table means an improvement of at least one complexity measure, provided n 5. The last family in this table {G n } n 1 is minimal in the sense of Definition 7.1; cf. Corollary 7.5. Whether it is also minimal in an absolute sense (i.e., does there exist a family of unambiguous grammars with ν(n) < 3n 3 and, consequently, with π(n) < 4n 4 for n large enough?) is a difficult open problem. First of all, the coefficient 3 is rather small, and any progress must be made by economizing in the 2n 4 elements of n 1 k=2 E n,k, since D(n, n) = 1 and D(n, 1) = n because E n,n = {S n } and E n,1 = {A 1, A 2,...,A n }, respectively. E.g., a straightforward divideand-conquer approach (usually to be considered as very efficient; cf. Proposition 8.3 in [2]) yields a grammar family with for n = 2 m (m 2), D(n, n) = 1, D(n, 2 l ) = n, for 0 l < m = log 2 n, and D(n, k) = 0, otherwise, which results in ν(n) = n log 2 n + 1. Of course, this is not an improvement with respect to ν (n) of Proposition 7.4. Secondly, and more importantly, determining the minimum number of context-free productions (regardlessly whether they are in Chomsky normal form) needed to generate a finite language is a notoriously difficult problem. For discussions, simple examples and complicated (partial) results we refer to [5, 4, 3, 1] and in particular to [13]. In Section 1 we noticed that viewed as a set of permutations of a 1 a 2 a n the set C n forms a cyclic subgroup of order n of the symmetric group S n over Σ n. We conclude this section with a few trivial subgroups of S n : I n = {a 1 a 2 a n } the identity permutation; R n = {a 1 a 2 a n 1 a n, a n a n 1 a 2 a 1 } an element and its reversal; T n = {a 1 a 2 a 3 a n, a 2 a 1 a 3 a n } an element and the result of transposing its first two symbols. We leave it as an exercise to the interested reader to construct families of unambiguous grammars for these language families for which the following holds (n 2). X n ν X (n) π X (n) δ X (n) ν X (2) ν X (n + 1) π X (2) π X (n + 1) I n 2n 1 2n 1 1 3 ν I (n) + 2 3 π I (n) + 2 R n 3n 3 3n 2 2 3 ν R (n) + 3 4 π R (n) + 3 T n 2n 1 2n 2 3 ν T (n) + 2 4 π T (n) + 2 The last four columns in this table show the recurrence relations by which ν X (n) and π X (n) are defined.

12 Peter R.J. Asveld References 1. B. Alspach, P. Eades & G. Rose, A lower-bound for the number of productions for a certain class of languages, Discrete Appl. Math. 6 (1983) 109-115. 2. P.R.J. Asveld, Generating all permutations by context-free grammars in Chomsky normal form, Theoret. Comput. Sci. 354 (2006) 118 130. An earlier version appeared in: F. Spoto, G.S. Scollo & A. Nijholt (eds.): Proc. Algebraic Methods in Language Processing (AMiLP 2003), 3rd AMAST Workshop on Language Processing, Verona, Italy, August 2003, pp. 55-68; ISSN 0929-0672. 3. W. Bucher, A note on a problem in the theory of grammatical complexity, Theoret. Comput. Sci. 14 (1981) 337-344. 4. W. Bucher, H.A. Maurer & K. Culik II, Context-free complexity of finite languages, Theoret. Comput. Sci. 28 (1984) 277-285. 5. W. Bucher, H.A. Maurer, K. Culik II & D. Wotschke, Concise description of finite languages, Theoret. Comput. Sci. 14 (1981) 227-246. 6. J. Dassow, On the circular closure of languages, EIK 15 (1979) 87 94. 7. R.L. Graham, D.E. Knuth & O. Patashnik, Concrete Mathematics (1989), Addison- Wesley, Reading, MA. 8. J. Gruska, Some classifications of context-free languages, Inform. Contr. 14 (1969) 152 179. 9. M.A. Harrison, Introduction to Formal Language Theory (1978), Addison-Wesley, Reading, MA. 10. V.A. Iljuškin, The complexity of the grammatical description of context-free languages, Dokl. Akad. Nauk SSSR 203 (1972) 1244-1245 / Soviet Math. Dokl. 13 (1972) 533-535. 11. A. Kelemenová, Complexity of normal form grammars, Theoret. Comput. Sci. 28 (1984) 299 314. 12. C.L. Liu, Introduction to Combinatorial Mathematics (1968), McGraw-Hill, New York, etc. 13. Z. Tuza, On the context-free production complexity of finite languages, Discrete Appl. Math. 18 (1987) 293-304.