CPSC 121 Lecture 36 April 8, 2009 Menu April 8, 2009 Topics: Example: NFA to DFA Conversion Final Reading List Summary The End! Reminders: On-line Quiz 12 deadline 5:00pm TODAY Teaching evaluation survey now available on-line deadline 23:00 April 12 Review session (Steve): Thu April 9, 9:00, DMP 310 Review session (Bob): Thu April 16, 14:00, DMP 110 Final exam Friday, April 17, 7:00pm, SRC A READ the WebCT Vista course announcements board Example: NFA to DFA Conversion The proof given in Lecture 35 that NFAs are not more powerful than DFAs shows explicitly how to construct a DFA corresponding to any given NFA. Let s demonstrate that construction for the specific example of the decimal number NFA (also first given in Lecture 35). The slides version of the lecture animates the construction, step by step. The figure given here in the with notes version shows only the final result. The steps, however, are described in words. Recall the NFA... Recall: Decimal Number NFA S S 0 1 int dot real The NFA has five (named) states: s 0, s 1, int, dot and real. Two of the states, s 0 and s 1, are initial states. Two of the states, int and real, are accepting states. Each state in the DFA corresponds to an element of the power set of the sets of states in the NFA. Thus, our DFA (potentially) has 2 5 = 32 states. Fortunately, as is the case in our example, not all states in the resulting DFA always are reachable. (Non reachable states are eliminated in the construction). We name each state in the DFA explicitly, using set notation, according to which element it is in the power set of the sets of states in the NFA. For example, the state in the DFA corresponding to the states s 1 and int in the NFA is named {s 1, int} We begin with the start state of the DFA and continue adding reachable states until the entire DFA is constructed.
1. The start state of the DFA is the state corresponding to the subset of all start states in the NFA. The start states in the NFA are s 0 and s 1. Thus, the start state in the DFA is {s 0, s 1 }. Create this as a state in the DFA and label it accordingly. (This is shown as the first step in the slides version animation). 2. We now consider possible next states when the DFA is in state {s 0, s 1 }. That is, we consider possible next states when the NFA is in either state s 0 or in state s 1. For input 0 9 and the NFA in state s 0 or s 1, the next states are either s 1 or int. Create a state in the DFA named {s 1, int} and add the associated labelled arc from the start state. The state {s 1, int} in the DFA is designated as an accepting states since one of its members, int, is an accepting state in the NFA. For input and the NFA in state s 0 or s 1, the only next state is s 1. Create a state in the DFA named {s 1 } and add the associated labelled arc from the start state. For input. and the NFA in state s 0 or s 1, there is no next state. Create a state in the DFA named { } (for the empty set) and add the associated label from the start state. (These three new states, with their arcs from the start state, are shown as the second step in the slides version animation). There are now three new states in the DFA to consider, {s 1 }, {s 1, int} and { }. 3. Consider possible next states when the DFA is in state {s 1 }. For input 0 9 and the NFA in state s 1, the next states are either s 1 or int. The state in the DFA named {s 1, int} already exists. Add the associated labelled arc from the state {s 1 }. For inputs. or and the NFA in state s 1, there is no next state. The state in the DFA named { } (for the empty set) already exists. Add the associated labelled arc from the state {s 1 }. (These two new labelled arcs are shown as the third step in the slides version animation). 4. Consider possible next states when the DFA is in state {s 1, int}. For input 0 9 and the NFA in state s 1 or int, the next states are either s 1 or int. The state in the DFA named {s 1, int} already exists. Add the associated labelled arc from the state {s 1, int} to itself. For input. and the NFA in state s 1 or int, the only next state is dot. Create a state in the DFA named {dot} and add the associated labelled arc from the state {s 1, int}. For input and the NFA in state s 1 or int, there is no next state. The state in the DFA named { } (for the empty set) already exists. Add the associated labelled arc from the state {s 1, int}. (This new state, {dot}, and the three new labelled arcs are shown as the fourth step in the slides version animation). 5. Consider possible next states when the DFA is in state {dot}. For input 0 9 and the NFA in state dot, the only next state is real. Create a state in the DFA named {real} and add the associated labelled arc from the state {dot}. The state {real} in the DFA is designated as an accepting states since real, is an accepting state in the NFA. For inputs. or and the NFA in state dot, there is no next state. The state in the DFA named { } (for the empty set) already exists. Add the associated labelled arc from the state {dot}. (This new state, {real}, and the two new labelled arcs are shown as the fifth step in the slides version animation). 6. Consider possible next states when the DFA is in state {real}. For input 0 9 and the NFA in state real, the only next state is real. The state in the DFA named {real} already exists. Add the associated labelled arc from the state {real} to itself. 2
For inputs. or and the NFA in state real, there is no next state. The state in the DFA named { } (for the empty set) already exists. Add the associated labelled arc from the state {real}. (The two new labelled arcs are shown as the sixth step in the slides version animation). 7. Finally, consider possible next states when the DFA is in state { }. For any input 0 9,. or and the DFA in state { }, there is no next state. The state in the DFA named { } (for the empty set) already exists. Add the associated labelled arc from the state { } to itself. The final (complete) DFA is shown as the seventh (and last) step in the slides version animation and is given here in the with notes version. In this (simple) example, the NFA had five states and the corresponding DFA has only six (reachable) states. In general, things are not so simple. It s important to note that, owing to the power set construction of the states of the DFA from the states of the NFA, we may indeed need up to 2 n states in the DFA constructed from a given n state NFA. Example 1: Build the DFA... Construct the DFA corresponding to the decimal number NFA {s,s } 0 1 { s 1,int} {dot} {real} {s } 1 { } Final Reading List All textbook readings are from Epp (3rd edition). (You should be able to solve the textbook problems given in each section). Final Exam Coverage 1. Section 203 Lectures 1 36 cumulative [slides] and [with notes] versions provided 2. Epp: Chapter 1 Chapter 2 Sections 3.1, 3.6, and 3.7 plus Theorem 3.4.1 and pages 159 163 3
Section 4.1 (purely as background reading) Sections 4.2 4.4 Sections 5.1 5.3 Section 7.1 and Section 7.2 (excluding Application: Hash Functions and Properties of Exponential and Logarithmic Functions ) Section 12.1 12.2 3. Labs 0 8 Note that while the textbook readings are a crucial part of the course, material from the labs, lectures, assignments, and tutorials that is not drawn directly from the textbook also is assessable on the final exam. Lab topics often complement but are not directly drawn from textbook material. Specifically, Labs 3, 7 and 8 were assigned as readings for Section 203 lectures. The rules for aides during the final exam are the same as they were for the midterm exam. They are repeated here for reference. Final Exam Aides The final exam is open book You may bring and access during the exam: any (reasonable) number of textbooks one binder or folder of notes The binder or folder may contain any notes you like (e.g., handwritten notes, printouts of practice finals, midterms, recipes for chocolate cake, etc.) We recommend carefully organizing and thinking through the material beforehand In a timed situation, you ll likely want to access your notes and books as infrequently as possible Finally, you may not have any other aides during the exam. (In particular, you may not use any electronic device such as a calculator) Summary Here is the cumulative set of learning goals for the course. 1. Propositional logic, combinational circuits and number representations: 1. Evaluate the truth of simple propositional logic statements using truth tables 2. Translate back and forth between simple natural language statements and propositional logic 3. Translate back and forth between propositional logic statements and combinational circuits built using standard logic gates (NOT, AND, OR, XOR, NAND, NOR) 4. Design combinational circuits based on propositional logic expressions and their equivalent logic circuits to solve real problems (e.g., a 7 segment LED numerical display) 5. Evaluate propositional logic as a model of computation for combinational circuits, identifying at least one explicit shortfall (e.g., timing based on gate delays, fan-out, wire length, instabilities, shared sub-circuits, etc.) 4
6. Translate back and forth between simple natural language statements and propositional logic, including conditionals and biconditionals 7. Evaluate the truth of simple propositional logic statements using truth tables, including conditionals and biconditionals 8. Given a propositional logic statement and a logical equivalence rule, apply the rule to create the equivalent statement 9. Transform propositional logic statements by application of logical equivalence rules in order to: simplify complex statements prove the logical equivalence of two statements represent statements in a standard canonical form 10. Convert integers from octal or hexadecimal to binary and back 11. Convert positive integers from decimal to binary by repeated division (octal/hex as intermediary) 12. Convert positive integers from binary to decimal 13. Take the 2 s complement of a fixed width binary number 14. Convert signed (either positive or negative) integers to binary and back 15. Add and subtract fixed width, 2 s complement (signed) binary integers 16. Convert decimal fractions (in positional notation) to binary fractions (in positional notation) by repeated multiplication (octal/hex as intermediary) 17. Critique different number representations describing their strengths and weaknesses (finite representation, overflow, etc.). Representations include: positional notation (binary, octal, decimal, hexadecimal); binary coded decimal (BCD); fixed-width, 2 s complement (signed) binary; IEEE 754 floating point (single and double precision) 18. Use truth tables to establish or refute the validity of a proposed rule of inference 19. Given a rule of inference and propositional logic statements that correspond to the rule s premises, apply the rule to infer a new statement implied by the original statements 20. Explore the logical consequences of a set of propositional statements by application of both equivalence and inference rules, especially in order to transform statements into a desired canonical form 2. Predicate calculus: 1. Understand the definition of a predicate and its associated domain of discourse 2. Evaluate the truth of predicates applied to particular values 3. Understand what it means for a predicate to be universally quantified or existentially quantified 4. Show predicate logic statements are true by enumerating examples (i.e., all examples in the domain of discourse for a universally quantified statement or at least one example for an existentially quantified statement) 5
5. Show predicate logic statements are false by enumerating counterexamples (i.e., one counterexample for a universally quantified statement or all for an existentially quantified statement) 6. Translate between statements in formal predicate logic notation and equivalent statements in closely matching informal language (i.e., informal statements with clear and explicitly stated quantifiers) 7. Construct predicate logic statements to capture the relationships between properties of various objects both real-world like and computing related 8. Determine the negation of any quantified statement, including multiply quantified statements, using generalized De Morgan 9. Given a quantified statement and a logical equivalence rule, apply the rule to create an equivalent statement 10. Apply additional rules of inference for quantified statements including universal instantiation, universal generalizarion, existential instantiation, existential generalization, universal modus ponens, universal modus tollens, and universal transitivity 11. Prove (or disprove) conjectures involving quantified statements using basic proof techniques, both direct and indirect, including proof by contradiction and proof by contrapositive 3. Proof techniques: 1. Understand the following basic proof strategies: constructive/nonconstructive proofs of existence ( witness ) disproof by counterexample exhaustive proof generalizing from the generic particular ( WLOG ) direct proof ( antecedent assumption ) proof by contradiction proof by contrapositive proof by cases well enough to identify the strategy when it is encountered in a given proof and well enough to apply it as a strategy in a novel proof 2. Devise and attempt multiple different, appropriate proof strategies for a given theorem including all those listed above that use definitions, premises, logical equivalences, rules of inference and rules of inference for quantified variables 3. Prove theorems requiring only simple insights beyond choice of proof strategy or for which the necessary insight is given as a hint/suggestion 4. Sequential circuits and the simple computer: 6
1. To design and analyze simple sequential circuits: circuits that perform sequences of steps and remember information from previous steps 2. To define a finite state machine (FSM) (aka a Deterministic Finite State Automaton (DFA)) both in terms of a state transition diagram and a state transition table 3. To implement any specific FSM (of modest complexity) as a sequential circuit 4. To specify the overall architecture of a (Von Neumann) stored program computer an architecture that instantiates the principle that both program and data are bits (i.e., state) loaded and stored in (common) memory 5. To interpret the (Von Neumann) stored program computer as a universal FSM (i.e., as a FSM that can implement any other FSM via changes to the program and data) 6. To analyze the (TKGate simulated) operation of a specific simple computer design. This includes understanding the basic fetch-decode-execute instruction cycle and the data flow to/from the arithmetic logic unit (ALU), the main memory, the Instruction Register (IR) and the Program Counter (PC) under control of the microcontroller 7. To run a provided program on the (TKGate simulated) simple computer. To test the behaviour of the program by monitoring values displayed in key registers during program execution. To modify the provided program to achieve other specified functionality 8. To complete CPSC 121 s bottom up treatment of circuits: demonstrating that: switch logic gate combinational sequential FSM simple circuit circuit computer (a) We can specify each one of these stages completely, both formally (i.e., as theory) and practically (i.e., as a constructive implementation) (b) There are no significant gaps between stages (i.e., we can build each successive stage using elements from the previous stage) 5. Mathematical induction: 1. Recognize mathematical induction as a proof technique for statements universally quantified over the positive integers, Z + 2. Given a theorem to prove expressed in terms of a variable, n, universally quantified over Z +, write out the skeleton of an inductive proof including: the base case(s) that need to be proved, the induction hypothesis, and the inductive step that needs to be proved 3. Complete all the steps of a formal proof by induction using either regular (weak) or strong induction, as needed 4. Critique formal inductive proofs to determine whether they are valid or where the error(s) lie if they are invalid 6. Sets: 7
1. Define basic set operations: union, intersection, complement, and set difference 2. Define logical operations on sets: subset, proper subset and set equality (in terms of predicate logic and set membership, e.g., x X) 3. Translate between sets represented explicitly, possibly using ellipses..., e.g., {4, 6, 8,... }, and using set builder notation, e.g., {x Z + x 2 > 10 x is even} 4. Compute union, intersection, complement, set difference, subset and set equality operations on sets expressed explicitly, expressed using set builder notation, or expressed as a combination of these and set operations 5. Interpret the empty set (symbol { } or ), including the fact that the empty set has no members and that it is a subset of any set 6. Define an n-tuple 7. Define the power set and Cartesian product operations one sets in terms of predicate logic and set membership/subset relations 8. Compute the power set, Cartesian product, and cardinality operations on sets expressed in any of the set notations considered 9. Apply proof techniques learned earlier to proofs involving sets 7. Functions: 1. Define the terms domain, codomain, range, image, and pre-image 2. Use appropriate function syntax to relate these terms, e.g., f : A B indicates that f is a function mapping domain A to codomain B 3. Determine whether f : A B is a function given a definition of f as an equation or as a bipartite graph (i.e., arrow diagram) 4. Define the terms injective (one-to-one), surjective (onto), bijective (one-to-one correspondence) and inverse 5. Determine whether a given function is injective, surjective, and/or bijective 6. Apply proof techniques learned earlier to proofs about the properties (e.g., injectiveness, surjectiveness, bijectiveness, and function-ness) of functions and their inverses 8. DFAs and regular expressions: 1. Specify a DFA formally as a 5-tuple defined using set and function notation 2. Define regular expressions and their associated regular language 3. Identify the regular language recognized by a particular DFA 4. Build a DFA to recognize a particular regular language 5. Connect the graphical (state transition diagram) and formal (5-tuple) representations of DFAs and illustrate how each part works 8
6. Use the formalisms that we ve learned (especially power sets and set union) to illustrate that a nondeterministic finite state automaton (NFA) is no more powerful than a deterministic finite state automaton (DFA) The End! Think Big! I have encouraged you to think big : Be curious Be academically adventurous (explore new ideas/topics/areas) Be tolerant/resilient to failure (but learn from your mistakes and the mistakes of others) develop your discernment (i.e., noticing) skills Four Big Ideas of Computer Science Big Idea #1: Finite State Machines (FSMs) Big Idea #2: Turing Machines Big Idea #3: Computability Big Idea #4: Universality Models of Computation: Summary Formal models (computability, Turing Machines, Universality) provide the basis for modern computer science: Fundamental limits (on what can not be done, even given plenty of memory and time) Fundamental equivalence of computation models Representation of algorithms as data, rather than as machinery Programs, Software, Interpreters, Compilers,... There remain many practical issues to deal with: Cost: memory size, time performance, power consumption Programmability Thanks! You have learned a lot! Be proud of what you have, and can, accomplish I had fun (and I hope most of you did too)! Feedback always is very welcome. I particularly like to hear from students 3 5 years down the road (after graduation) Special thanks to: Gwen Echlin My (few) after class, email and office hour regulars 9