Skip to main content
\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)
Mathematics LibreTexts

17.2: Boolean Logic

  • Page ID
    34283
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)

    We can often classify items as belonging to sets. If you went the library to search for a book and they asked you to express your search using unions, intersections, and complements of sets, that would feel a little strange. Instead, we typically using words like “and”, “or”, and “not” to connect our keywords together to form a search. These words, which form the basis of Boolean logic, are directly related to our set operations. (Boolean logic was developed by the 19th-century English mathematician George Boole.)

    Boolean logic

    Boolean logic combines multiple statements that are either true or false into an expression that is either true or false.

    In connection to sets, a search is true if the element is part of the set.

    Suppose \(M\) is the set of all mystery books, and \(C\) is the set of all comedy books. If we search for “mystery”, we are looking for all the books that are an element of the set \(M\); the search is true for books that are in the set.

    When we search for “mystery and comedy”, we are looking for a book that is an element of both sets, in the intersection. If we were to search for “mystery or comedy”, we are looking for a book that is a mystery, a comedy, or both, which is the union of the sets. If we searched for “not comedy”, we are looking for any book in the library that is not a comedy, the complement of the set \(C\).

    Connection to Set Operations

    \(A\) and \(B\) elements in the intersection \(A \cap B\)

    \(A\) or \(B\) elements in the union \(A \cup B\)

    not \(A\) elements in the complement \(A^{c}\)

    Notice here that or is not exclusive. This is a difference between the Boolean logic use of the word and common everyday use. When your significant other asks “do you want to go to the park or the movies?” they usually are proposing an exclusive choice – one option or the other, but not both. In Boolean logic, the or is not exclusive – more like being asked at a restaurant “would you like fries or a drink with that?” Answering “both, please” is an acceptable answer.

    Example 1

    Suppose we are searching a library database for Mexican universities. Express a reasonable search using Boolean logic.Solution

    We could start with the search “Mexico and university”, but would be likely to find results for the U.S. state New Mexico. To account for this, we could revise our search to read:

    Mexico and university not “New Mexico”

    In most internet search engines, it is not necessary to include the word and; the search engine assumes that if you provide two keywords you are looking for both. In Google’s search, the keyword or has be capitalized as OR, and a negative sign in front of a word is used to indicate not. Quotes around a phrase indicate that the entire phrase should be looked for. The search from the previous example on Google could be written:

    Mexico university -“New Mexico”

    Example 2

    Describe the numbers that meet the condition:

    even and less than 10 and greater than 0

    Solution

    The numbers that satisfy all three requirements are \(\{2,4,6,8\}\)

    Sometimes statements made in English can be ambiguous. For this reason, Boolean logic uses parentheses to show precedent, just like in algebraic order of operations.

    Example 3

    Describe the numbers that meet the condition:

    odd number and less than 20 and greater than 0 and (multiple of 3 or multiple of 5)

    Solution

    The first three conditions limit us to the set \(\{1,3,5,7,9,11,13,15,17,19\}\)

    The last grouped conditions tell us to find elements of this set that are also either a multiple of 3 or a multiple of \(5 .\) This leaves us with the set \(\{3,5,9,15\}\)

    Notice that we would have gotten a very different result if we had written

    (odd number and less than 20 and greater than 0 and multiple of 3) or multiple of 5

    The first grouped set of conditions would give {3, 9, 15}. When combined with the last condition, though, this set expands without limits:

    \(\{3,5,9,15,20,25,30,35,40,45, \dots\}\)

    Example 4

    The English phrase “Go to the store and buy me eggs and bagels or cereal” is ambiguous; it is not clear whether the requestors is asking for eggs always along with either bagels or cereal, or whether they’re asking for either the combination of eggs and bagels, or just cereal.

    For this reason, using parentheses clarifies the intent:

    Eggs and (bagels or cereal) means Option 1: Eggs and bagels, Option 2: Eggs and cereal

    (Eggs and bagels) or cereal means Option 1: Eggs and bagels, Option 2: Cereal

    Be aware that when a string of conditions is written without grouping symbols, it is often interpreted from the left to right, resulting in the latter interpretation.


    17.2: Boolean Logic is shared under a CC BY-SA 3.0 license and was authored, remixed, and/or curated by David Lippman via source content that was edited to conform to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.

    • Was this article helpful?