Documente Academic
Documente Profesional
Documente Cultură
Acknowledgement
The
Logic (S1.1)
Applications
Propositional
Equivalences (S1.3)
Part II:
Predicates
Nested
Rules
Quantifiers (S1.5)
of Inference (S1.6)
Introduction
to Proofs (S1.8)
Expressing
Queries
conditions in programs.
Definition of a Proposition
Definition: A proposition (denoted p, q, r, ) is
a
(F)
it is never both, neither, or somewhere in between!
Propositional Logic
Examples:
A proposition
Compound Propositions
Compound
NOT
Conjunction
AND
Disjunction
OR
Exclusive or
XOR
Implication
IMPLIES
Bi-conditional
IFF
An
Propositional
Truth Tables
A truth
p
T
F
ICS253 - 1The Foundations: Logic and Proofs61
p
F
T
Slide # 10
The Foundations : Logic and Proofs
pq
Slide # 11
The Foundations : Logic and Proofs
pq
Slide # 12
The Foundations : Logic and Proofs
pq
Slide # 13
The Foundations : Logic and Proofs
Slide # 14
The Foundations : Logic and Proofs
Slide # 15
The Foundations : Logic and Proofs
pq
The
Slide # 16
The Foundations : Logic and Proofs
Implication p q
Implication
If p then q
p is sufficient for q
a sufficient condition for q is p
q is necessary for p
a necessary condition for p is q
p only if q
If p, q
p implies q
q whenever p
q when p
q if p
q unless p
q follows from p
Slide # 17
The Foundations : Logic and Proofs
Implication p q
Discuss
Slide # 18
The Foundations : Logic and Proofs
q
If it is raining, then the home team wins
q p
is the Converse of p q
raining
p q is the Inverse of p q
If it is not raining, then the home team does not win
N.B. Only the contrapositive is equivalent to the original
statement.
ICS253 - 1The Foundations: Logic and Proofs61
Slide # 19
The Foundations : Logic and Proofs
pq
Slide # 20
The Foundations : Logic and Proofs
Slide # 21
The Foundations : Logic and Proofs
0001110001 1001001000
Slide # 22
The Foundations : Logic and Proofs
Slide # 23
The Foundations : Logic and Proofs
English Sentences
Specifications
Boolean
Searches
Logic
Puzzles
Logic
Circuits
Slide # 24
The Foundations : Logic and Proofs
a) p q
b) You get an A on the final, you do every exercise in this book, and you get an A in
b)p q
this class.
c) To get an A in this class, it is necessary for you to get an A on the final.
c) r p
d) You get an A on the final, but you dont do every exercise in this book;
nevertheless, you get an A in this class.
d)p q
e) Getting an A on the final and doing every exercise in this book is sufficient for
getting an A in this class.
e) (p q
f ) You will get an A in this class if and only if you either do every exercise in this
book or you get an A on the final.
ICS253 - 1The Foundations: Logic and Proofs61
r
f) r (q
Slide # 25
The Foundations : Logic and Proofs
(r s) q
Slide # 26
The Foundations : Logic and Proofs
Group Activity
System
Specifications
Or
Logic
Puzzles
Slide # 27
The Foundations : Logic and Proofs
System Specifications
System
(Q
5 pp 21).
Slide # 28
The Foundations : Logic and Proofs
(Q5 pp21).
1. The router can send packets to the edge
system (S) only if it supports the new
address space (N).
2. For the router to support the new
address space(N), it is necessary that
the latest software release be installed
(L).
1. SN
2. N L
3. L S
4. N
Slide # 29
The Foundations : Logic and Proofs
(Q5 pp21).
N true then N is F
1. SN
If N is F then S should be F for 1 to be true
2. N L
Since N is F then 2 is True, L could be T or F
3. L S
Since S is F then we take L to be F
Hence, Consistent
Slide # 30
The Foundations : Logic and Proofs
In [Sm78] Smullyan posed many puzzles about an island that has two
kinds of inhabitants, knights, who always tell the truth, and their
opposites, knaves, who always lie.
A says At least one of us is a knave and B says nothing.
and
P(x): x is a knave
Slide # 31
The Foundations : Logic and Proofs
Slide # 32
The Foundations : Logic and Proofs
Logic Circuits
Basic
An
Logic Gates
Slide # 33
The Foundations : Logic and Proofs
Q:
Slide # 34
The Foundations : Logic and Proofs
Slide # 35
The Foundations : Logic and Proofs
Slide # 36
The Foundations : Logic and Proofs
Example
pq (pq) p q p q
(pq)
p q
Slide # 37
The Foundations : Logic and Proofs
38
Identity
Laws
Domination
pF F
pp p
pp p
pq qp
Laws
Idempotent
Laws
Commutative
pq qp
(p) p
Laws
Associative
(pq)r p(qr)
Laws
(pq) pq
DeMorgan
(pq) pq
Laws
p(qr) (pq)(pr)
Distributive
p(qr) (pq)(pr)
Laws
p p T
p p F
(p q) (pq)
p (pq) p
ICS253 - 1The Foundations: Logic and Proofs61
Negation
Laws
Absorption
Laws
Slide # 40
The Foundations : Logic and Proofs
Slide # 41
The Foundations : Logic and Proofs
Slide # 42
The Foundations : Logic and Proofs
Slide # 43
The Foundations : Logic and Proofs
Examples
Show that
1.
(p(pq)) (p q)
2.
Slide # 44
The Foundations : Logic and Proofs
Examples
3. Show that
(pq) (pq) (p q)
(p q) (p q) [(p q) p] [(p q) q]
[(p p) (q p)] [(p q) (q q)]
[(T (q p)] [(p q) T]
(q p) (p q) (p q) (q p)
(pq)
(distribute and continue)
Slide # 45
The Foundations : Logic and Proofs
Slide # 46
The Foundations : Logic and Proofs
Slide # 47
The Foundations : Logic and Proofs
Predicates
P(x) x > 1
\\ P is called a propositional function
Q(x,y) x = y 5
R(x,y,z) z > x y
if P(x) then
x = x - 1;
else
x = x2;
end if;
Slide # 48
The Foundations : Logic and Proofs
Examples
Let
Slide # 49
The Foundations : Logic and Proofs
Quantifiers
Slide # 50
The Foundations : Logic and Proofs
Quantifiers
Slide # 51
The Foundations : Logic and Proofs
Quantifiers
Uniqueness
that
there exists a unique element x, in the
of x, such that P(x) is true,
domain
!x P(x) or 1x P(x)
P(x)
Slide # 52
The Foundations : Logic and Proofs
REMEMBER!
A predicate
Slide # 53
The Foundations : Logic and Proofs
Examples
Slide # 54
The Foundations : Logic and Proofs
Question 7 pp 50
P(x) x can speak Russian,Q(x) x knows
C++
For the universe of discourse all students at
your school
1.There is a student at your school who can 1. x (P(x) Q(x))
speak Russian and who knows C++
2.There is a student at your school who can 2. x (P(x) Q(x))
speak Russian but who doesnt know C++
3.Every student at your school either can
speak Russian or knows C++
3. x (P(x)Q(x))
4.No student at your school can speak
Russian or knows C++
4. !x (P(x) Q(x))
x (P(x)Q(x))
Slide # 55
The Foundations : Logic and Proofs
Truth of Quantifiers
Statement
When True?
When False?
x P(x)
x P(x)
Slide # 56
The Foundations : Logic and Proofs
Truth of Quantifiers
Statement
x P(x)
x P(x)
When True?
When False?
There is an x for
P(X) is true for
which P(x) is
every X
false
There is an x
P(X) is false for
for which P(x)
every X
is true
Slide # 57
The Foundations : Logic and Proofs
Operator
Precedence
Slide # 58
The Foundations : Logic and Proofs
Example
quantifiers and have higher precedence
than all logical operators from propositional
calculus.
The
It means
(x P(x)) Q(x)
Does not mean
x (P(x) Q(x))
Slide # 59
The Foundations : Logic and Proofs
Binding Variables
The
Slide # 60
The Foundations : Logic and Proofs
Slide # 61
The Foundations : Logic and Proofs
true.
If A is
Slide # 62
The Foundations : Logic and Proofs
Slide # 63
The Foundations : Logic and Proofs
Negation
x P(x) x P(x)
x P(x) x P(x)
x H(x)
2. x (x2 x)
x (x2 x)
Slide # 64
The Foundations : Logic and Proofs
Example Q 13 pp 51
Translate in two ways each of these statements into logical expressions
using predicates, quantifiers, and logical connectives. Let the domain
consist of the students in your class and
a. Someone in your class can speak Hindi
b. Everyone in your class is friendly
e. No student in your class has taken a course in logic programming
x H(x)
b. x (C(x) F(x)),
x F(x)
Slide # 65
The Foundations : Logic and Proofs
Example Q 18 pp 51
Translate in two ways each of these statements into logical expressions
using predicates , quantifiers, and logical connectives.
a. Something is not in the correct place
b. All tools are in the correct place and are in excellent condition
c. Everything is in the correct place and in excellent condition
d. Nothing is in the correct place and is in excellent condition
e. One of your tools is not in the correct place, but it is in excellent
condition
x ( P(x))
x(T(x) P(x) and Q(x))
x(P(x) and Q(x))
x (P(x) or Q(x))
x(T(x) and P(x) and Q(x))
Slide # 66
The Foundations : Logic and Proofs
Examples Q 19 pp 51
Suppose
Slide # 67
The Foundations : Logic and Proofs
Logic Programming
There
The
A Prolog
The
The
Slide # 70
The Foundations : Logic and Proofs
Facts in Prolog
A fact
Slide # 71
The Foundations : Logic and Proofs
Rules in Prolog
A rule
In
likable(X) :- likes(Y,X).
Slide # 72
The Foundations : Logic and Proofs
Logical
rules.
E.g.,
x [(P(x)Q(x))R(x)]S(x)
Slide # 73
The Foundations : Logic and Proofs
Deduction in Prolog
When
Slide # 74
The Foundations : Logic and Proofs
returns:
mary
fred
Slide # 75
The Foundations : Logic and Proofs
Example
Facts
instructor(Wasfi, ics253)
instructor(Yahya, ics324)
instructor(Marwan,coe202)
enrolled(ahmed, ics253)
enrolled(adel, ics324)
enrolled(rida, coe202)
enrolled(osamah, coe202)
enrolled(rida, ics253)
enrolled(osamah, ics324)
enrolled(ahmed, coe202)
enrolled(adel, ics253)
Queries
The query Is ahmed instructor of ics324 ?,
instructor(ahmed , ics324)
The query Is osamah enrolled in coe202 ?,
enrolled(osamah, coe202)
The query who is enrolled in coe202 ?,
enrolled(X, coe202)
The query who teaches rida?,
teaches(X, rida)
Rule
Teaches(P, S) :- instructor(P, C), enrolled(S, C)
ICS253 - 1The Foundations: Logic and Proofs61
Slide # 76
The Foundations : Logic and Proofs
Summary
Predicate logic notation & conventions
Conversions: predicate logic clear English
Meaning of quantifiers, equivalences
Simple reasoning with quantifiers
Slide # 77
The Foundations : Logic and Proofs