* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download CPS130, Lecture 1: Introduction to Algorithms
Mathematical logic wikipedia , lookup
Modal logic wikipedia , lookup
Foundations of mathematics wikipedia , lookup
Gödel's incompleteness theorems wikipedia , lookup
Quantum logic wikipedia , lookup
Peano axioms wikipedia , lookup
Intuitionistic logic wikipedia , lookup
Interpretation (logic) wikipedia , lookup
Analytic–synthetic distinction wikipedia , lookup
Axiom of reducibility wikipedia , lookup
Naive set theory wikipedia , lookup
Propositional formula wikipedia , lookup
History of the function concept wikipedia , lookup
Mathematical proof wikipedia , lookup
Boolean satisfiability problem wikipedia , lookup
List of first-order theories wikipedia , lookup
Propositional calculus wikipedia , lookup
Natural deduction wikipedia , lookup
Law of thought wikipedia , lookup
Truth-bearer wikipedia , lookup
Canonical normal form wikipedia , lookup
9/24/2002 CPS130, Lecture 9-10; Propositional Logic, Boolean Algebra, Proofs; Integers and Induction 1. Introduction Much of the material to be presented this week will be a review, but it is so important that I feel this is justified. For example, when I taught cps 196, Discrete Mathematics, Fall 2001, some students who had already taken cps130 did not feel entirely comfortable with this material. To make the presentation more interesting, and perhaps a bit unique, I will do propositional logic and Boolean expressions together since they are really the same and their generalization to Boolean Algebras is also equivalent to set theory for finite sets. I will leave the set theory interpretation mainly to you with an occasional comment. I will develop mathematical induction by assuming the properties of the integers. As I hinted in L1, one can really start with the properties of the natural numbers and the “successor set axiom”, but our approach will review these integer properties and allow us to get everything done succinctly. 2. Propositional Logic and Boolean Expressions Definition 1P: A proposition is a statement that is either true or false but not both. For example, “Betsy is a smart dog”, is a proposition that is true. We might call it p1. Definition 1B: A Boolean expression is a variable, say xi, which takes on value xi = 1 or xi = 0 but not both. We could be more precise by saying that propositions are functions from the set of statements, S, to the set {t,f}; i.e, p: S {t,f}. Similarly Boolean expressions x: L {0,1}. L is sometimes called the set of “literals.” The set of propositions can be expanded by allowing for compound statements built from statements and connectives. Consider the two connectives, (conjunction) and (disjunction). They are defined by their truth tables as follows: p q pq p q pq T T F F T F T F T F F F T T F F T F T F T T T F 1 The conjunction of p and q is the statement “p and q”; the disjunction is “p or q”. The negation of p (“not p”), written as p , is considered as another connective or if p is a proposition, p can be considered as a proposition with the “opposite” truth value (F for T and T for F). To other important connectives are: p q (conditional) and p q (biconditional) with truth tables p q T T F F T F T F pq T F T T p q pq T T F F T F T F T F F T In English, the conditional means “if p, then q”, “p implies q”, “p only if q”, “p is sufficient for q”, or “q is necessary for p”. The biconditional means “p if and only if q”or “p is necessary and sufficient for q” and is often written “p iff q”. Associated with the conditional, p q , are the statements: converse, inverse, and contrapositive of the conditional that are written as q p, p q, and q p , respectively. For compound statements, we also have the notion of logical equivalence. We say that two compound propositions P and Q made from propositions p1, p2, …, pn are logically equivalent if they have the identical truth values for all truth values of the pi; we write P Q. Example 1: p q p q Example 2 : p q (p q) (q p) (p q) (q p) (p q) (p q) Let T a proposition that is always true, called a tautology, and F be a proposition that is always false, called a contradiction. For example p p is a tautology while p p is a contradiction. The following is a summary of the rules, which can individually be verified using truth tables. Theorem P idempotent : pp p pp p double negation: (p) p De Morgan: (p q) p q (p q) p q 2 commutative: pq qp pq qp associative p (q r) (p q) r p (q r) (p q) r distributive: p (q r) (p q) (p r) p (q r) (p q) (p r) contapositive equivalence p q q p example1 example2 p q p q p q (p q) (q p) (p q) (q p) (p q) (p q) tautology contradiction pT p pF F pT T p p T p p F ppT We turn now to Boolean expressions that will turn out to be equivalent to the compound sentences discussed above but now the emphasis will be different. The logical connectives, conditional and bicondidtional, so important in the concept of “valid argument” or proof, will be deemphasized to be replace by the function viewpoint. These functions take the set 2 = {0,1} back into 2 . First we consider three fundamental “gates”; that is, elementary functions again called And, Or, and Not (or inverter). And and Or take two arguments (binary function) while Not has one argument (unary function). 3 Not ( ) is clear: (NT) Not(0) = 1 and Not(1) = zero. The “addition table” for Or (+) and “multiplication table” for And ( ) are (AO) 1 0 1 1 1 0 1 0 and 1 0 1 1 0 0 0 0 respectively. Note that these operations are implicitly assumed to be commutative. The Not, And , and Nor functions are commonly called combinatorial circuits; their implementation as modern solid-state devices are commonly called gates. A Boolean expression is defined recursively as: (BE) if X1 and X2 are Boolean expressions, then Not(Xi), And(X1,X2) and Or(X1,X2) are Boolean expressions. Since Boolean expressions are functions, each input must have a unique output. When more elaborate functions are expressed using a set of “basic” gates (circuits), the expansion of the functions in these gates is again a combinatorial circuit. Example 3: Not(OR(And(x1,x2), x3) is the circuit for the Boolean expression (function) y = (x1 x 2 x 3 ) (often the is omitted). We anticipate that circuits for Boolean functions may not be unique. Example 4: Using DeMorgan (below), y = (x1 x2)´ x3´; hence And(Not(And(x1, x2)),Not(x3)) also computes y but uses 4 gates. HOMEWORK3: Worse still, show that the equivalent y = (x1´+ x2´) x3´ uses 5 gates. We see that “gates” and “combinatorial circuits” (or just circuits) are often used interchangeably; they implement, at some level, Boolean functions (or expressions). The “rules” for our Not, And, and Or gates are exactly analogous to Theorem P above, but we omit the conditional and biconditional identities. Since we are dealing with functions we replace " " by " " ; also T 1 and F = 0 . 4 Theorem B idempotent : x xx xx x double negation: (x) x De Morgan: (x y) x y (x y) x y commutative: xy yx x yy x associative x (y z) (x y) z x (y z) (x y) z distributive: x (y z) (x y) (y z) x (y z) (x y) (y z) identity complement x 1 x x0 x x 1 1 x 00 x x 1 x x 0 There are now two remaining details to consider. Given any Boolean function (compound proposition), how do we know it can be realized as a circuit using Not, And, and Or. In other words are these really “basic gates”. And are there other “basic gates.” By “basic” we mean functionally complete and say that gates, g1, g2, …, gk are functionally complete if given any Boolean function, f, with n inputs (f: 2 n 2 ) , there is a combinatorial circuit that computes f using the gates gi. To answer the first question consider n=2 and the following Example 5: f(0,0) = 1 f(0,1) = 0 f(1,0) = 0 f(1,1) = 0. 5 We are going to write f as the sum of products. We look at the inputs that evaluate to 1 first and find that only f(0,0) =1. The first product will be x1 x 2 since this evaluates to 1 (only) for the given input. All other input evaluate to 0 so the function is simply f = x1 x 2 . If the value f(1,1) were also 1, we would just add the function x1x2 and then f = x1 x 2 + x1x2. In general, we look at the f output that evaluates to 1. If there are k of these f, will be the sum of k simple functions which are products of the input xi that are 1 and the Not of the input xj that are zero (in the correct order). This sketchy construction gives Theorem G: Any Boolean function can be computed using Not, And, and Or gates. For the second question we have: Theorem FC: The sets [And, Not], [Or, Not] and [Nand] are functionally complete where Nand(x,y) = Not(And(x,y)). proof; All we need to show is that Not, And , and Or can be computed; then we have the conclusion using Theorem G. For example, given And and Not, Or(x,y) = Not(And(Not(x), Not(y))) using DeMorgan and double negation. Obtaining And from [Or, Not]is similar. Obtaining Not, And , and Or from Nand is part of HOMEWORK 3. endproof; We close this section by the remark that a challenge in good circuit design is to mimimize the number of “cheap” functionally complete gates given the chosen device technology. Here is an example related to example5 and ThmG. Example 6. During basketball season a group of nefarious UNC students captured a Duke Computer Science major (CSD) and took CSD off to Chapel Hill. Chief_Nefarious, a grotesque bully, offer our major a chance to escape by saying: “One of the doors out of here leads to freedom and the other leads to your perpetually taking lowlevel UNC courses for our basket ball players. You will have two guards; one always lies and one always tells the truth. You can ask one question to one guard. Have a nice life.” CS Dukie thinks about it and realizes that the question “is door1 the way out” will not work nor will the question “are you truthful”. The question will have to be a compound question. 6 Let x = door1 or equivalently the proposition, dorr1 is the way out. Let y = trueguard1; i.e.; guard1 tells the truth. CS Dukie will design a Boolean function f(x,y) with f(1,1) = 1 (door 1) f(1,0) = 0 f(0,1) = 0 (door 2) f(0,0) = 1. The solution is the function z = xy + x y . The question to guard1 should be: (is door1 the way out and are you truthful) or (is door 2 the way out and are you lying). If the answer is “yes”, CSD takes door1; “no” selects door2. Recalling example 2 of ThmP the question could also be: is door1 the way out iff you are truthful. 3. Proofs (YUM) An argument or proof is a set hypotheses, hi, 1≤i≤n, and a conclusion, C. The hypotheses can be axioms, postulates, definitions and previously proven results (theorems). Little theorems are sometimes called lemmas or propositions and immediate consequences of theorems are sometimes called corollaries. Sometimes hypotheses are only implicitly stated; for example, they may be a basic property of the integers when proving something in that context. A valid argument is one such that C is true if all the hi are true; otherwise the argument is invalid. This is sometimes written in the form (for example) h1 h2 h3 C In principle, we could determine validity using the truth table approach; this is done is simple case to build up proof rules,; most of the basic rules are given below. pq p q p q pq T T T T F F (Modus Ponens) F T T F F T We read off from the truth table (line 1) that if p q is true and p is true then q must be true. Similarly (with the tables omitted) 7 (Modus Tollens) pq q p (Addition) p (p q) (Specialization) pq p p (Conjunction) q p q pq Hypothetical Syllogism qr p r Disjunctive Syllogism pq p q (Cases) (Case Elimination) p p (r s) rq sq q pq p (r r) q If we substitute p = p′ and q = p immediately above we obtain (since p p T ) (Contradiction 1) p (r r) p 8 A more usual form of proof by contradiction now substitutes (p q) p q (example1 and De Morgan) for p′ to obtain p q (r r ) p q (Contradiction 2) HOMEWORK3: Use the truth table approach to show (Contradiction 2) directly. We close with a metatheorem ( theorem about theorems). Theorem M: An argument with hypotheses (or premises) h1, . . ., hn and conclusion C is valid if and only if H = ( h1 h 2 ... h n C ) T ; that is; H is a tautology. proof; If all hi are true, C is true by the definition of valid; hence is true. If some hi is false the compound hypothesis is false; hence is (vacuously) true. Therefore H is always true. Now suppose H is not a tautology and use contraposition. The only way H can be false is for all hi to be true and for C to be false. But then, by definition, the argument is not valid. endproof; 4. Boolean Algebra Here we “pop-up” a level and show that our discussion in section 2 can be viewed in an (abstract) algebraic setting. A Boolean Algebra is a set B containing special elements 1 and 0 together with binary operators + and · and a unary operator ′ which satisfy the following axioms for all x, y, z B. (commutative laws) (associative laws) (distributive laws) x yy x xy yx x y z (x y) z x (y z) (x y) z x (y z) x y x z x (y z) (x y) (x z) 9 (identity laws) x 1 x x0 x (complement laws) x x 1 x x 0 The special elements 0 and 1 is usually called called zero and unity, respectively. x′ is the complement of x. Often x y is written as x y . Given these axioms we can derive (prove) the following “rules” Boolean arithmetic. TheoremBA: For elements 0,1, x and y of a Boolean algebra: (complement of identities) 0 1 1 0 (involution law) (x) x if (uniqueness of complement law) x x 1 and x x 0 and x x* 1 and x x* 0 then x x* (idempotent laws) xx x x xx (null laws) x 1 1 x 00 (absorption laws) x (x y) x x (x y) x (De Morgan’s Laws) (x y) x y (x y) x y Why is this theorem different from ThmB? ThmB started with a definition for +, · and ′ and then stated all the properties that are part of the definition of a Boolean algebra and ThmBA. Here we start with the definition of an algebraic system and state that the other properties follow. In fact, we will see soon that, if B ={0,1}, then the defining rules for +, · and ′ must be those of section 2. 10 proof; We prove (complement of identities) directly from the axioms. As HOMEWORK3 you can prove (uniqueness of complement law). 0 + 0′ = 1 0′ + 0 = 0′ 1 = 0′. complement laws; identity law; thus, using commutativity Now let’s do the proof over again replacing x (0) by x′ and + by · . 1 · 1′ = 0 1′ · 1 = 1′ 0 = 1′ (using the same rules). endproof; We see there is a dualism happening. Essentially the second part of the proof is just a copy of the first part by interchanging 1 and 0 and + and · . We can always do this interchange, and it is the reason that most of the statements in ThmBA comes in pairs. In essence, the dual of a Theorem in Boolean algebra is also a theorem. Example 7: B = {0,1}. We see that the identity and complement axioms and the idempotent or null laws in ThmBA force the (NT) and (AO) rules of section 2. Example 8: B is the set of propositions (as in section 2) and T and F + is (or) · is (and) ´ is ´ (not) 1 is T 0 is F Example 9: S is a set and B = P(S), the set of all subsets. + is (union) · ´ 1 0 is is is is ~ S {} (intersection) (complement with respect to s) (empty set) 11 5. The Integers and Induction The integers is the set I = {0, 1, , …, n, …}with the “usual” set of properties of integer arithmetic which are stated explicitly in the appendix, section 6. The set P = {1,2, …, n, …} is the set of positive integers (natural numbers – {0}). One property of I, called the trichotomy axiom, is that for all a in I, either a = 0, a > 0 (in P), or (-a) > 0. We also note from below the important well ordering axiom: any subset S of P has a least element; that is, there is an s0 in S such that s s0 for all s in S. In fact from this axiom we obtain the principles of induction as in ThmI below. First we remark that the least element s0 must be unique. For, if s0 and s1 were both least then s0 s1 and s1 s0 so s0 s1 . This also implies that s0 < x for all x s0 in S. Theorem I: Let p(n) be a proposition depending on n in P. The following are equivalent: (W) P is well ordered; (I1) p(1) and (for all n, p(n-1) p(n)), then p(m) is true for all m; (I2) p(1) is true and ((for all k<n, p(k)) p(n)), then p(m) is true for all m; proof; We prove (W) iff (I1) and (W) iff (I2) since the proofs are essentially the same. if (W) then (I1) and if (W) then (I2): Suppose there exists a set S = {k | p´(k) }. Then S has a least element m0 >1 since p(1) is true. By construction of S, we have p(k) is true for all k < m0, including m0-1. Therefore by the second part of the hypothesis for either (I1) or (I2), p(m0) must be true. This is a contradiction ( p(m0 ) p(m0 ) ) and there is no such set S. if (I1) then (W) and if (I2) then (W): Clearly a subset of P containing a single element has a least element (p(1)). Let p(k) any subset Sk P with |Sk| = k (k elements) has a least element, 1<k<n. Consider a set S with |S| = n and any element s of S. We need to show that p(n) is true; then p(m) will be true for all m and we are done. Consider Sn-1 = S – {s} and note that | Sn-1| = n-1. The induction hypothesis, in either case, insures that is p(n-1) is true, hence Sn-1 has a least element, say s1. Since s = s1 or s > s1 or s1 > s, s or s1 is the least element for S; that is p(n) is true. endproof; Example 10: We have never shown directly that log(x) as x (in any base), although it follows from the properties of the ex ( and its power series expansion). k As HOMEWORK3, consider the sum H k 1/ i ; show by induction that i 1 H 2n 1 n / 2 . Hence the harmonic sum diverges and we have shown that ln(n) = (Hn). 12 6. Appendix: Axioms for the Integers Equality (e1) (e2) (e3) for all a, a = a; for all a and b, if a = b, then b = a; for all a, b, c, if a =b and b = c, then a = c; Arithmetic For all a,b, and c: (a1) a + b and ab are integers; (a2) if a = b and c = d, a + c = b +d and ac = bd; (a3) a + b = b + a and ab = ba; (a4) (a + b) + c = (a + b) + c; (ab)c = a(bc); (a5) a(b + c) = ab + ac; (a6) there exist unique integers 0 and 1 such that a + 0 = a and a 1 = a (a7) (a8) for all a, there exists –a such that a + (-a) = 0; if ab = ac and a 0, the b = c; (commutative) (associative) (distributive) (additive and multiplicative identities) (additive inverse) (cancellation) Positive Integers and Order There exists a proper subset P (called positive integers and we write p>0 for each such p) of the integers such that (p1) 1 > 0; (p2) if a > 0 and b.> 0, then a + b > 0 and ab > 0; (p3) for all integers a one and only one of the following hold a > 0, -a > 0, or a = 0; It is now possible to define and as a>b iff a-b > 0 and a b iff a-b 0. (p4) any subset S of P has a least element; that is, there is an s0 in S such that s s0 for all s in S. 13