Strings, Languages, and Regular expressions
Lecture 2
1
Strings, Languages, and Regular expressions Lecture 2 1 Strings - - PowerPoint PPT Presentation
Strings, Languages, and Regular expressions Lecture 2 1 Strings 2 Definitions for strings e.g., = {0,1}, = { , , , } , = set of ascii characters alphabet = finite set of symbols string = finite
1
2
CS 374
3
e.g., Σ = {0,1}, Σ = {α, β, …, ω}, Σ = set of ascii characters |cat|=3 |ε| = ?
Could formalize as a function w: [n]→Σ where |w| = n
CS 374
4
CS 374
5
If |x|=m, |y|=n xy : [m+n]→ Σ such that xy(i) = x(i) if i≤m xy(i) = y(i-m) else
CS 374
6
CS 374
7
CS 374
8
CS 374
9
CS 374
10
This can be the formal definition of a “string”
CS 374
11
CS 374
12
1 ε 2 1 3 1 1 4 00 2 5 01 2 6 10 2 7 11 2 8 000 3 9 001 3 10 010 3 11 011 3 12 100 3 13 101 3 14 110 3 15 111 3 16 1000 4 17 1001 4 18 1010 4 19 1011 4 20 1100 4
CS 374
13
a ∈ Σ, u ∈ Σ* Well-defined: |u|<|w|
CS 374
14
Definition of Reversal: base-case
CS 374
15
Definition of Reversal: inductive-case Inductive Hypothesis: |w|<n Definition of Reversal: inductive-case
16
CS 374
17
CS 374
with the set of strings mapped to 1
– Computational problem for a language: given a string in Σ*, decide if it belongs to the language
set of strings of odd length, set of strings encoding valid C programs, set of strings encoding valid C programs that halt, …
each language has countably many strings)
18
1 ε 2 3 1 1 4 00 5 01 1 6 10 1 7 11 8 000 9 001 1 10 010 1 11 011 12 100 1 13 101 14 110 15 111 1 16 1000 1 17 1001 18 1010 19 1011 1 20 1100
CS 374
19
CS 374
20
21
CS 374
22
CS 374
23
CS 374
24
25
CS 374
26
* The star named after him is the Kleene star “*”
CS 374
27
Atomic expressions (Base cases)
Inductively defined expressions
alt notation (r1|r2) or (r1∪r2)
CS 374
28
CS 374
29
CS 374
30
31
CS 374
32
will show impossible!
CS 374
33
CS 374
34
CS 374
35
CS 374
36