500 likes | 602 Views
CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University 2010. Content Languages, Alphabets and Strings Strings & String Operations Languages & Language Operations Regular Expressions Finite Automata, FA Deterministic Finite Automata, DFA.
E N D
CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University 2010
Content • Languages, Alphabets and Strings • Strings & String Operations • Languages & Language Operations • Regular Expressions • Finite Automata, FA • Deterministic Finite Automata, DFA
Languages • defined over an alphabet: A language is a set of strings A String is a sequence of letters • An alphabet is a set of symbols
Alphabets and Strings • We will use small alphabets: Strings
= 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
Reverse (reversering) Example: Longest odd length palindrome in a natural language: saippuakauppias (Finnish: soap sailsman)
Length: String Length Examples:
Recursive Definition of Length • For any letter: • For any string : • Example:
= = u aab , u 3 = = v abaab , v 5 = = uv aababaab 8 = + = + = uv u v 3 5 8 Length of Concatenation Example:
Proof of Concatenation Length • Claim: • Proof: By induction on the length • Induction basis: • From definition of length:
Inductive hypothesis: for • Inductive step: we will prove for
Inductive Step • Write , where • From definition of length: • From inductive hypothesis: • Thus: END OF PROOF
Empty String • A string with no letters: • (Also denoted as ) • Observations:
Substring (delsträng) • Substring of a string: • a subsequence of consecutive characters • String Substring
prefix suffix Prefix and Suffix • Suffixes Prefixes
(String repeated n times) Repetition n = • Example: • Definition: w ww... w } n
The (Kleene* star) Operation • the set of all possible strings from alphabet [* Kleene is pronounced "clay-knee“] http://en.wikipedia.org/wiki/Kleene_star
{ } 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
} { 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
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 }
Example • An infinite language
{ } S = l * , a , b , aa , ab , ba , bb , aaa , aab , K Complement: Operations on Languages • The usual set operations
Reverse Definition: Examples:
Concatenation • Definition: Example
Repeat • Definition: • Special case:
Star-Closure (Kleene *) • Definition: • Example:
Positive Closure • Definition + 1 2 = L L U L U L { } = - l L *
Primitive regular expressions: Given regular expressions and are Regular Expressions Regular Expressions: Recursive Definition
A regular expression: Not a regular expression: Examples
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, ...}.
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)*.
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)*.
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)*.
Languages of Regular Expressions language of regular expression Example
Definition • For primitive regular expressions:
Definition (continued) • For regular expressions and
Example Regular expression:
Example • Regular expression
Example • Regular expression
{ all strings with at least two consecutive 0 } Example • Regular expression
= { all strings without two consecutive 0 } Example • Regular expression • (consists of repeating 1’s and 01’s).
Example = { all strings without two consecutive 0 } Equivalent solution: (In order not to get 00 in a string, after each 0 there must be an 1, which means that strings of the form 1....101....1 are repeated. That is the first parenthesis. To take into account strings that end with 0, and those consisting of 1’s solely, the rest of the expression is added.)
Equivalent Regular Expressions • Regular expressions and Definition: are equivalent if
= { all strings without two consecutive 0 } Example and are equivalent regular expressions.
Additional Sources • http://www.math.uu.se/~salling/Lennart Salling • http://www.math.uu.se/~salling/AUTOMATA_DV/index.html • Introduktion movie.mov • Program, strings, integers and integerfunctions.mov • Different infinities and integerfunctions that can not be calculated by a program .mov • Strings and languages.movRegularlanguages and regular expressions .mov