Download presentation
Presentation is loading. Please wait.
1
This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed. If you have opened this lesson in PowerPoint, use the PowerPoint menus to view it in slide show mode. If you have opened this lesson in a browser and see a bar similar to that below, click on the Slide Show icon A notice similar to the one below may appear warning that ActiveX or other scripts are disabled. Enable the controls for this website in order to see the animations.
2
Logical (Boolean) Operators This slide show describes the use of logical operators Christine S. Wolfe Ohio University Lancaster 2008-Aug-01 Vocabulary: == < <= > >= ! != || && AND NOT OR True False Boolean case condition logical complement logical logically equivalent negation truth (decision) table
3
3 Boolean expressions are "The type of an expression with two possible values, 'true' and 'false'. Also, a variable of Boolean type or a function with Boolean arguments or result. The most common Boolean functions are AND, OR and NOT." The Free On-line Dictionary of Computing, © 1993-2004 Denis HoweANDORNOT The Free On-line Dictionary of Computing, © 1993-2004 Denis Howe In 1854 he [George Boole] published An investigation into the Laws of Thought, on Which are founded the Mathematical Theories of Logic and Probabilities. Boole approached logic in a new way reducing it to a simple algebra, incorporating logic into mathematics. He pointed out the analogy between algebraic symbols and those that represent logical forms. It began the algebra of logic called Boolean algebra which now finds application in computer construction, switching circuits etc. http://www-history.mcs.st-andrews.ac.uk/Biographies/Boole.html The textbook generally uses the term logical expression when describing expressions that have a value of true or false. More traditionally, these are referred to as Boolean expressions in honor of the man who developed the algebra of logic. http://www-history.mcs.st-andrews.ac.uk/Posters2/Boole.html Christine S. Wolfe Ohio University Lancaster 01-Aug-2008
4
4 The Logical (Boolean) Operators EnglishANSI C SYMBOL equivalent to== greater than> less than< greater than or equal to>= less than or equal to<= not equivalent to!= NOT! AND&& OR|| Christine S. Wolfe Ohio University Lancaster 01-Aug-2008
5
5 Truth tables, also called decision tables, are graphical ways of determining if a complex logical expression is true based upon the logical value of its base conditions. Christine S. Wolfe Ohio University Lancaster 01-Aug-2008 The truth table below represents the complement or negation of a condition. The complement of a condition is "the opposite"; when the condition is True, the complement or negation is False and when the condition is False, the complement or negation is True ConditionATF !ConditionAFT It is rainingTF !(It is raining)FT Age > 21TF !(Age > 21)FT When "It is raining" is True, then "!(It is raining)" is False and when "It is raining" is False, then "!(It is raining)" is True.
6
6 Christine S. Wolfe Ohio University Lancaster 01-Aug-2008 When drawing a truth table, separate the base conditions from the results with a double horizontal line Include every possible combination of True and False for the base conditions Each column after the conditions represents a case or situation. Case 1: ConditionA is True so !ConditionA must be False Case 2: ConditionA is False so !ConditionA must be True
7
7 It is sometimes the case that there are more than one conditions and/or more than one result. Remember that the set of conditions are separated from the set of results by the double line. Christine S. Wolfe Ohio University Lancaster 01-Aug-2008 base conditions complex condition (results) Notice that the more conditions you have, the more cases (columns) you have. The truth table must include every possible combination of True and False for the base conditions. base conditions complex condition (results) Click Tip Click Tip
8
8 When evaluating a case (column). The Truth of the result is determined by the Boolean value of the base conditions. Christine S. Wolfe Ohio University Lancaster 01-Aug-2008 A compound condition in which the base conditions is prefaced with ! (not) is true only when the base condition is false.
9
9 When evaluating a case (column). The Truth of the result is determined by the Boolean value of the base conditions. Christine S. Wolfe Ohio University Lancaster 01-Aug-2008 A compound condition in which the base conditions are separated by && (and) is True only when ALL base conditions are True.
10
10 When evaluating a case (column). The Truth of the result is determined by the Boolean value of the base conditions. Christine S. Wolfe Ohio University Lancaster 01-Aug-2008 A compound condition in which the base conditions are separated by || (or) is True whenever any one of the base conditions are True.
11
11 When evaluating a case (column). The Truth of the result is determined by the Boolean value of the base conditions. Christine S. Wolfe Ohio University Lancaster 01-Aug-2008 A compound condition in which the base conditions are separated by a mix of && (ands) and || (ors) and ! (nots) must be evaluated step by step. ConditionA && !ConditionB is True only when ConditionA is True and !ConditionB is True. ConditionA is True in columns 1 and 2. !ConditionB is True only when Condition B is False (columns 2 and 4) The only column in which both ConditionA and !ConditionB are True is column 2. Click Tip Click Tip You may find it helpful to include intermediate steps in the results section.
12
T TT 12 In programming, our conditions and results are usually arithmetic expressions. 63 > 15 && 25 < 40 T TT 63 > 15 || 25 < 40 F FT 63 > 15 && 25 > 40 T FT 63 > 15 || 25 > 40
13
13 Which of the following expressions are TRUE? 10 > 8 10 != 8 10 == 8 + 2 5 1 10 >= 2 || 1 < 3 !(3 <= 3) 10 >= 8 10 >= 2 || 3 > 1 ! (10 > 8) Christine S. Wolfe Ohio University Lancaster 01-Aug-2008
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.