Unit 3 Basic Logic
Unit 3 Basic Logic
1: Propositional Logic
Logic
Ø Study of valid reasoning.
Ø Allows us to represent knowledge in precise, mathematical way.
Ø Allows us to make valid inferences using a set of precise rules.
Ø Many applications in CS:
Correctness of a program, automated testing and program analysis
etc.
Propositional Logic
Ø Simplest logic is propositional logic.
Ø Building blocks of propositional logic are propositions.
Ø A proposition is a statement that is either true or false.
Ø Examples:
1. UCS405 is a course in discrete mathematics in TIET :- True
2. Patiala is located in Haryana :- False
3. Pay attention, Attend all lectures :- Not a proposition
4. x + y>4 :- Not a proposition
5. Earth is the only planet that contains life. –T/F
Propositional Variables
ØEach proposition will be represented by a propositional variable.
Ø Propositional variables are usually represented as lower-case letters, such as p,
p1, p2, q, etc.
Ø Each variable can take one of two values: true or false.
ØWhat is truth value of “India hosted 2019 ICC Cricket World Cup”?
False
ØA truth table is a table showing the truth value of a propositional logic formula
as a function of its inputs.
Logical Connectives
Ø Three basic logical connectives:
1. Logical NOT: ¬p (not p)
Also called logical negation.
2. Logical AND: p ∧ q (p and q)
Also called logical conjunction.
3. Logical OR: p ∨ q (p or q)
Also called logical disjunction
Ø Propositions formed using logical connectives are called compound propositions
Truth Table
p q ¬p pᴧq p∨q
T T F T T
T F F F T
F T T F T
F F T F F
Example: Construct a truth table for (p ∨ q) ∨ (¬ r)
Summary
ØPropositional Logic
ØPropositional Variables
ØBasic Logical Connectives
ØTruth Table
Basic Logic
12
Example
ØConditional statement is “If it rained last night, then the sidewalk is
wet.”
ØThe converse of the conditional statement is
“If the sidewalk is wet, then it rained last night.”
ØThe contrapositive of the conditional statement is
“If the sidewalk is not wet, then it did not rain last night.”
ØThe inverse of the conditional statement is
“If it did not rain last night, then the sidewalk is not wet.”
Biconditional Statement
ØThe biconditional statement p ↔ q is the proposition “p if and only if q.”
ØThe biconditional statement p ↔ q is true when p and q have the same truth
values, and is false otherwise.
Ø Biconditional statements are also called bi-implications.
Truth Table
p q p→q p↔q
T T T T
T F F F
F T T F
F F T T
Ø Translation: b ᴧ c → a
Example 4
Ø Consider following propositional variables:
a: I will get up early this morning
b: There is a lunar eclipse this morning
c: There are no clouds in the sky this morning
d: I will see the lunar eclipse
ØConvert the following sentence in to propositional form:
“I won’t see the lunar eclipse if I don’t get up early this morning”
Translation: ¬a → ¬d
Example 5
Ø Consider following propositional variables:
a: I will get up early this morning
b: There is a lunar eclipse this morning
c: There are no clouds in the sky this morning
d: I will see the lunar eclipse
ØConvert the following sentence in to propositional form:
“If I get up early this morning, but it's cloudy outside, I won't see the lunar
eclipse.
Translation: a ∧ ¬c → ¬d
Example 6
Let us use the following propositions:
a: It is raining.
b: I will go to college.
c: The computers are broken.
d: I have a headache.
Expression English meaning
a∧d It is raining and I have a headache.
c → ¬b If the computers are broken then I will not go to college.
a ∨ d → ¬b If it is raining or I have a headache then I will not go to college.
Basic Logic
4:Propositional Equivalences
Tautology and Contradiction
ØSome propositions are interesting since their values in the truth table are
always the same
ØA compound proposition that is always true for all possible truth values of the
propositions is called a tautology.
ØA compound proposition that is always false is called a contradiction.
Ø A proposition that is neither a tautology nor contradiction is called a
contingency.
ØExample: p ∨ ¬p is a tautology
Example
Show that the statement (p Ú q) Ù [(¬p) Ù(¬q)] is contradiction
Logical equivalence
ØTwo propositions p and q are logically equivalent if their truth tables are the
same.
ØAlso, p and q are logically equivalent if p ↔ q is a tautology.
ØIf p and q are logically equivalent, we write p ≡ q.
Example
Look at the these two compound propositions: p → q and q ∨ ¬p
Example
ØProve ¬(p ∨ (¬p ∧ q)) ≡ ¬p ∧ ¬q
¬(p ∨ (¬p ∧ q)) ≡ ¬p ∧ ¬(¬p ∧ q) DeMorgan
≡ ¬p ∧ (p ∨ ¬q) DeMorgan
≡ (¬p ∧ p) ∨ (¬p ∧ ¬q) Distributivity
≡ F ∨ (¬p ∧ ¬q) Because ¬p ∧ p ≡ F
≡ ¬p ∧ ¬q Because F ∨r ≡ r for any r (Identity Law)
Example
Use the logical equivalences to show that ¬(p ∨ ¬(p ∧ q)) is a contradiction.
¬(p ∨ ¬(p ∧ q))
⇔ ¬p ∧ ¬(¬(p ∧ q)) De Morgan’s Law
⇔ ¬p ∧ (p ∧ q) Double Negation Law
⇔ (¬p ∧ p) ∧ q Associative Law
⇔F∧q Contradiction
⇔q∧F Commutative Law
⇔F Domination Law
Basic Logic
5:Normal Forms
Normal Forms
ØWe can convert any proposition in two normal forms −
1. Disjunctive normal form
2. Conjunctive normal form
Disjunctive normal form(DNF)/SOP
ØEvery compound proposition in the propositional variables p, q, r, ..., is
uniquely equivalent to a proposition that is formed by taking the disjunction of
conjunctions of some combination of that variables or their negations.
Ø This is called the disjunctive normal form of a proposition.
ØExample
(A∧B)∨(A∧C)∨(B∧C∧D)
ØThe individual conjunctions that make up the disjunctive normal form are
called minterms.
Method to construct DNF
ØConstruct a truth table for the proposition.
ØUse the rows of the truth table where the proposition is True to
construct minterms
ØIf the variable is true, use the propositional variable in the minterm
ØIf a variable is false, use the negation of the variable in the minterm
ØConnect the minterms with ∨’s(OR’s).
Example
Find the disjunctive normal form for the proposition p → q
7:Predicate Logic
Limitation of Propositional Logic
ØEvery COE student must study discrete mathematics
ØDeepak is a COE student
– So Deepak must study discrete mathematics
This idea can’t be expressed with propositional logic
ØWhat propositional logic allows to express:
Ø If Deepak is a COE student he must study discrete mathematics
Ø Deepak is a COE student
Ø So Deepak must study discrete mathematics
Predicate
ØA predicate is a statement that contains variables (predicate variables) and that
may be true or false depending on the values of these variables.
Example: P(x) = “x2 is greater than x” is a predicate
ØThe domain of a predicate variable is the collection of all possible values that
the variable may take.
e.g. the domain of x in P(x): integer
ØPredicate logic is an extension of Propositional logic.
ØIt adds the concept of predicates and quantifiers to better capture the meaning
of statements that cannot be adequately expressed by propositional logic.
Example
ØLet P(x, y) = “x > y”.
Domain: integers, i.e. both x and y are integers.
Ø P(4, 3) means “4 >3”, so P(4, 3) is TRUE;
ØP(1, 2) means “1>2” , so P(1, 2) is FALSE;
ØP(3,4) is false (in general, P(x, y) and P(y, x) not equal).
Quantifiers
Ø The variable of predicates is quantified by quantifiers.
Ø There are two types of quantifier in predicate logic −
1. Universal Quantifier
2. Existential Quantifier.
Universal Quantifiers
ØUniversal quantifier states that the statement within its scope is true for every
value of the specific variable.
Ø It is denoted by the symbol ∀.
Ø∀x P(x) is read as for every value of x, P(x) is true.
ØExample: Let P(x) denote x > x - 1.
What is the truth value of ∀x P(x) ?
Assume the universe of discourse of x is all real numbers.
Answer: Since every number x is greater than itself minus 1.
Therefore, ∀x P(x) is true
Existential quantifier
ØExistential quantifier states that the statement within its scope is true for some
values of the specific variable.
ØIt is denoted by the symbol ∃.
Ø∃x P(x) is read as for some values of x, P(x) is true.
ØExample Let T(x) denote x > 5 and x is from Real numbers.
Ø What is the truth value of ∃ x T(x)?
Ø Answer: Since 10 > 5 is true.
ØTherefore, it is true that ∃ x T(x).
Nested Quantification
ØA proposition can have multiple quantifier
– “All rabbits are faster than all tortoises.”
– Domains: R={rabbits}, T={tortoises}
– Predicate C(x, y): Rabbit x is faster than tortoise y
ØIn symbols
∀x ∈ R, ∀y ∈ T, C(x,y)
Ø In words
– For any rabbit x, and for any tortoise y, x is faster than y.
Truth Value of Quantified Statements
Statement When True When False
∀x ∈ D,P(x) P(x) is true for every x. There is one x for which
P(x) is false.
∃x ∈ D,P(x) There is at least one x for P(x) is false for every x.
which P(x) is true.
Negation of Quantification
ØNegation of a universal quantification becomes an existential quantification.
¬ (∀x ∈ D,P(x)) ≡ ∃x ∈ D, ¬P(x)
ØExample:
Not all students study hard ≡ There is at least one student who do not
study hard
ØNegation of an existential quantification becomes an universal quantification.
¬ (∃x ∈ D, P(x)) ≡ ∀x ∈ D, ¬ P(x)
ØExample:
It is not the case that some students in this class are from Jaipur≡ All
students in this class are not from Jaipur
Contd..
ج (∀x ∈ D,P(x) ∧ Q(x))
≡ ∃x ∈ D, ¬(P(x) ∧ Q(x)) (Negation of Quantification)
≡ ∃x ∈ D,( ¬P(x) ∨ ¬Q(x)) (DeMorgan Law)
ØExample: Not all students in this class are using Facebook and (also) Google+
There is some (at least one) student in this class who is not using
Facebook or not using Google+ (or may be using neither)
Summary of Session
ØPropositional Logic
ØLogical Connectives
ØTruth tables
ØLogical Equivalences
ØNormal Forms
ØPropositional inference rules
ØPredicate Logic