Discrete computational structures

Course notes for CS-1382: Discrete Computational Structures. Texas Tech University, Whitacre College of Engineering. Spring 2023.

Key Topics:

  1. Sets, functions, sequences
  2. Algorithms
  3. Number Theory
  4. Introduction to logic and proofs
  5. Mathematical induction
  6. Counting and probability
  7. Graphs

1 The Foundations: Logic and Proofs

Logic is the basis of all mathematical reasoning, and of all automated reasoning. To understand mathematics, we must understand what makes up a correct mathematical argument, that is, a proof. Many people find it surprising how important proofs are in computer science.

1.1 Propositional Logic

1.1.1 Introduction

Propositional logic is a branch of mathematical logic which studies the logical relationships between propositions taken as a whole, and connected via logical connectives.

1.1.2 Propositions

A proposition is a declarative sentence (a statement) that is either true or false, but not both.

We use letters to denote propositional variables (or sentential variables)—variables that represent propositions—just as letters are used to denote numerical variables. The conventional letters used for propositional variables are pp, qq, rr, ss, … .

The truth value of a proposition is true, denoted by T, if it is a true proposition, and the truth value of a proposition is false, denoted by F, if it is a false proposition.

Propositions that cannot be expressed in terms of simpler propositions are called atomic propositions. The area of logic that deals with propositions is called the propositional calculus or propositional logic.

New propositions, called compound propositions, are constructed from existing propositions using logical operators or logical connectives.

  • The negation of pp, written ¬p\neg p, is the opposite of the truth value of pp.
  • The conjunction of pp and qq, written pqp \land q, is true when both pp and qq are true and is false otherwise.
  • The disjunction of pp and qq, written pqp \lor q, is false when both pp and qq are false and is true otherwise.
  • The exclusive or of pp and qq, written pqp \oplus q, is true when exactly one of pp and qq are true and is false otherwise.

1.1.3 Conditional Statements

Conditional statements (also called an implication) are formed by combining two statements. The statement asserts that qq is true on the condition that pp holds.

  • The conditional statement pqp \rightarrow q is false when pp is true and qq is false and is true otherwise.

Converse, contrapositive, and inverse statements can be formed from the conditional statement pqp \rightarrow q.

  • The converse is qpq \rightarrow p
  • The inverse is ¬p¬q\neg p \rightarrow \neg q
  • The contrapositive is ¬q¬p\neg q \rightarrow \neg p

A conditional statement and its contrapositive are equivalent. The converse and inverse of a conditional statement are equivalent, but neither is equivalent to the original statement.

Biconditional statements express that two propositions have the same truth value.

  • The biconditional statement pqp \leftrightarrow q is true when pp and qq have the same truth values and is false otherwise.

Biconditionals are not always explicit in natural language. In particular, the “if and only if” construction used in biconditionals is rarely used in common language. Instead, biconditionals are often expressed using an “if, then” or an “only if” construction.

1.1.4 Truth Tables of Compound Propositions

We can use the five introduced logical connectives to build up complicated compound propositions involving any number of propositional variables. We can use truth tables to determine the truth values of these compound propositions. Use a separate column to find the truth value of each compound expression that occurs in the compound proposition as it is built up.

Example: For the compound proposition

(p¬q)(pq)(p \lor \neg q) \rightarrow (p \land q)

the truth table is

pp qq ¬q\neg q p¬qp \lor \neg q pqp \land q (p¬q)(pq)(p \lor \neg q) \rightarrow (p \land q)
T T F T T T
T F T T F F
F T F F F T
F F T T F F

1.1.5 Precedence of Logical Operators

Generally, parentheses are used to specify the order in which logical operators in a compound proposition are to be applied. However, to reduce the number of parenthesis, the following rules of precedence are applied.

Operator Precedence
¬\neg 1
\land 2
\lor 3
\rightarrow 4
\leftrightarrow 5

1.1.6 Logical and Bit Operations

A bit is a symbol with two possible values, 0 (zero) and 1 (one), and can be used to represent a truth value. Customarily, a 1 bit represents true and a 0 bit represents false. A variable is called a Boolean variable if its value is either true or false.

Computer bit operations correspond to the logical connectives. The notation OR, AND, and XOR correspond to the operators \lor, \land, and \oplus respectively.

A bit string is a sequence of zero or more bits. The length of this string is the number of bits in the string. We can extend bit operations to bit strings. We define the bitwise OR, bitwise AND, and bitwise XOR of two strings of the same length to be the strings that have as their bits the OR, AND, and XOR of the corresponding bits in the two strings, respectively.

1.2 Applications of Propositional Logic

Statements in mathematics and the sciences and in natural language are often imprecise or ambiguous. To make such statements precise, they can be translated into the language of logic.

Natural language

Translating sentences into compound statements removes ambiguity and allows us to apply the rules of inference.

System specifications

System and software engineers take requirements in natural language and produce precise and unambiguous specifications that can be used as the basis for system development.

Boolean search

Logical connectives are used extensively in searches of large collections of information, such as indexes of Web pages. Because these searches employ techniques from propositional logic, they are called boolean searches.

Logic puzzles

Puzzles that can be solved using logical reasoning are known as logic puzzles.

Logic circuits

A logic circuit receives input signals as bits [0 (off) or 1 (on)] and produces output signals as bits.

Cf. Logic gates

1.3 Propositional Equivalences

An important step used in a mathematical argument is the replacement of a statement with another statement with the same truth value.

A compound proposition that is always true, no matter what the truth values of the propositional variables that occur in it, is called a tautology. A compound proposition that is always false is called a contradiction. A compound proposition that is neither a tautology nor a contradiction is called a contingency.

Examples of a tautology and a contradiction

pp ¬p\neg p p¬pp \lor \neg p p¬pp \land \neg p
T F T F
F T T F

Logical Equivalences

Compound propositions that have the same truth values in all possible cases are called logically equivalent.

The compound propositions pp and qq are called logically equivalent if pqp \leftrightarrow q is a tautology (if and only if the columns giving their truth values agree).

For example, pqp \rightarrow q and ¬pq\neg p \lor q are logically equivalent

pp qq ¬p\neg p ¬pq\neg p \lor q pqp \rightarrow q
T T F T T
T F F F F
F T T T T
F F T T T

because the truth values of pqp \rightarrow q and ¬pq\neg p \lor q agree.

Logical equivalences

Equivalence Name
pTppTpp \land \text{T} \equiv p \\ p \lor \text{T} \equiv p Identity laws
pTTpFFp \lor \text{T} \equiv \text{T} \\ p \land \text{F} \equiv \text{F} Domination laws
ppppppp \lor p \equiv p \\ p \land p \equiv p Idempotent laws
¬(¬p)p\neg(\neg p) \equiv p Double negation law
pqqppqqpp \lor q \equiv q \lor p \\ p \land q \equiv q \land p Commutative laws
(pq)rp(qr)(pq)rp(qr)(p \lor q) \lor r \equiv p \lor (q \lor r) \\ (p \land q) \land r \equiv p \land (q \land r) Associative laws
p(qr)(pq)(pr)p(qr)(pq)(pr)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) Distributive laws
¬(pq)¬p¬q¬(pq)¬p¬q\neg (p \land q) \equiv \neg p \lor \neg q \\ \neg(p \lor q) \equiv \neg p \land \neg q De Morgan’s laws
p(pq)pp(pq)pp \lor (p \land q) \equiv p \\ p \land (p \lor q) \equiv p Absorption laws
p¬pTp¬pFp \lor \neg p \equiv \text{T} \\ p \land \neg p \equiv \text{F} Negation laws

Using De Morgan’s Laws

The two logical equivalences known as De Morgan’s laws are particularly important. They tell us how to negate conjunctions and how to negate disjunctions.

The negation of a disjunction is the conjunction of negations of the component propositions.

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

The negation of a conjunction is the disjunction of negations of the component propositions.

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

The extended version of De Morgan’s laws can be written concisely as

¬(j=1npj)=j=1n¬pj¬(j=1npj)=j=1n¬pj\neg \left( \bigwedge_{j=1}^{n} p_j \right) = \bigvee_{j=1}^{n} \neg p_j \\[16pt] \neg \left( \bigvee_{j=1}^{n} p_j \right) = \bigwedge_{j=1}^{n} \neg p_j

Satisfiability

A compound proposition is satisfiable if there is an assignment of truth values to its variables that makes it true (that is, when it is a tautology or a contingency). When no such assignments exist, that is, when the compound proposition is false for all assignments of truth values to its variables, the compound proposition is unsatisfiable.

1.4 Predicates and Quantifiers

1.4.1 Introduction

Propositional logic cannot adequately express the meaning of all statements in mathematics and in natural language. A more powerful type of logic called predicate logic can be used to express the meaning of a wide range of statements in mathematics and computer science in ways that permit us to reason and explore relationships between objects.

1.4.2 Predicates

The statement ”xx is greater than 3” has two parts.

  1. xx” - subject
  2. “is greater than 33” - predicate

The predicate refers to a property that the subject of the statement can have. We can denote the statement ”xx is greater than 3” by P(x)P(x), where PP denotes the predicate and xx is the variable.

For example, if P(x)P(x) denotes the statement ”x>3x > 3”, then P(4)P(4) is true because 4>34 > 3. However, P(2)P(2) is false because 232 \ngtr 3.

1.4.3 Quantifiers

Quantification expresses the extent to which a predicate is true over a range of elements. In English, the words all, some, many, none, and few are used in quantifications. The area of logic that deals with predicates and quantifiers is called the predicate calculus.

Statement When true? When false?
xP(x)\forall x P(x) P(x)P(x) is true for every xx. There is an xx for which P(x)P(x) is false.
xP(x)\exists x P(x) There is an xx for which P(x)P(x) is true. P(x)P(x) is false for every xx.
The Universal Quantifier

Many mathematical statements assert that a property is true for all values of a variable in a particular domain. Such a statement is expressed using universal quantification. The domain must always be specified when a universal quantifier is used; without it, the universal quantification of a statement is not defined.

The universal quantification of P(x)P(x) is the statement ”P(x)P(x) for all values of xx in the domain.”

The notation

xP(x)\forall x P(x)

read “for all xP(x)x P(x)”, denotes the universal quantification of P(x)P(x).

The Existential Quantifier

Many mathematical statements assert that there is an element with a certain property. Such statements are expressed using existential quantification. With existential quantification, we form a proposition that is true if and only if P(x)P(x) is true for at least one value of xx in the domain.

The existential quantification of P(x)P(x) is the proposition “There exists an element xx in the domain such that P(x)P(x).”

The notation

xP(x)\exists x P(x)

read “for some xP(x)x P(x)”, denotes the existential quantification of P(x)P(x).

1.4.4 Quantifiers over Finite Domains

When the domain of a quantifier is finite, quantified statements can be expressed using propositional logic. When the elements of the domain are x1,x2,,xnx_1, x_2, \ldots , x_n

xP(x)P(x1)P(x2)P(xn)\forall x P(x) \equiv P(x_1) \land P(x_2) \land \ldots \land P(x_n)

1.4.9 Negating Quantified Expressions

Negation of a universal quantifier

¬xP(x)x¬P(x)\neg \forall x P(x) \equiv \exists x \neg P(x)

Negation of an existential quantifier

¬xQ(x)x¬Q(x)\neg \exists x Q(x) \equiv \forall x \neg Q(x)

1.4.10 Translating from English into Logical Expressions

Example: Express the statement “Every student in this class has studied calculus.”

  • Let C(x)C(x) be the statement ”xx has studied calculus”
  • Domain is all students in this class:
    • xC(x)\forall x C(x)
  • Domain is all people:
    • x(S(x)C(x))\forall x (S(x) \rightarrow C(x))
    • Caution! This statement cannot be expressed as x(S(x)C(x))\forall x (S(x) \land C(x)) because this statement says “all people are students and have studied class.”

Example: Express the statement “Some student in this class has visited Mexico.”

  • Let M(x)M(x) be the statement ”xx has visited Mexico.”
  • Domain is all students in this class:
    • xM(x)\exists x M(x)
  • Domain is all people:
    • x(S(x)M(x))\exists x (S(x) \land M(x))
    • Caution! This statement cannot be expressed as x(S(x)M(x))\forall x (S(x) \rightarrow M(x)) which is true when there is someone not in the class.

1.5 Nested Quantifiers

A nested quantifier is where one quantifier is within the scope of another. The rules studied in Section 1.4 can help to use them.

1.5.2 Understanding Statements Involving Nested Quantifiers

The statement xy(x+y=0)\forall x \exists y (x + y = 0) says that for every real number xx there is a real number yy such that x+y=0x + y = 0.

1.5.3 The Order of Quantifiers

The order of the quantifiers is important, unless all the quantifiers are universal quantifiers or all are existential quantifiers.

Example: Let P(x,y)P(x, y) be the statement x+y=y+xx + y = y + x. The quantifications xyP(x,y)\forall x \forall y P(x, y) and yxP(x,y)\forall y \forall x P(x, y) have the same meaning and both are true.

Example: Let Q(x,y)Q(x, y) be the statement x+y=0x + y = 0. The quantification yxQ(x,y)\exists y \forall x Q(x, y) is false because no matter what value of yy that is chosen, there is only one value of xx for which x+y=0x + y = 0. However, the quantification xyQ(x,y)\forall x \exists y Q(x, y) is true because given any value of xx, there is a value of yy for which x+y=0x + y = 0.

1.5.7 Negating Nested Quantifiers

Express the negation of a statement so that no negation precedes a quantifier by successively applying De Morgan’s laws for quantifiers. Doing so moves the negation inside all the quantifiers.

1.6 Rules of Inference

1.6.1 Introduction

Before we study mathematical proofs, we will look at arguments that involve only compound propositions. We will define what it means for an argument involving compound propositions to be valid. Then we will introduce a collection of rules of inference in propositional logic. These rules of inference are among the most important ingredients in producing valid arguments.

After studying rules of inference in propositional logic, we will introduce rules of inference for quantified statements. Finally, we will show how rules of inference for propositions and for quantified statements can be combined.

1.6.2 Valid Arguments in Propositional Logic

An argument in propositional logic is a sequence of propositions. All but the final proposition in the argument are called premises and the final proposition is called the conclusion. An argument is valid if the truth of all its premises implies that the conclusion is true.

An argument form in propositional logic is a sequence of compound propositions involving propositional variables. An argument form is valid if no matter which particular propositions are substituted for the propositional variables in its premises, the conclusion is true if the premises are all true.

1.6.3 Rules of Inference for Propositional Logic

Using a truth table to show that an argument form is valid can be a tedious approach. Instead, we can first establish the validity of some relatively simple argument forms, called rules of inference. These rules of inference can be used as building blocks to construct more complicated valid argument forms.

Rule of Inference Tautology Name
ppqqp \\ p \rightarrow q \\ \rule{24px}{1px} \\ \therefore q (p(pq))q(p \land (p \rightarrow q)) \rightarrow q Modus ponens
¬qpq¬p\neg q \\ p \rightarrow q \\ \rule{24px}{1px} \\ \therefore \neg p (¬q(pq))¬p(\neg q \land (p \rightarrow q)) \rightarrow \neg p Modus tollens
pqqrprp \rightarrow q \\ q \rightarrow r \\ \rule{32px}{1px} \\ \therefore p \rightarrow r ((pq)(qr))(pr)((p \rightarrow q) \land (q \rightarrow r)) \rightarrow (p \rightarrow r) Hypothetical syllogism
pq¬pqp \lor q \\ \neg p \\ \rule{24px}{1px} \\ \therefore q ((pq)¬p)q((p \lor q) \land \neg p) \rightarrow q Disjunctive syllogism
ppqp \\ \rule{32px}{1px} \\ \therefore p \lor q p(pq)p \rightarrow (p \lor q) Addition
pqpp \land q \\ \rule{24px}{1px} \\ \therefore p (pq)p(p \land q) \rightarrow p Simplification
pqpqp \\ q \\ \rule{32px}{1px} \\ \therefore p \land q ((p)(q))(pq)((p) \land (q)) \rightarrow (p \land q) Conjunction
pq¬prqrp \lor q \\ \neg p \lor r \\ \rule{32px}{1px} \\ \therefore q \lor r ((pq)(¬pr))(qr)((p \lor q) \land (\neg p \lor r)) \rightarrow (q \lor r) Resolution

1.6.4 Using Rules of Inference to Build Arguments

When there are many premises, several rules of inference are often needed to show that an argument is valid.

1.6.7 Rules of Inference for Quantified Statements