Computer Science
Boolean Expressions
Boolean expressions are logical expressions that evaluate to either true or false. They are commonly used in programming and computer science to make decisions and control the flow of a program. Boolean expressions often involve the use of logical operators such as AND, OR, and NOT to compare values and conditions.
Written by Perlego with AI-assistance
Related key terms
1 of 5
11 Key excerpts on "Boolean Expressions"
- eBook - ePub
- Kuldeep Singh Kaswan, Jagjit Singh Dhatterwal, B Balamurugan(Authors)
- 2023(Publication Date)
- Chapman and Hall/CRC(Publisher)
4 Branch Control StructureDOI: 10.1201/9781003202035-44.1 Boolean Expressions
Arithmetic expressions evaluate numeric values; a Boolean expression, sometimes called a predicate, may have only one of two possible values: false or true. The term Boolean comes from the name of the British mathematician George Boole. A branch of discrete mathematics called Boolean algebra is dedicated to the study of the properties and the manipulation of logical expressions. While on the surface Boolean Expressions may appear very limited compared to numeric expressions, they are essential for building more interesting and useful programs [18 ].The simplest Boolean Expressions in Python are True and False . In a Python interactive shell we see:>>> True True >>> False False >>> type(True) <class 'bool'> >>> type(False) <class 'bool'>We see that bool is the name of the class representing Python’s Boolean Expressions. Program 4.1 (boolvars.py) above is a simple program that shows how Boolean variables can be used.Output a = True b = False a = False b = False# Assign some Boolean variables a = True b = False print('a =', a, ' b =', b) # Reassign a a = False; print('a =', a, ' b =', b)4.2 Additional Boolean Statements
We have seen that the simplest Boolean Expressions are false and true – the Python Boolean literals. A Boolean variable is also a Boolean expression. An expression comparing numeric expressions for equality or inequality is also a Boolean expression. These comparisons are done using relational operators. Table 4.1 - eBook - PDF
- Joyce Farrell(Author)
- 2012(Publication Date)
- Cengage Learning EMEA(Publisher)
All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it. The expressions hoursWorked > HOURS_IN_WK? and dentalPlan = Y? in Figures 3-3 and 3-4 are Boolean Expressions. A Boolean expression is one that represents only one of two states, true or false. Every decision you make in a computer program involves evaluating a Boolean expression. True/false evaluation is “ natural ” from a computer ’ s standpoint, because computer circuitry consists of two-state on-off switches, often represented by 1 or 0. Every computer decision yields a true-or-false, yes-or-no, 1-or-0 result. Mathematician George Boole (1815 – 1864) approached logic more simply than his predecessors did, by expressing logical selections with common algebraic symbols. Boolean (true/false) expressions are named for him. Using the Relational Comparison Operators Table 3-1 describes the six relational comparison operators supported by all modern programming languages. These operators are used to create Boolean Expressions. Each of these operators is binary — that is, each requires two operands. An operand is a value on either side of an operator. Usually, both operands in a comparison must be the same data type; that is, you can compare numeric values to other numeric values, and text strings to other strings. Operator Name Discussion = Equivalency operator Evaluates as true when its operands are equivalent. Many languages use a double equal sign ( == ) to avoid confusion with the assignment operator. > Greater than operator Evaluates as true when the left operand is greater than the right operand. - eBook - PDF
- Kyla McMullen, Elizabeth Matthews, June Jamrich Parsons, , Kyla McMullen, Kyla McMullen, Elizabeth Matthews, June Jamrich Parsons(Authors)
- 2021(Publication Date)
- Cengage Learning EMEA(Publisher)
Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it. PROGRAMMING WITH C++ 90 Boolean Expressions have similarities to Boolean data types. Both carry a value of True or False. In practice, however, you use a Boolean expression as part of a conditional statement, whereas you use a Boolean data type when making declaration or assignment statements. For example, you might want a variable called vip to hold True or False, depending on whether the customer has VIP status. In pseudocode you can initialize a Boolean variable like this: initialize bool vip = True In memory, Boolean variables hold 0 representing False, or 1 representing True. Theoretically, a Boolean requires only 1 bit of storage, but the actual storage requirements vary by language. Some programming languages, such as Python, require that True and False are capitalized. In other languages, such as C++ and Java, true and false have to be lowercase. In pseudocode, True and False are capitalized. Now take a look at the following pseudocode: declare bool vip assign vip = True if vip then output "Transferring you to the VIP agent." Q What is the Boolean variable in the pseudocode above? What is the conditional statement? What is the Boolean expression? A The Boolean variable is vip, which appears in the declaration and assignment statements. The conditional statement is if vip then. The Boolean expression is simply vip in the conditional statement. When a Boolean variable is used in a conditional statement, it does not need a relational operator. The Boolean is already either True or False, so it does not need a redundant expression, such as if vip == True. - eBook - PDF
Software Essentials
Design and Construction
- Adair Dingle(Author)
- 2014(Publication Date)
- Chapman and Hall/CRC(Publisher)
Boolean sentences may be rewritten according to many rules; techniques of simplification and logical equivalences permit transformations that retain the truth value of a Boolean expression. A clear understanding of Boolean Expressions helps one to write and read code, especially relative to the design of control structures. Boolean values are commonly manipulated with two binary operators: AND, commonly denoted by “^” or “&&”, and OR, denoted by “+” or “||”. The AND operation is known as conjunction and represents the combina-tion of two Boolean values such that the result is true if and only if both values are true. The OR operation is known as disjunction and represents the combination of two Boolean values such that the result is false if and only if both values are false. TABLE 3.2 Cluttered versus Readable Control Flow Cluttered Code Equivalent Streamlined Statement if (boolX) return true; else return false; return (boolX); if (boolY){ A; B; } else if (boolZ){ A; C; } else A; A; if (boolY) B; else if (boolZ) C; } Functionality ◾ 75 The logical OR differs from common usage of “or” in the English lan-guage. The colloquial question “would you prefer vanilla or chocolate ice cream?” implies a choice between two alternatives and usually would be answered with “vanilla” or “chocolate.” However, as a logical question, the answer would be true (affirmative) if one wanted either or both flavors and false if neither flavor would suffice. The logical operation EXCLUSIVE-OR or XOR denotes an evalua-tion more consistent with the use of “or” in the English language: p XOR q is true if and only if exactly one of the Boolean values is true. Thus, one chooses exactly one flavor, chocolate or vanilla, of ice cream. A sin-gle Boolean value or variable may be negated; negation is denoted by “!”. Table 3.3 is the classic truth table displaying the value of simple Boolean sentences. Many useful identities can be used to rewrite Boolean Expressions. - eBook - PDF
C# Programming
From Problem Analysis to Program Design
- Barbara Doyle, , , (Authors)
- 2015(Publication Date)
- Cengage Learning EMEA(Publisher)
However, many times selection statements are written that do not actually use a Boolean variable, but instead pro-duce a Boolean result. Boolean Results One of the great powers of the computer is being able to make decisions. You can write program statements that evaluate the contents of a variable. Based on the value of the variable, differing segments of code can be executed. Consider the following statements in Example 5-1. They are written in pseudocode. You will remember that pseudocode is “near code” but does not satisfy the syntax requirements of any programming language. Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it. Conditional Expressions | 259 5 EXAMPLE 5-1 1. if (gradePointAverage is greater than 3.80) awardType is assigned deansList 2. if (letterGrade is equal to ‘F’) display message “You must repeat course” 3. if (examScore is less than 50) display message “Do better on next exam” The three statements in Example 5-1 have common features. First, they each include a conditional expression, enclosed inside parentheses. Conditional expressions pro-duce a Boolean result. The result is either true or false . The first conditional expres-sion is ( gradePointAverage is greater than 3.80). Either gradePointAverage is greater than 3.8 ( true ) or it is not ( false ); similarly, letterGrade is equal to F ( true ) or it is not ( false ). The same holds for examScore . It does not matter how close the score is to 50. The result is true when examScore is less than 50. At other times, it is false . - eBook - PDF
- Xingni Zhou, Qiguang Miao, Lei Feng(Authors)
- 2020(Publication Date)
- De Gruyter(Publisher)
Logical operation • A logical operation connects one or more conditions using logical operators and determine whether these conditions are met. • A logical expression evaluates to a Boolean value (true of false). Logical expression • A logical expression is a statement that connects one or more expressions using logical operators and executes logical operations. We use logical expressions to express combination of multiple conditions in C. Figure 3.62: Logical operations and logical expressions. 3.7 Logical operations 121 (1) AND AND yields true if two operands are both true, and false otherwise. Suppose the operands are a and b, which are results of relational operations and are either true (1) or false (0). If a and b are both true (or 1), a AND b yields true; if one of them is false, the result is false. AND is similar to multiplication in their way of working. (2) OR OR yields false if two operands are both false, and true otherwise. OR is similar to addition in their way of working. (3) NOT NOT yields false if the operand is true, and true if the operand is false. We can remember rules of logical operators easily using this tip: AND yields false if one operand is false, OR yields true if one operand is true, NOT flips its operand. 3.7.2.3 Examples of Logical Operations Example 3.14 Classify a triangle There is a triangle whose edges have lengths a, b, and c, respectively. Use logical and condi-tional expressions in C to describe conditions for different types of triangles. [Analysis] The conditions and corresponding C expressions are shown in Figure 3.64. In the first row, an equilateral triangle requires a == b and a == c, which can be represented by a == b && a == c. - eBook - PDF
- Dale R. Patrick, Stephen W. Fardo, Vigyan Chandra(Authors)
- 2020(Publication Date)
- River Publishers(Publisher)
Boolean algebra is a special form of algebra that was designed to show the relationships of two-state variable logic operations. 49 50 Electronic Digital System Fundamentals This form of algebra is ideally suited for the analysis and design of binary logic systems. Through the use of Boolean algebra, it is possible to write mathematical expressions that describe specific logic functions. Boolean Expressions seem to be much more meaningful than complex word statements or elaborate truth tables. The laws that apply to Boolean algebra may also be used to simplify complex expressions. Through this type of operation, it may be possible to reduce the number of logic gates needed to achieve a specific function before it is built. In Boolean algebra the variables of an equation are commonly as-signed letters of the alphabet. Each variable then exists in states of 1 or 0 according to its condition. The 1, or true, state is normally represented by a single letter such as A, B, or C. The opposite state or condition is then described as 0, or false, and is represented by A or A’. This is described as NOT A, A negated, or A complemented. Boolean algebra is somewhat different from conventional algebra with respect to its mathematical operations. Boolean operators are con-cerned only with multiplication, addition, and negation. These are ex-pressed as follows. Multiplication: A AND B, AB, A x B Addition: A OR B, A + B Negation or complementation: NOT A, A , A *, A’ Equivalency: A equals B, A = B Boolean operators can be achieved with logic gates. An AND gate is used to accomplish multiplication. OR addition is achieved with an inclu-sive OR gate. Negation, or complementation, is achieved with an inverter, or NOT, gate. Boolean operators play an important role in the function of a digital system. We have looked at operator functions with respect to how they are accomplished with switches, diodes, transistors, and ICs. - No longer available |Learn more
- (Author)
- 2014(Publication Date)
- Orange Apple(Publisher)
Take for example the statement, The program should verify that the applicant has checked the male or female box. This should be interpreted as an XOR and a verification performed to ensure that one, and only one, box is selected. In other cases the proper interpretation of English may be less obvious; the author of the specification should be consulted to determine the original intent. ________________________ WORLD TECHNOLOGIES ________________________ Applications Digital electronic circuit design Boolean logic is also used for circuit design in electrical engineering; here 0 and 1 may represent the two different states of one bit in a digital circuit, typically high and low voltage. Circuits are described by expressions containing variables, and two such expressions are equal for all values of the variables if, and only if, the corresponding circuits have the same input-output behavior. Furthermore, every possible input-output behavior can be modeled by a suitable Boolean expression. Basic logic gates such as AND, OR, and NOT gates may be used alone, or in conjunction with NAND, NOR, and XOR gates, to control digital electronics and circuitry. Whether these gates are wired in series or parallel controls the precedence of the operations. Database applications Relational databases use SQL, or other database-specific languages, to perform queries, which may contain Boolean logic. For this application, each record in a table may be considered to be an element of a set. - eBook - PDF
- S Sasti D Sasti(Author)
- 2019(Publication Date)
- Macmillan(Publisher)
1 Module 1 Topic 1: Principles of digital electronics for computing Boolean algebra and logic gates Module 1 Overview At the end of this module, you will be able to: • Unit 1.1: Demonstrate algebraic laws using Boolean algebra. • Unit 1.2: Translate Boolean Expressions into logic diagrams and vice versa. • Unit 1.3: Use truth tables to represent Boolean Expressions. • Unit 1.4: Use decision tables to simplify Boolean Expressions. • Unit 1.5: Demonstrate knowledge of logic gates. • Unit 1.6: Demonstrate knowledge of the principles of logic devices. • Unit 1.7: Identify integrated circuits (ICs) that implement gates for computer systems. • Unit 1.8: Explain memory chips in terms of their use, functions and operational characteristics. Unit 1.1: Boolean algebra 1.1.1 Introduction You learned in Level 2 that computers are electronic devices made up of digital logic circuits that work on a sequence of ON or OFF switches. As programmers, we commonly refer to these switches as binary values represented by 1 or 0. Boolean algebra is a branch of mathematics based on logic . It has its own set of rules and laws which are used to analyse and simplify digital logic circuits. George Boole invented this logical way of analysing Boolean Expressions to produce either a TRUE or FALSE result which can be represented by 1 or 0. 1.1.2 Boolean algebra Definition: Boolean algebra Boolean algebra is the algebra of logic. Boolean algebra operates using the logical operators on Boolean values. We will look at some of the Boolean algebraic laws and operations in this module. Logical operators Refer to Table 1.1 for a brief explanation of logical operators. Did you know? In 1847, George Boole introduced the idea of Boolean algebra and Boolean logic in his first book, The Mathematical Analysis of Logic . His intention was to demonstrate how we can use mathematics to represent complex human reasoning in a logical way. This idea led to the design and logical working of computers. - eBook - PDF
- Vlad P. Shmerko, Svetlana N. Yanushkevich, Sergey Edward Lyshevski(Authors)
- 2018(Publication Date)
- CRC Press(Publisher)
When a Boolean formula is evaluated for all possible assignments of values to the variables, the set of pairs (assignment, value) is a Boolean function . For a given value of the binary variables, the function can be equal to either 1 or 0. Example 6.8 Boolean formulas can be evaluated using the following techniques: ( a ) Given the assignment ( x 1 = 1 , x 2 = 0 , x 3 = 1) , the value of the Boolean formula f = x 1 ∨ x 3 x 2 ∨ x 2 x 1 is calculated as follows: f = 1 ∨ 1 · 0 ∨ 0 · 1 = 1 ∨ 0 ∨ 0 = 1 . ( b ) The Boolean formula f = x 1 ∨ x 2 x 3 is equal to 1 if x 1 is equal to 1 or if both x 2 and x 3 are equal to 1. Formula f is equal to 0 otherwise. Boolean functions derived from formulas are called algebraic representations. Operations on Boolean variables such as Boolean sum, Boolean product, and complement can also be applied to the functions. Example 6.9 If f 1 = x 1 x 2 and f 2 = x 1 x 2 , then f = f 1 ∨ f 2 = x 1 x 2 ∨ x 1 x 2 . 6.4 Fundamentals of computing Boolean functions There are many forms that allow one each Boolean function to be described using algebraic representations. The efficiency of computing Boolean functions depends on the form of their representation. Foundation of Boolean Data Structures 141 6.4.1 Literals and terms The elementary groups of variables are Boolean terms: Boolean variables Boolean f unction Grouping −→ Boolean terms Boolean f unction The terms are composed of literals and are characterized as follows: A Boolean literal is either an uncomplemented or a complemented variable x i . The i -th literal is denoted by x c i i : where x 0 i = x i for c i = 0, and x 1 i = x i for c i = 1. A Boolean product term or product, is either a single literal, or the AND (product) of literals, that is, literals connected by the AND operation: x c 1 1 x c 2 2 . . . x c k k . A Boolean sum term , or sum, is either a single literal, or the OR (sum) of literals: x c 1 1 ∨ x c 2 2 ∨ . - Charles Roth, Jr., Larry Kinney, Eugene John, , Charles Roth, Jr., Larry Kinney, Eugene John(Authors)
- 2020(Publication Date)
- Cengage Learning EMEA(Publisher)
Usually, a 0 is assigned to the low voltage range and a 1 to the high voltage range. A logic gate which performs the AND operation is represented by The gate output is C = 1 if and only if the gate inputs A = 1 and B = 1. A logic gate which performs the OR operation is represented by The gate output is C = 1 if and only if the gate inputs A = 1 or B = 1 (or both). Electronic circuits which realize inverters and AND and OR gates are described in Appendix A. 2.3 Boolean Expressions and Truth Tables Boolean Expressions are formed by application of the basic operations to one or more variables or constants. The simplest expressions consist of a single constant or variable, such as 0, X, or Yuni2032 . More complicated expressions are formed by combin- ing two or more other expressions using AND or OR, or by complementing another expression. Examples of expressions are ABuni2032 + C (2-1) [A(C + D)] uni2032 + BE (2-2) Parentheses are added as needed to specify the order in which the operations are performed. When parentheses are omitted, complementation is performed first fol- lowed by AND and then OR. Thus in Expression (2-1), Buni2032 is formed first, then ABuni2032 , and finally ABuni2032 + C. A B C = A + B 0 0 0 0 1 1 1 0 1 1 1 1 A B C = A • B A B C = A + B + Copyright 2021 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it. 40 Unit 2 Each expression corresponds directly to a circuit of logic gates. Figure 2-1 gives the circuits for Expressions (2-1) and (2-2). An expression is evaluated by substituting a value of 0 or 1 for each variable.
Index pages curate the most relevant extracts from our library of academic textbooks. They’ve been created using an in-house natural language model (NLM), each adding context and meaning to key research topics.










