UNIT-I Mathematical Foundations of Computer Science
UNIT-I Mathematical Foundations of Computer Science
UNIT-I Mathematical Foundations of Computer Science
Mathematical Logic
INTRODUCTION
Proposition: A proposition or statement is a declarative sentence which is either
true or false but not both. The truth or falsity of a proposition is called its truth-value.
These two values ‗true‘ and ‗false‘ are denoted by the symbols T and F
respectively. Sometimes these are also denoted by the symbols 1 and 0 respectively.
Example 1: Consider the following sentences:
1. Delhi is the capital of India.
2. Kolkata is a country.
3. 5 is a prime number.
4. 2 + 3 = 4.
These are propositions (or statements) because they are either true of false.
Next consider the following sentences:
5. How beautiful are you?
6. Wish you a happy new year
7. x + y = z
8. Take one book.
These are not propositions as they are not declarative in nature, that is, they do not
declare a definite truth value T or F.
Propositional Calculus is also known as statement calculus. It is the branch of
mathematics that is used to describe a logical system or structure. A logical system
consists of (1) a universe of propositions, (2) truth tables (as axioms) for the logical
operators and (3) definitions that explain equivalence and implication of propositions.
Connectives
The words or phrases or symbols which are used to make a proposition by two or more
propositions are called logical connectives or simply connectives. There are five basic
connectives called negation, conjunction, disjunction, conditional and biconditional.
Negation
The negation of a statement is generally formed by writing the word ‗not‘ at a
proper place in the statement (proposition) or by prefixing the statement with the phrase
‗It is not the case that‘. If p denotes a statement then the negation of p is written as p and
read as ‗not p‘. If the truth value of p is T then the truth value of p is F. Also if the truth
value of p is F then the truth value of p is T.
Table 1. Truth table for negation
p ¬p
T F
F T
Conjunction
The conjunction of two statements (or propositions) p and q is the statement p ∧ q which is
read as ‗p and q‘. The statement p ∧ q has the truth value T whenever both p and q have the truth
value T. Otherwise it has truth value F.
p q p∧ q
T T T
T F F
F T F
F F F
Disjunction
The disjunction of two statements p and q is the statement p ∨ q which is read as ‗p or q‘.
The statement p ∨ q has the truth value F only when both p and q have the truth value F. Otherwise
it has truth value T.
p q p∨ q
T T T
T F T
F T T
F F F
Conditional proposition
If p and q are any two statements (or propositions) then the statement p → q which is read as,
‗If p, then q‘ is called a conditional statement (or proposition) or implication and the connective
is the conditional connective.
p q p→q
T T T
T F F
F T T
F F T
To understand better, this connective can be looked as a conditional promise. If the promise
is violated (broken), the conditional (implication) is false. Otherwise it is true. For this reason, the
only circumstances under which the conditional p → q is false is when p is true and q is false.
‘The crop will be destroyed if there is a flood’ into symbolic form using conditional
connective.
(i) You will get a speeding ticket if you drive over 70 km per hour.
(ii) Driving over 70 km per hour is sufficient for getting a speeding ticket.
(iii) If you do not drive over 70 km per hour then you will not get a speeding ticket.
(iv) Whenever you get a speeding ticket, you drive over 70 km per hour.
Solution: (i) p → q (ii) p → q (iii) p → q (iv) q → p.
2. Some of the alternative terminologies used to express p → q (if p, then q) are the
following: (i) p implies q
(ii) p only if q (‗If p, then q‘ formulation emphasizes the antecedent, whereas ‗p only if q‘
formulation emphasizes the consequent. The difference is only stylistic.)
(iii) q if p, or q when p.
(v) p is sufficient for q, or a sufficient condition for q is p. (vi) q is necessary for p, or a necessary
condition for p is q. (vii) q is consequence of p.
Converse, Inverse and Contrapositive
If P → Q is a conditional statement, then
(1). Q → P is called its converse
(2). ¬P → ¬Q is called its inverse
(3). ¬Q → ¬P is called its contrapositive.
Truth table for Q → P (converse of P → Q)
P Q Q→P
T T T
T F T
F T F
F F T
Truth table for ¬P → ¬Q (inverse of P → Q)
P Q ¬P ¬Q ¬P → ¬Q
T T F F T
T F F T T
F T T F F
F F T T T
Truth table for ¬Q → ¬P (contrapositive of P → Q)
P Q ¬Q ¬P ¬Q → ¬P
T T F F T
T F T F F
F T F T T
F F T T T
T T T T T
T F F T F
F T T F F
F F T T T
Biconditional proposition
If p and q are any two statements (propositions), then the statement p↔ q which is read as ‗p if and
only if q‘ and abbreviated as ‗p iff q‘ is called a biconditional statement and the connective is the
biconditional connective.
The truth table of p↔q is given by the following table:
Table 6. Truth table for biconditional
p q p↔q
T T T
T F F
F T F
F F T
It may be noted that p q is true only when both p and q are true or when both p and q are
false. Observe that p q is true when both the conditionals p → q and q → p are true, i.e., the truth-
values of (p → q) ∧ (q → p), given in Ex. 9, are identical to the truth-values of p q defined here.
Tautology: A statement formula which is true regardless of the truth values of the statements
which replace the variables in it is called a universally valid formula or a logical truth or a
tautology.
Contradiction: A statement formula which is false regardless of the truth values of the
statements which replace the variables in it is said to be a contradiction.
Contingency: A statement formula which is neither a tautology nor a contradiction is known
as a contingency.
Equivalence of Formulas
Two formulas A and B are said to equivalent to each other if and only if A↔ B is a
tautology.
If A↔B is a tautology, we write A ⇔ B which is read as A is equivalent to B.
Note : 1. ⇔ is only symbol, but not connective.
2. A ↔ B is a tautology if and only if truth tables of A and B are the same.
3. Equivalence relation is symmetric and transitive.
Method I. Truth Table Method: One method to determine whether any two statement
formulas are equivalent is to construct their truth tables.
Example: Prove P ∨ Q ⇔ ¬(¬P ∧ ¬Q).
Solution:
P Q P∨Q ¬P ¬Q ¬P ∧ ¬Q ¬(¬P ∧ ¬Q) (P ∨ Q) ⇔ ¬(¬P ∧ ¬Q)
T T T F F F T T
T F T F T F T T
F T T T F F T T
F F F T T T F T
As P ∨ Q ¬(¬P ∧ ¬Q) is a tautology, then P ∨ Q ⇔ ¬(¬P ∧ ¬Q).
Example: Prove (P → Q) ⇔ (¬P ∨ Q).
Solution:
P Q P→Q ¬P ¬P ∨ Q (P → Q) (¬P ∨ Q)
T T T F T T
T F F F F T
F T T T T T
F F T T T T
(a) (P ∨ Q) ∨ R ⇔ P ∨ (Q ∨ R) (b) (P ∧ Q) ∧ R ⇔ P ∧ (Q ∧ R)
3. Commutative laws:
(a) P ∨ Q ⇔ Q ∨ P (b) P ∧ Q ⇔ Q ∧ P
4. Distributive laws:
P ∨ (Q ∧ R) ⇔ (P ∨ Q) ∧ (P ∨ R) P ∧ (Q ∨ R) ⇔ (P ∧ Q) ∨ (P ∧ R)
5. Identity laws:
(a) (i) P ∨ F ⇔ P (ii) P ∨ T ⇔ T
(b) (i) P ∧ T ⇔ P (ii) P ∧ F ⇔ F
6. Component laws:
(a) P ∨ (P ∧ Q) ⇔ P (b) P ∧ (P ∨ Q) ⇔ P
8. Demorgan‘s laws:
Consider the statement: ‖If you study hard, then you will excel‖. Write its converse,
contra positive and logical negation in logic.
Duality Law
Two formulas A and A∗ are said to be duals of each other if either one can be obtained from the
other by replacing ∧ by ∨ and ∨ by ∧. The connectives ∨ and ∧ are called duals of each other. If the
formula A contains the special variable T or F , then A∗, its dual is obtained by replacing T by F and
F by T in addition to the above mentioned interchanges.
Example: Write the dual of the following formulas:
13
(i). (P ∨ Q) ∧ R (ii). (P ∧ Q) ∨ T (iii). (P ∧ Q) ∨ (P ∨ ¬(Q ∧ ¬S))
Solution: The duals of the formulas may be written as
(i). (P ∧ Q) ∨ R (ii). (P ∨ Q) ∧ F (iii). (P ∨ Q) ∧ (P ∧ ¬(Q ∨ ¬S))
Result 1: The negation of the formula is equivalent to its dual in which every variable
is replaced by its negation.
We can prove
¬A(P1, P2, ..., Pn) ⇔ A∗(¬P1, ¬P2, ..., ¬Pn)
Example: Prove that (a). ¬(P ∧ Q) → (¬P ∨ (¬P ∨ Q)) ⇔ (¬P ∨ Q)
(b). (P ∨ Q) ∧ (¬P ∧ (¬P ∧ Q)) ⇔ (¬P ∧ Q)
Solution: (a).¬(P ∧ Q) → (¬P ∨ (¬P ∨ Q)) ⇔ (P ∧ Q) ∨ (¬P ∨ (¬P ∨ Q)) [∵ P → Q ⇔ ¬P ∨ Q]
⇔ (P ∧ Q) ∨ (¬P ∨ Q)
⇔ (P ∧ Q) ∨ ¬P ∨ Q
⇔ ((P∧ Q) ∨ ¬P )) ∨ Q
⇔ ((P ∨ ¬P ) ∧ (Q ∨ ¬P )) ∨ Q
⇔ (T ∧ (Q ∨ ¬P )) ∨ Q
⇔ (Q ∨ ¬P ) ∨ Q
⇔ Q ∨ ¬P
⇔ ¬P ∨ Q
(b). From (a)
(P ∧ Q) ∨ (¬P ∨ (¬P ∨ Q)) ⇔ ¬P ∨ Q
Writing the dual
(P ∨ Q) ∧ (¬P ∧ (¬P ∧ Q)) ⇔ (¬P ∧ Q)
Tautological Implications
A statement formula A is said to tautologically imply a statement B if and only if A → B
is a tautology.
In this case we write A ⇒ B, which is read as ‘A implies B‘.
Note: ⇒ is not a connective, A ⇒ B is not a statement formula.
A ⇒ B states that A → B is tautology.
Clearly A ⇒ B guarantees that B has a truth value T whenever A has the truth value T .
One can determine whether A ⇒ B by constructing the truth tables of A and B in the same manner as
was done in the determination of A ⇔ B. Example: Prove that (P → Q) ⇒ (¬Q → ¬P ).
P Q ¬P ¬Q P→Q ¬Q → ¬P (P → Q) → (¬Q → ¬P )
T T F F T T T
T F F T F F T
F T T F T T T
F F T T T T T
Since all the entries in the last column are true, (P → Q) → (¬Q → ¬P ) is a
tautology.
Hence (P → Q) ⇒ (¬Q → ¬P ).
In order to show any of the given implications, it is sufficient to show that an
assignment of the truth value T to the antecedent of the corresponding condi-
tional leads to the truth value T for the consequent. This procedure guarantees that the
conditional becomes tautology, thereby proving the implication.
Other Connectives
We introduce the connectives NAND, NOR which have useful applications in the design of
computers.
NAND: The word NAND is a combination of ‘NOT‘ and ‘AND‘ where ‘NOT‘ stands for negation
and ‘AND‘ for the conjunction. It is denoted by the symbol ↑.
If P and Q are two formulas then
P ↑ Q ⇔ ¬(P ∧ Q)
The connective ↑ has the following equivalence:
P ↑ P ⇔ ¬(P ∧ P ) ⇔ ¬P ∨ ¬P ⇔ ¬P .
Normal Forms
n
If a given statement formula A(p1, p2, ...pn) involves n atomic variables, we have 2
possible combinations of truth values of statements replacing the variables.
The formula A is a tautology if A has the truth value T for all possible assignments of the
truth values to the variables p1, p2, ...pn and A is called a contradiction if A has the truth
value F for all possible assignments of the truth values of the n variables. A is said to be satis
able if A has the truth value T for atleast one combination of truth values assigned to p1, p2,
...pn.
The problem of determining whether a given statement formula is a Tautology, or a
Contradiction is called a decision problem.
The construction of truth table involves a finite number of steps, but the construc-tion
may not be practical. We therefore reduce the given statement formula to normal form and
find whether a given statement formula is a Tautology or Contradiction or atleast satisfiable.
It will be convenient to use the word ‖product‖ in place of ‖conjunction‖ and ‖sum‖ in
place of ‖disjunction‖ in our current discussion.
A formula which is equivalent to a given formula and which consists of a sum of elementary
products is called a disjunctive normal form of the given formula.
The method for obtaining conjunctive normal form of a given formula is similar to the one
given for disjunctive normal form. Again, the conjunctive normal form is not unique.
Minterm: For a given number of variables, the minterm consists of conjunctions in which each
statement variable or its negation, but not both, appears only once.
2
Let P and Q be the two statement variables. Then there are 2 minterms given by P ∧ Q, P ∧ ¬Q,
¬P ∧ Q, and ¬P ∧ ¬Q.
Minterms for three variables P , Q and R are P ∧ Q ∧ R, P ∧ Q ∧ ¬R, P ∧ ¬Q ∧ R,P∧ ¬Q ∧ ¬R, ¬P
∧ Q ∧ R, ¬P ∧ Q ∧ ¬R, ¬P ∧ ¬Q ∧ R and ¬P ∧ ¬Q ∧ ¬R. From the truth tables of these minterms
of P and Q, it is clear that
P Q P∧Q P ∧ ¬Q ¬P ∧ Q ¬P ∧ ¬Q
T T T F F F
T F F T F F
F T F F T F
F F F F F T
T T T P∧Q
T F F P ∧ ¬Q
F T T ¬P ∧ Q
F F T ¬P ∧ ¬Q
T T T P∧Q∧R T F T T
T T F P ∧ Q ∧ ¬R T F F T
T F T P ∧ ¬Q ∧ R F F F F
T F F P ∧ ¬Q ∧ ¬R F F F F
F T T ¬P ∧ Q ∧ R F T T T
F T F ¬P ∧ Q ∧ ¬R F F F F
F F T ¬P ∧ ¬Q ∧ R F T F T
F F F ¬P ∧ ¬Q ∧ ¬R F F F F
In order to obtain the principal disjunctive normal form of a given formula is con-
structed as follows:
P ∨ (P ∧ Q) ⇔ P
P ∨ (¬P ∧ Q) ⇔ P ∨ Q
Solution: We write the principal disjunctive normal form of each formula and com-pare these
normal forms.
(a) P ∨ (P ∧ Q) ⇔ (P ∧ T ) ∨ (P ∧ Q) [∵ P ∧ Q ⇔ P ]
⇔ (P ∧ (Q ∨ ¬Q)) ∨ (P ∧ Q) [∵ P ∨ ¬P ⇔ T ]
⇔ ((P ∧ Q) ∨ (P ∧ ¬Q)) ∨ (P ∧ Q) [by distributive laws]
⇔ (P ∧ Q) ∨ (P ∧ ¬Q) [∵ P ∨ P ⇔ P ]
which is the required PDNF.
Now, ⇔P∧T
⇔ P ∧ (Q ∨ ¬Q)
⇔ (P ∧ Q) ∨ (P ∧ ¬Q)
which is the required PDNF.
Hence, P ∨ (P ∧ Q) ⇔ P .
Now,
P ∨ Q ⇔ (P ∧ T ) ∨ (Q ∧ T )
⇔ (P ∧ (Q ∨ ¬Q)) ∨ (Q ∧ (P ∨ ¬P ))
⇔ (P ∧ Q) ∨ (P ∧ ¬Q) ∨ (Q ∧ P ) ∨ (Q ∧ ¬P )
⇔ (P ∧ Q) ∨ (P ∧ ¬Q) ∨ (¬P ∧ Q)
which is the required PDNF.
Hence, P ∨ (¬P ∧ Q) ⇔ P ∨ Q.
Example: Obtain the principal disjunctive normal form of
→ ((P → Q) ∧ ¬(¬Q ∨ ¬P )) ⇔ ¬P
∨ ((¬P ∨ Q) ∧ (Q ∧ P ))
⇔ ¬P ∨ ((¬P ∧ Q ∧ P ) ∨ (Q ∧ Q ∧ P )) ⇔
¬P ∨ F ∨ (P ∧ Q)
⇔ ¬P ∨ (P ∧ Q)
⇔ (¬P ∧ T ) ∨ (P ∧ Q)
⇔ (¬P ∧ (Q ∨ ¬Q)) ∨ (P ∧ Q)
Example: Obtain the principal conjunctive normal form of the formula (¬P→R)∧(Q↔P)
Solution:
(¬P → R) ∧ (Q ↔ P )
⇔ [¬(¬P ) ∨ R] ∧ [(Q → P ) ∧ (P → Q)]
⇔ (P ∨ R) ∧ [(¬Q ∨ P ) ∧ (¬P ∨ Q)]
⇔ (P ∨ R ∨ F ) ∧ [(¬Q ∨ P ∨ F ) ∧ (¬P ∨ Q ∨ F )]
⇔ [(P ∨ R) ∨ (Q ∧ ¬Q)] ∧ [¬Q ∨ P ) ∨ (R ∧ ¬R)] ∧ [(¬P ∨ Q) ∨ (R ∧ ¬R)]
⇔ (P ∨ R ∨ Q) ∧ (P ∨ R ∨ ¬Q) ∧ (P ∨ ¬Q ∨ R) ∧ (P ∨ ¬Q ∨ ¬R)
∧ (¬P ∨ Q ∨ R) ∧ (¬P ∨ Q ∨ ¬R)
⇔ (P ∨ Q ∨ R) ∧ (P ∨ ¬Q ∨ R) ∧ (P ∨ ¬Q ∨ ¬R) ∧ (¬P ∨ Q ∨ R) ∧ (¬P ∨ Q ∨ ¬R)
which is required principal conjunctive normal form.
Note: If the principal disjunctive (conjunctive) normal form of a given formula A containing n
variables is known, then the principal disjunctive (conjunctive) normal form of ¬A will consist of
the disjunction (conjunction) of the remaining minterms (maxterms) which do not appear in the
principal disjunctive (conjunctive) normal form of A. From A ⇔ ¬¬A one can obtain the principal
conjunctive (disjunctive) normal form of A by repeated applications of De Morgan‘s laws to the
principal disjunctive (conjunctive) normal form of ¬A.
Definition: If a conclusion is derived from a set of premises by using the accepted rules of
reasoning, then such a process of derivation is called a deduction or a formal proof and the argument
is called a valid argument or conclusion is called a valid conclusion.
Definition: Let A and B be two statement formulas. We say that ‖B logically follows from A‖ or
‖B is a valid conclusion (consequence) of the premise A‖ iff A → B is a tautology, that is A ⇒ B.
We say that from a set of premises {H1, H2, · · · , Hm}, a conclusion C follows logically iff
H1 ∧ H2 ∧ ... ∧ Hm ⇒ C
(1)
Let P1, P2, · · · , Pn be all the atomic variables appearing in the premises H1, H2, · · · , Hm and
in the conclusion C. If all possible combinations of truth values are assigned to P1, P2, · · · , Pn and if
the truth values of H1, H2, ..., Hm and C are entered in a table. We look for the rows in which all H1,
H2, · · · , Hm have the value T. If, for every such row, C also has the value T, then (1) holds. That is,
the conclusion follows logically.
Alternatively, we look for the rows on which C has the value F. If, in every such row, at
least one of the values of H1, H2, · · · , Hm is F, then (1) also holds. We call such a method a
‗truth table technique‘ for the determination of the validity of a conclusion.
Example: Determine whether the conclusion C follows logically from the premises
H1 and H2.
(a) H1 : P → Q H2 : P C : Q
(b) H1 : P → Q H2 : ¬P C : Q
(c) H1 : P → Q H2 : ¬(P ∧ Q) C : ¬P
(d) H1 : ¬P H2 : P Q C : ¬(P ∧ Q)
(e) H1 : P → Q H2 : Q C : P
Solution: We first construct the appropriate truth table, as shown in table.
P Q P→Q ¬P ¬(P ∧ Q) P Q
T T T F F T
T F F F T F
F T T T T F
F F T T T T
In (b) the third and fourth rows, the conclusion Q is true only in the third row, but not in the
fourth, and hence the conclusion is not valid.
Similarly, we can show that the conclusions are valid in (c) and (d) but not in (e).
Rules of Inference
The following are two important rules of inferences.
Implication Formulas
I1 : P ∧ Q ⇒ P (simplification)
I2 : P ∧ Q ⇒ Q
I3 : P ⇒ P ∨ Q
I4 : Q ⇒ P ∨ Q
I5 : ¬P ⇒ P → Q
I6 : Q ⇒ P → Q
I7 : ¬(P → Q) ⇒ P
I8 : ¬(P → Q) ⇒ ¬Q
I9 : P, Q ⇒ P ∧ Q
I :
10 ¬P, P ∨ Q ⇒ Q (disjunctive syllogism)
I
11 : P, P → Q ⇒ Q (modus ponens)
I
12 : ¬Q, P → Q ⇒ ¬P (modus tollens)
I
13 : P → Q, Q → R ⇒ P → R (hypothetical syllogism)
I
: P ∨ Q, P → R, Q → R ⇒ R
14 (dilemma)
Example: Demonstrate that R is a valid inference from the premises P → Q, Q → R, and P .
Solution:
{1} (1) P → Q Rule P
{2} (2) P Rule P,
{1, 2} (3) Q Rule T, (1), (2), and I13
{4} (4) Q → R Rule P
{1, 2, 4} (5) R Rule T, (3), (4), and I13
Hence the result.
Solution:
Q → R, P → M, and ¬M.
Solution:
‖If you work hard, you will pass the exam. You did not pass. Therefore, you did not work
hard‖.
‖If Sachin hits a century, then he gets a free car. Sachin does not get a free car.
Let P denote the conjunction of the set of premises and let R be any formula. The above
equivalence states that if R is included as an additional premise and S is derived from P ∧ R, then
R → S can be derived from the premises P alone.
Rule CP is also called the deduction theorem and is generally used if the conclu-sion of the form
R → S. In such cases, R is taken as an additional premise and S is derived from the given
premises and R.
Example: Show that R → S can be derived from the premises P → (Q → S), ¬R ∨ P , and Q.
(Nov. 2011)
Example: By using the method of derivation, show that following statements con-stitute a valid
argument: ‖If A works hard, then either B or C will enjoy. If B enjoys, then A will not work hard.
If D enjoys, then C will not. Therefore, if A works hard, D will not enjoy.
Example: Determine the validity of the following arguments using propositional logic:
‖Smoking is healthy. If smoking is healthy, then cigarettes are prescribed by physi-
cians. Therefore, cigarettes are prescribed by physicians‖. (May-2012)
Solution: Let us indicate the statements as follows:
P : Smoking is healthy.
Q: Cigarettes are prescribed by physicians.
Consistency of Premises
A set of formulas H1, H2, · · · , Hm is said to be consistent if their conjunction has the
truth value T for some assignment of the truth values to the atomic variables appearing in H1, H2,
· · · , Hm.
If, for every assignment of the truth values to the atomic variables, at least one of the
formulas H1, H2, · · · , Hm is false, so that their conjunction is identically false, then the formulas
H1, H2, · · · , Hm are called inconsistent.
Alternatively, a set of formulas H1, H2, · · · , Hm is inconsistent if their conjunction implies a
contradiction, that is,
H1 ∧ H2 ∧ · · · ∧ Hm ⇒ R ∧ ¬R
where R is any formula.
Thus, the given set of premises leads to a contradiction and hence it is inconsistent.