Formal Languages Philippe de Groote 2018-2019 Philippe de Groote - - PowerPoint PPT Presentation

formal languages
SMART_READER_LITE
LIVE PREVIEW

Formal Languages Philippe de Groote 2018-2019 Philippe de Groote - - PowerPoint PPT Presentation

Formal Languages Philippe de Groote 2018-2019 Philippe de Groote Formal Languages 2018-2019 1 / 28 Outline Regular expressions and regular languages 3 Definition Some algebraic properties From regular expressions to FSA From FSA to


slide-1
SLIDE 1

Formal Languages

Philippe de Groote 2018-2019

Philippe de Groote Formal Languages 2018-2019 1 / 28

slide-2
SLIDE 2

Outline

3

Regular expressions and regular languages Definition Some algebraic properties From regular expressions to FSA From FSA to type-3 grammars From type-3 grammars to regular expressions

Philippe de Groote Formal Languages 2018-2019 2 / 28

slide-3
SLIDE 3

Regular expressions and regular languages Definition

Definition

The set of regular epressions over an alphabet Σ is inductively defined as follows: 0 is a regular expression; 1 is a regular expression; every symbol a ∈ Σ is a regular expression; if α is a regular expression so is α∗; if α and β are regular expressions so is (α · β); if α and β are regular expressions so is (α + β);

Philippe de Groote Formal Languages 2018-2019 3 / 28

slide-4
SLIDE 4

Regular expressions and regular languages Definition

Definition

The set of regular epressions over an alphabet Σ is inductively defined as follows: 0 is a regular expression; 1 is a regular expression; every symbol a ∈ Σ is a regular expression; if α is a regular expression so is α∗; if α and β are regular expressions so is (α · β); if α and β are regular expressions so is (α + β); We write rexp(Σ) for the set of regular epressions over Σ.

Philippe de Groote Formal Languages 2018-2019 3 / 28

slide-5
SLIDE 5

Regular expressions and regular languages Definition

Definition

Language defined by a regular epressions: L(0) = ∅; L(1) = {ǫ}; L(a) = {a} for every a ∈ Σ; L(α∗) = L(α)∗; L(α · β) = L(α) · L(β); L(α + β) = L(α) ∪ L(β).

Philippe de Groote Formal Languages 2018-2019 4 / 28

slide-6
SLIDE 6

Regular expressions and regular languages Some algebraic properties

Some algebraic properties

(α + β) + γ = α + (β + γ) α + 0 = α 0 + α = α α + β = β + α α + α = α (α · β) · γ = α · (β · γ) α · 1 = α 1 · α = α α · 0 = 0 0 · α = 0 α · (β + γ) = α · β + α · γ (α + β) · γ = α · γ + β · γ

Philippe de Groote Formal Languages 2018-2019 5 / 28

slide-7
SLIDE 7

Regular expressions and regular languages Some algebraic properties

Some algebraic properties

0∗ = 1 1∗ = 1 (α∗)∗ = α∗ 1 + α · (α∗) = α∗ 1 + α∗ · α = α∗

Philippe de Groote Formal Languages 2018-2019 6 / 28

slide-8
SLIDE 8

Regular expressions and regular languages From regular expressions to FSA

From regular expressions to FSA

Automaton accepting L(0)

Philippe de Groote Formal Languages 2018-2019 7 / 28

slide-9
SLIDE 9

Regular expressions and regular languages From regular expressions to FSA

From regular expressions to FSA

Automaton accepting L(0) Automaton accepting L(1): ǫ

Philippe de Groote Formal Languages 2018-2019 7 / 28

slide-10
SLIDE 10

Regular expressions and regular languages From regular expressions to FSA

From regular expressions to FSA

Automaton accepting L(0) Automaton accepting L(1): ǫ Automaton accepting L(a): a

Philippe de Groote Formal Languages 2018-2019 7 / 28

slide-11
SLIDE 11

Regular expressions and regular languages From regular expressions to FSA

From regular expressions to FSA

Assuming we have an automaton accepting L(α):

α

Philippe de Groote Formal Languages 2018-2019 8 / 28

slide-12
SLIDE 12

Regular expressions and regular languages From regular expressions to FSA

From regular expressions to FSA

Assuming we have an automaton accepting L(α):

α

Automaton accepting L(α∗):

α

ǫ ǫ ǫ ǫ

Philippe de Groote Formal Languages 2018-2019 8 / 28

slide-13
SLIDE 13

Regular expressions and regular languages From regular expressions to FSA

From regular expressions to FSA

Assuming we have automata accepting L(α) and L(β):

α β

Philippe de Groote Formal Languages 2018-2019 9 / 28

slide-14
SLIDE 14

Regular expressions and regular languages From regular expressions to FSA

From regular expressions to FSA

Assuming we have automata accepting L(α) and L(β):

α β

Automaton accepting L(α · β):

α β

ǫ

Philippe de Groote Formal Languages 2018-2019 9 / 28

slide-15
SLIDE 15

Regular expressions and regular languages From regular expressions to FSA

From regular expressions to FSA

Assuming we have automata accepting L(α) and L(β):

α β

Philippe de Groote Formal Languages 2018-2019 10 / 28

slide-16
SLIDE 16

Regular expressions and regular languages From regular expressions to FSA

From regular expressions to FSA

Assuming we have automata accepting L(α) and L(β):

α β

Automaton accepting L(α + β):

α β

ǫ ǫ ǫ ǫ

Philippe de Groote Formal Languages 2018-2019 10 / 28

slide-17
SLIDE 17

Regular expressions and regular languages From FSA to type-3 grammars

From FSA to type-3 grammars

Let A = Q, Σ, δ, q0, F be an DFSA. Define a type-3 grammar G = N, ΣG, P, S as follows: N = Q ΣG = Σ P = {A→aB : δ(A, a) = B} ∪ {A→ǫ : A ∈ F} S = q0

Philippe de Groote Formal Languages 2018-2019 11 / 28

slide-18
SLIDE 18

Regular expressions and regular languages From FSA to type-3 grammars

From FSA to type-3 grammars

Let A = Q, Σ, δ, q0, F be an DFSA. Define a type-3 grammar G = N, ΣG, P, S as follows: N = Q ΣG = Σ P = {A→aB : δ(A, a) = B} ∪ {A→ǫ : A ∈ F} S = q0 Proposition L(A) = L(G).

Philippe de Groote Formal Languages 2018-2019 11 / 28

slide-19
SLIDE 19

Regular expressions and regular languages From FSA to type-3 grammars

From FSA to type-3 grammars

PROOF:

Philippe de Groote Formal Languages 2018-2019 12 / 28

slide-20
SLIDE 20

Regular expressions and regular languages From FSA to type-3 grammars

From FSA to type-3 grammars

PROOF: We prove by induction on the length of α that A ⇒∗ α if and only if ˆ δ(A, α) ∈ F.

Philippe de Groote Formal Languages 2018-2019 12 / 28

slide-21
SLIDE 21

Regular expressions and regular languages From FSA to type-3 grammars

From FSA to type-3 grammars

PROOF: We prove by induction on the length of α that A ⇒∗ α if and only if ˆ δ(A, α) ∈ F. Basis:

Philippe de Groote Formal Languages 2018-2019 12 / 28

slide-22
SLIDE 22

Regular expressions and regular languages From FSA to type-3 grammars

From FSA to type-3 grammars

PROOF: We prove by induction on the length of α that A ⇒∗ α if and only if ˆ δ(A, α) ∈ F. Basis: A ⇒∗ ǫ iff A ⇒ ǫ

Philippe de Groote Formal Languages 2018-2019 12 / 28

slide-23
SLIDE 23

Regular expressions and regular languages From FSA to type-3 grammars

From FSA to type-3 grammars

PROOF: We prove by induction on the length of α that A ⇒∗ α if and only if ˆ δ(A, α) ∈ F. Basis: A ⇒∗ ǫ iff A ⇒ ǫ iff (A→ǫ) ∈ P

Philippe de Groote Formal Languages 2018-2019 12 / 28

slide-24
SLIDE 24

Regular expressions and regular languages From FSA to type-3 grammars

From FSA to type-3 grammars

PROOF: We prove by induction on the length of α that A ⇒∗ α if and only if ˆ δ(A, α) ∈ F. Basis: A ⇒∗ ǫ iff A ⇒ ǫ iff (A→ǫ) ∈ P iff A ∈ F

Philippe de Groote Formal Languages 2018-2019 12 / 28

slide-25
SLIDE 25

Regular expressions and regular languages From FSA to type-3 grammars

From FSA to type-3 grammars

PROOF: We prove by induction on the length of α that A ⇒∗ α if and only if ˆ δ(A, α) ∈ F. Basis: A ⇒∗ ǫ iff A ⇒ ǫ iff (A→ǫ) ∈ P iff A ∈ F iff ˆ δ(A, ǫ) ∈ F

Philippe de Groote Formal Languages 2018-2019 12 / 28

slide-26
SLIDE 26

Regular expressions and regular languages From FSA to type-3 grammars

From FSA to type-3 grammars

Induction:

Philippe de Groote Formal Languages 2018-2019 13 / 28

slide-27
SLIDE 27

Regular expressions and regular languages From FSA to type-3 grammars

From FSA to type-3 grammars

Induction: A ⇒∗ aα′ iff A ⇒ aB ⇒∗ aα′, for some (A→aB) ∈ P

Philippe de Groote Formal Languages 2018-2019 13 / 28

slide-28
SLIDE 28

Regular expressions and regular languages From FSA to type-3 grammars

From FSA to type-3 grammars

Induction: A ⇒∗ aα′ iff A ⇒ aB ⇒∗ aα′, for some (A→aB) ∈ P iff (A→aB) ∈ P and B ⇒∗ α′

Philippe de Groote Formal Languages 2018-2019 13 / 28

slide-29
SLIDE 29

Regular expressions and regular languages From FSA to type-3 grammars

From FSA to type-3 grammars

Induction: A ⇒∗ aα′ iff A ⇒ aB ⇒∗ aα′, for some (A→aB) ∈ P iff (A→aB) ∈ P and B ⇒∗ α′ iff δ(A, a) = B and B ⇒∗ α′

Philippe de Groote Formal Languages 2018-2019 13 / 28

slide-30
SLIDE 30

Regular expressions and regular languages From FSA to type-3 grammars

From FSA to type-3 grammars

Induction: A ⇒∗ aα′ iff A ⇒ aB ⇒∗ aα′, for some (A→aB) ∈ P iff (A→aB) ∈ P and B ⇒∗ α′ iff δ(A, a) = B and B ⇒∗ α′ iff δ(A, a) = B and ˆ δ(B, α′) ∈ F by induction hypothesis

Philippe de Groote Formal Languages 2018-2019 13 / 28

slide-31
SLIDE 31

Regular expressions and regular languages From FSA to type-3 grammars

From FSA to type-3 grammars

Induction: A ⇒∗ aα′ iff A ⇒ aB ⇒∗ aα′, for some (A→aB) ∈ P iff (A→aB) ∈ P and B ⇒∗ α′ iff δ(A, a) = B and B ⇒∗ α′ iff δ(A, a) = B and ˆ δ(B, α′) ∈ F by induction hypothesis iff ˆ δ(δ(A, a), α′) ∈ F

Philippe de Groote Formal Languages 2018-2019 13 / 28

slide-32
SLIDE 32

Regular expressions and regular languages From FSA to type-3 grammars

From FSA to type-3 grammars

Induction: A ⇒∗ aα′ iff A ⇒ aB ⇒∗ aα′, for some (A→aB) ∈ P iff (A→aB) ∈ P and B ⇒∗ α′ iff δ(A, a) = B and B ⇒∗ α′ iff δ(A, a) = B and ˆ δ(B, α′) ∈ F by induction hypothesis iff ˆ δ(δ(A, a), α′) ∈ F iff ˆ δ(A, aα′) ∈ F

Philippe de Groote Formal Languages 2018-2019 13 / 28

slide-33
SLIDE 33

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

Consider α ∈ rexp(Σ)∗. One defines L(α) as follows: L(ǫ) = {ǫ} L(eα′) = L(e) · L(α′) We consider type-3 grammars whose set of terminal symbols is the set of regular expressions over some alphabet Σ: G = N, rexp(Σ), P, S

Philippe de Groote Formal Languages 2018-2019 14 / 28

slide-34
SLIDE 34

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

Consider α ∈ rexp(Σ)∗. One defines L(α) as follows: L(ǫ) = {ǫ} L(eα′) = L(e) · L(α′) We consider type-3 grammars whose set of terminal symbols is the set of regular expressions over some alphabet Σ: G = N, rexp(Σ), P, S For such grammars, one may define: LE(G) =

  • e∈L(G)

L(e)

Philippe de Groote Formal Languages 2018-2019 14 / 28

slide-35
SLIDE 35

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

Example:

Philippe de Groote Formal Languages 2018-2019 15 / 28

slide-36
SLIDE 36

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

Example: G = S → (a+b) S S → (c·d)

Philippe de Groote Formal Languages 2018-2019 15 / 28

slide-37
SLIDE 37

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

Example: G = S → (a+b) S S → (c·d) L(G) = {(c·d), (a+b)(c·d), (a+b)(a+b)(c·d), (a+b)(a+b)(a+b)(c·d), . . .}

Philippe de Groote Formal Languages 2018-2019 15 / 28

slide-38
SLIDE 38

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

Example: G = S → (a+b) S S → (c·d) L(G) = {(c·d), (a+b)(c·d), (a+b)(a+b)(c·d), (a+b)(a+b)(a+b)(c·d), . . .} LE(G) = {cd, acd, bcd, aacd, abcd, bacd, bbcd, aaacd, aabcd, abacd, . . .}

Philippe de Groote Formal Languages 2018-2019 15 / 28

slide-39
SLIDE 39

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

Example: G = S → (a+b) S S → (c·d) L(G) = {(c·d), (a+b)(c·d), (a+b)(a+b)(c·d), (a+b)(a+b)(a+b)(c·d), . . .} LE(G) = {cd, acd, bcd, aacd, abcd, bacd, bbcd, aaacd, aabcd, abacd, . . .} Remark: Since Σ ⊂ rexp(Σ), every grammar over Σ may be seen as a grammar

  • ver rexp(Σ), with LE(G) = L(G).

Philippe de Groote Formal Languages 2018-2019 15 / 28

slide-40
SLIDE 40

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

Elimination of non-recursive non-terminal symbols

Philippe de Groote Formal Languages 2018-2019 16 / 28

slide-41
SLIDE 41

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

Elimination of non-recursive non-terminal symbols Given a type-3 grammar G, one says that a rule is recursive if it is of the form A → aA. A non-terminal symbol A is said to be recursive in case there is at least one recursive rule whose lefthand side is A.

Philippe de Groote Formal Languages 2018-2019 16 / 28

slide-42
SLIDE 42

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

Elimination of non-recursive non-terminal symbols Given a type-3 grammar G, one says that a rule is recursive if it is of the form A → aA. A non-terminal symbol A is said to be recursive in case there is at least one recursive rule whose lefthand side is A. Let G1 = N1, rexp(Σ), P1, S1 be a type-3 grammar, and let A ∈ N1 be a non-recursive non-terminal symbol different from S.

Philippe de Groote Formal Languages 2018-2019 16 / 28

slide-43
SLIDE 43

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

Elimination of non-recursive non-terminal symbols Given a type-3 grammar G, one says that a rule is recursive if it is of the form A → aA. A non-terminal symbol A is said to be recursive in case there is at least one recursive rule whose lefthand side is A. Let G1 = N1, rexp(Σ), P1, S1 be a type-3 grammar, and let A ∈ N1 be a non-recursive non-terminal symbol different from S. Let PA = {A→e0B0, . . . , A→em−1Bm−1, A→f0, . . . , A→fn−1} ⊂ P1 be the set of all the production rules whose lefthand side is A.

Philippe de Groote Formal Languages 2018-2019 16 / 28

slide-44
SLIDE 44

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

Elimination of non-recursive non-terminal symbols Given a type-3 grammar G, one says that a rule is recursive if it is of the form A → aA. A non-terminal symbol A is said to be recursive in case there is at least one recursive rule whose lefthand side is A. Let G1 = N1, rexp(Σ), P1, S1 be a type-3 grammar, and let A ∈ N1 be a non-recursive non-terminal symbol different from S. Let PA = {A→e0B0, . . . , A→em−1Bm−1, A→f0, . . . , A→fn−1} ⊂ P1 be the set of all the production rules whose lefthand side is A. Let QA = {C0 →a0A, . . . , Cl−1 →al−1A} ⊂ P1 be the set of all the production rules whose righthand side contains A.

Philippe de Groote Formal Languages 2018-2019 16 / 28

slide-45
SLIDE 45

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

Elimination of non-recursive non-terminal symbols Given a type-3 grammar G, one says that a rule is recursive if it is of the form A → aA. A non-terminal symbol A is said to be recursive in case there is at least one recursive rule whose lefthand side is A. Let G1 = N1, rexp(Σ), P1, S1 be a type-3 grammar, and let A ∈ N1 be a non-recursive non-terminal symbol different from S. Let PA = {A→e0B0, . . . , A→em−1Bm−1, A→f0, . . . , A→fn−1} ⊂ P1 be the set of all the production rules whose lefthand side is A. Let QA = {C0 →a0A, . . . , Cl−1 →al−1A} ⊂ P1 be the set of all the production rules whose righthand side contains A. Define RA =

i∈l(( j∈m{Ci → (ai · ej)Bj}) ∪ ( j∈n{Ci → (ai · fj)}))

Philippe de Groote Formal Languages 2018-2019 16 / 28

slide-46
SLIDE 46

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

One defines a new grammar G2 = N2, rexp(Σ), P2, S2 as follows: N2 = N1 \ {A} P2 = (P \ (PA ∪ QA)) ∪ RA S2 = S1

Philippe de Groote Formal Languages 2018-2019 17 / 28

slide-47
SLIDE 47

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

One defines a new grammar G2 = N2, rexp(Σ), P2, S2 as follows: N2 = N1 \ {A} P2 = (P \ (PA ∪ QA)) ∪ RA S2 = S1 Proposition LE(G1) = LE(G2).

Philippe de Groote Formal Languages 2018-2019 17 / 28

slide-48
SLIDE 48

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

PROOF:

Philippe de Groote Formal Languages 2018-2019 18 / 28

slide-49
SLIDE 49

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

PROOF: We prove that LE(G1) ⊂ LE(G2) and LE(G2) ⊂ LE(G1).

Philippe de Groote Formal Languages 2018-2019 18 / 28

slide-50
SLIDE 50

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

PROOF: We prove that LE(G1) ⊂ LE(G2) and LE(G2) ⊂ LE(G1). PART 1: LE(G1) ⊂ LE(G2)

Philippe de Groote Formal Languages 2018-2019 18 / 28

slide-51
SLIDE 51

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

PROOF: We prove that LE(G1) ⊂ LE(G2) and LE(G2) ⊂ LE(G1). PART 1: LE(G1) ⊂ LE(G2) Let us write ⇒1 and ⇒2 for the generation relations of G1 and G2,

  • respectively. We prove that for every B ∈ N2 and every α1 ∈ rexp(Σ)∗

such that B ⇒∗

1 α1, there exists α2 ∈ rexp(Σ)∗ such that B ⇒∗ 2 α2 and

L(α1) = L(α2). The proof proceed by induction on the number of

  • ccurences of rules from QA that appear in the derivation B ⇒∗

1 α1.

Philippe de Groote Formal Languages 2018-2019 18 / 28

slide-52
SLIDE 52

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

PROOF: We prove that LE(G1) ⊂ LE(G2) and LE(G2) ⊂ LE(G1). PART 1: LE(G1) ⊂ LE(G2) Let us write ⇒1 and ⇒2 for the generation relations of G1 and G2,

  • respectively. We prove that for every B ∈ N2 and every α1 ∈ rexp(Σ)∗

such that B ⇒∗

1 α1, there exists α2 ∈ rexp(Σ)∗ such that B ⇒∗ 2 α2 and

L(α1) = L(α2). The proof proceed by induction on the number of

  • ccurences of rules from QA that appear in the derivation B ⇒∗

1 α1.

Basis:

Philippe de Groote Formal Languages 2018-2019 18 / 28

slide-53
SLIDE 53

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

PROOF: We prove that LE(G1) ⊂ LE(G2) and LE(G2) ⊂ LE(G1). PART 1: LE(G1) ⊂ LE(G2) Let us write ⇒1 and ⇒2 for the generation relations of G1 and G2,

  • respectively. We prove that for every B ∈ N2 and every α1 ∈ rexp(Σ)∗

such that B ⇒∗

1 α1, there exists α2 ∈ rexp(Σ)∗ such that B ⇒∗ 2 α2 and

L(α1) = L(α2). The proof proceed by induction on the number of

  • ccurences of rules from QA that appear in the derivation B ⇒∗

1 α1.

Basis: There is no occurence of any rule from QA in the derivation B ⇒∗

1 α1.

Then, there is no occurrence of any rule from PA either. Consequently, the derivation B ⇒∗

1 α1 is also a derivation of G2, and we take α2 = α1.

Philippe de Groote Formal Languages 2018-2019 18 / 28

slide-54
SLIDE 54

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

Induction:

Philippe de Groote Formal Languages 2018-2019 19 / 28

slide-55
SLIDE 55

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

Induction: If there is at least one occurence of a rule from QA in the derivation B ⇒∗

1 α1, it must obey one of the two following forms:

(1) B ⇒∗

1 βCi ⇒1 βaiA ⇒1 βaiejBj ⇒∗ 1 βaiejγ1

(2) B ⇒∗

1 βCi ⇒1 βaiA ⇒1 βaifj

where the occurrence of (Ci →aiA) ∈ QA is the leftmost occurrence of a rule from QA. Consequently, B ⇒∗

1 βCi is also a derivation of G2.

Philippe de Groote Formal Languages 2018-2019 19 / 28

slide-56
SLIDE 56

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

Induction: If there is at least one occurence of a rule from QA in the derivation B ⇒∗

1 α1, it must obey one of the two following forms:

(1) B ⇒∗

1 βCi ⇒1 βaiA ⇒1 βaiejBj ⇒∗ 1 βaiejγ1

(2) B ⇒∗

1 βCi ⇒1 βaiA ⇒1 βaifj

where the occurrence of (Ci →aiA) ∈ QA is the leftmost occurrence of a rule from QA. Consequently, B ⇒∗

1 βCi is also a derivation of G2.

In the first case, we have α1 = βaiejγ1 and Bj ⇒∗

1 γ1. By induction

hypothesis, there exists γ2 ∈ rexp(Σ)∗ such that Bj ⇒∗

2 γ2 and

L(γ1) = L(γ2). Hence: B ⇒∗

2 βCi ⇒2 β(ai · ej)Bj ⇒∗ 2 β(ai · ej)γ2

Then, we take α2 = β(ai · ej)γ2. Indeed L(α1) = L(βaiejγ1) = L(β)L(ai)L(ej)L(γ1) = L(β)L(ai · ej)L(γ2) = L(β(ai · ej)γ2) = L(α2)

Philippe de Groote Formal Languages 2018-2019 19 / 28

slide-57
SLIDE 57

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

In the second case, we have α1 = βaifj. Then, we take α2 = β(ai · fj) Indeed, we have that B ⇒∗

2 βCi ⇒2 β(ai · fj)

and that L(βaifj) = L(β(ai · fj)).

Philippe de Groote Formal Languages 2018-2019 20 / 28

slide-58
SLIDE 58

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

In the second case, we have α1 = βaifj. Then, we take α2 = β(ai · fj) Indeed, we have that B ⇒∗

2 βCi ⇒2 β(ai · fj)

and that L(βaifj) = L(β(ai · fj)). PART 2: LE(G2) ⊂ LE(G1)

Philippe de Groote Formal Languages 2018-2019 20 / 28

slide-59
SLIDE 59

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

In the second case, we have α1 = βaifj. Then, we take α2 = β(ai · fj) Indeed, we have that B ⇒∗

2 βCi ⇒2 β(ai · fj)

and that L(βaifj) = L(β(ai · fj)). PART 2: LE(G2) ⊂ LE(G1) We prove that for every B ∈ N2 and every α2 ∈ rexp(Σ)∗ such that B ⇒∗

2 α2, there exists α1 ∈ rexp(Σ)∗ such that B ⇒∗ 1 α1 and

L(α2) = L(α1). The proof, which proceed by induction on the number of

  • ccurences of rules from RA that appear in the derivation B ⇒∗

2 α2, is

similar to the proof of Part 1.

Philippe de Groote Formal Languages 2018-2019 20 / 28

slide-60
SLIDE 60

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

Elimination of recursive rules

Philippe de Groote Formal Languages 2018-2019 21 / 28

slide-61
SLIDE 61

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

Elimination of recursive rules Let G1 = N1, rexp(Σ), P1, S1 be a type-3 grammar, and let A ∈ N1 be a recursive non-terminal symbol different from S.

Philippe de Groote Formal Languages 2018-2019 21 / 28

slide-62
SLIDE 62

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

Elimination of recursive rules Let G1 = N1, rexp(Σ), P1, S1 be a type-3 grammar, and let A ∈ N1 be a recursive non-terminal symbol different from S. Let PA = {A→e0B0, . . . , A→el−1Bl−1, A→f0, . . . , A→fm−1} ⊂ P1 be the set of all the non-recursive production rules whose lefthand side is A.

Philippe de Groote Formal Languages 2018-2019 21 / 28

slide-63
SLIDE 63

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

Elimination of recursive rules Let G1 = N1, rexp(Σ), P1, S1 be a type-3 grammar, and let A ∈ N1 be a recursive non-terminal symbol different from S. Let PA = {A→e0B0, . . . , A→el−1Bl−1, A→f0, . . . , A→fm−1} ⊂ P1 be the set of all the non-recursive production rules whose lefthand side is A. Let QA = {A→g0A, . . . , A→gn−1A} ⊂ P1 be the set of all the recursive production rules whose lefthand side is A.

Philippe de Groote Formal Languages 2018-2019 21 / 28

slide-64
SLIDE 64

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

Elimination of recursive rules Let G1 = N1, rexp(Σ), P1, S1 be a type-3 grammar, and let A ∈ N1 be a recursive non-terminal symbol different from S. Let PA = {A→e0B0, . . . , A→el−1Bl−1, A→f0, . . . , A→fm−1} ⊂ P1 be the set of all the non-recursive production rules whose lefthand side is A. Let QA = {A→g0A, . . . , A→gn−1A} ⊂ P1 be the set of all the recursive production rules whose lefthand side is A. Define RA = (

i∈l{A → ((g0+ · · · +gn−1)∗·ei)Bi}) ∪

(

i∈m{A → ((g0+ · · · +gn−1)∗·fi)})

Philippe de Groote Formal Languages 2018-2019 21 / 28

slide-65
SLIDE 65

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

One defines a new grammar G2 = N2, rexp(Σ), P2, S2 as follows: N2 = N1 P2 = (P \ (PA ∪ QA)) ∪ RA S2 = S1

Philippe de Groote Formal Languages 2018-2019 22 / 28

slide-66
SLIDE 66

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

One defines a new grammar G2 = N2, rexp(Σ), P2, S2 as follows: N2 = N1 P2 = (P \ (PA ∪ QA)) ∪ RA S2 = S1 Proposition LE(G1) = LE(G2).

Philippe de Groote Formal Languages 2018-2019 22 / 28

slide-67
SLIDE 67

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

PROOF:

Philippe de Groote Formal Languages 2018-2019 23 / 28

slide-68
SLIDE 68

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

PROOF: PART 1: LE(G1) ⊂ LE(G2)

Philippe de Groote Formal Languages 2018-2019 23 / 28

slide-69
SLIDE 69

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

PROOF: PART 1: LE(G1) ⊂ LE(G2) We prove that for every B ∈ N1 and every α1 ∈ rexp(Σ)∗ such that B ⇒∗

1 α1, there exists α2 ∈ rexp(Σ)∗ such that B ⇒∗ 2 α2 and

L(α1) ⊂ L(α2). The proof proceed by induction on the number of

  • ccurences of rules from PA that appear in the derivation B ⇒∗

1 α1.

Philippe de Groote Formal Languages 2018-2019 23 / 28

slide-70
SLIDE 70

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

PROOF: PART 1: LE(G1) ⊂ LE(G2) We prove that for every B ∈ N1 and every α1 ∈ rexp(Σ)∗ such that B ⇒∗

1 α1, there exists α2 ∈ rexp(Σ)∗ such that B ⇒∗ 2 α2 and

L(α1) ⊂ L(α2). The proof proceed by induction on the number of

  • ccurences of rules from PA that appear in the derivation B ⇒∗

1 α1.

Basis:

Philippe de Groote Formal Languages 2018-2019 23 / 28

slide-71
SLIDE 71

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

PROOF: PART 1: LE(G1) ⊂ LE(G2) We prove that for every B ∈ N1 and every α1 ∈ rexp(Σ)∗ such that B ⇒∗

1 α1, there exists α2 ∈ rexp(Σ)∗ such that B ⇒∗ 2 α2 and

L(α1) ⊂ L(α2). The proof proceed by induction on the number of

  • ccurences of rules from PA that appear in the derivation B ⇒∗

1 α1.

Basis: There is no occurence of any rule from PA in the derivation B ⇒∗

1 α1.

Then, there is no occurrence of any rule from QA either. Consequently, the derivation B ⇒∗

1 α1 is also a derivation of G2, and we take α2 = α1.

Philippe de Groote Formal Languages 2018-2019 23 / 28

slide-72
SLIDE 72

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

Induction:

Philippe de Groote Formal Languages 2018-2019 24 / 28

slide-73
SLIDE 73

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

Induction: If there is at least one occurence of a rule from PA in the derivation B ⇒∗

1 α1, it must obey one of the two following forms:

(1) B ⇒∗

1 βA ⇒1 βgi0A ⇒1 · · · ⇒1 βgi0 . . . gik−1A

⇒1 βgi0 . . . gik−1eiBi ⇒1 βgi0 . . . gik−1eiγ1 (2) B ⇒∗

1 βA ⇒1 βgi0A ⇒1 · · · ⇒1 βgi0 . . . gik−1A

⇒1 βgi0 . . . gik−1fi where the occurrence of (A→eiBi) ∈ PA (respectively, (A→fi) ∈ PA) is the leftmost occurrence of a rule from PA, and the occurrence of (A→gi0A) ∈ QA is the leftmost occurrence of a rule from QA. Consequently, B ⇒∗

1 βA is also a derivation of G2.

Philippe de Groote Formal Languages 2018-2019 24 / 28

slide-74
SLIDE 74

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

In the first case, we have α1 = βgi0 . . . gik−1eiγ1 and Bi ⇒∗

1 γ1. By

induction hypothesis, there exists γ2 ∈ rexp(Σ)∗ such that Bi ⇒∗

2 γ2 and

L(γ1) ⊂ L(γ2). Hence: B ⇒∗

2 βA ⇒2 β((g0+ · · · +gn−1)∗·ei)Bi ⇒2 β((g0+ · · · +gn−1)∗·ei)γ2

Then, we take α2 = β((g0+ · · · +gn−1)∗·ei)γ2 Indeed L(α1) ⊂ L(α2) because L(gi0 . . . gik−1) ⊂ L((g0+ · · · +gn−1)∗) and L(α1) ⊂ L(α2)

Philippe de Groote Formal Languages 2018-2019 25 / 28

slide-75
SLIDE 75

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

In the first case, we have α1 = βgi0 . . . gik−1eiγ1 and Bi ⇒∗

1 γ1. By

induction hypothesis, there exists γ2 ∈ rexp(Σ)∗ such that Bi ⇒∗

2 γ2 and

L(γ1) ⊂ L(γ2). Hence: B ⇒∗

2 βA ⇒2 β((g0+ · · · +gn−1)∗·ei)Bi ⇒2 β((g0+ · · · +gn−1)∗·ei)γ2

Then, we take α2 = β((g0+ · · · +gn−1)∗·ei)γ2 Indeed L(α1) ⊂ L(α2) because L(gi0 . . . gik−1) ⊂ L((g0+ · · · +gn−1)∗) and L(α1) ⊂ L(α2) Similarly, in the second case, we have B ⇒∗

2 βA ⇒2 β((g0+ · · · +gn−1)∗·fi)

And, we take α2 = β((g0+ · · · +gn−1)∗·fi)

Philippe de Groote Formal Languages 2018-2019 25 / 28

slide-76
SLIDE 76

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

PART 2: LE(G2) ⊂ LE(G1)

Philippe de Groote Formal Languages 2018-2019 26 / 28

slide-77
SLIDE 77

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

PART 2: LE(G2) ⊂ LE(G1) We prove that for every B ∈ N2, every α2 ∈ rexp(Σ)∗ such that B ⇒∗

2 α2, and every ω ∈ L(α2), there exists α1 ∈ rexp(Σ)∗ such that

B ⇒∗

1 α1 and ω ∈ L(α1). The proof proceed by induction on the number

  • f occurences of rules from RA that appear in the derivation B ⇒∗

2 α2.

Philippe de Groote Formal Languages 2018-2019 26 / 28

slide-78
SLIDE 78

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

PART 2: LE(G2) ⊂ LE(G1) We prove that for every B ∈ N2, every α2 ∈ rexp(Σ)∗ such that B ⇒∗

2 α2, and every ω ∈ L(α2), there exists α1 ∈ rexp(Σ)∗ such that

B ⇒∗

1 α1 and ω ∈ L(α1). The proof proceed by induction on the number

  • f occurences of rules from RA that appear in the derivation B ⇒∗

2 α2.

Basis:

Philippe de Groote Formal Languages 2018-2019 26 / 28

slide-79
SLIDE 79

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

PART 2: LE(G2) ⊂ LE(G1) We prove that for every B ∈ N2, every α2 ∈ rexp(Σ)∗ such that B ⇒∗

2 α2, and every ω ∈ L(α2), there exists α1 ∈ rexp(Σ)∗ such that

B ⇒∗

1 α1 and ω ∈ L(α1). The proof proceed by induction on the number

  • f occurences of rules from RA that appear in the derivation B ⇒∗

2 α2.

Basis: There is no occurence of any rule from RA in the derivation B ⇒∗

2 α2.

Consequently, the derivation B ⇒∗

2 α2 is also a derivation of G1, and we

take α1 = α2.

Philippe de Groote Formal Languages 2018-2019 26 / 28

slide-80
SLIDE 80

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

Induction:

Philippe de Groote Formal Languages 2018-2019 27 / 28

slide-81
SLIDE 81

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

Induction: If there is at least one occurence of a rule from RA in the derivation B ⇒∗

2 α2, it must obey one of the two following forms:

(1) B ⇒∗

2 βA ⇒2 β((g0+ · · · +gn−1)∗·ei)Bi ⇒2 β((g0+ · · · +gn−1)∗·ei)γ2

(2) B ⇒∗

2 βA ⇒2 β((g0+ · · · +gn−1)∗·fi)

where the occurrence of (A→((g0+ · · · +gn−1)∗·ei)Bi) ∈ RA (respectively, (A→((g0+ · · · +gn−1)∗·fi)) ∈ RA) is the leftmost

  • ccurrence of a rule from RA. Consequently, B ⇒∗

2 βA is also a derivation

  • f G1.

Philippe de Groote Formal Languages 2018-2019 27 / 28

slide-82
SLIDE 82

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

In the first case, we have α2 = β((g0+ · · · +gn−1)∗·ei)γ2 and Bi ⇒∗

2 γ2.

Now, let ω ∈ L(α2). It must obey the following form: ω = ω1gi0 . . . gik−1ω2ω3 where: ω1 ∈ L(β); the sequence of gi’s is possibly empty; ω2 ∈ L(ei); ω3 ∈ L(γ2). By induction hypothesis, there exists γ1 ∈ rexp(Σ)∗ such that Bi ⇒∗

1 γ1

and ω3 ∈ L(γ1). Then, we take α1 = βgi0 . . . gik−1eiγ2 Indeed B ⇒∗

1 βA ⇒1 βgi0A ⇒1 · · · ⇒1 βgi0 . . . gik−1A

⇒1 βgi0 . . . gik−1eiBi ⇒1 βgi0 . . . gik−1eiγ1

Philippe de Groote Formal Languages 2018-2019 28 / 28

slide-83
SLIDE 83

Regular expressions and regular languages From type-3 grammars to regular expressions

From type-3 grammars to regular expressions

In the first case, we have α2 = β((g0+ · · · +gn−1)∗·ei)γ2 and Bi ⇒∗

2 γ2.

Now, let ω ∈ L(α2). It must obey the following form: ω = ω1gi0 . . . gik−1ω2ω3 where: ω1 ∈ L(β); the sequence of gi’s is possibly empty; ω2 ∈ L(ei); ω3 ∈ L(γ2). By induction hypothesis, there exists γ1 ∈ rexp(Σ)∗ such that Bi ⇒∗

1 γ1

and ω3 ∈ L(γ1). Then, we take α1 = βgi0 . . . gik−1eiγ2 Indeed B ⇒∗

1 βA ⇒1 βgi0A ⇒1 · · · ⇒1 βgi0 . . . gik−1A

⇒1 βgi0 . . . gik−1eiBi ⇒1 βgi0 . . . gik−1eiγ1 The second case, is similar.

Philippe de Groote Formal Languages 2018-2019 28 / 28