Languages 1
Languages A language is a set of strings String: A sequence of letters Examples: cat, dog, house, Defined over an alphaet: a,, c,, z 2
Alphaets and Strings We will use small alphaets: Strings a a u a aa v aaa aa w aa aaaaaa 3
String Operations w a a 1 2 a n aa v 1 2 m aaa Concatenation wv a a 1 2 an 1 2 m aaaaa 4
w a a 1 2 a n aaaaa Reverse w R a n a 2 a 1 aaaaa 5
w String Length a a 1 2 a n Length: w n Examples: aa 4 aa 2 a 1 6
Recursive Definition of Length For any letter: a 1 For any string wa : wa w 1 Example: aa a 1 a 11 a 111 1111 4 7
Length of Concatenation uv u v Example: u aa, u 3 v aaa, v 5 uv aaaaa 8 uv u v 3 5 8 8
Claim: Proof of Concatenation Length uv u v Proof: By induction on the length v Induction asis: v 1 From definition of length: uv u 1 u v 9
Inductive hypothesis: uv u v for v 1,2,,n Inductive step: we will prove uv u v for v n 1 10
Inductive Step v wa w n, a 1 Write, where From definition of length: uv uwa uw 1 wa w 1 From inductive hypothesis: uw u w Thus: uv u w 1 u wa u v 11
Empty String A string with no letters: Oservations: 0 w w w aa aa aa 12
Sustring of string: Sustring a susequence of consecutive characters String aa aa aa aa Sustring a aa a 13
Prefixes Prefix and Suffix aa Suffixes aa w uv a a a a prefix suffix a a aa aa 14
Another Operation n w ww w n Example: 2 aa aaaa Definition: 0 w 0 aa 15
* The * Operation : the set of all possile strings from alphaet a, *, a,, aa, a, a,, aaa, aa, 16
The + Operation : the set of all possile strings from alphaet a, except *, a,, aa, a, a,, aaa, aa, * a,, aa, a, a,, aaa, aa, 17
Language A language is any suset of * Example: a, *, a,, aa, a, a,, aaa, Languages: a, aa, aa {, aa, aa, aa, a, aaaaaa} 18
Another Example An infinite language L { a n n : n 0} a aa aaaaa L al 19
Operations on Languages The usual set operations a, a, aaaa, a a, a, aaaa, a { a, a,, aaaa} { a} a, a, aaaa, a a, aaaa Complement: L * L a, a,, aa, a,, aaa, 20
Definition: L R Reverse R { w : wl} Examples: R a, aa, aa a, aa, aa L { a n n : n 0} L R { n a n : n 0} 21
Concatenation Definition: L 1 L 2 xy 1, : x L yl 2 Example: a, a, a, aa a, aaa, a, aaa, a, aaa 22
Definition: Another Operation n L LL L n a, a, a, a, 3 aaa, aa, aa, a, aa, a, a, Special case: L 0,, aaa 0 a a 23
More Examples L n n { a : n 0} L 2 n n m m { a a : n, m 0} 2 aaaaal 24
Star-Closure (Kleene *) Definition: 0 1 L* L L L 2 Example: a, *, a,, aa, a, a,,,,, aaa aa aa a, 25
26 Positive Closure Definition: * 2 1 L L L L,,,,,,,,,,, aaa aa aa a a a aa a a
Finite Automata 27
Finite Automaton Input String Finite Automaton Output String 28
Finite Accepter Input String Finite Automaton Output Accept or Reject 29
Transition Graph Aa -Finite Accepter a a a a q0 q1 q2 3 q 5 q q4 initial state state transition final state accept 30
Initial Configuration Input String a a q 0 a a a a q1 q2 3 q 5 q q4 31
Reading the Input a a a a a a q0 q1 q2 3 q 5 q q4 32
a a a a a a q0 q1 q2 3 q 5 q q4 33
a a a a a a q0 q1 q2 3 q 5 q q4 34
a a a a a a q0 q1 q2 3 q 5 q q4 35
Input finished a a a a a a q0 q1 q2 3 q 5 q q4 Output: accept 36
Rejection a a q 0 a a a a q1 q2 3 q 5 q q4 37
a a a a a a q0 q1 q2 3 q 5 q q4 38
a a a a a a q0 q1 q2 3 q 5 q q4 39
a a a a a a q0 q1 q2 3 q 5 q q4 40
Input finished a a a a a a q0 q1 q2 3 q 5 q q4 Output: reject 41
Another Example a a a q0 1 a, q q2 42
a a a q0 1 a, q q2 43
a a a q0 1 a, q q2 44
a a a q0 1 a, q q2 45
Input finished a a a Output: accept q0 1 a, q q2 46
Rejection a a q0 1 a, q q2 47
a a q0 1 a, q q2 48
a a q0 1 a, q q2 49
a a q0 1 a, q q2 50
Input finished a a q0 1 a, q q2 Output: reject 51
Formalities Deterministic Finite Accepter (DFA) M Q,,, q0, F Q q 0 F : set of states : input alphaet : transition function : initial state : set of final states 52
Input Alphaet a a a a q0 q1 q2 3 q 5 q q4 53
Set of States Q Q q 0 1, 2, 3, 4,, q q q q q 5 a a a a q0 q1 q2 3 q 5 q q4 54
Initial State q0 q 0 a a a a q1 q2 3 q 5 q q4 55
Set of Final States F F q 4 a a a q q a 3 q0 q1 2 q 5 q 4 56
Transition Function : Q Q a a a a q0 q1 q2 3 q 5 q q4 57
q0, a q1 a a a a q0 q1 q2 3 q 5 q q4 58
q0, q5 q 0 a a a a q1 q2 3 q 5 q q4 59
3 2, q q a a a a q0 q1 q2 3 q 5 q q4 60
a q 0 q 1 q 2 q 3 q 4 q 5 q1 q5 q5 q2 q2 q3 q4 q5 q 5 q 5 Transition Function q 5 q 5 a a a a q0 q1 q2 3 q 5 q q4 61
Extended Transition Function * *: Q * Q a a a a q0 q1 q2 3 q 5 q q4 62
q0, a 2 * q a a a q q2 a q0 1 q 5 q3 q4 63
q0, aa 4 * q a a a a q0 q1 q2 3 q 5 q q4 64
q0, aaa 5 * q q 0 a a a a q1 q2 3 q 5 q q4 65
Oservation: There is a walk from with lael aaa q 0 to q 1 q0, aaa 5 * q q 0 a a a a q1 q2 3 q 5 q q4 66
Recursive Definition * q, q * q, wa ( *( q, w), a) a a a a q0 q1 q2 3 q 5 q q4 67
68 0 q 1 q 2 q 3 q 4 q a a q 5 a a 2 1 0 0 0 0,,,,,, * ),, *(, * q q a q a q a q a q
Languages Accepted y DFAs Take DFA M Definition: The language L contains all input strings accepted y M M L M M = { strings that drive to a final state} 69
M aa Example L M a a a a q0 q1 q2 3 q 5 q q4 accept 70
Another Example M, a aa L, M a a a a q0 q1 q2 3 accept accept q 5 q q4 accept 71
Formally For a DFA M Q,,, q0, F M Language accepted y : L M w : * q, w * 0 F alphaet transition initial final function state states 72
Oservation Language accepted y M : L M w : * q, w * 0 F Language rejected y : M L M w : * q, w * 0 F 73
More Examples L n M { a : n 0} a q0 1 a, q q2 accept trap state 74
L M = { all sustrings with prefix a } q a 0 q1 q2 a accept q 3 75
L M = { all strings without 001 sustring } 1 1 0 1 0 00 001 0 0 0, 1 76
Regular Languages A language a DFA L is regular if there is M L LM such that All regular languages form a language family 77
Example The language L awa: w a, * is regular: a q a 0 q2 q3 a q 4 78