Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Chapter 4: Propositional Logic

Logic is the beginning of wisdom, not the end.

Leonard Nimoy (as Spock)

4.1 Introduction to Propositional Logic

Propositional logic (also called Boolean logic or sentential logic) is the foundation of knowledge representation and automated reasoning in AI. It provides a formal language for expressing facts and a calculus for deriving new facts.

Why Logic in AI?

Advantages of Logic:

  1. Declarative: Specify what is true, not how to compute it

  2. Compositional: Build complex statements from simple ones using connectives

  3. Unambiguous: Precise mathematical semantics

  4. Inference: Automatically derive new knowledge from existing knowledge

  5. Explainable: Reasoning steps are transparent and traceable

  6. General: Apply same inference rules to any domain

Real-World Applications:

  • Expert systems (medical diagnosis, financial advising)

  • Hardware verification (chip design correctness)

  • Software verification (program correctness proofs)

  • Planning and scheduling systems

  • Natural language understanding

  • Semantic web and knowledge graphs

  • Circuit design and optimization

  • Database query optimization

4.2 Syntax of Propositional Logic

Atomic Propositions

Atomic propositions (or propositional symbols) are the basic building blocks:

  • Denoted by capital letters: P,Q,R,S,...P, Q, R, S, ...

  • Each represents a statement that is either true or false

  • Examples:

    • PP: “It is raining”

    • QQ: “I have an umbrella”

    • RR: “I will get wet”

Logical Connectives

We combine atomic propositions using logical connectives:

ConnectiveSymbolNameMeaning
Negation¬P\neg PNOTopposite of PP
ConjunctionPQP \land QANDboth PP and QQ
DisjunctionPQP \lor QORPP or QQ or both
ImplicationPQP \rightarrow QIF-THENif PP then QQ
BiconditionalPQP \leftrightarrow QIFFPP if and only if QQ

Well-Formed Formulas (WFF)

Definition: A formula is well-formed if constructed by these rules:

  1. Every atomic proposition is a WFF

  2. If α\alpha is a WFF, then ¬α\neg \alpha is a WFF

  3. If α\alpha and β\beta are WFFs, then:

    • (αβ)(\alpha \land \beta) is a WFF

    • (αβ)(\alpha \lor \beta) is a WFF

    • (αβ)(\alpha \rightarrow \beta) is a WFF

    • (αβ)(\alpha \leftrightarrow \beta) is a WFF

Examples:

  • PQP \land Q

  • (PQ)R(P \rightarrow Q) \lor R

  • ¬(P¬Q)\neg(P \land \neg Q)

  • PQP \land \land Q ✗ (not well-formed)

4.3 Semantics: Meaning of Formulas

Truth Values

Every proposition has a truth value: true (T, 1) or false (F, 0).

Models

A model (or interpretation) is an assignment of truth values to all propositional symbols.

Example: For symbols {P,Q,R}\{P, Q, R\}, one model is:

m={P:true,Q:false,R:true}m = \{P: \text{true}, Q: \text{false}, R: \text{true}\}

Truth Tables for Connectives

Negation (¬\neg):

PP¬P\neg P
TF
FT

Conjunction (\land):

PPQQPQP \land Q
TTT
TFF
FTF
FFF

Disjunction (\lor):

PPQQPQP \lor Q
TTT
TFT
FTT
FFF

Implication (\rightarrow):

PPQQPQP \rightarrow Q
TTT
TFF
FTT
FFT

Key insight: PQP \rightarrow Q is equivalent to ¬PQ\neg P \lor Q

Biconditional (\leftrightarrow):

PPQQPQP \leftrightarrow Q
TTT
TFF
FTF
FFT

Key insight: PQP \leftrightarrow Q means (PQ)(QP)(P \rightarrow Q) \land (Q \rightarrow P)

4.4 Logical Equivalences

Two formulas α\alpha and β\beta are logically equivalent (αβ\alpha \equiv \beta) if they have the same truth value in all models.

Important Equivalences

Identity Laws:

  • PtruePP \land \text{true} \equiv P

  • PfalsePP \lor \text{false} \equiv P

Domination Laws:

  • PfalsefalseP \land \text{false} \equiv \text{false}

  • PtruetrueP \lor \text{true} \equiv \text{true}

Idempotent Laws:

  • PPPP \land P \equiv P

  • PPPP \lor P \equiv P

Double Negation:

  • ¬(¬P)P\neg(\neg P) \equiv P

Commutative Laws:

  • PQQPP \land Q \equiv Q \land P

  • PQQPP \lor Q \equiv Q \lor P

Associative Laws:

  • (PQ)RP(QR)(P \land Q) \land R \equiv P \land (Q \land R)

  • (PQ)RP(QR)(P \lor Q) \lor R \equiv P \lor (Q \lor R)

Distributive Laws:

  • P(QR)(PQ)(PR)P \land (Q \lor R) \equiv (P \land Q) \lor (P \land R)

  • P(QR)(PQ)(PR)P \lor (Q \land R) \equiv (P \lor Q) \land (P \lor R)

De Morgan’s Laws:

  • ¬(PQ)¬P¬Q\neg(P \land Q) \equiv \neg P \lor \neg Q

  • ¬(PQ)¬P¬Q\neg(P \lor Q) \equiv \neg P \land \neg Q

Implication Elimination:

  • PQ¬PQP \rightarrow Q \equiv \neg P \lor Q

Biconditional Elimination:

  • PQ(PQ)(QP)P \leftrightarrow Q \equiv (P \rightarrow Q) \land (Q \rightarrow P)

  • PQ(PQ)(¬P¬Q)P \leftrightarrow Q \equiv (P \land Q) \lor (\neg P \land \neg Q)

4.5 Satisfiability, Validity, and Entailment

Satisfiability

A formula is satisfiable if there exists at least one model where it is true.

Example: PQP \land Q is satisfiable (true when P=T,Q=TP=T, Q=T)

A formula is unsatisfiable (contradiction) if it is false in all models.

Example: P¬PP \land \neg P is unsatisfiable

Validity

A formula is valid (tautology) if it is true in all models.

Examples:

  • P¬PP \lor \neg P (Law of Excluded Middle)

  • ¬(P¬P)\neg(P \land \neg P) (Law of Non-contradiction)

  • (PQ)(¬Q¬P)(P \rightarrow Q) \leftrightarrow (\neg Q \rightarrow \neg P) (Contrapositive)

Logical Entailment

A knowledge base KBKB entails a formula α\alpha (written KBαKB \models \alpha) if α\alpha is true in all models where KBKB is true.

Example:

  • KBKB: PQ,PP \rightarrow Q, P

  • Then KBQKB \models Q (by Modus Ponens)

Key Relationship:

KBα if and only if (KB¬α) is unsatisfiableKB \models \alpha \text{ if and only if } (KB \land \neg \alpha) \text{ is unsatisfiable}

This is the basis for refutation theorem proving.

4.6 Conjunctive Normal Form (CNF)

Definition

A formula is in Conjunctive Normal Form if it is a conjunction of clauses, where each clause is a disjunction of literals.

Literal: An atomic proposition or its negation (PP or ¬P\neg P)

Clause: Disjunction of literals (L1L2...LnL_1 \lor L_2 \lor ... \lor L_n)

CNF: Conjunction of clauses (C1C2...Cm)(C_1 \land C_2 \land ... \land C_m)

Examples:

  • (PQ)(¬PR)(P \lor Q) \land (\neg P \lor R) ✓ (in CNF)

  • (PQ)R(P \land Q) \lor R ✗ (not in CNF)

Conversion to CNF

Algorithm:

  1. Eliminate implications and biconditionals:

    • PQ¬PQP \rightarrow Q \Rightarrow \neg P \lor Q

    • PQ(¬PQ)(¬QP)P \leftrightarrow Q \Rightarrow (\neg P \lor Q) \land (\neg Q \lor P)

  2. Move negation inward (De Morgan’s laws):

    • ¬(PQ)¬P¬Q\neg(P \land Q) \Rightarrow \neg P \lor \neg Q

    • ¬(PQ)¬P¬Q\neg(P \lor Q) \Rightarrow \neg P \land \neg Q

    • ¬¬PP\neg \neg P \Rightarrow P

  3. Distribute \lor over \land:

    • P(QR)(PQ)(PR)P \lor (Q \land R) \Rightarrow (P \lor Q) \land (P \lor R)

Example Conversion:

Convert ¬(PQ)\neg(P \rightarrow Q) to CNF:

  1. Eliminate implication: ¬(¬PQ)\neg(\neg P \lor Q)

  2. De Morgan: ¬¬P¬Q\neg \neg P \land \neg Q

  3. Double negation: P¬QP \land \neg Q

Result: (P)(¬Q)(P) \land (\neg Q) (in CNF)

4.7 Model Checking

Model checking determines if KBαKB \models \alpha by enumerating all possible models.

Truth Table Enumeration

Algorithm: TT-ENTAILS?(KB, α)

begin
    symbols ← all propositional symbols in KB and α
    return TT-CHECK-ALL(KB, α, symbols, {})
end

Algorithm: TT-CHECK-ALL(KB, α, symbols, model)

begin
    if symbols is empty then
        if KB is true in model then
            return α is true in model
        else
            return true  // KB false, so entailment holds vacuously
    else
        P ← FIRST(symbols)
        rest ← REST(symbols)
        return TT-CHECK-ALL(KB, α, rest, model ∪ {P: true})
           and TT-CHECK-ALL(KB, α, rest, model ∪ {P: false})
end

Complexity: O(2n)O(2^n) where nn is the number of symbols

Sound: Yes - only returns true if entailment holds

Complete: Yes - always terminates with correct answer

4.8 Resolution Theorem Proving

Resolution is a single inference rule that is sound and refutation-complete for propositional logic.

Resolution Rule

From two clauses containing complementary literals, infer a new clause:

12...k,¬1m1...mn2...km1...mn\frac{\ell_1 \lor \ell_2 \lor ... \lor \ell_k, \quad \neg \ell_1 \lor m_1 \lor ... \lor m_n}{\ell_2 \lor ... \lor \ell_k \lor m_1 \lor ... \lor m_n}

Example:

PQ,¬PRQR\frac{P \lor Q, \quad \neg P \lor R}{Q \lor R}

Resolution Algorithm

To prove KBαKB \models \alpha, show that (KB¬α)(KB \land \neg \alpha) is unsatisfiable:

Algorithm: PL-RESOLUTION(KB, α)

begin
    clauses ← CNF(KB ∧ ¬α)
    new ← {}
    
    loop
        for each pair (Ci, Cj) of clauses in clauses do
            resolvents ← PL-RESOLVE(Ci, Cj)
            
            if resolvents contains empty clause then
                return true  // Proved by contradiction
            
            new ← new ∪ resolvents
        
        if new ⊆ clauses then
            return false  // No new clauses, cannot prove
        
        clauses ← clauses ∪ new
end

Algorithm: PL-RESOLVE(Ci, Cj)

begin
    resolvents ← {}
    
    for each literal ℓ in Ci do
        if ¬ℓ in Cj then
            resolvent ← (Ci - {ℓ}) ∪ (Cj - {¬ℓ})
            resolvents ← resolvents ∪ {resolvent}
    
    return resolvents
end

Properties:

  • Sound: Only derives true conclusions

  • Refutation-complete: Can prove all entailments by contradiction

  • Complexity: Exponential in worst case

Resolution Example

Prove: KBRKB \models R where KB={PQ,QR,P}KB = \{P \rightarrow Q, Q \rightarrow R, P\}

  1. Convert to CNF:

    • ¬PQ\neg P \lor Q

    • ¬QR\neg Q \lor R

    • PP

    • ¬R\neg R (negated query)

  2. Apply resolution:

    • Resolve PP and ¬PQ\neg P \lor Q: get QQ

    • Resolve QQ and ¬QR\neg Q \lor R: get RR

    • Resolve RR and ¬R\neg R: get empty clause \square

  3. Empty clause derived → proved!

4.9 DPLL Algorithm for SAT

The Davis-Putnam-Logemann-Loveland (DPLL) algorithm is an efficient method for determining satisfiability.

Key Ideas

  1. Early termination: Stop as soon as formula is satisfied or unsatisfied

  2. Pure symbol heuristic: If symbol appears only positive or only negative, assign accordingly

  3. Unit clause heuristic: If clause has only one literal, that literal must be true

  4. Backtracking search: Try assignments systematically

DPLL Algorithm

Algorithm: DPLL(clauses, symbols, model)

begin
    if every clause in clauses is true in model then
        return true
    
    if some clause in clauses is false in model then
        return false
    
    // Pure symbol heuristic
    P, value ← FIND-PURE-SYMBOL(symbols, clauses, model)
    if P is non-null then
        return DPLL(clauses, symbols - P, model ∪ {P: value})
    
    // Unit clause heuristic
    P, value ← FIND-UNIT-CLAUSE(clauses, model)
    if P is non-null then
        return DPLL(clauses, symbols - P, model ∪ {P: value})
    
    // Splitting: try both values
    P ← FIRST(symbols)
    rest ← REST(symbols)
    
    return DPLL(clauses, rest, model ∪ {P: true})
        or DPLL(clauses, rest, model ∪ {P: false})
end

Improvements over basic search:

  • Much faster in practice

  • Still exponential worst-case

  • Foundation of modern SAT solvers

4.10 Horn Clauses and Forward/Backward Chaining

Horn Clauses

A Horn clause is a clause with at most one positive literal.

Forms:

  1. Definite clause: Exactly one positive literal

    • Example: ¬P¬QR\neg P \lor \neg Q \lor R (equivalent to PQRP \land Q \rightarrow R)

  2. Fact: Single positive literal

    • Example: PP

  3. Goal clause: No positive literals

    • Example: ¬P¬Q\neg P \lor \neg Q (equivalent to ¬(PQ)\neg(P \land Q))

Why Horn clauses?

  • Many real-world KBs naturally expressed as Horn clauses

  • Inference is linear time in size of KB

  • Foundation of logic programming (Prolog)

Forward Chaining

Forward chaining is data-driven inference: start with facts, apply rules to derive new facts.

Algorithm: FORWARD-CHAIN(KB, query)

begin
    count ← table of number of premises for each rule
    inferred ← table, initially all false
    agenda ← queue of facts, initially all facts in KB
    
    while agenda is not empty do
        p ← POP(agenda)
        
        if p = query then
            return true
        
        if inferred[p] = false then
            inferred[p] ← true
            
            for each rule (premises → conclusion) where p is in premises do
                count[rule] ← count[rule] - 1
                
                if count[rule] = 0 then
                    ADD conclusion to agenda
    
    return false
end

Properties:

  • Complete: For definite clauses

  • Time: O(pn)O(pn) where pp = number of rules, nn = number of symbols

  • Space: Linear in KB size

  • Monotonic: Inferred facts never retracted

Backward Chaining

Backward chaining is goal-driven inference: start with query, work backward to find supporting facts.

Algorithm: BACKWARD-CHAIN(KB, query)

begin
    if query is a known fact in KB then
        return true
    
    for each rule (premises → conclusion) where conclusion = query do
        if BACKWARD-CHAIN-ALL(KB, premises) then
            return true
    
    return false
end

Algorithm: BACKWARD-CHAIN-ALL(KB, premises)

begin
    for each premise in premises do
        if not BACKWARD-CHAIN(KB, premise) then
            return false
    
    return true
end

Properties:

  • Complete: For definite clauses

  • Efficient: Only explores relevant parts of KB

  • Depth-first: Can get stuck in infinite loops (need loop detection)

Forward vs. Backward Chaining

AspectForwardBackward
DirectionData-drivenGoal-driven
StrategyBreadth-firstDepth-first
ComplexityO(pn)O(pn)O(pn)O(pn) with memoization
SpaceMoreLess
Best forDerive all consequencesAnswer specific query

4.11 Summary

Key Concepts

  1. Syntax: Propositions and connectives

  2. Semantics: Truth values and models

  3. CNF: Standard form for inference

  4. Entailment: Logical consequence

  5. Model checking: Truth table enumeration

  6. Resolution: Refutation-complete inference

  7. DPLL: Efficient SAT solving

  8. Horn clauses: Restricted but tractable

  9. Forward/Backward chaining: Efficient for Horn clauses

Inference Methods Comparison

MethodCompleteSoundComplexityBest For
Truth TablesYesYesO(2n)O(2^n)Small formulas
ResolutionYes*YesExponentialGeneral CNF
DPLLYesYesExponentialSAT problems
Forward ChainYes**YesO(pn)O(pn)Derive all facts
Backward ChainYes**YesO(pn)O(pn)Specific queries

*Refutation-complete, **For Horn clauses

Limitations of Propositional Logic

  1. Cannot express:

    • Quantification (all, some)

    • Objects and relations

    • Functions

  2. Lack of abstraction: Must enumerate all instances

  3. Solution: First-Order Logic (Chapter 5)

4.12 Implementation

For complete Python implementations, see:

Chapter 4: Propositional Logic - Implementation

The implementation notebook includes:

  1. Expression Classes: Symbol, Not, And, Or, Implies, Biconditional

  2. Truth Table Generation: Enumerate all models

  3. CNF Conversion: Transform any formula to CNF

  4. Resolution Prover: Theorem proving by refutation

  5. DPLL SAT Solver: Efficient satisfiability checking

  6. Forward Chaining: Data-driven inference for Horn clauses

  7. Backward Chaining: Goal-driven inference

  8. Knowledge Base: Store and query facts and rules

  9. Real-World Applications:

    • Logic puzzle solver (Einstein’s riddle)

    • Sudoku as SAT problem

    • Expert system for classification

Further Reading

Textbooks

  • Aggarwal, C. C. (2021). Artificial Intelligence: A Textbook. Springer. [Chapter 4]

  • Russell, S., & Norvig, P. (2020). Artificial Intelligence: A Modern Approach (4th ed.). Pearson. [Chapter 7]

  • Genesereth, M., & Nilsson, N. (1987). Logical Foundations of Artificial Intelligence. Morgan Kaufmann.

Classic Papers

  • Davis, M., & Putnam, H. (1960). A computing procedure for quantification theory. Journal of the ACM.

  • Robinson, J. A. (1965). A machine-oriented logic based on the resolution principle. Journal of the ACM.

  • Cook, S. A. (1971). The complexity of theorem-proving procedures. STOC.

Modern SAT Solvers

  • Biere, A., et al. (2009). Handbook of Satisfiability. IOS Press.

  • Marques-Silva, J., & Sakallah, K. A. (1999). GRASP: A search algorithm for propositional satisfiability. IEEE TC.

Online Resources