I am still wondering what it means that a term of the equality type eq
in COQ can be different from eq_refl
.
Is the following term an example for this?
((fun x:nat => eq_refl x) 2).
This term is syntactically different from eq_refl
, but nevertheless it computes to eq_refl
.
Does there exist examples of terms which do not compute to eq_refl
?
P.S. Its not a homework question ;-)
As you point out,
(fun x => eq_refl x) 2
is not actually different fromeq_refl 2
, since both expressions compute to the same thing.Answering your second question is a bit delicate, because it can be interpreted in many different ways. Here's one possibility (which I think is the one you had in mind):
I believe that the answer to this question is no. It should be possible to prove it formally by arguing that, since Coq's theory is strongly normalizing,
e
must have a normal forme'
, and that all normal forms that have typeeq
must beeq_refl
.Note that, if drop the requirement that
e
is typed in the empty context, this does not hold anymore. For instance, consider the proof term offorall n, n + 0 = n
.In the successor branch, we use the
match
to produce a proof ofS (n' + 0) = S n'
which does not compute toeq_refl
. This happens because thematch
cannot reduce theplus_n_0 n'
term, since it's a function applied to a variable. However, if we applyplus_n_0
to any concrete natural number (say,1729
), the resulting proof will compute toeq_refl 1729
(try it!).Another thing worth pointing out is that, when arguing that every closed proof of equality computes to
eq_refl
, we had to reason outside of Coq's logic, appealing to a normalization argument that we cannot phrase as a Coq proposition: note that, because Coq identifies terms up to convertibility, there's no way of writing a propositionP : nat -> Prop
such thatP n
holds if and only ifn
is a Coq term in normal form.Given this fact, you may wonder if there's anyway of establishing that result inside Coq's logic; that is,
or, paraphrased in English, "every proof of equality is equal to
eq_refl
". As it turns out, this statement is independent of Coq's logic, which means that it cannot be proved nor disproved within Coq itself.It may seem at first that this contradicts what I said earlier. But recall that we can always add new axioms to Coq's logic if they don't contradict results that can be proved inside the logic. This means that it is perfectly fine to assume that there exists some type
T
, some termx : T
, and some proofe
ofx = x
such thate <> eq_refl x
. If we added this axiom, then the argument I gave earlier would no longer apply, since there would be normal forms of equality proofs that would be syntactically different fromeq_refl
(namely,e
).The fact that we cannot establish this result inside Coq's logic (and similar formal systems, such as Martin-Löf's type theory) is exactly what enables homotopy type theory. HoTT postulates the existence of the univalence axiom, which allows one to produce provably different proofs of equality.
Edit It is important to remember that there are two notions of equality in Coq: definitional equality (i.e., terms that are equal by simplification) and propositional equality (i.e., terms that we can relate by
=
). Definitionally equal terms are interchangeable for Coq, whereas propositionally equal terms must be exchanged with an explicit rewriting step (or using thematch
statement, as seen above).I was a bit lax in the discussion above about the difference between these two variants. There are cases where proofs of equality are propositionally equal even if they aren't so definitionally. For instance, consider the following alternate proof of reflexivity for
nat
:The term
eq_refl_nat
is not definitionally equal toeq_refl
: we cannot obtaineq_refl
fromeq_refl_nat
just by simplification. However, both are propositionally equal: as it turns out, fornat
, it is possible to show thatforall n (e : n = n), e = eq_refl
. (As I mentioned above, this cannot be shown for arbitrary Coq types.)