unit 1.pptx-theory of computation complete notes

yuvaraniit 9 views 84 slides Mar 11, 2025
Slide 1
Slide 1 of 84
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74
Slide 75
75
Slide 76
76
Slide 77
77
Slide 78
78
Slide 79
79
Slide 80
80
Slide 81
81
Slide 82
82
Slide 83
83
Slide 84
84

About This Presentation

unit 1


Slide Content

THEORY OF C O M P U T A TI O N

Theory of Computation What? The theory of computation is a branch of computer science and mathematics combined D eals with how efficiently problems can be solved on a model of computation, using an algorithm. 2

Application Where? Text processing Compilers Programming Languages Artificial Intelligence Genetic programming Neural Networks Robotics 3

Models 4

Models 5

UNIT I AUTOMATA FUNDAMENTALS Introduction to formal proof – Additional forms of Proof – Inductive Proofs –Finite Automata – Deterministic Finite Automata – Non- deterministic Finite Automata – Finite Automata with Epsilon Transitions 6

Terminologies Alphabet Finite, non empty set of symbols Basic elements of a language Denoted by ∑ String Finite sequence of symbols chosen from some alphabets Empty string Length of the string Power of an alphabet Language Set of all strings which are chosen from ∑ * 7

Example English Alphabet – [a- z] String –{hi,hello,…} Binary number Alphabet – [0,1] String –{0,1,00,01,10,11…} Hexadecimal Alphabet –[0-9][a- e] String –[0,1,1A3,…] 8

Introduction to formal proof – Additional forms of Proof – Inductive Proofs

Introduction to Formal Proof Deductive Proof Reduction to definition Other theorem forms Theorem that appear not to be if- then statements 10

Deductive Proof A deductive proof consists of a sequence of statements whose truth leads us from some initial statement called the hypothesis or the given statement(s) to a conclusion statement. Each step in the proof must follow by some accepted logical principle from either the given facts or some of the previous statement The hypothesis may be true or false, depending on the value of its parameter If H then C . C is deducted from H 11

Hypothesis : x ≥ 4 Conclusion : 2 x ≥ x 2 Parameter : x Proof: If x=3, then 2 3 ≥ 3 2  If x=4 then 2 4 ≥ 4 2  8 ≥ 9 which is false 16 ≥ 16 which is true For each time x increments by 1, the LHS get incremented by 2 𝑥+1 𝑥 2 and the RHS If x ≥ 4, the 𝑥+1 𝑥 = 1.25, ( 1.25) 2 = 1.5625 1.5625 is less than 2 Hence 2 x ≥ x 2 will be true for x ≥ 4 23

If x is the sum of the squares of four positive integers, then 2 x ≥ x 2 13

Reduction to Definitions Convert all the terms in hypothesis to their definitions Deductive proof 14

Let S be a finite subset of some infinite set U. Let T be the complement of S with respect to U. Then T is infinite Let us assume T is finite, |T| = m As per the given statement, S is finite => |S|=n Then |S U T | = n+ m, which is finite which contradicts the given statement, Hence T should be infinite. 26

Other Theorem Forms Ways of saying If-Then H implies C H only if C C if H Whenever H holds, C follows If and only if statement A if and only if B If part : If B then A Only if part: If A then B 16

Theorem that appear not to be If- Then Statement 2 sin 𝛼 ± sin 𝛽 = sin 𝛼 ± 𝛽 cos Example 𝑎 2 + 𝑏 2 = 𝑐 2 1 1 2 2 𝛼 ∓ 𝛽 17

Additional Forms of Proof Proofs by sets Proof by Contrapositive Proofs by contradiction Proofs by counterexample 18

Proofs by sets R U (S ∩ T) = (R U S) ∩ (R U T) 19

20

Proof by Contrapositive The contrapositive of a statement negates the conclusion as well as the hypothesis. It is logically equivalent to the original statement asserted. Often it is easier to prove the contrapositive than the original statement. If H then C is equivalent to If not C then not H Example: If x ≥ 4 then 2 x ≥ x 2 If not 2 x ≥ x 2 then not x ≥ 4 If 2 x < x 2 then x < 4 21

Proofs by contradiction The method of proof by contradiction is to assume that a statement is not true and then to show that that assumption leads to a contradiction. To prove if H then C is to prove If H then not C implies falsehood. 22

Proofs by counterexample A proof by counterexample is not technically a proof. It is merely a way of showing that a given statement cannot possibly be correct by showing an instance that contradicts a universal statement. If integer x is a prime then x is odd 23

Inductive Proof Induction on integers Structural induction Mutual induction 24

Induction on integers Mathematical Induction is a mathematical technique which is used to prove a statement, a formula or a theorem is true for every natural number. The technique involves two steps to prove a statement, as stated below − Step 1(Base step) − It proves that a statement is true for the initial value. Step 2(Inductive step) − It proves that if the statement is true for the nth iteration (or number n), then it is also true for (n+1)th iteration ( or number n+1). 25

1 + 2 + ... + n = n(n+1)/2 Proof. (Proof by Mathematical Induction) Let's let P(n) be the statement "1 + 2 + ... + n = (n (n+1)/2." Basis Step. P(1) asserts "1 = 1(2)/2", which is clearly true. So we are done with the initial step. 26

Inductive Step. Induction Hypothesis/ Inductive assumption: Assume, 1 + 2 + ... + k = k (k+1)/2 is true Prove for k+1, (i.e) 1 + 2 + ... + k + (k+1) = (k+1)(k+2)/2. 1 + 2 + ... + k + (k+1) = k(k+1)/2 + (k+1) = (k(k+1) + 2 (k+1))/2 = (k+1)(k+2)/2. 27

28

29

Structural Induction Structural induction is a proof methodology similar to mathematical induction, only instead of working in the domain of positive integers (N) it works in the domain of such recursively defined structures! It is terrifically useful for proving properties of such structures. Its structure is sometimes “looser” than that of mathematical induction. 30

Every tree has one more node than its edges If T is a tree and T has n nodes and e edges then n=e+1 Basis: T is single node tree, then n=1, e=0, so n=e+1 holds true Inductive Hypothesis: Assume the statement S(T i ) hold for i=1,2,3,…,K and T i have n i nodes and e i edges then n i = e i + 1 Induction 31

32

Every expression has an equal number of left and right parentheses Let G is an expression Basis : G is a number or variable, so the number of left and right parenthesis is Inductive Hypothesis: Assume E and F are two expressions which has equal number of left and right parentheses. Induction : 33

34

35

36

37

Finite Automata Finite automata are used to recognize patterns . It takes the string of symbol as input and changes its state accordingly. When the desired symbol is found, then the transition occurs. At the time of transition, the automata can either move to the next state or stay in the same state. Finite automata have two states, Accept state or Reject state . When the input string is processed successfully, and the automata reached its final state, then it will accept. 38

Input Tape It is a linear tape having some number of cells. Each input symbol is placed in each cell. Finite control It decides the next state on receiving particular input from input tape. Tape reader It reads the cells one by one from left to right, and at a time only one input symbol is read. 39

A finite automaton consists of: a finite set S of N states a special start state a set of final (or accepting) states a set of transitions T from one state to another, labelled with chars in C 40

Execution of FA on an input sequence as follows: Begin in the start state If the next input char matches the label on a transition from the current state to a new state, go to that new state Continue making transitions on each input char If no move is possible, then stop If in accepting state, then accept 41

Deterministic Finite Automata Deterministic refers to the uniqueness of the computation. On each input there is one and only one state to which the automaton can transition from its current state DFA does not accept the null move. 42

Formal Definition of DFA A deterministic finite automaton (DFA) is a 5- tuple (Q,Σ,δ,q ,F) ,where Q is a finite set called the states, Σ is a finite set called the alphabet, δ:Q×Σ→Q is the transition function, q ∈ Q is the start state, and F ⊆ Q is the set of accepting states. 43

Transition Table A transition table is a tabular representation of the transition function that takes two arguments and returns a state. The column contains the state in which the automaton will be on the input represented by that column. The row corresponds to the state the finite control unit can be in. The entry for one row corresponding to state q and the column corresponds to input a is the state δ(q, a). 44

Transition Diagram Transition graph can be interpreted as a flowchart for an algorithm recognizing a language. A transition graph consists of three things: A finite set of states, at least one of which is designated the start state and some of which are designated as final states. An alphabet Σ of possible input symbols from which the input strings are formed. A finite set of transitions that show the change of state from the given state on a given input. 45

Example DFA states A b  q0 q1 q2 q1 q1 q3 q2 q2 q3 *q3 q3 q3 46 A= ({q0,q1,q2,q3},{a,b}δ,q0,{q3}) δ is given by δ(q0,a)=q1 δ(q0,b)=q2 δ(q1,a)=q1 δ(q2,b)=q2 δ(q1,b)=q3 δ(q2,a)=q3 δ(q3,a)=q3 δ(q3,b)=q3

Design a DFA with ∑ = {0, 1} accepts those string which starts with 1 and ends with 0. Design a DFA with ∑ = {0, 1} accepts the only input 101. 47

Design a DFA with ∑ = {0, 1} accepts the strings with an even number of 0's end by single 1. 48

Extended transition function δ ^ The DFA define a language: the set of all strings that result in a sequence of state transitions from the start state to an accepting state Extended Transition Function Describes what happens when we start in any state and follow any sequence of inputs If δ is our transition function, then the extended transition function is denoted by δ ^ The extended transition function is a function that takes a state q and a string w and returns a state p (the state that the automaton reaches when starting in state q and processing the sequence of inputs w) Let w=va then 60 δ(q, va) = δ ( δ ^ (q, v), a).

Language accepted by DFA The language of a DFA A = (Q, Σ, δ, q0, F), denoted L(A) is defined by L(A) = { w | δ ^ (q , w) is in F } The language of A is the set of strings w that take the start state q0 to one of the accepting states If L is a L(A) from some DFA, then L is a regular language 50

Nondeterministic Finite Automata An NFA is like a DFA, except that it can be in several states at once. This can be seen as the ability to guess something about the input. Useful for searching texts 51

Formal Definition of NFA A nondeterministic finite automaton (NFA) is a 5-tuple (Q,Σ,δ,q ,F) ,where Q is a finite set called the states, Σ is a finite set called the alphabet, δ:Q×Σ→P(Q) is the transition function, q ∈ Q is the start state, and F ⊆ Q is the set of accepting states. 52

Extended transition function δ ^ The extended transition function is a function that takes a state q and a string w and returns a set of states P (The set of possible state that the automaton reaches when starting in state q and processing the sequence of inputs w) Let w=va then δ ^ 𝑞0, 𝑣𝑎 = ∪ ′ ^ 𝑞 ∈ δ 𝑞0,𝑣 δ ( 𝑞 ′ ,a) 53

Language accepted by NFA The language L(A) accepted by the NFA A is defined as follows: L(A) = {w | δ ^ ( q0, w) ∩ F ≠ ∅ } 54

Example NFA 55

Design an NFA with ∑ = {0, 1} in which double '1' is followed by double '0'. Design an NFA with ∑ = {0, 1} accepts all string in which the third symbol from the right end is always 0. 56

Epsilon Nondeterministic Finite Automata Formal Definition A ε- NFA is a quintuple A=(Q,Σ,δ,q ,F) where Q is a set of states Σ is the alphabet of input symbols ε is never a member of Σ. Σ ε is defined to be (Σ ∪ ε) δ: Q × Σ ε → P(Q) is the transition function q ∈ Q is the initial state F ⊆ Q is the set of final states 57

Example ε- NFA ε- NFA for a language which contain Os followed by or more 1s. 58

ε- closure Epsilon means present state can goto other state without any input. This can happen only if the present state have epsilon transition to other state. Epsilon closure is finding all the states which can be reached from the present state on one or more epsilon transitions. ε- closure (0)={0,1,2} ε- closure(1)={1,2} ε- closure(2)={2} 59

ε- closure of state a 60

ε- closure of state 0,1,2,3,4 61

62

δ ^ - ε- NFA 𝑖=1 δ ^ 𝑞0, 𝑣𝑎 = ∪ 𝑘 𝑗=1 δ(𝑝 𝑖 , 𝑎) = ∪ 𝑚 j 𝐸𝑐𝑙𝑜𝑠𝑒(r ) Where δ (q0,v)= { p 1 ,p 2 ,…,p k } & 𝑖=1 ∪ 𝑘 δ(𝑝 𝑖 , 𝑎)= {r 1 ,r 2 ,…,r m } 63

Language accepted by ε- NFA The language of an ε- NFA E = (Q, Σ, δ, q0, F) is L(E) = {w | ˆ δ(q0, w) ∩ F ≠ ∅ } 64

Relationship between FAs 65

Every DFA is NFA but not vice versa. Both NFA and DFA have same power and each NFA can be translated into a DFA. There can be multiple final states in both DFA and NFA. NFA is more of a theoretical concept. DFA is used in Lexical Analysis in Compiler. Every NFA is ε- NFA but not vice-versa 66

Conversion of NFA to DFA Subset Construction Method Create state table from the given NFA. Create a blank state table under possible input alphabets for the equivalent DFA. Mark the start state of the DFA by q0 (Same as the NFA). Find out the combination of States {Q , Q 1 ,... , Q n } for each possible input alphabet. Each time we generate a new DFA state under the input alphabet columns, we have to apply step 4 again, otherwise go to step 6. The states which contain any of the final states of the NFA are the final states of the equivalent DFA. 67

NFA 68

Subset construction 69

Transition Diagram for the subset 70

Converted DFA 71

NFA  DFA State 1 →q0 q0 q1 q1 {q1, q2} q1 *q2 q2 {q1, q2} 72

Now we will obtain δ' transition for state q0. δ'([q0], ) = [q0] δ'([q0], 1 ) = [q1] The δ' transition for state q1 is obtained as: δ'([q1], ) = [q1, q2] ( new state generated) δ'([q1], 1 ) = [q1] 73

Now we will obtain δ' transition on [q1, q2]. δ'([q1, q2], ) = δ(q1, ) ∪ δ(q2, ) = {q1, q2} ∪ {q2} = [q1, q2] δ'([q1, q2], 1 ) = δ(q1, 1 ) ∪ δ(q2, 1 ) = {q1} ∪ {q1, q2} = {q1, q2} = [q1, q2] The state [q1, q2] is the final state as well because it contains a final state q2. 85

The transition table for the constructed DFA will be: State 1 →[q0] [q0] [q1] [q1] [q1, q2] [q1] *[q1, q2] [q1, q2] [q1, q2] 86

Conversion of ε- NFA to DFA Modified subset construction Find the ε- closure for the starting state of ε - NFA as a starting state of DFA. Find the states for each input symbol that can be traversed from the present. That means the union of transition value and their closures for each state of NFA present in the current state of DFA. If a new state is found, take it as current state and repeat step 2. Repeat Step 2 and Step 3 until there is no new state present in the transition table of DFA. Mark the states of DFA as a final state which contains the final state of ε- NFA. 87

Example Let us obtain ε- closure of each state. ε- closure {q0} = {q0, q1, q2} ε- closure {q1} = {q1} ε- closure {q2} = {q2} ε- closure {q3} = {q3} ε- closure {q4} = {q4} 77

let ε- closure {q0} = {q0, q1, q2} be state A δ'(A, 0) = ε- closure {δ((q0, q1, q2), 0) } = ε- closure {δ(q0, 0) ∪ δ(q1, 0) ∪ δ(q2, 0) } = ε- closure {q3} = {q3} call it as state B . δ'(A, 1) = ε- closure {δ((q0, q1, q2), 1) } = ε- closure {δ((q0, 1) ∪ δ(q1, 1) ∪ δ(q2, 1)} = ε- closure {q3} = {q3} = B. 78

δ'(B, 0) = ε- closure {δ(q3, 0) } = ϕ δ'(B, 1) = ε- closure {δ(q3, 1) } = ε- closure {q4} = {q4} i.e. state C δ'(C, 0) = ε- closure {δ(q4, 0) } = ϕ δ'(C, 1) = ε- closure {δ(q4, 1) } = ϕ 79

ε- closure(q0) = {q0, q1, q2} ε- closure(q1) = {q1, q2} ε- closure(q2) = {q2} 80

δ'(A, 0) = ε- closure{δ((q0, q1, q2), 0)} = ε- closure{δ(q0, 0) ∪ δ(q1, 0) ∪ δ(q2, 0)} = ε-closure{q0} = {q0, q1, q2} δ'(A, 1) = ε- closure{δ((q0, q1, q2), 1)} = ε- closure{δ(q0, 1) ∪ δ(q1, 1) ∪ δ(q2, 1)} = ε-closure{q1} = {q1, q2} call it as state B δ'(A, 2) = ε- closure{δ((q0, q1, q2), 2)} = ε- closure{δ(q0, 2) ∪ δ(q1, 2) ∪ δ(q2, 2)} = ε-closure{q2} = {q2} call it state C 81

δ'(B, 0) = ε- closure{δ((q1, q2), 0)} = ε- closure{δ(q1, 0) ∪ δ(q2, 0)} = ε-closure{ϕ} = ϕ δ'(B, 1) = ε- closure{δ((q1, q2), 1)} = ε- closure{δ(q1, 1) ∪ δ(q2, 1)} = ε-closure{q1} = {q1, q2} i.e. state B itself δ'(B, 2) = ε- closure{δ((q1, q2), 2)} = ε- closure{δ(q1, 2) ∪ δ(q2, 2)} = ε-closure{q2} = {q2} i.e. state C itself 82

δ'(C, 0) = ε- closure{δ(q2, 0)} = ε-closure{ϕ} = ϕ δ'(C, 1) = ε- closure{δ(q2, 1)} = ε-closure{ϕ} = ϕ δ'(C, 2) = ε- closure{δ(q2, 2)} = {q2} 83

ENFA to DFA 84
Tags