C04: Logic, sets, relations, and constructing proofs
On this page
- A. Prerequisites and observable goals
- B. The central question: what would make this claim true or false?
- C. Quantifiers and their order
- D. How to build a proof
- E. Relations organize objects into classes and orders
- F. Finite logic checking is useful within a stated boundary
- G. Independent practice
- H. Complete solutions: C04
- I. Retention and readiness
A. Prerequisites and observable goals#
C01 state and Boolean values; algebra and function notation.
Translate quantified claims, negate them correctly, construct direct and contrapositive proofs, find counterexamples, and distinguish a finite test from a general argument.
Level: Degree core.
B. The central question: what would make this claim true or false?#
A proof is a logically justified argument from stated assumptions to a conclusion. It is not a longer example or a report that code passed tests. Before proving a claim, identify its domain, quantifiers, and conditions. “This search works” is too vague. “For every finite nondecreasing integer sequence and every integer target, this function returns the first qualifying index or the length” is a proposition with a testable meaning and a possible proof structure.
A proposition has a truth value. The operators , , and mean not, and, and inclusive or. An implication is false only when is true and is false. When is false, the implication is true in classical propositional logic; it does not assert that occurs or causes . An equivalence requires both directions. Proving one implication does not establish the converse.
C. Quantifiers and their order#
means every element of the specified domain satisfies the predicate. means at least one witness exists. Negation changes both the quantifier and predicate:
Thus disproving a universal claim needs one valid counterexample, whereas proving it needs a general argument covering the entire domain. Testing a million cases can reveal a counterexample but cannot by itself prove a claim over all integers.
The claims and over the integers differ. The first is true: choose depending on . The second asks for one integer greater than every integer, which does not exist. This distinction appears in software contracts: “each request eventually gets some response” is not the same as “there is one fixed response time bound that works for every request.” Additional timing assumptions would be needed for a uniform bound.
Sets collect distinct elements without an intrinsic order. Membership differs from inclusion . Union, intersection, and complement act on sets; complements require a declared universe. De Morgan’s laws, and , follow by checking membership of an arbitrary element. A list can contain duplicates and preserve order, so it is not interchangeable with a mathematical set.
D. How to build a proof#
For a direct proof of , assume , unpack its definitions, and derive with justified steps. For a contrapositive proof, prove , which is logically equivalent to the original implication. For a contradiction proof, assume the negation of the desired claim together with the hypotheses and derive an impossibility. These methods are choices of argument organization, not magic words that turn an unsupported calculation into a proof.
Example: if an integer has even square, then is even. The contrapositive says an odd integer has odd square. Write an arbitrary odd integer as for an integer . Then , which is odd by definition. This covers every odd integer, including negative ones. Checking and would only illustrate it.
For a contradiction example, suppose with coprime integers and . Then , so is even by the previous result. Write to get , hence is even too. Both being even contradicts coprimality. The argument depends on choosing a reduced fraction; without that condition, discovering a common factor would not contradict the assumption.
E. Relations organize objects into classes and orders#
A binary relation on is a subset of . An equivalence relation is reflexive (), symmetric ( implies ), and transitive (, imply ). It partitions the set into disjoint equivalence classes. Equality modulo , defined by dividing , is an example: each integer belongs to exactly one residue class.
A partial order is reflexive, antisymmetric, and transitive. Antisymmetric means and together imply ; it does not mean that reversing every pair makes the relation false. Set inclusion is a partial order, and some sets are incomparable. A total order additionally compares every pair. Sorting and search rely on specific ordering assumptions; a comparator that changes its answer or violates transitivity can invalidate the algorithm’s reasoning.
A function assigns exactly one output in its codomain to each input in its domain. Injectivity means distinct inputs have distinct outputs; surjectivity means every codomain element occurs; bijectivity means both. The chosen codomain matters. The map from to is neither injective nor surjective, but restricted from to it is bijective. This revisits calculus inverse-function conditions in a discrete language.
F. Finite logic checking is useful within a stated boundary#
A truth-table checker can enumerate all assignments to Boolean names and find an assignment where every premise is true but the conclusion is false. For a fixed finite propositional formula, exhaustive enumeration is complete. It is not a proof method for arbitrary quantified integer claims unless the finite reduction itself is justified. The lab imposes a 16-name bound to keep exhaustive work intentional rather than accidentally exponential.
The invalid inference “; ; therefore ” is called affirming the consequent. Set false and true: both premises are true and the conclusion false. The valid inference “; ; therefore ” has no such assignment. Finding the counterexample is more informative than saying the first argument “looks wrong.”
G. Independent practice#
F foundation C standard course work T transfer S optional stretch L runnable lab or project. Attempt the complete set before opening its solutions.
Negate “for every request there exists a response that matches its identifier.” Keep the order of quantifiers explicit. What would a counterexample look like?
Prove that the sum of two odd integers is even. State the domain and use the definition of oddness rather than examples.
On the integers, define when divides . Prove this is an equivalence relation and describe its classes.
A developer claims a comparator is suitable for sorting because it returned consistent answers on ten examples. Explain what properties still need justification. Construct a three-object cyclic ordering that violates transitivity.
Implement counterexample in logic_lab.py. Enumerate every Boolean assignment to at most 16 distinct names; return an assignment satisfying all premises but falsifying the conclusion, or None if none exists. Check affirming the consequent and modus ponens. Explain exactly what the exhaustive result proves.
Optional small hints
C04.01: negate from the outside inward. C04.03: write the three divisibility witnesses separately. C04.04: use , , and .
H. Complete solutions: C04#
Compare the first step where your work differs. A corrected answer is not yet an independent success.
C04.01Show solution
A request with no matching response
Let mean response matches request . The claim is . Its negation is : there is a request for which no response matches. One unmatched request is the counterexample, but establishing it requires the relevant response domain or time/finality assumptions. Merely not having seen a response yet does not establish that none will ever arrive in an asynchronous system.
Back to C04.01C04.02Show solution
Definitions expose the general structure
Let and for arbitrary integers . Then . Since is an integer, the sum is even. This is a direct proof over all odd integers; it does not assume they are positive or restrict them to a tested range.
Back to C04.02C04.03Show solution
Residue classes form a partition
Reflexivity: . Symmetry: if , then . Transitivity: if and , then . The classes are integers congruent to 0, 1, or 2 modulo 3. Every integer has exactly one such remainder under Euclidean division, and two different remainder classes cannot overlap. These statements describe an equivalence relation, not an ordering.
Back to C04.03C04.04Show solution
A cycle defeats a sorted arrangement
A comparator used by a particular sorting interface must satisfy that interface’s ordering contract; a common C++ requirement is strict weak ordering. At minimum, a proposed strict order must not compare an object as less than itself and must be transitive, with compatible equivalence behavior. Define , , and . Transitivity of the first two would require , contradicting the cyclic direction in a strict order. Ten observed comparisons do not cover every triple or prove the relation stable across time. A comparator depending on mutable external state can fail even when its formula once behaved consistently.
Back to C04.04C04.05Show solution
Reference finite checker
"""C04.05: finite propositional entailment, not first-order theorem proving."""
from itertools import product
from collections.abc import Callable
def counterexample(names: list[str], premises: list[Callable],
conclusion: Callable) -> dict[str, bool] | None:
if len(names) != len(set(names)):
raise ValueError("variable names must be unique")
if len(names) > 16:
raise ValueError("educational exhaustive limit: 16 variables")
for bits in product((False, True), repeat=len(names)):
env = dict(zip(names, bits))
if all(p(env) for p in premises) and not conclusion(env):
return env
return None
if __name__ == "__main__":
implication = lambda e: not e["p"] or e["q"]
print(counterexample(["p", "q"], [implication, lambda e: e["q"]],
lambda e: e["p"]))Each Boolean assignment is visited exactly once by the Cartesian product enumeration. A returned environment is a concrete countermodel. If no countermodel exists, every assignment that satisfies all premises also satisfies the conclusion, so the finite propositional entailment holds. This does not establish real-world truth of the premises, quantify over arbitrary data structures, or solve every program-correctness problem. The domain bound also exposes exponential complexity: adding one name doubles the assignments.
Back to C04.05I. Retention and readiness#
Retrieve domains and inverse-function restrictions from calculus. Advance when you can negate a quantified statement, name a missing hypothesis, and produce a counterexample to a tempting converse. Do not skip proof practice merely because the corresponding code is easy to run.