720 likes | 733 Views
邏輯的世界 Logic. 陳鍾誠 2006 年於金門. 大綱 Outline. Boolean Logic ( 布林邏輯 ) First-Order Logic ( 一階邏輯 ). 何謂邏輯 ? What is Logic ?. A world of true and false. Data T , F. Function And (&) Or (|) Not (-). 邏輯系統的種類 Types of Logic. Propositional logic ( 命題邏輯 )
E N D
邏輯的世界Logic 陳鍾誠 2006 年於金門
大綱Outline • Boolean Logic (布林邏輯) • First-Order Logic (一階邏輯)
何謂邏輯?What is Logic ? • A world of true and false. • Data • T , F • Function • And (&) • Or (|) • Not (-)
邏輯系統的種類Types 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.
述詞邏輯Propositional Logic Propositional Logic is the logic of compound statements built from simpler statements using so-called Booleanconnectives. Some applications in computer science: • Design of digital electronic circuits. • Expressing conditions in programs. • Queries to databases & search engines. George Boole(1815-1864)
述詞邏輯的表示式Expressions of Propositional Logic • Use parentheses to group sub-expressions • Example : • m : male • c : child • m c : male child (boy) • Example : • f (g s)
自然語言的語義不清楚Natural 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.
運算五:導致The Implication 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)
pq 的真值表Implication Truth Table • p q is falseonly whenp is true but q is not true. • p q does not saythat pcausesq! • p q does not requirethat p or qare ever true! • E.g. “(1=0) pigs can fly” is TRUE!
Imply 運算 的範例Examples 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?
三種反運算Converse, Inverse, Contrapositive Some terminology, for an implication p q: • Its converseis: 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?
p q = -q -p 兩者相等 How do we know for sure? Proving the equivalence of p q and its contrapositive using truth tables:
p q = p + q = p+q 利用真值表來證明Proving Equivalence via Truth Tables • -(-p-q) = pq Ex. Prove that pq (p q). F T T T F T T F F T T F T F T T F F F T • Demorgan’s Theorem : (笛摩根定律)
p q 的真值表Biconditional 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.
布林運算總整理Boolean 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.
布林運算的幾種符號表達法Some Alternative Notations
Boolean Algebra- 把布林邏輯轉換為代數 陳鍾誠 2006 年於金門
位元運算Bits 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)
布林代數的基本運算Boolean Operator • Boolean Complement (-) 1=0 0=1 • Boolean Sum (+) • Boolean Product (‧) 1‧1=1 1‧0=0 0‧1=0 0‧0=0 1+1=1 1+0=1 0+1=1 0+0=0
布林集合Boolean Set • Boolean Set : B • B = {0,1} • Example : 0 • n tuple boolean set • Bn = {(x1, x2, …, xn)| xiB for 1 i n} • Example : • (0,0) • (0,1) • (1,0) • (1,1)
布林變數Boolean 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.
布林代數式Boolean 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
布林函數Boolean Function (1) • Boolean function of degree n • A function mapping from Bn to B • Example : • f(x,y) = xy
布林函數Boolean Function (2) • Drawing the truth table of • f(x,y,z) = xy + z
Some Applications of Boolean Logic 陳鍾誠 2006 年於金門
布林邏輯的應用Applications 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,
電路設計中的布林代數Boolean Algebra in Circuit Design • Truth Table (真值表) • Karnaugh Maps (卡諾圖)
QM布林化簡法Quine-McCluskey Method • Minimizing the boolean expression with any number of variable (10.4, pp. 727).
邏輯推論Logical Reasoning 陳鍾誠 2006 年於金門
問題Question • 要幾條邏輯推論規則才能推出所有真理呢 ? 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 ….
邏輯推論的歷史History of Proof System • Aristotle • Boole • Hilbert • Gentzen • Robinson
亞里斯多德Aristotle • 三段論 • http://zh.wikipedia.org/wiki/%E9%A1%B9%E9%80%BB%E8%BE%91
經典範例1 • 這個例子是亞里士多德給出的經典的 "Barbara" 三段論: • 如果所有人(M)都是必死的(P), (大前提) • 並且所有希臘人(S)都是人(M), (小前提) • 那麼所有希臘人(S)都是必死的(P). (結論)
經典範例2 • 還有, • 所有人都是必死的. (普遍原理) • 蘇格拉底是人. (特殊陳述) • 蘇格拉底是必死的. (把特殊(小)代換入一般(大))
型式 1 • P Q • Q R • PR
型式 2 • P • P Q • Q
Mr. 洪Mr. Horn • Horn Clause • P1 … Pk Q • P1 • … • Pk • Q
布爾George Boole • 真值表 • 從真值表可推出三段論嗎 ? • P • P Q • Q
Modus Ponens Hilbert
Axioms and Rules of Inference Gentzen
Disjunction rules Conjunction rules Gentzen’s Rules (1)
Gentzen’ Rules (2) • Implication rules • Negation rule