1 / 39

CS322

Week 14 - Friday. CS322. Last time. What did we talk about last time? Exam 3 post mortem Finite state automata Equivalence with regular expressions. Questions?. Logical warmup. U2 has 17 minutes to cross a bridge for a concert Plan a way to get them across in the darkness

krysta
Download Presentation

CS322

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Week 14 - Friday CS322

  2. Last time • What did we talk about last time? • Exam 3 post mortem • Finite state automata • Equivalence with regular expressions

  3. Questions?

  4. Logical warmup • U2 has 17 minutes to cross a bridge for a concert • Plan a way to get them across in the darkness • They have one flashlight • A maximum of two people can cross the bridge at one time, and one of them must have the flashlight • The flashlight must be walked back and forth • Each band member walks at a different speed • Bono: 1 minute to cross • The Edge: 2 minutes to cross • Adam: 5 minutes to cross • Larry: 10 minutes to cross • A pair must walk together at the rate of the slower man's pace

  5. Simplifying FSA's Student Lecture

  6. Simplifying FSA's

  7. Comparison • List strings accepted by the FSA A • List strings accepted by the FSA B A B 0 0 1 s0 s1 0 0 1 s0 s1 1 1 1 s3 s2 1 0 0

  8. *-equivalence • Two states of a finite-state automaton are *-equivalent if any string accepted by the automaton when it starts from one state is accepted when starting from the other • Given an automaton A with eventual-state function N*, we can formally say: • States s and t in A are*-equivalent iffN*(s,w) and N*(t,w) are both accepting states or both not • It turns out that *-equivalence defines an equivalence relation

  9. k-equivalence • *-equivalence is hard to demonstrate directly • Instead, we'll focus on equivalence after k or fewer inputs • Given an automaton A with eventual-state function N*, we can formally say: • States s and t in A are k-equivalent iffN*(s,w) and N*(t,w) are both accepting states or both not, for all strings w of length k or less

  10. Facts about k-equivalence • For k ≥ 0, k-equivalence is an equivalence relation • For k ≥ 0, the k-equivalence classes partition the set of all states of the automaton into a union of mutually disjoint subsets • For k ≥ 1, if two states are k-equivalent, they are also (k-1)-equivalent • For k ≥ 1, each k-equivalence class is a subset of a (k-1)-equivalence class • Any two states that are k-equivalent for all integers k ≥ 0 are *-equivalent

  11. k-equivalence theorems • Let A be an FSA with next-state function N • Given any states s and t in A: • s is 0-equivalent to tiff either s and t are both accepting states or they are both nonaccepting states • For every integer k ≥ 1, s is k-equivalent to tiffs and t are (k-1)-equivalent and for any input symbol m, N(s,m) and N(t,m) are also (k-1)-equivalent • These theorems essentially allow us to create a recursive definition for testing k-equivalence

  12. k-equivalence examples • Find the 0-equivalence classes, the 1-equivalence classes, and the 2-equivalence classes for the following FSA: 1 1 0 s0 s1 s2 1 0 1 1 0 0 s4 s3 0

  13. Finding the *-equivalence classes • Keep finding k-equivalence classes for larger and larger values of k • If you ever find that the set of k-equivalence classes is equal to the set of (k+1)-equivalence classes, that is the set of *-equivalence classes • This is known as a fixed point in mathematics

  14. The quotient automaton • We can build a new FSA from the *-equivalence classes • Recall that [s] means the equivalence class of s • This FSA is called the quotient automatonA', and is defined from an FSA A with states S, input symbols I, and next-state function N as follows: • The set of states S' of A' is the set of *-equivalent classes of states of A • The set of input symbols I' of A' equals I • The initial state of A' is [s0] where so is the initial state of A • The accepting states of A' are the states of the form [s] where s is an accepting state of A • The next-state function N': S' x I S' is: For all states [s] in S' and input symbols m, N'([s], m) = [N(s,m)]

  15. Constructing a quotient automaton • Let A be an FSA with states S, input symbols I, and next-state function N • To build A': • Find the set of 0-equivalence classes of S • For each integer k ≥ 1, find the k-equivalence classes of S until the k-equivalence classes are the same as the (k-1)-equivalence classes • Build a quotient automaton whose states are the equivalence classes given above with transition function N'([s],m) = [N(s,m)] for any input symbol m

  16. Quotient automaton example • Find the quotient automaton for the following FSA 1 1 0 s0 s1 s2 1 0 1 1 0 0 s4 s3 0

  17. Equivalent automata • Two automata A1 and A2 are equivalent iffL(A1) = L(A2) • Proving the languages accepted by two automata can be difficult • However, the quotient automata for both A1 and A2 will be the same (except for labeling) if A1 is equivalent to A2

  18. Proving equivalence • Prove that the following two automata are equivalent by finding their quotient automata s2 s1' 0, 1 0 1 1 0 0 1 1 s0 s0' s2' s1 0 0 0 1 1 1 s3 s3' 0

  19. Context Free Languages

  20. Context free languages • A context free language is one that can be described by a context free grammar • Every regular language is context free, but there are context free languages that are not regular • Classic examples: • Strings of k 0's followed by k 1's • Palindromes made up of a's and b's • Legally nested parentheses • All of these involve counting arbitrary numbers of characters • Regular expressions can't count

  21. Context free grammars • Instead of using regular expressions, a context free language is often described with a grammar • A grammar is a formal system of rewriting rules consisting of • Terminals: symbols of the alphabet • Non-terminals: symbols that produce other sequences of terminals and non-terminals • Grammars often start with the non-terminal starting symbol S • Any string that can be derived from S through some sequence of rule rewrites is a string in the language

  22. Simple context free grammars • The following is a grammar that produces the language of strings of 1s and 0s that end in a 1 • SA1 • A 1 | 0 | A1 | A0 • This language is regular and is equivalent to (0 | 1)* 1 • The following is a grammar that produces the language of akbk where k ≥ 1 (which is not regular • SA • Aab| aAb

  23. CFG examples • Write a grammar that legal nesting of parentheses and braces in Java • Don't worry about the stuff that goes inside • Write a grammar for legal mathematical expressions in Java using variables and integers, +, -, *, /, and parentheses • Write a grammar that corresponds to the same language defined by the regular expression ab* (a | bb) (ba)*

  24. Pushdown automata • As you know, regular languages can be expressed by regular expressions and finite state automata • Thus, regular expressions are equal to FSAs in power • Context free languages can be expressed by context free grammars • There is also a class of automata called pushdown automata that correspond to context free languages

  25. Pushdown automata • A pushdown automaton is an idealized machine with seven objects: • Q a finite set of states • Σ the finite input alphabet • Γ the finite stack alphabet • δ is a finite subset of Q x (Σ  ε) x Γ x Q x Γ*which gives a set of transition rules • q0is the start state • Z Γ is the initial stack symbol • F Q is the set of accepting states • All of this looks totally insane, but it's really just adding a stack to finite state automata

  26. Pushdown automaton example • To make the PDA for the language 0k1k, k ≥ 1, we have the following: • In this case, the notation X/Ymeans that if X is on the top of the stack, replace it with Y • The top of the stack is Z • Notation is not well standardized for PDAs • It's awkward keeping track of the stack 1: A/A 1: Z/Z s0 s1 s2 0: Z/AZ 0: A/AA 1: A/ε

  27. Chomsky's Hierarchy of Grammars

  28. Chomsky hierarchy • Noam Chomsky is a brilliant linguist who has recently focused mostly on political activism • Remember that a grammar consists of terminals (alphabet symbols), non-terminals, production rules, and a start symbol • He noted that grammars can be divided into four levels in terms of expressiveness: • Type-0 (Unrestricted grammars) • Type-1 (Context sensitive grammars) • Type-2 (Context free grammars) • Type-3 (Regular grammars)

  29. Rules for grammars • Each grammar has rules for what is a legal production rule • Let α, β, and γbe any combinations of terminals and non-terminals, where γ is non-empty • Unrestricted grammars • αβ(anything to anything) • Context-sensitive grammars • αAβαγβ(non-terminal in a particular context to anything) • Context-free grammars • A γ(a single non-terminal to anything) • Regular grammars • Aa and A aB(a single non-terminal to a single terminal or a terminal and a single non-terminal on the right side)

  30. Languages broken down • Every kind of language has a particular kind of machine associated with it

  31. Fun facts about formal languages • Each set of languages in the hierarchy strictly contains the sets beneath it • Regular languages • Can be accepted by nondeterministic or deterministic finite automata (or a read-0nly Turing machine) • Are closed under union, intersection, complement, concatenation, and Kleene star • Context-free languages • Are defined by those languages accepted by nondeterministic pushdown automata • Are closed under union, concatenation, and Kleene star (but not under intersection or complement) • Deciding whether a string is in a context-free language can be determined in polynomial time • Deciding whether a language is empty is decidable • Context-sensitive languages • Are very rarely used • Are closed under union, intersection, complement, and Kleene star • Deciding whether a string is in a context-sensitive language is a PSPACE-complete problem

  32. Turing machine • A Turing machine is a mathematical model for computation • It consists of a head, an infinitely long tape, a set of possible states, and an alphabet of characters that can be written on the tape • A list of rules saying what it should write and should it move left or right given the current symbol and state A

  33. Turing machine example • You can specify a Turing machine with a table giving its behavior for a specific configuration • Turing's first example machine printed an infinite sequence of alternating 1s and 0s, separated by spaces:

  34. Church-Turing thesis • If an algorithm exists, a Turing machine can perform that algorithm • In essence, a Turing machine is the most powerful model we have of computation • Power, in this sense, means the ability to compute some function, not the speed associated with its computation • Do you own a Turing machine?

  35. Halting problem • Given a Turing machine and input x, does it reach the halt state? • As you know, there is no algorithm to determine this • If you had a Turing machine that could solve the halting problem, it would cause a logical contradiction

  36. Other undecidable problems • Are two context-free languages the same? • Is the intersection of two context-free languages empty? • Is a context-free language equal to Σ* • Is a context-free language a subset of another context-free language? • Post correspondence problem: • You have lists a1, a2, … an and b1, b2, … bn, where ai and bj are strings of some alphabet Σ with at least 2 symbols • Is there a value k ≥ 1 such that some sequence of k strings from the a list concatenated is equal to some sequence of k strings from the b list concatenated? • Is a given statement of first-order logic provable from a starting set of axioms? • Given a set of matrices, is there some sequence that they can be multiplied in (perhaps with repetitions) that will yield the zero matrix?

  37. Upcoming

  38. Next time… • Review first third of the course

  39. Reminders • Review chapters 2 - 6 • Finish Assignment 10 • Due tonight before midnight

More Related