0% found this document useful (0 votes)
3 views32 pages

Lecture TWO LOGIC

This lecture covers the fundamentals of logic, focusing on logical propositions, logical equivalence, reasoning, and predicates with quantifiers. It explains propositional logic, including conjunctions, disjunctions, and negations, along with their truth tables and applications in programming. Additionally, it addresses conditional propositions, necessary and sufficient conditions, and the roles of quantifiers and predicates in logical statements.

Uploaded by

ombeni emmanuel
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)
3 views32 pages

Lecture TWO LOGIC

This lecture covers the fundamentals of logic, focusing on logical propositions, logical equivalence, reasoning, and predicates with quantifiers. It explains propositional logic, including conjunctions, disjunctions, and negations, along with their truth tables and applications in programming. Additionally, it addresses conditional propositions, necessary and sufficient conditions, and the roles of quantifiers and predicates in logical statements.

Uploaded by

ombeni emmanuel
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/ 32

Lecture two: Logic

Mr. Michael Peter

The Open University of Tanzania


Faculty of Science, Technology and Environmental studies

Mr. Michael Peter Logic 1 / 32


Introduction

In this lecture we will talk about logic, this is because it is an important


aspect in ICT and data management.

The following are the parts which will be covered:-logical


propositions,logical equivalence, Logical reasoning, and predicates and
quantifiers

Definition
Logic is the formal reasoning study which is mainly on statements or
proposition. It acts as a collections of rules which govern structure and
presentation of a mathematical proof.

Mr. Michael Peter Logic 2 / 32


Propositional logic

Definition
It is simply defined as a sentence (declarative statement) which is either
true or false but not both. The following are examples of a propositional
logic
Earth is the only planet in the universe that contain life
Discrete mathematics is among of the courses offered to ICT and
data management students.
While the following is not an example of propositional logic,

x +4=6 (1)

because we do not know the value of x

Restating this sentence as:-


If x = 2, then x + 4 = 6 becomes a propositional logic.
Mr. Michael Peter Logic 3 / 32
Propositional logic cont· · ·

Note
A propositional logic is typically expressed as a declarative sentence.They
are the building block of any logical theory.

In this course we will use variables such as p, q and r to represent


propositions. Also, the notation such as p : 1 + 1 = 0 is used to define p
as the proposition 1 + 1 = 0

Connectives AND/OR
These are word or symbols used to connect sentence in grammatically
acceptable way. In other words, these are boolean statement which are
used to join propositions and obtain a single proposition.

Mr. Michael Peter Logic 4 / 32


Propositional logic cont· · ·

Conjunctions
Let p and q be two propositions. The conjunction of p and q, denoted
p ∧ q is the proposition p and q.

Disjunction
Let p and q be two propositions. The disjunction of p or q, denoted p ∨ q
is the proposition p or q.

Example, If p and q are two proposition defined as;-

p : it is raining, q : it is cold. (2)

Then the conjuction p and q is

p ∧ q : it is raining and it is cold (3)

Mr. Michael Peter Logic 5 / 32


Propositional logic cont· · ·

Also the disjuction of p and q is

p ∨ q : it is raining or it is cold. (4)

The truth table


The truth value of both conjunction and disjunction can be determined by
the truth table.

Mr. Michael Peter Logic 6 / 32


Propositional logic cont· · ·

Suppose p and q, then the proposition p ∧ q is defined by the following


truth table

p q p∧q
T T T
T F F
F T F
F F F

Mr. Michael Peter Logic 7 / 32


Propositional logic cont· · ·

p ∧ q is true provided that p and q are true. That is


(
T : provided p and q are both true
p∧q = (5)
F : otherwise

Most programming language define and exactly as in the definition


above.For example in Python programming language the logical AND is
denoted as and, the expression

x < 10 and y > 4 , is true (6)

when the variable x is less than 10 and the variable y is greater than 4 is
true. Otherwise is false.

Mr. Michael Peter Logic 8 / 32


Propositional logic cont· · ·
Inclusive-or

Definition
Suppose p and q are propositions, then the new proposition p ∨ q is
defined by the following truth table

p q p∨q
T T T
T F T
F T T
F F F
Mr. Michael Peter Logic 9 / 32
Propositional logic cont· · ·

Note
The inclusive-or of propositions p and q is true if p or q is true and false
otherwise. That is

(
T : provided p or q or both is true
p∨q = (7)
F : otherwise

Most programming language define or exactly as in the definition above.


For example in Python programming language the logical OR is denoted as
or, the expression

x < 10 or y > 4 , is true (8)

when the variable x is less than 10 is true or the variable y is greater than
4 is true or both. Otherwise is false.
Mr. Michael Peter Logic 10 / 32
Propositional logic cont· · ·

Negation
The negation of p is denoted ¬p, means (not p). Truth value of the
proposition ¬p is defined by the truth table

p ¬p
T F
F T
Mr. Michael Peter Logic 11 / 32
Propositional logic cont· · ·

In Python or Java programming language not is denoted by !, and the


expression

! (x < 10) (9)

is true when the variable not x ≤ 10.


In expressions involving some or all of the operators ¬, ∧, ∨ in the absence
of parentheses, we first evaluate ¬, then ∧, and then ∨ . This convention
is called operator precedence.

Question. Given that the proposition p is false, proposition q is true, and


proposition r is false, Determine whether the proposition

p∨q∧r (10)

is true or false.
Mr. Michael Peter Logic 12 / 32
Propositional logic cont· · ·

Example.Searching the Web


A variety of web-search engines are available (G oog le, K iddle, Y ahoo) ,
which allows the user to enter keywords that the search engine then tries
to match with web pages. For example in Google entering the word
computer produce a huge list of pages which contains the word computer .

Mr. Michael Peter Logic 13 / 32


Conditional propositional and logic equivalence

Definition
If p and q are propositions, the proposition

if p then q (11)

is called a a conditional proposition and is denoted as

p =⇒ q. (12)

The proposition p is called hypothesis (or antecedent) and q is called the


conclusion (or consequent)

Mr. Michael Peter Logic 14 / 32


Conditional propositional and logic equivalence cont· · ·

The truth table of the conditional proposition p =⇒ q is defined as


follows

p q (p =⇒ q)
T T T
T F F
F T T
F F T

In the expressions that involve the logical operators ∨, ∧, ¬, and =⇒ , the


conditional operator =⇒ is evaluated last.

Mr. Michael Peter Logic 15 / 32


Conditional propositional and logic equivalence cont· · ·

For example:

p ∨ q =⇒ ¬r (13)

is interpreted as

(p ∨ q) =⇒ (¬r ) (14)

Assuming that p is true, q is false, and r true, find the truth value of each
propositions

p ∧ q =⇒ r (15)
p ∨ q =⇒ ¬r (16)
p ∧ (q =⇒ r ) (17)
p =⇒ (q =⇒ r ) (18)

Mr. Michael Peter Logic 16 / 32


Necessary and Sufficient
Necessary condition
This is a condition which is necessary for a particular outcome to be
achieved.

Sufficient condition
This is the condition that sufficies to guarantee a particular outcome.

Example

Mr. Michael Peter Logic 17 / 32


Converse, inverse, contrapositive (transposition)

Given the proposition p =⇒ q, then


the converse of it, is q =⇒ p.
the inverse of it, is ¬p =⇒ ¬q.
the contrapositive of it, is ¬q =⇒ ¬p.
This can be concluded that, the contrapositive is the inverse of the
converse.

Another useful proposition is

p if and only if q (19)

is called the bi-conditional proposition and is denoted by

p ⇐⇒ q (20)

Mr. Michael Peter Logic 18 / 32


Converse, inverse, contrapositive (transposition) cont· · ·

The following is the truth table for the bi-conditional statement

p q (p ⇐⇒ q)
T T T
T F F
F T F
F F T
Note.

p ⇐⇒ q = (p =⇒ q) ∧ (q =⇒ p) (21)

Mr. Michael Peter Logic 19 / 32


Logical equivalent

Two propositions p and q are said to be equivalent is and only if they have
the same truth value. For example

p =⇒ q ≡ ¬p ∨ q (22)

De Morgan’s laws for logic


Given two propositions p and q, then

¬ (p ∨ q) ≡ ¬p ∧ ¬q (23)
¬ (p ∧ q) ≡ ¬p ∨ ¬q (24)

Show that, in Python, the expressions

x < 10 or x > 20, and ! (x ≥ 10 and x ≤ 20) , are equivalent. (25)


Mr. Michael Peter Logic 20 / 32
Logical equivalent · · ·

Show that proposition p =⇒ q and its contrapostive ¬q =⇒ ¬p are


logically equivalent.

Exercise

Mr. Michael Peter Logic 21 / 32


Arguments and rules of inference

Deductive reasoning
This is the process of drawing conclusion from a sequence of propositions.
For example:-

The given propositions, such as XXX are called hypothesis or premises and
the propositions that follows from the hypothesis is called conclusion.

This can be concluded that, a deductive reasoning normally consists of


hypothesis together with conclusion.

Any argument has the form

If p1 and p1 and · · · and pn , then q (26)

Mr. Michael Peter Logic 22 / 32


Arguments and rules of inference cont · · ·

An argument is a sequence of propositions written

p1 , p2 , · · · , pn therefore q (27)

The argument is valid provided that if p1 and p1 and · · · and pn , are all
true then q must be true; otherwise the argument is invalid or fallacy.

Example. Determine whether the argument below is valid or not

p =⇒ q
p
q

The argument in example above is used extensively and is known as the


Modus ponens rules of inference.

Mr. Michael Peter Logic 23 / 32


Arguments and rules of inference cont · · ·
Several rues of inference for propositions which may be verified using truth
tables,

The following figure represent the rules of inference for propositions.

Mr. Michael Peter Logic 24 / 32


Quantifiers and Predicates

In the previous section of this lecture we have seen the roles of logic which
are incapable in describing most of the programming statements. For
example.

Consider the statement

p : n is an integer. (28)

p is not a proposition because whether p is true or false depends on the


value of n. For example: p is true if n = 13 and false if n = 8.

Therefore: Most of the statements in ICT use variables, we must extend


the system of logic to include such statements.

Mr. Michael Peter Logic 25 / 32


Quantifiers and Predicates cont· · ·

Definition
A predicate is a statement involving variables which are defined in a
particular domain. Sometimes is known as a propositional function.

Let p(x) be a statement involving variable x and let D be a set. P is


called a propositional function or predicate with respect to D if for each
x ∈ D, p(x) is a proposition.

D is called domain of discourse which specifies the allowable values of x.

Mr. Michael Peter Logic 26 / 32


Quantifiers and Predicates cont· · ·

Example The following are the propositional functions


n2 + 2n, is an odd integer, D ∈ Z+
x 2 − x − 6 = 0, D ∈ R

Universal quantifiers
Definition. Let P be a propositional function with domain of discourse D.
The statement

for exery x, P(x) is called a universal quntified statement (29)

The symbol ∀ means ”for every ”. Thus the statement for every x, P(x)
may be written as ∀ x P(x)

Mr. Michael Peter Logic 27 / 32


Quantifiers and Predicates cont· · ·

The statement ∀ x P(x) is true if P(x) is true for every x ∈ D.


The statement ∀ x P(x) is false if P(x) is false for at least on x ∈ D.

Example. Consider the universally quantified statement

∀x x 2 ≥ 0 ; x ∈ D = R

(30)

The statement is true because, for every real number x, it is true that the
square of x is positive or zero. Also is false if for at least one x in the
domain of discourse, the proposition P(x) is false.

Mr. Michael Peter Logic 28 / 32


Quantifiers and Predicates cont· · ·

A value x in the domain of discourse that makes P(x) false is called a


counterexample to the statement

∀ x P(x) (31)

Example. Suppose that P is a propositional function whose domain of


discourse is the set

{d1 , · · · , dn }. (32)

The following pseudo-code determine whether

∀ x P(x) (33)

is true or false

Mr. Michael Peter Logic 29 / 32


Quantifiers and Predicates cont· · ·

for i=1 to n
if (¬p(di ))
return false.
return true

The for loop examines the number di of the domain of discourse one by
one. If it finds the value di for which P(di ) is false, the condition ¬P(di )
in the if statement is true; So the code returns false and terminates. In
this case, di is a counterexample

Mr. Michael Peter Logic 30 / 32


Quantifiers and Predicates cont· · ·

Existential quantifiers
Definition. Let P be a propositional function with domain of discourse D.
The statement

there exists x, P(x) is said to be existentially quantified statement

The symbol ∃ means ”there exist”

Thus the statement there exists x, P(x) may be written as

∃ x P(x). (34)

Mr. Michael Peter Logic 31 / 32


Quantifiers and Predicates cont· · ·

The statement ∃ x P(x) is true if P(x) is true for at least one x in D. The
statement

∃x P(x) (35)

is true if P(x) is true for at least one x in D. The statement

∃x P(x) (36)

is false for every x ∈ D

Mr. Michael Peter Logic 32 / 32

You might also like