Logic and AI: Comprehensive Study Guide on Propositional Logic, First-Order Logic, and Automated Planning

Introduction to Artificial Intelligence and Knowledge Representation

  • Goal of AI Knowledge: The objective is to equip an AI with knowledge about the world and the ability to logically draw conclusions from that knowledge.
  • Limitations of Pure Search Algorithms:     * Standard search algorithms generate successors and evaluate them but lack a deep "understanding" of the setting or domain.     * Example Scenario: In a game of chess, a question might be asked: "Is it possible for a chess player to have all her pawns and 22 queens?"     * A search algorithm might exhaustively traverse millions of states to see if this configuration occurs, whereas a logic-based system can deduce the answer through rules (e.g., pawn promotion).
  • Dates and Metadata: The source material includes lecture notes recorded on dates including March 2323, March 2929, April 66, and April 2828. Logistics noted include a battery level of approximately 9%9\% and 68%−100%68\%-100\% across various pages and a software identification of "Scanned with OKEN Scanner."

Propositional Logic: The Roommate Story

  • The Scenario: You arrive home to find your roommate completely wet. You possess the following knowledge:     1. Your roommate is wet.     2. If your roommate is wet, it is because of rain, sprinklers, or both.     3. If your roommate is wet because of sprinklers, the sprinklers must be on.     4. If your roommate is wet because of rain, your roommate must not be carrying the umbrella.     5. The umbrella is not in the umbrella holder.     6. If the umbrella is not in the umbrella holder, either you must be carrying the umbrella, or your roommate must be carrying the umbrella.     7. You are not carrying the umbrella.
  • The Logical Question: Can an AI (or a human) conclude that the sprinklers are on?
  • Formal Knowledge Base Creation:     * RoommateWet\text{RoommateWet}     * RoommateWet⇒(RoommateWetBecauseOfRain OR RoommateWetBecauseOfSprinklers)\text{RoommateWet} \Rightarrow (\text{RoommateWetBecauseOfRain} \text{ OR } \text{RoommateWetBecauseOfSprinklers})     * RoommateWetBecauseOfSprinklers⇒SprinklersOn\text{RoommateWetBecauseOfSprinklers} \Rightarrow \text{SprinklersOn}     * RoommateWetBecauseOfRain⇒NOT(RoommateCarryingUmbrella)\text{RoommateWetBecauseOfRain} \Rightarrow \text{NOT}(\text{RoommateCarryingUmbrella})     * UmbrellaGone\text{UmbrellaGone}     * UmbrellaGone⇒(YouCarryingUmbrella OR RoommateCarryingUmbrella)\text{UmbrellaGone} \Rightarrow (\text{YouCarryingUmbrella} \text{ OR } \text{RoommateCarryingUmbrella})     * NOT(YouCarryingUmbrella)\text{NOT}(\text{YouCarryingUmbrella})

Propositional Logic: Syntax and Semantics

  • Syntax (Backus-Naur Form - BNF Grammar):     * Symbol→P,Q,R,…,RoommateWet,…\text{Symbol} \rightarrow P, Q, R, \dots, \text{RoommateWet}, \dots     * Sentence→True∣False∣Symbol∣NOT(Sentence)∣(Sentence AND Sentence)∣(Sentence OR Sentence)∣(Sentence⇒Sentence)\text{Sentence} \rightarrow \text{True} \mid \text{False} \mid \text{Symbol} \mid \text{NOT}(\text{Sentence}) \mid (\text{Sentence AND Sentence}) \mid (\text{Sentence OR Sentence}) \mid (\text{Sentence} \Rightarrow \text{Sentence})     * Note: Parentheses are formally required but often dropped for readability.
  • Semantics:     * Model: A model specifies which proposition symbols are true and which are false. Given a model, the truth value of any sentence can be determined.     * Operator Truth Table:         * If aa is false and bb is false: NOT(a)\text{NOT}(a) is true, a AND ba \text{ AND } b is false, a OR ba \text{ OR } b is false, a⇒ba \Rightarrow b is true.         * If aa is false and bb is true: NOT(a)\text{NOT}(a) is true, a AND ba \text{ AND } b is false, a OR ba \text{ OR } b is true, a⇒ba \Rightarrow b is true.         * If aa is true and bb is false: NOT(a)\text{NOT}(a) is false, a AND ba \text{ AND } b is false, a OR ba \text{ OR } b is true, a⇒ba \Rightarrow b is false.         * If aa is true and bb is true: NOT(a)\text{NOT}(a) is false, a AND ba \text{ AND } b is true, a OR ba \text{ OR } b is true, a⇒ba \Rightarrow b is true.
  • Important Caveats:     * OR: Standard logic uses inclusive OR. E.g., "TwoIsAnEvenNumber OR ThreeIsAnOddNumber\text{TwoIsAnEvenNumber OR ThreeIsAnOddNumber} is true."     * Implication (⇒\Rightarrow): If the left side (premise) is false, the implication is always true regardless of the conclusion. E.g., "TwoIsAnOddNumber⇒ThreeIsAnEvenNumber\text{TwoIsAnOddNumber} \Rightarrow \text{ThreeIsAnEvenNumber} is true."

Tautologies and Logical Equivalence

  • Tautology: A sentence that is true for every possible setting of its propositional symbols.     * Example: (P OR Q) OR (NOT(P) AND NOT(Q))(P \text{ OR } Q) \text{ OR } (\text{NOT}(P) \text{ AND } \text{NOT}(Q)) is a tautology.     * Self-Exercise: Is (P⇒Q) OR (Q⇒P)(P \Rightarrow Q) \text{ OR } (Q \Rightarrow P) a tautology?
  • Logical Equivalence: Two sentences are equivalent if they share the same truth value for every setting of their propositional variables.     * Identity: A Tautology is logically equivalent to True\text{True}.     * Example: P OR QP \text{ OR } Q is equivalent to NOT(NOT(P) AND NOT(Q))\text{NOT}(\text{NOT}(P) \text{ AND } \text{NOT}(Q)).
  • Specific Equivalences:     * Commutativity: (a OR b)≡(b OR a)(a \text{ OR } b) \equiv (b \text{ OR } a); (a AND b)≡(b AND a)(a \text{ AND } b) \equiv (b \text{ AND } a).     * Associativity: ((a AND b) AND c)≡(a AND (b AND c))((a \text{ AND } b) \text{ AND } c) \equiv (a \text{ AND } (b \text{ AND } c)).     * Double-Negation Elimination: NOT(NOT(a))≡a\text{NOT}(\text{NOT}(a)) \equiv a.     * Contraposition: (a⇒b)≡(NOT(b)⇒NOT(a))(a \Rightarrow b) \equiv (\text{NOT}(b) \Rightarrow \text{NOT}(a)).     * Implication Elimination: (a⇒b)≡(NOT(a) OR b)(a \Rightarrow b) \equiv (\text{NOT}(a) \text{ OR } b).     * De Morgan's Laws:         * NOT(a AND b)≡(NOT(a) OR NOT(b))\text{NOT}(a \text{ AND } b) \equiv (\text{NOT}(a) \text{ OR } \text{NOT}(b))         * NOT(a OR b)≡(NOT(a) AND NOT(b))\text{NOT}(a \text{ OR } b) \equiv (\text{NOT}(a) \text{ AND } \text{NOT}(b))     * Distributivity:         * (a AND (b OR c))≡((a AND b) OR (a AND c))(a \text{ AND } (b \text{ OR } c)) \equiv ((a \text{ AND } b) \text{ OR } (a \text{ AND } c))         * (a OR (b AND c))≡((a OR b) AND (a OR c))(a \text{ OR } (b \text{ AND } c)) \equiv ((a \text{ OR } b) \text{ AND } (a \text{ OR } c))

Inference and Entailment

  • Definition of Entailment: A sentence α\alpha is entailed by the Knowledge Base (KBKB) if, for every model where the KBKB is true, α\alpha is also true.
  • Inference Algorithm (Brute Force): By checking every possible model (2n2^n settings for nn variables), if the KBKB is true and α\alpha is false, then α\alpha is not entailed. This is inefficient.
  • Inconsistent Knowledge Bases: If no model satisfies the KBKB, the KBKB is inconsistent. In logic, an inconsistent KBKB technically implies anything (e.g., "TheMoonIsMadeOfCheese\text{TheMoonIsMadeOfCheese}").     * Example of Inconsistency:         1. PetOfRoommateIsABird⇒PetOfRoommateCanFly\text{PetOfRoommateIsABird} \Rightarrow \text{PetOfRoommateCanFly}         2. PetOfRoommateIsAPenguin⇒PetOfRoommateIsABird\text{PetOfRoommateIsAPenguin} \Rightarrow \text{PetOfRoommateIsABird}         3. PetOfRoommateIsAPenguin⇒NOT(PetOfRoommateCanFly)\text{PetOfRoommateIsAPenguin} \Rightarrow \text{NOT}(\text{PetOfRoommateCanFly})         4. PetOfRoommateIsAPenguin\text{PetOfRoommateIsAPenguin}

Reasoning Patterns and Formal Proofs

  • Modus Ponens: If aa and a⇒ba \Rightarrow b are present, conclude bb.
  • And-Elimination: From a AND ba \text{ AND } b, conclude aa.
  • Proof for Sprinklers (Step-by-Step):     * Steps derived from the Roommate Story: Using Modus Ponens on "Umbrella Gone" and relevant implications, we find the roommate is carrying the umbrella. By contraposition on the rain rule, we conclude it was not raining. Using the disjunction provided by the first rule (Roommate wet implies Rain or Sprinklers), logic dictates the sprinklers must be on.
  • Proof regarding Penguins: The contradiction that a penguin both can fly and cannot fly results in a logical state of "False," which can then be used to prove any arbitrary statement via the tautology FALSE⇒Anything\text{FALSE} \Rightarrow \text{Anything}.

Resolution and Conjunctive Normal Form (CNF)

  • General Strategy: To see if α\alpha is entailed, add NOT(α)\text{NOT}(\alpha) to the KBKB and check for inconsistency (producing the empty clause).
  • CNF Conversion: Every propositional formula can be rewritten as a conjunction of clauses (OR-statements).     * Example: A⇒(B OR C)A \Rightarrow (B \text{ OR } C) becomes (NOT(A) OR B OR C)(\text{NOT}(A) \text{ OR } B \text{ OR } C).
  • Resolution Rules:     * Unit Resolution: From (l1 OR l2 OR … OR lk)(l_1 \text{ OR } l_2 \text{ OR } \dots \text{ OR } l_k) and NOT(li)\text{NOT}(l_i), conclude the clause minus lil_i.     * General Resolution: From (l1 OR … OR lk)(l_1 \text{ OR } \dots \text{ OR } l_k) and (m1 OR … OR mn)(m_1 \text{ OR } \dots \text{ OR } m_n) where li=NOT(mj)l_i = \text{NOT}(m_j), conclude the union of both clauses excluding the contradictory literals.
  • Horn Clauses: A special case where clauses are implications with only positive literals (e.g., x1 AND x2⇒x3x_1 \text{ AND } x_2 \Rightarrow x_3). Inference is highly efficient and can be implemented by maintaining counts of satisfied LHS variables.

First-Order Logic (FOL)

  • Limitations of Propositional Logic:     * Propositional logic has no notion of objects or relations.     * Example: "If your roommate is wet because of rain, your roommate must not be carrying any umbrella" requires a separate symbol for every possible umbrella object in propositional logic.
  • Elements of FOL:     * Objects: Named entities like Umbrella0\text{Umbrella0}, John\text{John}, Earth\text{Earth}.     * Relations: Relationships between objects, such as Carrying(Person0,Umbrella0)\text{Carrying}(\text{Person0}, \text{Umbrella0}). Unary relations are called properties.     * Functions: Mapping from objects to objects (e.g., Roommate(Person0)\text{Roommate}(\text{Person0})).     * Equality: Determining if two terms refer to the same object (Roommate(Person0)=Person1\text{Roommate}(\text{Person0}) = \text{Person1}).
  • Quantifiers:     * Universal Quantifier (∀\forall): "For all xx, if P(x)P(x) then Q(x)Q(x)."     * Existential Quantifier (∃\exists): "There exists an xx such that P(x)P(x) and Q(x)Q(x)."     * Relative Relationship: ∀x:α≡NOT(∃x:NOT(α))\forall x: \alpha \equiv \text{NOT}(\exists x: \text{NOT}(\alpha)).

Advanced Logic Concepts

  • Higher-Order Logic: FOL cannot reason about relations or functions as objects themselves. Higher-order logic allows quantifying over properties (e.g., "For all properties pp, if John is Jack's roommate, then p(John)⇒p(Roommate(Jack))p(\text{John}) \Rightarrow p(\text{Roommate}(\text{Jack}))").
  • Inference in FOL:     * SUBST: Substitutes variables with terms. SUBST({x/John},IsHealthy(x))\text{SUBST}(\{x/\text{John}\}, \text{IsHealthy}(x)) gives IsHealthy(John)\text{IsHealthy}(\text{John}).     * Universal Instantiation (UI): Replace a universal variable with any ground term.     * Existential Instantiation (EI): Replace an existential variable with a new constant (Skolem Constant) not existing elsewhere in the KBKB.     * Skolemization: Removing existentials. If an existential is inside the scope of a universal, replace it with a Skolem Function dependent on that universal variable (e.g., ∀x∃y ParentOf(y,x)\forall x \exists y \text{ ParentOf}(y, x) becomes ∀x ParentOf(k(x),x)\forall x \text{ ParentOf}(k(x), x)).
  • Gödel's Incompleteness Theorem: A consistent system rich enough for basic arithmetic (including induction) contains true sentences that cannot be proven within that system.
  • Decidability: FOL is semidecidable—if a sentence is entailed, an algorithm will eventually find a proof. However, if it is not entailed, the algorithm may never terminate.

Automated Planning: STRIPS and PDDL

  • State of the World: Represented as a conjunction of positive, ground, function-free literals. Any literal not mentioned is assumed false (Closed World Assumption).     * Example State: At(Home) AND IsAt(Umbrella,Home) AND HandEmpty…\text{At}(\text{Home}) \text{ AND } \text{IsAt}(\text{Umbrella}, \text{Home}) \text{ AND } \text{HandEmpty} \dots
  • Action Schema (PDDL/STRIPS):     * Name: E.g., TakeObject(location,x)\text{TakeObject}(\text{location}, x).     * Preconditions: Literals that must be true for the action to occur.     * Effects: Literals that become true (add list) or false (delete list, denoted as \text{NOT}$ something).\n* **State-Space Search:**\n    * **Progression Planning:** Forward search from start state to goal.\n    * **Regression Planning:** Backward search from goal to start. Predecessors are found by picking actions that achieve a goal literal without undoing others.\n* **Heuristics:**\n    * **Subgoal Independence:** Sum of costs for each literal separately (can overestimate).\n    * **Empty-Delete-List:** Solving a relaxed version where actions don't have negative effects. Very effective in practice.\n\n# Complex Planning Problems\n\n* **Air Cargo Transport:** Basic actions include \text{Load},,\text{Unload},and, and\text{Fly}.Cargoisonly". Cargo is only "At"anairportifitisnot"" an airport if it is not "In" a plane.\n* **Spare Tire Problem:** Goals involve getting a spare tire on an axle. Actions include \text{Remove},,\text{PutOn},anda", and a "\text{LeaveOvernight}actionthatchangesseveralstates(makingbothtires"action that changes several states (making both tires "At(Ground)") but might be problematic for the goal.\n* **Blocks World:**\n    * Objects are blocks (A, B, C) on a table.\n    * Actions: \text{Move}(b, x, y)andand\text{MoveToTable}(b, x).\n    * **Sussman Anomaly:** A classic planning problem where subgoals interact in such a way that solving one individually first makes the other harder/impossible, requiring specific ordering of steps (\text{MoveToTable}(C, A),then, then\text{Move}(B, \text{Table}, C),then, then\text{Move}(A, \text{Table}, B)).\n\n# Partial-Order Planning (POP) and Planning Graphs\n\n* **Partial-Order Plan:** Instead of a linear sequence, a plan is a set of actions with ordering constraints and **causal links**. Causal links protect a literal between an action that achieves it and an action that needs it.\n* **Planning Graphs:** A leveled graph where each level contains a set of literals and actions that *could* be true/executed.\n* **Mutex Relations (Mutual Exclusion):**\n    * **For Actions:** \n        1. Inconsistent Effects: One negates the effect of another.\n        2. Interference: One negates the precondition of another.\n        3. Competing Needs: Mutex preconditions.\n    * **For Literals:** \n        1. Inconsistent Support: Every possible pair of actions achieving two literals is mutex.\n* **Graphplan Algorithm:** Expands the graph level by level until all goal literals appear without being mutex, then searches for a solution (often using CSP techniques).\n\n# Theorem Prover Examples (SPASS Syntax)\n\n* **Three Spouses Puzzle:** Assume exactly 3objectsandaspousefunction.Ifobjects and a spouse function. Ifx = \text{spouse}(y) \Rightarrow y = \text{spouse}(x), prove someone is their own spouse.\n* **Umbrella PDDL-style Axiom:**\n ```spass\n formula(forall([X], implies(and(Person(X), WetDueToS(X)), SprinklersOn))).\n formula(exists([X], and(Umbrella(X), and(equal(House(X), House(You)), NotAtHome(X))))).\n formula(forall([X], implies(and(Umbrella(X), NotAtHome(X)), \n exists([Y], and(Person(Y), and(equal(House(X), House(Y)), Carrying(Y,X))))))).\n    ```\n\n# Questions & Discussion\n\n* **Discussion on Logic Limitations:** The speaker notes that simple propositional symbols like \text{RoommateCarryingUmbrella0} are just strings to an AI; they only gain meaning through relations defined in FOL.\n* **Mathematical Proof Context:** Discussion around UI and EI references Section 8.3, 9.1.1,and, and9.5 of AI textbooks (likely Russell & Norvig). Instances like \text{King}(\text{John}) \text{ AND } \text{Greedy}(\text{John}) \Rightarrow \text{Evil}(\text{John})$$ are used to demonstrate universal instantiation.
  • Practical Applications: Practical uses of logic mentioned include proving hardware/software properties (verification), synthesis of programs, and formalizing planning domains.