Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 111 Computability, etc. Midterm review. Turing machines. Finite state machines. Push down automata. Homework: FSA, PDA, TM problems (can work in teams)

Similar presentations


Presentation on theme: "1 111 Computability, etc. Midterm review. Turing machines. Finite state machines. Push down automata. Homework: FSA, PDA, TM problems (can work in teams)"— Presentation transcript:

1 1 111 Computability, etc. Midterm review. Turing machines. Finite state machines. Push down automata. Homework: FSA, PDA, TM problems (can work in teams)

2 1 111 Midterm go over…

3 1 111 Theoretical Computer Science Notion of computability –what it means to be computable –models of different levels Complexity –what it takes in terms of resources to solve a class of problems Example: one sorting algorithm takes O(n 2 ), another takes O(n*log(n))

4 1 111 Benefits Practical as well as theoretical Sharpen logical/thinking/problem solving skills Learn history Appreciate when good solutions may be appropriate

5 1 111 Background The study of computability preceded the invention of computers. –What does it mean for something (a function, a set of numbers) to be computed/calculated/evaluated in a mechanical, procedural way? –Related to a problem posed by Hilbert in 1900 Solved by Alan Turing, and others (Post, Church) in the early 1930s.

6 1 111 Posting topic? How old are computers?

7 1 111 Turing work Defined an abstract machine (is this a contradiction in terms?): came to be called a Turing Machine for computing specific functions… ALSO defined set of functions called the recursive functions, made up by a starter set of functions with certain ways of building on functions to get new functions –Note: this definition of a recursive function is more general than "a function that calls itself". Primitive recursion is one of the building methods. Proved any function computed by a Turing Machine was a recursive function AND any recursive function can be computed by a Turing Machine. –Also proved these two definitions equivalent to one made by Post –Many other functions proved equivalent

8 1 111 Turing machine Imagine An [infinite] tape with cells or slots. Each cell can hold a symbol (from a finite alphabet) or a blank A specific cell is under the machine head where it can be read The machine is in one of a finite number of states For each state reading a given symbol, there is a fixed set of actions: –Optionally, erase and write a new symbol + –Optionally, change to another state + –Move left, right, or stay fixed (halting)

9 1 111 Turing machine function A given Turing machine computes a function F(input)  output by –representing the input on the tape and placing the head to the left of the input –Starting the TM in a special state called the Start state –If the function halts, then the content on the tape represents the output using an agreed upon representation. Related formulism: a TM recognizes a set of numbers or a set of strings of symbols (aka a language) if the TM halts in a state designated as an accepting state on each number/string in the set AND halts in a state designated as a rejecting state on numbers/strings not in the set.

10 1 111 Example: adding 1 Let the alphabet be B (for blank) and 1 Encode positive integers (0, 1, 2,…) by N+1 1s for input (so zero can be represented) Encode (interpret) output by counting up all the 1s on the tape (alternative: require one more 1.) States are Start state S, W, F for final Start head at start of input

11 1 111 Example: Adding 1 Definition of output exact # of 1s Three states: S, W, F State S: –Sees a 1, moves to the right and changes to State W. –Sees a blank, does nothing State W: –Sees a 1, moves to the right. –Sees a blank, changes to State F. State F: does nothing (halts) May not be needed CHECK IT with a couple of examples.

12 1 111 Example: adding 1 Definition of output: 1 more Three states: S, W, F State S: –Sees a 1, moves to the right and changes to State W. –Sees a blank, does nothing (invalid input) State W: –Sees a 1, moves to the right. –Sees a blank, writes a 1, changes to State F. State F: does nothing (halts) May not be needed CHECK IT with a couple of examples.

13 1 111 Classwork: adding two integers Encode the two integers N and M by placing N+1 1s followed by 1 blank followed by M+1 1s Make output be (N+M)+1 1s contiguously on the tape –Alternative: use the encoding of exactly N+M 1s anywhere on the tape.

14 1 111 Overview Define different types of machines. –abstract machines Machines are fed (my term) strings in a specified alphabet. Machines scan the strings and say yes or no (accept or reject) Each machine accepts strings in a certain pattern. We call the set of strings in that pattern a language.

15 1 111 Overview Repeat: a language is a set of strings. This set may be finite or infinite.

16 1 111 Example The [written, formal] English language is an infinite set of sentences made up of valid words, spaces and punctuation. Why infinite?

17 1 111 Example The set of all legal (acceptable, no syntax errors) Processing programs is a language. It also is infinite.

18 1 111 Overview, cont. Each machine  a language Each type of machine  set of languages Presumably, more powerful machines (machines with more capability) could accept a larger set of languages. It will turn out that some changes are less powerful than you would think…

19 1 111 Aside Turing Machines represented/implemented functions: –get input, produce output: an answer. These other machines: the input is a string of symbols in a fixed alphabet. The output is yes or no –or some other indication of yes, this is a string in the language; or no it is not.

20 1 111 Alphabets 2 symbols 0 and 1 or abcdefghijklmnopqrstuvwxyz or subset of the alphabet, say {a, b, c} or all symbols used in languages such as JavaScript, Processing, etc. It will turn out that alphabets can be represented by strings of 0 and 1…

21 1 111 Finite State Machine also called finite state automaton. Plural is automata. A FSM has a finite number of states! –express by writing out s0, s1, s2, etc. or drawing circles. –One state is specified as the initial state. –One or MORE states are specified as Final or Accepting states.

22 1 111 FSM, cont. For each state, there is a state transition table: for each symbol in the alphabet, there is a switch to another state or to stay in the same state. Draw this by a graph: representing the states by nodes and the edges by the state transition table.

23 1 111 Exercise Draw the graph –Initial state s0: 0 go to s1, 1 go to s2 –s1: 0 go to s1, 1 go to s3 –s2: 0 go to s3, 1 go to s2 –s3: 0 go to s3, 1 go to s3 –s1 and s2 are accepting states. What strings does it accept?

24 1 111 Problem Let's design a FSM that will accept strings over {0,1} of length 3 and nothing else.

25 1 111 Approach Take problem and think about different conditions that could arise and you need to keep track of… These will be the different states, or at least a first guess at the different states. For the "length 3" problem –start –length 1 –length 2 –length 3 –more than length 3

26 1 111 Problem Alphabet {a, b, c, d}. Language is all strings with at least one instance inside the string of abc. What are possible states?

27 1 111 Start of approach for abc States start a ab abc a and then something not a b. But maybe that can put us back at the start. ab and then something not a c. But maybe that can put us back at the start abc and anything else. But that can just keep us at the abc stage.

28 1 111 Finish the problem For the language containing all strings that have at least one abc inside. States: –start –a –ab –abc What are the accepting state(s)? What are the edges?

29 1 111 Your turn Each student draw a FSM over {0,1} Find a partner and try each other's FSM on sample strings.

30 1 111 Tricky but important The empty string is a string! Some languages may contain it, some may not. Design a FSM that accepts the empty string and only the empty string.

31 1 111 Definition A language is called a regular language if there is a finite state automaton that accepts it. –feed in a string in the language L and the FSM ends in an accepting state. –feed in a string that is NOT in the language and the FSM ends in a non-accepting state. You will need to check both things.

32 1 111 Cautions Empty set is not the empty string. The set consisting of one string, the empty string, is NOT empty. The set with no members, that is, consists of no strings, is a regular language. –What is a FSM for this language? Some regular languages are finite sets and some are infinite sets.

33 1 111 Stack Standard data structure used in programming. SOMETIMES it is built-in, say a Stack class. stack.push(x) adds x to the end x = stack.pop(); removes top element Last In: First Out (LIFO) NOTE: queue is the name for data structure LILO or FIFO

34 1 111 Push down automata FSM + a stack –stack is last in / first out. Reading and adding done only at the top. Adding is called pushing. Reading is done by popping the first item Non-deterministic Push Down automata recognize MORE languages than deterministic push down automaton. Non deterministic PDA are equivalent to Context Free languages so we focus on them and call them PDA…

35 1 111 Definition of PDA Finite set of States. Input alphabet. Stack alphabet. Starting state. Subset of States are accepting states. Transition function: State, Input or ∊,Top of Stack or ∊  State and Stack That is, for each combination of state, reading input, reading top of stack, the transition can be to new state, pushing a new symbol onto stack. Plus machine can do something without reading an input symbol and/or top of stack.

36 1 111 A PDA = (Q,A,K,d,q 0,F) –Q are the states. A is the input alphabet, K is the stack language (it can contain all or some of A plus other symbols), d is the transition function, q 0 is the first state, F is the subset of Q that are the accepting states. NOTE: x's here indicate what is called the cartesian product. –d is a function from Q x A ∊ x K ∊ to Q x K d(q,a, k)  (r,m) Function d for any state, input letter or ∊, top of stack MAY change state or remain at current state and may pop or push or pop AND push symbol onto the stack.

37 1 111 PDA accepts a string A string of letters w=w 1 w 2..w k in A is accepted by the PDA if there is a sequence of states r 1,r 2,..r m and strings s 0 s 1..s m (representing the stack) where r 1 is q 0 and s 0 is ∊ (Start at the start state and with an empty stack.) r m is in F (an accepting state). For all i, (r i+1,b) is in d(r i,w i+1,a) where s i = at and s i+1 = bt for some a, b in K ∊ and t in K* That is, the sequences obey the transition function. The transition function may have multiple values!

38 1 111 Preview There are different definitions/constructions/concepts that define the same set of functions or languages. So-called recursive functions (more later) correspond to computable (TM) functions. Languages defined by a Regular Expression (look it up) are languages recognized by a FSA. Languages defined by a Context Free Grammar (look it up) are languages recognized by a PDA.

39 1 111 Homework Define a FSA, alphabet {A,blank}, that accepts strings with even number of As. Define a second FSA that accepts strings with an odd number of As. Define a PDA, alphabet {A, blank,(, ),+} that accepts A, (A, A+A, (A+A), (A+(A+A)) etc. NOT A+, not unbalanced ( and ). Define TM that subtracts 1. If input is zero, then tape is cleared. Define Turing machine to subtract two numbers a and b, represented by a+1 1s followed by a blank followed by b+1 1s –if (a>=b), put (a-b) + 1 1s on the tape –if a<b, leave zero 1s in the tape OR return something else if a<b ???


Download ppt "1 111 Computability, etc. Midterm review. Turing machines. Finite state machines. Push down automata. Homework: FSA, PDA, TM problems (can work in teams)"

Similar presentations


Ads by Google