21
2012 년 년년년 년년년년년 년년년년년년년 년년년 년년년년 (Discrete Mathematics) 년 년년 (Logic)

2012 년 봄학기 강원대학교 컴퓨터과학전공 문양세

Embed Size (px)

DESCRIPTION

이산수학 (Discrete Mathematics)  논리 (Logic). 2012 년 봄학기 강원대학교 컴퓨터과학전공 문양세. 논리 (Logic) 란 ?. 1.1 Logic. 논리 (logic) 란 수학적 표현의 의미를 정확하게 기술할 수 있게 함 논리는 회로 설계 , 프로그램 작성 , 프로그램 정확성 검증 등에 활용. 명제 (Proposition). 1.1 Logic. 명제의 정의 - PowerPoint PPT Presentation

Citation preview

Page 1: 2012 년  봄학기 강원대학교  컴퓨터과학전공  문양세

2012 년 봄학기강원대학교 컴퓨터과학전공 문양세

이산수학 (Discrete Mathematics) 논리 (Logic)

Page 2: 2012 년  봄학기 강원대학교  컴퓨터과학전공  문양세

Discrete Mathemat-icsby Yang-Sae Moon

Page 2

논리 (Logic) 란 ?

논리 (logic) 란 수학적 표현의 의미를

정확하게 기술할 수 있게 함

논리는 회로 설계 , 프로그램 작성 ,

프로그램 정확성 검증 등에 활용

1.1 Logic

Page 3: 2012 년  봄학기 강원대학교  컴퓨터과학전공  문양세

Discrete Mathemat-icsby Yang-Sae Moon

Page 3

명제 (Proposition)

명제의 정의• 명제란 참 (true, T) 또는 거짓 (false, F) 을 판정할 수 있는 선언적 문장을 말한다 .• A proposition (p, q, r, s, …) is a declarative statement that is either true (T)

or false (F), but not both.

명제의 예제• 1 + 1 = 2. (T)• 2 + 2 = 5. (F)• Seoul is the capital of Korea.• 11213 is prime.

명제가 아닌 예제• Who is there? (not declarative, question)• Just do it! (command)• x + 2 = 5. (non-constant value, variable)

1.1 Logic

Page 4: 2012 년  봄학기 강원대학교  컴퓨터과학전공  문양세

Discrete Mathemat-icsby Yang-Sae Moon

Page 4

논리 연산자 (Logical Operator) (1/2)

1.1 Logic

논리 연산자 관련 용어 정의• 하나 또는 여러 명제를 조합하여 새로운 수학적 명제를 만들 수 있으며 , 이를

복합명제 (compound proposition) 라 한다 .

• 복합명제를 만들 때 사용하는 연산자를 논리 연산자 (logical operator)

혹은 접속사 (connective) 라 한다 .

• 논리 연산자는 명제 연산자 (propositional operator) 혹은 불리언 연산자

(Boolean operator) 라고도 불리며 , 피연산자 (operand) 로서 명제 혹은

진리 값 (truth value) 을 취한다 .

( 본 강의에서는 이들 용어를 동일한 의미로 혼용하여 사용할 예정임 )

Page 5: 2012 년  봄학기 강원대학교  컴퓨터과학전공  문양세

Discrete Mathemat-icsby Yang-Sae Moon

Page 5

논리 연산자 (Logical Operator) (2/2)

1.1 Logic

Boolean Operator 의 예명칭 ( 영어 ) 명칭 ( 한글 ) Nickname Arity Symbol

Negation operator 부정 연산자 NOT Unary ¬

Conjunction opera-tor

논리곱 연산자 AND Binary

Disjunction opera-tor

논리합 연산자 OR Binary

Exclusive-OR oper-ator

배타적 OR 연산자 XOR Binary

Implication opera-tor

함축 연산자 IMPLIES Binary

Biconditional op-erator

상호조건 연산자 IFF Binary ↔

Page 6: 2012 년  봄학기 강원대학교  컴퓨터과학전공  문양세

Discrete Mathemat-icsby Yang-Sae Moon

Page 6

부정 (Negation) (1/2)1.1 Logic

부정의 정의• p 가 명제이면 , “It is not the case that p” 역시 명제이며 , 이를 p 의 부정

(negation) 이라 하며 , ¬p(not p) 로 표기한다 .

• The unary negation operator “¬” (NOT) transforms a proposition

into its logical negation.

부정 명제의 예제• 명제 (p) “I have brown hair.” 의 부정 명제 (¬p) 는 “ I do NOT have

brown hair.” 이다 .

• 명제 “ Today is Sunday.” 의 부정 명제는 “ Today is NOT Sunday.” 이다 .

Page 7: 2012 년  봄학기 강원대학교  컴퓨터과학전공  문양세

Discrete Mathemat-icsby Yang-Sae Moon

Page 7

부정 (Negation) (2/2)1.1 Logic

Negation operator 의 truth table

p ¬p

T F

F TOperand col-

umnResult column

Page 8: 2012 년  봄학기 강원대학교  컴퓨터과학전공  문양세

Discrete Mathemat-icsby Yang-Sae Moon

Page 8

논리곱 (Conjunction) (1/2)

논리곱의 정의• p 와 q 가 명제이면 , “p and q” 도 명제이며 , 이를 p 와 q 의 논리곱

(conjunction) 이라 하고 , pq 라 표기한다 .

이 명제는 p, q 가 모두 참일 때만 참이 되며 , 그 외는 모두 거짓이 된다 .

• The binary conjunction operator “” (AND) combines two proposi-

tions

to form their logical conjunction.

논리곱 사용의 예제• p = “I will have salad for lunch.”, q = “I will have a steak for dinner.”

• pq = “I will have salad for lunch and I will have steak for dinner.”

1.1 Logic

Page 9: 2012 년  봄학기 강원대학교  컴퓨터과학전공  문양세

Discrete Mathemat-icsby Yang-Sae Moon

Page 9

논리곱 (Conjunction) (2/2)

Conjunction operator 의 truth tablep q pqT T TT F FF T FF F F

1.1 Logic

Page 10: 2012 년  봄학기 강원대학교  컴퓨터과학전공  문양세

Discrete Mathemat-icsby Yang-Sae Moon

Page 10

논리합 (Disjunction) (1/2)

논리합의 정의• p 와 q 가 명제이면 , “p or q” 도 명제이며 , 이를 p 와 q 의 논리합

(disjunction) 이라 하고 , pq 라 표기한다 .

이 명제는 p, q 가 모두 거짓일 때만 거짓이 되며 , 그 외는 모두 참이 된다 .

• The binary disjunction operator “” (OR) combines two propositions

to form their logical disjunction.

논리합 사용의 예제• p = “My car has a bad engine.”, q = “My car has a bad carburetor.”

• pq = “My car has a bad engine, or my car has a bad carburetor.”

1.1 Logic

Page 11: 2012 년  봄학기 강원대학교  컴퓨터과학전공  문양세

Discrete Mathemat-icsby Yang-Sae Moon

Page 11

논리합 (Disjunction) (2/2)

Disjunction operator 의 truth tablep q pqT T TT F TF T TF F F

1.1 Logic

Page 12: 2012 년  봄학기 강원대학교  컴퓨터과학전공  문양세

Discrete Mathemat-icsby Yang-Sae Moon

Page 12

배타적 -OR (Exclusive-OR) (1/2)

배타적 -OR 의 정의• p 와 q 가 명제이면 , “p exclusive-or q” 도 명제이며 , 이를 p 와 q 의

배타적 -OR(exclusive-or) 라 하고 , pq 라 표기한다 .

이 명제는 p, q 중 어느 하나만이 참일 때만 참이 , 그 외는 모두 거짓이 된

다 .

• The binary exclusive-or operator “” (XOR) combines two proposi-

tions

to form their logical “exclusive or”.

배타적 -OR 사용의 예제• p = “I will earn an A in this course.”, q = “I will drop this course.”

• pq = “I will either earn an A for this course, or I will drop it (but not

both!).”

1.1 Logic

Page 13: 2012 년  봄학기 강원대학교  컴퓨터과학전공  문양세

Discrete Mathemat-icsby Yang-Sae Moon

Page 13

배타적 -OR (Exclusive-OR) (2/2)

Exclusive-OR operator 의 truth tablep q pqT T FT F TF T TF F F

1.1 Logic

Page 14: 2012 년  봄학기 강원대학교  컴퓨터과학전공  문양세

Discrete Mathemat-icsby Yang-Sae Moon

Page 14

함축 (Implication) (1/2)

함축의 정의• p 와 q 가 명제이면 , 함축 (implication) “pq” 도 명제이며 , 이 명제는 p

가 참이고 q 가 거짓일 경우에만 거짓이 되며 , 그 외는 모두 참이 된다 .

이때 , p 를 hypothesis, antecedent 라 부르고 , q 를 conclusion,

consequent 라 부른다 .

• The implication pq states that p implies q. That is, if p is true,

then q is true; but p is not true, then q could be either true or false.

함축 사용의 예제• p = “You study hard.”, q = “You will get a good grade.”

• pq = “If you study hard, then you will get a good grade.”

(else it could go either way)

1.1 Logic

Page 15: 2012 년  봄학기 강원대학교  컴퓨터과학전공  문양세

Discrete Mathemat-icsby Yang-Sae Moon

Page 15

함축 (Implication) (2/2)

Implication operator 의 truth tablep q pqT T TT F FF T TF F T

1.1 Logic

“pq” 를 표현하는 영어 문장• p implies q.• If p, then q.• p only if q.• p is sufficient for q.• q is necessary for p.

Page 16: 2012 년  봄학기 강원대학교  컴퓨터과학전공  문양세

Discrete Mathemat-icsby Yang-Sae Moon

Page 16

역 (converse), 이 (inverse), 대우(contrapositive)

역 , 이 , 대우의 정의• 역 (converse): q p• 이 (inverse): ¬p ¬q• 대우 (contrapositive): ¬q ¬p

역 , 이 , 대우의 예제• 명제 : “If it is raining, then the home team wins.”• 역 : “If the home team wins, then it is raining.”• 이 : “If it is not raining, then the home team does not win.”• 대우 : “If the home team does not win, then it is not raining.”

Converse/Inverse/Contrapositive 의 truth table

p q ¬p ¬q pq qp ¬p¬q ¬q¬pT T F F T T T TT F F T F T T FF T T F T F F TF F T T T T T T

1.1 Logic

동치 (equivalent)

Page 17: 2012 년  봄학기 강원대학교  컴퓨터과학전공  문양세

Discrete Mathemat-icsby Yang-Sae Moon

Page 17

상호조건명제 (Biconditional) (1/2)

상호조건명제의 정의• p 와 q 가 명제이면 , “p↔q” 를 상호조건명제 (biconditional) 라 하고 , p

와 q 가 동일한 진리 값을 가질 때 참이 되며 , 다른 진리 값을 가지면 거짓이

된다 .

• The biconditional p↔q states that p is true if and only if (IFF) q

is true.

• p↔q (pq)(qp) ¬(pq)

상호조건명제의 사용의 예제• p = “You can take the flight.”, q = “You buy a ticket.”

• p↔q = “You can take the flight if and only if you buy a ticket.”

1.1 Logic

Page 18: 2012 년  봄학기 강원대학교  컴퓨터과학전공  문양세

Discrete Mathemat-icsby Yang-Sae Moon

Page 18

상호조건명제 (Biconditional) (2/2)

Biconditional operator 의 truth tablep q p↔qT T TT F FF T FF F T

1.1 Logic

“p↔q” 를 표현하는 영어 문장• p if and only if q.• p is necessary and sufficient for q.• q is necessary and sufficient for p.

Page 19: 2012 년  봄학기 강원대학교  컴퓨터과학전공  문양세

Discrete Mathemat-icsby Yang-Sae Moon

Page 19

논리 연산자의 우선순위(Precedence)

우선 순위 테이블Operator Precedence

¬ 1 2 3 4↔ 5

1.1 Logic

우선 순위를 명확히 하기 위하여 괄호 “ ()” 를 사용

• ¬pq 는 (¬p)q 를 의미하며 , ¬(pq)를 의미하지 않는다 .

• pqr 은 (pq)r 를 의미하며 , p(qr)를 의미하지 않는다 .

Page 20: 2012 년  봄학기 강원대학교  컴퓨터과학전공  문양세

Discrete Mathemat-icsby Yang-Sae Moon

Page 20

Some Alternative Notations1.1 Logic

Name: not and or xor implies iff Propositional logic: Boolean algebra: p pq + C/C++/Java (wordwise): ! && || != == C/C++/Java (bitwise): ~ & | ^ Logic gates:

Page 21: 2012 년  봄학기 강원대학교  컴퓨터과학전공  문양세

Discrete Mathemat-icsby Yang-Sae Moon

Page 21

Logic and Bit Operations

비트 (bit) 란 binary digit( 이진수 ) 에서 따온 단어임• 비트는 1(true) 과 0(false) 의 값을 가짐• True 혹은 false 를 값으로 갖는 변수 (variable) 를 Boolean variable 이라 함

Bit operator(OR, AND, XOR) 의 truth table

1.1 Logic

Bit operation 의 예제

p q pq pq pq0 0 0 0 00 1 1 0 11 0 1 0 11 1 1 1 0

01 1011 011011 0001 1101

11 1011 1111 bitwise OR01 0001 0100 bitwise AND10 1010 1011 bitwise XOR