LOGIC
COMPUTER SCIENCE DEPARTMENT
MAGOMELO M.
Introduction
• In developing a mathematical theory, assertions or
statements are made.
• These statements are made in the form of sentences using
words and mathematical symbols.
• When proving a theory, a mathematician uses a system of
logic.
• This is also the case when developing an algorithm for a
program or system of programs in computer science.
• The system of logic is applied to decide if a statement follows
from, or is a logical consequence of, one or more other
statements.
LOGIC
Logic is the study of the principles and
methods that distinguishes between a valid
and an invalid argument.
Statements
• A statement is an assertion or a declarative sentence that
is either true or false but not both.
• A statement is also referred to as a proposition
• The truth value of a mathematical statement can be
determined by application of known rules, axioms and
laws of mathematics.
• A statement which is true requires a proof.
• Example: 2+2 = 4, It is Sunday today
• If a proposition is true, its truth value is "true”.
• If a proposition is false, its truth value is "false".
• The truth values “true” and “false” are, respectively,
denoted by the letters T and F or by 1 and 0 resp.
Simple Statements
• A simple or primitive statement is a statement which
cannot be broken down into anything simpler.
• A simple statement is denoted by use of letters p, q,
r...
• Examples:
– p: There are seven days in a week
• p is a simple statement
– r: 3+ 2 = 6
• r is a simple statement
More Examples
EXAMPLES:
1.Grass is green.
2.4 + 2 = 6
3.4 + 2 = 7
4.There are four fingers in
a hand.
are propositions
Understanding Statements
1.x + 2 is positive. Not a statement
2.May I come in? Not a statement
3.Logic is interesting. A statement
4.It is hot today. A statement
5.-1 > 0 A statement
6.x + y = 12 Not a statement
Compound Statement
• A compound or composite statement is a
statement which is comprised of simple
statements and logical operations
(connectives).
• A compound statement is denoted by use of
letters P, Q, R...
Examples:
• P: There are seven days in a week and twelve months in a year.
• p: There are seven days in a week
• q: There twelve months in a year
• Operation: and
• Q: The grass is green or It is hot today
• q: The grass is green
• r: It is hot today
• Operation: or
• P: If it is not raining then I will go outside and eat my lunch.
• p: It is raining
• q: I will go outside
• r: I will eat my lunch
• Negation of p
• Operations: If… then, and
Exercise
Logical Operations/Connectives
1
Examples
• p = “Harare is the capital of Zimbabwe”
q = “18 is divisible by 3”
• p q = “Harare is the capital of Zimbabwe and 18 is divisible by
3”
• p q = “Harare is the capital of Zimbabwe or 18 is divisible by 3”
• ~p = “It is not the case that Harare is the capital of Zimbabwe” or
simply
“Harare is not the capital of Zimbabwe”
TRANSLATING FROM ENGLISH TO SYMBOLS
Let p = “It is hot”, and q = “ It is sunny”
SENTENCE SYMBOLIC FORM
1.It is not hot. ~p
2.It is hot and sunny. p q
3.It is hot or sunny. pq
4.It is not hot but sunny. ~ p q
5.It is neither hot nor sunny. ~ p ~ q
Examples/Practice
Let h = “Don is healthy”
w = “Don is wealthy”
s = “Don is wise”
Translate the compound statements to symbolic form:
1.Don is healthy and wealthy but not wise. (h w) (~s)
2. is not wealthy but he is healthy and wise. ~w (h s)
3.Don is neither healthy, wealthy nor wise. ~h ~w ~s
TRANSLATING FROM SYMBOLS TO ENGLISH
Let
m = “Alex is good in Mathematics”
c = “Alex is a Computer Science student”
:
Translate the following statement forms into plain English:
1.~ c Alex is not a Computer Science student
2.c m Alex is a Computer Science student or good in Maths.
3.m ~c Alex is good in Maths but not a Computer Science
student
A convenient method for analyzing a compound statement is to
make a truth table for it.
Truth Tables
• A statement P can hold one of two truth values, true or
false.
• These are denoted “T” and “F” respectively.
• Some books may use “1” for true and “0” for false.
• When determining the truth value of a compound
statement all possible combinations of the truth values of
the statements comprising it must be considered.
• This is done systematically by the use of truth tables.
• Therefore, a truth table specifies the truth value of a
compound proposition for all possible truth values of its
constituent propositions
Truth Table Construction
•• To
construct a truth table assign each statement a
column.
• The number of rows in the table is determined by the
number of statements.
– For n statements, rows will be required.
• Systematically assign truth vales to each of the
statements, beginning in the first column.
• Once all possible truth values for the simple statements
are inserted, determine the truth vales of the compound
statements following the rules for the operations.
Negation, “not”
• If P is a statement, the negation of P is “not P” or “it is
not the case that P” and is denoted ~P.
•
1
Conjunction ()/ “and”:
If p and q are statements, then the conjunction of p
and q is “p and q”, denoted as “p q”.
It is true when, and only when, both p and q are true.
If either p or q is false, or if both are false, pq is
false. Truth Table: p q
Disjunction () /“or”
I f p & q are statements, then the disjunction of p and
q is “p or q”, denoted as “p q”.
It is true when at least one of p or q is true and is false
only when both p and q are false.
Truth Table: p q
Exercise
Exclusive Disjunction
• The exclusive disjunction of p and q is symbolized
by p ⊕ q.
• This compound proposition is true when exactly
one (i.e. one or other, but not both) of its
components is true. The truth table for p q
p q pq
T T F
T F T
F T T
FF FF FF
Exclusive Cont’d……
• When two simple propositions are combined using
‘or’, context will provide the clue as to whether the
inclusive or exclusive sense is intended.
• “Tomorrow I will go swimming or play football”
seems to suggest that I will not do both and
therefore becomes exclusive or.
• ‘Applicants for this post must be over 25 or have at
least 3 years relevant experience’ suggests that
applicants who satisfy both criteria will be
considered, therefore or becomes inclusive
Disjunction cont’d…….
• Where context does not resolve the ambiguity
surrounding the word ‘or’, the intended sense
can be made clear by affixing ‘or both’ to
indicate an inclusive reading,
• Or by affixing ‘but not both’ to make clear the
exclusive sense.
• Where there is no clue as to which
interpretation is intended and context does
not make this clear, then ‘or’ is conventionally
taken in its inclusive sense.
Conditional/ “If … then”, “implies”
Statements
• Also known as Implication
• Consider the statement:
• "If you earn an A in Math, then I'll buy you a computer."
• This statement is made up of two simpler statements:
• p: "You earn an A in Math," and
• q: "I will buy you a computer."
• The original statement is then saying :
if p is true, then q is true, or, more simply, if p, then q.
• We can also phrase this as p implies q, and we write
p q.
Conditional Statements
• If p and q are statement variables, the conditional of q by p
is “If p then q” or “p implies q” and is denoted by p
q.
• It is only false when p is true and q is false; otherwise it is
true.
• The arrow " " is the conditional operator, and in p
q the statement p is called the hypothesis (or antecedent)
and q is called the conclusion (or consequent).
The Truth Table
1
Other Ways of Expressing Implications
The implication p q could be expressed in many
alternative ways as:
•“if p then q” •“not p unless q”
•“p implies q” •“q follows from p”
•“if p, q” •“q if p”
•“p only if q” •“q whenever p”
•“p is sufficient for q” •“q is necessary for p”
More About Conditional
• Given the conditional proposition p →q, we
define the following:
• (a) the converse of p → q : q → p
• (b) the inverse of p →q : ~ p → ~ q
• (c) the contrapositive of p →q : ~ q → ~ p.
Conditionals cont’d…..
• The truth table gives conditional values for its
converse, inverse and contrapositive
•
p q pq q p ~p~q ~q~p
T T T T T T
T F F T T F
F T T F F T
F F T T T T
Exercise
• State the converse, inverse and contrapositive of
the proposition:
– If Jack plays his guitar then Sara will sing.
• State the converse, inverse and contrapositive of
the proposition:
– If it’s not Sunday then the supermarket is open until
midnight.
Possible Solution: First Proposition
• Solution
• We define: p: Jack plays his guitar
• q: Sara will sing
• so that: p →q: If Jack plays his guitar then Sara will
sing.
• Converse: q → p: If Sara will sing then Jack plays his
guitar.
• Inverse: ~ p → ~ q: If Jack doesn’t play his guitar
then Sara won’t sing.
• Contrapositive: ~ q → ~ p: If Sara won’t sing then
Jack doesn’t play his guitar.
Inverse of Conditional Statements
The inverse of the conditional statement p q is
~p ~q
A conditional and its inverse are not equivalent as
could be seen from the truth table.
Biconditional “If and only if”
• If p and q are statement variables, the biconditional
of p and q is “p if, and only if, q” and is denoted
pq. if and only if abbreviated iff.
• The double headed arrow " " is the biconditional
operator.
• Alternative wording for P⇔Q can be:
– P if, and only if Q.
– P iff Q.
– P implies and is implied by Q.
– P is equivalent to Q.
– P is a necessary and sufficient condition for Q.
Order of operation for logical operators
• The order of operation for logical operators is as follows:
1. Evaluate negations first
2. Evaluate ∨and ∧ second. When both are present,
parenthesis may be needed, otherwise work left to
right.
3. Evaluate ⇒ and ⇔ third. When both are present,
parenthesis may be needed, otherwise work left to
right.
• Note: Use of parenthesis will determine order of
operations which over ride the above order.
Summary
1.What is a statement?
2.How a compound statement is formed.
3.Logical connectives (negation, conjunction,
disjunction).
4.How to construct a truth table for a statement form.
TAUTOLOGY
• A tautology is a statement form that is always true
regardless of the truth values of the statement
variables.
• A tautology is represented by the symbol “t”..
EXAMPLE:The statement form p ~ p is tautology
CONTRADICTION
• A contradiction is a statement form that is always
false regardless of the truth values of the statement
variables.
• A contradiction is represented by the symbol “c”.
• So if we have to prove that a given statement form
is CONTRADICTION we will make the truth
table for the statement form and if in the column of
the given statement form all the entries are F ,then
we say that statement form is contradiction.
EXAMPLE:
The statement form p ~ p is a contradiction.
EXAMPLE
Since in the last column in the truth table we have F
in all the entries so is a contradiction
p ~p c
p ~p p ~p
T F F
F T F
REMARKS
REMARKS:
– Most statements are neither tautologies nor
contradictions.
– A proposition that is neither a tautology nor a
contradiction is called a contingency.
– The negation of a tautology is a contradiction and vice
versa.
– In common usage we sometimes say that two statement
are contradictory.
By this we mean that their conjunction is a
contradiction: they cannot both be true.
Logical Equivalence
• Two compound propositions are called logically equivalent if
and only if they have the same truth values no matter what truth
value their constituent propositions they have.
• For instance p → q and ~ p ∨ q are logically equivalent, and we
write it:
p→q~p∨q
• Note that if two propositions P and Q are logically equivalent
then P ↔Q is a tautology.
• To determine if two statements P and Q are logically equivalent,
construct a full truth table for each statement.
• If their truth values at the main connective are identical, the
statements are equivalent.
• Alternatively show P ↔ Q is a tautology and hence conclude P
≡Q.
Example
• Show that p → q ~ p ∨ q
Practice
• Using truth tables, show that the following propositions
are logically equivalent
1. p ↔ q ≡ (p → q) (q → p)
2. ~(p q) and p q
3.De Morgan’s Laws for Logic. :
i. ~ (p q) ≡ ~ p ~ q
ii. ~ (p q) ≡ ~ p ~ q
LAWS OF LOGIC
•
1.Commutative Law:
pqqp
(p q) (q p)
(p q) (q p)
2.Implication Laws:
p q ~p q ~(p ~q)
3.Exportation Law:
(p q)r p (q r)
4.Equivalence:
p q (p q)(q p)
5.Reductio ad absurdum:
p q (p ~q) c
6. De Morgan’s Laws:
i. ~ (p q) ≡ ~ p ~ q
ii. ~ (p q) ≡ ~ p ~ q
•
7. Associative Laws:
((p q) r) (p (q r))
((p q) r) (p (q r))
((p q) r) (p (q r))
8. Distributive Laws:
((p q) r) (p q) (q r))
((p q) r) (p q) (q r))
9. Double Negation (Involution) Law:
~~p p
10. Identity Laws:
(p F) p
(p T) p
11. Negation (Complement) Laws:
(p ~p) T
(p ~p) F
12. Idempotent Laws:
(p p) p
(p p) p
13. Absorption Laws:
p (p q) p
p (p q) p
LAWS OF LOGIC - APPLICATION
Rewrite the statement forms without using the symbols or
i. p~q r
ii. (p r)(q r)
SOLUTION
iii. p~q r (p~q)r order of operations
~(p~q) r implication law
ii. (p r)(q r) (~p r)(~q r)implication law
[(~p r) (~q r)] [(~q r) (~p r)]
equivalence of biconditional [~(~p r) (~q r)]
[~(~q r) (~p r)]
implication law
Practice: Rewrite the statement form ~p q r ~q to a logically
equivalent form that uses only ~ and
SOLUTION
STATEMENT REASON
~p q r ~q Given statement form
(~p q) (r ~q) Order of operations
~[(~p q) ~ (r ~q)] Implication law
pq ~(p~ q)
~[~(p ~q) (~r q)] De Morgan’s law
Exercise
1. Let p be the statement “Mathematics is easy” and q be
the statement “I do not need to study”. Write down in
words the following statements, and simplify if
possible:
a. ~p q b. p q
2. Construct truth tables for the compound statements
(p ∨ ~p ) ∧(q ∨ r) and q ∨ r . What do you notice?
3. Using Laws of Logic, write the following expressions
using only ∧, ∨ and ~ . Further, write the expression in
the simplest form.
4. Let p, q and r be statements. Using Logical
Equivalences, prove the following.