Regular Expressions I Example (0 1)0 This is a simplification of - - PowerPoint PPT Presentation

regular expressions i
SMART_READER_LITE
LIVE PREVIEW

Regular Expressions I Example (0 1)0 This is a simplification of - - PowerPoint PPT Presentation

Regular Expressions I Example (0 1)0 This is a simplification of ( { 0 } { 1 } ) { 0 } Regular expressions are practically useful Example: finding lines in a file containing a or b egrep (a|b) file


slide-1
SLIDE 1

Regular Expressions I

Example (0 ∪ 1)0∗ This is a simplification of ({0} ∪ {1}) ◦ {0}∗ Regular expressions are practically useful Example: finding lines in a file containing “a” or “b” egrep ’(a|b)’ file

September 18, 2020 1 / 13

slide-2
SLIDE 2

Regular Expressions II

Formally this means we consider the language Σ∗aΣ∗ ∪ Σ∗bΣ∗ Σ∗: all strings over Σ Example (0 ∪ 1)∗ all strings by 0 and 1 Example: (0Σ∗) ∪ (Σ∗1) all strings start with 0 or end with 1

September 18, 2020 2 / 13

slide-3
SLIDE 3

Formal definition of regular expression I

R is a regular expression if it is one of the following expressions

1

a, where a ∈ Σ

2

ǫ (ǫ / ∈ Σ)

3

4

R1 ∪ R2, where R1, R2 are regular expressions

5

R1 ◦ R2, where R1, R2 are regular expressions

6

R∗

1, where R1 is a regular expression

∅ and ǫ ǫ: empty string

September 18, 2020 3 / 13

slide-4
SLIDE 4

Formal definition of regular expression II

∅: empty language (language without any string) (0 ∪ ǫ)1∗ = 01∗ ∪ 1∗ (0 ∪ ∅)1∗ = 01∗ ∅1∗ = 1∗∅ = ∅ Concatenating 1∗ with nothing ⇒ nothing We have an inductive definition An expression is constructed from smaller strings

September 18, 2020 4 / 13

slide-5
SLIDE 5

Examples I

0∗10∗: strings with exactly one 1 (ΣΣ)∗: strings with even length Assume Σ = {0, 1} 0Σ∗0 ∪ 1Σ∗1 ∪ 0 ∪ 1 Strings that start and end with the same symbol ∅∗ = {ǫ} R ∪ ∅ = R R ◦ ǫ = R

September 18, 2020 5 / 13

slide-6
SLIDE 6

Floating number in language I

(+ ∪ − ∪ ǫ)(DD∗ ∪ DD∗.D∗ ∪ D∗.DD∗), where D = {0, . . . , 9} 72, 2.1, 7., -.01 72 ∈ DD∗ 2.1 ∈ DD∗.D∗

  • 7. ∈ DD∗.D∗

.01 ∈ D∗.DD∗

September 18, 2020 6 / 13

slide-7
SLIDE 7

Floating number in language II

Why not D∗.D∗ . is not allowed

September 18, 2020 7 / 13

slide-8
SLIDE 8

Equivalence with finite automata I

They have equivalent descriptive power language regular ⇔ described by regular expression

September 18, 2020 8 / 13

slide-9
SLIDE 9

Lemma 1.55 I

Language by a regular expression ⇒ regular (described by an automaton) The proof is by induction. We go through all cases in the definition R = a ∈ Σ Can such a language be recognized by an NFA? This language has only one string and can be recognized by a

September 18, 2020 9 / 13

slide-10
SLIDE 10

Lemma 1.55 II

Note that this is an NFA. Formal definition: N = ({q1, q2}, Σ, δ, q1, {q2}) δ(q1, a) = {q2} δ(r, b) = ∅, r = q1 or b = a R = ǫ

September 18, 2020 10 / 13

slide-11
SLIDE 11

Lemma 1.55 III

Formal definition N = ({q1}, Σ, δ, q1, {q1}) δ(q1, a) = ∅, ∀a R = ∅

September 18, 2020 11 / 13

slide-12
SLIDE 12

Lemma 1.55 IV

Formal definition N = ({q}, Σ, δ, q, ∅) δ(r, a) = ∅, ∀r, a Note: earlier we only say F ⊂ Q, so F can be ∅ For the other three situations R = R1 ∪ R2 R = R1 ◦ R2 R = R∗

1

we use the proof in NFAs

September 18, 2020 12 / 13

slide-13
SLIDE 13

Lemma 1.55 V

We will see details by an example

September 18, 2020 13 / 13