= 0} Bal = { strings of balanced parentheses} WW = {ww : w   *} PalEven {ww R : w   *} A n B n C n = {a n b n c n : n >= 0} HP ALL = { : T is a Turing machine that eventually halts, no matter what input it is given} PRIMES = {w : w is the binary encoding of a prime integer}"> = 0} Bal = { strings of balanced parentheses} WW = {ww : w   *} PalEven {ww R : w   *} A n B n C n = {a n b n c n : n >= 0} HP ALL = { : T is a Turing machine that eventually halts, no matter what input it is given} PRIMES = {w : w is the binary encoding of a prime integer}">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

MA/CSSE 474 Theory of Computation Decision Problems DFSMs.

Similar presentations


Presentation on theme: "MA/CSSE 474 Theory of Computation Decision Problems DFSMs."— Presentation transcript:

1 MA/CSSE 474 Theory of Computation Decision Problems DFSMs

2 Your Questions? Friday's class Reading Assignments HW1 solutions HW2 or HW3 Anything else

3 Some "Canonical" Languages from our textbook A n B n = {a n b n : n >= 0} Bal = { strings of balanced parentheses} WW = {ww : w   *} PalEven {ww R : w   *} A n B n C n = {a n b n c n : n >= 0} HP ALL = { : T is a Turing machine that eventually halts, no matter what input it is given} PRIMES = {w : w is the binary encoding of a prime integer}

4 Decision Problems

5 A decision problem is simply a problem for which the answer is yes or no (True or False). A decision procedure answers a decision problem. Examples: Given an integer n, does n have a pair of consecutive integers as factors? The language recognition problem: Given a language L and a string w, is w in L? Our focus in this course Recap - Decision Problems

6 Recap - The Power of Encoding Anything can be encoded as a string. For example, on a computer everything is encoded as a string of bits. Assume that we have a scheme for encoding objects (integers, for example). is the string encoding of X. is the string encoding of the pair X, Y. Problems that don’t look like decision problems about strings and languages can be recast into new problems that do look like that.

7 Web Pattern Matching Pattern matching on the web: Problem: Given a search string w and a web document d, do they “match”? In other words, should a search engine, on input w, consider returning d? An instance of the problem: (w, d) The language to be decided: { : d is a candidate match for the string w}

8 The Halting Problem Does a program always halt? Problem: Given a program p, written in some some standard programming language L, is p guaranteed to halt, no matter what input it is given? An instance of the problem: Does Python program "print(input())" always halt? The language to be decided: HP ALL = {p  L : p halts on all inputs}

9 Primality Testing Problem: Given a nonnegative integer n, is it prime? An instance of the problem: Is 9 prime? To encode the problem we need a way to encode each instance: We encode each nonnegative integer as a binary string. The language to be decided (2 ways to express it): PRIMES = {w : w is the binary encoding of a prime integer}. Equivalent: PRIMES = { : n is a prime integer}.

10 Problem: Given an undirected graph G, is it connected? An instance of the problem: 1 2 3 4 5 Encoding of the problem: Let V be a set of binary numbers, one for each vertex in G. Then we construct  G  as follows: Write |V| as a binary number, Write a list of edges; each pair of binary numbers represents one edge. Separate all such binary numbers by “/”. 101/1/10/1/100/10/101/10/11 The language to be decided: CONNECTED = {w  {0, 1, /}* : w = n 1 /n 2 /…n i, where each n i is a binary string and w encodes a connected graph, as described above}. Graph Connectivity The string below encodes a connected graph, but 110/1/10/1/100/10/101/10/11 Encodes a graph that is not connected. Can you see why?

11 Problem: Given a protein fragment f and a complete protein molecule p, could f be a fragment from p? Encoding of the problem: Represent each protein molecule or fragment as a sequence of amino acid residues. Assign a letter to each of the 20 possible amino acids. So a protein fragment might be represented as AGHTYWDNR. The language to be decided: { : f could be a fragment from p}. Protein Sequence Alignment

12 Cast multiplication as language recognition: Problem: Given two nonnegative integers, compute their product. Encoding of the problem: Transform computing into verification. The language to be decided: L = {w of the form: x =, where: is any well-formed integer, and integer 3 = integer 1  integer 2 } 12x9=108  L 12=12  L 12x8=108  L Turning Problems into Language Recognition Problems

13 Cast sorting as language recognition decision problem: Problem: Given a list of integers, sort it. Encoding of the problem: Transform the sorting problem into one of examining a pair of lists. The language to be decided: L ={w 1 # w 2 :  n  1 (w 1 is of the form, w 2 is of the form, and w 2 contains the same objects as w 1 and w 2 is sorted)} Examples: #  L #  L Turning Problems Into Language Recognition Problems

14 Casting database querying as decision: Problem: Given a database and a query, execute the query. Encoding of the problem: Transform the query execution problem into evaluating a reply for correctness. The language to be decided: L = {d # q # a: d is an encoding of a database, q is a string representing a query, and a is the correct result of applying q to d} Example: (name, age, phone), (John, 23, 567-1234) (Mary, 24, 234-9876)#(select name age=23)# (John)  L Turning Problems Into Decision Problems

15 By equivalent we mean that either problem can be reduced to the other. If we have a machine to solve either problem, we can use it to build a machine to solve the other, using only the starting machine and other functions that can be built using machines of equal or lesser power. We will see that eduction does not always preserve efficiency! The Traditional Problems and their Language Formulations are Equivalent

16 Consider the multiplication example: INTEGERPROD = {w of the form x =, where: is any well-formed integer representation, and integer 3 = integer 1  integer 2 } Given a multiplication procedure, we can build a language recognition decision procedure : Given the language recognition procedure, we can build a multiplication procedure : An Example

17 Regular Languages Regular Language Regular Expression Finite State Machine Represents Accepts

18 A real-world FSM Example A D C B

19 Recap - Definition of a DFSM M = (K, , , s, A), where: K is a finite set of states  is a (finite) alphabet s  K is the initial state (a.k.a. start state) A  K is the set of accepting states  : (K   )  K is the transition function Sometimes we will put an M subscript on K, , , s, or A (for example, s M ), to indicate that this component is part of machine M. The D is for Deterministic

20 Acceptance by a DFSM Informally, M accepts a string w iff M winds up in some element of A after it has finished reading w. The language accepted by M, denoted L(M), is the set of all strings accepted by M. But we need more formal notations if we want to prove things about machines and languages.

21 Configurations of a DFSM A configuration of a DFSM M is an element of: K   * It captures the two things that affect M’s future behavior: its current state the remaining input to be read. The initial configuration of a DFSM M, on input w, is: (s M, w) Where s M is the start state of M.

22 The "Yields" Relations The yields-in-one-step relation: |- M : (q, w) ⊦ M (q', w') iff w = a w' for some symbol a  , and  (q, a) = q' The yields-in-zero-or-more-steps relation: ⊦ M * ⊦ M * is the reflexive, transitive closure of ⊦ M. Note that this accomplishes the same thing as the "extended delta function" that we considered on Day 1. Two notations for the same concept.

23 Computations Using FSMs A computation by M is a finite sequence of configurations C 0, C 1, …, C n for some n  0 such that: C 0 is an initial configuration, C n is of the form (q,  ), for some state q  K M,  i  {0, 1, …, n-1} (C i ⊦ M C i+1 )

24 An Example Computation A FSM M that accepts decimal representations of odd integers: even odd even q 0 q 1 odd On input 235, the configurations are: (q 0, 235) ⊦ M (q 0, 35) ⊦ M (q 1, 5) ⊦ M (q 1,  ) Thus (q 0, 235) ⊦ M * (q 1,  )

25 Accepting and Rejecting A DFSM M accepts a string w iff: (s M, w) ⊦ M * (q,  ), for some q  A M A DFSM M rejects a string w iff: (s M, w) ⊦ M * (q,  ), for some q  A M The language accepted by M, denoted L(M), is the set of all strings accepted by M. Theorem: Every DFSM M, in configuration (q, w), halts after |w| steps. Thus a DFSM accepts or rejects every string.

26 Proof of Theorem Theorem: Every DFSM M, in configuration (q, w), halts after |w| steps. Proof: by induction on |w| Base case: If w is , it halts in 0 steps. Induction step: Assume true for strings of length n and show for strings of length n+1. Let w   *, w  . Then | w | = n+1 for some n  ℕ. So w must be ax for some a, x *, | x | = n. Let q' be  (q, a ). By definition of ⊦, (q, w ) ⊦ M (q', x ) By the induction hypothesis, starting from configuration (q', x ), M halts after n steps. Thus, starting from the original configuration, M halts after n+1 steps.

27 Regular Languages Definition: A language L is regular iff L = L(M) for some DFSM M.

28 Example L = {w  { a, b }* : every a is immediately followed by a b }. state  input  ab q 0 q1q1 q0q0 q1q1 q2q2 q0q0 q2q2 q2q2 q2q2  can also be represented as a transition table: q 2 is a dead state.

29 Exercises: Construct DFSMs for L = {w  { 0, 1 }* : w has odd parity}. iI.e. an odd number of 1's. L = {w  { a, b }* : no two consecutive characters are the same}. L = {w  {a, b}* : # a (w) >= # b (w) } L = {w  {a, b}* : ∀ x,y  {a, b}* (w=xy → | # a (x) - # b (x)| <= 2 ) }


Download ppt "MA/CSSE 474 Theory of Computation Decision Problems DFSMs."

Similar presentations


Ads by Google