Languages 1 Languages A language is a set

  • Slides: 78
Download presentation
Languages 1

Languages 1

Languages A language is a set of strings String: A sequence of letters Examples:

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

Alphabets and Strings We will use small alphabets: Strings 3

String Operations Concatenation 4

String Operations Concatenation 4

Reverse 5

Reverse 5

String Length: Examples: 6

String Length: Examples: 6

Recursive Definition of Length For any letter: For any string : Example: 7

Recursive Definition of Length For any letter: For any string : Example: 7

Length of Concatenation Example: 8

Length of Concatenation Example: 8

Proof of Concatenation Length Claim: Proof: By induction on the length Induction basis: From

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 hypothesis: for Inductive step: we will prove for 10

Inductive Step Write , where From definition of length: From inductive hypothesis: Thus: 11

Inductive Step Write , where From definition of length: From inductive hypothesis: Thus: 11

Empty String A string with no letters: Observations: 12

Empty String A string with no letters: Observations: 12

Substring of string: a subsequence of consecutive characters String Substring 13

Substring of string: a subsequence of consecutive characters String Substring 13

Prefix and Suffix Prefixes Suffixes prefix suffix 14

Prefix and Suffix Prefixes Suffixes prefix suffix 14

Another Operation Example: Definition: 15

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 16

The + Operation : the set of all possible strings from alphabet except 17

The + Operation : the set of all possible strings from alphabet except 17

Language A language is any subset of Example: Languages: 18

Language A language is any subset of Example: Languages: 18

Another Example An infinite language 19

Another Example An infinite language 19

Operations on Languages The usual set operations Complement: 20

Operations on Languages The usual set operations Complement: 20

Reverse Definition: Examples: 21

Reverse Definition: Examples: 21

Concatenation Definition: Example: 22

Concatenation Definition: Example: 22

Another Operation Definition: Special case: 23

Another Operation Definition: Special case: 23

More Examples 24

More Examples 24

Star-Closure (Kleene *) Definition: Example: 25

Star-Closure (Kleene *) Definition: Example: 25

Positive Closure Definition: 26

Positive Closure Definition: 26

Finite Automata 27

Finite Automata 27

Finite Automaton Input String Output Finite Automaton String 28

Finite Automaton Input String Output Finite Automaton String 28

Finite Accepter Input String Output Finite Automaton “Accept” or “Reject” 29

Finite Accepter Input String Output Finite Automaton “Accept” or “Reject” 29

Transition Graph Abba -Finite Accepter initial state transition final state “accept” 30

Transition Graph Abba -Finite Accepter initial state transition final state “accept” 30

Initial Configuration Input String 31

Initial Configuration Input String 31

Reading the Input 32

Reading the Input 32

33

33

34

34

35

35

Output: “accept” 36

Output: “accept” 36

Rejection 37

Rejection 37

38

38

39

39

40

40

Output: “reject” 41

Output: “reject” 41

Another Example 42

Another Example 42

43

43

44

44

45

45

Output: “accept” 46

Output: “accept” 46

Rejection 47

Rejection 47

48

48

49

49

50

50

Output: “reject” 51

Output: “reject” 51

Formalities Deterministic Finite Accepter (DFA) : set of states : input alphabet : transition

Formalities Deterministic Finite Accepter (DFA) : set of states : input alphabet : transition function : initial state : set of final states 52

Input Aplhabet 53

Input Aplhabet 53

Set of States 54

Set of States 54

Initial State 55

Initial State 55

Set of Final States 56

Set of Final States 56

Transition Function 57

Transition Function 57

58

58

59

59

60

60

Transition Function 61

Transition Function 61

Extended Transition Function 62

Extended Transition Function 62

63

63

64

64

65

65

Observation: There is a walk from with label to 66

Observation: There is a walk from with label to 66

Recursive Definition 67

Recursive Definition 67

68

68

Languages Accepted by DFAs Take DFA Definition: The language contains all input strings accepted

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

Example accept 70

Another Example accept 71

Another Example accept 71

Formally For a DFA Language accepted by alphabet transition function : initial state final

Formally For a DFA Language accepted by alphabet transition function : initial state final states 72

Observation Language accepted by : Language rejected by : 73

Observation Language accepted by : Language rejected by : 73

More Examples accept trap state 74

More Examples accept trap state 74

= { all substrings with prefix } accept 75

= { all substrings with prefix } accept 75

= { all strings without substring } 76

= { all strings without substring } 76

Regular Languages A language is regular if there is a DFA such that All

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

Example The language is regular: 78