Presentation is loading. Please wait.

Presentation is loading. Please wait.

MA/CSSE 474 Theory of Computation Computation FSM Intro.

Similar presentations


Presentation on theme: "MA/CSSE 474 Theory of Computation Computation FSM Intro."— Presentation transcript:

1 MA/CSSE 474 Theory of Computation Computation FSM Intro

2 Trying Another PDA A PDA to accept strings of the form:
AnBnCn = {anbncn : n  0} We’ll see later that it is impossible. Q1

3 Turing Machines A read/write head and a tape that is infinite in both directions. Based on current state and symbol it sees on the tape, it writes a symbol (possibly the same one) to the tape and moves one position left or right. If it reaches an accepting state or rejecting state, it halts. The (finite) input string is originally written consecutively on a portion of the tape; the rest is initially blank, but the read/write head can write things on any square. At any given time, only a finite part of the tape is non-blank. The head starts at the square to the left of the first input symbol.

4 Turing Machines A Turing Machine to accept AnBnCn: Q2

5 Decidable and Semidecidable Languages
A language L is decidable iff there exists a Turing machine M that halts on all inputs, accepts all strings that are in L, and rejects all strings that are not in L. In other words, M can always say yes or no, as appropriate.

6 Decidable and Semidecidable Languages
A language L is semidecidable iff there exists a Turing machine M that accepts all strings that are in L and does not accept any string that is not in L. Given a string that is not in L, M may reject or it may loop forever. M can always recognize a string in L and say yes, but it may not know when it should give up looking for a solution and say no. A language L is undecidable iff it is not semidecidable. Q3

7 Languages and Machines
Rule of Least Power: “Use the least powerful language suitable for expressing information, constraints or programs on the World-wide web.” --Tim Berners-Lee and Noah Mendelsohn(2006)

8 Some "Canonical" Languages
AnBn = {anbn : n >= 0} Bal = { strings of balanced parentheses} WW = {ww : w  *} PalEven {wwR : w  *} AnBnCn = {anbncn : n >= 0} HPALL = {<T> : 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} Go really fast here

9 Nondeterminism A nondeterministic machine in a given state, looking at a given symbol (and with a given symbol on top of the stack if it is a PDA), has a choice of multiple possible moves that it can make. If there is a move that leads toward acceptance, it makes that move.

10 Nondeterminism Given a string in {a, b}*, is it in PalEven = { wwR : w  {a,b}*} ? PDA Choice: Continue pushing, or start popping? This language can be accepted by a nondeterministic PDA but not by any deterministic one.

11 Nondeterministic value-added?
Ability to recognize additional languages? FSM: no PDA : yes TM: no Ease of designing a machine for a particular language Yes in all cases We will prove these later

12 Nondeterministic Computation
First case: Each action will return True, return False, or run forever. If any of the actions returns TRUE, choose returns true. If all of the actions return FALSE, choose returns FALSE. If none of the actions return TRUE, and some do not halt, choose does not halt. 1. choose (action 1;; action 2; action n ) 2. choose(x from S: P(x)) First case: Each action will return True, return False, or run forever. If any of the actions returns TRUE, choose returns true. If all of the actions return FALSE, choose returns FALSE. If none of the actions return True, and some do not halt, choose does not halt. Second case: S may be finite or infinite (with a generator(enumerator)). If P returns true on some x, so does Choose If it can be determined that P(x) is false for all x in P, return False. Otherwise, fail to halt. Second case: S may be finite, or infinite with a generator (enumerator). If P returns true on some x, so does Choose If it can be determined that P(x) is false for all x in P, return False. Otherwise, fail to halt.

13 Implementing Nondeterminism
before the first choice choose makes first call to choose first call to choose choice choice 2 second call to choose second call to choose choice choice 2

14 Sample Decision Problems
Example: Given two strings s and t, does s occur anywhere as a substring of t? It's easy to see that this is decidable. A decision problem is a problem that has a yes/no answer for each instance. A decision problem may be decidable, undecidable, or semidecidable. A decision procedure is an algorithm to solve a decision problem. Must always halt and return an answer. Q4

15 Sample Decision Problems Prime Fermat Numbers
Fermat numbers: Fn = , n  0 F0 = 3, F1 = 5, F2 = 17, F3 = 257, F4 = 65,537, F5 = 4,294,967,297 • Are there any prime Fermat numbers less than 1,000,000? • Are there any prime Fermat numbers greater than The first one is clearly decideable: Sketch the algorithm. What about the second one? Why won't the same approach work? But there is a decision procedure for this problem: Return yes Or Return No. One of these is the correct algorithm, but we just don't know which one. Q5

16 Sample Decision Problems
Given a Java program P, is there some input string on which P halts? Given a Java program P, and a value v, is v the shortest input string on which P halts? These turn out not to be decidable.

17 SAT Decision Problem Given a Boolean (propositional) wff, is it satisfiable? Examples: 1. (P  Q)  Q  P 2. P  R This and next 2 slides hidden because of time shortage in Pick up later? I unhid for summer.

18 Nondeterministically Deciding SAT
decideSAT(w: Boolean wff) = If there are no variables in w then: Simplify w until it is either True or False. Return w. Else: Find P, the first variable in w. /* Let w/P/x mean the wff w with every instance of P replaced by x. */ Return choose (decideSAT(w/P/True);; decideSAT(w/P/False)).

19 A Tractability Hierarchy
P NP PSPACE P  NP  PSPACE P contains those languages that can be decided in time that grows as some polynomial function of the length of the input string NP contains those languages that can be decided by a nondeterministic machine (one that can conduct a search by correctly guessing which move to make) with the property that the amount of time required to explore one sequence of guesses ( one path) grows as some polynomial function of the length of the input PSPACE contains those languages that can be decided by a machine whose space requirement grows as some polynomial function of the length of the input.

20 Functions on Languages
Functions whose domains and ranges are languages maxstring(L) = {w  L: z  * (z    wz  L)}. Examples: • maxstring( AnBn ) • maxstring( {a}* ) Let INF be the set of infinite languages. Let FIN be the set of finite languages. Are the language classes FIN and INF closed under maxstring? maxstring(AnBn) = AnBn - { } maxstring(a*) =  FIN, yes, because every subset of a finite set is finite. INF, no, see {a}* example Q6

21 Functions on Languages
chop(L) = {w : xL (x = x1cx2, x1  L*, x2  L*, c  L, |x1| = |x2|, and w = x1x2)}. What is chop(AnBn)? What is chop(AnBnCn)? Are FIN and INF closed under chop? Empty set {a2n+1b2nc2n+1} Yes (FIN) No (INF) If we don't have much time left, we'll skip this in class

22 Functions on Languages
firstchars(L) = {w : yL (y = cx  c  L  x  L*  w  {c}*)}. . What is firstchars(AnBn)? What is firstchars({a, b}*)? Are FIN and INF closed under firstchars? firstchars(AnBn) = {a}* firstchars({a, b}*) = {a}*  {b}* FIN, no. firstchars({a}) = {a}* INF, yes. If we don't have much time left, we'll skip this in class

23 Representing Languages as Machines
Compute union using descriptions like: {w  {a, b}* : w has odd length} {w  {a, b}* : all a’s in w precede all b’s} Much easier to do union, concatenation, etc. with machines.

24 Finite State Machine Intro

25 Languages and Machines

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

27 Finite State Machines An (ancient) Soda Machine FSM to accept $.25 in change: (Note that a couple of the dime transitions are incorrect, but you get the idea).

28 Another FSM Example A C B D
But it is more complicated, because time is also an input. But the use of the buttons can be modeled as an FSM. B D

29 Definition of a DFSM The D is for Deterministic
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, sM), to indicate that this component is part of machine M.

30 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.

31 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: (sM, w)

32 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 . Q7

33 Computations Using FSMs
A computation by M is a finite sequence of configurations C0, C1, …, Cn for some n  0 such that: • C0 is an initial configuration, • Cn is of the form (q, ), for some state q  KM, • i{0, 1, …, n-1} (Ci |-M Ci+1)

34 An Example Computation
An FSM M that accepts decimal representations of odd integers: even odd even q q1 odd On input 235, the configurations are: (q0, 235) |-M (q0, 35) |-M Thus (q0, 235) |-M* (q1, )

35 Accepting and Rejecting
A DFSM M accepts a string w iff: (sM, w) |-M* (q, ), for some q  AM A DFSM M rejects a string w iff: (sM, w) |-M* (q, ), for some q  AM 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 in |w| steps. 201020: We got to this slide but not to the quiz question/proof. If time, have them do FSM diagram for "divisible by 3" Base case: If w is , it halts in 0 steps. Assume true for strings of length n and show for strings of length n+1. Let w  *, w   |w| = n+1 for some n  ℕ. Then w is ax for some a , x*, |x| = n. Let q' be (q, a). Then (q,w) |-M (q', x) By induction, from configuration (q', x), M halts in n steps. So, starting from the original configuration, M halts in n+1 steps. Q8-10


Download ppt "MA/CSSE 474 Theory of Computation Computation FSM Intro."

Similar presentations


Ads by Google