Ch1 sets and_logic(1)

Preview:

DESCRIPTION

 

Citation preview

Chapter 1

Sets and Logic

2008 학년도 2 학기고려대학교 과학기술대학 컴퓨터 정보학과

2

1.1 Sets Set

– a collection of distinct unordered objects– members of a set are called elements– notation

{ }, Φ S = { a1, a2, a3, …, an }, a1 ∈ S { x R∈ | - 2 < x < 5 } { { a1, a2 }, { b1, b2, b3 } }

Symbol Set

R Set of all REAL numbers

Z Set of all INTEGERs

Q Set of all RATIONAL numbers

superscript indicate

+ Positive

- Negative

nonneg nonnegative

x R∈x R

R+ : set of positive real numbers

Znonneg : set of natural numbers

3

Cardinality– |X| = number of elements in the set

Example 1.1.1

Empty Set (or Null Set)– Only one set with no elements.– { }, – The empty set is a subset of every set.

A = {1, 2, 3, 4} , |A| = ?|{R, Z}| = ?

Cardinality &Empty Set

4

Equal

Example 1.1.2

Example 1.1.3

Equal

Two sets X and Y are equal if X and Y have the same elements.X = Y if for every x, if x ∈ X, then x ∈ Y and for every y, if y ∈ Y, then y ∈ X

A = {1, 3, 2}, B = {2, 3, 2, 1}. A = B ?

Let us prove that if A = {x | x2 + x – 6 = 0} and B = {2, -3}

Then A = B.

5

Subset Subset

If A and B are sets, then A is called a subset of B, written A B⊆ ,If, and only if, every element of A is also an element of B.Symbolically :

A ⊆ B ⇔ ∀x, if x ∈ A then x ∈ B.

The phrases A is contained in B and B contains A are alternative ways of saying that A is a subset of B.

A set A is not a subset of a set B, written A ⊆ B, if, and only if, there is at least one element of A that is not an element of B.Symbolically :

A ⊆ B ⇔ ∃x, x ∈ A and x ∈ B.

6

Example 1.1.5

Example 1.1.7

Example 1.1.9

Subset

Z Q ?⊆

LetX = {x | 3x2 – x – 2 = 0}.

X Z ?⊆

C = {1, 3}, B = {1, 2, 3, 4}. C A ?⊆

77

Proper Subset Proper subset

Venn Diagrams If sets A and B are represented as regions in the plane, relationships between

A and B can be presented by pictures.

Let A and B be sets.A is a proper subset of B, if, and only if, every element of A is in Bbut there is at least one element of B that is not A.

AA BB

A = BA = B

AA BB AA BB

BBAA

AA BB

A = BA = B

A B⊆A B⊆ A B⊆A B⊆ A B⊂A B⊂

88

Power Set Power set

Example 1.1.13

Given a set A, the power set of A, denoted P(A),is set of all subsets of A

Find the power set of the set A ={a, b, c}. That is, find P( A) .P( A ) =

The Number of Subsets of a Set

For all integers n ≥ 0, if a set X has n elements, then P(X) has 2n elements

9

Set Operations Set Operations

Let A and B be subset of a universal set U.① Union: X Y = { ∪ x | x X or ∈ x Y }∈② intersection: X ∩ Y = { x | x X and∈ x Y }∈③ Difference: X – Y = { x | x X and∈ x Y }④ Complement: Xc = { x | x A }

Example 1.1.15

A ={1, 3, 5}, B = {4, 5, 6}A B =∪A ∩ B =A – B =B – A =

Since Q ⊆ R,R Q =∪R ∩ Q =R – Q =Q – R =

Example 1.1.14

10

Disjoint Disjoint

Example 1.1.14

Two sets are called disjoint if, and only if, they have no elements in common. Symbolically : A and B are disjoint ⇔ A ∩ B = Φ

- {1, 4, 5} and {2, 6}- S = {{1, 4, 5,}, {2, 6}, {3}, {7, 8}}

11

Set Operations Example 1.1.20

• Total students: 165• Taking CALC, PSYCH and COMPSCI: 8• Taking CALC and COMPSCI: 33• Taking CALC and PSYCH : 20• Taking PSYCH and COMPSCI: 24• Taking CALC: 79• Taking PSYCH : 83• Taking COMPSCI: 63

How many are taking none of the three subjects?

12

Set Identity Theorem 1.1.21

Let U be a universal set and let A, B, and C be subsets of U. The following properties hold

a) Associative laws : (A B) C = A (B C) and (A ∩ B) ∩ C = A ∩∪ ∪ ∪ ∪ (B (B ∩ C)b) Commutative laws : A B = B A and A ∩ B = B ∩ A∪ ∪c) Distributive laws :

A (B ∩ C) = (A B) ∩ (A C)∪ ∪ ∪ A ∩ (B C) = (A ∩B) (A ∩ C)∪ ∪d) Identity laws : A Φ = A and A ∩ ∪ U = A

e) Complement laws : A A∪ c = U and A ∩ Ac = Φ

f) Idempotent laws : A A = A and A ∩ A = A∪

13

Set Identity

g) Bound laws : A U = U and A ∩ Φ = Φ∪

h) Absorption Laws : A (A∩B) = A and A ∩ (A B) = A∪ ∪ i) Involution law (double negation laws) :

(Ac)c = A j) 0/1 laws:

U c = Φ and Φc = U. k) DeMorgan’s Laws : (A B)∪ c = Ac ∩ Bc and (A∩B)c = Ac B∪ c

14

Union & intersection of a family S of sets– if S = {A1, A2, …, An},

– If S = {A1, A2,…},

Example 1.1.22

i

n

iAS

1 i

n

iAS

1

ii

AS

1 i

iAS

1

For i ≥ 1,defineAi = {i, i+1, … } and S = {A1, A2, …, An}.

Then, and ?S S

15

Partition of sets Mutually disjoint

Partition– A partition of a set A divides A into nonoverlapping subsets.

Sets A1, A2, A3, …, An are mutually disjoint if, and only if, no two sets Ai and Aj with distinct subscripts have any elements in common.

More precisely, for all i, j = 1, 2, 3, …, n,Ai ∩ Aj = Φ whenever i ≠ j

A collection of nonempty sets {A1, A2, A3, …, An } is a partition of a set A if, and only if,

① A = A1 A∪ 2 A∪ 3, …, A∪ n ② A1, A2, A3, …, An are mutually disjoint.

AA11

AA22

AA33

…… AAnn

16

Cartesian product Definition

Example

a. Is ( 1, 2 ) = ( 2, 1 )? b. Is ( 3, ( - 2 )2, 1/2 ) = ( , 4, 3/6 )?

Let n be a positive integer and let x1, x2, x3, … xn be elements. The ordered n-tuple, ( x1, x2, x3, … xn ), consists of x1, x2, x3, …, xn together with the ordering. An ordered 2-tuple is called an ordered pair; and an ordered 3-tuples is called an ordered triple.Two ordered n-tuples ( x1, x2, x3, …, xn ) and ( y1, y2, y3, …, yn ) are equal if, and only if,

x1 = y1, x2 = y2, x3 = y3, …, xn = yn.Symbolically : ( x1, x2, x3, …, xn ) = ( y1, y2, y3, …, yn ) ⇔ x1 = y1, x2 = y2, x3 = y3, …, xn = yn

9

17

Cartesian product Definition

Example 1.1.24 Let X = { 1, 2, 3 }, and Y = { a, b }.

Find X × Y Find Y ×X Find X × X Find Y × Y

Given two sets A and B, the Cartesian Product of A and B, denote A × B( read “A cross B” ), is the set of all ordered pairs ( a, b ), where a is in A and b is in B.Given A1 × A2 × A3, …, × An, is the set of all ordered n-tuples ( a1, a2, a3, …, an )where a1 ∈ A1, a2 ∈ A2, a3 ∈ A3, …, an ∈ An . Symbolically :

A × B = { ( a, b ) | a A and b B },∈ ∈ A1 × A2 × A3 ×… × An = { ( a1, a2, a3, …, an ) | a1 ∈ A1, a2 ∈ A2, a3 ∈ A3, …, an ∈ An }.

18

Logic Logic = the study of correct reasoning Use of logic

– In mathematics: to prove theorems– In computer science: to prove that programs do what they are

supposed to do

19

1.2 Propositions Definition

Examples:– The only positive integers that divide 7 are 1 and 7 itself.– Alfred Hitchcock won an Academy Award in 1940 for directing

“Rebecca”.– For every positive integer n, there is a prime number larger than n.– Earth is the only planet in the universe that contains life.– Buy two tickets to the “Unhinged Universe” rock concert for Friday.– x + 4 = 6

A proposition ( 명제 ) is a statement or sentence that can be determined to be either true or false but not both

20

More examples– 3 + 6 = 8– 대한민국의 수도는 서울이다– 물은 수소와 산소로 이루어져 있다– 3 × 4 > 123 × 4 > 12– 다음주 이산구조 수업은 휴강이다 .– X + Y > 0– 컴퓨터의 가격은 비싸다 .– 세종 대왕은 이순신 장군보다 훌륭하다 .

Propositions

21

Connectives If p and q are propositions, new compound propositions can

be formed by using connectives Most common connectives:

– Conjunction (AND) Symbol ^ – (Inclusive) disjunction (OR) Symbol v– Exclusive disjunction (XOR) Symbol – Negation Symbol – Implication Symbol – Double implication Symbol

22

Conjunction() Definition 1.2.3 Truth table of conjunction

Example 1.2.2

p q p qT T T

T F F

F T F

F F F

Ifp: It is rainingq: It is cold

then what is the conjunction of p and q ?

23

Example 1.2.4

Example 1.2.5

Ifp: A decade is 10 yearsq: A millennium is 100 years

then what is the conjunction of p and q ? Is it true or false?

x < 10 && y > 4

24

Disjunction() Definition 1.1.6 The truth table of (inclusive) disjunction

Example 1.2.7

Example 1.2.8

p q p v q

T T T

T F T

F T T

F F F

If p: A millennium is 100 yearsq: A millennium is 1000 years

then what is the disjunction of p and q ? Is it true or false?

x < 10 || y > 4

25

Exclusive OR Truth Table of Exclusive OR :

( p q ) ~ ( p q )∨ ∧ ∧

p q p q∨ p q∧ ~(p q)∧ ( p q ) ~ ( p q )∨ ∧ ∧

T T T T F F

T F T F T T

F T T F T T

F F F F T F

26

Logical connectives in C programs

[Ex] int i, j; i = 2 && ( j = 2 ); printf(“%d %d\n”, i, j); /* 1 2 is printed */ ( i = 0 ) && ( j = 3 ); printf(“%d %d\n”, i, j); /* 0 2 is printed */ i = 0 || ( j = 4 ); printf(“%d %d\n”, i, j); /* 1 4 is printed */ ( i = 2 ) || ( j = 5 ); printf(“%d %d\n”, i, j); /* 2 4 is printed */

27

Negation() Definition 1.1.9 Negation of p (p):

Example– p: Paris is the capital of England– p: It is not the case that Paris is the capital of England – p: Paris is not the capital of England

Example 1.2.11

p p

T F

F T

! ( x < 10)

28

More compound statements Example: ( p q ) ∧ ∨ r

Precedence of logical operations– first evaluate , then , and then .

p q r p q∧ r ( p q ) ∧ ∨ r

T T T T F T

T T F T T T

T F T F F F

T F F F T T

F T T F F F

F T F F T T

F F T F F F

F F F F T T

29

1.3 Conditional propositions and logical equivalence

Definition 1.3.1 conditional proposition– 임의의 명제 p, q 의 조건 연산자는 p → q 로 표기

p is called the hypothesis( 가정 , 전제조건 ) q is called the conclusion( 결론 , 결과 )

– p → q p is sufficient for q q is necessary for p P implies q

Example: – p : The Mathematics Department gets an additional $40,000– q : The mathematics Department will hire one new faculty member– p q : If The Mathematics Department gets an additional $40,000,

then it will hire one new faculty member.

30

Implication()

Definition 1.3.3 Truth table of conditional proposition

p q p q

T T T

T F F

F T T

F F T

p q is true when both p and q are true or when p is false

true by default orvacuously true

31

Example 1.3.5Assume p: true, q: false, and r is true

a. p q → r

b. p q → r

c. p (q → r)

d. p →(q → r)

Example 1.3.6 Restate each proposition in the form if p then q

a. Mary will be a good student if she studies hard.

b. John takes calculus only if he has sophomore, junior, or senior standing.

Implication

If "p then q" is considered logically the same as "p only if q"

32

Implicationc. When you sing, my ears hurt.

d. A necessary condition for the Cubs to win the World Series is that they sign a right-handed relief pitcher.

e. A sufficient condition for Maria to visit France is that she goes to the Eiffel Tower

A necessary condition is expressed by the conclusion.A sufficient condition is expressed by the hypothesis.

33

Double Implication() Definition 1.3.8

– p ↔ q ≡ ( p → q ) ( q → p )∧– Truth Table for p ↔ q

The biconditional of p and q (p ↔ q)– p if and only if q– p is necessary and sufficient for q

p q p → q q → p ( p → q ) ( q → p )∧ p ↔ q

T T T T T T

T F F T F F

F T T F F F

F F T T T T

34

Logical Equivalence Definition 1.3.10 Logical Equivalence

Example 1.3.11 De Morgan’s Laws for Logic

Example 1.3.12

x < 10 || x > 20

– 각각의 다른 합성 명제 ( 또는 단순 명제 ) 가 동일한 진리표를 가진다면 , 이 두 개의 명제는 논리적 동치라고 한다 .

– 명제 P 와 Q 가 논리적 동치라면 , P ≡ Q 표기

( p q ) ≡ ∧ p ∨ q

( p q ) ≡ ∨ p ∧ q

35

Logical Equivalence p → q ≡ ~ p q∨

p q p → q ~p ~p q∨

T T T F T

T F F F F

F T T T T

F F T T T

Rewrite the following statement in if-then form

Either you get to work on time or you are fired.

Example

36

Logical Equivalence

~ (p → q) ≡ ~ ( ~ p q )∨ ≡ ~ ( ~ p ) ~q ∧ ☞ 드모르간 법칙에 의해 ≡ p ~q ∧ ☞ 이중 부정 법칙에 의해

The Negation of “if p then q” is locally equivalent to “p and not q”.

If Jerry receives a scholarship, then he goes to college

Example 1.3.14 Negation of If-Then Statement

Negation of → : ~ (p → q) ≡ p ~q∧

a. If my car is in the repair shop, then I cannot get to class

b. If Sara lives in Athens, then she lives in Greece

More Example

37

Contrapositive Definition 1.3.16

p q p → q ~q ~p ~q → ~p

T T T F F T

T F F T F F

F T T F T T

F F T T T T

The contrapositive( 대우 ) of p → q is ~ q → ~ p

If the network is down, then Dale cannot access the Internet

Example 1.3.17 Writing the Contrapositive

The conditional statement and its contrapositive are logically equivalent

Theorem 1.3.18

38

Converse & Inverse Definition

– Conditional statement and its converse are not equivalent

– Conditional statement and its inverse are not equivalent– The converse and the inverse of a conditional statement are logically

equivalent to each other

p q p → q q → p ~p ~q ~p → ~q

T T T T F F T

T F F T F T T

F T T F T F F

F F T T T T T

The converse( 역 ) of p → q is q → pThe inverse( 이 ) of p → q is ~ p → ~ q

39

Tautology & Contradiction

합성 명제의 진리값이 항상 T 인 명제 , 즉 , 합성명제를 구성하고 있는 단순명제들의 진리값에 상관없이 항상 T 의 진리값을 가진 명제

합성명제의 진리값이 항상 F 인 명제 , 즉 , 합성명제를 구성하고 있는 단순명제들의 진리값에 상관없이 항상 F 의 진리값을 가진 명제

Tautology ( 항진 명제 )

Contradiction( 모순명제 )

40

Tautology & Contradiction

Example: Logical Equivalence Involving Tautologies and Contradictions– If t is a tautology and c is a contradiction, show that

p ∧ t ≡ p p ∧ c ≡ c

p t p ∧ t

T T T

F T F

p c p ∧ c

T F F

F F F

p ~p p ~p∨ p ~p∧

T F T F

F T T F

ContradictionTautology

Example