1 / 20

Strings and Languages Operations

Strings and Languages Operations. Concatenation Exponentiation Kleene Star Regular Expressions. Strings and Language Operations. Concatenation Exponentiation Kleene star Pages 27-30 of the text Regular expressions Pages 71-75 of the text. String Concatenation.

kamran
Download Presentation

Strings and Languages Operations

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Strings and Language Operations • Concatenation • Exponentiation • Kleene star • Pages 27-30 of the text • Regular expressions • Pages 71-75 of the text

  3. String Concatenation • If x and y are element of 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. • 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, x3=ba, 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 }

  7. Associativity of Language Concatenation • (L1L2)L3 = L1(L2L3) = L1L2L3 • Example • Let L1={a,b}, L2={c,d}, and L3={e,f} • L1L2L3=({a,b}{c,d}){e,f} ={ac, ad, bc, bd}{e,f} ={ ace,acf,ade,aef,bce,bcf,bde,bdf } • L1L2L3={a,b}({c,d}{e,f}) ={a,b}{ce, df, ce, df} ={ ace,acf,ade,aef,bce,bcf,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 concatentation 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* | |x|=3 } • L3 = LLL

  10. Examples of Exponentiation • Let x=abb, S={a,b}, L={ab,b} • a4 = aaaa • x3 = (abb)(abb)(abb) = abbabbabb • S3= SSS = {a,b}{a,b}{a,b} ={aaa,aab,aba,abb,baa,bab,bba,bbb} • L3 = LLL = {ab,b}{ab,b}{ab,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,bb}0 = { /\ } • { 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* = Uk>0 Lk = L0U L1U L2U … • For any L, /\ is always an element of L* • because L0 = { /\ } • Thus, for any L, L* != 

  14. Example of Kleene Star • Let L={aa} • L0={ /\ } • L1=L={aa } • 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 L={aa, b} • L0={ /\ } • L1=L={aa,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 • See lecture 14 and pages 71-75 of the text

  17. Examples of Regular Languages • {aab} (i.e. {a}{a}{b} ) • {aa,b} (i.e. {a}{a}  {b} ) • {a,b}* language of strings that can be obtained by concatenating any number of a’s and b’s • {bb}{a,b}* language of strings that begin with bb (followed by any number of a’s and b’s) • {a}*{bb,/\} language of strings that begin with any number of a’s and end with an optional bb. • {a}*{b}* language of strings that consist of only a’s or only b’s 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

  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 a’s 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.

More Related