Introduction to Boolean Logic Boolean logic is a form of algebra in which all values are reduced to either TRUE Logic (Mathematics 1BA1) or FALSE . Rozenn Dahyot Some of the very early computers attempted to use the decimal system for machine computation. But it proved to be unreliable. Room 128 Lloyd Institute School of Computer Science and Statistics Trinity College Dublin, IRELAND https://www.cs.tcd.ie/Rozenn.Dahyot/ It was realized that the only reliable operating conditions for electronic and [email protected] electromechanical devices was an on-off mode. Week 2 - 15 January 2007 The on-off mode has to be done with two symbols: TRUE (or 1) and FALSE (or 0). Boolean Algebra The Binary System Remember in the decimal system are the symbols {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, used with their position values (units, tens, hundreds, thousands, etc.): Hundreds: 102 Tens: 101 z}|{ 6 Once the binary system was chosen for the representation of numbers for Ones: 100 z}|{ 5 computers, the next problem was to mechanize the arithmetic operations in binary. z}|{ 3 The solution of mechanization of arithmetic was provided by the algebra of Logic meaning 6 × 100 + 5 × 10 + 3 × 1 = 653. invented by G. Boole. In the binary system are the symbols {0, 1}: Fours: 22 Twos: 21 z}|{ 1 The Boolean algebra is a two-state algebra, but has no direct relationship to binary Ones: 20 z}|{ 1 arithmetic. z}|{ 0 meaning 1 × 4 + 1 × 2 + 0 × 1 equals to 110 in binary or 6 in decimal. Boolean expressions Other Logics Definitions: There are only two boolean constants: True (T) and False (F). A boolean variable may take either of the values T or F. For information, examples of other Logic: Definitions: Fuzzy Logic is an extension of Boolean Logic. A boolean operator: function which maps boolean variables to the value True(T) or False(F). Boolean operators may be termed: Probability & Statistics: Theory of Probability is taken as a branch of Logic, the logic of partial belief and inconclusive argument. unary: a boolean operator with only one argument. binary: a boolean operator with two arguments. F. P. Ramsey Examples: unary operator: ¬ (not) binary operators: ∧ (and), ∨ (or ) and = (is equal to) Truth Table Boolean operators Truth tables are used to establish the truth value of a boolean expression for all possible states of its constituent variables. Let E be a boolean expression with variables z1 , z2 , . . . , zn . Then a truth table for E is a table where each row is a possible state of the variables z1 , . . . , zn , together with E evaluated in that state. The number of variables in the boolean expression determines how many rows the truth table must have. Since E depends on n different variables, the truth table for E has 2n rows of all the possible states. or and follows from implies equals exclusive or p q p∨q p∧q p⇐q p⇒q = 6= F F F F T T T F F T T F F T F T T F T F T F F T T T T T T T T F nor nand equivalent not-equivalent p q p NOR q p NAND q p≡q p 6≡ q F F T T T F F T F T F T T F F T F T T T F F T F Example of Truth Table for Id and ¬: p ¬p T F F T Id p T F Boolean operators Exercise: Boolean operators Notice how the pairs of operators (∨, NOR), (∧, NAND), (=, 6=), (≡, 6≡) are simply the negatives of each other. Let E be the expression p ∨ (q ∧ ¬r). The truth table will then have 23 = 8 rows. Write down the truth table of E. Notice also that some pairs of operators have the same values in every state: p q r ¬r q ∧ ¬r p ∨ (q ∧ ¬r) T T T F F T Example : Let E be the expression p ≡ (p ∨ (¬q ∧ p)). The expression contains two T T F T T T variables, p and q, so the truth table will have 22 = 4 rows. T F T F F T T F F T F T T T F F F (=, ≡) and (6=, 6≡). q ¬q (¬q ∧ p) p ∨ (¬q ∧ p) p ≡ (p ∨ (¬q ∧ p)) F T T F F T T F T F T T T T F T T T T F F T F F F F T F F F T F F F T F F F F T F F T p G. Boole (1815-1864) Table of Precedences The Problem: When evaluating a boolean expression, it is difficult to know which parts of the expression should be evaluated first. The Solution: To solve this problem, a Table of Precedences is defined. Example: Given the expression F = T ≡ F F = T should be evaluated first because = is higher in the table of precedences than ≡, to give F. Or the expression can be rewritten: (F = T) ≡ F Then (F) ≡ F gives the value T. MP3 about icons of irish science: http://www.rte.ie/radio1/story/1068297.html Table of Precedences Associativity & Conjunctionality Table of Precedences Highest (a) [x := E] (textual substitution) (b) . (function application) (c) the unary prefix operators: + − ¬ # ∼ P (d) ⋆⋆ (e) · / ÷ mod gcd If the binary operator ◦ is associative then ((b ◦ c) ◦ d) = (b ◦ (c ◦ d)) for all b, c, d. (f) +−∩∪×◦• If the binary operator ◦ is conjunctional then b ◦ c ◦ d is an abbreviation for (g) ↓↑ (b ◦ c) ∧ (c ◦ d). (h) # (i) b (j) the conjunctional operators: = < > ∈ ⊂ ⊆ ⊃ ⊇ | (k) ∨∧ (l) ⇒⇐ Lowest (m) ≡ Differences between Equality & Equivalence Differences between Equality & Equivalence The boolean operators Equality (=) and Equivalence (≡) have the same truth tables. Example: Differences are: 1 To see the differences we now evaluate the expressions ≡ has lower precedence than =. F = F = T and F ≡ F ≡ T. Example: F≡F≡T F=F=T A = B ≡ C means (A = B) ≡ C h = is conjunctional i = (F ≡ F) ≡ T (F = F) ∧ (F = T) h Evaluate both = i = 2 ≡ is associative and = is conjunctional. h Evaluate ∧ i = A≡B≡C means (A ≡ B) ≡ C and A ≡ (B ≡ C) A=B=C means (A = B) ∧ (B = C) Exercise: Differences between Equality & Equivalence F h Evaluate first ≡ i = T≡T T ∧F Example: h By associativity i = h Evaluate ≡ i = T Satisfiability A boolean expression P is satisfied in a state if its value is true in that state. 1 Evaluate the following expressions using the table of precedences. Example: (i) F=F≡F (v) T=F=T (ii) F≡F=F (vi) T=F≡T=F (iii) F=F=F (vii) F≡T≡T≡T (iv) F≡F≡F (viii) (T = T) = T = F Let P be the boolean expression p ∨ q. Then P is satisfied in the state (T, F). P is not satisfied in the state (F, F). A boolean expression P is satisfiable if there is some state in which it is satisfied. Solutions: (i) F = F ≡ F is F (v) T = F = T is F (ii) F ≡ F = F is F (vi) T = F ≡ T = F is T (iii) F = F = F is T (vii) F ≡ T ≡ T ≡ T is F (iv) F ≡ F ≡ F is F (viii) (T = T) = T = F is F Example: Let P be the boolean expression p ∧ q. Then P is satisfiable since it is satisfied in the state (T, T). Validity & Tautology Exercise: Satisfiability, Validity & Tautology 1 State if the following expressions are satisfiable and which, if any, are tautologies. A boolean expression P is valid if it is true in all states. A valid boolean expression is (i) p (v) T ∧ T called a tautology . (ii) p ∧ ¬p (vi) T ∨ F∨ T ∨p (iii) p ∨ q (vii) p ⇒ F (iv) p ∨ ¬p (viii) ¬p ⇒ T Example: Let P be the boolean expression p ∨ T. Then P is valid since it is true for both p = F, T. Duality Solutions: (i) (ii) (iii) (iv) satisfiable/not valid not satisfiable/ not valid satisfiable /not valid p ∨ ¬p satisfiable/ valid (tautology) (v) (vi) (vii) (viii) tautology tautology satisfiable /not valid tautology Exercise: Metatheorem Duality The dual PD of a boolean expression P is constructed from P by interchanging occurrences of T and F ∧ and ∨ (i) p≡q (v) p≡q≡p ≡ and 6≡ (ii) p ⇒ q ≡ ¬p ∨ q (vi) p∨T ⇐q ⇒ and 6⇐ (iii) F⇒p≡T (vii) p ∧ (q ∨ r) ⇐ and 6⇒ (iv) F∨F (viii) F ⇒ p∨T Example: Let P be the boolean expression p ∨ T. Then the dual expression PD is p ∧ F. Metatheorem Duality. (a) P is valid if and only if ¬PD is valid. (b) P ≡ Q is valid if and only if PD ≡ QD is valid. 1 For each of the following boolean expressions, write down the dual expression. Solutions: (i) p 6≡ q (v) p 6≡ q 6≡ p (ii) p 6⇐ q 6≡ ¬p ∧ q (vi) p ∧ F 6⇒ q (iii) T 6⇐ p 6≡ F (vii) p ∨ (q ∧ r) (iv) T ∧T (viii) T 6⇐ p ∧ F
© Copyright 2026 Paperzz