On the Nielsen-Schreier Theorem in Homotopy Type Theory

We give a formulation of the Nielsen-Schreier theorem (subgroups of free groups are free) in homotopy type theory using the presentation of groups as pointed connected 1-truncated types. We show the special case of finite index subgroups holds constructively and the full theorem follows from the axiom of choice. We give an example of a boolean infinity topos where our formulation of the theorem does not hold and show a stronger"untruncated"version of the theorem is provably false in homotopy type theory.


Introduction
The statement of the Nielsen-Schreier theorem sounds very simple at first: subgroups of free groups are themselves free. However direct proofs are known to be surprisingly intricate and difficult. This was the case for the original proofs by Nielsen [Nie21], for finitely generated free groups, and Schreier [Sch27], generalising to all free groups.
However, later on much clearer proofs were developed based on ideas from topology, the first by Baer and Levi [BL36]. 1 The idea essentially is that free groups are precisely the fundamental groups of bouquets of circles. Any subgroup is then the fundamental group of a covering space of a bouquet of circles. However, any covering space is homotopic to the geometric realisation of a graph, so the problem is reduced to showing that the fundamental groups of graphs are free groups. This is proved by constructing a spanning tree of the graph, which is then contracted down to point, leaving the remaining edges outside the spanning tree as edges from that point to itself, showing that the graph is homotopy equivalent to a bouquet of circles.
This use of ideas from topology makes the Nielsen-Schreier theorem a natural candidate for formalisation in homotopy type theory [Uni13]. In homotopy type theory we can study spaces from a synthetic point of view, allowing us to use much simpler definitions that are easier to deal with in formalisations, while still being guided by the same topological Key words and phrases: homotopy type theory, free groups. I gratefully acknowledge the support of the Air Force Office of Scientific Research through MURI grant FA9550-15-1-0053. Any opinions, findings and conclusions or recommendations expressed in this material are those of the authors and do not necessarily reflect the views of the AFOSR.. Definition 2.3. Let (BG, base) be a group. A covering space on BG is a function BG → hSet.
A pointed covering space is a covering space X : BG → hSet together with an element of X(base).
We say a covering space X : BG → hSet is connected if the total space z:BG Xz is connected.
We say a covering space X : BG → hSet has index I if there merely exists an equivalence between X(base) and I. In particular, we say it has finite index if X(base) is merely equivalent to an initial segment of N.
Pointed connected covering spaces on BG correspond precisely to subgroups of G [BvDR18, Theorem 7.1(3)]. We will therefore sometimes refer to them simply as subgroups.
Free groups in this setting were studied by Kraus and Altenkirch [KA18]. We recall some of their results below.
We first define the free higher group BF ∞ A as the higher inductive type generated by the following constructors: (1) BF ∞ A contains a point base.
(2) For each a : A we add a path loop(a) from base to base.
If A is a set with decidable equality then BF A is 1-truncated, and so a group, as defined above. It is currently an open problem whether this can be proved constructively for sets A in general. We therefore define the free group on A to be the 1-truncation BF A := BF ∞ A 1 . We can equivalently characterise the free group on A using any of the following descriptions.
(1) The 1-truncation of the wedge product of A copies of (S 1 , base).
(2) The coproduct of A copies of the group Z := (S 1 , base) in the category of groups and group homomorphisms. (3) The 1-truncation of the coequalizer of the graph A ⇒ 1.
(4) The unique group (BF A , base) equipped with a map loop : satisfying the universal property that for any group (BG, base G ) and any map g : A → Ω(BG, base G ), there is a unique homomorphism h : (BF A , base F A ) → (BG, base G ) such that for all a : A, ap h (loop(a)) = g(a).

Coequalizers in HoTT
In this section we review the definition of coequalizers in homotopy type theory and show some useful lemmas. We will omit some of the formal details. See the Agda formalisation for complete proofs. 3 Definition 3.1. A graph consists of two types V and E together with two maps π 0 , π 1 : E ⇒ V . We will refer to elements of V as vertices and elements of E as edges.
Definition 3.2. Suppose we are given a graph π 0 , π 1 : E ⇒ V . The coequalizer of (V, E, π 0 , π 1 ), denoted V /E when π 0 and π 1 are clear from the context, is the higher inductive type generated by the following constructors.
(1) For every v : V , V /E contains a point [v].
We will use the following three key lemmas about coequalizers in the proof.
In the first lemma we are given a graph where the type of edges is a coproduct of two types E 0 and E 1 . We show that the coequalizer V /E 0 + E 1 can be computed in two steps, first quotienting by E 0 , and then by E 1 . We can visualise this as follows. Suppose we are given a topological space V , and produce a new space by gluing on a set of intervals indexed by E. Then we obtain the same space by first gluing on half of the intervals, and then separately gluing on the other half.
Lemma 3.3. Suppose we are given types E 0 , E 1 , V together with a pair of maps π 0 , π 1 : E 0 + E 1 ⇒ V . By composing with the coproduct inclusion we get a diagram E 0 ⇒ V , and so a type V /E 0 given by coequalizer. We then obtain a pair of maps E 1 ⇒ V /E 0 by composing with the other coproduct inclusion and the map [−] : V → V /E 0 . We then have the equivalence below.
can be constructed by recursion on coequalizers. One can then show f • g ∼ 1 and g • f ∼ 1 by induction on the construction of the coequalizers.
We visualise the second lemma as follows. We are given a space X together with a point x ∈ X. We extend X to a larger space by adding an extra path e with one endpoint attached at x. Then X is homotopy equivalent to X, since we can contract the new path e down to the point x. The analogous construction in algebraic topology is sometimes known as "growing a whisker." Lemma 3.4. Let X be a type with an element x : X. Define two maps 1 ⇒ X + 1 corresponding to the two elements inl(x) and inr( * ) of X + 1. Then the canonical map to the coequalizer f : X → X + 1 → X + 1/1 is an equivalence.
Proof. We can construct an inverse g : (X + 1)/1 → X by recursion on the definition of coequalizer. Note that g • f is definitionally equal to 1, and we can show f • g ∼ 1 by induction on the definition of (X + 1)/1. Lemma 3.5. "Coequalizers are stable under pullback." Suppose we are given a graph E ⇒ V and a family of types X : V /E → Type. Define E := e:E X([π 0 (e)]) and V := v:V X([v]). Define π 0 , π 1 : E → V by π 0 (e, x) := (π 0 (e), x) and π 1 (e, x) := edge(e) * (x) Proof. This can be seen as a special case of the flattening lemma for coequalizers [Uni13, Lemma 6.12.2]. However, for completeness we will give a direct proof.
We first define a map f : z:V /E X(z) → V /E . Equivalently we can define a dependent function f : z:V /E (X(z) → V /E ). We define f using the elimination principle of V /E.
. Given e : E we need to define a path as below.
edge(e) * (f ([π 0 (e)])) = f (π 1 (e)) (3.1) However, by path induction we can show that for all paths p : z = z in V /E and all h : X(z) → V /E that p * (h)(x) = h(p −1 * (x)). By applying the above with h = f (π 0 (e)) and p = edge(e), and function extensionality, we can deduce (3.1) by finding for each e : E and each x : X(π 1 (e)) a path of the type below. By definition, it suffices to find a path (π 0 (e), edge(e) −1 * (x)) = (π 1 (e), x) in V . However, by the characterisation of identity types for -types, this is the same as a path q : π 0 (e) = π 1 (e) together with a path as below.
We will define g : V /E → z:V /E X(z) by recursion on the construction of V /E . We define g , we have an evident path ([π 0 (e)], x) = ([π 1 (e)], edge(e) * (x)), which gives us the well defined function g.
Finally, one can verify f • g ∼ 1 by induction on the definition of V /E , and g • f ∼ 1 by induction on the definition of V /E.
We will often also implicitly use the following lemma.
Lemma 3.6. Suppose we are given graphs τ 0 , τ 1 : D ⇒ U and π 0 , π 1 : E ⇒ V together with equivalences D E and U V commuting with the endpoint maps. Then we have an equivalence U/D V /E.
Proof. For convenience we will assume that all types involved lie at the same universe level. 4 By univalence we may assume that D = E and U = V , and that the equivalences are given by transport along these paths. Hence it suffices to show that for all types D, E, U, V , all paths p : D = E and q : U = V , all maps τ 0 , τ 1 : D ⇒ U and π 0 , π 1 : E ⇒ V and finally all proofs that q * • τ i = π i • p * we have an equivalence U/D V /E. However, the preceding statement can be proved by iterated path induction.

Spanning Trees in HoTT
We think of the coequalizer of a graph E ⇒ V as its geometric realisation, the topological space that has a point for each vertex v : V , and a path from π 0 (e) to π 1 (e) for each edge e : E. Note that a graph is connected if and only if its geometric realisation is connected. Similarly a graph is a tree if and only if its geometric realisation is contractible, or equivalently if it is both connected and 0-truncated (contains no non trivial cycles). We will take this topological point of view as the definition of connected and tree.
Definition 4.1. Let E ⇒ V be a graph. We say the graph is connected if E/V is a connected type, and we say the graph is a tree if E/V is contractible.
Definition 4.2. Let π 0 , π 1 : E ⇒ V be a graph. A subgraph is a graph D ⇒ U together with embeddings h : D → E and k : U → V such that the following squares commute for i = 0, 1: For the more general statement where the types can have different universe levels, we need an additional lemma that coequalizers are preserved by "lifting" to higher universe levels. See the file main/Coequalizers/PreserveEquivalence.agda in the formalisation for details.

18:6
A.W. Swan Vol. 18:1 Definition 4.3. Let E ⇒ V be a graph. A spanning tree is a subgraph D ⇒ U such that D ⇒ U is a tree, the embedding U → V is an equivalence and the embedding D → E has decidable image. 5 We will give two lemmas on the existence of spanning trees. Both will use Lemma 4.5, which in turn uses the lemma below.
Lemma 4.4. Suppose we are given a connected graph E ⇒ V , and that V decomposes as a coproduct V V 0 + V 1 . Suppose further that we are given an element of each component v 0 : V 0 and v 1 : V 1 . Then there merely exists an edge e : E such that either π 0 (e) ∈ V 0 and π 1 (e) ∈ V 1 , or π 0 (e) ∈ V 1 and π 1 (e) ∈ V 0 .
Proof. We first define a family of propositions P : V /E → Type. We wish P to satisfy the following. For v : V 0 , P ([inl(v)]) = 1, and for v : V 1 we require the equation below.
To show such a P exists, we note that the requirements above precisely define the action on points of a recursive definition on V /E. Hence to get a well defined function it suffices to define an action on paths. That is, we need equalities P ([π 0 (e)]) = P ([π 1 (e)]) for e : E. By propositional extensionality we just need to show P ([π 0 (e)]) and P ([π 1 (e)]) are logically equivalent. However, this is straightforward by considering the 4 cases depending on whether π i (e) ∈ V 0 or π i (e) ∈ V 1 for i = 0, 1: if π 0 (e) and π 1 (e) lie in the same component of the coproduct, then P ([π 0 (e)]) and P ([π 1 (e)]) are the same by definition, and if they lie in different components, then P ([v]) is true for all v : V . We now construct a map from [inl(v 0 )] = z to P (z) for each z : V /E. By based path induction it suffices to construct an element of P (inl(v 0 )), but this was defined to be 1, so is trivial. By connectedness, there merely exists an element of [inl(v 0 )] = [inl(v 1 )], and so P (inl(v 1 )) is inhabited and the lemma follows.
To further illustrate the proof of Lemma 4.4 we give an alternative non constructive proof using the same family of types P .
Using the law of excluded we can assume there is no edge with endpoints in different components of V and derive a contradiction. Under this assumption, our requirement on P is that it is 1 on V 0 and 0 on V 1 . In other words we have a 2-colouring of vertices and want to extend it to a 2-colouring on the whole graph. We can do this by the assumption, since any edge has the same colour on both its endpoints, so we can take the whole edge to be that colour. This now contradicts connectedness, since we have a surjection from the graph to 2. Topologically, we can think of this as a continuous surjection from a connected space to the discrete space 2, which is not possible.
Lemma 4.5. Let E ⇒ V be a connected graph where V has decidable equality and E is a set, together with a subgraph D ⇒ U such that the inclusion U → V has decidable image.
Suppose further that we are given elements u ∈ U and v ∈ V \ U . Then there merely exists a larger subgraph whose type of vertices is U + 1 and whose type of edges is D + 1, 5 It is not clear if decidable image should be part of the definition of spanning tree for every application.
However, the main use of spanning trees for this paper will be Lemma 4.8 below, where it does play a critical role. such that the canonical map U/D → (U + 1)/(D + 1) is an equivalence, as illustrated below: Applying Lemma 4.4 shows there merely exists an edge e : E such that either π 0 (e) ∈ U and π 1 (e) / ∈ U or vice versa. We consider the former case, the latter being similar.
We define the map U + 1 → V to be the same as the map U → V on the U component and to be equal to π 1 (e) on the 1 component. Since π 1 (e) / ∈ U , this is an embedding. Similarly we define the map D + 1 → E by taking the 1 component to e. Note that we cannot have e ∈ D, since this would imply π 1 (e) ∈ U , and so the map D + 1 → E is also an embedding.
We define the endpoint maps D + 1 ⇒ U + 1 as appropriate to satisfy commutativity conditions.
Finally, we verify the equivalence by computing as follows.
(U + 1)/(D + 1) ((U + 1)/1)/D Lemma 3.3 U/D Lemma 3.4 Lemma 4.6. Let E ⇒ V be a connected graph where V is finite, say with |V | = n and E is a set with decidable equality. Then the graph merely has a spanning tree D → E ⇒ V where D is finite with |D| = n − 1.
Proof. We show by induction that for 1 ≤ k ≤ n there merely exists a subgraph D ⇒ U such that |U | = k, |D| = k − 1 and U/D is contractible. For k = 1 we observe that by the definition of connectedness, V /E is merely inhabited, and so V is also merely inhabited. An element v of V defines an embedding 1 → V , and it is clear that the coequalizer 1/0 is contractible. Now suppose we have already defined a suitable subgraph for 1 ≤ k < n, say D ⇒ U . Since V is finite, it in particular has decidable equality. Furthermore, since |U | = k with 1 ≤ k < n, there exist u ∈ U and v / ∈ U . Hence we can apply Lemma 4.5 to show the existence of a subgraph of the form D + 1 ⇒ U + 1 where (U + 1)/(D + 1) U/D. Since U/D is contractible, so is (U + 1)/(D + 1), as required. Now we apply the above with k = n to get a subgraph D ⇒ U where U/D is contractible. Since U and V are both finite of the same size n, the embedding U → V is an equivalence. Since E has decidable equality and D is finite, the embedding D → E has decidable image. Hence this does indeed give a subtree.
Lemma 4.7. Let E ⇒ V be a connected graph where E and V are both sets. Suppose that the axiom of choice holds. Then a spanning tree for the graph merely exists.
Proof. Recall that the axiom of choice implies the law of excluded middle and Zorn's lemma.
We consider the set of subgraphs of E ⇒ V that are trees, ordered by inclusion. We verify that the poset is chain complete. If we are given a chain of subgraphs (D i ⇒ U i ) (i:I) , take D ⇒ U to be the union of all the subgraphs, and write ι i for the canonical map U i /D i → U/D. Fix u : U , noting that such a u merely exists since I is merely inhabited 6 and U i /D i is contractible for each i. Hence the poset has a maximal element D ⇒ U by Zorn's lemma. We wish to show every element of V belongs to U . By the law of excluded middle, it suffices to derive a contradiction from the assumption of v ∈ V \ U . However, by Lemma 4.5 we could obtain a larger tree subgraph, contradicting maximality, as required.
Again using excluded middle, D has a complement in E, giving us the spanning tree.
We next see a key lemma that establishes the geometric realisation of graphs that have spanning trees are equivalent to bouquets of circles. The way to visualise this is that we contract the spanning tree down to a single point. This leaves the remaining edges not in the spanning tree as loops from this single point to itself.

The Nielsen-Schreier Theorem
We now prove two versions of the Nielsen-Schreier theorem in HoTT. Following the classical proofs, we proceed in two steps. We first show that every subgroup of a free group is equivalent to the geometric realisation of a graph. We then use the results of Section 4 to deduce that it equivalent to a free group, under certain conditions. Lemma 5.1. "Every bundle on a free ∞-group is the geometric realisation of a graph." Let A be any type, and (BF A , base) the free ∞-group on A generated by paths loop(a) for a : A. Let X : BF A → Type be any family of types over BF A . We define a graph π 0 , π 1 : A × X(base) → X(base) by taking π 0 to be projection, and define π 1 (a, x) to be loop(a) * (x). We then have Proof. Note that BF A is equivalent to the coequalizer of a graph A ⇒ 1 with base = [ * ] where * is the unique element of 1. Hence we can apply Lemma 3.5 to express z:BF A X(z) as a coequalizer V /E . However, we then have the following definitional equalities and equivalences.
In order to derive the truncated version of Lemma 5.1 we first recall the following flattening lemma for truncation.
Lemma 5.2. Suppose we are given a type Y and a family of sets X : Y 1 → hSet. Then z: Y 1 X(z) y:Y X(|y| 1 ) 1 . Proof. Similar to the proof of Lemma 3.5.
Lemma 5.3. "Every subgroup of a free group is the geometric realisation of a graph." Let A be a set, and (BF A , base) the free group on A. Let X : BF A → hSet be a covering space on BF A . Then we then have the following.
Proof. We define X : BF ∞ A → Type to be the composition of X with the truncation map | − | 1 : BF ∞ A → BF A and projection from hSet to Type. Lemma 5.1 then gives us an equivalence z:BF ∞ A X (z) X (base)/(A × X (base)). However, X (base)/(A × X (base)) is definitionally equal to X(base)/(A × X(base)). By Lemma 5.2 we have that Putting these together gives us the required equivalence z: BF ∞ A 1 X(z) X(base)/(A × X(base)) 1 .
We now give two versions of the Nielsen-Schreier theorem that hold in homotopy type theory. The first is entirely constructive and includes the Nielsen-Schreier index formula.
Theorem 5.4. Suppose that BF A is the free group on a set A with decidable equality. Suppose that X : BF A → hSet is a finite index, connected covering space. Then z:BF A Xz is merely equivalent to the classifying space of a free group.
Moreover, suppose that A is finite of size n and that X is of finite index m. Then there merely exists an equivalence, Proof. By Lemma 5.3 we have z:BF A X(z) X(base)/(A × X(base)) 1 . 8 Note that X(base)/(A × X(base)) is a coequalizer where the vertex set X(base) is finite and the edge set A × X(base) has decidable equality. Hence we can apply Lemma 4.6 to show a spanning tree exists. Hence we can apply Lemma 4.8 to show X(base)/(A × X(base)) is equivalent to a free higher group. Truncating gives us an equivalence between X(base)/(A × X(base)) and a free group. Now suppose that A is also finite, with |A| = n and |X(base)| = m. Then Lemma 4.6 in fact gives us a spanning tree with m vertices and m − 1 edges. In particular we can write the edge set A × X(base) as a coproduct E 0 + E 1 where X(base)/E 0 is contractible and |E 0 | = m − 1. Lemma 4.8 then tells us X(base)/(A × X(base)) is equivalent to the free (higher) group on E 1 . However |E 1 | = mn − (m − 1) = m(n − 1) + 1, as required.
Theorem 5.5. Assume the axiom of choice. Suppose that BF A is the free group on a set A. Let X : BF A → hSet be any connected covering space. Then z:BF A Xz is merely equivalent to a free group.
Proof. Similar to the proof of Theorem 5.4 using Lemmas 5.3, 4.7 and 4.8.

A Boolean ∞-Topos where the Theorem does not Hold
We recall that Läuchli proved the following theorem in [Läu62, Section IV].
We will sketch out how to adapt the proof to obtain a model of homotopy type theory with excluded middle where the Nielsen-Schreier theorem does not hold. In order to do this we will work in a classical metatheory and we will switch back to the classical definition of free groups using reduced words. In the presence of the law of excluded middle this is equivalent to our earlier definition by [KA18, Section 2.2].
We first recall the following lemma from Läuchli's proof.
Lemma 6.2. Let F A be a free group and C ≤ F A the subgroup generated by elements of the form aba −1 b −1 for a, b ∈ A. Let X ⊆ C be a set that freely generates C. Then X cannot be invariant under any transposition (a b) for a = b ∈ A.
We will construct our example using the (1-)topos of nominal sets [Pit13]. We first recall the basic definitions. We fix a countably infinite set A. We write Perm(A) for the group of finitely supported permutations of A (i.e. π : A ∼ −→ A such that π(a) = a for all but finitely many a ∈ A).
If (X, ·) is a Perm(A)-set, x ∈ X and A ⊆ A, we say A is a support for x if π · x = x whenever π ∈ Perm(A) satisfies π(a) = a for all a ∈ A.
The topos of nominal sets is defined to be the full subcategory of Perm(A)-sets consisting of (X, ·) such that every element x ∈ X has a finite support. Proof. First recall that A can itself be viewed as a nominal set by taking the action to be π · a := π(a). Take F A to be the internal free group on A. Observe, e.g. by verifying the universal property that F A is just the external definition of F A together with the action given by the action on A and the universal property.
We define C ≤ F A by externally taking it to be the subgroup generated by elements of the form aba −1 b −1 for a, b ∈ A. We observe that the action of Perm(A) on F A restricts to C, giving us a subgroup C ≤ F A in nominal sets. The object of freely generating subsets, G of C can be explicitly described as the set of X ⊆ C such that X has finite support and (externally) freely generates C, with the obvious action. The Nielsen-Schreier theorem implies that G contains some element X. Let A ⊆ A be a finite support for X. Let a, b be distinct elements of A \ A. Then (a b) · X = X, contradicting Lemma 6.2.
Corollary 6.4. There is a boolean ∞-topos where the Nielsen-Schreier theorem does not hold. The Nielsen-Schreier theorem is not provable in homotopy type theory, even with the addition of the law of excluded middle.
Proof. The topos of nominal sets is equivalent to a Grothendieck topos referred to as the Schanuel topos [Pit13, Section 6.3].
Lurie showed in [Lur09, Proposition 6.4.5.7] that any Grothendieck (1-)topos is equivalent to the 0-truncated elements of some Grothendieck ∞-topos. In particular, if we apply this to the topos of nominal sets we obtain a boolean Grothendieck ∞-topos where Nielsen-Schreier does not hold.
Shulman proved in [Shu19] that homotopy type theory can be interpreted in any Grothendieck ∞-topos. We thereby obtain a model of HoTT with the law of excluded middle where Nielsen-Schreier does not hold. Remark 6.5. As an alternative to the non constructive methods of Lurie and Shulman, it may also be possible to use a cubical sheaf model, as developed by Coquand, Ruch and Sattler [CRS19], but we leave a proof for future work.

The Untruncated Nielsen-Schreier Theorem is False
In this section we will again work with the more usual definition of group as set with a binary operation satisfying the well known axioms. We will write the free group as F A , which is the loop space of BF A at base. We recall the observation of Kraus and Altenkirch [KA18, Section 2.2] that when A has decidable equality we can use the classical description of F A as the set of reduced words with multiplication given by concatenation followed by reduction. In particular we note that when A has decidable equality so does F A .
In Theorems 5.4 and 5.5 we were careful to state that the equivalences merely exist, to emphasise that formally we are only constructing an element of the truncation z:BF A Xz BF B , not the type z:BF A Xz BF B itself. In this section we will see why the distinction is important. To understand this, we first define the following two variants of the Nielsen-Schreier theorem.
Definition 7.1. We say the untruncated Nielsen-Schreier theorem holds if for each set A and each subgroup H → F A we can choose a subset C A,H → H that freely generates H, i.e. the lift F C A,H → H given by universal property is an isomorphism.
Definition 7.2. We say the equivariant Nielsen-Schreier theorem holds if for each set A and each subgroup H → F A we can choose a subset C A,H → H that freely generates H satisfying the following condition. Given any equivalence π : A → A we writeπ for the lift to an isomorphism F A ∼ = F A given by universal property. We require that C A ,π(H) =π(C A,H ). Moreover, the untruncated Nielsen-Schreier theorem restricted to free groups generated by merely finite sets implies the equivariant Nielsen-Schreier theorem with the same restriction. = idtoeqv(p)(C A,H ). However, by univalence and the fact that the projection from hSet to Type is an embedding, for every equivalence π : A A , there is a unique path p : A = A such that π = idtoeqv(p), so this is true for all equivalences. Note that the projection from merely finite sets to sets is an embedding, so it remains true for merely finite A, A that any π : A A can be written uniquely as idtoeqv(p) for some p : A = A . At this point it is possible to apply Lemma 6.2 to show the equivariant Nielsen-Schreier theorem is false. However, for the theorem below we will use an alternative proof, for two reasons. Firstly, we will give a stronger result that the equivariant version of the theorem fails already for the case of finite index subgroups of finitely generated free groups, whereas in Läuchli's example the free group is infinitely generated, and we can see by Theorem 5.4 the given subgroup must have infinite index. Secondly, we can use an easier, more straightforward argument, since to find a counterexample to equivariance, we only need to show any set of generators is not fixed by some transposition, rather than the stronger result that any generating set is not fixed by any non-trivial transposition. In fact we will see that one of the very simplest instances of the Nielsen-Schreier theorem suffices to find a counterexample.
Theorem 7.4. The equivariant Nielsen-Schreier theorem is false in homotopy type theory, extensional type theory and classical mathematics. Moreover, it remains false if we restrict to finite index subgroups of finitely generated free groups.
Proof. We will given an example of a finite index subgroup of a finitely generated free group F A that does not satisfy the equivariance condition for all automorphisms π : A A.
We take A to be a type with exactly two elements that we write as a and b. Note that we have a unique homomorphism θ : F A → Z/2Z that sends both a and b to 1. We take H ≤ F A to be the kernel of θ. We first observe that H has index 2, since for homomorphisms θ in general, the index of ker(θ) is equal to the size of the image of θ, and in this case θ is surjective and the codomain has size 2.
Take π to be the transposition (a b). By the assumption of equivariant Nielsen-Schreier we have C A,H such thatπ(C A,H ) = C A,π(H) . However, note that θ(π(g)) = θ(g) for all g ∈ F A , since this is clearly true whenever g ∈ A. Henceπ(H) = H. It follows that π(C A,H ) = C A,H . We next show that C A,H has exactly 3 elements. Certainly H can be freely generated by a (non-equivariant) set of 3 elements by the Nielsen-Schreier theorem, say g 1 , g 2 , g 3 . 9 We only need finitely many elements of C A,H to generate each of g 1 , g 2 , g 3 , and so a finitely enumerable subset 10 of C A,H generates all of H. By freeness and the fact that F A has decidable equality, it follows C A,H itself is finitely enumerable. Again using that F A has decidable equality it follows that C A,H is finite, i.e. in bijection with an initial segment of N. One can then show C A,H has the same size as any other finite set that freely generates H using standard arguments from algebra such as [Rot03, Proposition 5.75], which is constructively valid as stated. Hence |C A,H | = 3.
We can now deduce thatπ permutes the set with three elements C A,H . However, it has order 2, and any permutation of 3 elements of order 2 has a fixed point. We deduce that π(h) = h for some h ∈ C A,H . But, using the explicit description of F A in terms of reduced words, the only element of F A fixed byπ is the identity, which cannot appear in any free generating set, giving a contradiction.
Corollary 7.5. The untruncated Nielsen-Schreier theorem is false in homotopy type theory. Moreover, it remains false if we restrict to finite index subgroups of finitely generated free groups.
Proof. By Lemma 7.3 it suffices to show the equivariant Nielsen-Schreier theorem in finite index subgroups of finitely generated free groups is false, which was Theorem 7.4.

Conclusion
We have given a proof of two versions of the Nielsen-Schreier theorem in homotopy type theory. The proof of the finite index version, Theorem 5.4 has been verified electronically in the Agda proof assistant using the HoTT Agda library [BHC + ]. Since we only used axioms that are always present in homotopy type theory, the formal proof holds in a wide variety of models. Alternatively, we could have used the new cubical mode now available in Agda [VMA19]. In this case the class of models is currently limited to those following the Orton-Pitts approach [OP16], but some of the proofs would have been a bit easier (see below).
In the proof we made good use of concepts in HoTT to transfer ideas from the topological proof into type theory. In particular we used the coequalizer higher inductive type to represent the geometric realisation of graphs and (in particular) free groups. This approach was even useful in the relatively concrete construction of spanning trees in Section 4. We defined trees and connected graphs by applying the existing concepts of contractibility and connectedness of types to the coequalizer of the graph. We were able to work directly with these definitions throughout, without ever needing to define or use the more usual notion of path in a graph as a finite sequence of edges, which was an advantage in the electronic formalisation.
One minor difficulty in the formal proof is the lemmas on coequalizers appearing in Section 3, in particular the higher paths that appear when constructing the equality part of an equivalence by coequalizer induction. However, many of these difficulties could have been eliminated by instead using cubical mode. This allows one to define coequalizers using the usual Agda data syntax, to use pattern matching instead of elimination terms and it makes β-reduction for path constructors definitional, the latter playing a useful role in these proofs particularly. To demonstrate this a formalisation of some of the results of Section 3 using cubical mode has been added in a separate directory.
The independence result in Section 6 shows that the axiom of choice is necessary for the main theorem. It also demonstrates that independence results in HoTT can now be relatively straightforward thanks to Shulman's interpretation of HoTT in a Grothendieck ∞-topos [Shu19], Lurie's construction of enveloping ∞-toposes [Lur09] and the existing body of work on Grothendieck toposes, in this case the use of nominal sets to provide simpler categorical versions of proofs using Fraenkel-Mostowski models.
Finally the result in Section 7 provides a simple example of an important concept in HoTT and its relevance to the Nielsen-Schreier theorem: mathematics in the presence of univalence is "inherently equivariant."