Toa Handout 2
Toa Handout 2
Handout no 2
1
Courtesy Costas Busch - RPI 2
Languages
3
Language
• Informal language
• Incoherent strings are also
understandable
• Like idiom
• Raise ambiguity
– Interpretation varies with region
– Same words have multiple meanings.
• Like, light, base, etc.
Informal languages
– List of words
• Set of all valid words of a given language,
e.g., a language English_Words that contains
all valid words of English would have a =
{all entries of the dictionary + punctuation
marks and blank space….}
• Denoted by
• Strings: A string a finite sequence of symbols
chosen from alphabet. For example
0111100 , 123045, abbbcdeg etc.
• String Variable: A letter used for
denoting a string. The author uses w, x, y
and z as string variable. For example
w = 0111100 , x = 123045, z =
abbbcdeg
• Length of String: The number of
positions for symbols in the string. For
simplicity we can say that it is the
number of symbols in the string. For
example
|w| = 7 , |x| = ? , |z| = ?
Finite vs. Infinite Languages
• Finite Languages
– Countable set of words
– Can be defined by rigorously listing the
words in
– E.g. English-Words
• Infinite Languages
– Infinite set of valid words
– Cant be listed completely
– E.g. English_Sentences
Infinite Languages
• Most of the languages are infinite
• How can u check whether a word
belongs to a language if it is
– Finite
• Checking its entry in
– Infinite
• Validating against rules
Defining Languages
• Define alphabet set
• Define rules for forming valid words and
sequences of words from
– Called grammar
– Can be descriptive
– Can be mathematical
• Can also define supporting functions e.g.,
length(X), reverse(x)
Defining languages
• Example ={a,b,…z}
– L = {all words formed only of odd number
of xs}
– L = {xn | n is odd}
– L = {all words of length less than or equal
to 4}
– PALINDROME ={Λ, all strings x such that
reverse (x) = x}
Kleene Closure
• Set closure
• Kleene Closure (applied to )
– A set of all the strings (finite) that can be
formed by the elements of where the
elements may be repeated any number of
times.
– Denoted by *
– Also called Kleene star.
• ∑* : The set of all strings over an
alphabet ∑ and called Kleene Star
Closure of alphabet. So we have
∑* = ∑0 U ∑1 U ∑2 U ∑3 U……………
• ∑+ : The set of all strings over an
alphabet ∑ excluding empty string, ε,
and called plus operation. So we
have
∑+ = ∑1 U ∑2 U ∑3 U……………
Some observations
• Λ represents an empty string (not
alphabet thus not a part of )
• ε also represents the same
• ε is not equivalent to
• If = then
* = {Λ}
• Is S* == (S*)* and so on
Alphabets and Strings
We will use small alphabets: a, b
Strings
a
ab u ab
abba v bbbaaa
baba w abba
aaabbbaabab
22
String Operations
w a1a2 an abba
v b1b2 bm bbbaaa
Concatenation
23
w a1a2 an ababaaabbb
Reverse
R
w an a2 a1 bbbaaababa
24
String Length
w a1a2 an
Length: w n
Examples: abba 4
aa 2
a 1
25
Length of Concatenation
uv u v
Example: u aab, u 3
v abaab, v 5
uv aababaab 8
uv u v 3 5 8
26
Empty String
A string with no letters: ,
Observations: 0
w w w
String Substring
abbab ab
abbab abba
abbab b
abbab bbab
28
Prefix and Suffix
abbab
Prefixes Suffixes
abbab w uv
a bbab
prefix
ab bab
suffix
abb ab
abba b
abbab
29
Another Operation
n
w ww
w
n
2
Example: abba abbaabba
0
Definition: w
0
abba
30
The * Operation
* : the set of all possible strings from
alphabet
a, b
* , a, b, aa, ab, ba, bb, aaa, aab,
31
The + Operation
: the set of all possible strings from
alphabet except
a, b
* , a, b, aa, ab, ba, bb, aaa, aab,
*
a, b, aa, ab, ba, bb, aaa, aab,
32
Languages
*
A language is any subset of
Example: a, b
* , a, b, aa, ab, ba, bb, aaa,
Languages:
Sets { } {}
Set size { } 0
n n
An infinite language L {a b : n 0}
ab
L abb L
aabb
aaaaabbbbb
35
Operations on Languages
The usual set operations
R R
Definition: L {w : w L}
n n
L {a b : n 0}
R n n
L {b a : n 0}
37
Concatenation
38
Another Operation
Definition: n
L LL L
n
3
a, b a, ba, ba, b
aaa, aab, aba, abb, baa, bab, bba, bbb
0
Special case: L
0 1 2
Definition: L* L L L
Example:
,
a, bb,
a, bb*
aa , abb, bba , bbbb,
aaa, aabb, abba, abbbb,
40
Positive Closure
1 2
Definition: L L L
L *
a, bb,
a, bb aa, abb, bba, bbbb,
aaa, aabb, abba, abbbb,
41