Skip to main content icon/video/no-internet

Logical expressions are statements that follow the rules of propositional logic both in their composition and their evaluation. They are used ubiquitously in programming and GIS applications to express the conditions or constraints that must be met prior to conducting certain operations.

Most logical expressions have a simple structure: two operands P and Q, connected with each other through a logical operator, such as AND, OR, XOR (exclusive OR), IMPLIES, and so on. All expressions evaluate to one of only two truth values: true or false. For example, the logical expression

P AND Q

evaluates to true if and only if both P and Q are true and evaluates to false in all other cases.

Both the operands of a logical expression and the expression itself can be made subject to the NOT modifier. For instance, the logical expression

NOT(P) AND Q

evaluates to true if and only if P is false and Q is true and evaluates to false in all other cases. Similarly, the expression

NOT(P AND Q)

evaluates to true if and only if either P or Q is false.

Logical Operators

Table 1 is a truth table that shows the truth values (true or false) for various logical expressions containing two operands and a single logical operator. These operators are described in the following sections.

Conjunction: AND

The conjunction P AND Q (in formal logic often written as PλQ) evaluates to true if both P and Q evaluate to true. The application of this type of expression is straightforward, as we can use it to say that a specific action X must be taken in case both P and Q are true. For instance,

Condition: if a location is within the metropolitan growth boundary AND the location is zoned “industrial”Action: add the location to the list of candidates for development of an industrial park

Disjunction: OR

The disjunction P OR Q (in formal logic often written as PηQ) evaluates to true if either P or Q is true. Disjunctions are easier to satisfy than conjunctions; in Table 1, PηQ evaluates to true in three of the four combinations of P's and Q's truth values, whereas the conjunction PλQ is true only in one of the four combinations.

Table 1 Truth Table
P, QP, Not(Q])Not(P), QNot(P), Not(Q)
P AND Qtruefalsefalsefalse
P OR Qtruetruetruefalse
P XOR Qfalsetruetruefalse
P NAND Qfalsetruetruetrue
P NOR Qfalsefalsefalsetrue
P implies Qtruefalsetruetrue

Exclusive or: XOR

The exclusive or expression P XOR Q (sometimes written as P⊕Q) evaluates to true if one of the operands P or Q is true and the other is false. The XOR is not elementary like OR and AND, as it can be rewritten as

  • (P AND NOT(Q)) OR (NOT(P) AND Q)

XOR expressions are used less frequently than conjunctions and disjunctions. They have some interesting applications, however. One of these is as a means to quickly convert between various series of operator values. To illustrate this, let the series 1101 represent four logical operands, P, Q, R and S, with a 1 representing true and a 0 representing false. XORing this series with another series, say 0101, yields 1101 XOR 0101 = 1000. Interestingly, if we now XOR, the result (1000) again with the series 0101, we obtain the original series back: 1000 XOR 0101 = 1101. Since series of 1s and 0s are used to represent numbers in binary form and since computers can manipulate binary numbers very rapidly, XORing is often used in computer programs that require certain properties to flip back and forth between two predefined values, using a third value as the XOR intermediary.

...

  • Loading...
locked icon

Sign in to access this content

Get a 30 day FREE TRIAL

  • Watch videos from a variety of sources bringing classroom topics to life
  • Read modern, diverse business cases
  • Explore hundreds of books and reference titles

Sage Recommends

We found other relevant content for you on other Sage platforms.

Loading