* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Chapter5
Survey
Document related concepts
Meaning (philosophy of language) wikipedia , lookup
Fuzzy logic wikipedia , lookup
Quantum logic wikipedia , lookup
Modal logic wikipedia , lookup
Axiom of reducibility wikipedia , lookup
Intuitionistic logic wikipedia , lookup
Law of thought wikipedia , lookup
Natural deduction wikipedia , lookup
Propositional calculus wikipedia , lookup
Propositional formula wikipedia , lookup
History of the function concept wikipedia , lookup
Principia Mathematica wikipedia , lookup
Truth-bearer wikipedia , lookup
Transcript
BSC(Hons) Computer Science DIS Foundation Year Mathematics for Computing Chapter 5 Boolean Algebra 1. Boolean Algebra Boolean Algebra derives its name from the mathematician George Boole who developed this mathematical notation that is now used widely in Computing and Engineering. It uses Boolean Logic to describe logical behaviour. BooleanLogic uses values, variables and operations : True is represented by the value 1. False is represented by the value 0. Variables are represented by letters and can have one of two values, either 0 or 1. Boolean Operations are functions of one or more variables that produce a True or False result. The following are common Boolean operations: AND is represented by X.Y (or sometimes X&Y) OR is represented by X+Y (or sometimes X||Y) NOT is represented by X' or used. x . Throughout these notes the X' form will be These basic operations can be combined to give expressions. e.g. X.Y means X and Y using the AND operation X.Y+Z means ‘and’ the X with Y and the ‘or’ the result with Z . 2. Precedence As with any other branch of mathematics, these operators have an order of precedence. NOT operations have the highest precedence, followed by AND operations, followed by OR operations. Brackets can be used as with other forms of algebra to specify the order of precedence. e.g. X.(Y + Z) changes the precedence so that (Y + Z) is calculated first and the result is used to ‘or’ with X. 1 The rules of precedence for Boolean operators are : 1. invert 2. products 3. sums Example (0+1)'+0.1 (OR the two values inside the brackets first) = (1)'+ 0.1 ( then invert NOT the result inside the brackets) = 0 + 0.1 ( AND the two values in the second term) = 0 +0 ( OR the two remaining values) = 0 (represents FALSE) 3. Function Definitions The logic operations given previously can be defined more formally as follows : Define F(X,Y) to be some function of the variables X and Y e.g. F(X.Y) = X.Y (i.e. X AND Y) F(X,Y) = X+Y (i.e. X OR Y) A Boolean function is represented using a Boolean expression made up of Boolean variables and operators. An example of a Boolean function is F(X,Y) = X.Y where X.Y is the Boolean expression. The truth table for F(X,Y) = X.Y is: X Y F ----------0 0 0 0 1 0 1 0 0 1 1 1 The truth table for F(X,Y) = X+Y is: X Y F ----------0 0 0 0 1 1 1 0 1 1 1 1 2 4. Truth Tables Truth tables are a means of representing the results of a logic function using a table. They are constructed by defining all possible combinations of the inputs to a function, and then calculating the output for each combination in turn. A summary of truth tables are shown below. NOT The NOT operator is the simplest to understand. It is a unary operator (i.e. it only takes one value) that simply takes a value, and returns the opposite of that value. So NOT true is false and NOT false is true. The truth table for this function is shown below: A A' 0 1 1 0 AND The output of the AND function is true only if all of the inputs are true. That's to say that if you have two variables, A and B, then ‘A AND B’ is only true if A is true AND B is true. A 0 0 1 1 B 0 1 0 1 A AND B 0 0 0 1 The AND function can also be represented by a dot (.), so A AND B can also be written A.B - this is because the AND operator behaves in a similar way to the multiplication operator in arithmetic (see below). OR The output of the OR function is true if any of the inputs are true. That's to say that if you have two variables, A and B, then ‘A OR B’ is true if A is true OR B is true. A 0 0 1 1 B 0 1 0 1 A OR B 0 1 1 1 3 The OR function can also be represented by a + sign. So ‘A OR B’ can also be written ‘A + B’ - this is because the OR operator behaves in a similar way to the addition operator in arithmetic (see below). Exclusive-OR Exclusive-OR (often written as EOR or XOR) can only be used with two variables. The result of ‘A EOR B’ is true if either A is true or B is true, but not both. Or, in simpler terms, the result of ‘A EOR B’ is true only if A and B have different values. A B A XOR B 0 0 0 0 1 1 1 0 1 1 1 0 The exclusive-OR operator is also represented by the symbol . NAND and NOR A 0 0 1 1 B 0 1 0 1 A NAND B 1 1 1 0 There are no special symbols to represent the NAND and NOR operators – just follow AND with NOT to give NAND , and follow OR with NOT to give NOR. A NOR B, therefore, could be written (A + B) '. A B A NOR B 0 0 1 0 1 0 1 0 0 1 1 0 In electronic logic circuits, NAND and NOR gates are often used to reproduce a NOT gate. This can be done simply by connecting together both inputs i.e. A NOR A = NOT A, and also A NAND A = NOT A. 4 Truth tables may contain as many input variables as desired. e.g. F(x, y, z) = x.y + z' The truth table for F(x,y,z) = x.y + z' is: x 0 0 0 0 1 1 1 1 y 0 0 1 1 0 0 1 1 z 0 1 0 1 0 1 0 1 z' 1 0 1 0 1 0 1 0 x.y 0 0 0 0 0 0 1 1 x.y + z' (= F) 1 0 1 0 1 0 1 1 The table is constructed in order of precedence of operations. In addition to the columns for the input variables x, y, x we create columns for intermediate values, namely for z’ and x.y. This makes it easier to calculate the final result. Here the first thing we do is invert the z variable to give z’, then the AND operation is performed to give x.y and finally the z’ and x.y are ORed to obtain the function F . Examples 1. Construct a truth table for the following Boolean expression: F = AB' + A'B A B B' A' AB' A'B 0 0 1 0 1 1 1 F = AB' +A'B 1 0 0 0 0 1 0 1 1 0 1 0 1 0 1 1 0 0 0 0 0 2. Construct a truth table for the following Boolean expression F = x + x.y x y x.y x + (x.y) (=F) --------------------0 0 0 0 0 1 0 0 1 0 0 1 1 1 1 1 END 5