Logic is the study of the principles that govern correct reasoning.
Mastering formal logic is vital for computing students because propositional and predicate logic serve as the languages for conditional statements, loop invariants, database queries, circuit designs, and program specifications.
This domain involves the mathematical language of logic, which includes propositions, logical connectives, predicates, quantifiers, and rules of inference.
These components form the basis for standard methods of mathematical proof.
PROPOSITIONAL LOGIC
Definition and Recognition
Proposition: A proposition is a declarative sentence that is either true or false, but not both. Every proposition has exactly one definite truth value.
Non-propositions: Sentences that are not propositions include:
Questions.
Commands.
Sentences where truth depends on an unassigned variable (e.g., x+3=8).
Examples of Propositions:
"Gaborone is the capital of Botswana": This is a true proposition.
"2+2=5": This is a false proposition.
"Every even integer greater than 2 is the sum of two primes" (Goldbach’s Conjecture): This is a proposition because it has a definite truth value, regardless of whether mathematicians have yet proven what that value is.
Notation: Propositions are typically denoted by lower-case letters như p,q,r,s, referred to as propositional variables or statement letters.
p≡true indicates that the proposition p is true.
p≡false indicates that the proposition p is false.
Logical Connectives and Compound Propositions
Compound Propositions: Created by building upon existing propositions using logical connectives.
Atomic Propositions: Propositions that cannot be broken down into further components.
Negation (¬): Let p be a proposition. the negation of p is written as ¬p (read as "not p"). It is the proposition "It is not the case that p". The truth value of ¬p is the exact opposite of p.
Truth Table for Negation:
If p is true, ¬p is false.
If p is false, ¬p is true.
Conjunction (∧): The conjunction of p and q (read as "p and q") is true only when both p and q are true; otherwise, it is false.
Disjunction (∨): The disjunction of p and q (read as "p or q") is false only when both p and q are false; otherwise, it is true.
Inclusive vs. Exclusive "Or": The connective ∨ is an inclusive or, meaning it is true if either or both propositions are true. This differs from the exclusive or (⊕), where the proposition is true only if precisely one of the variables is true.
Exclusive Or (⊕): The proposition p⊕q is true exactly when precisely one of p or q is true.
p
q
p∧q
p∨q
p⊕q
true
true
true
true
false
true
false
false
true
true
false
true
false
true
true
false
false
false
false
false
Conditional Statements
Definition: The conditional statement p→q (read as "if p then q") is false only when the hypothesis (antecedent) p is true and the conclusion (consequent) q is false. It is true in all other scenarios.
Vacuous Truth: The statement p→q is considered true whenever p is false, regardless of the truth value of q. This is because the statement makes no claim when the hypothesis is not met.
Truth Table for Conditional (p→q):
true, true: true
true, false: false
false, true: true
false, false: true
English Equivalents for p→q:
"p implies q"
"p is sufficient for q"
"q is necessary for p"
"q if p"
"q whenever p"
"q follows from p"
Related Statements:
Converse:q→p
Inverse:¬p→¬q
Contrapositive:¬q→¬p
Note: Only the contrapositive is logically equivalent to the original conditional statement (p→q). The converse and inverse are generally not equivalent to the original.
Biconditional Statements
Definition: The biconditional statement p↔q (read as "p if and only if q" or "iff") is true only when p and q possess the same truth value.
Equivalence:p↔q is true precisely when both p→q and q→p are true.
p
q
p↔q
true
true
true
true
false
false
false
true
false
false
false
true
Precedence of Logical Operators
To minimize the need for parentheses, connectives are evaluated in a standardized order:
Negation (¬)
Conjunction (∧)
Disjunction (∨)
Conditional (→)
Biconditional (↔)
PROPOSITIONAL EQUIVALENCES
Tautologies, Contradictions, and Contingencies
Tautology: A compound proposition that is always true, regardless of the truth values of its variables (e.g., p∨¬p, the Law of the Excluded Middle).
Contradiction: A compound proposition that is always false, regardless of variable truth values (e.g., p∧¬p).
Contingency: A compound proposition that is neither a tautology nor a contradiction (it is true for at least one assignment and false for at least one other).
Logical Equivalence
Two compound propositions A and B are logically equivalent (A≡B) if A↔B is a tautology, meaning they have identical truth tables.
De Morgan's Laws:
¬(p∧q)≡¬p∨¬q
¬(p∨q)≡¬p∧¬q
Fundamental Logical Equivalences Toolkit
Equivalence
Name
p∧true≡p, p∨false≡p
Identity laws
p∨true≡true, p∧false≡false
Domination laws
p∨p≡p, p∧p≡p
Idempotent laws
¬(¬p)≡p
Double negation law
p∨q≡q∨p, p∧q≡q∧p
Commutative laws
(p∨q)∨r≡p∨(q∨r), (p∧q)∧r≡p∧(q∧r)
Associative laws
p∨(q∧r)≡(p∨q)∧(p∨r)
Distributive law
p∧(q∨r)≡(p∧q)∨(p∧r)
Distributive law
¬(p∧q)≡¬p∨¬q, ¬(p∨q)≡¬p∧¬q
De Morgan's laws
p∨(p∧q)≡p, p∧(p∨q)≡p
Absorption laws
p∨¬p≡true, p∧¬p≡false
Negation laws
Rewriting Conditionals and Biconditionals
Conditional as disjunction:p→q≡¬p∨q
Contrapositive law:p→q≡¬q→¬p
Biconditional expansion:p↔q≡(p→q)∧(q→p)
Other Identities:
p∨q≡¬p→q
p∧q≡¬(p→¬q)
p↔q≡¬p↔¬q
Satisfiability
Satisfiable: A compound proposition is satisfiable if there is at least one assignment of truth values to its variables that makes it true (called a solution).
Unsatisfiable: A compound proposition is unsatisfiable if no such assignment exists (i.e., it is a contradiction).
Importance: The satisfiability problem (SAT) is the archetypal NP-complete problem in computer science.
PREDICATES AND QUANTIFIERS
Predicates (Propositional Functions)
Ordinary propositional logic cannot capture the internal structure of sentences like "x>3".
Definition: A predicate or propositional function P(x) involves a variable x from a domain of discourse D. It becomes a proposition once a specific value from D is substituted for x.
Example: Let P(x) denote "x2−5x+6=0" with domain Z.
P(2) is true (0=0).
P(5) is false (6=0).
Quantifiers
Universal Quantifier (∀): The proposition "P(x) is true for all values of x in the domain D," denoted ∀xP(x). A value that makes P(x) false is a counterexample.
Existential Quantifier (∃): The proposition "there exists an element x in the domain D for which P(x) is true," denoted ∃xP(x). A value that makes P(x) true is a witness.
Bound vs. Free Variables: A variable associated with a quantifier is bound. A variable not associated with one is free. A statement with no free variables is a true proposition.
Restricted Domain Shorthand:
∀x<0(x2>0) is shorthand for ∀x(x<0→x2>0).
∃x>100(x is prime) is shorthand for ∃x(x>100∧x is prime).
Negating Quantifiers (De Morgan's Laws for Quantifiers)
¬[∀xP(x)]≡∃x¬P(x)
¬[∃xP(x)]≡∀x¬P(x)
Negation swaps ∀ for ∃ and moves the negation symbol inside next to the predicate.
NESTED QUANTIFIERS
Nested quantifiers occur when multiple quantifiers are applied in sequence (e.g., the definition of a limit in Calculus).
Order Matters:
Quantifiers of the same type can be reordered (∀x∀y≡∀y∀x and ∃x∃y≡∃y∃x).
Mixed quantifiers cannot generally be reordered. ∀x∃yP(x,y) (where y may depend on x) is not the same as ∃y∀xP(x,y) (which requires one single y for all x).
RULES OF INFERENCE
Validity and Arguments
Argument: A sequence of propositions (premises) followed by a final proposition (conclusion).
Validity: An argument is valid if the conclusion is necessarily true whenever all premises are true. Formally, (p1∧p2∧⋯∧pn)→q must be a tautology.
Rule of Inference: A standard, verified argument form used as a single step in a proof.
Table of Rules for Propositional Logic
Name
Rule
Tautology Form
Modus Ponens
p→q,p∴q
(p∧(p→q))→q
Modus Tollens
p→q,¬q∴¬p
(¬q∧(p→q))→¬p
Hypothetical Syllogism
p→q,q→r∴p→r
((p→q)∧(q→r))→(p→r)
Disjunctive Syllogism
p∨q,¬p∴q
((p∨q)∧¬p)→q
Addition
p∴p∨q
p→(p∨q)
Simplification
p∧q∴p
(p∧q)→p
Conjunction
p,q∴p∧q
((p)∧(q))→(p∧q)
Resolution
p∨q,¬p∨r∴q∨r
((p∨q)∧(¬p∨r))→(q∨r)
Rules for Quantified Statements
Universal Instantiation: From ∀xP(x), infer P(c) for a particular element c.
Universal Generalisation: From P(c) for an arbitrary c, infer ∀xP(x).
Existential Instantiation: From ∃xP(x), infer P(c) for some element c.
Existential Generalisation: From P(c) for some witness c, infer ∃xP(x).
Logic Fallacies
Affirming the Consequent: Concluding p from p→q and q. Invalid because q might be true for other reasons.
Denying the Hypothesis: Concluding ¬q from p→q and ¬p. Invalid because q might still be true even if p is false.
INTRODUCTION TO PROOFS
Mathematical Definitions
Theorem: A proposition proved true, usually significant.
Proof: A valid chain of reasoning establishing a theorem's truth.
Axiom (Postulate): A statement accepted as true without proof.
Lemma: A minor theorem used as a stepping stone.
Corollary: A theorem that follows directly from a proved theorem.
Conjecture: A statement believed but not yet proved true. Once proved, it becomes a theorem.
Even Integer: an integer n such that n=2k for some integer k.
Odd Integer: an integer n such that n=2k+1 for some integer k.
Rational Number: A real number r that can be expressed as a/b where a,b∈Z and b=0.
Irrational Number: A real number that is not rational.
Proof Methods
Direct Proof: To prove p→q, assume p is true and use axioms/definitions to show q must be true.
Standard pattern: Unpack definition (e.g., n=2k), compute algebraically, repackage into the required form.
Proof by Contraposition: To prove p→q, give a direct proof of the contrapositive ¬q→¬p. Assume q is false and show p must be false.
Example: To prove "if 3n+2 is odd, then n is odd," it is easier to show "if n is even, then 3n+2 is even."
Proof by Contradiction: Assume the negation of what you want to prove (assume ¬p) and derive a contradiction (r∧¬r). Since ¬p leads to a falsehood, p must be true.
Proof by Cases: Establish p→q by proving it for an exhaustive list of individual scenarios (p1→q,p2→q,…). Example: Proving a property for all integers by checking cases for n≤−1, n=0, and n≥1.
Existence Proofs:
Constructive: Explicitly find a witness a that satisfies P(a).
Nonconstructive: Show that an element must exist without finding it (e.g., using cases or contradiction).
Uniqueness Proofs: To show a unique element exists, prove existence first, then prove that any arbitrary element satisfying the property must be equal to that first element.
Counterexamples: A single counterexample is sufficient to disprove a universal statement ∀xP(x).
Case Study: Proof by Contradiction of 2
Suppose 2 is rational: 2=a/b where gcd(a,b)=1.
Square both sides: 2=a2/b2, so a2=2b2.
a2 is even, so a is even (by lemma: even square implies even base). Let a=2c.
Substitute: (2c)2=2b2→4c2=2b2→2c2=b2.
b2 is even, so b is even.
If both a and b are even, gcd(a,b)≥2, contradicting the assumption gcd(a,b)=1. Therefore, 2 is irrational.