Languages 1 Languages A language is a set Slides: 78 Download presentation Languages 1 Languages A language is a set of strings String: A sequence of letters Examples: “cat”, “dog”, “house”, … Defined over an alphabet: 2 Alphabets and Strings We will use small alphabets: Strings 3 String Operations Concatenation 4 Reverse 5 String Length: Examples: 6 Recursive Definition of Length For any letter: For any string : Example: 7 Length of Concatenation Example: 8 Proof of Concatenation Length Claim: Proof: By induction on the length Induction basis: From definition of length: 9 Inductive hypothesis: for Inductive step: we will prove for 10 Inductive Step Write , where From definition of length: From inductive hypothesis: Thus: 11 Empty String A string with no letters: Observations: 12 Substring of string: a subsequence of consecutive characters String Substring 13 Prefix and Suffix Prefixes Suffixes prefix suffix 14 Another Operation Example: Definition: 15 The * Operation : the set of all possible strings from alphabet 16 The + Operation : the set of all possible strings from alphabet except 17 Language A language is any subset of Example: Languages: 18 Another Example An infinite language 19 Operations on Languages The usual set operations Complement: 20 Reverse Definition: Examples: 21 Concatenation Definition: Example: 22 Another Operation Definition: Special case: 23 More Examples 24 Star-Closure (Kleene *) Definition: Example: 25 Positive Closure Definition: 26 Finite Automata 27 Finite Automaton Input String Output Finite Automaton String 28 Finite Accepter Input String Output Finite Automaton “Accept” or “Reject” 29 Transition Graph Abba -Finite Accepter initial state transition final state “accept” 30 Initial Configuration Input String 31 Reading the Input 32 33 34 35 Input finished Output: “accept” 36 Rejection 37 38 39 40 Input finished Output: “reject” 41 Another Example 42 43 44 45 Input finished Output: “accept” 46 Rejection 47 48 49 50 Input finished Output: “reject” 51 Formalities Deterministic Finite Accepter (DFA) : set of states : input alphabet : transition function : initial state : set of final states 52 Input Alphabet 53 Set of States 54 Initial State 55 Set of Final States 56 Transition Function 57 58 59 60 Transition Function 61 Extended Transition Function 62 63 64 65 Observation: There is a walk from with label to 66 Recursive Definition 67 68 Languages Accepted by DFAs Take DFA Definition: The language contains all input strings accepted by = { strings that drive to a final state} 69 Example accept 70 Another Example accept 71 Formally For a DFA Language accepted by alphabet transition function : initial state final states 72 Observation Language accepted by : Language rejected by : 73 More Examples accept trap state 74 = { all substrings with prefix } accept 75 = { all strings without substring } 76 Regular Languages A language is regular if there is a DFA such that All regular languages form a language family 77 Example The language is regular: 78