Automaten und Formale Sprachen“ alias ” Theoretische Informatik
Transcription
Automaten und Formale Sprachen“ alias ” Theoretische Informatik
Automaten und Formale Sprachen“ ” alias Theoretische Informatik“ ” Sommersemester 2012 Dr. Sander Bruggink Übungsleitung: Jan Stückrath Sander Bruggink Automaten und Formale Sprachen 1 Organisatorisches und Einführung Who are we? Teacher: Dr. Sander Bruggink Roomm LF 265 E-Mail: [email protected] Teaching assistent: Jan Stückrath Room LF 265 E-Mail: [email protected] Tutors: Dennis Nolte / Martin Kutscher Dennis Nolte: [email protected] Martin Kutscher: [email protected] Sander Bruggink Automaten und Formale Sprachen 2 Organisatorisches und Einführung Introduction Who are you? BAI ISE Others Website www.ti.inf.uni-due.de/teaching/ss2012/afs/ Moodle-Site Sander Bruggink Automaten und Formale Sprachen 3 Organisatorisches und Einführung Appointments Lecture: Tuesday, 12pm–2pm, room LB 131 Exercise groups: Group ISE: Tuesday, 8am–10am, room LC 137 (English) Jan Stückrath Group BAI-1: Wednesday, 12pm–2pm, room LE 120 (German) Martin Kutscher Group BAI-2: Thursday, 2pm–4pm, room LF 125 (German) Dennis Nolte Group BAI-3: Thursday, 4pm–6pm, room LF 125 Dennis Nolte Group BAI-4: Friday, 10am–12pm, raum LE 120 Dennis Nolte Sander Bruggink Automaten und Formale Sprachen 4 Organisatorisches und Einführung Advice about the exercises Please try to split evenly among the exercise groups. Visit the exercise groups and do the homework. The material of this lecture can only be mastered by frequent practice. Memorizing doesn’t help much. The exercise groups start in the third week of the semester. Thus, the first exercise group take place from 24 to 27 April. Sander Bruggink Automaten und Formale Sprachen 5 Organisatorisches und Einführung Advice about the exercises The exercise sheet is put online every week on Tuesday at the latest. The written exercises must be handed in on Monday, 4pm of the following week. In this week the exercise sheet is discussed in the exercise groups. Handing in: in the letter box adjacent to room LF 259. online through Moodle. Plase write clearly your name, student number and group number on your exercise. Also write down the name of the lecture. Sander Bruggink Automaten und Formale Sprachen 6 Organisatorisches und Einführung Exam BAI: Oral exam in the module “Theoretische Informatik” (“Automaten und formale Sprachen” together with “Berechenbarkeit und Komplexität”). Students, who have started in the summer semester, can take an exam in both lectures separately. ISE: Written exam after the semester. Others: Written exam after the semester. Sander Bruggink Automaten und Formale Sprachen 7 Organisatorisches und Einführung Bonus points Bonus points: During the semester the will be 12 (or 11) exercise sheets of 20 points each. If you receive 50% of the points, you will recieve one grade level higher (for example 2,0 instead of 2,3) for your exam. For the oral exam of the module “ Theoretische Informatik” you must obtain the bonus in both “Automaten und Formale Sprachen” and in “Berechenbarkeit und Komplexität”. Sander Bruggink Automaten und Formale Sprachen 8 Organisatorisches und Einführung Literature We use the following book: Uwe Schöning: Theoretische Informatik – kurzgefaßt. Spektrum, 2008. (5. Auflage) Other relevant literature: Neuauflage eines alten Klassikers: Hopcroft, Motwani, Ullman: Introduction to Automata Theory, Languages, and Computation. Addison-Wesley, 2001. Sander Bruggink Automaten und Formale Sprachen 9 Organisatorisches und Einführung Literatur Sander Bruggink Automaten und Formale Sprachen 10 Organisatorisches und Einführung Adventure-Problem 10 1 4 2 6 5 7 11 12 9 3 13 8 14 15 Sander Bruggink 16 Automaten und Formale Sprachen 11 Organisatorisches und Einführung Adventure-Problem Adventure Problem (Level 1) Rules of the Adventure Problem: The Treasure Rule You must find at least two treasures. The Door Rule You can only go through a door, when you found a key before. (The key can be used arbitrarily many times.) Sander Bruggink Automaten und Formale Sprachen 12 Organisatorisches und Einführung Adventure-Problem Adventure Problem (Level 1) The Dragon Rule Immediately after the encounter with a dragon, you must jump into a river, because the dragon will otherwise ignite you. This is not the case anymore, if you have previously found a sword, because then you can kill the dragon. Remark: Dragons, treasures and keys are “refilled” after you left the according field. We are look for a path from a start to an end state, which satisfies all of the above conditions. Sander Bruggink Automaten und Formale Sprachen 13 Organisatorisches und Einführung Adventure-Problem Adventure Problem (Level 1) Question (Level 1) Is there a solution in the example? Adventure Yes! The shortest solution is: 1, 2, 3, 1, 2, 4, 10, 4, 5, 6, 4, 5, 6, 4, 11, 12 (length 16). Is there a general solving procedure which – given an adventure in the form of a graph – can always determine whether there is a solution? Yes! We will see this procedure in the lecture. In order to be able to implement this procedure, we need also formal description of the rules (door rule, dragon rule, treasure rule). Sander Bruggink Automaten und Formale Sprachen 14 Organisatorisches und Einführung Adventure-Problem Adventure Problem (Level 2) New Door Rule The keys are magical and disappear immediately after being used to open a door. As soon as you go through a door, the door is locked again. However, you can carry more than one key. Sander Bruggink Automaten und Formale Sprachen 15 Organisatorisches und Einführung Adventure-Problem Adventure Problem (Level 2) Questions (Level 2) Is there a solution in the example? Adventure Yes! The shortest solution is: 1, 2, 3, 1, 2, 4, 10, 4, 7, 8, 9, 4, 7, 8, 9, 4, 11, 12. (length 18) Is there a general solving procedure? Yes! We will see this procedure in the lecture. Why is the new problem harder? We have to “count” the keys. Sander Bruggink Automaten und Formale Sprachen 16 Organisatorisches und Einführung Adventure-Problem Adventure Problem (Expert Level) New Dragon Rule Swords become unusable by the dragon’s blood, as soon as one has killed a dragon. However, dragons are replaced after being killed. Key Regel A magic gate can only be passed, when you don’t own a key. Sword Rule A river can only be passed, when you don’t have a sword (otherwise, you’ll drown). Sander Bruggink Automaten und Formale Sprachen 17 Organisatorisches und Einführung Adventure-Problem Adventure Problem (Expert Level) Questions (Expert Level) Is there a solution in the example? Adventure Yes! The shortest solution is: Ja! Die kürzeste Lösung ist 1, 2, 3, 1, 2, 4, 10, 4, 7, 8, 9, 4, 10, 4, 5, 6, 4, 11, 12. (Länge 19) Is there a general solving procedure? No! It is a so-called undecidable problem. This is not discussed in this lecture, but in “Berechenbarkeit und Komplexität”. Sander Bruggink Automaten und Formale Sprachen 18 Organisatorisches und Einführung Formal Languages Adventure Problem and Formal Languages (Formal) Languages Language = Set of words Languages contain in general infinitely may words. Thus: We need finite descriptions of infinite languages. Sander Bruggink Automaten und Formale Sprachen 19 Organisatorisches und Einführung Formal Languages Adventure Problem und Formale Languages Questions Typical questions here are: Is a language L empty or does it contain (at least) one word? L = ∅? Is a word w in the language? w ∈ L? Are two languages included in one another? L1 ⊆ L2 ? Depending on the language (or languages) these question are either decidable (there is a general procedure to solve the problem) or undecidable Sander Bruggink Automaten und Formale Sprachen 20 Organisatorisches und Einführung Formal Languages Adventure Problem and Formal Languages The single levels of the adventure belong to the following language classes: Level 1 → regular languages Level 2 → context free languages Expert level → Chomsky-0 languages (semi-decidable languages) These are discussed in “Berechenbarkeit & Komplexität”. Sander Bruggink Automaten und Formale Sprachen 21 Organisatorisches und Einführung Contents of the Lecture For theoretical computer science How can infinite structures be represented by finite descriptions (automata, grammars)? There are numerous applications – for example in the following areas: searching in texts (regular expressions) syntax of (programming) languages and compiler construction modelling system behaviour verification of systems Sander Bruggink Automaten und Formale Sprachen 22 Organisatorisches und Einführung Contents of the Lecture Contents of the lecture Automata and formal languages Mathematical foundations and formal proofs Languages, grammars and automata Chomsky Hierarchy (different language classes) Regular languages and context free languages How can we show that a language is not of a certain class (pumping lemma) Decision procedures Closure properties (is the intersection of two regular languages also regular?) Sander Bruggink Automaten und Formale Sprachen 23 Organisatorisches und Einführung Mathematical Foundations and Formal Proofs Sets Set A set M of elements is denoted as enumerations M = {0, 2, 4, 6, 8, . . . } or a a set of elements with a certain property M = {n | n ∈ N and n even} General format: M = {x | P(x)} (M is the set of all elements x, which satisfy property P.) Sander Bruggink Automaten und Formale Sprachen 24 Organisatorisches und Einführung Mathematical Foundations and Formal Proofs Sets Remarks: The elements of a set a unordered, that is, their order is not important. For example: {1, 2, 3} = {1, 3, 2} = {2, 1, 3} = {2, 3, 1} = {3, 1, 2} = {3, 2, 1} An element cannot occur in a set more than once. It is either in the set, or not. For example: {1, 2, 3} = 6 {1, 2, 3, 4} = {1, 2, 3, 4, 4} Sander Bruggink Automaten und Formale Sprachen 25 Organisatorisches und Einführung Mathematical Foundations and Formal Proofs Stes Element of a set We write a ∈ M, when an element a is contained in the set M. Number of elements of a set For a set M the number of elements of M is denoted by |M|. Subset We write A ⊆ B when every element of A is also an element of B. A is then called a subset of B. The relation ⊆ is also called inclusion. Sander Bruggink Automaten und Formale Sprachen 26 Organisatorisches und Einführung Mathematical Foundations and Formal Proofs Sets Example: 2 ∈ {1, 2, 3}? 3 2 ⊆ {1, 2, 3}? 7 {1, 2} ∈ {1, 2, 3}? 7 {1, 2} ⊆ {1, 2, 3}? 3 Sander Bruggink Automaten und Formale Sprachen 27 Organisatorisches und Einführung Mathematical Foundations and Formal Proofs Venn-Diagrams Venn-Diagrams are graphical representation of sets and the relationships between them. • A B B A Sander Bruggink Automaten und Formale Sprachen 28 Organisatorisches und Einführung Mathematical Foundations and Formal Proofs Set operations Union: A ∪ B = {e | e ∈ A oder e ∈ B} Intersection: A ∩ B = {e | e ∈ A und e ∈ B} Difference: A \ B = {e | e ∈ A und e ∈ / B} A∪B A A∩B B A Sander Bruggink A\B B A Automaten und Formale Sprachen B 29 Organisatorisches und Einführung Mathematical Foundations and Formal Proofs Power set Power set Let M be a set. The set P(M) is the set of all subsets of M. P(M) = {A | A ⊆ M} We have: |P(M)| = 2|M| (for a finite set M). Sander Bruggink Automaten und Formale Sprachen 30 Organisatorisches und Einführung Mathematical Foundations and Formal Proofs Tupel Tupel Besides sets we also use tuples, which are written with (round) parenthesis: (a1 , . . . , an ) In a tuple the elements are ordered. For example: (1, 2, 3) 6= (1, 3, 2) An element can occur multiple times in a tuple. Tuples of different size are always unequal. For example (1, 2, 3, 4) 6= (1, 2, 3, 4, 4) A tuple (a1 , . . . , an ) consisting of n elements is called n-tuple. A 2-tupel is also called a pair. Sander Bruggink Automaten und Formale Sprachen 31 Organisatorisches und Einführung Mathematical Foundations and Formal Proofs Cross product Cross product (or cartesian product) Let A, B be two sets. The set A × B is the set of all pairs (a, b), where a is an element of A and b an element of B. A × B = {(a, b) | a ∈ A, b ∈ B} We have: |A × B| = |A| · |B| (for finite sets A, B). Sander Bruggink Automaten und Formale Sprachen 32 Organisatorisches und Einführung Mathematical Foundations and Formal Proofs Relations Binary relation Let A, B be two sets. A binary relation between A and B is a set of pairs R ⊆ A × B. Relation Let A1 , . . . , An be sets. An (n-ary) relation is a set of tuples R ⊆ A1 × · · · × An . Sander Bruggink Automaten und Formale Sprachen 33 Organisatorisches und Einführung Mathematical Foundations and Formal Proofs Properties of Relations Let R ⊆ A × A be a relation from A to A. R is called reflexive, when for all x ∈ A it holds, that x R x. R is called symmetric, when for all x, y ∈ A it holds, that when x R y , then y R x. R is called antisymmetric, when for all x, y ∈ A it holds, that when x R y and y R x, then x = y . R is called transitive, when for all x, y , z ∈ A it holds, that when x R y and y R z, then x R z. Sander Bruggink Automaten und Formale Sprachen 34 Organisatorisches und Einführung Mathematical Foundations and Formal Proofs Properties of Relations (Continued) Reflexive: a Symmetric: a Antisymmetric: a Transitive: a Sander Bruggink b 7 b b wobei a 6= b c Automaten und Formale Sprachen 35 Organisatorisches und Einführung Mathematical Foundations and Formal Proofs Speical Relations A quasi-order (or pre-order) is a reflexive, transitive relation. A order is a reflexive, transitive und antisymmetric relation. An equivalence relation is a reflexive, transitive and symmetric relation. Quasi-order: a b order: c a d b Sander Bruggink equivalence relation: c a d b c d Automaten und Formale Sprachen 36 Organisatorisches und Einführung Mathematical Foundations and Formal Proofs functions Function f:A→B a 7→ f (a) The function f maps an element a ∈ A to an element f (a) ∈ B. Here, A is the domain and B the codomain. Formally: a function f : A → B is a total and unambiguous relation between A and B. Sander Bruggink Automaten und Formale Sprachen 37 Organisatorisches und Einführung Mathematical Foundations and Formal Proofs Mathematical Statements In mathematics, statement are either true or false. Statements can be composed from smaller statements: P and Q – When P, then Q – For all P, Q – P doesn’t hold There are: basic statements of mathematics (axioms) statements which are already proved from the axioms (theorems) statements which are assumed to be true (hypotheses, premises, assumptions) assertions that we want to prove or refute. Sander Bruggink Automaten und Formale Sprachen 38 Organisatorisches und Einführung Mathematical Foundations and Formal Proofs Formal Proofs Example of a theorem For all n > 0 it holds, that 1 + 2 + · · · + n = n · (n + 1) . 2 Premise: n is a number greater than 0. Conclusion: 1 + 2 + · · · + n = n · (n + 1) . 2 If the premises are true, then the conclusion is also true. Sander Bruggink Automaten und Formale Sprachen 39 Organisatorisches und Einführung Mathematical Foundations and Formal Proofs Implication Implication (“if, then”) Wenn P, dann Q“ (P → Q) ist wahr, wenn Q aus P folgt. ” Using: If P is known, and P → Q is known, then Q is known. (Modus Ponens). Proving: To prove P → Q, assume P, and show under this assumption, that Q is true. Refuting: To refute P → Q, show that P is true, but Q isn’t. Sander Bruggink Automaten und Formale Sprachen 40 Organisatorisches und Einführung Mathematical Foundations and Formal Proofs Konjunktion Conjunction (“and”) P and Q“ (P ∧ Q) is true, when P and Q are both true. ” Using: When P ∧ Q ist known, then P and Q are also known separately (and can be used as premises). Proving: To prove P ∧ Q, we have to prove P and prove Q. Refuting: To refute P ∧ Q, we have to refute P or refute Q. Sander Bruggink Automaten und Formale Sprachen 41 Organisatorisches und Einführung Mathematical Foundations and Formal Proofs Disjunction Disjunction (“or”) P or Q“ (P ∨ Q) is true, when P is true or Q is true. ” Refuting: To refute P ∨ Q, one must refute P or refute Q. Using: To prove R from P ∨ Q: Assume P, and show under that assumption, that R is true. Assume Q, and show under that assumption, that R is true. Since R follows from both P and Q, and P or Q holds, R must also hold. Prove: To prove P ∨ Q, you have to prove P or you have to prove Q. (In most cases, this doesn’t work, however.) Sander Bruggink Automaten und Formale Sprachen 42 Organisatorisches und Einführung Mathematical Foundations and Formal Proofs Negation Negation (“not”) “Not P” (¬P) is true, when P is not true, and false, when P is true. Using: Negations can be used to prove contradictions. Proving: You prove ¬P by refuting P. (In many cases you need a proof by contradiction. Refuting: You refute ¬P by proving P. Sander Bruggink Automaten und Formale Sprachen 43 Organisatorisches und Einführung Mathematical Foundations and Formal Proofs Universal quantifier Universal quantifier (“for all”) “For all x from P it holds that Q“ (∀x ∈ P : Q) is true, when Q holds for all objects x from P. Using: When ∀x ∈ P : Q is known, and you have an object a from P hat, you know that Q holds for a. Proving: Assume, that x is an element of P and show under this assumption that Q holds for x. You cannot assume any other things about x! Wiederlegen: Suche einen Gegenbeispiel, das heißt ein Objekt aus P, für das Q nicht gilt. Sander Bruggink Automaten und Formale Sprachen 44 Organisatorisches und Einführung Mathematical Foundations and Formal Proofs Existential quantifier Existential quantifier (“there is a”) “There is a x from P, such that Q” (∃x ∈ P : Q) is true, when an object x ∈ P exists, such that Q holds for x. Using: When ∃x ∈ P : Q is known, you may introduce an object from P (with an arbitrary name) for which Q holds. You cannot assume any other things about Q. Proving: Suche ein Beispiel: ein Objekt x ∈ P für das Q gilt. Refuting: Nehme an, dass x ∈ P, und beweise, dass Q nicht für x gilt. Sonst darf man nichts über x annehmen. Sander Bruggink Automaten und Formale Sprachen 45 Organisatorisches und Einführung Mathematical Foundations and Formal Proofs Example Prove the following theorem: Theorem Let A be a set, and ⊆ A × A a quasi-order on A. Define the relation ≈ as follows: x ≈ y whenever x y and y x. Then ≈ is an equivalence relation. Sander Bruggink Automaten und Formale Sprachen 46