Sets, Functions, and Proofs
Goal
By the end of this chapter, you should be able to read basic mathematical language about sets, functions, relations, and proofs. You should also understand why this language matters when studying cryptographic systems such as Chia.
Prerequisites
You need only ordinary programming experience. If you know what a collection, value, input, output, and boolean condition are, you already have the right starting point.
Motivation
Cryptography is full of statements that sound like code comments but behave like contracts:
- this function maps every input to exactly one output
- this operation is reversible
- this relation groups equivalent objects together
- this algorithm succeeds with high probability
- no efficient attacker can distinguish two cases
To understand statements like these, we need a small amount of mathematical vocabulary. Sets describe collections of objects. Functions describe controlled input-output behavior. Relations describe when two objects are connected. Proofs explain why a claim follows from definitions instead of from examples alone.
Sets and Elements
A set is a collection of distinct objects. The objects in a set are called elements.
We write to mean " is an element of ." We write to mean " is not an element of ."
Example:
Then and .
Sets do not care about order or duplicates:
That is different from many programming containers. A list or array usually remembers order. A mathematical set does not.
Subsets
A set is a subset of a set if every element of is also an element of . We write .
Example:
Then .
The empty set, written , has no elements. It is a subset of every set. This can feel strange at first, but it follows from the definition: there is no element of that violates the subset condition.
Ordered Pairs and Tuples
A set ignores order, but cryptography and programming often need ordered data. An ordered pair is a pair where position matters. We write it as .
In general:
unless .
A tuple is an ordered list of fixed length, such as or . Tuples are useful for representing structured data: inputs to a function, coordinates, public parameters, or protocol messages.
Programming analogy:
- set: roughly like a collection where membership matters
- tuple: roughly like a fixed-shape record where position matters
The analogy is not exact, but it is a good starting point.
Functions
A function assigns each input in one set exactly one output in another set. If a function is called , we write:
This means " is a function from to ."
The set is the domain. It contains the allowed inputs. The set is the codomain. It contains the possible kind of output.
Example:
defined by .
Then:
The value is in the codomain, but it is not actually hit by this function. The set of outputs that are actually hit is called the image of the function.
Domains and Codomains
The domain and codomain are part of a function's definition. The same formula can define different functions if the domain or codomain changes.
Consider .
If , then inputs and outputs are integers.
If , then inputs and outputs are real numbers.
If , then the function is finite and can be checked by a table.
In programming, this is similar to caring about types. A function's behavior is not just the expression in its body. It also depends on what inputs are allowed and what outputs are expected.
Injective, Surjective, and Bijective Functions
These three words describe how inputs and outputs match.
A function is injective if different inputs always produce different outputs. It never collapses two distinct inputs into the same output.
Formally, is injective if:
Example: defined by is injective.
Non-example: defined by is not injective, because and .
A function is surjective if every element of the codomain is hit by at least one input.
Formally, is surjective if for every , there exists an such that .
Example: defined by is surjective.
Non-example: defined by is not surjective, because no integer squares to .
A function is bijective if it is both injective and surjective. A bijection matches every input with exactly one output and every output with exactly one input. In programming terms, a bijection is the mathematical shape of a perfectly reversible transformation.
Relations
A relation between two sets and says which pairs are connected. Formally, a relation from to is a subset of , the set of all ordered pairs with first element in and second element in .
Example:
Let and . Define a relation by saying is related to when .
Then:
Relations are more general than functions. A relation may connect one input to many outputs, or to none. A function must assign exactly one output to every input in its domain.
Equivalence Relations
An equivalence relation is a relation that behaves like "is the same kind of thing as." It must satisfy three properties.
For a relation on a set :
- Reflexive: for every .
- Symmetric: if , then .
- Transitive: if and , then .
Example:
On the set of integers, define if and have the same remainder when divided by .
Then:
This relation groups integers into classes by remainder:
- numbers congruent to modulo
- numbers congruent to modulo
- numbers congruent to modulo
Equivalence relations are important because they let us replace many objects with a smaller set of representatives. Modular arithmetic depends on this idea.
Basic Proof Methods
A proof is an argument that a claim follows from definitions and accepted facts. A proof is stronger than many examples. Examples can suggest a pattern, but they cannot establish that the pattern always holds.
Direct Proof
In a direct proof, start from the assumptions and move step by step to the conclusion.
Claim: If is even, then is even.
Proof:
If is even, then for some integer . Then:
Since is an integer, is even.
Contrapositive
The contrapositive of "if , then " is "if not , then not ." These two statements are logically equivalent.
Sometimes the contrapositive is easier to prove.
Claim: If is even, then is even.
Contrapositive: If is not even, then is not even.
Proof of contrapositive:
If is odd, then for some integer . Then:
So is odd. Therefore, if is even, must be even.
Contradiction
In a proof by contradiction, assume the opposite of what you want to prove. Then show that this assumption leads to an impossible statement.
Claim: There is no smallest positive real number.
Proof:
Assume there is a smallest positive real number . Since , the number is also positive. But , which contradicts the assumption that was the smallest positive real number. Therefore, no such smallest positive real number exists.
Induction
Induction proves a statement for all natural numbers by proving two things:
- Base case: the statement is true for the first value.
- Inductive step: if the statement is true for , then it is true for .
Claim:
for every integer .
Base case: when , the left side is and the right side is:
Inductive step: assume the formula is true for . Then:
That is the same formula with in place of , so the claim holds for all .
Why Proofs Matter in Cryptography
Cryptographic systems are designed to keep working even when someone is trying to break them. Testing examples is not enough. An attacker is free to look for the one case you did not test.
Proofs help us make precise claims such as:
- a verification equation accepts valid signatures
- a transformation is reversible only with certain information
- two protocol states are equivalent for a particular purpose
- a probability bound is small enough to be meaningful
- an attacker would need to solve a hard mathematical problem
This does not mean every deployed system is proven secure in every possible sense. Real systems also depend on implementations, parameter choices, side-channel resistance, serialization rules, and consensus behavior. The point is that proof language gives us a way to separate what is mathematically true from what is an engineering assumption.
Chia Connection
Chia uses mathematical objects that are easiest to understand once this chapter is comfortable.
Sets appear whenever we define the allowed values of a system: possible inputs, valid outputs, coins, puzzle conditions, signatures, or group elements.
Functions appear in hashes, signature verification, plotting algorithms, and state transitions. The domain and codomain matter because a function that is well-defined for one kind of object may be meaningless for another.
Equivalence relations appear in modular arithmetic, where many integers can represent the same remainder class. This idea later supports finite fields and other algebraic structures.
Proof methods appear throughout cryptography. When a later chapter says "this works for all group elements" or "this algorithm verifies the result," it is making a universal statement. Proofs are how we justify those statements.
Chia-specific implementation claims still need primary references. This chapter gives the mathematical vocabulary; it does not by itself specify Chia consensus behavior.
Common Pitfalls
Confusing examples with proofs. Checking , , and does not prove a claim for all even numbers.
Ignoring the codomain. Surjectivity depends on the codomain. The same formula may be surjective for one codomain and not another.
Treating sets like arrays. Sets do not have order or duplicate elements. Tuples do.
Assuming a relation is a function. A relation can connect one input to many outputs. A function cannot.
Forgetting one equivalence property. A relation must be reflexive, symmetric, and transitive to be an equivalence relation.
Using contradiction too casually. A contradiction proof must contradict a precise assumption, not merely produce a surprising result.
Exercises
- Let and . Is ? Explain using the definition of subset.
- Give an example of two sets that are equal even though they are written in a different order.
- Let be defined by . Is injective? Is it surjective? Explain both answers.
- Give an example of a relation from to that is not a function.
- On the integers, define if is even. Check whether this relation is reflexive, symmetric, and transitive.
- Prove directly: if is odd, then is odd.
- Prove by contrapositive: if is odd, then is odd.
- Use induction to prove that for every integer .
- In one paragraph, explain why a cryptographic claim needs more than a list of passing test cases.
Further Reading
- Any introductory discrete mathematics text covering sets, functions, and proof methods
- Later chapter: Modular Arithmetic
- Later chapter: Groups
- Later chapter: Probability for Crypto