CSE 1400 Applied Discrete Mathematics Boolean Logic Department of Computer Sciences College of Engineering Florida Tech Fall 2011
Total Page:16
File Type:pdf, Size:1020Kb
CSE 1400 Applied Discrete Mathematics Boolean Logic Department of Computer Sciences College of Engineering Florida Tech Fall 2011 Control Structures 1 Boolean Logic 3 Normal Forms 4 The Conditional Operator 5 Complex Propositions 6 Truth Tables 8 Logical Equivalence 10 Satisfiable and Valid Propositions 11 Constructing Boolean Functions 12 Satisfiability 13 Counting Boolean Expressions 14 Consistency and Completeness of Boolean Algebra 14 Problems on Boolean Logic 15 Abstract Logic controls the action of a computer. Control Structures The Böhm-Jacopini theorem shows that only three funda- mental control structures are necessary to implement any Turing algorithm. 1. Execute instructions sequentially one after another as in figure 1 2. Select one of two instruction to execute according to the value of a Boolean variable as in figure 2 3. Iterate through a sequence of instructions until a Boolean variable changes value as in figure 3 cse 1400 applied discrete mathematics boolean logic 2 Figure 1: Sequential execution of statements. Statement Next Statement Figure 2: Conditional execution of statements. Boolean Condition Then Else Statement(s) Statement(s) Figure 3: Loop (iterative) execution of statements. Boolean Condition Loop Statement(s) cse 1400 applied discrete mathematics boolean logic 3 Boolean Logic Boolean logic provides the basis to control the execution of algorithms.Propositional calculus studies the behav- ior of formulas constructed using Boolean variables. The domain Boolean variables are typically named of these variables is the set of truth values B = fFalse, Trueg.A p, q, r, s, . .. Boolean variable is also called a proposition and is often inter- preted as the name for a declarative natural language sentence: A proposition is a sentence that can only be True or False. A formal Example propositions: syntax describes what propositions are and how they can be ma- • All humans are mortal. (True) nipulated. • Socrates was human. (True) • Socrates was mortal. (True) 1. False, also called 0, is a proposition. • George Washington was President of the United States of America from 2. True, also called 1, is a proposition. 1789 to 1797. (True) 3. Boolean variables over the set of bits are propositions. If p is a • May 1, 1911 was a Wednesday. (False) Boolean variable, then p 2 f0, 1g. •2 + 3 = 7 (False) 4. If p and q are propositions, then • p = 3.14 (False) • All relations are functions. (False) : (a)N ot p, denoted p is a proposition p and :p are called literals. One of (b) p and q, denoted p ^ q is a proposition them is False, the other is True. Haskell uses && to express and. (c) p or q, denoted p _ q is a proposition Haskell uses k to express or. 5. Nothing else is a proposition. To begin we need to define the Boolean operations described above. The not operator : is defined by truth table 1 and repre- sented by the logic gate in figure 4. The not Operator Table 1: The truth table for the not Input Output operator. p :p 0 1 1 0 p :p Figure 4: Logic gate for the not opera- tor. The and operator ^ is defined by truth table 2 and represented by the logic gate in figure 5. p p ^ q Figure 5: Logic gate for the and opera- q tor. cse 1400 applied discrete mathematics boolean logic 4 The and Operator Table 2: The truth table for the and Input Output operator. p q p ^ q 0 0 0 0 1 0 1 0 0 1 1 1 The or Operator Table 3: The truth table for the or Input Output operator. p q p _ q 0 0 0 0 1 1 1 0 1 1 1 1 The or operator _ is defined by truth table 3 and represented by the logic gate in figure 6. From a mathematical point of view, the meaning of proposition p is immaterial. Collections of Boolean variables are manipulated using the above rules, that is all. From a computing point of view, the meaning of a proposition gives reasons for manipulating it. Normal Forms A form is a syntactic structure. A form is normal if every expression can be transformed into its structure. Two normal forms for Boolean logic are conjunctive and disjunctive normal forms. •A literal is a Boolean variable p or its denial :p. •A clause is a disjunction of literals, for example p _:q _:r is a clause. • An implicant is a conjunction of literals, for example p ^ :q ^ :r is a implicant. p _ Figure 6: Logic gate for the or operator. q p q cse 1400 applied discrete mathematics boolean logic 5 A Boolean expression B is in conjunctive normal form if B is the conjunction of clauses ck (each ck is the disjunction of literals.) n−1 ^ B = ck k=0 For instance, (p _ r) ^ (:q _ r) is in conjunctive normal form. A Boolean expression B is in disjunctive normal form if B is the disjunction of implicants dk (each dk is the conjunction of liter- als.) n−1 _ B = dk k=0 For instance, (p ^ r) _ (:q ^ r) is in disjunctive normal form. The Conditional Operator Conditional statements bridge from True statement to True statement. In logic, the conditional is written if p then q where p and q are Boolean variables. Symbolically, the conditional is written p ! q The value of a conditional ‘if p then q’ is defined as follows. The logical conditional is sim- ilar to the Haskell conditional 1. When p is True the value of the conditional has the value of q. if p then q else true. 2. When p is False the value of the conditional is True. That is, 8 <q if p = True if p then q = :True if p = False These rules are summarized in the truth table below, which also shows that the conditional p ! q is equivalent to :p _ q. The value (True or False) of a conditional can be difficult to understand, especially when the premise is False. To gain some understanding, consider these statements. • “John scores above 90 on the final.” Call this p. cse 1400 applied discrete mathematics boolean logic 6 Table 4: The conditional operator. Input Output p q p ! q :p _ q 0 0 1 1 0 1 1 1 1 0 0 0 1 1 1 1 p p ! q q • “John earns an A in the course.” Call this q. Pretend I make the statement • “If John scores above 90 on the final, then John earns an A in the course.” That is p ! q. Ask yourself, when my statement is True and when it is False? There are four cases. Two cases where p is True: 1. If John scores above 90 on the final and John earns an A in the course, do you agree my statement p ! q is True? 2. If John scores above 90 on the final and John does not earn an A in the course, do you agree my statement p ! q is False? And two cases where p is False. 2. If John scores 90 or below on the final and John’s grade is B or be- low, do you agree my statement p ! q is not False and therefore must be True? 3. If John scores 90 or below on the final and John grade is A, do you agree my statement p ! q is not False and therefore must be True? Notice the statement p ! q tells you nothing about the value of q when p = False. The conditional operator is at the heart of establishing a proof. p ! q is called an argument. p is called the premise. q is called the conclusion. Complex Propositions Complex propositions can be made from by combining sim- ple propositions using Boolean not, and and or opera- tions. For values of n = 0, 1, 2, . ., it is useful to list the expressions 2n that can be created using n Boolean variables p0 through pn−1. There are 2 Boolean functions on n Boolean variables. cse 1400 applied discrete mathematics boolean logic 7 1. When n = 0 there are no propositions, but there are two Boolean functions, the constant True and the constant False. 2. When n = 1 there is one proposition p and four Boolean functions: True, False, p, and :p. Notice that True can be written as an expression in p: True = p _:p. Also, 3. When n = 2 there is 2 propositions p and q, and sixteen Boolean False can be written as an expression in functions. p: False = p ^ :p. See the section on primitive type Bool. Name Symbol Name Symbol False 0 not or (nor) :(_) and ^ equivalence ≡ not conditional :( ! ) not q :q bufferp p converse not converse :( ) not p :p bufferq q conditional ! exclusive or ⊕ not and (nand) :(^) or _ True 1 I use the binary value in the table as Input BooleanFunctions a check-sum to know that each of the 2 22 = 16 Boolean functions are listed. p q 0 p ^ q :(p ! q) p :(q ! p) q p ⊕ q p _ q 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 1 1 1 0 0 0 1 1 0 0 1 1 1 1 0 1 0 1 0 1 0 1 Binary 0 1 2 3 4 5 6 7 Input Boolean Functions p q :(p _ q) ≡ :q q ! p :p p ! q :(p ^ q) 1 0 0 1 1 1 1 1 1 1 1 0 1 0 0 0 0 1 1 1 1 1 0 0 0 1 1 0 0 1 1 1 1 0 1 0 1 0 1 0 1 Binary 8 9 10 11 12 13 14 15 Each of the three variables can assume one of two values giving eight combi- 23 4.