3 Logic - V3
3 Logic - V3
CHAPTER 3
LOGIC
WHAT IS LOGIC?_______________________________________ 1
PROPOSITIONAL LOGIC _________________________________ 2
CONNECTIVES _______________________________________ 3
TRUTH TABLES ______________________________________ 5
EQUIVALENCES ______________________________________ 6
AND/OR GRAPH ______________________________________ 8
REASONING ________________________________________ 10
INFERENCE TECHNIQUES _____________________________ 12
PREDICATE CALCULUS ________________________________ 15
REASONING & INFERENCE TECHNIQUES IN PREDICATE
CALCULUS _________________________________________ 18
RESOLUTION REFUTATION____________________________ 19
PRACTICE MAKES PERFECT ____________________________ 23
3:0
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
3 LOGIC
WHAT IS LOGIC?
Logic is one of the basic disciplines of computer science. Logic is primarily concerned with
reasoning about the truth of statements. Logic is used to reason about the truth values of a
sentence. Logic concerned with the truthfulness of a chain of statements. Consider the
following three sentences:
Two kind of logic to be discussed in this chapter are propositional logic and predicate logic.
3:1
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
PROPOSITIONAL LOGIC
Proposition is commonly used to refer to a statement. A proposition (or statement) can be
assigned truth values: true (T) or false (F). Propositional logic is the simplest of logic. The
smallest entity to which a value of true or false can be assigned is called an atomic
proposition (or known as atom). Two or more atomic propositions can be combined
together with a connective to produce a compound proposition. For example, the following
are propositions:
Each of the propositions has a truth value of ‘true’ or ‘false’. For example, consider the first
sentence. If I happen to know a person named Siti who worked as a teacher and the
proposition is referred to the particular person, then the value of the proposition would be
‘true’. In the situation, where Siti in the first sentence is referring to Datuk Siti Nurhaliza, this
proposition would have a value of ‘false’.
Propositional logic has a formal language which allows us to formally represent propositions
and to construct complex sentences that are composed from two or more atomic
propositions. There are two aspects of language: syntax and semantics. Syntax is
concerned with the how the symbols can be combined to represent sentences and
semantics is concerned with the meaning.
The formal language of propositional logic defines a set of symbols for representing
propositions and a set of symbols for representing the logical connectives (or also referred to
as logical operators).
English sentences that we use in daily life can be formalized using propositional logic. The
process involves identifying the smallest parts of the sentence that can be assigned truth
values and denote these parts using propositional symbols. Link the small parts using the
connectives. For example, given the following sentences and their symbols:
Muzaffar is an astronaut. p
Faiz is an astronaut. q
From the example above, the sentence below can be structured by using the connective and
(which symbol is ).
3:2
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
CONNECTIVES
The connectives (or also known as logical operator) are defined using truth tables.
Connectives can be unary or binary connectives.
Unary connectives: the connective with only one argument. The only unary connective is not.
Binary connectives: the connective which take two arguments. A binary connective connects
two propositions together.
Connective Symbol
and , ∩,
or ,
not ¬,~
implies →,
equivalent ≡,↔
Not connective has the effect of inverting the truth value of the argument. The
negation of true is false and vice versa.
A sentence of a form ¬A i s true, if A is false and vice versa. (As shown in truth table
3).
The compound proposition which consist of two arguments and connected with an
and, will only be true if both arguments are true.
A sentence of a form A B will only be true if A and B is both true. (As shown in truth
table 1).
Example: ‘I have a million ringgit and a house in Kuala Lumpur’. This sentence is
only true if I have a million ringgit and the house. If I have a million ringgit, but don’t
have the house, this sentence is false.
3:3
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
Or connective (disjunction)
The compound proposition which consist of two arguments and connected with an or,
will be true if one or both arguments are true.
Example: ‘I want to buy the red dress or the blue blouse’. This sentence can be
interpreted as ‘I want to buy the red dress or the blue blouse, or both the red dress
and the blue blouse’.
Implies connective
p antecedent, evidence
q consequent, hypothesis
The compound proposition which consist of two arguments and connected with an
implies, will be true if one or both arguments are true.
Example: ‘If I am hungry, then I will eat’. Imagine the situation where you are visiting
a friend, and she ask you whether you want to taste her new recipe. Assuming you
make the given statement and you still do not eat when you are hungry. Then you
have lied to your friend about your statement.
Consider another example: ‘If the battery is dead (A), then the car can’t start (B)’. We
could translate the statement into A → B. There are four possible condition of this
statement:
A B
Battery is dead (T) → car can’t start (T) T
Battery is dead (T) → car can start (F) F
Battery not dead (F) → the car can’t start (T) T
Battery not dead (F) → car can start (F) T
3:4
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
TRUTH TABLES
The truth table for a connective defines what is the truth value should be assigned to a
compound proposition, given each combination of truth values for the component
propositions. For example, in the sentence p q. Both p and q can have values of T or F.
The truth tables for all four connectives are shown as below.
Procedure to find the truth table for an expression can be described as several basic
steps:
3:5
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
Example (p q) (p r)
4. Form the other columns by breaking the expression into simple component
parts.
1 2 3 4 5 4 5
p q r pq pr (p q) (p r)
T T T T T T
T T F T T T
T F T T T T
T F F T T T
F T T T T T
F T F T F F
F F T F T F
F F F F F F
EQUIVALENCES
If two expressions have the same truth table, they are said to be equivalent. The symbol ≡
is used to denote equivalence. For example:
(p q) (p r) ≡ p (q r)
This can be checked by the following truth table, showing that the resultant columns (in grey)
are the same.
1 2 3 4 5 4 5 6 7
p q r pq pr (p q) (p r) (q r) p (q r)
T T T T T T T T
T T F T T T F T
T F T T T T F T
T F F T T T F T
F T T T T T T T
F T F T F F F F
F F T F T F F F
F F F F F F F F
3:6
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
Equivalence can also be proven by using several laws. This is shown in the following table.
¬(¬A) ≡ A
De Morgan’s ¬(A B) ≡ ¬A ¬B
¬(A B) ≡ ¬A ¬B
(A B) C ≡ A (B C)
Association
(A B) C ≡ A (B C)
(A B) C ≡ (A C) (B C)
Distributive
(A B) C ≡ (A C) (B C)
Contradiction A ¬A ≡ F
Tautology A ¬A ≡ T
AB≡ BA
Commutative
AB≡ BA
A (A B) ≡ A
Absorption
A (A B) ≡ A
Solution p → ( q →r )
≡ ¬p ( q →r ) Idempotent Law
≡ ¬p (¬q r ) Idempotent Law
≡ (¬p ¬q ) r Association Law
≡ ¬(p q ) r De Morgan’s Law
≡(pq)→r Idempotent Law
3:7
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
AND/OR GRAPH
Logical operators AND and OR could be represented in a graph called AND/OR graph. This
graph connects nodes by sets of arcs. This is shown in the figure below:
AND CONNECTOR C
A B→C
A B
C C
OR CONNECTOR C
A B→C
A B
C C
If the truth value of the fact is known, a box is drawn to represent its value.
A B→C
A
B
Solution C
A B
3:8
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
Find the complete set of truth values for all possible truth assignments to p and q in the
following expressions.
Ex1 (p → q) (q → p)
Solution 1 2 3 4 34
p q p→q q→p (p → q) (q → p)
T T T T T
T F F T F
F T T F F
F F T T T
Solution 1 2 3 4 5: 3 4 5→3
p→q q→p (p → q) (q → p) (p → q) (q → p)
p q → (p → q)
T T T T T T
T F F T F F
F T T F F F
F F T T T T
Given the following rule base, draw the AND/OR graph for the following knowledge.
Ex3 A
B
C
A B→C
A C→E
B D→F
F→G
A E→ H
Solution
H
G
E
F
A B D
3:9
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
REASONING
Deductive reasoning
This type of reasoning involves process used by humans to deduce new information
from logically related known information. Human usually uses problem facts (axioms)
and related knowledge which are in the form of rules in problem solving. These rules
and facts should have been proven or accepted before they can be compared to the
axioms in order to conclude new axioms.
Example:
Premise : I will get wet if I am standing in the rain (A → B)
Premise : I am standing in the rain (A)
Conclusion : I will get wet (B)
This type of reasoning is logically appealing and become one of the most common
problem-solving techniques used by humans. The modus ponen inference technique
is the basic form of deductive reasoning
Inductive reasoning
Example:
Premise : Monkeys in the National Zoo eat bananas
Premise : Monkeys in the Taiping Zoo eats bananas
Conclusion : All monkeys eat bananas
Abductive reasoning
Example:
Premis : If a person has hypertension, he has heart attack
Premis : My grandfather has heart attack
Conclusion : My grandfather has hypertension
3:10
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
From the example given above, conclusion made is might be right or wrong even
though those two premises are true. The heart attack might not be caused by the
hypertension. It might be triggered by any other reason.
Analogical reasoning
Analogical reasoning is a reasoning type where human takes note of the fact that two
or more things are similar in some respects and concludes that they are probably
also similar in some further respect. In analogical reasoning, an analogy for a given
thing or situation is found, where the analogy is like the given thing in some way.
Other attributes of the analogical situation are then taken to also represent other
attributes of the given thing
Example:
Premise : MyVi is one of Perodua’s car.
Premise : MyVi is sold at a reasonable price.
Premise : MyVi is a very good car.
Premise : Viva is one of Perodua’s car.
Conclusion : Viva is a very good car and sold at a reasonable price.
In the example given above, an analogy is built about Perodua MyVi, and using the
same analogy the conclusion about Perodua Viva is achieved.
Common-sense reasoning
Example:
An experienced chess player plays chess based on experiences and
observations. While a novice player plays chess without any knowledge. This
kind of reasoning involves obtaining facts by observation, experience and use
them in solving problem.
Non-monotonic reasoning
Several terminologies:
Monotonic: something static and during execution the fact remain constant.
Non-monotonic: changing information during execution (human can adapt
with changes).
Non- monotonic reasoning deals with dynamic situations, where particular facts can
change as new information during execution. There are so many non-monotonic
factors that might affect the conclusion, for example, the weather, stock process,
foreign exchange, etc.
3:11
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
INFERENCE TECHNIQUES
Inference is reasoning mechanisms that are used to relate between facts and rules, to derive
new conclusions or facts. Inference used to determine when and how to retrieve, match
and execute what and which knowledge.
There are four inference techniques to be discussed in this chapter, which are as follows:
Modus Ponens
Modus ponens is an inference technique where given a rule, and the condition is
true, we can infer the conclusion is also true. Modus ponens can be summarized in
the following form:
X→Y
X
Conclude: Y
A simple example of the use of modus ponens in the propositional calculus, assume
the following observations:
Through an application of modus ponens, the fact that the ground will be wet, may be
added to the set of true expressions. In other words, modus ponens can be
formularized as ((X→ Y) X ) → Y. The formula means when X implies Y is true and
we know that X is true, and then we can conclude Y is true.
Modus Tollens
Modus Tollens is quite similar to modus ponens. Under the inference rule modus
tollens, if given a rule known to be true, and the consequence is known to be false,
we can infer that the condition is also false. A summary of modus tollens can be seen
in following formula:
X→Y
¬Y
Conclude: ¬X
Compared to modus ponen and hypothetical syllogism, modus tollens is a less useful
technique because its emphasis is on the negation of facts.
3:12
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
Hypothetical Syllogism
Hypothetical syllogism is one of the proof rules in classical logic that may or may not
be available in a non-classical logic. The hypothetical syllogism is a valid argument of
the following form:
P → Q.
Q → R.
P → R.
When the conclusion of one rule is the condition of a second rule, then you can
establish a third rule whose antecedent is that of the first rule and whose consequent
belong to the second rule.
Example:
If I do not wake up, then I cannot go to work.
If I cannot go to work, then I will not get paid.
Therefore, if I do not wake up, then I will not get paid.
Resolution Refutation
2. Negate the goal and convert result to clause form. Add the result to the clauses
obtained in step 1.
3:13
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
All clauses: 1) p q
2) p
3) q
3. q pq
p p
3:14
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
PREDICATE CALCULUS
In propositional calculus, each atomic symbol (P,Q, etc) denotes a proposition of some
complexity. There is no way to access the components of an individual assertion. This is
because the propositional logic is the simplest form of logic. Propositional logic is limited in
expressiveness and it is not good in representing situations.
For example, instead of representing the whole sentence ‘it rained on Tuesday’ with a single
symbol, we can create a predicate weather that describes the relationship between a date
and the weather: weather(tuesday,rain).
Another fall back of using propositional logic is some symbolized argument might not be
valid. For further understanding of this deficiency, the following example illustrates the
problem.
The symbolized argument is not valid and yet we can see that the original premises must
surely imply the conclusion Sadie has a master.
First Order Predicate Calculus (FOPC) is a more expressive type of logic, builds upon
propositional logic. Most of what presented previously in this chapter carries over to FOPC.
Several symbols are used in FOPC. Several terminologies to understand before constructing
the FOPC are as follows:
Predicate
The word used in FOPC to describe the symbols used when we make claims
about the object or relations between objects. Predicates are symbol expression
which having the first character lowercase.
Argument
The symbol representing the object enclosed within the parenthesis. An
argument can be a constant or variable symbol.
Arity
The number of arguments enclosed within the parenthesis. A predicate which has
arity = 1, is called unary predicates. While binary predicates has arity of 2.
Constant
The set of names used to refer to particular objects. These symbol expressions
have first character lowercase.
3:15
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
Variable
The set of names used to any object. These symbol expressions begin with an
uppercase character.
Quantifier
A variable quantifier used to constrain the meaning of a sentence containing a
variable. There are two types of quantifiers: universal quantifier () and
existential quantifier ().
A valid symbol to be used for predicates, and arguments must only consists of alphabets
(a,b,c,… and A,B,C,…), digits (0, 1, … , 9) and underscore (_). Any other characters are not
allowed in representing the symbols.
Linda is a girl.
predicate argument(constant)
predicate argument(constant)
Variable VS Constant
In this sentence, there are several objects to be considered. All children describe every child
that exists, while Linda is only one particular person named Linda. Therefore, we need a
variable to describe any children, and a constant to describe Linda.
3:16
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
Suppose that we are talking about children in a kindergarten, which are named in the
following set:
The previous set defines the domain of objects within the world, which we are concerned. If
All children like Linda, it can also be represented as:
The symbol quantifier helps in defining which object in the domain involves in the sentence.
The symbol is called universal quantifier and defines everything or all. While symbol is
called existential quantifier defines at least one or some.
Ex3 If Tompok is a dog, and Abu owns Tompok, then Abu is Tompok’s master.
Solution dog(tompok) owns(abu,tompok) → master(abu, tompok)
3:17
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
As discussed in propositional logic, there are several inference techniques could be used.
The same reasoning strategies and inference techniques may be applied with predicate
logic. However, the focus of the following chapter is only on resolution refutation in predicate
calculus.
Unification
Unification means a process that computes the appropriate substitution. The objective of
unification is to find a substitution that will allow two sentences to look the same. Once we
make two sentences look the same, it is possible to apply resolution.
In propositional logic, substitution is easier to be done. Propositions which are written with
the same symbol are considered as substitutes. However, the process is much complicated
for predicates because of the existence of variables and constants.
3:18
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
RESOLUTION REFUTATION
The only technique to be discussed for predicate calculus is resolution refutation. The other
inference techniques in propositional calculus can simply be applied with predicates as well.
However, some differences appear for predicate calculus. There are several steps involved
in refutation.
Step 4: Move all quantifiers to the left to obtain a prenex normal form.
(X) a(X) (Y) b(Y) ≡ (X)(Y) a(X) b(Y)
3:19
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
Skolem constant
• (X)(dog(X)) may be replaced by dog(fido) where the name fido is
picked from the domain of definition of X to represent that individual X.
Skolem function
• If the predicate has more than one argument and the existentially
quantified variable is within the scope of universally quantified
variables, the existential variable must be a function of those other
variables.
• Example:
(X)(Y) (mother(X,Y))
≡ (X)mother(X,m(X))
(X)(Y)(Z)(W)(foo (X,Y,Z,W))
≡ (X)(Y)(W)(foo(X,Y,f(X,Y),w))
2. Negate the goal and convert result to clause form. Add the result to the clauses
obtained in step 1.
3:20
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
1 Anyone passing his history exams and winning the lottery is happy
X (pass(X,history) win(X,lottery) → happy(X))
Step7: ¬study(john)
lucky(john)
3:21
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
6) ¬lucky(C) win(C,lottery)
7) ¬happy(john)
{X/john}
{C/john}
{A/john, B/history}
¬lucky(john) lucky(john)
3:22
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
a. ( p q) → r ≡ ( p ¬ r) → ¬ q
3:23
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
3. Given P and Q are true, and R and S are false. Find the values of the following
expressions:
3:24
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
b) (P → R) ^ (⌐Q → S)
4. Verify that the following logical expressions are tautology by computing its truth table.
3:25
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
b) (P (P→Q))→Q
Construct the proposition for the following sentences and create the truth table.
If you are fussy and have bad temper, you do not have many friends.
3:26
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
Write the following rules using pp, qq, and rr and logical connectives, and draw the
AND/OR graph for those rules below.
a) You get an A in this class, but you do not do every exercise in the book.
c) Getting an A on the final and doing every exercise in the book is sufficient for getting
an A in this class.
AND/OR graph:
R1: If a then b
R2: If c then d
R3: If e then f
R4: If g then a
R5: If h then c
R6: If d then i
3:27
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
8. Consider the following rules below, and then answer the following questions.
R1: If it's a nice day and it's summer, then I'll go to the golf course
R2: If it's a nice day and it's winter, then I'll go to the ski resort
R3: If it's not a nice day and it's summer, then I'll go to work
R4: If it's not a nice day and it's winter, then I'll go to class
R5: If I go to the golf course, then I'll play golf
R6: If I go to the ski resort, then I'll go skiing
R7: If I go skiing or play golf, then I'll have lots of fun
R8: If I go to work, then I'll be making money
R9: If I go to class, then I'll learn something useful
9. Use the following premises to prove the goals using resolution refutation.
a) PQ
P→R
Q→R
Goal: R
3:28
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
b) (P → Q) → Q
(P → P) → R
(R → S) → ¬(S → Q)
Goal: R
c) P→Q
¬P → ¬R
Goal: ¬Q → ¬R
3:29
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
e) (b c) → a
b
(d e) → c
ef
d ¬f
Goal: a
3:30
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
11. Represent the knowledge given below using propositional logic and prove the exciting
life using resolution refutation.
All people who are not poor and are smart are happy. Those people who read are not
stupid. John can read and is wealthy. Happy people have exciting lives.
3:31
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
2) Chicken is food.
4) Bill is tall.
3:32
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
3:33
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
3:34
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
13. Attempt to unify the following pair of expressions. Either show the unifiers or explain
why they will not unify.
3:35
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
a. All dogs are animal. Fido is a dog. All animals will die. Prove that Fido will die.
Solution:
Step 1: Transform into Predicate Statement (FOLC)
Clausal 1:
Clausal 2:
Clausal 3:
Negation:
3:36
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
b. All dogs like bones. Dogs eat everything they like. Pasta is a dog. Prove that Pasta
eat bone.
Solution:
Step 1: Transform into Predicate Statement (FOLC)
Goal statement:
Predicate:
Negation:
3:37
MODULE – LECTURE NOTES ISP542/ITS462 LOGIC
c. Sam is pink. Oscar is gray and likes Clyde. Oscar is either pink or gray. Oscar likes
Sam.
Prove that: [gray(X) pink(Y) likes(X,Y)]
d. All people who are not poor and are smart are happy. Those people who read are
not stupid. John can read and is wealthy. Happy people have exciting lives. Prove
that John has an exciting life.
e. No animal lover kills any animal. Jack owns a cat. Every cat owner is an animal
lover. Either Jack or Curiosity killed Tuna. Tuna is a cat. All cats are an animal.
Prove that Jack did not kill Tuna.
f. John likes all kinds of food. Anything anyone eats and isn’t killed by is food. Bill
eats peanuts and he is still alive. Sue eats everything Bill eats. Prove that John like
peanuts.
g. Every child loves Santa. Everyone who loves Santa loves any reindeer. Rudolph is
a reindeer and Rudolph has a red nose. Anything which has a red nose is weird or
is a clown. No reindeer is a clown. Scrooge does not love anything which is weird.
Prove that Scrooge is not a child.
h. Tony, Mike, and John are members of the Alpine Club. Every member of the Alpine
Club is either a skier or a mountain climber. No mountain climber likes rain. All
skiers like snow. Mike dislikes whatever Tony likes and likes whatever Tony
dislikes. Tony likes rain and snow. Prove that Mike a mountain climber.
i. Anyone who rides Harley is a rough character. Every biker ride either a Harley or a
BMW. Anyone who rides BMW is a yuppie. Every yuppie is a lawyer. Any nice girl
does not date anyone who is a rough character. Mary is a nice girl, and John is a
biker. If John is not a lawyer, proof that Mary does not date John.
j. Anyone whom Mary loves is a football star. Anyone who does not pass does not
play. Michael is a student. Anyone who does not study does not pass. Anyone who
does not play is not a football star. Michael does not study. Prove that Mary does
not love Michael.
k. Every coyote chases some roadrunner. Every roadrunner who says “beep-beep” is
smart. No coyote catches any smart roadrunner. Any coyote who chases some
roadrunner but does not catch it is frustrated. All roadrunners are smart. Wendy is
a roadrunner. Prove that all coyotes are frustrated.
3:38