scieee AI-readable full text Open interactive document viewer

Some applications of the formalization of the pumping lemma for context-free languages

Ramos, Marcus V. M.; Almeida, José Bacelar; Moreira, Nelma; de Queiroz, Ruy J. G. B.

Abstract

Context-free languages are highly important in computer language processing technology as well as in formal language theory. The Pumping Lemma for Context-Free Languages states a property that is valid for all context-free languages, which makes it a tool for showing the existence of non-context-free languages. This paper presents a formalization, extending the previously formalized Lemma, of the fact that several well-known languages are not context-free. Moreover, we build on those results to construct a formal proof of the well-known property that context-free languages are not closed under intersection. All the formalization has been mechanized in the Coq proof assistant.

Full text

Some Applications of the Formalization of the Pumping Lemma for Context-Free Languages Marcus V. M. Ramos1 Colegiado de Engenharia de Computação UNIVASF Juazeiro, Bahia, Brazil José Carlos Bacelar Almeida2 HASLab - INESC TEC Universidade do Minho Braga, Portugal Nelma Moreira3 Departamento de Ciência de Computadores Faculdade de Ciências Porto, Portugal Ruy J. G. B. de Queiroz4 Centro de Informática UFPE Recife, Pernambuco, Brazil Abstract Context-free languages are highly important in computer language processing technology as well as in formal language theory. The Pumping Lemma for Context-Free Languages states a property that is valid for all context-free languages, which makes it a tool for showing the existence of non-context-free languages. This paper presents a formalization, extending the previously formalized Lemma, of the fact that several wellknown languages are not context-free. Moreover, we build on those results to construct a formal proof of the well-known property that context-free languages are not closed under intersection. All the formalization has been mechanized in the Coq proof assistant. Keywords: non-context-free languages, closure, intersection, pumping lemma, formalization, Coq 1Email:[email protected] 2Email:[email protected] 3Email:[email protected] 4Email:[email protected] Available online at www.sciencedirect.com Electronic Notes in Theoretical Computer Science 344 (2019) 151–167 1571-0661/© 2019 The Author(s). Published by Elsevier B.V. www.elsevier.com/locate/entcs https://doi.org/10.1016/j.entcs.2019.07.010 This is an open access article under the CC BY license (http://creativecommons.org/licenses/by/4.0/). 1 Introduction A context-free grammar Gis a four-tuple (V,Σ,P,S)where Vis the vocabulary (a finite set consisting of terminal and non-terminal symbols), Σis the set of terminal symbols or alphabet (thus N=V\Σis the set of non-terminal symbols), Pis the (finite) set of rules of the form X→β, where X∈Nand β∈V∗, and Sis the start symbol of the grammar, S∈N. A language is a set of words (also called “sentences”) defined over an alphabet. The language Lgenerated by a context-free grammar G is the (finite or infinite) set of words that can be obtained from the start symbol of the grammar by repeated use of its rules: L(G)={w|S⇒∗wand w∈Σ∗}.A language is context-free (CFL for short) if there exists a context-free grammar that generates it. Otherwise, the language is not context-free. To prove that a language is not context-free requires, thus, to prove that there is no context-free grammar that generates it (a similar argument can be formulated about the nonexistence of pushdown automata that accept the language, but this is not in the scope of this work). This task can be simplified, however, by exploring a property that is observed by all context-free languages. This is accomplished by means of the Pumping Lemma for Context-Free Languages, which can be used to prove that a given language is not context-free. Proving that an arbitrary language is context-free is, however, an undecidable property [3]. The Pumping Lemma for CFLs was stated and proved for the first time by Bar- Hillel, Perles and Shamir in 1961 [1]. In what follows, it will be referred simply as “Pumping Lemma”. The main objectives of this paper are: (i) Derive formal proofs that some well-known, classic languages, are not contextfree. For this, we use the formalization of the Pumping Lemma previously obtained by the authors [7] in the Coq proof assistant [2]. For each of these languages, we discuss the formalization of their non-context-freeness and make hopefully useful considerations about the proof construction process and the complexity of the corresponding formal and text proofs; (ii) Develop a formal proof of the fact that the class of the context-free languages is not closed under the intersection operation. For that, we follow the classical proof that uses a counter-example, which in our case is one of the languages proved not to be context-free in the previous objective. The results presented here are important for various reasons. First, they are applications of the previous formalization of the Pumping Lemma. Second, they are the first ever languages to be proved not to be context-free using a computerized theorem prover. As far as the authors are aware of, all proofs of any language claimed to be non-context-free published until now are text (pen and paper) ones, as can be found in textbooks, papers and lectures on the subject. Thus, the present work brings mathematical formalization into a new area of application. Third, they give rise to interesting considerations about building formal proofs from text proofs. Fourth, they can be very useful in teaching the theory of context-free languages within a logic and formal background, with the help of interactive theorem provers and Coq M.V.M. Ramos et al. / Electronic Notes in Theoretical Computer Science 344 (2019) 151–167152 in particular. Besides this, we extend our previous results on the formalization of closure properties for context-free languages (closure under union, concatenation and Kleene star, [9]) with a new result with respect to language intersection. The work presented here is part of a long-term project aimed at the formalization of context-free languages and grammars. It started with the formalization of closure properties for context-free grammars [9], evolved later into the formalization of context-free grammar simplification [10] and then into the Chomsky normalization of context-free grammars. Formalization of simplification enabled Chomsky normalization, which in turn enabled the formalization of the Pumping Lemma and then the results presented here. The whole work is described in detail in [5], and more information can be found in [8]. Previous results will not be discussed here and can be retrieved from the references. In order to follow this paper, the reader is required to have basic knowledge of Coq and of context-free language theory. Background on context-free language theory can be found in [12], [3]or[11], among others. The statement and applications of the Pumping Lemma for CFLs are presented in Section 2. The approach that we have adopted towards the formalization of languages in general is discussed in Section 3. Then, in Sections 3.1, 3.2 and 3.3, respectively, we present formalizations of three different and well-known languages using the approach discussed before. Besides that, each of these sections contains a text proof of the fact that the language is not context-free, a discussion about the formalization of such a proof and considerations about the complexity of the text and formal proofs. In Section 4we describe our formalization of the nonclosure of context-free languages under intersection, a result that is built on top of formalization described in 3.3. Final conclusions are presented in Section 5. The definitions and proof scripts discussed in this paper were written in plain Coq and are available for download at [6]. Statements about prime numbers, required in Section 3.2,were written in SSReflect (a Coq plugin) and adapted from existing proofs in the Mathematical Components library [4]. 2 Pumping Lemma for Context-Free Languages The Pumping Lemma states that, for every context-free language and for every sentence of such a language that has a minimum length, it is possible to obtain an infinite number of new sentences that must also belong to the language. This minimum length depends on the definition of the language. Let Lbe a context-free language defined over alphabet Σ. Then there is a number n, depending only on L, such that for every sentence α∈L,if|α|≥n, then all of the following are true (|w|denotes the length of the word w): •∃u, v, w, x, y.(α=uvwxy); •|vx|≥1; •|vwx|≤n; •∀i.(uviwxiy∈L) M.V.M. Ramos et al. / Electronic Notes in Theoretical Computer Science 344 (2019) 151–167 153 A more concise, yet more difficult to read, representation of this statement is (“cfl” is a predicate that asserts that a language is context-free, see Section 3): ∀L.(cfl L)→∃n.∀α. (α∈L)∧(|α|≥n)→∃u, v, w, x, y.(α=uvwxy)∧(|vx|≥1) ∧(|vwx|≤n)∧(∀i.uviwxiy∈L) A typical use of the Pumping Lemma is to show that a given language is not context-free by using the contrapositive of the statement of the lemma. The informal proof proceeds by contraposition: the language is assumed to be context-free, and this leads to a contradiction from which one concludes that the language in question can not be context-free. For details about our previous formalization of the Pumping Lemma, please refer to [7]. The non-context-free languages formalized in this work are: (i) square:{w∈{a}∗|∃i, |w|=i2,i≥0}, (ii) prime:{w∈{a}∗||w|is a prime number}, (iii) anbncn:{w∈{a, b, c}∗|∃i, w =aibici,i≥0}. For each of these, we will refer to the text proofs of their non-context-freeness using the Pumping Lemma, as well as to the corresponding formalization in Sections 3.1, 3.2 and 3.3. The Pumping Lemma does not characterize the CFLs, however, since it is also verified by some non-CFLs [3]. Besides that, the authors are not aware of any independent characterization of the class of languages that satisfy it. 3 Languages In order to formally prove that a language is not context-free, we first need to have a formal definition of such a language. The definitions of the languages square,prime and anbncn introduced before are presented in the next three sections, however they all share the same and more fundamental definitions discussed in this section. A language is defined as a predicate that maps a sentence (a list of terminal symbols) to a proposition (Prop): Definition lang (terminal:Type):= list terminal →Prop. Two languages are equal if they have the same sentences: Definition lang_eq (lk:lang):= ∀w,lw↔kw. Finally, a language is context-free if it is generated by some context-free grammar (for the definition of a context-free grammar in Coq, and other related definitions, please refer to [8]). The following definition is a predicate that represents this M.V.M. Ramos et al. / Electronic Notes in Theoretical Computer Science 344 (2019) 151–167154 property: Definition cfl (terminal:Type)(l:lang terminal): Prop:= ∃non_terminal:Type, ∃g:cfg non_terminal terminal, lang_eq l (lang_of_g g). where lang_of_g represents the language generated by grammar g: Definition lang_of_g (g:cfg non_terminal terminal): lang := fun w:sentence ⇒produces g w. Thus, the definition of a new language comprises, essentially, the definition of a new type terminal whose constructors are the elements of Σand of a membership predicate that asserts whether an arbitrary list of terminal symbols is a word of the language or not. This predicate, in our case, will carry the name of the language being defined. Examples of this are presented in the next three sections. 3.1 Language square Language square ({ai|iis the square of some number}) is defined over a single symbol alphabet and contains words whose length corresponds to the square of some natural number. Thus, it contains words such as ,a,aaaa,aaaaaaaaa etc. Text proof To prove that square is not context-free, suppose that it is context-free and consider the word am, where m=n2and nis the constant of the Pumping Lemma. It is easy to observe that am∈square and that |am|≥n. Thus, the Pumping Lemma can be applied. Then, am=uvwxy for some u,v,w,xand y, with |uvwxy|=n2,1≤|vwx|≤nand uviwxiy∈square,∀i≥0. But take i=2. Then, |uv2wx2y|=|uvwxy|+|vx|. Since |uvwxy|=n2and 1≤|vx|≤n, we have n2<|uv2wx2y|≤n2+n, which is the same as n2<|uv2wx2y|<(n+1)2. However, there is no such a number that is the square of another number and lies between the squares of two consecutive numbers. Thus, the hypothesis is false and square is not context-free. Formalization of the definition The language square is defined in our formalization as follows: Inductive terminal:Type:= |a. Definition square:lang terminal:= fun (s:list terminal)⇒ ∃i:nat, length s =i∗i. The type terminal has a single constructor a, which corresponds to the single element of the alphabet. Definition square is a predicate on lists of terminals, expressing the property that the length of the list is a square of some number. It embeds the property that all words of the language must satisfy, namely that the length of the word must be the square of some number. M.V.M. Ramos et al. / Electronic Notes in Theoretical Computer Science 344 (2019) 151–167 155 Formalization of the statement The statement of this lemma simply says that the predicate square can not represent a context-free language because it does not satisfy the predicate cfl: Lemma not_cfl_square:∼cfl square. Formalization of the proof The formal proof follows closely the argument and steps of the text proof. Two simple auxiliary lemmas had to be proved, however. The first asserts the existence of an infinite number of words in square: ∀n.∃w.(|w|=n2)∧(w∈square) while the second asserts the key property of natural numbers used in the proof 5: ∀i, j, k.(j≥1) ∧(j≤i)→¬(i2+j=k2) Comparison of the formal and text proofs While the text proof is less than 10 lines long, the formal proof script is approximately 200 lines long. Despite the expansion factor being significant, the proof is simple and very readable. The size, in this case, can be justified by the style adopted in the writing of the script (with only one tactic per line, for example) and the details that are inherent to the proof. The elegance of this formalization stimulated the authors to pursue the formalization of the next section. 3.2 Language prime Language prime ({ai|iis a prime number}) is defined over a single symbol alphabet and contains words whose length is a prime number. Thus, it contains words such as aa,aaa,aaaaa,aaaaaaa etc. Text proof To prove that prime is not context-free, suppose that it is context-free and consider the word am, where m≥n+2is a prime number and nis the constant of the Pumping Lemma. It is easy to observe that am∈prime and that |am|≥n. Thus, the Pumping Lemma can be applied. Then, am=uvwxy for some u,v,w,y and y, with |uvwxy|=m,1≤|vwx|≤nand uviwxiy∈prime,∀i≥0. But make i=|uwy|. Then, |uv|uwy|wx|uwy|y|=|uwy|+|uwy|∗|vx|=|uwy|∗(1 + |vx|). Since |uvwxy|≥n+2and n≥|vx|≥1, we have that |uwy|≥2. Also, that 1+|vx|≥2, since |vx|≥1. Thus, the length of the new word is a composite number and not a prime number. The hypothesis is false and prime is not context-free. 5The scripts of this section can be found in file pumping_square.v. M.V.M. Ramos et al. / Electronic Notes in Theoretical Computer Science 344 (2019) 151–167156 Formalization of the definition The language prime is defined in our formalization as follows: Inductive terminal:Type:= |a. Definition prime_lang:lang terminal:= fun (s:list terminal)⇒ ∃i:nat, is_prime i ∧ length s =i. The predicate is_prime is the primality predicate. As in the previous case, the type terminal has a single constructor a. Definition prime is a predicate on lists of terminals, expressing the property that the length of the list is a prime number. It embeds the property that all words of the language must satisfy, namely that the length of the word must be a prime number. Formalization of the statement As before, the statement of this lemma says that the predicate prime_lang can not represent a context-free language because it does not satisfy the predicate cfl: Lemma not_cfl_prime:∼cfl prime_lang. Formalization of the proof Similar to the previous case, the formal proof follows closely the argument and steps of the text proof. Three auxiliary lemmas had to be proved, however. The first asserts the existence of an infinite number of words in prime: ∀n.∃w.(|w|≥n)∧(prime |w|) while the second and third assert key properties of prime numbers used in the proof: ∀i.∃j.(j≥i)∧(prime j) ∀n, p, q.(n=p∗q)∧(p≥2) ∧(q≥2) →¬(prime n) The proof of the two lemmas on prime numbers was accomplished by means of previously existing proofs in the Mathematical Components library [4] 6. Comparison of the formal and text proofs Also in this case, the text proof is less than 10 lines long, while the formal proof script is approximately 200 lines long, elegant, simple and readable. This and the previous result led the authors to work on the formalization of the next section. 3.3 Language anbncn Language anbncn ({aibici|i≥0}) is defined over a three symbol alphabet (a,b and c) and contains words that start with some number of as, followed by the same 6The scripts of this section can be found in file pumping_prime.v. M.V.M. Ramos et al. / Electronic Notes in Theoretical Computer Science 344 (2019) 151–167 157 number of bs and then by the same number of cs. Thus, it contains words such as ,abc,aabbcc,aaabbbccc etc. Text proof To prove that anbncn is not context-free, suppose that it is context-free and consider the word anbncn, where nis the constant of the Pumping Lemma. It is easy to observe that anbncn∈anbncn and that |anbncn|≥n. Thus, the Pumping Lemma can be applied. Then, anbncn=uvwxy for some u,v,w,xand y, with |uvwxy|=3n,1≤|vwx|≤nand uviwxiy∈anbncn,∀i≥0. It can be observed that vwx, due to its length limitation, contains only one or two different kind of symbols. If it contains only one kind of symbol, then vand xare also built out of a single symbol and the pumping of vand xwill change the number of a single symbol, while the number of the other two remain unchanged. Thus, the new word can not belong to anbncn. If it contains two different kinds of symbols, then vand xmight contain one or two different kinds of symbols each. If both contain only one kind of symbol, pumping will change the number of at most two symbols, while the third will remain unchanged. If vor xcontain two different kinds of symbols, pumping will lead to a word where the order is not respected (first as, then bs then cs). In all cases, the new word does not belong to anbncn. Thus, the hypothesis is false and anbncn is not context-free. Formalization of the definition The language anbncn is defined in our formalization as follows: Inductive terminal:Type:= |a |b |c. Definition anbncn:lang terminal:= fun (s:list terminal)⇒ ∃xyz:list terminal, ∃i:nat, s=x ++y ++z ∧ length x =i∧na x =i∧length y =i∧ nb y =i∧length z =i∧nc z =i. The functions na,nb and nc evaluate, respectively, to the number of symbols a, band cin the argument (a list of terminal symbols). The type terminal has three constructors a,band c. Definition anbncn is a predicate on lists of terminals, expressing the property that the list is built by the same number of each of the symbols a,band c, in this order. It embeds the property that all words of the language must satisfy, as described above. Formalization of the statement Similar to previous cases, the statement of this lemma says that the predicate anbncn can not represent a context-free language because it does not satisfy the predicate cfl: Lemma not_cfl_anbncn:∼cfl anbncn. M.V.M. Ramos et al. / Electronic Notes in Theoretical Computer Science 344 (2019) 151–167158 Formalization of the proof Differently from the two previous cases, the proof that anbncn is not contextfree is much longer and more complex. It is accomplished by means of extensive case analysis on the components of the uvwxy word, which result in various cases to be considered. To start with, we observe that, since vwx is part of uvwxy, and since |vwx|≤n, then vwx must contain only symbols afollowed by symbols b,or only symbols bfollowed by symbols c. Observe also that, according to the Pumping Lemma, vx =, which means that vand xcan not be empty simultaneously. An extensive analysis of the possibilities for vand xunder these circunstances is presented below:7 ⎧ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎨ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎩ vwx ∈a∗b∗ ⎧ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎨ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎩ (v=)∧(x=) ⎧ ⎪ ⎪ ⎨ ⎪ ⎪ ⎩ |v|a=0 ∧|v|b=0 ∧|v|c=0 ∧|x|a=0 ∧|x|b=0 ∧|x|c=0 (1) |v|a=0 ∧|v|b=0 ∧|v|c=0 ∧|x|a=0 ∧|x|b=0 ∧|x|c=0 (2) |v|a=0 ∧|v|b=0 ∧|v|c=0 ∧|x|a=0 ∧|x|b=0 ∧|x|c=0 (3) (v=)∧(x=) ⎧ ⎪ ⎪ ⎨ ⎪ ⎪ ⎩ |v|a=0 ∧|v|b=0 ∧|v|c=0 ∧|x|a=0 ∧|x|b=0 ∧|x|c=0 (4) |v|a=0 ∧|v|b=0 ∧|v|c=0 ∧|x|a=0 ∧|x|b=0 ∧|x|c=0 (5) |v|a=0 ∧|v|b=0 ∧|v|c=0 ∧|x|a=0 ∧|x|b=0 ∧|x|c=0 (6) (v=)∧(x=)can not occur, since |vx|≥1(7) (v=)∧(x=) ⎧ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎨ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎩ |v|a=0 ∧|v|b=0 ∧|v|c=0 ∧|x|a=0 ∧|x|b=0 ∧|x|c=0 (8) |v|a=0 ∧|v|b=0 ∧|v|c=0 ∧|x|a=0 ∧|x|b=0 ∧|x|c=0 (9) |v|a=0 ∧|v|b=0 ∧|v|c=0 ∧|x|a=0 ∧|x|b=0 ∧|x|c= 0 (10) |v|a=0 ∧|v|b=0 ∧|v|c=0 ∧|x|a=0 ∧|x|b=0 ∧|x|c= 0 (11) |v|a=0 ∧|v|b=0 ∧|v|c=0 ∧|x|a=0 ∧|x|b=0 ∧|x|c= 0 (12) vwx ∈b∗c∗ ⎧ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎨ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎩ (v=)∧(x=) ⎧ ⎪ ⎪ ⎨ ⎪ ⎪ ⎩ |v|a=0 ∧|v|b=0 ∧|v|c=0 ∧|x|a=0 ∧|x|b=0 ∧|x|c= 0 (13) |v|a=0 ∧|v|b=0 ∧|v|c=0 ∧|x|a=0 ∧|x|b=0 ∧|x|c= 0 (14) |v|a=0 ∧|v|b=0 ∧|v|c=0 ∧|x|a=0 ∧|x|b=0 ∧|x|c= 0 (15) (v=)∧(x=) ⎧ ⎪ ⎪ ⎨ ⎪ ⎪ ⎩ |v|a=0 ∧|v|b=0 ∧|v|c=0 ∧|x|a=0 ∧|x|b=0 ∧|x|c= 0 (16) |v|a=0 ∧|v|b=0 ∧|v|c=0 ∧|x|a=0 ∧|x|b=0 ∧|x|c= 0 (17) |v|a=0 ∧|v|b=0 ∧|v|c=0 ∧|x|a=0 ∧|x|b=0 ∧|x|c= 0 (18) (v=)∧(x=)can not occur, since |vx|≥1 (19) (v=)∧(x=) ⎧ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎨ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎩ |v|a=0 ∧|v|b=0 ∧|v|c=0 ∧|x|a=0 ∧|x|b=0 ∧|x|c= 0 (20) |v|a=0 ∧|v|b=0 ∧|v|c=0 ∧|x|a=0 ∧|x|b=0 ∧|x|c= 0 (21) |v|a=0 ∧|v|b=0 ∧|v|c=0 ∧|x|a=0 ∧|x|b=0 ∧|x|c= 0 (22) |v|a=0 ∧|v|b=0 ∧|v|c=0 ∧|x|a=0 ∧|x|b=0 ∧|x|c= 0 (23) |v|a=0 ∧|v|b=0 ∧|v|c=0 ∧|x|a=0 ∧|x|b=0 ∧|x|c= 0 (24) For each of the two initial cases (vwx ∈a∗b∗and vwx ∈b∗c∗), we consider other four: •(v=)∧(x=),or •(v=)∧(x=),or •(v=)∧(x=),or •(v=)∧(x=). Condition (v=)∧(x=), corresponding to cases (7) and (19) above, can not of course happen since we know that vx =and for this reason they are dropped out. Next, for each of the subcases, it is possible to make statements about the number of each kind of symbol in both vand x(whether they are zero or not zero). Now observe that, in all 22 valid cases above, at most two numbers are not zero 7|v|astands for na v, that is, the number of symbols acontained in the word v. Similarly, |v|bstands for nb v and |v|cstands for nc v. M.V.M. Ramos et al. / Electronic Notes in Theoretical Computer Science 344 (2019) 151–167 159 structure of substrings, a feature that (as far as the authors are aware of) is not natively available in Coq nor in any of its standard libraries. First of all, the size and complexity of the formal proofs for anbncn,anbnanbn and ww involve combinatory aspects needed in intermediate reasoning steps required to build the final proof, and this led to large and fully detailed scripts. If this is a consequence of some characteristic (or lack of feature) of Coq or its libraries, this is a matter still to be investigated. Indeed, it sounds very much like the libraries of Coq are not so well developed in respect to the combinatorics of strings, as it is in other areas, such as sets, lists and algebra to mention a few. Thus, this might suggest that some effort is required in this area in order to ease the development of proofs such as the ones that we have discussed in Section 3. What is needed are lemmas that prove that strings with some property that are substrings of another string with another property can get proper descriptions. An example is a lemma that proves that any string with maximum length nthat is a substring of string anbncnbelongs to a∗b∗|b∗c∗. Similarly for any string with the same size nthat is a substring of anbnanbn, in this case being described by a∗b∗|b∗a∗. Note, however, that this need was not present in the formal proofs developed for square and prime, which involve basically the length of the generated strings. Second, we argue that perhaps the classical text proofs of anbncn,anbnanbn and ww are not as clear and understandable as they seem or claim to be. Indeed, the text proof that anbncn is not context-free is only 10 lines long, but hides in it 24 different cases. For the language anbnanbn the situation is even worse: 28 (or 22) different cases are hidden in the text proof, which is about 10 lines long as well. Is everyone capable of seeing so many cases in so few lines of english text? Aren’t these text proofs oversimplified and relying too much on the common sense and perceptions of the reader (student, teacher, professional, whatever)? The proof that context-free languages are not closed under intersection is a nice result that derives almost directly from one of the previous results. It demanded, however, some effort in order to adequately cope with the many details involved in proofs that usually do not take too much time or effort from the reader of a text proof (such as to convince himself that a given grammar generates a given language). Once again, we see here the formalization making all the details of a text proof explicit. This result, along with the other results previously obtained about the formalization of closure under union, concatenation and Kleene star [9], represent a good set of formalized results of closure properties for the class of the context-free languages. The results obtained so far are interesting in their own. They correspond to important applications of an important property of context-free languages which can be used for different purposes. These include to guarantee the correctness of text proofs that may hide too much information, and thus escape from the full understanding of the reader, and to better understand the nature of the corresponding proofs. Also, these formal proofs are original and valuable material for courses in formal language theory and/or formal reasoning using interactive proof assistants. Future works include improvements in the source code of this formalization via M.V.M. Ramos et al. / Electronic Notes in Theoretical Computer Science 344 (2019) 151–167166 simplifications and generalizations. As an example, files pumping_anbncn.v and intersection.v contain different lemmas and functions that can be combined into a single lemma or function. One case are functions na,nb and nc that count the occurrences of, respectively, symbols a,band cin a list and can be grouped into a single function that counts the occurrences of a parametrized symbol. Another case are lemmas cfl_ambm and cfl_bmcm that can be merged into a single lemma where the terminal symbols are parameters of the lemma. Besides that, we plan to extend our work on the formalization of context-free language theory with the formalization of the closure of the class of the context-free languages under intersection with regular languages, of the non-closure of the same class under complementation and of Ogden’s Lemma, a stronger version of the Pumping Lemma for Context-Free Languages [3]. References [1] Yehoshua Bar-Hillel, Micha A. Perles, and Eli Shamir. On formal properties of simple phrase structure grammars. Zeitschrift für Phonetik, Sprachwissenschaft und Kommunikationsforschung, 14:143–172, 1961. [2] The Coq Development Team. The Coq Reference Manual, version 8.8.0, 2018. Available electronically at https://coq.inria.fr/distrib/current/refman/. [3] John E. Hopcroft and Jeffrey D. Ullman. Introduction To Automata Theory, Languages and Computation. Addison-Wesley Publishing Co., Inc., 1979. [4] Inria – Microsoft Research Joint Centre. SSReflect and the Mathematical Components library, 2018. http://math-comp.github.io/math-comp/, accessed August 14th, 2018. [5] Marcus Vinícius Midena Ramos. Formalization of Context-Free Language Theory. PhD thesis, Centro de Informática - UFPE, 2016. http://www.marcusramos.com.br/univasf/tese.pdf, 2016. [6] Marcus Vinícius Midena Ramos. Source files, 2016. https://github.com/mvmramos/intersection, 2018. [7] Marcus Vinícius Midena Ramos, José Carlos Bacelar Almeida, Nelma Moreira, and Ruy José Guerra Barretto de Queiroz. Formalization of the Pumping Lemma for Context-Free Languages. Journal of Formalized Reasoning, 9(2):53–68, 2016. https://jfr.unibo.it/article/view/5595. [8] Marcus Vinícius Midena Ramos, José Carlos Bacelar Almeida, Nelma Moreira, and Ruy José Guerra Barretto de Queiroz. On the Formalization of Some Results of Context-Free Language Theory. In Jouko Väänänen, Åsa Hirvonen, and Ruy de Queiroz, editors, 23rd International Workshop, WoLLIC 2016, Puebla, Mexico, August 16-19th, 2016, Proceedings, volume 9803 of Lecture Notes in Computer Science, pages 338–357. Springer, 2016. http://dx.doi.org/10.1007/978-3-662-52921-8_21. [9] Marcus Vinícius Midena Ramos and Ruy José Guerra Barretto de Queiroz. Formalization of closure properties for context-free grammars. CoRR, abs/1506.03428, 2014. http://arxiv.org/abs/1506.03428. [10] Marcus Vinícius Midena Ramos and Ruy José Guerra Barretto de Queiroz. Formalization of simplification for context-free grammars. CoRR, abs/1509.02032, 2015. http://arxiv.org/abs/1509.02032. [11] Marcus Vinícius Midena Ramos, João José Neto, and Italo Santiago Vega. Linguagens Formais: Teoria Modelagem e Implementação. Bookman, 2009. [12] Thomas A. Sudkamp. Languages and Machines. Addison-Wesley, 3rd edition, 2006. M.V.M. Ramos et al. / Electronic Notes in Theoretical Computer Science 344 (2019) 151–167 167