Mulungushi University
ICT351 Theory of Computation
Lecture 2. Logic and Sets
Contents
• Review of Logic
• Review of Sets
Boolean Logic Wffs
A well-formed formula (wff) is any string that is formed
according to the following rules:
• A propositional symbol (or variable) is a wff.
• If P is a wff, then P is a wff.
• If P and Q are wffs, then so are:
P Q, P Q, P → Q, and P Q.
• If P is a wff, then (P) is a wff.
Truth Tables Define Operators
P Q P PQ PQ P→Q PQ
True True False True True True True
True False False True False False False
False True True True False True False
False False True False False True True
When Wffs are True
• A Boolean wff is valid or is a tautology iff it is true for
all assignments of truth values to the variables it
contains.
• A Boolean wff is satisfiable iff it is true for at least one
assignment of truth values to the variables it contains.
• A Boolean wff is unsatisfiable iff it is false for all
assignments of truth values to the variables it contains.
• Two wffs P and Q are equivalent, written P Q, iff
they have the same truth values regardless of the truth
values of the variables they contain.
Using Truth Tables
P P is a tautology:
P P P P
True False True
False True True
Properties of Boolean Operators
• and are commutative and associative.
•
• is commutative but not associative.
• and are idempotent:
(e.g., (P P) P).
• and distribute over each other:
• P (Q R) (P Q) (P R).
• P (Q R) (P Q) (P R).
More Properties
• Absorption laws:
• P (P Q) P.
• P (P Q) P.
• Double negation: P P.
• de Morgan’s Laws:
• (P Q) (P Q).
• (P Q) (P Q).
Entailment
A set A of wffs logically implies or entails a conclusion Q
iff, whenever all of the wffs in A are true, Q is also true.
Example:
ABC entail A→D
D
Inference Rules
• An inference rule is sound iff, whenever it is
applied to a set A of axioms, any conclusion
that it produces is entailed by A. An entire
proof is sound iff it consists of a sequence of
inference steps each of which was
constructed using a sound inference rule.
• A set of inference rules R is complete iff,
given any set A of axioms, all statements that
are entailed by A can be proved by applying
the rules in R.
Some Sound Inference Rules
• Modus ponens: From (P → Q) and P,
conclude Q.
• Modus tollens: From (P → Q) and Q,
conclude P.
• Or introduction: From P, conclude (P Q).
• And introduction: From P and Q, conclude
(P Q).
• And elimination: From (P Q), conclude P
or conclude Q.
First-Order Logic
A well-formed formula (wff) in first-order logic is an
expression that can be formed by:
• If P is an n-ary predicate and each of the expressions
x1, x2, … , xn is a term, then an expression of the form
P(x1, x2, … , xn) is a wff. If any variable occurs in such
a wff, then that variable is free.
• If P is a wff, then P is a wff.
• If P and Q are wffs, then so are P Q, P Q, P → Q,
and P Q.
• If P is a wff, then (P) is a wff.
• If P is a wff, then x (P) and x (P) are wffs. Any free
instance of x in P is bound by the quantifier and is
then no longer free.
Sentences
A wff with no free variables is called a sentence or a
statement.
1. Bear(Smoky).
2. x (Bear(x) → Animal(x)).
3. x (Animal(x) → Bear(x)).
4. x (Animal(x) → y (Mother-of(y, x))).
5. x ((Animal(x) Dead(x)) → Alive(x)).
A ground instance is a sentence that contains no
variables.
Truth
1. Bear(Smoky).
2. x (Bear(x) → Animal(x)).
3. x (Animal(x) → Bear(x)).
4. x (Animal(x) → y (Mother-of(y, x))).
5. x ((Animal(x) Dead(x)) → Alive(x)).
Which of these are true in the everyday world?
Interpretations and Models
• An interpretation for a sentence w is a pair (D, I), where D
is a universe of objects. I assigns meaning to the symbols
of w: it assigns values, drawn from D, to the constants in w
and it assigns functions and predicates (whose domains
and ranges are subsets of D) to the function and predicate
symbols of w.
• A model of a sentence w is an interpretation that makes w
true. For example, let w be the sentence:
x (y (y < x)).
• A sentence w is valid iff it is true in all interpretations.
• A sentence w is satisfiable iff there exists some
interpretation in which w is true.
• A sentence w is unsatisfiable iff w is valid.
Examples
• x ((P(x) Q(Smoky)) → P(x)).
• (x (P(x) (P(x))).
• x (P(x, x)).
Additional Sound Inference Rules
• Quantifier exchange:
• From x (P), conclude x (P).
• From x (P), conclude x (P).
• From x (P), conclude x (P).
• From x (P), conclude x (P) .
• Universal instantiation: For any constant C, from
x (P(x)), conclude P(C).
• Existential generalization: For any constant C,
from P(C) conclude x (P(x)).
A Simple Proof
Assume the following three axioms:
[1] x (P(x) Q(x) → R(x)).
[2] P(X1).
[3] Q(X1).
We prove R(X1) as follows:
[4] P(X1) Q(X1) → R(X1). (Universal instantiation, [1].)
[5] P(X1) Q(X1). (And introduction, [2], [3].)
[6] R(X1). (Modus ponens, [5], [4].)
Gödel’s Theorems
• Completeness Theorem: there exists some set of
inference rules R such that, given any set of axioms A
and a sentence c, there is a proof of c, starting with A
and applying the rules in R, iff c is entailed by A.
• Incompleteness Theorem: any theory that is derived
from a decidable set of axioms and that characterizes
the standard behavior of the constants 0 and 1, plus
the functions plus and times on the natural numbers,
cannot be both consistent and complete.
Sets
• S1 = {13, 11, 8, 23}.
• S2 = {8, 23, 11, 13}.
• S3 = {8, 8, 23, 23, 11, 11, 13, 13}.
• S4 = {apple, pear, banana, grape}.
• S5 = {January, February, March, April, May, June, July,
August, September, October, November, December}.
• S6 = {x : x S5 and x has 31 days}.
• S7 = {January, March, May, July, August, October,
December}.
Sets
• ℕ = the nonnegative integers (also called the natural
numbers).
• Z = the integers ( … -3, -2, -1, 0, 1, 2, 3, …).
Sets
• S8 = {i : x ℕ (i = 2x)}.
• S9 = {0, 2, 4, 6, 8, …}.
• S10 = the even natural numbers.
• S11 = the syntactically valid C programs.
• S12 = {x : x S11 and x never gets into an infinite loop}.
• S13 = {finite length strings of a’s and b’s}.
Defining a Set
• Write a program that enumerates the elements of S.
• Write a program that decides S by implementing the
characteristic function of S. Such a program
returns True if run on some element that is in S and
False if run on an element that is not in S.
Cardinality
The cardinality of every set we will consider is:
• a natural number (if S is finite),
• “countably infinite” (if S has the same number of
elements as there are integers), or
• “uncountably infinite” (if S has more elements than
there are integers).
Relating Sets to Each Other
Sets of Sets
• The power set of A is the set of all subsets of A.
Let A = {1, 2, 3}. Then:
P(A) = {, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}}.
• P(A) is a partition of a set A iff:
• no element of is empty,
• all pairs of elements of are disjoint , and
• the union of all the elements of equals A.
Partitions of A:
{{1}, {2, 3}} or {{1, 3}, {2}} or {{1, 2, 3}}.
What is a Relation?
An ordered pair is a sequence of two objects, written:
(x, y).
Order matters. So (unless x and y are equal):
(x, y) (y, x).
Cartesian Products
The Cartesian product of two sets A and B is the set of
all ordered pairs (a, b) such that a A and b B. We
write it as:
AB
If A and B are finite, the cardinality of their Cartesian
product is:
|A B| = |A||B|.
Cartesian Products
Let A be: {Dave, Sara, Billy}
Let B be: {cake, pie, ice cream}
A B = { (Dave, cake), (Dave, pie),
(Dave, ice cream), (Sara, cake),
(Sara, pie), (Sara, ice cream),
(Billy, cake), (Billy, pie), (Billy, ice cream)}.
B A = { (cake, Dave), (pie, Dave),
(ice cream, Dave),
(cake, Sara), (pie, Sara), (ice cream, Sara),
(cake, Billy), (pie, Billy), (ice cream, Billy)}.