Introduction
This time we will talk about a strong grammar named as Boolean Grammars which is a derivation of Context-Free Grammars. By introducing set-theoretic intersection and logical negation to Context-Free Grammars, we can form the Boolean Grammars. The last derivation of Context-Free Grammars will be Boolean Grammars which is the last objective of the paper.
According to our studies until now, we leaned that there exists language recognizers and language generators. In this section we are going to make an entrance to the language generators, specifically Context-Free Language generators. The following sections will improve this generators by adding new operators such as conjunction and negation in order.
When a person is capable of understanding whether a sentence is correct or not, he is acting as a language recognizer. However this is not our concern in this paper. The main objective is to generate legal sentences, language generating.
The regular languages are closed under a variety of operations that regular languages may be specified either by regular expressions or by deterministic or Non-Deterministic Finite Automata. These facts, used singly or in combinations, provide a variety of techniques for showing languages to be regular.
Theorem 1:
Let L be a regular language. There is an integer n≥1 such that any string w∈ L with |w|≥n can be rewritten as w = xyz such that y ≠ e, |xy| ≤ n, and xyiz ∈ L for each i ≥ 0.
(This theorem is one of a general class called pumping theorems, because they assert the existence of certain points in certain strings where a substring can be repeatedly inserted without affecting the acceptability of the string.)
The problem about regular languages is that they don't accept some specific languages.
Example 1:
Consider a grammar(Context-Free) G=(V,Σ,R,S), where V={S,a,b}, ={a,b} and R={(S→aSb), (S→e)}. A possible derivation of this grammar is
S ⇒ aSb ⇒ aaSbb ⇒ aabb
In the first two st we used the first rule of R and in the last one the second. It is observable that L(G)={anbn | n≥0}. And it can be easily inferred that this language is not regular but it is Context-Free.
Definition 1:
A Context-Free Grammar is a quadruple G = (V,Σ,R,S) where:
- V is an alphabet,
- Σ is a finite set of terminal symbols where it is a subset of V,
- R is a finite set of rules which is a finite subset of (V-Σ)×V*
- S is the starting symbol where S∈ V-Σ
The members of V-Σ are called as non-terminals. For any A∈V-Σ and u ∈ V*, we write A→Gu whenever (A,u)∈R. For any strings u,v∈V*, we write u ⇒G v if and only if there are strings x,y∈ V*, and A∈V-Σ such that u = xAy, v = xv'y, and A⇒Gv'. The relation ⇒*G is reflexive, transitive closure of ⇒G. The language generated by G is L(G)={w∈ Σ* | S⇒*Gw}; which means G generates each string in L(G). With respect to these conditions, a language is said to be Context-Free Language if L=L(G) for some Context-Free Grammar G.
A language L is said to be a Context-Free Language (CFL) if its grammar is Context-Free. More precisely, it is a language whose words, sentences and phrases are made of symbols and words from a Context-Free Grammar. Usually, CFL is of the form L=L(G).
Theorem 2:
For every Context-Free Grammar G=(Σ,N,P,S) there exists a Pushdown Automata M=(K,Σ,Г,Δ,s,F) that recognizes it, where
- K is a finite set of states
- Σ is an alphabet(the input symbols)
- Г is an alphabet(the stack symbols)
- s∈ K is the initial state,
- F⊆K is the set of final states, and(V-Σ)
- Δ is a finite subset of (K×(Σ∪{e})×Г×(K×Г*).
Pushdown Automata is a very important aspect for Context-Free Grammars because:
Theorem 3:
The class of languages accepted by Pushdown Automata is exactly the class of Context-Free Languages.
Conjunctive Grammars
As in the formal language theory, conjunctive grammars are a class of formal grammars. They extend the Context-Free Grammars with a conjunction operation. Conjunctive Grammars allow implicit disjunction represented by multiple rules for a single non-terminal symbol, which is the only logical connective expressible in Context-Free Grammars. Conjunction can be used, in particular, to specify intersection of languages. A further extension of Conjunctive Grammars known as Boolean Grammars additionally allows explicit negation, which we will consider in the following sections of the paper. The rules of a conjunctive grammar are of the form
A→α1&..&αn
where A is a non-terminal and α1...αm are strings formed of symbols in Σ and N. Informally, such a rule asserts that every string w over Σ that satisfies each of the syntactical conditions represented by α1...αm therefore satisfies the condition defined by A.
Two equivalent formal definitions of the language specified by a conjunctive grammar exist. One definition is based upon representing the grammar as a system of language equations with union, intersection and concatenation and considering its least solution. The other definition generalizes Chomsky's generative definition of the Context-Free Grammars using rewriting of terms over conjunction and concatenation.
Though the expressive means of conjunctive grammars are greater than those of Context-Free Grammars, Conjunctive Grammars retain some practically useful properties of the latter, such as efficient parsing algorithms.
Definition 2:
A Conjunctive Grammar is a quadruple G = (Σ,N,P,S) where:
- Σ is a finite set of terminal symbols
- N is a finite set of non-terminal symbols
- P is a finite set of grammatical rules(productions) which formally defined as an ordered pair (A,{α1...αn}) of a non-terminal and a finite set of strings over Σ∪N and written in the form A→α1&..&αn in which the order of s are fixed.α
- S is the starting symbol where S∈ N
- N∩ = Σ∅
Let V = Σ∪N with respect to this we can form V'=V∪{“(”,”&”,”)”}, it is assumed that none of the characters “(“,”&”,”)” are in V.
For each rule A→α1&..&αn ∈ P and for each i (1≤i ≤ n), a pair of the form (A,αi) is called a conjunct; in cases where that will not cause confusion with productions, a conjunct (A,αi) will be denoted as A→αi.
Definition 3:
Let G = (Σ,N,P,S) be a Conjunctive Grammar:
•Any string over V is a conjunctive formula
•If A and B are formulae, then AB is a formula
•If A
1...A
n (n≥1) are formulae, then (A
1&..&A
n) is a formula.
Definition 4:
- Let G=(Σ,N,P,S) be a Conjunctive Grammar. Define ⇒G as a relation of immediate derivability on the set of conjunctive formulae:A non-terminal can be written by the body of some rule enclosed in parentheses ,i.e. for all s1.s2∈V', and for all A∈ N, if s1As2 is a formula, then for all A→α1&..&αn∈ P :
s1As2⇒Gs1(α1&..&αn)s2
- Conjunction of several identical terminal strings enclosed in parentheses can be replaced by one such string, i.e. for all s1,s2∈ V'*, for all w∈Σ* and for all 1≤n, if s1(w&...&w)s2 is a formula with n number of w's,then
s1(w&...&w)s2 ⇒G s1ws2
So let
⇒*G be the reflexive, transitive closure of
⇒G.
By the help of these rules we can reform the rules and compose a smaller version of the grammars which are conjunctive.
Definition 5:
Let G=(Σ,N,P,S) be a grammar and let A be a formula. The language generated by A is a set of all strings over Σ derivable from A:
LG(A) = {w | w∈Σ, A
⇒*G w}
The language generated by the grammar is the set of all strings over Σ derivable from its start symbol: L(G)=LG(S). A language L is called a conjunctive, if it is generated by some Conjunctive Grammar. Let L& be the set of all Conjunctive Languages.
Aforementioned, we have Pushdown Automata for Context-Free Languages. As mentioned in Theorem 2, the classes of both Pushdown Automata and Context-Free Languages are the same. There is a similar case for conjunctive grammars but we need to make some clarifications over the grammar because we need a specific Conjunctive Grammar which is in linear normal form to use the automaton which can accept the grammar.
Example 2:
Let's try to define a language {ba2ba4b...ba2n-2ba2nb | n ≥ 0}. This language is has a super-linear growth, which can also be represented as an intersection of two Context-Free Languages. However instead of using a grammar with a single conjunction on top, which would probably require many non-terminals, let us give a more compact solution:
S → Sab&Cb
S → b
A → aA
A → ℇ
C → bCaa
C → aC
C → baa
Every next string ba2bab...ba2n-2ba2n+2b is generated out of the previous string ba2ba4b...ba2n-2ba2nb by right-concatenating twice as many a's as there are b's spread a × the previous string; this behavior is directed by the rule S → SA&Cb, where Sab generates Sa*b and thus adds some number of a's and then b, while the non-terminal C ensures that the number of a's added is correct. The rule S → b forms the induction thesis.
As we saw from the example, if we consider all the strings that a Context-Free Grammar as a set, the set conjunction of two Context-Free Grammar gives us the exact set of the Conjunctive Grammar where both of these Context-Free Grammar rules are satisfied.
With this example it is now obvious that Conjunctive Grammars are more powerful when compared to Context-Free Grammars.
Example 3:
A Conjunctive Grammar for the language {
anbncn n | n ≥ 0} :
S → AB&DC
A → aA
A → ℇ
B → bBc
B → ℇ
C → cC
C → ℇ
D → aDb
D → ℇ
It is obvious that A,B,C and D generate the languages {ai i | i ≥ 0},{bjcj j | j ≥ 0},{cl | l ≥ 0} and {akbk k | k ≥ 0}, respectively. Therefore S generates:
{aibjcj | i,j ≥ 0}∩{akbkcl | k,l ≥ 0} = { anbncn | n ≥ 0}
This language can't be implemented by a Context-Free Grammar because we can't count the number of three variables. We can use a version of pumping lemma to prove that this language is not Context-Free .
Theorem 4:
Let G = (Σ,N,P,S) be a Conjunctive Grammar. Let A1...An,B be formulae, let A∈N, let u ∈Σ*. Then,
LG((A1&...&An)) =
∩ nk=1 LG(Ak)
LG(AB) = LG(A)
● LG(B)
LG(A) =
∪ Ak→a1∧...∧am∈P LG(a
1∧...
∧a
m)
LG(a) = {a}
LG(ℇ) = {ℇ}
This shows that one can obtain a certain system of language equations by using the explicit union, intersection and concatenation. We can refer that there exists a vector of languages as the solution of this system.
Definition 6:
A Conjunctive Grammar is said to be in the linear, if each rule in P is of the form:
- A → u1B1v1&...& umBmvm (uivi ∈Σ*,Bi∈ N)
- A → w (w ∈Σ*)
Definition 7:
Let G = (Σ,N,P,S) be a Conjunctive Grammar. A conjunct of the form A → ℇ, where A∈N, is called an epsilon conjunct.
We can for every Conjunctive Grammar an equivalent grammar without epsilon conjuncts.
Theorem 5:
For any Conjunctive Grammar G = (Σ,N,P,S) there exists a Conjunctive Grammar G' = (Σ,N,P',S'), free of epsilon conjuncts such that
L(G') = L(G) \ {ℇ}
Definition 8:
Let G = (Σ,N,P,S) be a Conjunctive Grammar. A conjunct of the form A → B, where A,B∈N is called an unit conjunct.
Lemma 1:
Let G = (Σ,N,P,S) be a Conjunctive Grammar. Let
A→α
1&..&α
k-1&B&α
k&..&α
m (m ≥ 1, 1 ≤ k ≤ m, α
i∈Σ*)
be some rule for A that contains a unit conjunct.
B→ β
1l &..&β
1l
...
B→ β
r1 &..&β
rlk
be all rules for B that do not contain the unit conjunct B → B (βij ≠ B), if A ≠ B, then the rule in Lemma 1 can be replaced with the collection of rules:
A→ α
1&..&α
k-1&β
r1 &..&β
rlk&α
k&..&α
m (1 ≤ i ≤ r)
without altering the language generated by the grammar.
If A=B, then the rule in Lemma 1 may be just removed.
Definition 9:
A linear Conjunctive Grammar G = (Σ,N,P,S) is said to be in the linear normal form, if each rule in P is of the form
- A → bB1&..&bBm& C1c&..&Cnc (m+n ≥ 1; A,Bi,Cj ∈ N; b,c∈Σ )
- A → α(A∈N, α∈Σ)
- S → ℇ, only if S doesn't appear in right parts of rules
There is a way to convert every Linear Conjunctive Grammar to linear normal form. If one removes all the ℇ and unit conjuncts, cuts the long conjuncts until all of them are of the form A→ α, A→bB and A→ cC and removing the rules with contradicting conjuncts,which clearly can't be used in a successful derivation, the process of converting a linear conjunctive grammar to linear normal form will be finished.
Definition 10:
A treillis automaton is a sex-tuple M=(Σ,Q,I,ℊ,F,e), where:
- Σ is the input alphabet,
- Q is a finite nonempty set of states(of processing units),
- I:Σ→Q is a function that sets the initial states(loads values into the bottom processors),
- ℊ:Q × Q→Q is the transition function(the function computed by processors),
- F∈Q is the set of final states(effective in the top processor),
- e∈{0,1} determines whether ℇ is accepted or rejected.
Given a nonempty string α1...αn (αi∈Σ, n ≥ 1), every node of trellis corresponds to a certain substring α1...αn (1 ≤ i ≤ j ≤ n) of symbols on which its value depends. The value of a bottom node corresponding to one symbol of the input is I(αi); the value of a successor of two nodes is ℊ of the values of these ancestors. Denote the value of a node corresponding to αi...αj as Δ(I(αi...αj))∈Q: here I(αi...αj) is a string of states (the bottom row of the trellis), while Δ denotes the result (a single state) of triangular computation starting from a row of states. By definition :
Δ(I(α
i)) = I(α
i) and Δ(I(α
i,...,α
j)) = (Δ(I(ℑα
i,..,α
j-1 j-1)),Δ(I( α
i+1 ,..,α
j))).
Now define language generated by M as
L(M) = {w ∈Σ
+ | Δ(I(w)) F} {∈∪ℇ | if e = 1}
These relationships such as Context-Free Grammars with Pushdown Automata and Conjunctive Grammars with trellis automaton resembles the relationship between regular expressions and Deterministic Finite Automatas. To be precise, the left sides are for humans and the right sides are for implementations.
References
Conjunctive Grammars, Journal of Automata, Languages and Combinatorics, Alexander Okhotin, 2001
An overview of conjunctive grammars, Alexander Okhotin, 2003
Elements of the Theory of Computation (2nd ed.), H.R. Lewis,C.H. Papadimitriou, 1998