In what respect are univalent foundations "better" than set theory?
I like your analogy with programming languages. If we think of ST as a low-level programming language and UF as a high-level one, then one advantage of UF is obvious: it is more convenient to write proofs (programs) in a high-level language. It is feasible to write proofs in UF, but it's virtually impossible to write down even statements of theorems in plain ST. This argument shows that UF is more convenient in practice than ST (well, I didn't give any proofs of this statement, but they can be found somewhere else, see this question and this list for example), but your question is about foundations and not about practice, so let me address this aspect.
Let me give two reasons why UF may be better as a foundation of mathematics than ST. The first reason is that all the constructions in homotopy type theory are stable under isomorphism, so if you prove a property of (let's say) a group, then this property is true for any isomorphic group. This is not true in ST and this problem is usually swept under the carpet. Another argument is that the category theory in UF is more well-behaved. For example, we have the concept of anafunctors in ST, but we don't need them in UF since they coincide with ordinary functors for univalent categories.
Finally, let's discuss the problem that UF is more complicated than ST. I claim that it's not actually true: ST isn't much smaller than UF. ZFC has (about) 10 axioms, but it is based on the formalism of first-order logic which has quite a few rules too. A types theory combines the rules of the logic and axioms of a set theory into one system (which, I think, is more elegant, but it's a matter of taste I guess). To prove that the number of constructions of a type theory is roughly the same as FOL+ZFC, let me just list some of them. On the left we have a type theoretic construction and on the right I write a FOL+ZFC construction which is analogous or similar (this correspondence is very informal and isn't precise).
- Sigma types / Existential quantifier, Axiom of union
- Pi types / Universal quantifier, Axiom of power set
- Sum types / Disjunctions, Axiom of pairing
- Identity types / Equality
- Natural numbers types / Axiom of infinity
- Universes / Large cardinals
- Univalence axiom (for propositions) / Axiom of extensionality
I could continue this list, but this relationship isn't precise, so let me stop here. You can see that some type theoretic constructions correspond to two different constructions on the FOL+ZFC side. This is because the logic and the set theory are fused together in TT, propositions are just a special kind of type. So one construction in TT may correspond to two constructions in FOL+ZFC. Thus the basic (homotopy) type theory has less constructions than FOL+ZFC. You can extends TT with other constructions such as (higher) inductive types, but you don't have to. The basic version of TT with the axiom of choice is roughly equivalent to ZFC (this statement can be made precise, but that's beside the point). So you get an equivalent theory with less constructions and (arguably) more elegant presentation. Moreover, you can get not only a set theory, but also a theory of homotopy types almost for free, you just need to add a very simple extension (universes + the univalence axiom).
This is a question that has been discussed a lot on the Foundations of Mathematics mailing list (unfortunately with more polemics than necessary IMO—though I confess that I may have been guilty of stoking the flames somewhat because I love to watch a good argument!).
My feeling is that to ask whether univalent foundations or set theory is the "better foundation for mathematics" is to start off on the wrong foot. Phrasing the question that way seems to take for granted that we know (1) what a "foundation for mathematics" is, (2) what makes a foundation good, and (3) that if we choose Foundation 1 instead of Foundation 2 then it will be because Foundation 1 is "better." I don't think that any of these should be taken for granted. There are multiple axes along which one may evaluate the quality of a proposed foundation for mathematics.
I think that it is better to start off by asking what UF is and what it is good for. Probably the most important point to recognize is that homotopy theory (or large chunks of it at least) turn out to be very naturally formalized in type theory, and much less naturally formalized in traditional set-theoretic foundations. Let me quote an FOM post by Urs Schreiber:
It had been mentioned here before that homotopy type theory offers some advantages for formal set-based mathematics, such as providing quotient types and isomorphism invariance. What seems not to have been mentioned much before here is that the key point of homotopy type theory however is that it goes way beyond this in that it provides a native (i.e. direct, synthetic, see below) formalization not just of constructive set theory, but of homotopy theory (aka algebraic topology). And the neat thing is: of homotopy theory in its modern and most powerful incarnation in the guise of infinity-toposes.
Just like plain dependent type theory is the internal language of locally cartesian closed categories, so homotopy type theory is the internal language of locally cartesian closed infinity-categories, and homotopy type theory with univalent type universes is the internal language of infinity-toposes. This means that homotopy type theory provides a "structural" foundation of the kind that William Lawvere had found in topos theory, but refined to homotopy theory in the refined guise of infinity-topos theory.
The fact that homotopy theory and type theory are so well-adapted to each other is a non-trivial insight. From a traditional set-theoretic point of view, homotopy theory at first glance requires slightly more than ZFC, because it invokes Grothendieck universes. However, it turns out that the core of the subject requires much less logical strength than that. Again let me quote someone, this time Neel Krishnaswami:
Voevodsky is coming to type theory from the point of view of a homotopy theorist. The traditional set-theoretic formulations of that subject make use of Grothendieck universes, and so go beyond ZFC. However, the big discovery of his univalent foundations project is that homotopy theory has a natural formalization in Martin-Lof type theory, which has the proof-theoretic strength of Kripke-Platek set theory (ie, vastly less than ZF). (IIRC, Anton Setzer has written a survey paper on this, "Proof Theory of Martin-Lof Type Theory: an Overview".)
Generally, it's no surprise when a theorem can be encoded in a weaker foundations, but the real shocker behind homotopy type theory is that a suitable type-theoretic view seemingly requires fewer encoding tricks than the traditional view. The apparent need for large constructions vanishes because the type structure of type theory prevents you from performing constructions which are okay on points but which fail to respect geometrical invariants like continuity. As a result, you can now talk about plain old functions instead of natural transformations on sheaf categories or whatever.
One practical consequence of this is that large chunks of homotopy theory can be (and have been) readily formalized using a proof assistant that is designed with UF in mind. Indeed it is impressive how much cutting-edge homotopy theory has been actually mechanically formalized; I'm not sure that any other subfield of mathematics can compete in this regard.
Now, one can counter (and some have countered) that formalizing the Blake-Massey theorem—or other important theorems in homotopy type theory that have been touted as successes for UF-based proof assistants—can be done with only a modest amount of additional effort using other type-theoretic proof assistants or even set-theoretic proof assistants. One can also counter that the theorem that is being proved in UF is not literally the same theorem that we would get by expanding all the definitions in a traditional set-theoretic manner, and so it's "cheating" to gloss over the work needed to show that the type-theoretic formulation and the set-theoretic formulation are essentially equivalent. These objections are technically correct, but I think that they obscure the important point that homotopy theory and UF really are an extremely natural fit.
Things get more interesting when we ask whether UF is well-suited to other areas of mathematics besides homotopy theory. In principle, UF is powerful and flexible enough to formalize most if not all of mathematics. The question is, why would you want to? There are a couple of possible reasons.
It could be that formalizing mathematics with a UF-based proof assistant is a lot easier and more natural than in any other proof assistant. Outside of homotopy theory, I think that the jury is still out on this one. Type-theoretic proof assistants such as Coq, HOL Light, and Isabelle do seem to have gained the upper hand over Mizar (probably the most significant proof assistant based on set theory), though it's unclear to me whether this is due to intrinsic advantages of type theory over set theory. But would a UF-based proof assistant have made it significantly easier to formalize the four-color theorem or Feit–Thompson? As I said, I think it's too early to make a definitive judgment.
It could be that UF provides a better conceptual foundation for all of mathematics than set theory does. The jury may still be out on this one too, but in my opinion it is doubtful that UF will ever completely supplant set theory in this regard. In a sense, the question is something of an academic one. Arguably the most important question in the foundations of mathematics is whether all of mathematics can be put on a common foundation in a simple and rigorous manner, and that question has already been answered affirmatively, by set theory. Once the job has been done, it is much less difficult to see how to use some other approach to unify all of mathematics, because we can always piggy-back on set theory. One can make aesthetic arguments for some other foundation, but it will be hard to escape the feeling that the choice of foundation is a matter of personal taste.
To summarize: UF does seem to be the "right" foundation for homotopy theory, although to appreciate this fact fully, you might need to learn quite a bit of homotopy theory. Whether UF is the "right" foundation for a broader swath of mathematics than that—well, my personal feeling is that we should adopt a "wait-and-see" approach and keep an open mind.
The two main things I find compelling about type theory as a foundation are:
- A more direct way to deal with $\infty$-groupoids.
- A closer match to how mathematicians actually talk about mathematics.
Timothy Chow's answer touches on point 1, so let me just add that personally I had a lot of trouble understanding and dealing with set theoretic definitions of $\infty$-groupoids, and find the HoTT definition natural and easy to work with.
The second one I think is pretty important. If you ask an actual mathematician whether 5 is an element of 7 or what the intersection of the Monster group and the real numbers is, they'll tell you "that question doesn't make sense!" But in set theoretic foundations those kinds of questions do make sense and have answers! In type theory the answer is "that doesn't type check," which is the slightly formal version of "that doesn't even make sense."
This sort of "type checking" is really important practically! It's like dimensional analysis and often quickly tells you when a formula is wrong or gives you a good guess as to what could possibly be true.
Even for really simple things like the set theoretic definitions of particular natural numbers, of ordered pairs, and of functions, the answer that set theory gives is not at all like the typical mathematicians intuition. But the type theoretic definitions do closely match my intuition. An ordered pair is a new type of thing and you're allowed to make an ordered pair by telling me the first entry and the second entry. A function is a new type of thing and if you tell me something in the source it tells you something in the target.