4. Logic

CAUTION - CHAPTER UNDER CONSTRUCTION!

This chapter was last updated on February 18, 2025.
Added link to DNF and CNF website
Contents locked until 11:59 p.m. Pacific Standard Time on May 23, 2025.

Logic is the study of reasoning. Logic is used to create, analyze, and validate arguments, where an argument is a finite sequence of statements that ends with a conclusion based on inferences made from earlier statements in the argument.

Among the applications of logic to computer science are design of electronic circuits and validation of algorithms and programs.

Key terms and concepts covered in this chapter:

  • Propositional logic (also called "propositional calculus")

    • Logical operators (also called "logical connectives")

      • Negation ("not")

      • Conjunction ("and")

      • Disjunction ("or")

      • Conditional ("implication")

        • The converse, inverse, and contrapositive of a conditional

      • Biconditional ("if and only if," abbreviated as "iff")

    • Truth tables

    • Well-formed formulas

    • Satisfiability, tautology, and contradiction

    • Normal forms (conjunctive and disjunctive)

  • Predicate logic

    • Predicates as "statement-valued functions"

    • Quantification of Predicates

      • Universal quantifier

      • Existential quantifier

  • To be added to this chapter after May 23, 2025:

    • Limitations of propositional and predicate logic (e.g., expressiveness issues)

    • Boolean algebra and Boolean circuits

4.1. Propositional Logic

A proposition is a statement that declares a fact that is either True or False (but not both!)

Propositions
  • Atlanta is the capital of California.

  • \(1 + 1 = 2\)

  • \(1 + 1 = 3\)

Not propositions
  • How much is this cookie?

  • Please sit down.

  • Wow!

  • This sentence is false.

  • \(x + 1 = y\)

Propositional logic consists of a set of formal rules for combining propositions in order to derive new propositions.

A goal of propositional logic is to have a method for creating valid arguments that are sequences of propositions, where the correctness and validity of the argument is based solely on the propositions' truth values (True and False), ignoring the actual content of the propositions. Compare this to doing algebra: You can write \(2 (x + 3 y) = 2x + 6y\) because it is a correct and valid step to distribute multiplication over addition. You can do the algebra and ignore the specific numerical values (the "numerical content") that \(x\) and \(y\) stand for.

In propositional logic, it is traditional to use propositional variables such as p, q, and r to stand for the possible assignments of truth values to propositions; often, the propositional variables themselves are referred to as the propositions. Again, compare this to the algebraic example where you can treat \(x\) and \(y\) as numbers even though they are actually variables that stand for numbers.

What is the advantage of using symbols? A long time ago, philosophers discovered that is easier to follow lines of reasoning by putting our thoughts into symbols. This was an important step in the eventual development of modern technological society and, in particular, electronic computers. Before a computer can do its work, humans need to put our thoughts into them; however, a spoken language like English can be too difficult to use because many different phrases can represent the same logical statements.

Example 1 - Generalizing and abstracting an argument

Consider the following argument consisting of three propositions:

  • Sarah earned a B.S. in Computer Science.

  • Anyone who earned a B.S. in Computer Science must have earned a C or better in Discrete Math.

  • Therefore, Sarah earned a C or better in Discrete Math.

This argument is valid: If you ASSUME that the first two propositions are True, then you can correctly conclude that the third proposition (which follows the introductory phrase "Therefore,") must be True as well.

Notice that you could change the name "Sarah" to "Daniel" without affecting the validity of the argument.

You can generalize the argument by changing "Sarah" to "the student." In fact, you can generalize much more by noticing that the form of the argument matches the following argument.

  • Individual X is a member of category A

  • Any individual that is a member of category A must also be a member of category B.

  • Therefore, individual X is a member of category B

You can make this argument completely abstract using propositional variables.

  • p is true.

  • The implication "if p then q " is true, too.

  • Therefore, q is true

You can build compound propositions (also called "propositional functions") from simpler propositions. For example, in the preceding example, the compound propostion "if p then q " was introduced as a new proposition built from the propositional variables p and q . In the next section, you will learn how to represent compound propositions using symbols.

4.2. Logical Operations and Truth Tables

In this section, compound propostions will be represented by using propositional variables and logical operator symbols (also called "logical operations" or "logical connectives") Once again, you can compare this to how numerical and algebraic relationships can be represented in symbols using algebraic expressions built with the usual arithmetic operator symbols with variables and numerals.

In Python, we use \(\texttt{Boolean}\) variables to represent propositions and define functions for each compound proposition. Each compound proposition can implemented using the \(\texttt{Boolean}\) operations \(\texttt{not}\), \(\texttt{and}\), and \(\texttt{or}\) discussed in the section Operators and Expressions in the chapter "Appendix: An Introduction to Python".

A truth table can be used to display the truth values of a compound proposition that is built from propositional variables and logical operators. A truth table is created with rows representing all possible interpretations of the propositional variables, that is, all possible assignments of truth values to the propositional variables. Each column of a truth table displays the truth values for either one of the propositional variables or a compound proposition built up from propositional variables and/or simpler compound propositions. As an analogy, think of how a table can be used to display the numerical input and output values of a function represented by an algebraic expression.

The most commonly-used logical operators are described in the rest of this section.

4.2.1. Negation

"I am not an astronaut."

The negation of a proposition \(p\), denoted in mathematics by \(\neg p\) and read as "not \(p\)", is the proposition "It is not the case that \(p\)". The proposition \(\neg p\) has the opposite truth value to \(p.\)
Other textbooks and sources may use \(\overline{p}\) or \(\sim \! p\) to represent \(\neg p.\)

\(p\) \(\neg p\)

True

False

False

True

For example, the negation of the proposition "Today is Friday." would be "It is not the case that today is Friday." or more succinctly "Today is not Friday."
For a proposition \(p,\) exactly one of \(p\) and \(\neg p\) is True and exactly one is False. Two propositions can be contrary (that is, they could not both be True) without being negations of each other: As an example, both of the propositions "Today is Friday." and "Today is Saturday." could be False, so "Today is Saturday." is not the negation of "Today is Friday."

Notice that the two propositions \(p\) and \(\neg (\neg p)\) must always have the same truth value (You can see this by inserting a column for \(\neg (\neg p)\) in the truth table shown earlier in this subsection.)

In the first few truth tables in this chapter, "True" and "False" are spelled out, but it is more often the case that these words are abbreviated to their first letters, "T" and "F" in truth tables.
Example 2 - Negation in Python

The code below prints the truth table for negation. Note that the values True and False are constants in Python, and that not p implements the negation \(\neg p\) in Python.

Try to predict the variable names, values, and data types at different steps in the execution. Use the Next button to check your answers.

4.2.2. Conjunction

"I am a rock and I am an island."

Let \(p\) and \(q\) be propositions. The conjunction of \(p\) and \(q\), denoted in mathematics by \(p \land q\) and read as "\(p\) and \(q\)", is True when both \(p\) and \(q\) are True and is False otherwise.

\(p\) \(q\) \(p \land q\)

True

True

True

True

False

False

False

True

False

False

False

False

Notice that the two propositions \(p \land q\) and \(q \land p\) always have the same truth value.

Example 3 - Conjunction in Python

The code below prints the truth table for conjunction. Try to predict the variable names, values, and data types at different steps in the execution. Use the Next button to check your answers.

4.2.3. Disjunction

"They studied hard or they are extremely bright."

Let \(p\) and \(q\) be propositions. The disjunction of \(p\) and \(q\), denoted in mathematics by \(p \lor q\) and read as "\(p\) or \(q\)", is True when at least one of \(p\) and \(q\) are True and is False otherwise.

\(p\) \(q\) \(p \lor q\)

True

True

True

True

False

True

False

True

True

False

False

False

Notice that the two propositions \(p \lor q\) and \(q \lor p\) always have the same truth value.

Example 4 - Disjunction in Python

The code below prints the truth table for disjunction. Try to predict the variable names, values, and data types at different steps in the execution. Use the Next button to check your answers.

4.2.4. Conditional

" If you get a 100 on the final exam, then you earn an A in the class."

Let \(p\) and \(q\) be propositions. The conditional statement \(p \rightarrow q\), read as "if p then q ", " p implies q ", or, more formally, "the conditional with hypothesis p and conclusion q ", is the proposition that is False when p is True and q is False, and True otherwise. The conditional statement \(p \rightarrow q\) is also called "the implication \(p \rightarrow q\)".
The conditional \(p \rightarrow q\) can also be denoted by \(p \Rightarrow q\) or \(p \implies q.\) In addition, there are many other ways to express the conditional \(p \rightarrow q\) in English, two of which are " p only if q " and " q if p ".

\(p\) \(q\) \(p \rightarrow q\)

True

True

True

True

False

False

False

True

True

False

False

True

  • \(p \rightarrow q\) and \(q \rightarrow p\) do NOT always have the same truth value!

  • The conditional can be considered a "contract" which fails only when the conditions are met and the results are not fulfilled.

  • The conditional may or may not represent a "cause-and-effect" relationship. For example, the conditional "if Shakespeare wrote Hamlet then \(2 + 2 = 4\)" is a True proposition because the conclusion "\(2 + 2 = 4\)" is True, but the arithmetic equation is not an effect that was caused by the authorship of Hamlet .

Example 5 - You Try: Conditional in Python

Complete the code below by clicking one of the "edit" links then replacing \(#FIX ME#\) with an expression involving \(p\), \(q\), and some of the Python operators not , and , and or . Once correctly defined, the correct truth table for the conditional statement should print.

The Converse, Contrapositive and Inverse of a Conditional Statement

Given propositions p and q , we can form three additional compound propositions that are related to the conditional \(p \rightarrow q\):

  • \(q \rightarrow p\), called the converse of \(p \rightarrow q\)

  • \( \neg q \rightarrow \neg p\), called the contrapositive of \(p \rightarrow q\)

  • \( \neg p \rightarrow \neg q\), called the inverse of \(p \rightarrow q\)

The extended truth table for the conditional and the three related propositions is shown below.

\(p\) \(q\) \(p \rightarrow q\) (conditional) \(q \rightarrow p \) (converse) \( \neg q \rightarrow \neg p\) (contrapositive) \( \neg p \rightarrow \neg q\) (inverse)

True

True

True

True

True

True

True

False

False

True

False

True

False

True

True

False

True

False

False

False

True

True

True

True

From the truth table it can be seen that

  • \(p \rightarrow q\) and the converse \(q \rightarrow p\) do NOT always have the same truth value!

  • \(p \rightarrow q\) and its contrapositive \( \neg q \rightarrow \neg p\) MUST have the same truth value!

  • The converse \(q \rightarrow p\) and the inverse \( \neg p \rightarrow \neg q\) MUST have the same truth value.

In the section on logically equivalent propositions we will discuss the bullet points in the preceding note in more detail.

The next example illustrates these four propositions.

Example 6 - Conditional, Converse, Contrapositive and Inverse.
  1. Translate the statement "If the number of students in class is divisible by 4, then the number of students in class is divisible by 2" using a conditional.

  2. Form and translate the converse, contrapositive, and inverse.

Solution
  1. Let

    \(p\) be the proposition "The number of students in class is divisible by 4."

    \(q\) be the proposition "The number of students in class is divisible by 2."

    The conditional \(p\rightarrow q\) translates as "If the number of students in class is divisible by 4, then the number of students in class is divisible by 2."

  2. The converse \(q \rightarrow p\) may be translated as "If the number of students in class is divisible by 2, then the number of students in class is divisible by 4."

    The contrapositive \( \neg q \rightarrow \neg p\) may be translated as "If the number of students in class is not divisible by 2, then the number of students in class is not divisible by 4."

    The inverse \( \neg p \rightarrow \neg q\) may be translated as "If the number of students in class is not divisible by 4, then the number of students in class is not divisible by 2."

Notice that in this example, the conditional must be True, based on properties of factors of integers, but its converse could be False: Consider the case where the number of students in class is equal to 26, so \(p\) is False and \(q\) is True, and \(p\rightarrow q\) is True but \(q\rightarrow p\) is False. This also shows, again, that the conditional need not represent a "cause-and-effect" relationship, since NOT being "divisible by 4" does not let us conclude anything about being "divisible by 2".

4.2.5. Biconditional

"It is raining outside if and only if it is a cloudy day."

Let \(p\) and \(q\) be propositions. The biconditional \(p \leftrightarrow q\), read as " p if and only if q ", is the proposition that is True when p and q have the same truth value, and False otherwise. The biconditional is also called "the bi-implication". Note that \(p \leftrightarrow q\) can also be denoted by \(p \Leftrightarrow q\) or \(p \iff q.\)

\(p\) \(q\) \(p \leftrightarrow q\)

True

True

True

True

False

False

False

True

False

False

False

True

You can use a truth table to show that two propositions \(p \leftrightarrow q\) and \(q \leftrightarrow p\) always have the same truth value.

The biconditional \(p \leftrightarrow q\) is read as " p if and only if q " because it has the same truth table as the conjunction of the two conditionals " p if q " (that is, \(q \rightarrow p\)) and " p only if q " (that is, \(p \rightarrow q\)).

Example 7 - You Try: Biconditional in Python

Complete the code below by clicking one of the "edit" links then replacing \(#FIX ME#\) with an expression involving \(p\), \(q\), and some of the Python operators not , and , and or . Once correctly defined, the correct truth table for the biconditional statement should print.

It is important to contrast the conditional with the biconditional. Consider the conditional example "If you get a 100 on the final exam, then you earn an A in the class." This means that when you get a 100 on the final you also get an A in the class. The conditional represents a one-way contract: You earn an A in the class if you get a 100 on the final exam. There is nothing said about the result (the grade you earn in the class) if you do NOT meet the condition (get a 100 on the final exam).

As a biconditional the example would say "You get a 100 on the final exam if and only if you earn an A in the class." This becomes a two-way contract: You earn an A in the class if you get a 100 on the final, but you do not earn an A in the class if you do not get a 100 on the final.

4.2.6. Other Compound Propositions

The negation, disjunction, conjunction, conditional, and biconditional are the most commonly-used logical operators for forming compound propostions and will be the ones used throughout the rest of this chapter. However, there are at least three others you should know about.

Exclusive Disjunction

"I took either 2 Advil or 2 Tylenol."

Let \(p\) and \(q\) be propositions. The exclusive disjunction of \(p\) and \(q\) (also known as xor ), denoted in mathematics by \(p \oplus q\), is True when exactly one of \(p\) and \(q\) are True and False otherwise.

\(p\) \(q\) \(p \oplus q\)

True

True

False

True

False

True

False

True

True

False

False

False

Notice that the two propositions \(p \oplus q\) and \(q \oplus p\) always have the same truth value.

The NAND and NOR Operators

The NAND and NOR operators correspond to two important digital logic gates used in electronic devices.

NAND

"An onion is not both a fruit and a vegetable."

Let \(p\) and \(q\) be propositions. In this textbook, the NAND of \(p\) and \(q\) is denoted by \(p \uparrow q\) and is False when both \(p\) and \(q\) are True and is True otherwise. That is, the NAND is the negation of \(p \land q\) - think of NAND as "Not AND."

\(p\) \(q\) \(p \uparrow q\)

True

True

False

True

False

True

False

True

True

False

False

True

Notice that the two propositions \(p \uparrow q\) and \(q \uparrow p\) always have the same truth value.

NOR

"This pen’s ink is neither red nor blue."

Let \(p\) and \(q\) be propositions. In this textbook, the NOR of \(p\) and \(q\) is denoted by \(p \downarrow q\) and is True when both of \(p\) and \(q\) are False and is False otherwise. The NOR is also referred to as "joint denial" since it is True exactly when neither \(p\) nor \(q\) is True. That is, the NOR is the negation of \(p \lor q.\)

\(p\) \(q\) \(p \downarrow q\)

True

True

False

True

False

False

False

True

False

False

False

True

Notice that the two propositions \(p \downarrow q\) and \(q \downarrow p\) always have the same truth value.

4.2.7. Well-Formed Formulae and Operator Precedence (Order Of Operations)

A well-formed formula (or wff for short) is a string of symbols that represents a compound propsition.

Here is a recursive definition of wff:

  • A propositional variable is a well-formed formula.

  • If \(\alpha\) ("alpha") and \(\beta\) ("beta") are well-formed formulas, then the following are also well-formed formulas:

    • \(\left( \neg \alpha \right)\)

    • \(\left( \alpha \land \beta \right)\)

    • \(\left( \alpha \lor \beta \right)\)

    • \(\left( \alpha \rightarrow \beta \right)\)

    • \(\left( \alpha \leftrightarrow \beta \right)\)

The definition of wff allows you or, even better, a computer to analyze any string of symbols to determine whether the string of symbols is a wff. For example, \((p \land q \lor r)\) isn’t a wff but both \((p \land (q \lor r))\) and \(((p \land q) \lor r)\) are wffs. You could write code to implement an algorithm to validate a string as a wff.

It can be shown that every compound proposition can be represented by at least one wff. However, a wff may be difficult to read quickly if it contains many parentheses. As an example, it is not easy to read \(( (p \rightarrow q) \lor ( (\neg r) \land (s \leftrightarrow t) ) )\). For this reason, we can introduce operator precedence rules that allow us to eliminate some of the parentheses.

To evaluate a compound proposition, we start by evaluating

  • all expressions enclosed in parentheses from left to right, then

  • all negations from left to right, then

  • all conjunctions from left to right, then

  • all disjunctions from left to right, then

  • all conditionals from left to right, and finally

  • all biconditionals from left to right.

This allows us to drop some parentheses from a wff that represents a compound proposition.

For example, the compound proposition \(\neg p \lor q \land r \rightarrow s\) represents the same proposition as the wff \((((\neg p) \lor (q \land r)) \rightarrow s)\). At least some of the parentheses must be used if you want to represent a different proposition such as \((\neg p \lor q) \land (r \rightarrow s)\).

4.2.8. Truth Tables of Compound Propositions

To compute the truth values of a longer compound proposition or wff by hand, it can be useful to break up the proposition or wff into the smaller propositions or wffs that it was built from.

Example 8

The code below reveals the truth table of the compound proposition:

\((p \land q) \lor \neg q\)

Recall: \(\neg q\) is mathematical shorthand for not q .

You Try

Edit the code above to reveal the truth value of the compound proposition:

\((p \lor \neg q) \land \neg p\)

Hint: You only need to change line 10.

When creating your own truth table it is crucial to be systematic about ensuring you have all possible truth values for each of the simple propositions. Each simple proposition has two possible truth values, so the number of rows in the table should be \(2^n\) where \(n\) is the number of propositions (Do you recall why the number of rows must be \(2^n\)?) You should also consider breaking complex propositions into smaller pieces.

Example 9

Create a truth table for the compound proposition:

\((p \land q) \rightarrow (p \land r)\) for all values of \(p, q, r\).

Solution

It should have 8 rows - since there are three simple propositions and each one has two possible truth values.

\(p\) \(q\) \(r\) \(p \land q\) \(p \land r\) \((p \land q) \rightarrow (p \land r)\)

T

T

T

T

T

T

T

T

F

T

F

F

T

F

T

F

T

T

T

F

F

F

F

T

F

T

T

F

F

T

F

T

F

F

F

T

F

F

T

F

F

T

F

F

F

F

F

T

4.3. Logically Equivalent Propositions

Recall that an interpretation of a proposition is an assignment of truth values to the propositional variables.

Two propositions are considered logically equivalent (or simply equivalent ) if they have the same truth values for every possible interpretation. It is often easiest to see this by constructing a truth table for the two propositions and comparing.

Example 10

Consider the propositions \(\neg p \lor q\) versus \(p\rightarrow q\).

\(p\) \(q\) \(\neg p \lor q\) \(p \rightarrow q\)

True

True

True

True

True

False

False

False

False

True

True

True

False

False

True

True

Since the truth table in all rows is the same for the two compound propositions, they are equivalent.

We use the symbol \(\equiv\) to denote that two propositions are logically equivalent. So in the preceding example, we would write \(\neg p \lor q \equiv p\rightarrow q\).

\(\equiv\) is NOT a logical operator used to build compound propositions, but instead is used to say that two propositions are logically equivalent. This is similar to how \(=\) is used in arithmetic: We can write \(2 + 2 = 5 - 1\) to say that \(2 + 2\) and \(5 - 1\) are numerically equivalent, but we don’t use the \(=\) sign as an arithmetic operator to actually do any arithmetic.
Saying that two propositions p and q are logically equivalent is the same as saying that the biconditional compound proposition \(p \leftrightarrow q\) is always True.
Example 11

Consider three compound propositions:

  1. \((p\land q) \rightarrow r\)

  2. \((p \rightarrow q) \land (p \rightarrow r)\)

  3. \(p \rightarrow (q \land r)\)

The code below reveals the truth table for 1. Modify it for 2 and 3 in order to determine which set of compound propositions are equivalent.

Hint: You only need to change line 11.

4.3.1. Tautologies, Contradictions and Contingencies

A proposition is a tautology if its truth value is always True. That is, a tautology is True for every possible interpretation of its propositional variables.

A proposition is called satisfiable if there is at least one interpretation for which the proposition is True.

A proposition is unsatisfiable if there is no interpretation for which the proposition is True.

A proposition is a contradiction if its truth value is always False. That is, a contradiction is False for every possible interpretation of its propositional variables. This is just another way of saying that it is unsatisfiable.

A proposition that is neither a tautology nor a contradiction is said to be a contingency since its truth value can be either True or False, contingent on the truth value assigned to its propositional variables.

Example 12 - Tautology and Contradiction

\(p \lor \neg p\) is an example of a tautology.

\(p \land \neg p\) is an example of a contradiction.

This can be seen in the truth table.

\(p\) \(\neg p\) \( p \lor \neg p\) \(p \land \neg p\)

True

False

True

False

False

True

True

False

Notice that the truth values for \(p \lor \neg p\) are all True and \(p \land \neg p\) are all False.

The two compound propositions in the previous example are so important that they have their own names,

The Law of Excluded Middle

Given any proposition \(p\), the compound proposition \[p \lor \neg p\] is a tautology (that is, the compound proposition is always True.)

The Law of Contradiction

Given any proposition \(p\), the compound proposition \[p \land \neg p\] is a contradiction (that is, the compound proposition is always False.)

4.3.2. De Morgan’s Laws

Two important logical equivalences are De Morgan’s Law. These describe how to "distribute" the \(\neg\) operator across the \(\land\) and \(\lor\) operators.

De Morgan’s Laws

\(\neg (p \land q)\equiv \neg p \lor \neg q\)

\(\neg (p \lor q)\equiv \neg p \land \neg q\)

De Morgan’s Laws can be verified by creating truth tables for \(\neg (p \land q) \leftrightarrow \neg p \lor \neg q\) and \(\neg (p \lor q) \leftrightarrow \neg p \land \neg q\) to show that these propositions are True for every interpretation of \(p\) and \(q\).

4.3.3. Some Other Logical Equivalencies

Here is a collection of additional equivalencies of compound propositions. Each of these can be verified by constructing a truth table to show that the biconditional of the left-hand side and the right-hand side of the logical equivalence is true for all interpretations of the propositional variables.

Double Negation: \[ p \equiv \neg (\neg p) \]

Commutative laws: \[ p \lor q \equiv q \lor p \] \[ p \land q \equiv q \land p \]

Associative laws: \[ p \lor (q \lor r) \equiv (p \lor q) \lor r \] \[ p \land (q \land r) \equiv (p \land q) \land r \]

Distributive laws: \[ p \lor (q \land r) \equiv (p \lor q) \land (p \lor r) \] \[ p \land (q \lor r) \equiv (p \land q) \lor (p \land r) \]

4.3.4. Disjunctive Normal Form (DNF)

It is traditional to focus on negation \(\neg\), conjunction \(\land\), and disjunction \(\lor\) as the three primary logical operations. This is because any compound proposition can be rewritten in terms of these three operations and the propositional variables present in the original compound proposition.

One way to justify this is by using an expression in disjunctive normal form (DNF), which is a disjunction of one or more conjunctions, where only one of the conjunctions can be true for any interpretation of the propositional variables. This description should become clearer after reading the following example.

Example 13 - Finding A Logically Equivalent Proposition (DNF) From A Truth Table

Suppose we have a truth table for an unknown compound proposition. Perhaps someone wrote the truth table but did not write down the expression for the compound proposition in the header of the rightmost column.

\(p\) \(q\) \(r\) \(\text{unknown}\)

T

T

T

F

T

T

F

F

T

F

T

T

T

F

F

F

F

T

T

F

F

T

F

T

F

F

T

T

F

F

F

F

We can write a new compound proposition that is equivalent to the unknown one, using the propositional variables \(p\), \(q\), and \(r\) and the logical operators \(\neg\), \(\land\) and \(\lor\) as follows:

  • For each row of the truth table that has T in the rightmost column, write the conjunction that would have a T in only that one row of its truth table.

  • Form the disjunction of all the conjunctions found in the previous step. This new expression is called a disjunctive normal form (DNF) for the unknown proposition.

For the truth table above, we have three rows with T in the rightmost column. The first of the three rows corresponds to \(p \land \neg q \land r\), which is only True if \(p\) is True, \(q\) is False, and \(r\) is True. In the same way, the second of the three rows corresponds to \(\neg p \land q \land \neg r\), and the third of the three rows corresponds to \(\neg p \land \neg q \land r\). We now form the disjunction of these three expressions. \[(p \land \neg q \land r) \lor (\neg p \land q \land \neg r) \lor (\neg p \land \neg q \land r)\]

This new compound proposition has a truth table that is the same as the one for the unknown proposition. This means that the expression we found is logically equivalent to the unknown proposition.

\(p\) \(q\) \(r\) \(\text{unknown}\) \((p \land \neg q \land r) \lor (\neg p \land q \land \neg r) \lor (\neg p \land \neg q \land r)\)

T

T

T

F

F

T

T

F

F

F

T

F

T

T

T

T

F

F

F

F

F

T

T

F

F

F

T

F

T

T

F

F

T

T

T

F

F

F

F

F

4.3.5. Conjunctive Normal Form (CNF)

In some applications of propositional logic, it is more useful to find a logically equivalent expression for a given proposition that is written as a conjunction of several disjunctions. This conjunctive normal form (CNF) can be constructed as shown in the following example.

Example 14 - Finding A Logically Equivalent Proposition (CNF) From A Truth Table

Consider the same unknown proposition we used in the previous example.

\(p\) \(q\) \(r\) \(\text{unknown}\)

T

T

T

F

T

T

F

F

T

F

T

T

T

F

F

F

F

T

T

F

F

T

F

T

F

F

T

T

F

F

F

F

One way to find a CNF is as follows.

  • Find the disjunctive normal form for the negation of the unknown proposition.

  • Apply De Morgan’s Laws to the DNF for the negation of the unknown proposition found in the first step - the result will be a CNF for the double negation of the unknown proposition (which is logically equivalent to the unknown proposition).

\(p\) \(q\) \(r\) \(\text{unknown}\) \(\neg \text{unknown}\)

T

T

T

F

T

T

T

F

F

T

T

F

T

T

F

T

F

F

F

T

F

T

T

F

T

F

T

F

T

F

F

F

T

T

F

F

F

F

F

T

From the truth table above, we obtain the following DNF for the negation of the unknown proposition: \((p \land q \land r) \lor (p \land q \land \neg r) \lor (p \land \neg q \land \neg r) \lor (\neg p \land q \land r) \lor (\neg p \land \neg q \land \neg r)\).

Next, we negate the DNF, using De Morgan’s Laws, and simplify the resulting expression \[\neg [ (p \land q \land r) \lor (p \land q \land \neg r) \lor (p \land \neg q \land \neg r) \lor (\neg p \land q \land r) \lor (\neg p \land \neg q \land \neg r) ],\] which simplifies to the CNF we wanted to find, \[(\neg p \lor \neg q \lor \neg r) \land (\neg p \lor \neg q \lor r) \land (\neg p \lor q \lor r) \land (p \lor \neg q \lor \neg r) \land (p \lor q \lor r).\]

The last expression is logically equivalent to the unknown proposition.

Here is a website that allows you to build the DNF and CNF for a given propositional function.

4.3.6. Functional Completeness

A set \(S\) of logical operators is called functionally complete if every compound proposition is logically equivalent to a compound proposition involving only operators that are members of \(S.\)

Theorem

The set \(\{ \neg , \land , \lor \}\) is functionally complete.

Proof
An informal justification can use the method shown in the previous examples for finding a DNF or CNF. A formal proof requires the mathematical induction proof technique and the recursive defintion of well-formed formulae given earlier in this chapter.

The importance of the NAND and NOR in electronic circuits arises from the following theorem.

Theorem
  1. The set \(\{ \uparrow \}\) is functionally complete. That is, any compound proposition is logically equivalent to a compound proposition involving the same variables and only the \(\uparrow\) operator.

  2. The set \(\{ \downarrow \}\) is functionally complete. That is, any compound proposition is logically equivalent to a compound proposition involving the same variables and only the \(\downarrow\) operator.

Proof
These proofs are exercises for you. See the Challenge Exercises at the end of this chapter.

4.4. Predicates and Quantifiers

Up to this point, most of our propositions have been of the form "Sarah earned a B.S. in Computer Science" - the proposition describes a single individual constant (in this case, "Sarah.")

However, we often need to discuss an entire category of individuals at once, which is equivalent to replacing the constant "Sarah" by a variable. We will discuss this idea in this section.

4.4.1. Predicates

A predicate is a statement that includes one or more variables such that when values are assigned to the variables the predicate becomes a proposition.

Example 15 - Predicates
  • \(x \leq 3\)

  • Computer \(c\) is infected.

  • Country \(x\) is on continent \(y\).

Predicates are denoted as \(P(x)\) or \(Q(x,y)\) where \(P\) and \(Q\) represent the statements and \(x\) and \(y\) are variables. After a value is assigned to each variable, the predicate becomes a proposition which has a truth value. That is, we "evaluate" a predicate by substituting inputs into the variables and get a proposition as the output.

Example 16

Let \(P(x)\) be the predicate \(x \leq 3\).

What are the propositions \(P(5)\) and \(P(2)\)? What are the truth values of \(P(5)\) and \(P(2)\)?

Example 17

Let \(P(x)\) be the predicate "The sum of the first \(n\) positive odd integers is equal to \(n^{2}\)."

What are the propositions \(P(1{\small,}000)\) and \(P(1{\small,}000{\small,}000)\) ? Notice that code correctly outputs the two propositions as strings (of type str in Python). The predicate does not tell us whether the propositions it outputs are True or False.

Example 18

Let \(Q(x,y)\) be the statement \(x-y=4\).

The Python code displays each of the three propositions \(Q(6,2)\), \(Q(1,5)\), and \(Q(-2,2)\) and describes their truth values.

4.4.2. Quantifiers

Consider the statements

  • For all integers \(x\), \(x^2\geq 0\).

  • Some student in the class has a birthday in July.

Each of these statements considers a proposition over an entire population or set, called the domain, and describes whether at least one element, or all of the elements in the domain satisfy the proposition. There are two commonly-used quantifiers, the universal quantifier and the existential quantifier .
The domain is also called the domain of discourse or the universe of discourse.

The Universal Quantifier, \(\forall,\) represents the statement "for all", "for every", "for each". When it comes before a statement, it means that statement is true for all values in the domain.

Example 19

Universal Quantifier \(\forall x, x + 1 \gt x\)

Let \(P(x)\) be the statement \(x + 1 \gt x\). Is this true for all integers x?

We use the example domain [-2, -1, 0, 1, 2] because code can not check all integers.
Example 20

Universal Quantifier \(\forall x, x + x \gt x\)

Let \(P(x)\) be the statement \(x + x \gt x\). Is this true for all integers x?

The Existential Quantifier, \(\exists,\) represents the statement "there exists", "for some", "at least one". When it comes before a statement, it means the statement is true for at least one value in the domain.

Example 21

Existential Quantifier \(\exists x, x^2 = 4\)

Let \(P(x)\) be the statement \(x^2 = 4\). Is this true for at least one integer x?

Example 22

Existential Quantifier \(\exists x, x^3 = 4\)

Let \(P(x)\) be the statement \(x^3 = 4\). Is this true for at least one integer x?

Again, we use the example domain [-2, -1, 0, 1, 2] because code can not check all integers.

Recall the previous example statements:

  • For all integers \(x\), \(x^2 \geq 0\).

Let \(P(x)\) be the predicate "\(x^2 \geq 0\)". Then we write the statement as \(\forall x P(x)\), where the domain is the set of all integers. This quantified statement will be true since anytime you square a nonzero integer it is positive and \(0^2=0\).

  • Some student in the class has a birthday in July.

Let \(Q(s)\) be the predicate "student \(s\) has a birthday in July". Then we write the statement as \(\exists s Q(s)\), where the domain is the set of all students in the class. This statement will be true as long as at least one student in the class has a birthday in July. It will be false, otherwise.

4.4.3. Negation of Quantifiers

It is important to consider the negation of a quantified expression.

  • "Every student in this class has taken Programming Fundamentals."

This is a universally quantified statement and can be expressed as \(\forall x P(x)\) where \(P(x)\) is the statement "\(x\) has taken Programming Fundamentals" and the domain consists of all the students in this class. The negation of the statement would be "It is not true that every student in this has taken Programming Fundamentals." Equivalently,

  • "There is a student in this class who has NOT taken Programming Fundamentals."

This is an existentially quantified statement expressed as \(\exists x \neg P(x)\).

This demonstrates that the negation of a universally quantified statement is an existential statement. In symbols, we have \(\neg \forall x P(x)\equiv \exists x \neg P(x)\).

Similarly, the negation of an existential statement is a universal statement. \(\neg \exists x P(x) \equiv \forall x \neg P(x)\).

De Morgan’s Laws with Quantifiers

For any predicate \(P(x)\) \[\neg \forall x P(x)\equiv \exists x \neg P(x)\] and \[\neg \exists x P(x) \equiv \forall x \neg P(x)\]

Example 23
  • Someone in the class can speak Latin.

Using quantifiers, we write this statement as \(\exists x L(x)\) where \(L(x)\) is the proposition "\(x\) speaks Latin." and the domain is the students in the class. Its negation would be \(\forall x \neg L(x)\).

  • All the students in the class can not speak Latin.

You Try

Find the negation of the statement "For all integers \(x\), \(x^2 \geq x\)."

The predicate of a quantified statement could be a compound statement. For instance,

  • Some dogs are big and fluffy.

This is written as \(\exists x (B(x) \land F(x))\) where \(B(x)\) is the proposition "\(x\) is big." and \(F(x)\) is the proposition "\(x\) is fluffy." and the domain is dogs. Negating this statement would give

\(\neg \exists x (B(x) \land F(x)) \equiv \forall x \neg (B(x) \land F(x)) \equiv \forall x (\neg B(x) \lor \neg F(x))\)

In words,

  • All dogs are not big or not fluffy.

4.4.4. Nested Quantifiers

There are times it will take more than one quantifier to express a statement.

  • For all integers \(x\), there exists an integer \(y\), such that \(x+y=0\).

This statement contains both a universal and an existential quantifier. \(\forall x \exists y S(x,y)\) where \(x\) and \(y\) are integers and \(S(x,y)\) is the proposition \(x+y=0\). This statement means, if you have any integer \(x\) (for instance \(x=5\)) then you can find an integer \(y\) (for instance \(y=-5\)) such that \(x+y=0\).

The order of the quantifiers matters. \(\exists x \forall y S(x,y)\) would be

  • There exists an integer \(x\), such that for all integers \(y\), \(x+y=0\).

Note that in this statement you find an integer \(x\) so that when you add any integer \(y\) to it you always get 0.

The first statement, for all integers \(x\), there exists an integer \(y\) such that \(x+y=0\), is true. For any integer \(x\) you could choose \(y=-x\) and \(x+y=x+(-x)=0\). While the second statement, there exists an integer \(x\), such that for all integers \(y\), \(x+y=0\), is false.

Example 24

Let \(Q(x,y)\) be the statement \(xy=0\). If the domain for both variables consists of all integers, what are the truth values of the following statements?

  • \(Q(0,3)\) is True since \(0\cdot 3=0\)

  • \(Q(6,2)\) is False since \(6\cdot 2=12\)

  • \(\exists x Q(x,4)\) is True. Use the value of \(x=0\), and since \(0\cdot 4=0\) there is at least one integer \(x\) so that \(x\cdot 4=0\).

  • \(\forall x \exists y Q(x,y)\) is True. If you have any integer \(x\), you can pick the value \(y=0\) and get \(x\cdot 0=0\).

You Try - Determine the truth value of each statement and justify the answer.
  • \(\forall y Q(1,y)\)

  • \(\exists x \forall y Q(x,y)\)

  • \(\forall x \forall y Q(x,y)\)

To negate nested quantifiers, repeatedly apply De Morgan’s Laws of negating a quantifier and a predicate.

Namely, \(\neg \forall x P(x) \equiv \exists x \neg P(x)\) and \(\neg \exists x P(x) \equiv \forall x \neg P(x)\).

Example 25 - Negation of quantified statements

Find the negation of the statment "For all integers \(x\), there exists an integer \(y\) such that \(x=-y\)."

Solution

Using quantifiers, we write this statement as \(\forall x \exists y N(x,y)\) where \(N(x,y)\) is the proposition "\(x=-y\)." and the domain of \(x\) and \(y\) is the integers. Its negation would be \(\exists x \forall y \neg N(x,y)\).

  • There exists an integer \(x\), such that for all integers \(y\), \(x \neq -y\).

You Try

Find the negation of the statement "Some student in the class will solve every practice problem."

Hint: Let \(x\) be a student in the class, \(y\) be a practice problem, and \(P(x,y)\) be the statement "student \(x\) has solved practice problem \(y\)".

4.5. Applications of Logic

Remixer’s Note: This section is taken from the original “Discrete Math” book with minor edits to include base-two notation and a link to the NANDgame website.

In this section we consider two applications of logic to information technology and computer science. The first involves bitwise operations, and the second designing and analyzing logic circuits.

4.5.1. Bitwise operations

A bitwise operation is a Boolean operation that operates on the individual bits (\(0s\), or \(1s\)) of the operand(s) and are summarized

Bitwise Operations
  1. The bitwise AND , denoted by "&", applies the and \(\land\) to the corresponding bits of each operand.

  2. The bitwise OR , denoted by "\(|\)", applies the or \(\lor\) to the corresponding bits of each operand.

  3. The bitwise XOR , denoted by "\({}^{\wedge}\)", applies the disjunctive or \(\oplus \) to the corresponding bits of each operand.

  4. The bitwise NOT , denoted by "!", applies the negation \(¬\) (flips \(0\longleftrightarrow 1\) ), to the corresponding bits of each operand.

We summarize the truth tables for the bitwise boolean operators.

\(p\) \(q\) \(AND\) & \( \ OR\ | \) \(XOR\) \({}^{\wedge}\) \(IF\) \(\Rightarrow\) \(IFF\) \(\Leftrightarrow\)

1

1

1

1

0

1

1

1

0

0

1

1

0

0

0

1

0

1

1

1

0

0

0

0

0

0

1

1

Example 26 - Bitwise Operations

Find the bitwise \(AND, OR, XOR\) for the following binary numbers,

\[ A = 111101\] \[ B = 001111\]

Solution

Using the truth tables for Boolean operators, where the results are noted in the bottom row, we have

Bitwise AND Bitwise OR Bitwise XOR

111101

111101

111101

001111

001111

001111

001101

111111

110010

4.5.2. Logic Circuits

Logic circuits are important in designing the arithmetic and logic units of a computer processor.

Consider the problem of adding two \(8\)-bit numbers in binary. In binary, \((0)_2 + (0)_2 = (0)_2\) and \((0)_2 + (1)_2 = (1)_2 + (0)_2 = (1)_2\), but as in decimal addition, \((1)_2 + (1)_2 = (10)_2\) requires a carry, that is, the "sum bit" is \(0\) with a "carry bit" of \(1\) to the next significant column on the left.
Note: The bits are enclosed in parentheses which are followed by the subscript \(_2\) to emphasize that binary notation, not decimal notation, is being used. This notation is covered in much more detail in the Number Bases chapter.

Thinking then of adding a specific column of two binary digits, say \(A\) and \(B\), involves as input the bits \(A, B\) and the carry in from the previous column say \(C_{in}\). The output will be the sum \(S\) and the carry out to the next column, say \(C_{out}\). These are the basic components of what is called a binary adder.

binary adder
Figure 8. A Binary adder

The logic table for binary addition based on the digital inputs \(A, B, C_{in}\), and digital outputs \(S\) and \(C_{out}\) is summarized in the table.

Table 1. Truth table for Binary adder
\(A\) \(B\) \(C_{in}\) \(\mathbf{S}\) \(\mathbf{C_{out}}\)

1

1

1

\(\mathbf{1}\)

\(\mathbf{1}\)

1

1

0

\(\mathbf{0}\)

\(\mathbf{1}\)

1

0

1

\(\mathbf{0}\)

\(\mathbf{1}\)

1

0

0

\(\mathbf{1}\)

\(\mathbf{0}\)

0

1

1

\(\mathbf{0}\)

\(\mathbf{1}\)

0

1

0

\(\mathbf{1}\)

\(\mathbf{0}\)

0

0

1

\(\mathbf{1}\)

\(\mathbf{0}\)

0

0

0

\(\mathbf{0}\)

\(\mathbf{0}\)

It can be shown that the logic for the outputs \(S\), and \(C_{out}\) is given by the following propositions \[ C_{out}=(A\land B)\lor \left(B\land C_{in}\right)\lor \left(A\land C_{in}\right)\] \[S=\left(\sim A\land \sim B\land C_{in}\right)\lor \left(\sim A\land B\land \sim C_{in}\right)\lor \left(A\land \sim B\land \sim C_{in}\right)\lor \left(A\land B\land C_{in}\right) \]

Implementing these logical outputs based on the inputs \((A,B, C_{in})\), is through the use of electronic circuits called logic gates.

The basic logic gates, are the Inverter or Not gate, the And gate, the Or gate and the Xor gate. The graphical representation for each is shown below.

basic gates
Figure 9. Basic gates

We end this section by first analyzing logic circuits to give their outputs in terms of their input variables, and then, constructing logic circuits based on logical statements.

Example 27 - Output of a logic circuit in terms Input

Determine the output of the following logic circuit in terms of the input variables, \(p, q\), and \(r\).

logic gate 3
Solution

Proceeding left to right, determine the output of the leftmost gates first using the basic gate outputs.

logic gate 3a

The output of the logic circuit is \( ( p \lor q)\land ( \neg p \lor \neg q)\)

In the next two examples, we design logic circuits based on logical propositions. The idea is to work backward using order of operations from the right to the left.

Example 28 - Design a Logic Circuit

Design a logic circuit for \((p\vee\lnot\ q)\land\lnot\ p\).

Solution

Working backwards from right to left we have the following sequence of gates

1) An AND gate \((p\vee\lnot\ q)\underline{\land} \lnot\ p\).

2) The inputs to the AND gate are \((p\vee\lnot\ q)\) and \(\lnot\ p\).

3) These inputs come from the output of an INVERTER , for \(\underline{\lnot}\ p\) and an OR gate \((p \underline{\vee}\lnot\ q)\).

4) There are two inputs to the OR gate \((p \underline{\vee}\lnot\ q)\), being \(p\), and the output of an INVERTER , \(\underline{\lnot} q\).

Putting these now in left to right order we obtain the following logic circuit.

logic gate 4
Example 29 - Design a Logic Circuit

Design a logic circuit for \(r\land (p\lor (r\land \neg q))\).

Solution

Working backwards from right to left we have the following sequence of gates

1) An AND gate \(r\underline{\land} (p\lor (r\land \neg q))\).

2) The inputs to the AND gate are \(r\) and \(p\lor (r\land \neg q)\).

3) The input, \(p\lor (r\land \neg q)\), comes from the output of an OR gate for \(p \underline{\lor} (r\land \neg q)\).

4) The inputs to the OR gate, \(p \underline{\lor} (r\land \neg q)\), are \(p\) and \((r\land \neg q)\), which is an AND gate.

5) The inputs to the AND , gate, \(r \underline{\land} \neg q\), are \(r\) and the output of an INVERTER , \(\underline{\neg} q\).

Putting these now in left to right order we obtain the following logic circuit.

logic gate 5
How about a game of nand?
Here is a link to a website that lets you build a computer, starting from the most basic level of the NAND component.

4.6. Exercises

Remixer’s Note: This section is taken from the original “Discrete Math” book with no changes.

  1. Which of these statements are propositions? Explain your reasoning

    1. Is Atlanta the capital of Georgia?

    2. All birds fly

    3. \(2\ \times\ \ 3\ =\ 5\)

    4. \(5\ +\ 7\ =\ 7+5\)

    5. \(x\ +\ 2\ =\ 11\)

    6. Answer this question.

    7. The rain in Spain

  2. Construct truth tables for,

    1. \(a\vee b\Rightarrow\lnot b\)

    2. \((a\vee\lnot b)\ \Leftrightarrow\ a\)

    3. \((a\Rightarrow b)\ \bigwedge\ (b\ \bigwedge\ \lnot c)\)

    4. \((a\ \bigvee\ b)\ \Rightarrow\ (\ \lnot c\ \bigvee\ a)\)

    5. \((a\ \bigvee\ b)\ \bigwedge\ (c\ \bigvee\lnot d\ )\)

    6. \((\lnot c\ \bigwedge\ \ b)\ \bigvee\ \ (a\Rightarrow\ \lnot d\ )\)

  3. Using truth tables, determine if each of the following is a tautology, contradiction, or neither (conditional)

    1. \(\neg ((a\lor b)\lor (\neg a\land \neg b))\)

    2. \(\left(\left(a\vee b\right)\land\lnot a\right)\Rightarrow b\)

    3. \(\left(\left(a\vee b\right)\land a\right)\Rightarrow b\)

    4. \(p\land r)\lor (\neg p\land \neg r)\)

    5. \(\neg ((p\lor q)\lor (\neg p\land (\neg q\lor r)))\)

    6. \(\neg (p\land q)\lor (q\lor r)\)

  4. Using truth tables determine which of the following are equivalent

    1. \(\left(p\Rightarrow q\right)\Rightarrow r\),

      \(\left(p\land\lnot q\right)\vee r,\) and

      \(\left(p\land\lnot q\right)\land r\)

    2. \((a\lor b)\land c,\)

      \((c\land a)\lor (c\land b),\) and

      \(\neg ((\neg a\land \neg b)\lor \neg c)\)

  5. Let \(C(x)\) be the statement "\(x\) has visited Canada." where the domain consists of the students at GGC. Express each of the quantifications in English.

    1. \(\exists x C(x)\)

    2. \(\forall x C(x)\)

    3. How would you determine whether each of these statements is true or false?

  6. Determine the truth value of each of these statements if the domain for all variables, \(m , n\) is the set of all integers, \(\mathbb{Z}\), explaining your reasoning.

    1. \(\forall n:\left(n^2\geq 1\right)\)

    2. \(\forall n:\left(n^2\geq 0\right)\)

    3. \(\ \exists\ n:(n^2=3)\)

    4. \(\ \exists\ m\forall\ n:(m+n=n-m)\)

    5. \(\forall\ n\exists\ m:\ (n\cdot\ m=m)\)

    6. \(\ \exists\ n\forall\ m:\ (n\cdot\ m=m)\)

    7. \(\ \exists\ n\forall\ m:\ (n\cdot\ m=n)\)

  7. Consider each of the compound propositions. (i) Translate each using logical symbols and letters, stating what each letter represents, (ii) Negate each using plain English sentences, and (iii) Translate the negated statements using logical symbols and quantifiers.

    1. If it snows today, then I will go skiing tomorrow.

    2. Mei walks or takes the bus to class.

    3. Every person in this class understands mathematical induction.

    4. In every mathematics class there is some student who falls asleep during lectures.

    5. There is a building on the campus of some college in the United states in which every room is painted white.

  8. Let \(p\), be the proposition ”My bicycle needs a tire replaced,” \(q\), be the proposition ”I will go cycling”, and, \(r\), be the proposition ”Rain is in the forecast.”

    1. Express each of these compound propositions using plain English sentences.

      1. \(\neg p\vee q\)

      2. \(\neg p\Rightarrow \neg q\)

      3. \((\neg p\wedge r)\Rightarrow q\)

      4. \((\neg p\wedge r)\Rightarrow q\)

      5. \((\neg p\wedge q)\vee r\)

    2. Write these compound propositions using \(p\), \(q\) and, \(r\) and logical connectives (including negation).

      1. If my bicycle tire does not replacement I will go cycling.

      2. My bicycle tire does not replacement, there is rain in the forecast but I will go cycling

      3. Whenever there is rain in the forecast, I do not go cycling.

      4. If there is rain in the forecast or my tire needs replacement I will not go cycling.

      5. Rain is not forecast whenever I go cycling.

      6. Rain is not forecast and my tire does not need replacement whenever I go cycling.

  9. Design logic circuits with the following output

    1. \((p\lor (q\land \neg r))\lor \neg (p\land q)\)

    2. \((p\lor (q\land r))\land \neg (p\land q)\)

  10. Consider the predicate \(Q(x,y): x\ \cdot\ y=5\), where the domain of \(x\) and \(y\) is all positive real numbers \(\mathbb{R}^+\), or \(x,\ y\ >0\). Determine the true value of the following, an explain your reasoning.

    1. \(Q(1,5)\)

    2. \(Q\left(2,\frac{5}{2}\right)\)

    3. \(\exists\ y,\ Q\left(7,y\right)\)

    4. \(\ \forall\ y,\ Q\left(7,y\right)\)

    5. \(\exists\ x\ \forall\ y,\ Q\left(x,y\right)\)

    6. \(\ \forall\ \ x\ \exists\ \ y,\ Q\left(x,y\right)\)

  11. Consider the predicate \(R(x,y):\ 2x+y=0\), where the domain of \(x\) and \(y\) is all rational numbers, \(\mathbb{Q}\). Determine the true value of the following, an explain your reasoning.

    1. \(R(0,0)\)

    2. \(R(2,-1)\)

    3. \(R\left(\frac{1}{5},-\frac{2}{5}\right)\)

    4. \(\exists y,\ R\left(0.2,y\right)\)

    5. \(\ \forall y,\ R\left(7,y\right)\)

    6. \(\exists\ x\forall\ y,\ R\left(x,y\right)\)

    7. \(\ \forall\ x\ \exists\ y,\ R\left(x,y\right)\)

  12. Calculate the bitwise \(AND\), the bitwise \(OR\), and the bitwise \(XOR\) of the following pairs of bytes, or sequence of bytes

    1. \(01111111\) and \(11101001\)

    2. \(1110010111111010\) and \(0101110101100011\)

  13. Give the output for each of the logic circuits in terms of the input variables,

    1. The logic circuit, with input variables, \(p, q\), \(r\).

      logic gate 1
    2. The logic circuit, with input variables, \(a, b\), \(c\).

      logic gate 2
  14. Design a logic circuit for \(r\land (p\lor (r\land \neg q))\).

4.7. Challenge Exercises

  1. Complete parts (a) and (b) to show that every compound proposition is logically equivalent to one that uses the same propositional variables but only the NAND operator \(\uparrow.\)

    1. For each of the three propositions \(\neg p\), \(p \land q,\) and \(p \lor q,\) write a logically equivalent proposition that uses only \(p,\) \(q,\) and \(\uparrow.\)

    2. Use the theorem that every compound proposition is equivalent to a compound proposition in disjunctive normal form to justify that the compound proposition is also equivalent to one that uses only the NAND operator \(\uparrow.\)

  2. Complete parts (a) and (b) to show that every compound proposition is logically equivalent to one that uses the same propositional variables but only the NOR operator \(\downarrow.\)

    1. For each of the three propositions \(\neg p\), \(p \land q,\) and \(p \lor q,\) write a logically equivalent proposition that uses only \(p,\) \(q,\) and \(\downarrow.\)

    2. Use the theorem that every compound proposition is equivalent to a compound proposition in disjunctive normal form to justify that the compound proposition is also equivalent to one that uses only the NOR operator \(\downarrow.\)