You are on page 1of 13

Languages

Lecture 2
Introduction to defining languages
 Today, we will begin with only one finite set of fundamental
units out of which we build structures, it is called alphabet.
 A certain specified set of strings of characters from the
alphabet is called the language.
 The strings which are permissible in the language are called
words.
 We shall allow a string to have no letters. This we call the
empty string or null string and denote with the symbol Λ.
 Lets start with an alphabet having only one letter, the ‘x’
 Σ = {x}
 L1 = {x xx xxx xxxx ……..}
 Or L1 = {xn for n = 1 2 3 4…..}
 Similarly L2 = {x xxx xxxxx xxxxxxx ……….}
 L2 = {x2n+1 for n = 0 1 2 3 4……..}
Alphabets
Definition
• A finite non-empty set of symbols (called letters),
is called an alphabet. It is denoted by ∑ ( Greek
letter sigma).
• Example
• ∑ = {a,b}
• ∑ = {0,1} (important as this is the language which
the computer understands.)
• ∑ = {i,j,k}
Strings

• Definition
• Concatenation of finite number of letters from
the alphabet is called a string.
• Example
• If ∑ = {a,b} then
• a, abab, aaabb, ababababababababab
Word
• Definition: Those strings that are permissible in
the language L are called words of the language L.
• Remarks:
• A language is just a specific collection of strings.
• We will use the words string and word
interchangeably.
• Thus, for a given string w and a particular
language L, we might call w, a word even if it is
not in the language L.
Concatenation of strings
• Definition: Given two strings w1 and w2, we define the
concatenation of w1 and w2 to be the string w1w2.
• Examples:
• If w1 = xx and w2 = x, then w1w2 = xxx.
• If w1 = abb and w2 = ab, then w1w2 = abbab and w2w1 =
ababb.
• If w1 = and w2 = ab, then w1w2 = ab.
• If w1 = bb and w2 = , then w1w2 = bb.
• If w1 = Λ and w2 = Λ , then w1w2 = Λ Λ ; i.e., Λ Λ = Λ.
Formal Language
• Definition:
• A formal language L is a set of strings over an alphabet for which
there are explicit rules for the strings in the set. Throughout these
notes, we will only consider formal languages, and so we will
simplify the discussion by saying language instead of formal
language.

• Examples:
• Computer languages, e.g., C or C++ or Java, are formal languages
with alphabet = { a, b, . . . , z, A, B, . . . , Z, , 0, 1, 2, . . . , 9, >, <, =, +, -
, *, /, (, ), ., ,, &, !, %, ^, {, }, |, ’, :, ; }. The rules of syntax define the
rules for the language.
• The set of valid variable names in C++ is a formal language. What
are the alphabet and rules defining valid variable names in C++?
Set Operations
• Membership operator
• Empty set
• Subset of a set
• Union of two sets
• Intersection of two sets
• Disjoint sets
• Difference of two sets
• Cardinality of a set
• Cartesian Product
• Concatenation of sets
• Power set
Length and Reverse of a string and Palindrome
 We define the length of the string to be the number of letters in
the string.
 If a = xxxx then length(a) = 4
 Length(428) = 3
 Length(Λ) = 0
 If ‘a’ is a word in some language L, then reverse(a) is the same
string of letters spelled backward, called the reverse of ‘a’.
 Reverse(xxx) = xxx (Palindrome)
 Reverse(420) = 024 (Not a Palindrome)
 If Σ = { a b} then PALINDROME = { Λ, and all strings x
such that reverse(x) = x}
 PALINDROME = {Λ a b aa bb aaa aba bab bbb
aaaa abba………}
 This language has some very interesting properties which
we will examine later.
KLEENE CLOSURE
 Given an alphabet Σ, we wish to define a language in which
any string of letters from Σ is a word, even the null string
 This is called closure of the alphabet and denoted by Σ*
 This notation is sometimes known as Kleene star after the
name of the logician, who was one of the founders of this
subject.
 If Σ = {x}, then
 Σ* = L1 = {Λ x xx xxx xxxx……….}
 If Σ = {0 1} then
 Σ* = L2 = {Λ 0 1 00 01 10 11 000 001…….}
 If Σ = {a b c} then
 Σ* = L3 = {Λ a b c aa ab ac ba bb bc ca cb cc
aaa …..}
KLEENE CLOSURE
 If S is a set of words, then by S*, we mean the set of all finite
string formed by concatenating words from S, where null string
is also included.
 If S = {aa b} then
 S* = { Λ plus any word composed of factors of aa and b}
 S* = { Λ b aa bb aab baa bbb aaaa aabb baab bbaa
bbbb aaaab ……..}
 If we wish to modify the concept of closure to refer to only the
concatenation of some (non-zero) strings from a set S, we use
the notation + instead of *
 If Σ = {x} then
 Σ+ = {x xx xxx xxxx ………}
Example
• Let S = { a, ab }. Then

S* = {^ plus any word composed of factors of a


and ab}
= {^ plus all strings of a's and b's except those
that start with b and those that contain a double
b}
= {^ a aa ab aaa aab aaaa aaab aaba abaa abab
aaaaa aaaab aaaba aabaa aabab abaaa abaab
ababa... }

You might also like