@@ -42,17 +42,29 @@ would like to enforce that constructions on $\operatorname{Fin}(n)$
4242wrapped it in ` Irr ` {.Agda}.
4343
4444In dependent type theory, it's common to instead define the finite sets
45- as a family indexed over ` Nat ` {.Agda}. However, we prefer the definition
46- above because it lets us ` cast ` {.Agda} elements of
47- $\operatorname{Fin}(n)$ along a path $n = m$ in a way that
48- definitionally preserves the underlying number:
45+ as an inductive family indexed over ` Nat ` {.Agda}. However, in cubical
46+ type theory, there is a good reason to avoid inductive families: they
47+ have ` subst ` {.Agda} as an additional constructor, * including* along
48+ constant paths. This makes the normal form of any expression involving
49+ substitution in an indexed family, even if the thing being transported
50+ is a constructor form, very bad.
51+
52+ Instead, we would like the ` subst ` {.Agda} operation on ` Fin ` {.Agda} to
53+ definitionally commute with the constructors, and (if possible) to
54+ definitionally preserve the underlying numeric value. Defining
55+ ` Fin ` {.Agda} as an indexed type with an irrelevant proof field achieves
56+ exactly this:
4957
5058``` agda
51- cast : ∀ {m n} → m ≡ n → Fin m → Fin n
52- cast p (fin n ⦃ i ⦄) = record
53- { lower = n
54- ; bounded = subst (n Nat.<_) p <$> i
55- }
59+ private
60+ cast : ∀ {m n} → m ≡ n → Fin m → Fin n
61+ cast p (fin n ⦃ i ⦄) = record
62+ { lower = n
63+ ; bounded = subst (n Nat.<_) p <$> i
64+ }
65+
66+ _ : ∀ {m n} {p : m ≡ n} {x : Fin m} → subst Fin p x ≡ cast p x
67+ _ = refl
5668```
5769
5870<!--
@@ -141,15 +153,6 @@ Fin-elim P pfzero pfsuc i with fin-view i
141153```agda
142154fin-ap : ∀ {n} {x y : Fin n} → x .lower ≡ y .lower → x ≡ y
143155fin-ap p = ap₂ (λ x y → fin x ⦃ y ⦄) p (to-pathp refl)
144-
145- cast-uncast : ∀ {m n} → (p : m ≡ n) → ∀ x → cast (sym p) (cast p x) ≡ x
146- cast-uncast p x = refl
147-
148- cast-is-equiv : ∀ {m n} (p : m ≡ n) → is-equiv (cast p)
149- cast-is-equiv p = is-iso→is-equiv $ iso
150- (cast (sym p))
151- (cast-uncast (sym p))
152- (cast-uncast p)
153156```
154157-->
155158
0 commit comments