TITLE: Practical example in using (homotopy) type theory
QUESTION [15 upvotes]: I have just read Grayson's introduction on homotopy type theory as a possible foundation for mathematics. It is very enlightening about what all the fuss is about, but I am left with some doubts. Forgive my naiveté, I am not expert in type theory at all.
When one uses ZFC as a foundation for mathematics, one evenutally moves to doing informal reasoning, knowing that it is always possible, although slightly tedious, to formalize all arguments. I am not sure about how to perform this step in HTT.
Let me take the example of Grayson, who shows how to define a group in HTT. First, he defines

a type $P$ is a proposition iff it has at most one element (that is, the type $\prod_{p : P} \prod_{q : P} p = q$ is inhabited) - which, if existent, is called a proof of $P$
a type $S$ ia a set iff for all $s: S$ and $t: S$ the type $s = t$ is a proposition

Then a group is a tuple $(G, e, i, m, \alpha, \lambda, \rho, \lambda', \rho', \iota)$ where

$G$ is a type
$e: G$, $i: G \to G$, $m: G \times G \to G$
$\alpha$ is a proof of the identity stating associativity, and so on for $\lambda, \rho, \lambda', \rho'$ which prove left and right identity of $e$ and existence of left and right inverses
$\iota$ is a proof that $G$ is a set (according to Grayson, it is a theorem that this fact is itself a proposition)

So far, so good: I am inclined to believe that with a little ingenuity one can in fact define most (all?) usual concepts in mathematics.
Now, I would like to go on proving theorems about groups. The simplest non-trivial theorem I can think of is Lagrange theorem: if $G$ is a finite group and $H < G$ a subgroup, then $|H|$ divides $|G|$. The intuitive proof is very short: for every coset $C$ of $H$ and any $c \in C$, multiplication by $c$ is a bijection $H \to C$, and $G$ is partitioned into cosets.
It is clear to me how to formalize this in ZFC, but I would be lost trying to do that in HTT. I have two kind of doubts:
1) Do all steps work as well? It seems to me that one uses the notion of subset. Is there such a notion in HTT? I guess there are no subtypes, so it would seem no subsets as well. I guess that one can define a subgroup as a triple $(H, f, p)$ where $H$ is a group, $f \colon H \to G$ and $p$ is a proof that $f$ is injective. But eventually we are doing something like "counting elements" - is this justified?
2) Even logic has changed into this new setting: proof are themselves objects of this mathematical universe. I guess I need to have something like a constructive proof to make this work out? Does it matter that I have to choose arbitrary elements $c \in C$ to find a bijection?
Sorry for the vague question: I am trying to understand what it would be like to do mathematics knowning in the back of your head that one can formalize thing into HTT, and it is not obvious to a beginner like me

REPLY [12 votes]: The answers and comments on this question show that there is still a ton of misinformation out there about HoTT.
The short answer (but much more time-consuming for you) is that you should read the HoTT Book, which was explicitly written to address this sort of question.  To address the specific questions you asked, and the points raised in the other answers:

HoTT is not a structural set theory.  Nor is it a material set theory; it is a type theory, a different kind of beast altogether.  For an explanation of the differences, see this blog post of mine.
There absolutely is a notion of subset type (or subtype).  The rules for subset types are explained in that blog post.  Subsets of a type $A$ are usually encoded as their characteristic functions $P:A \to \rm Prop$.  Given such a subset, one can always take its $\Sigma$-type $\sum_{x:A} P(x)$ which is a type with an injective function to $A$, but often it's easier and better to work directly with subsets than with such things.  Of course, when you want a subset of a group to be itself a group, you'll need to consider it as a type in its own right, and you might find it easier to formulate Lagrange's theorem in terms of an arbitrary injective group homomorphism.
Constructive logic is a red herring if what you're wondering about is what mathematics looks like in HoTT versus in ZFC.  It's true that HoTT is "by default" constructive due to its inheritance from type theory, but one can simply add the axioms of excluded middle and choice to obtain a mathematics that looks just like classical mathematics in most respects.  (If you do want to be constructive, then as others have pointed out you have to be careful about the meaning of "finite" -- but this would also be true if you were trying to use a constructive set theory like IZF, and is irrelevant to doing mathematics in HoTT+LEM+AC.)