08 — Discrete Mathematics for Computer Science
A structured introduction to the logic, sets, relations, functions, and proof methods that form the mathematical foundation of computer science.
Foundations and the Computer Science Perspective
Discrete mathematics focuses on finite, countable, and other non-continuous structures. In computer science, it supplies precise ways to specify program behavior, represent data, analyze algorithms, and establish correctness.
The main ideas build on one another:
Logic describes truth and conditions.
Predicates and quantifiers describe properties of objects and collections of objects.
Sets describe domains and collections.
Relations describe connections, equivalence, and ordering.
Functions describe deterministic input-output behavior.
Proof methods justify correctness and impossibility claims.
A useful general workflow is to identify the objects and their domains, translate informal claims into definitions or symbolic statements, make assumptions explicit, and then select a proof strategy that matches the claim.
Takeaway: Discrete mathematics provides a common language for describing computational objects and reasoning rigorously about them.
Logic, Truth, and Inference
A is a declarative statement with exactly one truth value: true or false. For example, “ is prime” is true, while “ is less than ” is false. A symbolic variable such as can stand for either .
A forms compound propositions:
Negation: , meaning “not .”
Conjunction: , meaning “ and .”
Disjunction: , meaning inclusive “ or .”
Implication: , meaning “if , then .”
Biconditional: , meaning “ if and only if .”
For an implication , is the antecedent and is the consequent. The implication is false only in the case where is true and is false. A truth table checks every possible assignment of truth values.
Important equivalences include:
Double negation: .
De Morgan’s laws: and .
Contrapositive: .
Implication rewriting: .
A tautology is true for every assignment, whereas a contradiction is false for every assignment. Two propositions are logically equivalent when they have the same truth value in every possible case.
A rule of inference gives a valid pattern for deriving a conclusion from premises. Modus ponens uses and to conclude . Modus tollens uses and to conclude . These forms matter in program conditions, query languages, digital circuits, and formal verification.
Takeaway: Truth tables and equivalence laws let you analyze conditions independently of their application domain.
Predicates, Domains, and Quantifiers
A predicate is a statement containing variables whose truth depends on assigned values. For example, can express that is prime. Before a value is assigned to , the predicate is not yet a .
A connects a predicate to its domain:
means that is true for every in the domain.
means that at least one element makes true.
For example,
asserts a property of every natural number, while
is true because both and satisfy the predicate.
Negating quantifiers reverses their type and negates the predicate:
Thus, “not every input is valid” means that there exists an invalid input. The order of multiple quantifiers must be examined carefully because changing it can change the meaning of a specification.
Takeaway: Always identify the domain and scope before deciding whether a quantified statement is true.
Sets and Operations
A is a collection of distinct elements. It can be described by listing elements, as in , or by a condition, as in . The statement expresses membership, and denotes the empty .
If every element of is also in , then is a of , written . Common operations are:
Union: contains elements in or .
Intersection: contains elements in both and .
Difference: contains elements in but not in .
Complement: contains elements in the chosen universal that are not in .
The Cartesian product is the of ordered pairs
For and ,
The power contains every of . If has elements, then has elements.
To prove equality, prove both inclusions: and . Equivalently, choose an arbitrary element and show that exactly when . For example, the distributive law
follows from the corresponding propositional equivalence .
Takeaway: notation turns informal collections and membership conditions into objects that can be manipulated and proved equal.
Relations, Equivalence, and Order
A from to is a of . If belongs to the relation , it may be written as . Relations can represent enrollment, network connectivity, numerical comparison, or having the same remainder modulo a fixed number.
When a relation is defined on a , its properties include:
Reflexive: for every .
Symmetric: if , then .
Antisymmetric: if and , then .
Transitive: if and , then .
An is reflexive, symmetric, and transitive. It partitions a into equivalence classes. For example, having the same remainder modulo is an on the integers.
A partial order is reflexive, antisymmetric, and transitive. The relation is a partial order on a power . Partial orders model dependencies, version constraints, and task precedence.
Relations can be represented as ordered pairs, tables, Boolean matrices, or directed graphs. The representation can be chosen to suit an application such as a database, graph algorithm, access-control system, or state-transition model.
Takeaway: To classify a relation, test each defining property separately; combinations of properties reveal its mathematical structure.
Functions and Mappings
A is written . It assigns every element of the domain exactly one element of the codomain . The range, or image, is the of values actually produced:
An injective maps distinct inputs to distinct outputs:
A surjective reaches every element of its codomain:
A is both injective and surjective. For example, defined by is bijective, with inverse . In contrast, from to is not injective because , and it is not surjective because no integer maps to .
Functions can be composed. If and , then
This composition applies first and then . Functions therefore provide a formal model for algorithms, encodings, transformations, hash computations, and state updates.
Takeaway: When analyzing a , distinguish its domain, codomain, and actual range before testing injectivity or surjectivity.
Proof Strategies and Mathematical Rigor
A proof is a logically valid argument that derives a conclusion from definitions, accepted facts, and established results. The best proof method depends on the structure of the claim.
Direct proof
To prove directly, assume , apply definitions and valid deductions, and derive . If and are even, write and . Then , so is even.
Proof by contrapositive
Because is equivalent to , prove the contrapositive when it is easier. To prove that an even square has an even root, show that an odd root has an odd square. If , then
which is odd.
Proof by contradiction
Assume the negation of the desired statement and derive an impossibility such as or . The original statement then follows because the assumption of its negation cannot hold.
Proof by cases
Divide the possibilities into exhaustive cases and prove the conclusion in each one. For example, an integer is either even or odd, so a claim about every integer can be addressed through those two cases.
To prove for every natural number in a specified range:
Prove the base case, such as .
Assume for an arbitrary allowed ; this is the inductive hypothesis.
Use that hypothesis to prove .
For example, induction establishes
Induction is especially useful for loops, recursive algorithms, data structures, and recursively generated objects.
Counterexamples
To disprove a universal claim, one is enough. The statement that every prime number is odd is false because is prime and even. The must satisfy the assumptions while violating the conclusion.
Takeaway: Match the proof technique to the logical form: direct reasoning for constructive implications, contrapositive for reversed conditions, contradiction for impossible negations, cases for exhaustive alternatives, induction for recursive structure, and counterexamples for universal claims.
Connecting the Tools in Computer Science
The concepts become most useful when combined in a formal specification. A sorting algorithm, for example, should produce an output that is a permutation of its input and is ordered. The ordering condition can be written as
The permutation requirement can be expressed using sets or multisets. Quantifiers state what must hold for every relevant pair of positions, relations express the ordering comparison, and functions can model the algorithm's transformation from input to output. A proof can then use induction on the number of elements or on the algorithm's recursive structure.
A disciplined reasoning process is:
State the objects and their domains precisely.
Translate informal language into definitions or symbolic statements.
Identify the assumptions and the desired conclusion.
Choose a proof strategy suited to the logical form.
Justify every non-obvious step.
Test universal claims with small examples and search for counterexamples.
These tools support algorithm correctness, security guarantees, type-system soundness, formal specifications, databases, networks, and theoretical computer science.
Final takeaway: Logic states what a computation should do, sets and relations describe its objects and structure, functions model its behavior, and proofs establish that the intended properties actually hold.