CS221 Artificial Intelligence, Notes on Logic (Week 9)

  • High level summaries

    • State-based models: search problems, MDPs, games
      • Applications: route finding, game playing, etc
      • Terms: states, actions, costs
    • Variable-based models: CSPs, Bayesian networks
      • Applications: scheduling, tracking, medical diagnosis, etc
      • Terms: variables, factors
    • Logic-based models: propositional logic, first-order logic
      • Applications: theorem proving, verification, etc
      • Terms: logical formulas, inference rules
      • Problems with logic:
        • Deterministic, cannot handle uncertainty
        • Rule-based, does not allow to learn from data

Propositional Logic

  • Propositional symbols (atomic formulas): A,B,C

  • Use Logical connectives to build up formulas recursively: if f and g are formulas, so are the following

    • Negation: ¬f
    • Conjunction: fg
    • Disjunction: fg
    • Implication: fg
    • Bicodintional: fg

Models

  • Model w: an assignment of values to propositional symbols

  • Interpretation function: for a formula f and a model w, I(f,w)=1{w satisfies f}

    • Define M(f)={w:I(f,w)=1}

Knowledge base

  • Knowledge base KB: M(KB)=fKBM(f)

  • Add a formula to the knowledge base:

    • From KB to KBf
    • Shrinks the set of models: from M(KB) to M(KB)M(f)
  • Relationships between a KB and a formula f

Relationship Notation Definition Meaning
Entailment KBf M(KB)M(f) Already knew that.
Contradiction M(KB)M(f)= Don’t believe that.
Contingency M(KB)M(f)M(KB) Learned something new.
Inference
  • KB contradicts with f KB entails ¬f

  • Probabilistic interpretation P(fKB)=wM(KB{f})P(W=w)wM(KB)P(W=w)

  • A KB is satisfiable if M(KB)

drawing
Figure source: Stanford CS221 spring 2025, lecture slides week 9
  • Checking satisfiability (SAT) in propositional logic is a special case of CSPs

    Logic term Counterpart CSP term
    propositional symbol variable
    formula constraint
    model assignment

Inference Rules

  • Inference rule: if the premises f1,,fk are in the KB, then your can add the conclusion g to the KB. Formula: f1,,fkg(premises)(conclusion)

  • Modus ponens inference rule: captures the if-then reasoning pattern. For any propositional symbols p and q, we have p,pqq

  • Derivation: KB derives f, written as KBf, iff f eventually gets added to KB.

    • Inference rules operate directly on syntax, not on semantics.

Soundness and completeness

  • A set of inference rules is sound if {f:KBf}{f:KBf}
    • Nothing but the truth
    • Showing soundness is easy
  • A set of inference rules is complete if {f:KBf}{f:KBf}
    • Whole truth
    • Showing completeness if hard
  • Fixing completeness
    • Option 1: restrict the allowed set of formulas, to propositional logic with only Horn clauses
    • Option 2: use more powerful inference rules, change from Modus ponens to resolution
Formulas allowed Inference rules Complete?
Propositional logic modus ponens No
Propositional logic (only Horn clauses) modus ponens Yes
Propositional logic resolution Yes

Propositional Modus Ponens

  • Horn clauses: is either a definite clause, (p1pk)q, or a goal clause (p1pk)false

  • A more generic version of the modus ponens inference rule p1,,pk,(p1pk)qq

  • Theory: Modus ponens is complete with respect to Horn clauses. This is, if KB contains only Horn clauses, then KBp(entailment)KBp(derivation)

Propositional Resolution

  • Rewrite implication AC to disjunction ¬AC
    • In this way, we can rewrite modus ponens as A,¬ACC Note that A and ¬A are cancelled out.
  • Resolution inference rule: cancel out p and ¬p in the middle f1fnp,¬pg1gmf1fng1gm

Conjunctive normal form (CNF)

  • CNF is a conjunction () of clauses ()

    • Every formula in propositional logic can be converted into an equivalent CNF formula

    • Conversion rules

    Propositional logic CNF
    fg ¬fg
    fg (fg)(gf)
    ¬(fg) ¬f¬g
    ¬(fg) ¬f¬g
    ¬¬f f
    f(gh) (fg)(fh)

Proof by Resolution

  • Add ¬f into KB KB=KB¬f
  • Convert all formulas into CNF
  • Repeatedly apply resolution rule
  • Return entailment iff derive false

First-order Logic

  • Syntax of first-order logic
    • Terms (object)
      • constant symbol (e.g., arithmetic)
      • variable (e.g., x)
      • function of terms (e.g., Sum(3, x))
    • Formulas (truth values)
      • Atomic formulas (atoms): predicate applied to terms, e.g., Knows(x, arithmetic)
      • Connectives applied to formulas: e.g., Student(x) Knows(x, arithmetic)
      • Quantifiers applied to formulas: e.g., x Student(x) Knows(x, arithmetic)
  • Quantifiers: for all () and exists ()
    • Note the different connectives:
      • Student(x) Knows(x, arithmetic)
      • Student(x) Knows(x, arithmetic)
drawing
Figure source: Stanford CS221 spring 2025, lecture slides week 9

First-order Modus Ponens

  • Definite clause in first-order logic for variables x1,,xn and atomic formuas a1,,ak,b which contain those variables, has the following form x1xn(a1ak)b

  • Substitution θ is a mapping from variables to terms Subst[θ,f] returns the result of performing substitution θ on f.

    • E.g., Subst[{x/alice},P(x)]=P(alice)
  • Unification: takes two formulas f and g and returns a substitution θ which is the most general unifier: Unify[f,g]={θ, such that Subst[θ,f]=Subst[θ,g]fail, if no such θ exists

  • First-order modus ponens with substitution: Let θ=Unify[a1ak,a1ak] and b=Subst[θ,b], then a1ak,x1xn(a1ak)bb