1 / 57

CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 2

CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 2 School of Innovation, Design and Engineering Mälardalen University 2012. Content Languages, Alphabets and Strings Strings & String Operations Languages & Language Operations

Download Presentation

CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 2

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. CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 2 School of Innovation, Design and Engineering Mälardalen University 2012

  2. Content • Languages, Alphabets and Strings • Strings & String Operations • Languages & Language Operations • Regular Languages and their Representations • Regular Expressions

  3. Languages, Alphabets and Strings Based on C Busch, RPI, Models of Computation

  4. Languages • defined over an alphabet: A language is a set of strings A string is a sequence of symbols • An alphabet is a set of symbols.

  5. Alphabets and Strings • We will use small alphabets: Strings

  6. Operations on Strings

  7. = w a a a L x abba 1 2 n = v b b b y  bbbaaa L 1 2 m String Operations Concatenation (sammanfogning) xy abbabbbaaa

  8. Reverse (reversering) Example: Longest odd length palindrome in a natural language: saippuakauppias (Finnish: soap sailsman)

  9. Length: String Length Examples:

  10. Recursive Definition of Length • For any letter: • For any string : • Example:

  11. = = u aab , u 3 = = v abaab , v 5 = = uv aababaab 8 = + = + = uv u v 3 5 8 Length of Concatenation Example:

  12. Proof of Concatenation Length • Claim: • Proof: By induction on the length • Induction basis: • From definition of length:

  13. Inductive hypothesis: for • Inductive step: we will prove for

  14. Inductive Step • Write , where • From definition of length: • From inductive hypothesis: • Thus: END OF PROOF

  15. Empty String • A string with no letters: • (Also denoted as ) • Observations:

  16. Substring (delsträng) • Substring of a string: • a subsequence of consecutive characters • String Substring

  17. prefix suffix Prefix and Suffix • Suffixes Prefixes

  18. (String repeated n times) Repetition n = • Example: • Definition: w ww... w } n

  19. The (Kleene* star) Operation • the set of all possible strings from alphabet [* Kleene is pronounced "clay-knee“] http://en.wikipedia.org/wiki/Kleene_star

  20. { } S = l * , a , b , aa , ab , ba , bb , aaa , aab , K The + (Kleene plus) Operation :the set of all possible strings from the alphabet except { } S = a , b

  21. } { S = oj , fy , usch { S = l, oj, fy, usch, ojoj, fyfy,uschusch, ojfy, ojusch * } + + S S K Example = S - l * { = oj, fy, usch, ojoj, fyfy,uschusch, ojfy, ojusch } K

  22. Operations on Languages

  23. Language • A language is any subset of • Example: • Languages: { } S = a , b { } S = l * , a , b , aa , ab , ba , bb , aaa , K { } l { } a , aa , aab l { , abba , baba , aa , ab , aaaaaa }

  24. Example • An infinite language

  25. { } S = l * , a , b , aa , ab , ba , bb , aaa , aab , K Complement: Operations on Languages • The usual set operations

  26. Reverse Definition: Examples:

  27. Concatenation • Definition: Example

  28. Repeat • Definition: • Special case:

  29. Example

  30. Star-Closure (Kleene *) • Definition: • Example:

  31. Positive Closure • Definition + 1 2 = L L U L U L { } = - l L *

  32. Regular Languages

  33. Definition of Set of Regular Languages • Basis Clause: • where    are regular languages. • Inductive Clause: IfLrandLsare regular languages, thenLr Ls, LrLs and Lr*are regular languages. Nothing is a regular language unless it is obtained from the above two clauses.

  34. Standard Representations of Regular Languages

  35. Regular Expression DFA Regular Language NFA Regular Grammar Regular Language Representations

  36. Regular Expressions

  37. Primitive regular expressions: Given regular expressions and are Regular Expressions Regular Expressions: Recursive Definition

  38. A regular expression: Not a regular expression: Examples

  39. Building Regular Expressions • Zero or more. • a* means "zero or more a's." • To say "zero or more ab's," that is, • {, ab, abab, ababab, ...}, you need to say (ab)*. • ab*denotes {a, ab, abb, abbb, abbbb, ...}.

  40. Building Regular Expressions • One or more. • Since a* means "zero or more a's", you can use aa* (or equivalently, a*a) to mean "one or more a's.“ • Similarly, to describe "one or more ab's," that is, • {ab, abab, ababab, ...}, you can use ab(ab)*.

  41. Building Regular Expressions • Any string at all. • To describe any string at all (with = {a, b, c}), you can use (a+b+c)*. • Any nonempty string. • This can be written as any character from followed by any string at all: (a+b+c)(a+b+c)*.

  42. Building Regular Expressions • Any string not containing.... • To describe any string at all that doesn't contain an a (with = {a, b, c}), you can use (b+c)*. • Any string containing exactly one... • To describe any string that contains exactly one a, put "any string not containing an a," on either side of the a, like this: (b+c)*a(b+c)*.

  43. Languages of Regular Expressions language of regular expression Example

  44. Definition • For primitive regular expressions:

  45. Definition (continued) • For regular expressions and

  46. Example Regular expression:

  47. Example • Regular expression

  48. Example • Regular expression

  49.  { all strings with at least two consecutive 0 } Example • Regular expression

  50. = { all strings without two consecutive 0 } Example • Regular expression • (consists of repeating 1’s and 01’s).

More Related