Logic gives a precise language for knowledge, with exact rules for what follows from it. Propositional logic is its simplest form.
Syntax
A proposition is a declarative statement that is either true or false: "It is raining", "2 + 2 = 4". Propositional logic uses atomic sentences, single proposition symbols (P, Q, Rain), and builds complex sentences with connectives: ¬ (not, negation), ∧ (and, conjunction), ∨ (or, disjunction), → (implies, implication, true unless the premise is true and the conclusion false) and ↔ (if and only if, biconditional). Parentheses fix the order; the usual precedence is ¬, ∧, ∨, →, ↔.
Semantics and Truth Tables
A model assigns true or false to every symbol. The truth of a complex sentence in a model is computed recursively from the connectives; a truth table lists all 2ⁿ models of n symbols. A sentence is valid (a tautology) if true in all models (P ∨ ¬P), satisfiable if true in at least one, and unsatisfiable (a contradiction) if true in none (P ∧ ¬P). The knowledge base entails α (KB ⊨ α) if α is true in every model in which KB is true. Checking entailment by enumerating all models is model checking; it takes O(2ⁿ) time, and SAT (satisfiability) is the first NP-complete problem.
Definition: Propositional logic. A formal language whose sentences are built from proposition symbols and the connectives not, and, or, implies and if-and-only-if, with truth determined by assignments of true or false to the symbols.
Equivalences and Inference Rules
Two sentences are logically equivalent if true in the same models. Key equivalences: De Morgan's laws ¬(P ∧ Q) ≡ ¬P ∨ ¬Q and ¬(P ∨ Q) ≡ ¬P ∧ ¬Q; implication elimination P → Q ≡ ¬P ∨ Q; contraposition P → Q ≡ ¬Q → ¬P; double negation ¬¬P ≡ P; commutativity, associativity and distributivity. Inference rules: Modus Ponens (from P → Q and P infer Q), Modus Tollens (from P → Q and ¬Q infer ¬P), And-elimination, Hypothetical syllogism (from P → Q and Q → R infer P → R) and Resolution (below). Propositional logic is easy and decidable, but not expressive: it cannot say "all squares adjacent to a pit are breezy" without a separate sentence for every square.
Table 3.1: Truth table of the connectives
| P Q | P ∧ Q | P ∨ Q | P → Q | P ↔ Q |
|---|---|---|---|---|
| T T | T | T | T | T |
| T F | F | T | F | F |
| F T | F | T | T | F |
| F F | F | F | T | T |
Example 3.1: Checking modus ponens by truth table
Problem: Show that {P → Q, P} entails Q.
Solution:
- List the four models of P and Q.
- P → Q is true in TT, FT and FF; P is true in TT and TF.
- Both KB sentences are true only in the model P = T, Q = T.
- Q is true in that model, so KB ⊨ Q.
Result: Modus ponens is sound: whenever P → Q and P hold, Q holds.
from itertools import product
def entails(kb, query, n=2):
return all(query(*m) for m in product([True, False], repeat=n)
if kb(*m))
kb = lambda p, q: ((not p) or q) and p
print("KB entails Q:", entails(kb, lambda p, q: q))
print("KB entails not Q:", entails(kb, lambda p, q: not q))
taut = all((p or not p) for p in (True, False))
print("P or not P is a tautology:", taut)
Output
KB entails Q: True
KB entails not Q: False
P or not P is a tautology: True
Common mistakes
- Reading P → Q as "P causes Q"; it is true whenever P is false.
- Confusing KB ⊨ α with "α is in the KB".
- Forgetting that ¬(P ∧ Q) is ¬P ∨ ¬Q, not ¬P ∧ ¬Q.
- Expecting propositional logic to express general rules over many objects.
Key takeaways
- Connectives: ¬, ∧, ∨, →, ↔; a model assigns truth values.
- Valid = true in all models; satisfiable = true in some; unsatisfiable = true in none.
- KB ⊨ α if α holds in every model of the KB; truth tables take O(2ⁿ).
- Modus ponens: from P → Q and P infer Q.
Practice questions
- When is P → Q false?
- What is a tautology?
- State De Morgan's laws.
Answers to the practice questions
- Only when P is true and Q is false.
- A sentence that is true in every model.
- ¬(P ∧ Q) ≡ ¬P ∨ ¬Q and ¬(P ∨ Q) ≡ ¬P ∧ ¬Q.
Sources
- Official BCA syllabus Artificial Intelligence, course code 26BCA404DS04, Unit III
