Presentation is loading. Please wait.

Presentation is loading. Please wait.

15-251 Great Theoretical Ideas in Computer Science.

Similar presentations


Presentation on theme: "15-251 Great Theoretical Ideas in Computer Science."— Presentation transcript:

1 15-251 Great Theoretical Ideas in Computer Science

2 Proofs and Logic Lecture 10 (September 23, 2010) P, P  Q Q

3 1+1 = 2 do we need a proof?

4 In mathematics, sometimes your intuition can be dead wrong. We know that 1  2 But here’s a theorem of Banach & Tarski: A solid ball in 3-dimensions can be cut up into a finite number of pieces, so that these pieces can be moved around and assembled into two identical copies of the original ball. Not possible in 1 or 2 dimensions, btw.

5 So it really pays off to: Formalize concepts, give precise definitions Make implicit assumptions explicit Write careful proofs, where every step can be checked carefully. Even “mechanically” using a “computing machine”, if you will

6 What is a proof?

7 3. Math. and Logic. A sequence of steps by which a theorem or other statement is derived from given premises. 1. a. Something that proves a statement; evidence or argument establishing a fact or the truth of anything, or belief in the certainty of something; an instance of this. Let’s ask the OED

8 What is a proof? Intuitively, a proof is a sequence of “statements”, each of which follows “logically” from some of the previous steps. What are “statements”? What does it mean for one to follow “logically” from another?

9 We’ll lay the groundwork for these questions in today’s lecture… But we will come back to these questions again later…

10 Propositions A proposition is a statement that is either true or false. snow is white 2+2 = 5 Socrates had six digits on his left hand the summer solstice occurs on June 21 st

11 Propositions A proposition is a statement that is either true or false. snow 2+2 is xadk keosign sziable?

12 Complex Statements If snow is white then the sun rises in the west Socrates was bald and Cicero ate a pie 2 + 2 = 5 if and only if 4 + 4 = 9 Snow is not white

13 Complex Statements snow is white  the sun rises in the west Socrates was bald  Cicero ate a pie 2 + 2 = 5  4 + 4 = 9  (Snow is white)

14 Well-Formed Statements Every “simple” proposition is a well-formed propositional statement If A and B are well-formed so are (A  B), (A  B),  A, (A  B), (A  B) and or notif… thenif and only if

15 The “meaning” of these connectives (A  B) “A and B” (A  B) “A or B”  A“not A” true if both A and B are true true if at least one of A and B is true true if A is false ABAÆBAÆB TTT TFF FTF FFF AB A  B TTT TFT FTT FFF A AA TF FT

16 The “meaning” of these connectives (A  B)“if A then B” what are the rules for this? “A implies B”

17 The “meaning” of these connectives (A  B)“if A then B” (A  B)“A if and only if B” what are the rules for this? AB ABAB TTT TFF FTT FFT “A implies B” same as (A  B) and (B  A) AB ABAB TTT TFF FTF FFT

18 If snow is white then grass is green. Therefore, grass is green. Snow is white. Which of the following are true? Snow is white. If snow is white then grass is green. Therefore, grass is green.

19 Which of the following are true? The orchestra will not play both Bach and Haydn. The orchestra will not play Bach. Therefore, the orchestra will play Haydn.

20 Let’s abstract out the underlying mathematical structure…

21 Well-Formed Propositional Formulas If A and B are well-formed so are (A  B), (A  B),  A, (A  B), (A  B) p? Is  (p   q) well formed? The truth values T and F are well-formed All variables p, q, p 1, p 2, … are well-formed (p   (  q))? (p  q)  (  p  q)?

22 (Well-Formed) Propositional Formulas Each propositional formula B on n variables defines a function f B from {T,F} n to {T,F}. How is this function defined? Inductively.

23 Tautologies (a.k.a. Truths) A propositional formula B is a tautology if it is true for every setting of the variables T p p  q p   p p   p (  p  q)  (p  q) F (p  q)  (q  p) (p  q)  ((p  q)  (q  p))

24 Checking for Tautologies Evaluate the propositional formula B on every input in {T,F} n How?

25 E.g., B = (p Æ (p  q))  q pq p  qp Æ (p  q))(p Æ (p  q))  q TT TF FT FF

26 E.g., B = (p Æ (p  q))  q pq p  qp Æ (p  q))(p Æ (p  q))  q TTTTT TFFFT FTTFT FFTFT

27 Truth Table for formula B Create a table with 2 n rows p 1 =T, p 2 =T, p 3 =T…, p n =T p 1 =F, p 2 =T, p 3 =T…, p n =T p 1 =T, p 2 =F, p 3 =T…, p n =T p 1 =F, p 2 =F, p 3 =F…, p n =F... Evaluate the function for each setting B(T,T,T,…,T) B(F,T,T,…,T) B(T,F,T,…,T)... B(F,F,F,…,F) Takes at least 2 n time

28 Recursive Evaluation for B eval(formula B, setting M) { If (B == “T”) return T; if (B == “F”) return F; if (B == “B 1 Æ B 2 ”) return eval(B 1,M) Æ eval(B 2,M); … }

29 OK, quick recap propositional formulas a formula maps each possible “world” in {T,F} n into either T or F some formulas are “truths” (tautologies): they are true in all possible 2 n worlds can check if a formula is a tautology in ¼ 2 n time.

30 What is a proof? The truth table gives us a “proof” that a propositional formula is a tautology What are the pros of this proof technique? What are the cons?

31 ( (p 1  p 2 )  (p 2  p 3 )  …  (p n-1  p n ) )  (p 1  p n ) Does not give much “intuition” Even simple things have very long proofs has truth-table of size 2 n Does not scale to non-Boolean proofs. Later we will want to prove things about all the naturals, then we’re in trouble with brute-force.

32 A “more natural” way to prove things… Let us start with a simple tautology we’ll call this an “axiom” And use one of these rules at each step: Whatever we can prove, we’ll call “theorems” A Ç (B Ç C) (A Ç B) Ç C A Ç A A A B Ç A (A Ç B), (  A Ç C) (B Ç C) (  A Ç A) we’ll call these “inference rules” associativity contraction expansion cut rule

33 Proof of commutativity rule A Ç B B Ç A A Ç B(hypothesis)  A Ç A(axiom) B Ç A(cut rule to 1,2) (1) (2)

34 Proof of new expansion rule A(hypothesis) B Ç A(expansion rule) A Ç B (commutativity) A A Ç B

35 Proof of “modus ponens” A, A  B B A(hypothesis) A  B (hypothesis)  A Ç B (def. of  ) A Ç B(apply expansion to 1) B Ç B(cut rule to 2,3) B(contraction) Since the logical system does not have “  ” we define it to be  A Ç B (1) (2) (3)

36 What is a proof? A sequence of statements, each of which is an axiom, or a hypothesis, or follows from previous statements using an inference rule

37 Another recap (well-formed) propositional formulas some formulas are tautologies (“truths”) p Ç  p (p Æ (p  q))  q some formulas are “theorems” p Ç  p (p Æ (p  q))  q can check by truth-table these are formulas for which we can give proofs

38 Are all theorems “true” (i.e., tautologies)? Are all tautologies theorems? Yes. (easy proof by induction) Yes. (much more involved proof) Yay! Our logical system is “sound”. We only prove truths. Double yay! Our logical system is “complete”. We can prove all the truths via inference rules. For this logical system and Boolean formulas

39 The high-level picture

40 A Logical System A “logic” consists of: 1)A collection S of well-formed sentences 2)Some sentences in S called “axioms” 3)A set of “rules of inference” A “truth concept” consists of: 1)A collection S of well-formed sentences 2)Some sentences in S called “truths”

41 A Logical System for Propositions Axiom: Inference Rules: A Ç (B Ç C) (A Ç B) Ç C A Ç A A A B Ç A (A Ç B), (  A Ç C) (B Ç C) (  A Ç A) associativity contraction expansion cut rule

42 This logical system is sound and complete for propositional truths (tautologies) “all theorems are true” “all truths are theorems”

43 Another (Toy) Example

44 Example: Balanced Parens Consider strings of parentheses Well-formed string: Has an equal number of “(”s and “)”s Truths: The parens are balanced. E.g., ))))((((, (), )()()()(, ² E.g., (((()))), (), ²

45 Example: Balanced Parens A Logical System: Axiom: ² Rules of inference: Theorems are those strings of parens that can obtained via this logical system A (A) A, B AB

46 Example: Balanced Parens Proof of theorem “(())()” ² (axiom) ()(rule 1) (())(rule 1 again) (())()(rule 2) A Logical System: Axiom: ² Rules of inference: A (A) A, B AB

47 Example: Balanced Parens Truth concept: The parens are balanced. The logical system with one axiom and two rules of inference In HW2, you showed this logical system is sound and complete for this truth concept! You also showed: another system was sound, but not complete!

48 Onwards and Upwards!

49 Propositional logic is fine in its place but it does not capture too much… Socrates is a human. All humans are crazy. Hence Socrates is crazy. E.g., Or 8 x, y ((x < y)  (x+1 < y+1) H(s) 8 x H(x)  C(x)  C(s)

50 First Order Logics Have variables, and usual logical operators But variables can range over more general structures Can have functions, relations and predicates and quantifiers 8 x  y P(x)  Q(y)

51 One concrete example Let’s say we want a language for arithmetic that captures statements like: 16 is even Every natural number is either even or odd “  natural x such that 2*x = 16” “  natural x ( (  natural y such that 2*y = x) Ç (  natural z such that 2*z+1 = x) ) Need quantifiers, “=”, “+”, (“–” ?), “*”, “<” and we need the naturals 0,1,2,… too!

52 Peano Arithmetic The Peano axioms formally define properties of the natural numbers

53 a) 0 is a natural number. d) For all natural numbers m and n, if S(m) = S(n), then m = n. b) For every natural number n, its “successor” S(n) is a natural number. c) For every natural number n, S(n) ≠ 0. Peano Arithmetic

54 h) If n is a natural number and n = m, then m is also a natural number. e) For every natural n, n = n f) For all naturals, if n = m, then m = n. g) For all naturals if k = m and m = n then k = n. Peano Arithmetic

55 Peano: Inductive Definition of +  = { 0, S0, SS0, SSS0,...} Inductive definition of addition (+): X, Y 2  ) X “+” 0 = X X “+” SY = S(X “+” Y)

56 S0 + S0 = SS0 (i.e., “1+1=2”) Proof: S0 + S0 = S(S0 + 0) = S(S0) = SS0

57 Peano: Inductive Definition of *  = { 0, S0, SS0, SSS0,...} Inductive definition of multiplication (*): X, Y 2  ) X “*” 0 = X X “*” SY = (X “*” Y) “+” X

58 Defining < for  : 8 x, y 2  “x > y” is TRUE  “y < x” is FALSE “x > y” is TRUE  “y > x” is FALSE “x+1 > 0” is TRUE “x+1 > y+1” is TRUE ) “x > y” is TRUE Peano: Defining “<”

59 Defining partial minus for  : 8 x,y 2  x – 0 = x x > y ) (x+1) – (y+1) = x-y Peano: Defining “minus”

60 Peano: and so on… You can build an edifice for arithmetic to conceivably prove all arithmetic truths and use this logical system Thm: the Peano system is sound for arithmetic Q: Is it complete?

61 We’ll be back…

62 Here’s What You Need to Know… Propositional Logic well-formed expressions truth tables tautologies Logical Systems truths theorems soundness and completeness First-order Logics quantifiers Peano’s axioms


Download ppt "15-251 Great Theoretical Ideas in Computer Science."

Similar presentations


Ads by Google