Strings and Languages Operations - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Strings and Languages Operations

Description:

We use exponentiation to indicate the number of items being concatenated. Symbols ... Exponentiation of a set of symbols or a set of strings results in a set of ... – PowerPoint PPT presentation

Number of Views:40
Avg rating:3.0/5.0
Slides: 21
Provided by: Patchrawat4
Learn more at: http://www.cse.msu.edu
Category:

less

Transcript and Presenter's Notes

Title: Strings and Languages Operations


1
Strings and Languages Operations
  • Concatenation
  • Exponentiation
  • Kleene Star
  • Regular Expressions

2
Strings and Language Operations
  • Concatenation
  • Exponentiation
  • Kleene star
  • Pages 28-32 of the recommended text
  • Regular expressions
  • Pages 85-90 of the recommended text

3
String Concatenation
  • If x and y are strings over alphabet S, the
    concatenation of x and y is the string xy formed
    by writing the symbols of x and the symbols of y
    consecutively.
  • Suppose x abb and y ba
  • xy abbba
  • yx baabb

4
Properties of String Concatenation
  • Suppose x, y, and z are strings.
  • Concatenation is not commutative.
  • xy is not guaranteed to be equal to yx
  • Concatenation is associative
  • (xy)z x(yz) xyz
  • The empty string is the identity for
    concatenation
  • x/\ /\x x

5
Language Concatenation
  • Suppose L1 and L2 are languages (sets of
    strings).
  • The concatenation of L1 and L2, denoted L1L2,is
    defined as
  • L1L2 xy x ? L1 and y ? L2
  • Example,
  • Let L1 ab, bba and L2 aa, b, ba
  • What is L1L2?
  • Solution
  • Let x1 ab, x2 bba, y1 aa, y2 b, y3 ba
  • L1L2 x1y1, x1y2, x1y3, x2y1, x2y2, x2y3
    abaa, abb, abba, bbaaa, bbab, bbaba

6
Language Concatenation is not commutative
  • Let L1 aa, bb, ba and L2 /\, aba
  • Let x1 aa, x2 bb, x3ba, y1 /\, y2 aba
  • L1L2 x1y1, x1y2, x2y1, x2y2, x3y1, x3y2
    aa, aaaba, bb, bbaba, ba, baaba
  • L2L1 y1x1, y1x2, y1x3, y2x1, y2x2, y2x3
    aa, bb, ba, abaaa, ababb, ababa
  • L2L2 y1y1, y1y2, y2y1, y2y2 /\,
    aba, aba, abaaba /\, aba, abaaba
    (dropped extra aba)

7
Associativity of Language Concatenation
  • (L1L2)L3 L1(L2L3) L1L2L3
  • Example
  • Let L1a,b, L2c,d, and L3e,f
  • L1L2L3(a,bc,d)e,f ac, ad,
    bc, bde,f ace,acf,ade,aef,bce,bc
    f,bde,bdf
  • L1L2L3a,b(c,de,f) a,bce,
    df, ce, df ace,acf,ade,aef,bce,bc
    f,bde,bdf

8
Special Cases
  • What language is the identity for language
    concatenation?
  • The set containing only the empty string /\ /\
  • Example
  • aab,ba,abc/\ /\aab,ba,abc
    aab,ba,abc
  • What about ?
  • For any language L, L L
  • Thus for concatenation is like 0 for
    multiplication
  • Example
  • aab,ba,abc aab,ba,abc
  • The intuitive reason is that we must choose a
    string from both sets that are being
    concatenated, but there is nothing to choose from
    .

9
Exponentiation
  • We use exponentiation to indicate the number of
    items being concatenated
  • Symbols
  • Strings
  • Set of symbols (S for example)
  • Set of strings (languages)
  • a3 aaa
  • x3 xxx
  • S3 SSS x ? S x3
  • L3 LLL

10
Examples of Exponentiation
  • Let xabb, Sa,b, Lab,b
  • a4 aaaa
  • x3 (abb)(abb)(abb) abbabbabb
  • S3 SSS a,ba,ba,b aaa,aab,aba,abb,b
    aa,bab,bba,bbb
  • L3 LLL ab,bab,bab,b
    ababab,ababb,abbab,abbb,
    babab,babb,bbab,bbb

11
Results of Exponentiation
  • Exponentiation of a symbol or a string results in
    a string.
  • Exponentiation of a set of symbols or a set of
    strings results in a set of strings
  • a symbol ? a string
  • a string ? a string
  • a set of symbols ? a set of strings
  • a set of strings ? a set of strings

12
Special Cases of Exponentiation
  • a0 /\
  • x0 /\
  • S0 /\
  • L0 /\ for any language L
  • aa,bb0 /\
  • a, aa, aaa, aaaa, 0 /\
  • /\ 0 /\
  • ?0 0 /\

13
Kleene Star
  • Kleene is a unary operation on languages.
  • Kleene is not an operation on strings
  • However, see the pages on regular expressions.
  • L represents any finite number of concatenations
    of L.
  • L Ukgt0 Lk L0 U L1 U L2 U
  • For any L, /\ is always an element of L
  • because L0 /\
  • Thus, for any L, L ! ?

14
Example of Kleene Star
  • Let Laa
  • L0 /\
  • L1Laa
  • L2 aaaa
  • L3
  • L L0 ? L1 ? L2 ? L3
  • /\, aa, aaaa, aaaaaa,
  • set of all strings that can be obtained by
    concatenating 0 or more copies of aa

15
Example of Kleene Star
  • Let Laa, b
  • L0 /\
  • L1Laa,b
  • L2 LL aaaa, aab, baa, bb
  • L3
  • L L0 ? L1 ? L2 ? L3
  • set of all strings that can be obtained by
    concatenating 0 or more copies of aa and b

16
Regular Languages
  • Regular languages are languages that can be
    obtained from the very simple languages over S,
    using only
  • Union
  • Concatenation
  • Kleene Star

17
Examples of Regular Languages
  • aab (i.e. aab )
  • aa,b (i.e. aa ? b )
  • a,b language of strings that can be
    obtained by concatenating any number of as and
    bs
  • bba,b language of strings that begin with
    bb (followed by any number of as and bs)
  • abb,/\ language of strings that begin
    with any number of as and end with an optional
    bb.
  • a?b language of strings that consist of
    only as or only bs and /\.

18
Regular Expressions
  • We can simplify the formula for regular languages
    slightly by
  • leaving out the set brackets and
  • replacing ? with
  • The results are called regular expressions.

19
Examples of Regular Expressions
Set notation Regular Expressions
aab aab
aa,b aa?b aab
a,b (a?b) (ab)
bba,b bb(a?b) bb(ab)
abb,/\ a(bb?/\) a(bb/\)
a?b ab
20
String or Language?
  • Consider the regular expression a(bb/\)
  • a(bb/\) is a string over alphabet a, b, , ,
    /\, (, ), ?
  • a(bb/\) represents a language over alphabet a,
    b
  • It represents the language of strings over a,b
    that begin with any number of as and end with an
    optional bb.
  • Some regular expressions look just like strings
    over alphabet a,b
  • Regular expression aaba represents the language
    aaba
  • Regular expression /\ represents the language
    /\
  • It should be clear from the context whether a
    sequence of symbols is a regular expression or
    just a string.
Write a Comment
User Comments (0)
About PowerShow.com