research36 min studyLesson 993 in Mathematics

Dependent products and dependent sums

Let result types depend on inputs, count finite families, and distinguish data-level choice from truncated choice.

On this page

What you’ll understand

  • Form and use dependent function and dependent pair types.
  • Compute finite dependent-product and dependent-sum sizes.
  • Derive a choice operation from supplied witness data without assuming truncated choice.

An ordinary function has a fixed codomain. A dependent function can return a value whose type is determined by its input, while a dependent pair stores an index together with an element of the corresponding fiber. These constructions express quantification, certified outputs, and mathematical structures in one language. Their dependency is essential: exchanging two components can make a package ill typed. We will count a small family exactly and then inspect why one familiar form of choice is simply a program on already supplied data.

Families assign a type to each possible index

Let A be a type and let B assign a type to each element of A. A dependent product contains functions that return an element of B at every input. Its application rule substitutes the actual input into the result type. When B is constant this reduces to an ordinary function type. When B describes vectors of a specified length, a dependent function can return a vector whose length is determined by the requested index rather than hidden in an unchecked convention.

A dependent sum contains pairs whose first component is an index a and whose second component belongs to B of that very index. Its first projection has type A, but its second projection has a type involving the first projection. This is why a purported second component cannot be checked before its index is known. A certified integer can similarly store an integer together with evidence of a predicate about it. Ordinary Cartesian products are the constant-family special case.

f:∏a:AB(a) ⟹ f(a):B(a),z:∑a:AB(a) ⟹ π2(z):B(π1(z)).f:\prod_{a:A}B(a)\ \Longrightarrow\ f(a):B(a),\qquad z:\sum_{a:A}B(a)\ \Longrightarrow\ \pi_2(z):B(\pi_1(z)).
The codomain of application and the type of the second projection both retain the relevant index.↔ Scroll wide equations horizontally.

Finite fibers distinguish choosing all outputs from choosing one pair

For a finite index type with explicitly enumerated finite fibers, the dependent sum counts disjoint tagged possibilities, so its size is the sum of the fiber sizes. A dependent product chooses one output in each fiber, so its size is their product. These formulas count actual finite data and can be justified by constructing the corresponding lists or tables. Functions are identified extensionally by their output tables; the internal type-theoretic counting interpretation therefore uses function extensionality. This is an explicit assumption for the counts, not an infinite choice principle.

An empty fiber makes the distinction particularly sharp. The sum may still contain pairs from other fibers, but a section of the entire family cannot exist because it would have to return an element of the empty fiber. Conversely, a product over an empty index type contains the empty function, while its sum is empty. These edge cases follow from the introduction and elimination rules and are useful checks against an informal slogan that dependent sums and products merely mean some or all.

∣∑a:AB(a)∣=∑a∈A∣B(a)∣,∣∏a:AB(a)∣=∏a∈A∣B(a)∣for enumerated finite families.\left|\sum_{a:A}B(a)\right|=\sum_{a\in A}|B(a)|,\qquad \left|\prod_{a:A}B(a)\right|=\prod_{a\in A}|B(a)|\quad\text{for enumerated finite families}.
The additive formula retains a tag; the multiplicative formula records an entire table of outputs.↔ Scroll wide equations horizontally.

Untruncated witness families already contain their choices

Suppose h supplies, for every a, a dependent pair consisting of some b and evidence of a relation between a and b. Define a choice function by projecting the first component of h at a; project the second component to certify that this function satisfies the relation. This construction is sometimes called the type-theoretic axiom of choice, but in this untruncated form it is a theorem directly obtained from projections and abstraction.

It does not say that a mere statement that every fiber is inhabited provides such a table of witnesses. Propositional truncation can erase the selected elements, and moving from separately truncated existence to a simultaneous choice function is a different principle. We will give its elimination restrictions explicitly in a later lesson. The distinction prevents a common mistake: importing classical choice into a constructive argument while claiming it followed from the elementary dependent-pair projection program.

(∏a:A∑b:B(a)R(a,b))→∑f:∏a:AB(a)∏a:AR(a,f(a)),h↦(λa.π1(h(a)),λa.π2(h(a))).\left(\prod_{a:A}\sum_{b:B(a)}R(a,b)\right)\to\sum_{f:\prod_{a:A}B(a)}\prod_{a:A}R(a,f(a)),\qquad h\mapsto\bigl(\lambda a.\pi_1(h(a)),\lambda a.\pi_2(h(a))\bigr).
Every chosen b is already present in the input h; no truncation is removed by this construction.↔ Scroll wide equations horizontally.

Count and construct a two-fiber section

Index a family by Bool. Let the false fiber be Fin(2) and the true fiber Fin(3), where Fin(n) consists of natural numbers strictly below n. Count the dependent sum and product, then exhibit a section.

  1. The sum has two false-tagged pairs, with second components zero and one, and three true-tagged pairs, with second components zero, one, and two. These five pairs remain distinct because their tags or finite values differ.

  2. A dependent function chooses one of two values at false and one of three values at true. The six possible ordered output tables are (0,0), (0,1), (0,2), (1,0), (1,1), and (1,2).

  3. Choose the table (1,2). Its false output is below two and its true output is below three, so both typing obligations hold. Pairing the input true with the corresponding output constructs the dependent-sum element (true,2).

∣ΣB∣=2+3=5,∣ΠB∣=2⋅3=6,f(true):Fin⁡(3).|\Sigma B|=2+3=5,\qquad |\Pi B|=2\cdot3=6,\qquad f(\mathrm{true}):\operatorname{Fin}(3).
The value two would be invalid in the false fiber even though it is valid in the true fiber.↔ Scroll wide equations horizontally.
The result

The sum contains five elements and the product six. The section f(false)=1, f(true)=2 is well typed in both fibers.

Explore the model

Interactive lab

Interactive lab · modular

Enumerate finite codes without forgetting the interpretation

Pause and Reset, then set modulus to 5 and additive step to 2. Predict the orbit 0, 2, 4, 1, 3 before it repeats; these can code the five sum elements listed on paper. For a fresh comparison Reset and set modulus to 6 and step to 1, enumerating the six function tables. The instrument only traverses finite codes; it neither checks dependent types nor chooses a canonical coding. Parameter edits retain time, so Reset and set both controls before each comparison.

Enumerate finite codes without forgetting the interpretationAddition modulo m starts at zero: rₙ = na mod m. Playback advances two additions per second. The orbit has period m/gcd(m,a), including period one for a = 0. This is not a cryptographic security test or a primality algorithm. Current readings: Residue r0: 0; Orbit period · m/gcd(m,a): 12; Distinct residues visited: 1 of 12. All parameters are adjustable with the labeled controls below.Repeated addition modulo 12: the current residue is 0, and the orbit period is 12.01234567891011+ 5mod 12An additive orbitn = 0rₙ = 0Period = 12Cycle starts at 0:0 → 5 → 10 → 3 →8 → 1 → 6 → 11 →4 → 9 → 2 → 7 → 0Exact residues · two additions per second
Additive orbitCurrent residue / next edge
Residue r0
0
Orbit period · m/gcd(m,a)
12
Distinct residues visited
1 of 12
t = 0 s

Addition modulo m starts at zero: rₙ = na mod m. Playback advances two additions per second. The orbit has period m/gcd(m,a), including period one for a = 0. This is not a cryptographic security test or a primality algorithm. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forA finite coding can enumerate data once the correspondence between codes and typed objects is supplied.

Check your understanding

Which input justifies the displayed constructive choice-by-projections program?

Try it yourself

Replace the false fiber by Fin(0) and the true fiber by Fin(2). Count the sum and product, and explain what the product count says about a proposed section.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

List the available tagged pairs, then inspect the output a section would have to provide at false.

Compare with the solution

Only the true-tagged pairs (true,0) and (true,1) remain, so the sum has two elements. The product has zero elements because its size is zero times two. More directly, a proposed section evaluated at false would produce an element of Fin(0), which is empty. The sum can therefore be inhabited while the family has no section, and the obstruction is a particular missing fiber rather than an appeal to an infinite choice principle.

Take it with you

  • Dependent application substitutes the input into the output type.
  • A dependent sum stores one indexed element; a dependent product supplies every fiber's output.
  • Choice from untruncated pairs is a projection program, distinct from truncated choice.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.