72
邏邏邏邏邏 邏邏邏邏邏 Logic Logic 邏邏邏 邏邏邏 2006 2006 邏邏邏邏 邏邏邏邏

邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

Embed Size (px)

Citation preview

Page 1: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

邏輯的世界邏輯的世界

LogicLogic

陳鍾誠 陳鍾誠 2006 2006 年於金門年於金門

Page 2: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

大綱大綱OutlineOutline

• Boolean Logic ( 布林邏輯 )

• First-Order Logic ( 一階邏輯 )

Page 3: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

何謂邏輯何謂邏輯 ??What is Logic ?What is Logic ?

• A world of true and false.

• Data–T , F

• Function–And (&)

–Or (|)

–Not (-)

Page 4: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

邏輯系統的種類邏輯系統的種類Types of LogicTypes of Logic

• Propositional logic ( 命題邏輯 )– Also known as Boolean Logic (§1.1-1.2):– Basic definitions. (§1.1)– Equivalence rules & derivations. (§1.2)

• Predicate logic ( 述詞邏輯 或 謂詞邏輯 )– Also known as First-Order Logic (§1.3-1.4)– Predicates.– Quantified predicate expressions.– Equivalences & derivations.

Page 5: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

述詞邏輯述詞邏輯Propositional LogicPropositional Logic

Propositional Logic is the logic of compound statements built from simpler statements using so-called Boolean connectives.

Some applications in computer science:• Design of digital electronic circuits.• Expressing conditions in programs.• Queries to databases & search engines.

George Boole(1815-1864)

Page 6: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

述詞邏輯的基本運算述詞邏輯的基本運算Propositional Logic – OperatorsPropositional Logic – Operators

Formal Name Nickname Arity Symbol

Negation operator NOT Unary ¬

Conjunction operator AND Binary

Disjunction operator OR Binary

Exclusive-OR operator XOR Binary

Implication operator IMPLIES Binary

Biconditional operator IFF Binary ↔

Page 7: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

運算一:反相運算一:反相Negation operator - NOTNegation operator - NOT

p pT FF T

Page 8: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

運算二:及運算二:及Conjunction operator – ANDConjunction operator – AND

p q p qF F FF T FT F FT T T

Page 9: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

運算三:或運算三:或Disjunction operator – ORDisjunction operator – OR

p q p qF F FF T TT F TT T T

Page 10: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

述詞邏輯的表示式述詞邏輯的表示式Expressions of Propositional LogicExpressions of Propositional Logic

• Use parentheses to group sub-expressions– Example :

• m : male• c : child• m c : male child (boy)

– Example : • f (g s)

Page 11: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

運算四:互斥或運算四:互斥或Exclusive-Or – XORExclusive-Or – XOR

p q pqF F FF T TT F TT T F

Page 12: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

自然語言的語義不清楚自然語言的語義不清楚Natural Language is AmbiguousNatural Language is Ambiguous

Note that English “or” can be ambiguous regarding the “both” case!

“Pat is a singer orPat is a writer.” -

“Pat is a man orPat is a woman.” -

Need context to disambiguate the meaning!

For this class, assume “or” means inclusive.

p q p "or" qF F FF T TT F TT T ?

Page 13: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

運算五:導致運算五:導致The The ImplicationImplication Operator Operator

• p q means p implies q.– If p is true, then q is true;– but if p is not true, then q could be either true or false.

• Example :– E.g., let p = “You study hard.”

q = “You will get a good grade.”– p q = “If you study hard, then you will get a good

grade.” (else, it could go either way)

Page 14: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

ppq q 的真值表的真值表Implication Truth TableImplication Truth Table

• p q is false only whenp is true but q is not true.

• p q does not saythat p causes q!

• p q does not requirethat p or q are ever true!

• E.g. “(1=0) pigs can fly” is TRUE!

p q p q F F T F T T T F F T T T

Page 15: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

Imply Imply 運算 運算 的範例 的範例Examples of ImplicationsExamples of Implications

• “If this lecture ends, then the sun will rise tomorrow.” True or False?

• “If Tuesday is a day of the week, then I am a penguin.” True or False?

• “If 1+1=6, then Bush is president.” True or False?

• “If the moon is made of green cheese, then I am richer than Bill Gates.” True or False?

Page 16: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

三種反運算三種反運算Converse, Inverse, ContrapositiveConverse, Inverse, Contrapositive

Some terminology, for an implication p q:• Its converse is: q p.

• Its inverse is: ¬p ¬q.

• Its contrapositive: ¬q ¬ p.

• One of these three has the same meaning (same truth table) as p q. Can you figure out which?

Page 17: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

p p q = -q q = -q -p -p 兩者相等兩者相等How do we know for sure?

Proving the equivalence of p q and its contrapositive using truth tables:

p q q p p q q pF F T T T TF T F T T TT F T F F FT T F F T T

Page 18: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

利用真值表來證明利用真值表來證明Proving Equivalence via Truth TablesProving Equivalence via Truth Tables

• -(-p-q) = pq

Ex. Prove that pq (p q).p q pp qq pp qq pp qq ((pp qq))F FF TT FT T

FT

TT

T

T

T

TTT

FF

F

F

FFF

F

TT

• Demorgan’s Theorem : (笛摩根定律 )

p q = p + q = p+q

Page 19: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

p p q q 的真值表的真值表Biconditional Truth TableBiconditional Truth Table

• p q means that p and qhave the same truth value.

• Note this truth table is theexact opposite of ’s!– p q means ¬(p q)

• p q does not implyp and q are true, or cause each other.

p q p qF F TF T FT F FT T T

Page 20: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

布林運算總整理布林運算總整理Boolean Operations SummaryBoolean Operations Summary

• We have seen 1 unary operator (out of the 4 possible) and 5 binary operators (out of the 16 possible). Their truth tables are below.

p q p p q p q pq p q pqF F T F F F T TF T T F T T T FT F F F T T F FT T F T T F T T

Page 21: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

布林運算的幾種符號表達法布林運算的幾種符號表達法Some Alternative NotationsSome Alternative Notations

Name: notandorxorimplies iffPropositional logic: Boolean algebra: ppq+C/C++/Java (wordwise):!&&||!= ==C/C++/Java (bitwise): ~&|^Logic gates:

Page 22: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

Boolean AlgebraBoolean Algebra

- - 把布林邏輯轉換為代數把布林邏輯轉換為代數

陳鍾誠 陳鍾誠 2006 2006 年於金門年於金門

Page 23: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

位元運算位元運算Bits and Bit OperationsBits and Bit Operations

• A bit is a binary (base 2) digit: 0 or 1.

• Bits may be used to represent truth values.

• By convention: 0 represents “false”; 1 represents “true”.

• Boolean algebra is like ordinary algebra except that variables stand for bits, + means “or”, and multiplication means “and”.– See chapter 10 for more details.

John Tukey(1915-2000)

Page 24: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

布林代數的基本運算布林代數的基本運算Boolean OperatorBoolean Operator

• Boolean Complement (-)

1+1=11+0=10+1=10+0=0

• Boolean Product ( )‧

1‧1=11‧0=00‧1=00‧0=0

• Boolean Sum (+)

1=0 0=1

Page 25: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

布林集合布林集合Boolean SetBoolean Set

• Boolean Set : B– B = {0,1}– Example : 0

• n tuple boolean set– Bn = {(x1, x2, …, xn)| xi B for 1 i n}– Example :

• (0,0)• (0,1)• (1,0)• (1,1)

Page 26: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

布林變數布林變數Boolean VariableBoolean Variable

• The variable x is called a boolean variable if it assume values only from B, that is , if its only possible value are 0 and 1.

Page 27: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

布林代數式布林代數式Boolean ExpressionBoolean Expression

• Boolean expression– 0,1,x1,x2,…,xn

– If E1 and E2 are Boolean expression, then the following expressions are boolean expressions

• E1• (E1E2)• (E1+E2)

• Example :– 0– x– (1+x)– (x+y)(zy)

Counter example ( 反例)

xy+)(+z

Page 28: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

布林函數布林函數Boolean Function (1)Boolean Function (1)

• Boolean function of degree n– A function mapping from Bn to B

• Example :– f(x,y) = xy

Page 29: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

布林函數布林函數Boolean Function (2)Boolean Function (2)

• Drawing the truth table of – f(x,y,z) = xy + z

Page 30: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

Some Applications of Some Applications of Boolean LogicBoolean Logic陳鍾誠 陳鍾誠 2006 2006 年於金門年於金門

Page 31: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

布林邏輯的應用布林邏輯的應用Applications of Boolean LogicApplications of Boolean Logic

• Circuit Design : – Building Truth Table– Minimizing the number of circuit

• By Karnaugh Maps ( 卡諾圖 )

• Database Querying

• Logical Inference in Artificial Intelligence– An extension of Boolean Logic called

First-Order Logic• Example : Prolog,

Page 32: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

電路設計中的布林代數電路設計中的布林代數Boolean Algebra in Circuit DesignBoolean Algebra in Circuit Design

• Truth Table ( 真值表 )

• Karnaugh Maps ( 卡諾圖 )

Page 33: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

卡諾圖化簡方法卡諾圖化簡方法Karnaugh MapsKarnaugh Maps

1

1 1

B2 B1B0

0 1

0 0

0 1

1 1

1 0

1

1 1

B2 B1B0

0 1

0 0

0 1

1 1

1 0

Page 34: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

QM布林化簡法QM布林化簡法Quine-McCluskey MethodQuine-McCluskey Method

• Minimizing the boolean expression with any number of variable (10.4, pp. 727).

Page 35: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

Circuit Design - AdderCircuit Design - Adder

Page 36: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

邏輯推論邏輯推論

Logical ReasoningLogical Reasoning

陳鍾誠 陳鍾誠 2006 2006 年於金門年於金門

Page 37: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

問題問題QuestionQuestion

• 要幾條邏輯推論規則才能推出所有真理呢 ?p T p p F p

p T T p F F

p p p p p p

p p

p q q p p q q p(p q) r p (q r)(p q) r p (q r)p(qr) (pq)(pr)p(qr) (pq)(pr)(pq) p q

(pq) p q

….

Page 38: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

邏輯推論的歷史邏輯推論的歷史History of Proof SystemHistory of Proof System

• Aristotle

• Boole

• Hilbert

• Gentzen

• Robinson

Page 39: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

亞里斯多德亞里斯多德Aristotle Aristotle

• 三段論– http://zh.wikipedia.org/wiki/%E9%A1%B9%E9

%80%BB%E8%BE%91

Page 40: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

經典範例經典範例 11

這個例子是亞里士多德給出的經典的 "Barbara" 三段論 :如果所有人 (M)都是必死的 (P), (大前提 ) 並且所有希臘人 (S)都是人 (M), (小前提 ) 那麼所有希臘人 (S)都是必死的 (P). (結論 )

Page 41: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

經典範例經典範例 22

還有,所有人都是必死的 . ( 普遍原理 ) 蘇格拉底是人 . ( 特殊陳述 ) 蘇格拉底是必死的 . ( 把特殊 ( 小 ) 代換入一般 ( 大 ))

Page 42: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

型式 型式 11

P QQ R

PR

Page 43: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

型式 型式 22

PP Q

Q

Page 44: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

Mr. Mr. 洪洪Mr. HornMr. Horn

• Horn Clause

P1 … Pk Q P1 … Pk

Q

Page 45: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

布爾布爾George Boole George Boole

• 真值表

• 從真值表可推出三段論嗎 ?

P P Q

Q

Page 46: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

HilbertHilbert

• Modus Ponens

Page 47: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

Hilbert’s AxiomHilbert’s Axiom

Page 48: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

Gentzen

• Axioms and Rules of Inference

Page 49: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

Gentzen’s Rules (1)

• Disjunction rules

• Conjunction rules

Page 50: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

Gentzen’ Rules (2)

• Implication rules

• Negation rule

Page 51: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

CompletenessCompleteness

• Gentzen’s Rules are complete

– All logical theorem can be proofed from these rules.

Page 52: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

RobinsonRobinson

• Resolution Proof :

P Q ; -P R

Q R

Page 53: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

Robinson – second formRobinson – second form

-P Q ; P R

Q R

Page 54: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

CompletenessCompleteness

• Robinson’s Rule is Complete under the resolution procedure.

• Refutation– Proof by contradiction

Page 55: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

ExampleExample

Page 56: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

QuestionQuestion

P Q -PR

QS RS

Is S true under these rules ?

Page 57: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

Question in Question in - -

-P Q P R-Q S -R S

Page 58: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

ProofProof-P Q P R-Q S-R S -S

-Q

-P

R

S

Page 59: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

ReferenceReference

• Symbolic Logic– http://en.wikipedia.org/wiki/Symbolic_logic

• 三段論– http://zh.wikipedia.org/wiki/%E4%B8%89%E6

%AE%B5%E8%AB%96

Page 60: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

邏輯式之間的相等關係邏輯式之間的相等關係

Page 61: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

述詞邏輯述詞邏輯 == 布林代數的邏輯系統布林代數的邏輯系統• 述詞邏輯的表示式

(Expression in Propositional Logic)

– f (g s)

• 布林代數的表示式 (Boolean Expression)– f (g + s)

Page 62: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

相等關係的推導相等關係的推導Equivalence LawsEquivalence Laws

• These are similar to the arithmetic identities you may have learned in algebra, but for propositional equivalences instead.

• They provide a pattern or template that can be used to match all or part of a much more complicated proposition and to find an equivalence for it.

Page 63: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

相等關係的範例 相等關係的範例 (1)(1)Equivalence Laws - ExamplesEquivalence Laws - Examples

• Identity:p T p p F p

• Domination:p T T p F F

• Idempotent:p p p p p p

Page 64: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

相等關係的範例 相等關係的範例 (2)(2)Equivalence Laws - ExamplesEquivalence Laws - Examples

• Double negation: p p

• Commutative: p q q p p q q p

• Associative: (p q) r p (q r)(p q) r p (q r)

Page 65: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

更多的相等關係 更多的相等關係 (1) (1) More Equivalence LawsMore Equivalence Laws

• Distributive: p(qr) (pq)(pr)p(qr) (pq)(pr)

• De Morgan’s:(pq) p q

(pq) p q Augustus

De Morgan(1806-1871)

Page 66: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

更多的相等關係 更多的相等關係 (2) (2) More Equivalence LawsMore Equivalence Laws

• Trivial tautology/contradiction:

p p T

p p F

Page 67: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

以相等關係做為運算的定義以相等關係做為運算的定義 (1)(1)Defining Operators via EquivalencesDefining Operators via Equivalences

Using equivalences, we can define operators in terms of other operators.

• Exclusive or:

p q ( p q ) ( p q )

p q ( p q ) ( q p )

Page 68: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

以相等關係做為運算的定義以相等關係做為運算的定義 (2)(2)Defining Operators via EquivalencesDefining Operators via Equivalences

• Implies: p q p q

• Biconditional:

p q ( p q ) ( q p )

p q ( p q )

Page 69: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

一個很長推論的範例一個很長推論的範例An Example ProblemAn Example Problem

• Check using a symbolic derivation whether

(p q) (p r) p q r.

(p q) (p r)

[Expand definition of ] (p q) (p r)

[Defn. of ] (p q) ((p r) (p r))

[DeMorgan’s Law]

(p q) ((p r) (p r))

[associative law] cont.

Page 70: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

繼續推論繼續推論……Example Continued...Example Continued...

(p q) ((p r) (p r)) [ commutes]

(q p) ((p r) (p r)) [ associative]

q (p ((p r) (p r))) [distrib. over ]

q (((p (p r)) (p (p r)))

[assoc.] q (((p p) r) (p (p r)))

[trivail taut.] q ((T r) (p (p r)))

[domination] q (T (p (p r)))

[identity] q (p (p r)) cont.

Page 71: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

終於推導完畢 終於推導完畢 End of Long ExampleEnd of Long Example

q (p (p r))

[DeMorgan’s] q (p (p r))

[Assoc.] q ((p p) r)

[Idempotent] q (p r)

[Assoc.] (q p) r

[Commut.] p q r

Q.E.D. (quod erat demonstrandum)

Page 72: 邏輯的世界 Logic 陳鍾誠 2006 年於金門 大綱 Outline Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 )

回顧:述詞邏輯回顧:述詞邏輯

• Atomic propositions: p, q, r, …

• Boolean operators:

• Compound propositions: s : (p q) r

• Equivalences: pq (p q)

• Proving equivalences using:

– Truth tables.

– Symbolic derivations. p q r …