Chapter 5 Equality and Object-Level Unification
5.1.4 equality for sequences
The reason for adopting rather than
when working with dependent types can be seen clearly when we attempt to extend the notion of equality to cover not just two terms in a type but two sequences of terms in a telescope. Suppose we have ^
^ D ^ ù for some ^ -telescope ^ ù
. We may not, in general, state the equality of sequences^
and^ as LK7·EKPx1<MNÚM*x J7J7J ( Ð ) since<M D ù M*EK while<M D ù M]EK
, and these may be different.
There is, of course, nothing to stop us writing
LK EKx1M <MMx J7J7J
which will henceforth be abbreviated as the telescopic equation^
^
.
We may correspondingly abbreviate the sequence of reflexivity proofs
> LK }xF > <Mx J7J7J
by >
.
Let us not stop at that: in fact, we may prove substitutivity and uniqueness for tele- scopic equations.
CONSTRUCTION: telescopic substitution
For each natural number O , we may derive
a substitution principle for telescopic equa- tions of lengthO .
The reduction behaviour will be as follows:
>;)(c¥ £ =Bh ³ CÄD ^ ù LMNPORQ C ^ E ^ D ^ ù J E ^ D ^ ^ J C ^ >;)(c¥ £ =?h ³ ^ ù ^ C {,B! ^ : > ^ ]K {,&
The construction is by recursion on O , effectively iterating>;4§pfg¨ .
The zero case is proved by the polymorphic identity func- tion. Clearly the reduction behaviour is correct.
>;)(c¥ £ =?h ® CÄD LMNPOQ C C
Now, assuming we have al- ready constructed >;)(c¥ £ =Bh ³ , let us construct>;*(c¥ £ =?h ³<P K . >;*(c¥ £ =?h ³P K CrD ù x ^ ù LMNPOQ C cx ^ E cx ^ D ù x ^ ù J E x ^ D cx ^ cx ^ J C cx ^ Fixingù x ^ ù ,cx ^ ,C
and the proof ofC x
^
, we
have the goal shown. XRQ·ñ?S'T
DVE cx ^ D ù x ^ ù E x ^ D x ^ x ^ C ¬x ^ Now, is a proof that
, where both have type
ù
, hence we may elimi- nate
by>;A§fg¨ . The generated scheme includes all the
^ and^ : Y D ù JFY D J E ^ D ^ ù J E ^ D ^ ^ J C cx ^
Note that, as nothing depends on
, the proof relevance of >;A§fg¨ is not
necessary for this construction, just as in the construction ofg*(c¥
£
=?h from gA§fg¨ .
The elimination leaves with the subgoal shown. Note that ù x ^ ù is just VU}p ^ ù , which is exactly the telescope of^
. X<W ¹ ð Q·ñXS'T DVEj^ D ù x ^ ù E ^ D^ ^ C x ^ Now that ^ and^
have the same telescope, we may eliminate the remaining
^ by>;)(c¥ £ =Bh ³
: the scheme is just
C
. This leaves us with the subgoal
C
x
^
, a proof of which we fixed in the context.
From the Y-reduction associated with >;4§pfg¨ and then the inductive hy-
pothesis, we may deduce that
>;)(c¥ £ =?h ³P K ù x ^ ù cx ^ C { cx ^ : > *}xF > ^ F >;A§fg¨ ù : J7JMJ >;*(c¥ £ =?h ³ J7J7J : > ] JMJ7J >;)(c¥ £ =?h ³ ù x ^ ù ] ^ : C ] {, ^ : > ^ FR {
Observe that the same proof structure also yields substitutivity in the other direction.
Although the roles of ^
and ^
are reversed, we may still fix the ^
and abstract over the ^
(the right hand sides) as required by
>;A§fg¨ . >;)(c¥ £ =Bh[Z]\ ³ CÄD ^ ù LMNPORQ C^ E ^ D ^ ù J E ^ D ^ ^ J C ^
CONSTRUCTION: telescopic uniqueness
For each natural number O , we may derive a
substitution principle for telescopic equations of lengthO .
The reduction behaviour will be as follows:
>;):yg;A¥y> ³ CÄD ^ Ã2 ^ æ LMNPORQ C > ^ à E ^ D ^ ÃI ^ à J C ^ >;):yg;4¥¦> ³ ^ ù ^ C {,& ^ : > ^ Fª {&
This construction also proceeds by recursion onO , again with polymorphic
identity as the base case. The step case is slightly more subtle than for
>;)(c¥
£
=Bh.
Suppose we have already constructed >;*:yg;A¥y>
³ : let us construct >;):yg;A¥y> ³<P K .
This time we fix everything except the proofs of the equations. X<Q·ñXS'T D}E x ^ D Ã x ^ ÃIÅÃ x ^ Ã C cx ^
We have little choice but to eliminate
with>;4§pfg¨ . Perforce, this intro-
duces equational constraints in the scheme:
Y D ù JFY D C D ÃI J E cx ^ D Ã x ^ Ã2ÉÃ x ^ Ã J Î ÅÃ D C ] C x ^
Neither of these constraints is disposable, since
definitely occurs in the goal, and, in general, we may expectà to occur (implicitly) in the types of
the^
.
Consequently, the subgoal we get is as shown.
We may discard ^C
, then eliminate _ with
>;)(c¥ £ =Bh K . X<W ¹ ð Q·ñXS'T DVE x ^ D à x ^ ÃI¸Ã x ^ à E C D ÃIÉà E _ D >ÙÃ2 C x ^
Now we are ready to appeal to
>;):yg;A¥y> ³ , with scheme C >ºÃ . XRW ¹ ð Q·ñXS'T DVE ^ D ^ ÃI ^ à C >ºÃ }x ^
This turns the remaining ^
into > ^ Ã
, so that the fixed proof ofC
>ÙÃ
completes our obligations.
As far as the reduction behaviour is concerned, forgive me if I omit the de- tail. The construction successively applies elimination rules for equations which reduce to their single subgoals when those equations are instantiated with reflexivity. Consequently, each>;):yg;A¥y>
³
inherits this behaviour.
It is not impossible to build a notion of telescopic equality with substitution using
, but it is considerably more cumbersome. The method forces each equation to typecheck, by explicit appeal to the substitution operator for the prefixed equations. That is, we need the first O operators in order to formulate a telescopic equation of length Oa`
b
, let alone establish its own substitutivity. Furthermore, in order to make the step in the construction, it is not sufficient simply to substitute for the first equation with
g)(c¥
£
=?h, but rather we must eliminate it withgA§pfg¨ , not only substituting the terms,
but also instantiating the proof with reflexivity, allowing the substitutions repairing the remainder of the equations to reduce. By adopting , we achieve at least this telescopic