Anda di halaman 1dari 56

Module #1 - Logic

4/18/2014 1
Universitas Islam Indonesia
Jurusan Teknik Informatika
Matematika Diskret
Yudi Prayudi
Slides for a Course Based on the Text
Discrete Mathematics & Its Applications (5
th
Edition)
by Kenneth H. Rosen

Module #1 - Logic
4/18/2014 2
Module #1:
The Fundamentals of Logic
Rosen 5
th
ed., 1.1-1.4
~81 slides, ~4 lectures
Module #1 - Logic
4/18/2014 3
Module #1: Foundations of Logic
(1.1-1.3, ~3 lectures)
Logika Matematika adalah sebuah tools untuk
memahami hubungan yang terkait dengan kalimat
majemuk (compound statements). Meliputi :
Formal language untuk ekspresi.
Notasi untuk menulisnya .
Metodologi untuk menentukan secara objektif nilai
kebenaran.
Sebagai fondasi untuk ekspresi pembuktian formal
pada semua cabang matematika lainnya.
Module #1 - Logic
4/18/2014 4
Foundations of Logic: Overview
Propositional logic (1.1-1.2):
Basic definitions. (1.1)
Equivalence rules & derivations. (1.2)
Predicate logic (1.3-1.4)
Predicates.
Quantified predicate expressions.
Equivalences & derivations.
Module #1 - Logic
4/18/2014 5
Propositional Logic (1.1)
Propositional Logic adalah logika dari
kalimat majemuk (compound statements)
yang dibangun dari kalimat tunggal
(simpler statements)
menggunakan Boolean connectives.
Beberapa aplikasi pada bidang komputer :
Design of digital electronic circuits.
Expressing conditions in programs.
Queries to databases & search engines.
Topic #1 Propositional Logic
George Boole
(1815-1864)
Chrysippus of Soli
(ca. 281 B.C. 205 B.C.)
Module #1 - Logic
4/18/2014 6
Definisi dari Proposisi
Definition: Sebuah proposisi (dgn notasi p, q, r, ), secara
sederhananya adalah :
Sebuah statement (i.e., a declarative sentence)
Dengan makna yang jelas tidak bersifat makna ganda atau kabur (definite
meaning, not vague or ambiguous)
Memiliki salah satu nilai kebenaran (truth value), baik itu true (T)
atau false (F)
Tidak keduanya, atau dua-duanya, atau diantara keduanya. Hanya boleh
salah satu.
Pada bidang bahasan lain (probability theory),dimungkinkan adanya derajat
kepastian (degrees of certainty, antara T dan F) pada sebuah proposisi.
Namun saat ini yang diperhatikan : kepastian terhadap nilai kebenaran, yaitu True
atau False.
Topic #1 Propositional Logic
Module #1 - Logic
4/18/2014 7
Contoh Proposisi
Hari Hujan (Menunjukkan situasi yang terjadi)
Jakarta adalah ibukota Indonesia
1 + 2 = 3
Namun berikut ini adalah bukan proposisi :
Siapakah mereka ? (interrogative, question)
La la la la la. (meaningless interjection)
Kerjakan ! (imperative, command)
Yaa, Maaf dong, jangan marah .. (vague)
1 + 2 (expression with a non-true/false value)
Topic #1 Propositional Logic
Module #1 - Logic
4/18/2014 8
Sebuah operator/connective akan
mengkombinasikan satu atau dua ekspresi
menjadi ekspresi yang lebih besar.
Unary operators, hanya 1 operand (mis: 3);
Binary operators memerlukan 2 operands (mis : 3 4).
Operators / Connectives
Topic #1.0 Propositional Logic: Operators
Module #1 - Logic
4/18/2014 9
Boolean Operators
Formal Name Nickname Arity Symbol
Negation operator NOT Unary
Conjunction operator AND Binary .
Disjunction operator OR Binary v
Exclusive-OR operator XOR Binary
Implication operator IMPLIES Binary
Biconditional operator IFF Binary
Topic #1.0 Propositional Logic: Operators
Module #1 - Logic
4/18/2014 10
Tabel Kebenaran

p q
p p.q pvq pq pq pq
F F T F F F T T
F T T F T T T F
T F F F T T F F
T T F T T F T T
Topic #1.0 Propositional Logic: Operators
Module #1 - Logic
4/18/2014 11
Notasi Lain Operator
Name:
not and or xor implies iff
Propositional logic:
. v
Boolean algebra:
p
pq +

C/C++/Java (wordwise):
! && || != ==
C/C++/Java (bitwise):
~ & | ^
Logic gates:
Topic #1.0 Propositional Logic: Operators
Module #1 - Logic
4/18/2014 12
Bits dan Operasi Bit
Sebuah bit adalah biner (base 2) : digit: 0 atau 1.
Bits dapat pula digunakan untuk representasi nilai
kebenaran.
Konvensi:
0 representasi false; 1 representasi true.
Aljabar Boolean adalah sebuah aljabar dengan
dasar variabel pada operasi bit, dimana + artinya
or, dan X artiya and.
Dibahas lebih detail dibagian khusus Ajabar Boolean.
Topic #2 Bits
John Tukey
(1915-2000)
Module #1 - Logic
4/18/2014 13
Bit Strings
Sebuah Bit string dengan panjang n adalah sebuah
urutan (series, tuple) dari n > 0 bits.
Sesuai konvensi, bit strings ditulis/dibaca dari arah
kiri ke kanan (left to right):
Bit pertama dari string 1001101010 adalah 1.
Bila sebuah bit string adalah representasi dari
bilangan dasar 2,maka secara konvensi leftmost
bit adalah the most significant bit.
Ex. 1101
2
=8+4+1=13.
Topic #2 Bits
Module #1 - Logic
4/18/2014 14
Bitwise Operations
Operasi Boolean dapat pula diterapkan pada
strings bit atau bit tunggal.
01 1011 0110
11 0001 1101
11 1011 1111 Bit-wise OR
01 0001 0100 Bit-wise AND
10 1010 1011 Bit-wise XOR
Topic #2 Bits
Module #1 - Logic
4/18/2014 15
End of 1.1
Materi Yang telah
dibahas :
Proposisi.
Operator Untuk
Logika Proposisi
Symbolic notations.
English equivalents.
Logical meaning.
Truth tables.
Atomic vs. compound
propositions.
Alternative notations.
Bits and bit-strings.

Module #1 - Logic
4/18/2014 16
Propositional Equivalence
(1.2)
Dua buah proposisi secara sintaks
(penulisan) bisa jadi adalah dua bentuk
yang berbeda namun secara semantik
(makna) dapat memiliki nilai yang sama.
Hal ini dikenal sebagai equivalent.
Topic #1.1 Propositional Logic: Equivalences
Module #1 - Logic
4/18/2014 17
Tautologi dan Kontradiksi
Runut balik materi Logika Matematika :
Tautologi
Kontradiksi
Kontingen
Topic #1.1 Propositional Logic: Equivalences
Module #1 - Logic
4/18/2014 18
Ekuivalensi Logika
Sebuah compound proposition p adalah logically
equivalent terhadap proposition q, ditulis pq,
IFF bila compound proposition pq adalah
sebuah tautology.
Sebuah compound propositions p dan q adalah
logically equivalent satu dengan yang lain IFF p
dan q memuat nilai tabel kebenaran yang sama
untuk setiap baris dari tabel kebenaran.
Topic #1.1 Propositional Logic: Equivalences
Module #1 - Logic
4/18/2014 19
Ex. Prove that pvq (p . q).

p q
p
p
v
v
q
q

p
p

q
q

p
p
.
.

q
q

(
(

p
p
.
.

q
q
)
)
F F
F T
T F
T T
Pembuktian Ekuivelensi
lewat Truth Tables
F
T
T
T
T
T
T
T
T
T
F
F
F
F
F
F
F
F
T
T
Topic #1.1 Propositional Logic: Equivalences
Module #1 - Logic
4/18/2014 20
Equivalence Laws
Identity: p.T p pvF p
Domination: pvT T p.F F
Idempotent: pvp p p.p p
Double negation: p p
Commutative: pvq qvp p.q q.p
Associative: (pvq)vr pv(qvr)
(p.q).r p.(q.r)
Topic #1.1 Propositional Logic: Equivalences
Module #1 - Logic
4/18/2014 21
Equivalence Laws
Distributive: pv(q.r) (pvq).(pvr)
p.(qvr) (p.q)v(p.r)
De Morgans:
(p.q) p v q
(pvq) p . q
Trivial tautology/contradiction:
p v p T p . p F
Topic #1.1 Propositional Logic: Equivalences
Augustus
De Morgan
(1806-1871)
Module #1 - Logic
4/18/2014 22
Definisi Operators via Equivalences
Menggunakan ekuivalensi dapat pula
mendefiniskan operator lain :
Exclusive or: pq (pvq).(p.q)
pq (p.q)v(q.p)
Implies: pq p v q
Biconditional: pq (pq) . (qp)
pq (pq)
Topic #1.1 Propositional Logic: Equivalences
Module #1 - Logic
4/18/2014 23
Review: Propositional Logic
(1.1-1.2)
Atomic propositions: p, q, r,
Boolean operators: . v
Compound propositions: s : (p . q) v r
Equivalences: p.q (p q)
Proving equivalences using:
Truth tables.
Symbolic derivations. p q r
Topic #1 Propositional Logic
Module #1 - Logic
4/18/2014 24
Predicate Logic (1.3)
Predicate logic adalah pengembangan dari
propositional logic dengan memandang kebenaran
sebagai satu kesatuan entitas.
Propositional logic dapat dipandang sebagai
simple propositions (sentences) yang bersifat
atomic entities.
Predicate logic membedakan pengertian kalimat
dari subjek dan predikatnya.
Ingat aturan tata bahasan / grammar
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 25
Applikasi dari Predicate Logic
Adalah notasi formal untuk menuliskan
definisi, aksioma, teorema dari semua
bidand matematika.
Dasar bagi bidang mathematical logic
Predicate logic with function symbols, the = operator, and a
few proof-building rules is sufficient for defining any
conceivable mathematical system, and for proving
anything that can be proved within that system!
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 26
Aplikasi Praktis Dari
Predicate Logic
Dasar bagi ekspresi formal specifications untuk
setiap complex system.
Dasar bagi automatic theorem provers dan bidang
Artificial Intelligence systems.
Mis: automatic program verification systems.
Predicate-logic sebagaimana sebuah pernyataan
adalah mendukung implementasi database query
engines dan container class libraries
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 27
Subjects dan Predicates
Pada kalimat The dog is sleeping:
Phrase the dog merujuk pada subject, pelaku utama
dari objek pada kalimat tersebut.
Phrase is sleeping merujuk pada predicate, sifat yang
menunjukkan pada aktifitas subject.
Pada predicate logic, predicate dimodelkan
sebagai function P( ) dari objek pada proposisi.
P(x) = x is sleeping (where x is any object).
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 28
Predicates
Konvensi : huruf kecil dari variabel x, y, z...
Merujuk pada objects/entitas; huruf besar variabel
variables P, Q, R merujuk pada propositional
functions (predicates).
Menerapkan predicate P terhadap object x adalah
meruakan sebuah proposition P(x). Tetapi
predicate P-nya sendiri bukanlah sebuah proposisi,
Misalnya (P=is sleeping).
P(x) = x is a prime number,
P(3) is the proposition 3 is a prime number.
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 29
Propositional Functions
Predicate logic generalizes the grammatical
notion of a predicate to also include
propositional functions of any number of
arguments, each of which may take any
grammatical role that a noun can take.
E.g. let P(x,y,z) = x gave y the grade z, then if
x=Mike, y=Mary, z=A, then P(x,y,z) =
Mike gave Mary the grade A.
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 30
Universes of Discourse (U.D.s)
The power of distinguishing objects from
predicates is that it lets you state things
about many objects at once.
E.g., let P(x)=x+1>x. We can then say,
For any number x, P(x) is true instead of
(0+1>0) . (1+1>1) . (2+1>2) . ...
The collection of values that a variable x
can take is called xs universe of discourse.
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 31
Quantifier Expressions
Quantifiers adalah notasi yang memungkinkan
menghitung (quantify) banyaknya object dalam
universe of disclosure.
is the FORLL or universal quantifier.
x P(x) means for all x in the universe of
disclosure (u.d) P holds.
- is the -XISTS or existential quantifier.
-x P(x) means there exists an x in the u.d. (that is,
1 or more) such that P(x) is true.
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 32
The Universal Quantifier
Example:
Let the u.d. of x be parking spaces at UII.
Let P(x) be the predicate x is full.
Then the universal quantification of P(x),
x P(x), is the proposition:
All parking spaces at UII are full.
i.e., Every parking space at UII is full.
i.e., For each parking space at UII, that space is full.
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 33
The Existential Quantifier -
Example:
Let the u.d. of x be parking spaces at UII.
Let P(x) be the predicate x is full.
Then the existential quantification of P(x),
-x P(x), is the proposition:
Some parking space at UII is full.
There is a parking space at UII that is full.
At least one parking space at UII is full.
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 34
Free and Bound Variables
Sebuah ekspresi seperti P(x) dikenal
memiliki sebuah free variable x (maknanya,
x is undefined).
Sebuah quantifier (baik atau -) akan
menggunakan (operates) satu atau lebih free
variable, dan diantara nya akan berfungsi
sebagai bound variable.
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 35
Example of Binding
P(x,y) memiliki 2 free variables, x dan y.
x P(x,y) memiliki 1 free variable, dan one
bound variable. [Which is which?]
P(x), where x=3 is another way to bind x.
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 36
Nesting of Quantifiers
Example: Let the u.d. of x & y be people.
Let L(x,y)=x likes y (a predicate with 2 free
variable.s)
Then -y L(x,y) = There is someone whom x
likes. (A predicate with 1 free variable, x)
Then x (-y L(x,y)) =
Everyone has someone whom they like.
(A __________ with ___ free variables.)
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 37
Review: Predicate Logic (1.3)
Objects x, y, z,
Predicates P, Q, R, are functions
mapping objects x to propositions P(x).
Multi-argument predicates P(x, y).
Quantifiers: [x P(x)] : For all xs, P(x).
[-x P(x)] : There is an x such that P(x).
Universes of discourse, bound & free vars.
Module #1 - Logic
4/18/2014 38
Quantifier Exercise
If R(x,y)=x relies upon y, express the
following in unambiguous English:
x(-y R(x,y))=
-y(x R(x,y))=
-x(y R(x,y))=
y(-x R(x,y))=
x(y R(x,y))=
Everyone has someone to rely on.
Theres a poor overburdened soul whom
everyone relies upon (including himself)!
Theres some needy person who relies
upon everybody (including himself).
Everyone has someone who relies upon them.
Everyone relies upon everybody,
(including themselves)!
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 39
Natural language is ambiguous!
Everybody likes somebody.
For everybody, there is somebody they like,
x -y Likes(x,y)
or, there is somebody (a popular person) whom
everyone likes?
-y x Likes(x,y)
Somebody likes everybody.
Same problem: Depends on context, emphasis.
[Probably more likely.]
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 40
Game Theoretic Semantics
Thinking in terms of a competitive game can help you tell
whether a proposition with nested quantifiers is true.
The game has two players, both with the same knowledge:
Verifier: Wants to demonstrate that the proposition is true.
Falsifier: Wants to demonstrate that the proposition is false.
The Rules of the Game Verify or Falsify:
Read the quantifiers from left to right, picking values of variables.
When you see , the falsifier gets to select the value.
When you see -, the verifier gets to select the value.
If the verifier can always win, then the proposition is true.
If the falsifier can always win, then it is false.
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 41

Lets Play, Verify or Falsify!
Let B(x,y) : xs birthday is followed within 7 days
by ys birthday.
Suppose I claim that among you:
x -y B(x,y)
Your turn, as falsifier:
You pick any x (so-and-so)
-y B(so-and-so,y)
My turn, as verifier:
I pick any y (such-and-such)
B(so-and-so,such-and-such)
Lets play it in class.
Who wins this game?
What if I switched the
quantifiers, and I
claimed that
-y x B(x,y)?
Who wins in that
case?
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 42
Still More Conventions
Sometimes the universe of discourse is
restricted within the quantification, e.g.,
x>0 P(x) is shorthand for
For all x that are greater than zero, P(x).
=x (x>0 P(x))
-x>0 P(x) is shorthand for
There is an x greater than zero such that P(x).
=-x (x>0 . P(x))
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 43
More to Know About Binding
x -x P(x) - x is not a free variable in
-x P(x), therefore the x binding isnt used.
(x P(x)) . Q(x) - The variable x is outside
of the scope of the x quantifier, and is
therefore free. Not a complete proposition!
(x P(x)) . (-x Q(x)) This is legal,
because there are 2 different xs!
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 44
Quantifier Equivalence Laws
Definitions of quantifiers: If u.d.=a,b,c,
x P(x) P(a) . P(b) . P(c) .
-x P(x) P(a) v P(b) v P(c) v
From those, we can prove the laws:
x P(x) -x P(x)
-x P(x) x P(x)
Which propositional equivalence laws can
be used to prove this?
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 45
More Equivalence Laws
x y P(x,y) y x P(x,y)
-x -y P(x,y) -y -x P(x,y)
x (P(x) . Q(x)) (x P(x)) . (x Q(x))
-x (P(x) v Q(x)) (-x P(x)) v (-x Q(x))
Exercise:
See if you can prove these yourself.
What propositional equivalences did you use?
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 46
Review: Predicate Logic (1.3)
Objects x, y, z,
Predicates P, Q, R, are functions
mapping objects x to propositions P(x).
Multi-argument predicates P(x, y).
Quantifiers: (x P(x)) =For all xs, P(x).
(-x P(x))=There is an x such that P(x).
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 47
More Notational Conventions
Quantifiers bind as loosely as needed:
parenthesize x P(x) . Q(x)
Consecutive quantifiers of the same type
can be combined: x y z P(x,y,z)
x,y,z P(x,y,z) or even xyz P(x,y,z)
All quantified expressions can be reduced
to the canonical alternating form
x
1
-x
2
x
3
-x
4
P(x
1
,

x
2
, x
3
, x
4,
)
( )
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 48
Defining New Quantifiers
As per their name, quantifiers can be used to
express that a predicate is true of any given
quantity (number) of objects.
Define -!x P(x) to mean P(x) is true of
exactly one x in the universe of discourse.
-!x P(x) -x (P(x) . -y (P(y) . y= x))
There is an x such that P(x), where there is
no y such that P(y) and y is other than x.
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 49
Some Number Theory Examples
Let u.d. = the natural numbers 0, 1, 2,
A number x is even, E(x), if and only if it is equal
to 2 times some other number.
x (E(x) (-y x=2y))
A number is prime, P(x), iff its greater than 1
and it isnt the product of any two non-unity
numbers.
x (P(x) (x>1 . -yz x=yz . y=1 . z=1))
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 50
Goldbachs Conjecture (unproven)
Using E(x) and P(x) from previous slide,
E(x>2): -P(p),P(q): p+q = x
or, with more explicit notation:
x [x>2 . E(x)]
-p -q P(p) . P(q) . p+q = x.
Every even number greater than 2
is the sum of two primes.
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 51
Calculus Example
One way of precisely defining the calculus
concept of a limit, using quantifiers:
( )
( ) ( )
|
|
.
|

\
|
< <
> - >
=

c o
o c
| ) ( | | |
: : 0 : 0
) ( lim
L x f a x
x
L x f
a x
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 52
Deduction Example
Definitions:
s : Socrates (ancient Greek philosopher);
H(x) : x is human;
M(x) : x is mortal.
Premises:
H(s) Socrates is human.
x H(x)M(x) All humans are mortal.
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 53
Deduction Example Continued
Some valid conclusions you can draw:
H(s)M(s) [Instantiate universal.] If Socrates is human
then he is mortal.
H(s) v M(s) Socrates is inhuman or mortal.
H(s) . (H(s) v M(s))
Socrates is human, and also either inhuman or mortal.
(H(s) . H(s)) v (H(s) . M(s)) [Apply distributive law.]
F v (H(s) . M(s)) [Trivial contradiction.]
H(s) . M(s) [Use identity law.]
M(s) Socrates is mortal.
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 54
Another Example
Definitions: H(x) : x is human;
M(x) : x is mortal; G(x) : x is a god
Premises:
x H(x) M(x) (Humans are mortal) and
x G(x) M(x) (Gods are immortal).
Show that -x (H(x) . G(x))
(No human is a god.)
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 55
The Derivation
x H(x)M(x) and x G(x)M(x).
x M(x)H(x) [Contrapositive.]
x [G(x)M(x)] . [M(x)H(x)]
x G(x)H(x) [Transitivity of .]
x G(x) v H(x) [Definition of .]
x (G(x) . H(x)) [DeMorgans law.]
-x G(x) . H(x) [An equivalence law.]
Topic #3 Predicate Logic
Module #1 - Logic
4/18/2014 56
End of 1.3-1.4, Predicate Logic
From these sections you should have learned:
Predicate logic notation & conventions
Conversions: predicate logic clear English
Meaning of quantifiers, equivalences
Simple reasoning with quantifiers
Upcoming topics:
Introduction to proof-writing.
Then: Set theory
a language for talking about collections of objects.
Topic #3 Predicate Logic

Anda mungkin juga menyukai