• No results found

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 „EKx1M „<MMx J7J7J

which will henceforth be abbreviated as the telescopic equation^



^

„

.

We may correspondingly abbreviate the sequence of reflexivity proofs

™ > LK Ÿ}xF™ > <MŸx 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 LMNPOQ C C

Now, assuming we have al- ready constructed >;)(c¥ £ =Bh ³ , let us construct>;*(c¥ £ =?h ³<P K . >;*(c¥ £ =?h ³P K CrD ù x ^ ù ƒ LMNPOQ 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 ]Ÿ {, ^ :™ > ^ FŸR  {

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