Formale Systeme Prof. Dr. Bernhard Beckert WS 2010/2011 KIT INSTITUT FÜR THEORETISCHE INFORMATIK KIT University of the State of Baden-Württemberg and National Large-scale Research Center of the Helmholtz Association
Sudoku 5 3 7 6 1 9 5 9 8 6 8 6 3 4 8 3 1 7 2 6 6 2 8 4 1 9 5 8 7 9 Prof. Dr. Bernhard Beckert Formale Systeme WS 2010/2011 2/24
Sudoku 5 3 7 6 1 9 5 9 8 6 8 6 3 4 8 3 1 7 2 6 6 2 8 4 1 9 5 8 7 9 Vervollständigen Sie das Sudoku so, dass in jeder der neun Spalten in jeder der neun Reihen und in jeder der neun Regionen alle Zahlen von 1 bis 9 vorkommen. Prof. Dr. Bernhard Beckert Formale Systeme WS 2010/2011 3/24
Sudoku 5 3 4 6 7 8 9 1 2 6 7 2 1 9 5 3 4 8 1 9 8 3 4 2 5 6 7 8 5 9 7 6 1 4 2 3 4 2 6 8 5 3 7 9 1 7 1 3 9 2 4 8 5 6 9 6 1 5 3 7 2 8 4 2 8 7 4 1 9 6 3 5 3 4 5 2 8 6 1 7 9 Prof. Dr. Bernhard Beckert Formale Systeme WS 2010/2011 4/24
Lösungsweg via Aussagenlogik Wir führen für jede Zellenposition (i, j) des Sudoku und jede Zahl k zwischen 1 und 9 eine Boolesche Variable D k i,j ein, mit der Vorstellung, dass D k i,j den Wert wahr hat, wenn auf dem Feld (i, j) die Zahl k steht. Wir benutzen kartesische Koordinaten zur Notation von Positionen. So ist z.b. D9,1 9 wahr, wenn in der rechten unteren Ecke die Zahl 9 steht. Prof. Dr. Bernhard Beckert Formale Systeme WS 2010/2011 5/24
Sudoku Regeln als AL-Formeln D 1 1,9 D1 2,9 D1 3,9 D1 4,9 D1 5,9 D1 6,9 D1 7,9 D1 8,9 D1 9,9 sagt, dass die Ziffer 1 mindestens einmal in der ersten Zeile vorkommen muß. D 1 1,1 D1 1,2 D1 1,3 D1 1,4 D1 1,5 D1 1,6 D1 1,7 D1 1,8 D1 1,9 sagt, dass die Ziffer 1 mindestens einmal in der ersten Spalte vorkommen muß. D 1 1,1 D1 1,2 D1 1,3 D1 2,1 D1 2,2 D1 2,3 D1 3,1 D1 3,2 D1 3,3 sagt, dass die Ziffer 1 mindestens einmal in der Region links unten vorkommen muss. Prof. Dr. Bernhard Beckert Formale Systeme WS 2010/2011 6/24
Zusätzliche AL-Formeln Die bisherigen Formeln beschreiben Sudoku noch nicht genau. Man muss noch sagen, dass auf jeder Zelle höchstens eine Zahl stehen kann. (D 1 1,1 D2 1,1 ), (D1 1,1 D3 1,1 ), (D1 1,1 D4 1,1 ), (D1 1,1 D5 1,1 ), (D 1 1,1 D6 1,1 ), (D1 1,1 D7 1,1 ), (D1 1,1 D8 1,1 ), (D1 1,1 D9 1,1 ), (D 2 1,1 D3 1,1 ), (D2 1,1 D4 1,1 ), (D2 1,1 D5 1,1 ), (D2 1,1 D6 1,1 ), (D 2 1,1 D7 1,1 ), (D2 1,1 D8 1,1 ), (D2 1,1 D9 1,1 ), (D3 1,1 D4 1,1 ), usw. Prof. Dr. Bernhard Beckert Formale Systeme WS 2010/2011 7/24
Zusätzliche AL-Formeln Allgemein: (Di,j s Di,j t ) für alle 1 i, j, s, t 9 mit s < t. Ergibt 81 36 = 2916 Formeln. Prof. Dr. Bernhard Beckert Formale Systeme WS 2010/2011 8/24
Das 8-Damen-Problem Man plaziere acht Damen so auf einem Schachbrett, dass sie sich gegenseitig nicht bedrohen. Prof. Dr. Bernhard Beckert Formale Systeme WS 2010/2011 9/24
Eine Lösung des 8-Damen-Problems Prof. Dr. Bernhard Beckert Formale Systeme WS 2010/2011 10/24
Wiederholung Syntax und Semantik der Aussagenlogik Prof. Dr. Bernhard Beckert Formale Systeme WS 2010/2011 11/24
Vokabular der Aussagenlogik Logische Zeichen 1 Symbol für den Wahrheitswert wahr 0 Symbol für den Wahrheitswert falsch Negationssymbol ( nicht ) Konjunktionssymbol ( und ) Disjunktionssymbol ( oder ) Implikationssymbol ( wenn... dann ) Symbol für beiderseitige Implikation ( genau dann, wenn ) (,) die beiden Klammern Prof. Dr. Bernhard Beckert Formale Systeme WS 2010/2011 12/24
Vokabular der Aussagenlogik Signatur Eine (aussagenlogische) Signatur ist eine abzählbare Menge Σ von Symbolen, etwa oder Σ = {P 0,..., P n } Σ = {P 0, P 1,...}. Die Elemente von Σ heißen auch atomare Aussagen, Atome oder Aussagevariablen. Prof. Dr. Bernhard Beckert Formale Systeme WS 2010/2011 13/24
Formeln der Aussagenlogik Zur Signatur Σ ist For0 Σ, die Menge der induktiv definiert durch Formeln über Σ 1 For0 Σ 0 For0 Σ Σ For0 Σ wenn A, B For0 Σ dann sind auch A (A B) (A B) (A B) (A B) Elemente von For0 Σ Prof. Dr. Bernhard Beckert Formale Systeme WS 2010/2011 14/24
Semantik der Aussagenlogik Interpretation Es sei Σ eine aussagenlogische Signatur. Eine Interpretation über Σ ist eine beliebige Abbildung I : Σ {W, F}. Prof. Dr. Bernhard Beckert Formale Systeme WS 2010/2011 15/24
Semantik der Aussagenlogik Auswertung Zu jedem I über Σ wird eine zugehörige Auswertung der Formeln über Σ definiert mit: val I : For0 Σ {W, F} val I (1) = W val I (0) = F val I (P) = I(P) für jedes P Σ val I ( A) = { F falls vali (A) = W W falls val I (A) = F Prof. Dr. Bernhard Beckert Formale Systeme WS 2010/2011 16/24
Semantik der Aussagenlogik Auswertung (Forts.) val I auf (A B), (A B), (A B), (A B) wird gemäß der folgenden Tabelle berechnet val I val I val I val I val I (A) val I (B) (A B) (A B) (A B) (A B) W W W W W W W F F W F F F W F W W F F F F F W W Prof. Dr. Bernhard Beckert Formale Systeme WS 2010/2011 17/24
Quiz 1 (A B) ( B A) ja 2 (A B) (A B) ja 3 (A B) (A B) nein 4 (A B) ( A B) nein 5 ( A B) (A B) ja Prof. Dr. Bernhard Beckert Formale Systeme WS 2010/2011 18/24
Logische Grundbegriffe Definition Ein Modell einer Formel A For0 Σ ist eine Interpretation I über Σ mit val I (A) = W. Zu einer Formelmenge M For0 Σ ist ein Modell von M eine Interpretation I, welche Modell von jedem A M ist. A For0 Σ heißt allgemeingültig gdw val I (A) = W für jede Interpretation I über Σ. A For0 Σ heißt erfüllbar gdw es gibt eine Interpretation I über Σ mit val I (A) = W. Prof. Dr. Bernhard Beckert Formale Systeme WS 2010/2011 19/24
Logische Grundbegriffe (Forts.) Definition Σ sei eine Signatur, M For0 Σ, A, B For0 Σ. M = A lies: aus M folgt A gdw Jedes Modell von M ist auch Modell von A. A, B For0 Σ heißen logisch äquivalent gdw A = Σ B und B = Σ A Prof. Dr. Bernhard Beckert Formale Systeme WS 2010/2011 20/24
Beispiele allgemeingültiger Formeln A A Selbstimplikation A A Tertium non datur A (B A) Abschwächung 0 A Ex falso quodlibet (A (A B)) B Modus Ponens A A A Idempotenz ( A) A Doppelnegation A (A B) A Absorption (A B) ((A B) (B A)) Äquivalenz/Implikation A (B C) (A B) (A C) Distributivität A (B C) (A B) (A C) Distributivität Prof. Dr. Bernhard Beckert Formale Systeme WS 2010/2011 21/24
Beispiele allgemeingültiger Formeln (Forts.) (A B) ( B A) Kontraposition (A (B C)) ((A B) (A C)) Verteilen (A B) A B De Morgan (A B) A B De Morgan Prof. Dr. Bernhard Beckert Formale Systeme WS 2010/2011 22/24
Einfache Sätze Theorem A erfüllbar gdw A nicht allgemeingültig = A gdw A ist allgemeingültig = A gdw A ist unerfüllbar A = B gdw = A B M {A} = B gdw M = A B A, B sind logisch äquivalent gdw A B ist allgemeingültig Prof. Dr. Bernhard Beckert Formale Systeme WS 2010/2011 23/24
Logische Umformung Theorem Wenn dann A und B logisch äquivalent A Unterformel von C C entsteht aus C dadurch, dass A durch B ersetzt wird C und C logisch äquivalent Prof. Dr. Bernhard Beckert Formale Systeme WS 2010/2011 24/24