0% found this document useful (0 votes)
15 views49 pages

Lec 03 Truth Table

Lecture 3 of CS228 covers semantics and truth tables in propositional logic, defining key concepts such as models, satisfaction relations, and the decidability of the satisfiability problem. It discusses the truth values, logical connectives, and provides examples of truth tables to illustrate the equivalence of logical formulas. The lecture concludes with the introduction of truth functions and their application in determining the validity of logical expressions.

Uploaded by

itachiisgenius
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views49 pages

Lec 03 Truth Table

Lecture 3 of CS228 covers semantics and truth tables in propositional logic, defining key concepts such as models, satisfaction relations, and the decidability of the satisfiability problem. It discusses the truth values, logical connectives, and provides examples of truth tables to illustrate the equivalence of logical formulas. The lecture concludes with the introduction of truth functions and their application in determining the validity of logical expressions.

Uploaded by

itachiisgenius
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

CS228 Logic for Computer Science 2021

Lecture 3: Semantics and truth tables

Instructor: Ashutosh Gupta

IITB, India

Compile date: 2021-01-12

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 1
Topic 3.1

Semantics - meaning of the formulas

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 2
Truth values

We denote the set of truth values as B , {0, 1}.

0 and 1 are only distinct objects without any intuitive meaning.

We may view 0 as false and 1 as true, but it is only our emotional response to the symbols.

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 3
Model

Definition 3.1
A model is an element of Vars → B.

Example 3.1
{p1 7→ 1, p2 7→ 0, p3 7→ 0, . . . } is a model

Since Vars is countable, the set of models is non-empty and infinite.

A model m may or may not satisfy a formula F .


The satisfaction relation is usually denoted by m |= F in infix notation.

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 4
Propositional Logic Semantics
Definition 3.2
The satisfaction relation |= between models and formulas is the smallest relation that satisfies
the following conditions.
I m |= >
I m |= p if m(p) = 1
I m |= ¬F if m 6|= F
I m |= F1 ∨ F2 if m |= F1 or m |= F2
I m |= F1 ∧ F2 if m |= F1 and m |= F2
I m |= F1 ⊕ F2 if m |= F1 or m |= F2 , but not both
I m |= F1 ⇒ F2 if if m |= F1 then m |= F2
I m |= F1 ⇔ F2 if m |= F1 iff m |= F2

Exercise 3.1
Why ⊥ is not explicitly mentioned in the above definition?
cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 5
Example: satisfaction relation

Example 3.2
Consider model m = {p1 7→ 1, p2 7→ 0, p3 7→ 0, . . . } and formula (p1 ⇒ (¬p2 ⇔ (p1 ∧ p3 )))

m 6|=(p1 ⇒ (¬p2 ⇔ (p1 ∧ p3 )))

m |= p1 m 6|= (¬p2 ⇔ (p1 ∧ p3 ))

m |=¬p2 m 6|=(p1 ∧ p3 )

m 6|= p2 m |= p1 m 6|= p3

Exercise 3.2
Formally, write the satisfiability checking procedure .

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 6
Satisfiable, valid, unsatisfiable

We say
I m satisfies F if m |= F ,
I F is satisfiable if there is a model m such that m |= F ,
I F is valid (written |= F ) if for each model m m |= F , and
I F is unsatisfiable (written 6|= F ) if there is no model m such that m |= F .

Exercise 3.3
If F is sat then ¬F is .
If F is valid then ¬F is .
If F is unsat then ¬F is .

A valid formula is also called a tautology.

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 7
Overloading |= : set of models
We extend the usage of |= in the following natural ways.

Definition 3.3
Let M be a (possibly infinite) set of models. M |= F if for each m ∈ M, m |= F .

Example 3.3
{{p → 1, q → 1}, {p → 1, q → 0}} |= p ∨ q

Exercise 3.4
Which of the following hold?
I {{p → 1, q → 1}, {p → 0, q → 0}} |= p
I {{p → 1, q → 1}} |= p ∧ q
I {{pi → (k = i)|i ∈ N}|k ∈ N} |= p1

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 8
Overloading |= : set of formulas
Definition 3.4
Let Σ be a (possibly infinite) set of formulas.
Σ |= F if for each model m that satisfies each formula in Σ, m |= F .

I Σ |= F is read Σ implies F .
I If {G } |= F then we may write G |= F .

Example 3.4 Exercise 3.5


{p, q} |= p ∨ q Which of the following hold?
I {p, q} |= p ∧ q
I {p ⇒ q, q ⇒ p} |= p ⇔ q
I {p ⇒ q, q} |= p ⊕ q
I {p ⇒ q, ¬q, p} |= p ⊕ q
cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 9
Equivalent

Definition 3.5
Let F ≡ G if for each model m

m |= F iff m |= G .

Example 3.5
(p ∨ q) ∨ r ≡ p ∨ (q ∨ r )

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 10
Equisatisfiable and Equivalid

Definition 3.6
Formulas F and G are equisatisfiable if

F is sat iff G is sat.

Definition 3.7
Formulas F and G are equivalid if
|= F iff |= G .

Commentary: The concept of equisatisfiable is used in formula transformations. We often say that after a transformation the formula remained equisatisfiable. Equivalid
is the dual concept, rarely used in practice.
cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 11
Topic 3.2

Decidability of SAT

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 12
Notation alert: decidable

A problem is decidable if there is an


algorithm to solve the problem.

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 13
Propositional satisfiability problem
The following problem is called the satisfiability problem

For a given F ∈ P, is F satisfiable?


Theorem 3.1
The propositional satisfiability problem is decidable.

Proof.
Let n = |Vars(F )|.
We need to enumerate 2n elements of Vars(F ) → B.

If any of the models satisfy the formula, then F is sat. Otherwise, F is unsat.

Exercise 3.6
Give a procedure to decide the validity of a formula.
cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 14
Complexity of the decidability question?

I If we enumerate all models to check satisfiability, the cost is exponential

I We do not know if we can do better.

I However, there are several tricks that have made satisfiability checking practical for the
real-world formulas.

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 15
Topic 3.3

Truth tables

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 16
Truth tables

Truth tables was the first method to decide propositional logic.

The method is usually presented in slightly different notation. We need to assign a truth value to
every formula.

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 17
Truth function

A model m is in Vars → B.

We can extend m to P → B in the following way.


(
1 m |= F
m(F ) =
0 otherwise.

The extended m is called truth function.

Since truth functions are natural extensions of models, we did not introduce new symbols.

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 18
Truth functions for logical connectives

Let F and G be logical formulas, and m be a model.


Due to the semantics of the propositional logic, the following holds for the truth functions.

m(F ) m(¬F )
0 1
1 0

m(F ) m(G ) m(F ∧ G ) m(F ∨ G ) m(F ⊕ G ) m(F ⇒ G ) m(F ⇔ G )


0 0 0 0 0 1 1
0 1 0 1 1 1 0
1 0 0 1 1 0 0
1 1 1 1 0 1 1

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 19
Truth table
For a formula F , a truth table consists of 2|Vars(F )| rows. Each row considers one of the models
and computes the truth value of F for each of them.
Example 3.6
Consider (p1 ⇒ (¬p2 ⇔ (p1 ∧ p3 ))). We will not write m(.) in the top row for brevity.

p1 p2 p3 (p1 ⇒ ( ¬ p2 ⇔ ( p1 ∧ p3 )))
0 0 0 0 1 1 0 0 0 0 0
0 0 1 0 1 1 0 0 0 0 1
0 1 0 0 1 0 1 1 0 0 0
0 1 1 0 1 0 1 1 0 0 1
1 0 0 1 0 1 0 0 1 0 0
1 0 1 1 1 1 0 1 1 1 1
1 1 0 1 1 0 1 1 1 0 0
1 1 1 1 0 0 1 0 1 1 1
The column under the leading connective has 1s therefore the formula is sat. But, there are some
0s in the column CS228
cbna
therefore the formula is not valid. Instructor: Ashutosh Gupta
Logic for Computer Science 2021 IITB, India 20
Example : DeMorgan law

Example 3.7
Let us show p ∨ q ≡ ¬(¬p ∧ ¬q).

p q (p ∨ q) ¬ (¬ p ∧ ¬ q)
0 0 0 0 1 0 1 1 0
0 1 1 1 1 0 0 0 1
1 0 1 1 0 1 0 1 0
1 1 1 1 0 1 0 0 1

Since the truth values of both the formulas are same in each row, the formulas are equivalent.

Exercise 3.7
Show p ∧ q ≡ ¬(¬p ∨ ¬q) using a truth table
Commentary: p ∧ q ≡ ¬(¬p ∨ ¬q) and p ∨ q ≡ ¬(¬p ∧ ¬q) are called DeMorgan law.
cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 21
Example : definition of ⇒

Example 3.8
Let us show p ⇒ q ≡ (¬p ∨ q).

p q (p ⇒ q) (¬ p ∨ q)
0 0 1 1 0 1 0
0 1 1 1 0 1 1
1 0 0 0 1 0 0
1 1 1 0 1 1 1

Since the truth values of both the formulas are same in each row, the formulas are equivalent.

It appears that ⇒ is a redundant symbol. We can write it in terms of the other symbols.

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 22
Example : definition of ⇔

Example 3.9
Let us show p ⇔ q ≡ (p ⇒ q) ∧ (q ⇒ p).

p q (p ⇔ q) (p ⇒ q) ∧ (q ⇒ p)
0 0 1 0 1 0 1 0 1 0
0 1 0 0 1 1 0 1 0 0
1 0 0 1 0 0 0 0 1 1
1 1 1 1 1 1 1 1 1 1

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 23
Example: definition ⊕

Example 3.10
Let us show (p ⊕ q) ≡ (¬p ∧ q) ∨ (p ∧ ¬q) using truth table.

p q (p ⊕ q) (¬ p ∧ q) ∨ (p ∧ ¬ q)
0 0 0 1 0 0 0 0 0 0 1 0
0 1 1 1 0 1 1 1 0 0 0 1
1 0 1 0 1 0 0 1 1 1 1 0
1 1 0 0 1 0 1 0 1 0 0 1

Exercise 3.8
Show (p ⊕ q) ≡ (¬p ∨ ¬q) ∧ (p ∨ q)

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 24
Example: associativity

Example 3.11
Let us show (p ∧ q) ∧ r ≡ p ∧ (q ∧ r )

p q r (p ∧ q) ∧ r p ∧ (q ∧ r)
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 1 0 0 0 0 1
0 1 0 0 0 1 0 0 0 0 1 0 0
0 1 1 0 0 1 0 1 0 0 1 1 1
1 0 0 1 0 0 0 0 1 0 0 0 0
1 0 1 1 0 0 0 1 1 0 0 0 1
1 1 0 1 1 1 0 0 1 0 1 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 25
Exercise: associativity

Exercise 3.9
Prove/disprove using truth tables
I (p ∨ q) ∨ r ≡ p ∨ (q ∨ r )
I (p ⊕ q) ⊕ r ≡ p ⊕ (q ⊕ r )
I (p ⇔ q) ⇔ r ≡ p ⇔ (q ⇔ r )
I (p ⇒ q) ⇒ r ≡ p ⇒ (q ⇒ r )

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 26
Exercise: distributivity

Exercise 3.10
Prove/disprove using truth tables prove that ∧ distributes over ∨ and vice-versa.
I p ∨ (q ∧ r ) ≡ (p ∨ q) ∧ (p ∨ r )
I p ∧ (q ∨ r ) ≡ (p ∧ q) ∨ (p ∧ r )

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 27
Tedious truth tables

I We need to write 2n rows even if a simple observation about the formula prove
(un)satisfiability.

For example,
I (a ∨ (c ∧ a)) is sat (why? - no negation)
I (a ∨ (c ∧ a)) ∧ ¬(a ∨ (c ∧ a)) is unsat (why?- contradiction at top level)

I We should be able to take such shortcuts?

We will see methods that will allow us to


take such shortcuts. But not now!

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 28
Topic 3.4

Expressive power of propositional logic

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 29
Boolean functions

A finite boolean function is in B n → B.

A formula F with Vars(F ) = {p1 , . . . , pn } can be viewed as a Boolean function f that is defined
as follows.
for each model m, f (m(p1 ), . . . , m(pn )) = m(F )
We say F represents f .

Example 3.12
Formula p1 ∨ p2 represents the following function

f = {(0, 0) → 0, (0, 1) → 1, (1, 0) → 1, (1, 1) → 1}

A Boolean function is another way of writing truth table.

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 30
Expressive power
Theorem 3.2
For each finite boolean function f , there is a formula F that represents f .

Proof.
Let f : B n → B. We construct a formula F to represent f .

Let pi0 , ¬pi and pi1 , pi .


(
n (p1b1 ∧ · · · ∧ pnbn ) if f (b1 , . . . , bn ) = 1
For (b1 , . . . , bn ) ∈ B , let F(b1 ,...,bn ) ,
⊥ otherwise.

F , F(0,...,0) ∨ · · · ∨ F(1,...,1)
| {z } We used only three logical
All Boolean combinations connectives to construct F
Exercise 3.11
Workout if F really represents f .
cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 31
Insufficient expressive power

If we do not have sufficiently many logical connectives, we cannot represent all Boolean functions.

Example 3.13
∧ alone can not express all boolean functions.

To prove this we show that Boolean function f = {0 → 1, 1 → 1} can not be achieved by any
combination of ∧s.

We setup induction over the sizes of formulas consisting a variable p and ∧.

Commentary: We are assuming that only one variable occurs in the formula, since there is exactly one input to f . Our definition of “represents” requires the number of
variables must match the arity of the function.
cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 32
Insufficient expressive power II

base case:
Only choice is p.(why?) For p = 0, the function does not match.

induction step:
Let us assume that formulas F and G of size less than n − 1 do not represent f .
We can construct a longer formula in the following way.

(F ∧ G )

The formula does not represent f , because we can always pick(why?) a model when F or G
produces 0.

Therefore ∧ alone is not expressive enough.

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 33
Minimal logical connectives
We used
I 2 0-ary,
I 1 unary, and
I 5 binary
connectives to describe the propositional logic.

However, it is not the minimal set needed for the maximum expressivity.
Example 3.14
¬ and ∨ can define the whole propositional logic.
I > ≡ p ∨ ¬p for some p ∈ Vars I (p ⊕ q) ≡ (p ∧ ¬q) ∨ (¬p ∧ q)
I ⊥ ≡ ¬> I (p ⇒ q) ≡ (¬p ∨ q)
I (p ∧ q) ≡ ¬(¬p ∨ ¬q) I (p ⇔ q) ≡ (p ⇒ q) ∧ (q ⇒ p)

Exercise 3.12
a. Show ¬ and ∧ can define all the other connectives b. Show ⊕ alone can not define ¬
cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 34
Topic 3.5

Problems

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 35
Semantics

Exercise 3.13
Show F (⊥/p) ∧ F (>/p) |= F |= F (⊥/p) ∨ F (>/p).

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 36
Truth tables

Exercise 3.14
Prove/disprove validity of the following formulas using truth tables.
1. (p ⇒ (q ⇒ r )) ⇔ ((p ∧ q) ⇒ r ))
2. p ∧ (q ⊕ r ) ⇔ (p ∧ q) ⊕ (q ∧ r )
3. (p ∨ q) ∧ (¬q ∨ r ) ⇔ (p ∨ r )
4. ⊥ ⇒ F for any F

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 37
Expressive power

Exercise 3.15
Show ¬ and ⊕ is not as expressive as propositional logic.

Exercise 3.16
Prove/disprove that the following subsets of connectives are fully expressive.
I ∨, ⊕
I ⊥, ⊕
I ⇒, ⊕
I ∨, ∧
I ⇒, ⊥

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 38
Expressive power(2)

Exercise 3.17
Prove/disprove: if-then-else is fully expressive

Exercise 3.18
Show ⇒ alone can not express all the Boolean functions

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 39
All minimal combinations*

Exercise 3.19
List all minimal subsets of the logical connectives that are fully expressive.

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 40
Encode boolean functions***

Exercise 3.20
Find smallest formulas that encode the following functions over n inputs
I Encode parity function
I Encode majority function

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 41
|= vs. ⇒

Exercise 3.21
Using truth table prove the following
I F |= G if and only if |= (F ⇒ G ).
I F ≡ G if and only if |= (F ⇔ G ).

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 42
Exercise: downward saturation
Exercise 3.22
Let us suppose we only have connectives ∧, ∨, or ¬ in our formulas. Consider a set Σ of
formulas such that
1. for each p ∈ Vars, p 6∈ Σ or ¬p 6∈ Σ
2. if ¬¬F ∈ Σ then F ∈ Σ
3. if (F ∧ G ) ∈ Σ then F ∈ Σ and G ∈ Σ
4. if ¬(F ∨ G ) ∈ Σ then ¬F ∈ Σ and ¬G ∈ Σ
5. if (F ∨ G ) ∈ Σ then F ∈ Σ or G ∈ Σ
6. if ¬(F ∧ G ) ∈ Σ then ¬F ∈ Σ or ¬G ∈ Σ
Show that Σ is satisfiable, i.e., there is a model that satisfies every formula in Σ.

Exercise 3.23
Given algorithm that extends a set Σ into a set of the formula that satisfy the above. Can we use
the algorithm as a satisfiability checker?
Commentary: Please note that the above does not hold if we drop any of the six conditions. You need to show that all six are needed.
cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 43
Exercise: counting models

Exercise 3.24
Let propositional variables p, q, are r be relevant to us. There are eight possible models to the
variables. Out of the eight, how many satisfy the following formulas?
1. p
2. p ∨ q
3. p ∨ q ∨ r
4. p ∨ ¬p ∨ r

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 44
Exercise: universal connective

Let ∧ be a binary connective with the following truth table

m(F ) m(G ) m(F ∧G )


0 0 1
0 1 1
1 0 1
1 1 0

Exercise 3.25
a. Show ∧ can define all other connectives
b. Are there other universal connectives?

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 45
Topic 3.6

Extra slides: sizes of models

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 46
Size of models

A model must assign value to all the variable, since it is a complete function.

However, we may not want to handle such an object.

In practice, we handle partial models. Often, without explicitly mentioning this.

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 47
Partial models

Let m|Vars(F ) : Vars(F ) → B and for each p ∈ Vars(F ), m|Vars(F ) (p) = m(p)

Theorem 3.3
If m|Vars(F ) = m0 |Vars(F ) then m |= F iff m0 |= F

Proof sketch.
The procedure to check m |= F only looks at the Vars(F ) part of m. Therefore, any extension of
m|Vars(F ) will have same result either m |= F or m 6|= F .

Definition 3.8
We will call elements of Vars ,→ B as partial models.

Exercise 3.26
Write the above proof formally.

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 48
End of Lecture 3

cbna CS228 Logic for Computer Science 2021 Instructor: Ashutosh Gupta IITB, India 49

You might also like