논리 ((g)Logic) - Kangwonysmoon/courses/2011_1/dm/01.pdf · 2016-06-02 ·...

21
이산수학 이산수학(Discrete Mathematics) (Discrete Mathematics) 이산수학 이산수학(Discrete Mathematics) (Discrete Mathematics) 논리 논리 (Logic) (Logic) 2011 2011년 봄학기 봄학기 강원대학교 강원대학교 컴퓨터과학전공 컴퓨터과학전공 문양세 문양세

Transcript of 논리 ((g)Logic) - Kangwonysmoon/courses/2011_1/dm/01.pdf · 2016-06-02 ·...

Page 1: 논리 ((g)Logic) - Kangwonysmoon/courses/2011_1/dm/01.pdf · 2016-06-02 · 논리논리연산자연산자(Logical Operator) (1/2) 1.1 Logic 논리연산자관련용어정의 •

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

20112011년년 봄학기봄학기

강원대학교강원대학교 컴퓨터과학전공컴퓨터과학전공 문양세문양세강원대학교강원대학교 컴퓨터과학전공컴퓨터과학전공 문양세문양세

Page 2: 논리 ((g)Logic) - Kangwonysmoon/courses/2011_1/dm/01.pdf · 2016-06-02 · 논리논리연산자연산자(Logical Operator) (1/2) 1.1 Logic 논리연산자관련용어정의 •

논리논리(Logic)(Logic)란란??1.1 Logic

논리(logic)란 수학적 표현의 의미를 정확하게 기술할 수 있게 함

논리는 회로 설계, 프로그램 작성, 프로그램 정확성 검증 등에 활용

Discrete Mathematicsby Yang-Sae MoonPage 2

Page 3: 논리 ((g)Logic) - Kangwonysmoon/courses/2011_1/dm/01.pdf · 2016-06-02 · 논리논리연산자연산자(Logical Operator) (1/2) 1.1 Logic 논리연산자관련용어정의 •

명제명제(Proposition)(Proposition)1.1 Logic

명제의 정의

• 명제란 참(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)• 2 + 2 = 5. (F)

• Seoul is the capital of Korea.

• 11213 is prime.

명제가 아닌 예제

• Who is there? (not declarative question)• Who is there? (not declarative, question)

• Just do it! (command)

• x + 2 = 5. (non-constant value, variable)

Discrete Mathematicsby Yang-Sae MoonPage 3

Page 4: 논리 ((g)Logic) - Kangwonysmoon/courses/2011_1/dm/01.pdf · 2016-06-02 · 논리논리연산자연산자(Logical Operator) (1/2) 1.1 Logic 논리연산자관련용어정의 •

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

논리 연산자 관련 용어 정의

• 하나 또는 여러 명제를 조합하여 새로운 수학적 명제를 만들 수 있으며, 이를

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

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

속사(connective)라 한다.

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

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

(truth value)을 취한다.

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

Discrete Mathematicsby Yang-Sae MoonPage 4

Page 5: 논리 ((g)Logic) - Kangwonysmoon/courses/2011_1/dm/01.pdf · 2016-06-02 · 논리논리연산자연산자(Logical Operator) (1/2) 1.1 Logic 논리연산자관련용어정의 •

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

Boolean Operator의 예

명칭(영어) 명칭(한글) Nickname Arity Symbol명칭(영어) 명칭(한글) Nickname Arity Symbol

Negation operator 부정 연산자 NOT Unary ¬

Conjunction operator 논리곱 연산자 AND Binary

Di j i 논리합 연산자 OR BiDisjunction operator 논리합 연산자 OR Binary

Exclusive-OR operator 배타적OR 연산자 XOR Binary

Implication operator 함축 연산자 IMPLIES Binary

Biconditional operator 상호조건 연산자 IFF Binary ↔

Discrete Mathematicsby Yang-Sae MoonPage 5

Page 6: 논리 ((g)Logic) - Kangwonysmoon/courses/2011_1/dm/01.pdf · 2016-06-02 · 논리논리연산자연산자(Logical Operator) (1/2) 1.1 Logic 논리연산자관련용어정의 •

부정부정(Negation) (1/2)(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.”이다.

Discrete Mathematicsby Yang-Sae MoonPage 6

Page 7: 논리 ((g)Logic) - Kangwonysmoon/courses/2011_1/dm/01.pdf · 2016-06-02 · 논리논리연산자연산자(Logical Operator) (1/2) 1.1 Logic 논리연산자관련용어정의 •

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

Negation operator의 truth table

p ¬pp ¬p

T F

F T

Operand column Result column

Discrete Mathematicsby Yang-Sae MoonPage 7

Page 8: 논리 ((g)Logic) - Kangwonysmoon/courses/2011_1/dm/01.pdf · 2016-06-02 · 논리논리연산자연산자(Logical Operator) (1/2) 1.1 Logic 논리연산자관련용어정의 •

논리곱논리곱(Conjunction) (1/2)(Conjunction) (1/2)1.1 Logic

논리곱의 정의

와 가 명제이면 “ d ”도 명제이며 이를 와 의 논리곱( j i )• p와 q가 명제이면, “p and q”도 명제이며, 이를 p와 q의 논리곱(conjunction)

이라 하고, pq라 표기한다.

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

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

to form their logical conjunctionto 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.”

Discrete Mathematicsby Yang-Sae MoonPage 8

Page 9: 논리 ((g)Logic) - Kangwonysmoon/courses/2011_1/dm/01.pdf · 2016-06-02 · 논리논리연산자연산자(Logical Operator) (1/2) 1.1 Logic 논리연산자관련용어정의 •

논리곱논리곱(Conjunction) (2/2)(Conjunction) (2/2)1.1 Logic

Conjunction operator의 truth tablep q pqp q p qT T TT F FF T FF F F

Discrete Mathematicsby Yang-Sae MoonPage 9

Page 10: 논리 ((g)Logic) - Kangwonysmoon/courses/2011_1/dm/01.pdf · 2016-06-02 · 논리논리연산자연산자(Logical Operator) (1/2) 1.1 Logic 논리연산자관련용어정의 •

논리합논리합(Disjunction) (1/2)(Disjunction) (1/2)1.1 Logic

논리합의 정의

와 가 명제이면 “ ”도 명제이며 이를 와 의 논리합(di j ti )이라• p와 q가 명제이면, “p or q”도 명제이며, 이를 p와 q의 논리합(disjunction)이라

하고, pq라 표기한다.

이 명제는 p, q가 모두 거짓일 때만 거짓이 되며, 그 외는 모두 참이 된다.이 명제는 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 ”• pq = My car has a bad engine, or my car has a bad carburetor.

Discrete Mathematicsby Yang-Sae MoonPage 10

Page 11: 논리 ((g)Logic) - Kangwonysmoon/courses/2011_1/dm/01.pdf · 2016-06-02 · 논리논리연산자연산자(Logical Operator) (1/2) 1.1 Logic 논리연산자관련용어정의 •

논리합논리합(Disjunction) (2/2)(Disjunction) (2/2)1.1 Logic

Disjunction operator의 truth tablep q pqp q p qT T TT F TF T TF F F

Discrete Mathematicsby Yang-Sae MoonPage 11

Page 12: 논리 ((g)Logic) - Kangwonysmoon/courses/2011_1/dm/01.pdf · 2016-06-02 · 논리논리연산자연산자(Logical Operator) (1/2) 1.1 Logic 논리연산자관련용어정의 •

배타적배타적--OR (ExclusiveOR (Exclusive--OR) (1/2)OR) (1/2)1.1 Logic

배타적-OR의 정의

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

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

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

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

to form their logical “exclusive or”.

배타적-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 • pq = I will either earn an A for this course, or I will drop it (but not

both!).”

Discrete Mathematicsby Yang-Sae MoonPage 12

Page 13: 논리 ((g)Logic) - Kangwonysmoon/courses/2011_1/dm/01.pdf · 2016-06-02 · 논리논리연산자연산자(Logical Operator) (1/2) 1.1 Logic 논리연산자관련용어정의 •

배타적배타적--OR (ExclusiveOR (Exclusive--OR) (2/2)OR) (2/2)1.1 Logic

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

Discrete Mathematicsby Yang-Sae MoonPage 13

Page 14: 논리 ((g)Logic) - Kangwonysmoon/courses/2011_1/dm/01.pdf · 2016-06-02 · 논리논리연산자연산자(Logical Operator) (1/2) 1.1 Logic 논리연산자관련용어정의 •

함축함축 (Implication) (1/2)(Implication) (1/2)1.1 Logic

함축의 정의

와 가 명제이면 함축(i li ti ) “ ”도 명제이며 이 명제는 가 참• p와 q가 명제이면, 함축(implication) “pq”도 명제이며, 이 명제는 p가 참

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

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

라 부른다.

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

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.”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)

Discrete Mathematicsby Yang-Sae MoonPage 14

( g y)

Page 15: 논리 ((g)Logic) - Kangwonysmoon/courses/2011_1/dm/01.pdf · 2016-06-02 · 논리논리연산자연산자(Logical Operator) (1/2) 1.1 Logic 논리연산자관련용어정의 •

함축함축 (Implication) (2/2)(Implication) (2/2)1.1 Logic

Implication operator의 truth tablep q pqp q p qT T TT F FF T TF F T

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

Discrete Mathematicsby Yang-Sae MoonPage 15

Page 16: 논리 ((g)Logic) - Kangwonysmoon/courses/2011_1/dm/01.pdf · 2016-06-02 · 논리논리연산자연산자(Logical Operator) (1/2) 1.1 Logic 논리연산자관련용어정의 •

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

역, 이, 대우의 정의

• 역(converse): q p

• 이(inverse): ¬p ¬q

• 대우(contrapositive): ¬q ¬p

역, 이, 대우의 예제

• 명제: “If it is raining, then the home team wins.”

역 “If th h t i th it i i i ”• 역: “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.”

동치(equivalent)

Converse/Inverse/Contrapositive의 truth tablep 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 T

Discrete Mathematicsby Yang-Sae MoonPage 16

F T T F T F F TF F T T T T T T

Page 17: 논리 ((g)Logic) - Kangwonysmoon/courses/2011_1/dm/01.pdf · 2016-06-02 · 논리논리연산자연산자(Logical Operator) (1/2) 1.1 Logic 논리연산자관련용어정의 •

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

상호조건명제의 정의

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

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

• The biconditional p↔q states that p is true if and only if (IFF) q is true• 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.”

Discrete Mathematicsby Yang-Sae MoonPage 17

Page 18: 논리 ((g)Logic) - Kangwonysmoon/courses/2011_1/dm/01.pdf · 2016-06-02 · 논리논리연산자연산자(Logical Operator) (1/2) 1.1 Logic 논리연산자관련용어정의 •

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

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

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

Discrete Mathematicsby Yang-Sae MoonPage 18

Page 19: 논리 ((g)Logic) - Kangwonysmoon/courses/2011_1/dm/01.pdf · 2016-06-02 · 논리논리연산자연산자(Logical Operator) (1/2) 1.1 Logic 논리연산자관련용어정의 •

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

우선 순위 테이블

Operator Precedence는 ( ) 를 의미하며 ( )를 의¬ 1

2 3

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

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

4↔ 5

의미하지 않는다.

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

Discrete Mathematicsby Yang-Sae MoonPage 19

Page 20: 논리 ((g)Logic) - Kangwonysmoon/courses/2011_1/dm/01.pdf · 2016-06-02 · 논리논리연산자연산자(Logical Operator) (1/2) 1.1 Logic 논리연산자관련용어정의 •

Some Alternative NotationsSome Alternative Notations1.1 Logic

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

Discrete Mathematicsby Yang-Sae MoonPage 20

Page 21: 논리 ((g)Logic) - Kangwonysmoon/courses/2011_1/dm/01.pdf · 2016-06-02 · 논리논리연산자연산자(Logical Operator) (1/2) 1.1 Logic 논리연산자관련용어정의 •

Logic and Bit OperationsLogic and Bit Operations1.1 Logic

비트(bit)란 binary digit(이진수)에서 따온 단어임

• 비트는 1(true)과 0(false)의 값을 가짐

• True 혹은 false를 값으로 갖는 변수(variable)를 Boolean variable이라 함

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

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

Bit operation의 예제

01 1011 011001 1011 011011 0001 1101

11 1011 1111 bitwise OR01 0001 0100 bitwise AND

Discrete Mathematicsby Yang-Sae MoonPage 21

01 0001 0100 bitwise AND10 1010 1011 bitwise XOR