2. Languages - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

2. Languages

Description:

Let u = ab, v = ca, and w = bb, then uv = abca, vw = cabb (uv)w = abcabb u ... {ab}* Exercise : ... Exercise : Write a regular expression that represent the ... – PowerPoint PPT presentation

Number of Views:157
Avg rating:3.0/5.0
Slides: 19
Provided by: A2A
Category:
Tags: languages

less

Transcript and Presenter's Notes

Title: 2. Languages


1
2. Languages
2
2.1 Strings and Languages
  • A string over a set X is a finite sequence of
    element from X.
  • Strings are the fundamental objects used in the
    definition of languages
  • The strings are built by a set of elements called
    alphabet
  • An alphabet consists of a finite set of
    indivisible objects.
  • The alphabet of a language is donated S

3
  • Definition 2.1.1
  • Let S be an alphabet.
  • S, the set of string over S, is defined
    recursively as follows
  • i) Basis ? ? S.
  • ii) Recursive step if w ? S and a ? S,
    then wa ? S
  • iii) Closure w? S only if it can be obtained
    from ? by a finite number of applications
    of the recursive step.
  • For any non empty alphabet S, S contains
    infinitely many elements.
  • If S a,
  • ? S contains strings
  • ? , a, aa, aaa, .
  • length of a string w, no. of elements (length
    (w))
  • ? If S contain n elements,
  • ? nk string of length k is S

4
  • Example 2.1.1
  • Let S a, b, c
  • S
  • length 0 ?
  • length 1 a b c
  • length 2 aa ab ac ba bb bc ca cbcc
  • length 3 aaa aab aac aba
  • baa
  • caa
  • Definition 2.1.2
  • A language over an alphabet S is a subset of S
  • idea concat. 2 strings ? new string

5
  • Definition 2.1.3
  • Let u, v ? S . The concat. of u and v , ? uv ,
    is a binary operation on
  • S defined as follow
  • i) Basis If length (v) 0, then u ? and
    uv U
  • ii) Recursive step Let v be a string with
    length (v) n gt 0. Then v wa ,
  • for some string w with length n-1, and a ? S
    , and uv (uw)a
  • Let u ab, v ca, and w bb, then uv abca,
    vw cabb
  • (uv)w abcabb u(vw) abcabb
  • The result of concat. Is independent of the
    order.
  • Property ? associability

6
  • Theorem 2.1.4 proves this.
  • Let u, v, w ? S. Then (uv)w u(vw)
  • Proof by induction on the length of the string
    w.
  • Basis length (w) 0 ? w ? , (uv)w uv by the
    definition of concat.
  • on the other hand, u(vw) u(v) uv
  • Induction Hypothesis Assume that (uv)w u(vw)
    for all string w of
  • length n or less
  • Inductive step We need to prove , ?
  • (uv)w u(vw) , ?strings w , length n1
  • Let w is a string, then w xa for some string x
    of length a ? S
  • (uv)w (uv)(xa) , subs. w xa
  • ((uv)x)a) , def. of concat
  • (u (vx))a , inductive hypothesis
  • u( (vx)a) , def. of
    concat
  • u(v (xa)) , def. of concat
  • u(vw) , subst. xa w

7
  • Definition 2.1.5
  • Let u be a string in S. The reversed of u , uR ,
    defined as follows
  • i) Basis length (u) 0 , then u ? , and ?R
    ?
  • ii) Recursive step If length (u) n gt 0 ,
    then u wa for some string
  • w with length n-1 and some a ? S , and
    uR awR
  • Theorem 2.1.6
  • Let u, v ? S, then (uv) R vRuR
  • Proof
  • Basis length (v) 0 , then v ? and (uv)R
    uR. Similarly , vRuR ?RuR , ?string v of length
    n
  • Inductive step
  • Prove ? (uv)R vRuR , for any string v of length
    n1
  • Let v be a string of length n1. then v wa ,
    where w is a string of
  • length n , a ? S .

8
  • (uv)R (u(wa))R
  • ((uw)a)R , associativity of concat.
  • a(uw)R , def. of reversed
  • a(wRuR) , inductive hyp.
  • (awR)uR ,assoc. of concat
  • (wa)RuR , def. of reversed
  • vRuR

9

2.2 Finite Spec. of Languages.
  • The spec. of a languages requires an unambiguous
    description of the strings
  • of the languages.
  • Example
  • The language, L of strings over a, b in which
    each string begin with a
  • and has even length is determined by

10
  • i) Basis aa, ab ? L
  • ii) Recursive step If a ? L, then uaa, uba,
    ubb ? L.
  • iii) Closure A string u ? L only if can be
    obtained from the basis element let a finite
    member of application of the recursive step.
  • The strings in L are built by joining 2 elements
    to the Right-hand side of
  • a previously constructed string. The basis
    ensures that each string in L
  • begin with an a. Adding substrings of length 2
    maintain even parity.
  • Definition 2.2.1
  • The concat. Of languages X and Y, XY is the
    language
  • XY uv u ? X and v ? Y
  • The concat. of X with itself n times, Xn .
  • X0 ?

11
  • Example
  • Let X a,b,c and Y abb,ba. Then
  • XY aabb, babb, cabb, aba, bba, cba
  • X0 ?
  • X1 X a, b, c
  • X2 X X aa, ab, ac, .. cc
  • X3 XXX aaa, aab, ccc
  • Definition 2.2.2
  • Let X be a set. Then
  • X 8Ui0Xi and X 8Ui1Xi
  • all strings over nonnull strings
  • alphabet X over X
  • ? X XX

12
  • Example 2.2.4
  • L a,b bba,b consists of the strings
    over a,b that contains the substring bb
  • Example 2.2.5
  • L aa a,b U a,bbb
  • L1 bb and L2 ?, bb, bbbb be languages
    over b
  • L aa, bb, ab, ba , even length over a,b
  • L a,b

13
  • 2.3 REGULAR SETS AND EXPRESSION
  • A set is regular if it can be generated from the
    empty set, the set
  • containing null string, and the elements of the
    alphabet using union,
  • concat., and the Kleens Star operations.
  • Definition 2.3.1
  • Let S be an alphabet. The regular sets over S are
    defined recursively as follows
  • i) Basis ø, ? and a , ? a? S are regular
    sets over S
  • ii) Recursive step let X and Y be regular sets
    over S . The sets
  • X ? Y
  • XY
  • X
  • are regular sets over S.
  • iii) Closure X is a regular set over S only if
    it can be obtained from the basis elements by a
    finite number of applications of the recursive
    step.

14
  • Example L a, bbb a,b
  • bb is a regular set over a, b
  • a , b are regular set.
  • Using Kleene Star operation ? a, b , the set
    of all strings over a, b
  • By concat. b b bb is regular
  • Applying twice concat. ? a, b bb ab
  • Exercise
  • Write the set of strings that begin and end with
    an a and contain at least one
  • b is regular over a, b.
  • Hint
  • The strings in this set could be described
    intuitively as an a, followed by
  • any string, followed by a b , followed by any
    string, followed by an a.
  • a a, bb a, ba

15
  • Definition 2.3.2
  • Let S be an alphabet. The regular expression over
    S are defined recursively
  • as follows
  • i) Basis ø, ?, and a , for every a? S , are
    regular expressions over S .
  • ii) Recursive step Let u and v be regular
    expressions over S . The expressions
  • (u ? v)
  • (uv)
  • (u)
  • are regular expressions aver S .
  • iii) Closure u is a regular expression over S
    only if it can be obtained from the basis element
    by a finite.

16
  • Employing Kleene star , concat. and union
  • a regular set of
  • a, bbb a, b
  • Can be written as
  • (a ? b) bb (a ? b)
  • and set of
  • a a, bb a, ba
  • ? a (a ? b)b (a ? b)a
  • The set bawab w? (a, b) is regular over a,
    b

17
  • The following table demonstrates the recursive
    generation of a regular set
  • and corresponding regular expression.

18
  • Exercise
  • Write a regular expression that represent the
    regular sets with
  • strings containing over a, b
  • 1) aa
  • 2) bb
  • 3) aa and bb
  • 4) exactly two bs
  • 5) two or more bs
  • Ans
  • 1) (a ?b) aa(a?b)
  • 2) (a ?b) bb(a?b)
  • 3) (a ?b) aa bb(a?b)
  • 4) aba? ba
  • 5) i) abab(a ?b)
  • ii) (a ?b)baba
  • iii) (a ?b)b(a ?b)b(a ?b)
Write a Comment
User Comments (0)
About PowerShow.com