Lean’s Dependent Type Theory
Transcript
So, yeah, this is a talk about the type theory, the axiomatic system that Lean depends on, and some properties about it. So Lean... so most of you already know this, but Lean is a open source interactive theorem prover, developed by Leonardo de Moura at Microsoft Research, and his work is also being extended here at CMU and Pitt. There is a focus on software verification and formalized mathematics - well not so much with the software verification
right now, but at least some programming and metaprogramming capabilities, in this functional programming language. Lean is based on dependent type theory, and that's going to be the main topic here. It is a classical - as opposed to intuitionistic - not a homotopy type theory based system. It's very similar to CIC, which depending on who you ask is the axiom system that Coq uses, or is some idealized version of the axiom system that Coq uses. Lean 3
also has metaprogramming facilities and an active development for the mathlib library which is developing pure mathematics and tools for programming and metaprogramming. So we start with the untyped lambda calculus. So here is a very simple display of what's happening in the lambda calculus. The top line here is saying that an expression e is either a variable, or an application - that's just the adjacency of two expressions - so we have
an expression applied to an expression, or we have a lambda, and that binds the value x inside the term e. And it has these reduction rules... so what I'm giving here are the nondeterministic reduction rules, where you just go into each application - or, you go somewhere into an application and you beta reduce. And then you apply this over and over, and you get somewhere. Or you get multiple places, or you get nowhere. And so that's basically how
reduction of the lambda calculus works in a nutshell. It was developed by Alonzo Church as a simple model of computation; this is equivalent to Turing machines in power. There is some stuff I haven't mentioned here about how exactly substitution and bound variables are defined, but the details of that are mostly the same as any other system involving bound variables. So we won't go into that right now unless someone asks. So yeah, there is a primitive notion of bound variables and substitution, and this reduction operation is the nondeterministic one. There are restrictions of this, where you can say, well, it's call by value, or it's call by name, depending on how exactly you do these reductions, but here we're just saying all the possible reductions. Reduction is confluent; so this is called the Church-Rosser theorem, it's important - we're going to come back to this later - so
if you have an expression which can reduce in zero or more steps to e1 and also to e2, then there is another term e' such that they both reduce in zero or more steps back together. So even though there might not - there might be an infinite sequence of steps going off, you can always bring two terms that have started from a common term back together. So we're going to extend this a little bit - or, we're going to add in a type system on top of this
lambda calculus. So now the main difference is that our lambdas have a type annotating the x. And the available types here - I'm just keeping it very basic - we just have function types and then some base type of individuals. And this is really - I mean we don't really need the individuals except that if we took it out then there would be no types at all and so there wouldn't be anything in the theory. We have rules here for the typing
judgment. I've left off the rules for reduction but they are exactly the same as the last slide. So here we have - this is the variable rule. This is saying that - in the context Gamma, x has the type tau, assuming that we have, in the context, that x has the type tau. So this is just the variable rule, it's just looking somewhere in the context for "x has the type tau", and then we can typecheck it there. And then this rule is for how to
check an application. So if you know that e1 is a function which has domain alpha and codomain beta and e2 is a value which has type alpha, then you can apply e1 to e2 and then you get something of type beta. And then over here we have the rule for lambda - so a lambda is a function type. It has type alpha to beta if, in the context extended with x having the type alpha, e has the type beta. So this is enough for you to be able to typecheck
some simple terms, and interestingly, unlike the untyped lambda calculus, here we have - just because we have this typing system - we get that all terms normalize. So this property is called strong normalization. There are certain terms, like the Y combinator, which I haven't written, which are - which you can write down in the untyped lambda calculus, but have no valid typing in the - in simple type theory. So they are just not available
anymore, and those terms would unfold forever if they were in the system, so this is excluding them. Okay, so now we want to go from this to dependent type theory. So the first change is - well let's say - we have this function type, and I want to say, okay, I want the first thing to depend on the second thing. So I'm going to replace that - so yeah, this is just rearranging them - but I'm going to replace the arrow type with a forall type.
And so it looks very similar, we have a forall here instead of a - and this is also called the dependent Pi - I'm going to use forall in these slides, but just treat them interchangeably. So here we have, instead of alpha -> beta we have forall x in alpha, beta, and this beta here is allowed to refer to x. And then the rule for application involves a substitution for the x's in beta. Now we can't really do that much interesting with the - with x inside
tau because tau doesn't actually have any operators to be able to put x's in there. First though, we're going to - oh yeah, so first, notice also that x has to vary over a type, tau, and one of the common applications of this is if we want to have foralls which are parametric. So if we wanted to write the parametric identity function, we might want to generalize over a variable which is actually a type. So in order to do that we need a type
of types. And so I'll call that U, and so we'll add another type U, and then we can just add rules that say, "oh yeah, all those other guys are types". So iota is a type, and this forall is a type if its parts are, and type is a type. And actually - so at this point, we don't really need to have two separate classes anymore, and this is where we actually get most of the power from, is by just folding the tau and the e together. So instead of
having a collection of terms and a collection of types, we're now just going to mush everything together, so we just have expressions, which can be terms and types, and so now it's exactly - all the rules are exactly the same as before, but now it's just one big soup of things. And so now we can talk about lambdas which have results which are types, and so this allows you to do computations at the type level. So this really gives you some extra
power. Okay. So there's two problems with this, as I've written it here. So - oh yeah, sorry, and also, we don't really need this iota anymore because we've got plenty of types now, so we're just going to drop it. So, two problems. First of all, that rule there is inconsistent. If you have - if you know that type has type type, then you can construct a slightly more complicated version of Russell's paradox in the system, and you can show that
basically all propositions are inhabited, i.e. all things are provable, that's not good. So, in order to solve that, we can break this circularity by saying okay, actually there's a whole hierarchy of universes. We have that the universe at level n is a type at universe level n+1. And then we're going to have a rule for the Pi, that says, well, if you've got two different universes, then when you make their Pi you get one in the larger of
the two. So this avoids you populating things at an unusually low level. Okay. Now that's also not quite what we want. So this is not really doing the topic justice, but I'm just going to throw up the Curry-Howard isomorphism, or the Curry-Howard correspondence, which is basically this idea that propositions act a whole lot like types, where the terms of that type are the proofs of the proposition. So the false propositions are going to be
empty types, and the provable propositions, we're going to have maybe one or more ways to inhabit those types. And so that's actually why we're using the arrow and forall symbol here, because it is actually - it acts just like what we would want material implication and the forall quantifier like in first order logic - this acts just like that. So we're actually going to have a universe of propositions. In order for things to work, we're going to
say that forall is a proposition, and that means that it has the type U0, which here I'm going to denote as P. So this is the universe of propositions. But now if you look at this rule before, I said that if you got U_m and U_n then you get the max of m and n. So if this one here is zero, then this is going to be m, and so if we take some example proposition - I haven't given all the things in order to define what even or odd means, but let's
suppose we can define this thing - this is a proposition, it's in U0 - we have natural numbers, this is a type, it lives in U1 - and so when we stick them together to form this particular proposition that says every natural number is either even or odd, then we end up with something in U1. And this isn't quite what we'd like. I mean, we want this to be some kind of proposition which is just talking - it's either true or false, we'd like to think of it that way, and so having it end up as a type seems a little bad. So we're just going to add an extra rule - we're just going to fix this rule so that instead of using max, we're going to add this weird imax function instead, which is the same thing as max, except when n = 0, it's just going to be 0. And so we're just saying, well, okay fine, in this case, it's 0. It's not 1. This is called impredicativity. It means that you can construct objects at
a high - in a high universe, and then reflect them back into this lowest universe of propositions. So this actually adds quite a lot of power to the language, axiomatically. Okay, so this is where we are at. Now we have this imax and levels of universes. And now, problem number two is that we have a convertibility issue. So we have the ability to form the type - we have the ability to form a type which is the identity function applied to
tau, and that's not the same thing as tau itself. So you can have not well typed applications, where you have a function whose domain says identity applied to tau, and you're applying it to an argument which has just type tau, and that's just not going to typecheck. We'd like to be able to typecheck those, especially when we have some kind of reduction rule like this. So the solution is just to have a convertibility judgment. We're just going to say that, if
alpha and beta are definitionally equal, then anything which has type alpha also has type beta. And that comes with a whole bunch of rules. These rules are fairly self-evident. These three are saying that convertibility is an equivalence relation - so it's reflexive on well typed terms, and it's symmetric and it's transitive. These rules are just saying that it has - these are compatibility rules. These are called compatibility rules, and
they just say that as long as all the parts are definitionally equal then so are the whole terms. And then these are the rules that actually have some content. This is the beta rule, it's exactly the same as the reduction rule from before, but now it's just being stated as a definitional equality. And this one is called the eta rule, it says that if e doesn't depend on x, then if you have a lambda applied to an application like this, this is just the same thing as e itself. So this is called the eta rule, and we also have a rule for that. So the last major feature in this axiom system are inductive types, and this is one of the more complicated features. We want to have a general mechanism for defining a bunch of new types. I'm not going to give the typing rules because they're complicated, but the syntax at least, I'm going to write it as - so K here, I call it an inductive
specification, it's really just a disjoint sum of labeled expressions, and these labels are the constructors. I have a bunch of examples here. So the natural numbers are - so read this as - this is the fixed point of the function which takes a type and is either an element of that type or an arrow from the type to itself. So zero is in the natural numbers, and successor is a function from the natural numbers to the natural numbers, and then the
natural numbers are the smallest type which has these two functions, and which is freely generated by them. I'll show how the recursors are done in a second. I just want to give some examples here of the sorts of things you can do with an inductive specification like this. So here's sort of the rest of propositional connectives. You can do exists, by defining it as an inductive type where you have a dependent introduction here, where you say well you've
got an x, and then you've got a proof that p is satisfied at x, and from that you get an element of this exists, and because it's the smallest thing you also get the ability to prove facts by cases on exists. And then "and" can be defined as one where you have an introduction which has two arguments. So you have p and q and from that you get "p and q". For "or", you can either have a p gives you a "p or q", and a q also gives you a "p or q".
Bottom, or false, is the proposition which has no constructors, and true is one which has exactly one named constructor. Each inductive type, when you write down one of these inductive types, you get the type itself, that's this mu thing, and then you also get the constructors. And so these constructors are just formed by taking those expressions there with the T and replacing T by nat. And so you get that zero is a nat and
succ is a nat -> nat. And you also get this recursor - so this is generated based on the form of this description, on the form of this inductive specfication. In this case, it's saying that if you have a dependent family over natural numbers, such that you have an element at zero and then given an element at n you can produce an element at succ n, then you get an element at C n for all n in the natural numbers. So this is really the one that's
going to give you the ability to prove that this is the smallest type which has those two, zero and successor. And this thing also comes with these so-called computation rules. These are actually reduction rules, I haven't written them like that, because these are both definitional equalities, but also reduction rules. So you can reduce this thing where you apply zero to the first argument, that will be this C zero, and then if you have
- if you apply this function - so here we have C and z and s, and then here we're applying succ n. And so this is just s which is this function here, applied to n and to the value of the recursor. So this is - this looks a lot like primitive recursion, and using this where U_i - where you replace i with 0, you end up with a rule in Prop, which is allowing you to prove things by induction on the natural numbers. So this - if you view it like that then this is just the Peano axiom of induction.
[Jeremy Avigad] So let me just remark that, so I think a lot of people are kind of comfortable with this, but are really curious about the features of lean that are - so just keep an eye on the time. [Mario] Yes... almost there. Okay, so there are some caveats on exactly what specifications are allowed. So an inductive declaration has to be strictly positive, which basically means that you don't have this T appearing on the left side of a left side of one of these arrows. An example of where
you can get into trouble if you don't have a rule like that is this "bad" definition here. If this thing were allowed, then you would end up with a function, an injective function from the powerset of bad, or bad -> 2 here, to bad, which would be a violation of Cantor's theorem. So since you can prove Cantor's theorem you would be able to get a contradiction from this. Inductive families are also allowed. This is how equality is defined. You just have - given an x, you can define equality to be the least type which is inhabited at x only. So you end up with a constructor refl, which says that x is equal to x, and then this recursor for eq is just saying that - this is just the substitution property for equality. If x is equal to y, and C holds of x then C holds of y. Proof irrelevance is this idea that if we have two proofs, two elements of this
lowest universe, then they are just definitionally equal. This has some interesting consequences. One of the things is that this an anti-HoTT axiom; this is in contradiction to univalence. So we can't do HoTT with this. But it also means that propositions are going to actually have restrictions on them. When you create an inductive type which lies in Prop, and which has many ways for it to be inhabited, then there is going to be a restriction on the recursor that says you can only eliminate this
into the lowest universe - into propositions. So this would be called a small eliminating type. [Karl Crary] So you said that this is in contradiction to univalence. Is it actually in contradiction, or does it just lead to a degenerate type theory? [Mario] If you assume univalence you can prove that there are types which have more than one inhabitant for their equality - more than one, unequal inhabitant. So it is in contradiction to axiom K, or to proof irrelevance, or definitional proof irrelevance. [Jeremy Avigad] So if you have univalence then you can derive false. [Mario] Yes.
[Carlo Angiuli] Are bold P and U0 exactly the same? [Mario] Yes. The other interesting property is that there is an out, here. There is a way for propositions, things that are lying - inductive types that have been defined to be in the lowest universe U0 - that they will still be able to eliminate to higher universes. The short description of when that will happen is if they have all of their non-recursive arguments, the ones that don't end in T - those all have to be propositions, or else they have to somehow appear in the final type.
I didn't want to write that condition because it's a little complicated to state, but when it does happen, then you get what's called a subsingleton eliminating type. So for instance, eq here - this is actually a subsingleton eliminating type. You can recurse eq into any universe even though it's a Prop. And so, the actual axioms; by actual axioms here I mean these are just objects that are added to the language and they have no interpretation,
they are just things that are inhabiting various types. Propositional extensionality is saying that if p and q are - if p if and only if q, meaning that p implies q, or - there is an inhabitant of p -> q and also an inhabitant of q -> p, then p and q are actually equal, which means you can substitute for them in all contexts. This is kind of a weak version of univalence at the lowest universe. Quotient types - I'm not going to deal with them
too much, but they are given by - you have a mk and a lift and a rule - this looks a lot like an inductive rule except it's not freely generated, it's generated up to this relation r. And then you can inhabit it when you know that functions preserve the relation r. And then the axiom of choice, well you just - so you can define this nonempty here to be just an element of Prop which is - this is the least element of Prop which is inhabited when alpha
is inhabited. And choice is just saying you can go the other way around. If you have an element of nonempty alpha, then you can element of alpha. This has no computational interpretation, this is just a thing which allows you to do classical mathematics. From this you can get the law of excluded middle, so with this it's really a fully classical logic. [Karl Crary] I'm sorry, but I don't understand the definition of nonempty here at all. [Mario] Nonempty is - so in lean we would write this as...
So this thing is a Prop, which is given a single constructor which says that if you have an element of alpha then you have an element of nonempty alpha. So this looks sort of looks like an identity... [Karl Crary] So shouldn't it say intro : alpha -> T? [Mario] Oh dear. I'm sorry, yes you're right. Yeah, that's a typo, it should be alpha -> T. [Carlo Angiuli] Is this different from the quotient of alpha by the total relation?
[Karl Crary] Yeah because that doesn't tell you that it's nonempty. [Mario] It is. The quotient is not in U0. The quotient is not a Prop. Mathlib actually has both definitions; there is nonempty and then there is trunc - the quotient by the total relation is called trunc, and it is just like propositional truncation. And it doesn't lose information - it doesn't put you into this world where all proofs are definitionally equal, and that makes a big difference. So the fact that choice is saying, oh we can get out of that, that's what really breaks the computational interpretation. So, one of the unusual consequences of all these axioms put together is undecidability of the type system. This is a bit of a disappointment for a type theorist, but basically the type judgment is almost decidable, but there is a way in which they can interact, and so let
me try to sketch this situation. Consider this inductive type acc. This is defined as - well, basically, if everything less than x is accessible then x is accessible. It's inductively generated by that clause right there. This is basically saying that it's well founded - the type is well founded... if everything is accessible in this sense, then the type is well founded. In general we're just talking about things which can
be reached from the bottom by things which are "smaller", according to this relation less-than. Importantly, this thing is a subsingleton eliminator. The rules of lean say that because this thing has - this guy here is a recursive argument; this one is not a recursive - this forall x, this is x in alpha - this is not a recursive argument, but it appears over here in the target type and so it's okay, so this whole thing is a subsingleton eliminating type and
so when you ask lean, "what's the recursor?", it will say "this is a recursor which eliminates into any type", even though this thing is a Prop. Now, there is only one constructor, and you can invert that constructor in the sense than if you have an element proving that "acc of x", then you can construct a function "inv x" which takes "acc x" and a "y" less than "acc x" and proves that y is accessible; and this will be in such a way
that if you apply inv - just as a result of the type of it - "inv a" is of the right type to have - to be applied to "intro x", and this thing is definitionally equal to "a" because this is a proof - it is an element of a proposition, namely "acc x". So those two are definitionally equal. And that basically means that we can use it to do reductions repeatedly without having to pay for it. Let me see if I can explain this. So let's suppose that we have
a decidable proposition P for which forall n, P n is not decidable. There are plenty of examples of this, like - a Turing machine doesn't halt after n steps. You can decide whether it halts or not after n steps, but you can't decide whether that's true for all n, at least not for some choices of machine. And suppose that we know that 0 is *greater than* accessible. So that's saying that 0 is accessible from above by the greater than relation. This is not true.
But we can put it in our context anyway. We can just suppose that it is true; we can derive false, but we can also derive some other things. So we're going to define a function by recursion on acc_> x. We can define a function for which it reduces in the following way: If you apply it to "n" and to "h" you can replace this "h" with an intro of inv of h, like on the previous slide, and then we can set it up so that it reduces
to this expression here. So we'll say, well, if P is true, then we're going to evaluate f at n+1. And then this is some proof, it doesn't really matter. Otherwise it's going to be zero. So this thing will reduce to zero if P is false, but if P is true then it's going to reduce to the next value. So you can see that this - if we just pump this, it will reduce to - like if we start at zero, it's going to find out whether P is true, and if
it is, then it is going to try the next value, and if it is true, it's going to try the next value, and if at any point it finds that P is not true, then it's going to reduce to zero. So this is really emulating - we're just stepping up the natural numbers, and we're trying this function f on all of the natural numbers. So you end up showing that under this context h0, this inconsistent context, we have that this thing is definitionally equal to zero
iff forall n, P n, which is exactly the nondecidable proposition. [Karl Crary] You have that backwards, right? It's definitionally equal to zero iff there exists some n where P n is false. [Mario] Oh, yes. Okay. Yes, just replace true with false. [Karl Crary] Well you need an exists rather than a forall. [Mario] If (forall n, P n) is false. [Karl Crary] If exists n, (P n is false). Oh, I see, I'm parsing it differently. [Mario] If not (forall n, P n).
Or maybe I'll just draw a line over here. Another thing which I want to mention is that you might say, well, kind of you're cheating, I mean, what's up with this inconsistent context here? Who cares about false contexts? Well what we can actually do is just lambda-abstract both sides; we'll say, lambda h0 : acc 0, f 0 h = lambda h0 : acc 0, 0, and those will be definitionally equal iff this is definitionally equal.
So even though those are two empty functions, and we should be able to treat them as equal and we can prove that they are equal, without the definitional equality, just regular equal; but they are definitionally equal if and only if this nondecidable proposition holds. So that's that. Of course lean can't evaluate nondecidable propositions... It does purport to evaluate this typing judgment, so what's it doing? Well, it does something else.
It does - so we can introduce some new judgments just to say "you know, that thing that lean does", that isn't quite what I just said - and that will be an underapproximation of the actual typing rules. So the algorithmic typing judgment is sometimes going to say this thing is not well typed even though it really is, you know, if lean worked out that Turing machine to ten steps it would find out that it is, but it's not going to bother with that. So
in this example, it will just say, no I don't believe you. It's not going to bother evaluating that Turing machine. It's just going to say no, they are not definitionally equal. So there are times when it will get the wrong answer from an ideal perspective. As a result, you can get that it can't be transitive. If it were transitive, then you would be able to recover the original thing. So the actual definitional equality, this weird example
manifests itself in lean as nontransitivity of this definitional equality relation. In practice this is a really weird combination of features which no one ever deals with. If it ever comes up, you can always insert identity functions in order to hide the nontransitivity. So if you want to get lean to see where that transitivity path is, you can just insert identity functions at different types, and then lean will be forced to figure out smaller steps rather than trying to jump the big step.
[Karl Crary] Does that actually work in practice though, since you don't have reduction, so you might be able to find the term but you probably you couldn't use it? [Mario] So you can always write - I want to say e has type gamma, but it actually has type alpha, and I want lean to know that it has type gamma, but it can't prove that alpha is definitionally equal to gamma, so I'll just add in "id gamma (id beta e)", you know, insert enough insert enough identity functions of different kinds
that lean will be like "oh, I see where you're going with this" - it can figure out the smaller steps where it can't figure out the big step because it's not transitive. [Karl Crary] So my question is, since you can't reduce one of those ids, right? [Mario] Yeah. So if they reduce, that property that reduction preserves typing is called subject reduction, and lean doesn't have it. [Karl Crary] So my question is, since I can't reduce those ids, don't they serve as basically like a blocker? [Mario] Yes. [Karl Crary] that's going to keep us from using this term effectively as an element of gamma. [Mario] Well, so you can use it, you just have to unfold it carefully, basically. As long as you control the ways in which you are unfolding it you'll be okay. In practice, I think we would just settle for having a regular equality at some point, because those tend to be a lot more stable...
like you can just not worry about how that's been proven, you just have a regular equality, and then it's not a definitional equality; you don't have to worry about the definitional equality unfolding. So that's usually what people do when it starts getting flaky. [Karl Crary] So I don't know lean, but my experience with Coq is that when you fall to using Leibniz equality instead of definitional equality, then you are in a world of hurt. Because dependent types don't work right anymore. [Mario] ...Yes. So I have a slightly different perspective on that, which is that dependent types put you in a world of hurt, and if you can just use regular equalities everywhere and stay in simple types, then you'll be fine. So yeah. There are a lot of things I could say about that will probably take us off topic, but yeah, this is a major practical sticking point. You do have to deal with definitional equalities,
especially when you are dealing with certain kinds of dependent types, and those can cause lots of issues. So I actually would try to avoid definitional - relying on definitional equality when possible. Alright. So lean has a sort of obvious model of types as sets and elements of those types as elements of the sets. So we can write down a particular interpretation function where we just say when you've got these foralls, these are function types.
And we're just going to interpret that as a dependent function. ZFC has the ability to say you've got a function, it's a set of ordered pairs, and then its domain is exactly alpha, and at x it's going to be beta at x. So you just have these dependent function types in ZFC, and you can write down what a dependent function is, and you're going to interpret universes as very large types. So the lowest universe is - because of the axiom of choice we have
the law of excluded middle, we have proof irrelevance and all these things - we're basically forced to have Prop look like that. So there's just two propositions; one of them is the empty set, which is false, and the other one is a singleton set which contains this little thing I call the proof object, which is representing true. And the proof of true. For the larger universes, we end up with these very large - so they have to be Grothendieck universes
because they are closed under inductive types of various kinds, and also function types, and all this. So they basically have to be inaccessible cardinals. So if you assume there are n inaccessible cardinals, then we can define this thing; if we assume there are omega inaccessible cardinals then we can define all of them. But it's useful to consider the case where we just have n of them, and then we end up with this. So the soundness theorem
is this. The main part is, if e has type alpha, then you have elementhood of the mapping, and if you have a definitional equality then that turns into a regular equality in the mapping. So lean is consistent. I'm going to mention the overview of unique typing but not the proof. Unique typing is this property here; we actually need it in order to prove the well definedness of that model - or, of the mapping - so we need to know that there
is a particular universe that every type lives in. And it doesn't live in any other universes. So that is to say that if you can derive that alpha has type U_n then it doesn't also have universe m where m is something else. So that boils down to this theorem, the unique typing theorem, which says that if e has two different types, then they are definitionally equal; and then you combine this and this rule here about inversion of definitions to say, ah,
so m is equal to n. And so there's only one universe that this term can live in. This is a little bit interesting in light of the undecidability results that you can prove much at all about this typing relation, but you can actually prove this unique typing theorem, even in inconsistent contexts. This is false in Coq because of universe cumulativity. There is possibly some analogous statement; I'm not sure exactly what that is,
it would be quite difficult to state, I think. You can have universes switch around, and because of that they aren't actually definitionally equal anymore, they are like - there is some subtyping relation. So it gets more complicated in Coq, because of cumulativity. But this is true in Lean because we don't have cumulativity. And, yeah I'm going to skip the Church-Rosser theorem. So... I do want to talk about what's not here. I'd like to extend this a little bit,
to show some concrete unprovability results. For instance, that thing with the double equals, I didn't talk about that but that's called heterogeneous equality, and one I guess folklore result is that heterogeneous equality is not - you can't prove that application preserves heterogeneous equality. Also, equality of types - you can almost never prove that two types are not equal. So for instance you can't prove that int and nat are not equal to each other.
Or even nat and nat' which is exactly identical to nat, where you just write down exactly the same constructors... you cannot prove that those two are not equal. You can prove that they are isomorphic but that's the best that you can get. The only thing that you can do to really distinguish - prove that two types are not equal is cardinality, because if two types are equal then they have to have the same cardinality. But that's about it.
Another interesting topic is what the VM does - the virtual machine of lean will perform some sequence of evaluations which kind of sidesteps a lot of the issues with the reduction relation that I've talked about. So when you have casts from one type to another lean is just going to ignore those. It's not going to evaluate the recursor down to a refl - it just - it doesn't care. So it starts working through terms that are actually not
well typed in the course of evaluation, and yet at some - when it gets to the end it somehow gets the right result. It doesn't go wrong. So there's something interesting to show there. There's this concept of a type erasure map where you just take out all the types and it's going to preserve the result of your computation. If we did have something like that, one application would be a good theory for being able to show when a VM override
is valid, which is a recent topic which we've been discussing - the ability to take one definition and replace it with another one in the VM. And then being able to do that without breaking the results of the reductions would be very important. So having a good theory for that would be very useful. Strong normalization is another... I mean, calling it folklore is, I don't know. But Coq has various proofs of strong normalization of
some subsystems of it. So I'd really like to have the full theory, all together, strong normalization. I'm pretty sure that with the algorithmic reduction, it is strongly normalizing, because it stops before it gets into the weird stuff. And then, yeah, well this is a formal theorem prover, so this stuff should all be formalized. Okay. [Applause] [Jeremy Avigad] The practice with these things is to usually start with the committee member who comes from the furthest distance. All the way across the town. [Tom Hales] Okay. How long do I have?
So your answer to the undecidability of definitional equality is another thing. Is it conceivable that there would be a more complicated way in which subsingleton elimination [INAUDIBLE]? [Mario] Well, for the proof here I use a different reduction, this kappa reduction, which - one of its interesting properties is that it will actually do reductions even in that case where I showed. When you take one of these acc rec terms, it will reduce it like this.
So it will reduce it even though it hasn't been given any fuel to work with. And because this thing actually contains a subterm of itself, this is going to run off. This is going to - in that Turing machine example this really will evaluate all the steps, and so it's not a decision procedure, it's a semi-decision procedure. So you can just run this thing, and then if they are definitionally equal it will find it eventually. And that's about the best you can say with these sorts of things; because it is not a decidable relation, you can't have both decidability and transitivity, or you know - one of these other rules is going to break. You cannot have all of the rules, because all of the rules together are not decidable. So if you want to have an underapproximation, then you've got to give up one of the rules, or, you live with a semi-decision procedure instead. And I think that in practice that wouldn't be so bad. I mean, having people sit at a prompt while the thing is humming
and then eventually times out, I think that would be fine for the purpose of definitional equality, especially because usually people write down proof terms that are actually correct - like they've only put the terms into the big file because it's actually going to work, so we should feel comfortable just running them until they actually succeed, and that is just as good of a proof. So I would be comfortable with having a reduction which is more like this one, where it just does - it does all the stuff, and it might not halt, but at least as long as you are giving it good proofs, then it will halt. [Jeremy Avigad] But if I can interrupt, just going in the other way, say look, I'm absolutely committed, I want to be decidable. So then, coming from that direction, what's the best you can do? [Mario] I think it would be best to eliminate subsingleton elimination.
[Tom Hales] And that's an all or nothing thing? [Jeremy Avigad] Even for equality? [Mario] Yes, that has some, some consequences. It might actually be recoverable in the case of equality. So you might be able to restrict subsingleton elimination to things that look like acc. There are certain conditions that you can say about - like equality is not recursive, for instance. Acc is recursive. And that's part of what makes this engine go, the fact that it is recursive, and it's just going to keep unfolding and unfolding. If it could only do that one step, then it would be okay. So maybe you can just say - you could restrict you rules on subsingleton elimination to say, no you don't get subsingleton elimination unless you're not recursive at all. And then acc would be not subsingleton eliminating. And that would affect some proofs, like your well-foundedness proofs would not be proofs anymore,
they would be regular types. And that might affect some stuff. So I think that as far as "damage to the ecosystem" I think that would be the least painful way to do it and recover decidability, which I think is important. [Tom Hales] So a related question. As I understand it, you need that to get unique typing. Is that minimal? [Mario] You need definitional equality? To get unique typing. Well if you don't have definitional equality, you still get unique typing, it becomes equality, right.

Ask anything
We've read this whole study set, so questions about it get the best answers.