de - macs.hw.ac.ukfairouz/forest/talks/talks2001/talkppdp2001.pdf · a ew f uses of generalised...

27

Upload: ngoquynh

Post on 03-Mar-2019

214 views

Category:

Documents


0 download

TRANSCRIPT

De Bruijn's syntax and redu tional equivalen e of�-termsFairouz Kamareddine (Heriot-Watt University)Roel Bloo and Rob Nederpelt (Eindhoven,NL)5 September 2001

PPDP'01, 5 September 2001

Item Notation/Lambda Cal ulus �a la de Bruijn

� I translates to item notation:I(x) = x; I(�x:B) = [x℄I(B); I(AB) = (I(B))I(A)� (�x:�y:xy)z translates to (z)[x℄[y℄(y)x.� The items are (z), [x℄, [y℄ and (y). The last x is the heart of the term.� The appli ator wagon (z) and abstra tor wagon [x℄ o ur NEXT to ea h other.� The � rule (�x:A)B !� A[x := B℄ be omes in item notation:(B)[x℄A!� [x := B℄APPDP'01, 5 September 2001 1

Redexes in Item NotationClassi al Notation Item Notation((�x:(�y:�z:zd) )b)a (a)(b)[x℄( )[y℄[z℄(d)z#� #�((�y:�z:zd) )a (a)( )[y℄[z℄(d)z#� #�(�z:zd)a (a)[z℄(d)z#� #�ad (d)a

(a)(b) [x℄ ( ) [y℄ [z℄ (d) z

PPDP'01, 5 September 2001 2

Segments, Partners, Ba helors� The \bra keting stru ture" of ((�x:(�y:�z:��) )b)a), is `f1 f2 f3 g2 g1 g3',where `fi' and `gi' mat h.� The bra keting stru ture of (a)(b)[x℄( )[y℄[z℄(d) is simpler: ff gf gg.� (a) and [z℄ are partners. (b) and [x℄ are partners. ( ) and [y℄ are partners.� (d) is ba helor.� A segment s is well balan ed when it ontains only partnered main items.(a)(b)[x℄( )[y℄[z℄ is well balan ed.� A segment is ba helor when it ontains only ba helor main items.

PPDP'01, 5 September 2001 3

More on Segments, Partners, and Ba helors� The main items are those at top level.In ([y℄(y)y)[x℄x the main items are: ([y℄(y)y) and [x℄.[y℄ and (y) are not main items.� Ea h main ba helor [℄ pre edes ea h main ba helor ().For example, look at: [u℄(a)(b)[x℄( )[y℄[z℄(d)u.� Removing all main ba helor items yields a well balan ed segment.For example from [u℄(a)(b)[x℄( )[y℄[z℄(d) we get: (a)(b)[x℄( )[y℄[z℄.� Removing all main partnered items yields a ba helor segment[v1℄ : : : [vn℄(a1) : : : (am).For example from [u℄(a)(b)[x℄( )[y℄[z℄(d) we get: [u℄(d).� If [v℄ and (b) are partnered in s1(b)s2[v℄s3, then s2 must be well balan ed.PPDP'01, 5 September 2001 4

Even More on Segments, Partners, and Ba helorsEa h non-empty segment s has a unique partitioning into sub-segmentss = s0s1 � � � sn su h that n � 0,� si is not empty for i � 1,� si is well balan ed if i is even and is ba helor if i is odd.� if si = [x1℄ � � � [xm℄ and sj = (a1) � � � (ap) then si pre edes sj� Example: s � [x℄[y℄(a)[z℄[x0℄(b)( )(d)[y0℄[z0℄(e) is partitioned as:

� s � s0z}|{; [x℄[y℄| {z }s1 s2z }| {(a)[z℄ [x0℄(b)| {z }s3 s4z }| {( )(d)[y0℄[z0℄ (e)|{z}s5PPDP'01, 5 September 2001 5

More on Item Notation� Above dis ussion and further details of item notation an be foundin [Kamareddine and Nederpelt, 1995, 1996℄.� Item notation helped greatly in the study of a one-sorted style ofexpli it substitutions, the �s-style whi h is related to ��, but has ertainsimpli� ations [Kamareddine and R��os, 1995, 1997; Kamareddine and R��os,2000℄.� For expli it substitution in item notation see [Kamareddine and Nederpelt,1993℄PPDP'01, 5 September 2001 6

Canoni al Forms

� Ni e anoni al forms look like:ba helor [ ℄s ()[ ℄-pairs, Ai in CF ba helor ()s, Bi in CF end var[x1℄ : : : [xn℄ (A1)[y1℄: : :(Am)[ym℄ (B1) : : : (Bp) x� lassi al: �x1 � � ��xn:(�y1:(�y2: � � � (�ym:xBp � � �B1)Am � � � )A2)A1� For example, a anoni al form of:[x℄[y℄(a)[z℄[x0℄(b)( )(d)[y0℄[z0℄(e)xis [x℄[y℄[x0℄(a)[z℄(d)[y0℄( )[z0℄(b)(e)xPPDP'01, 5 September 2001 7

Some Helpful Rules for rea hing anoni al formsName In Classi al Notation In Item Notation((�x:N)P )Q (Q)(P )[x℄N(�) # #(�x:NQ)P (P )[x℄(Q)N(�x:�y:N)P (P )[x℄[y℄N( ) # #�y:(�x:N)P [y℄(P )[x℄N((�x:�y:N)P )Q (Q)(P )[x℄[y℄N( C) # #(�y:(�x:N)P )Q (Q)[y℄(P )[x℄N((�x:�y:N)P )Q (Q)(P )[x℄[y℄N(g) # #(�x:N [y := Q℄)P (P )[x℄[y := Q℄NPPDP'01, 5 September 2001 8

A Few Uses of Generalised Redu tion and Term Reshu�ing� Regnier [1992℄ uses term reshu�ing and generalized redu tion in analyzingperpetual redu tion strategies.� Term reshu�ing is used in [Kfoury et al., 1994; Kfoury and Wells, 1994℄ inanalyzing typability problems.� [Nederpelt, 1973; de Groote, 1993; Kfoury and Wells, 1995℄ use generalisedredu tion and/or term reshu�ing in relating SN to WN.� [Ariola et al., 1995℄ uses a form of term-reshu�ing in obtaining a al ulus that orresponds to lazy fun tional evaluation.� [Kamareddine and Nederpelt, 1995; Kamareddine et al., 1999, 1998; Blooet al., 1996℄ shows that they ould redu e spa e/time needs.� [Kamareddine, 2000℄ shows various strong properties of generalised redu tion.PPDP'01, 5 September 2001 9

Obtaining Canoni al Forms

�-nf: ()[ ℄-pairs mixed with ba h. [ ℄s ba h. ()s end var(A1)[x℄[y℄[z℄(A2)[p℄ � � � (B1)(B2) � � � x -nf: ba h. [ ℄s ()[ ℄-pairs mixed with ba h. ()s end var[x1℄[x2℄ � � � (B1)(A1)[x℄(B2) � � � x�- -nf: ba h. [ ℄s ()[ ℄-pairs ba h. ()s end var[x1℄[x2℄ � � � (A1)[y1℄(A2)[y2℄ : : : (Am)[ym℄ (B1)(B2) : : : x -�-nf: ba h. [ ℄s ()[ ℄-pairs ba h. ()s end var[x1℄[x2℄ � � � (A1)[y1℄(A2)[y2℄ : : : (Am)[ym℄ (B1)(B2) : : : x

PPDP'01, 5 September 2001 10

Example

For M � [x℄[y℄(a)[z℄[x0℄(b)( )(d)[y0℄[z0℄(e)x:

�(M): ba h. [ ℄s ()[ ℄-pairs mixed with ba h. [ ℄s ba h. ()s end var[x℄[y℄ (a)[z℄[x0℄(d)[y0℄( )[z0℄ (b)(e) x (M): ba h. [ ℄s ()[ ℄-pairs mixed with ba h. ()s ba h. ()s end var[x℄[y℄[x0℄ (a)[z℄(b)( )[z0℄(d)[y0℄ (e) x�( (M)): ba h. [ ℄s ()[ ℄-pairs ba h. ()s end var[x℄[y℄[x0℄ (a)[z℄( )[z0℄(d)[y0℄ (b)(e) x (�(M)): ba h. [ ℄s ()[ ℄-pairs ba h. ()s end var[x℄[y℄[x0℄ (a)[z℄(d)[y0℄( )[z0℄ (b)(e) x

PPDP'01, 5 September 2001 11

Classes of terms modulo redu tional behaviour� !� and ! are SN and CR. Hen e �-nf and -nf are unique.� Both �( (A)) and (�(A)) are in anoni al form.� �( (A)) =p (�(A)) where !p is the rule(A1)[y1℄(A2)[y2℄B !p (A2)[y2℄(A1)[y1℄B if y1 =2 FV(A2)� We de�ne: [A℄ to be fB j �( (A)) =p �( (B))g.� When B 2 [A℄, we write that B �equi A.� !�;! ;= ;=�;=p��equi�=� (stri t in lusions).� De�ne CCF(A) as fA0 in anoni al form jA0 =p �( (A))g.PPDP'01, 5 September 2001 12

Redu tion based on lasses

� One-step lass-redu tion ;� is the least ompatible relation su h that:A;�B i� 9A0 2 [A℄:9B0 2 [B℄: A0 !� B0� ;� really a ts as redu tion on lasses:� If A;� B then forall A0 �equi A, forall B0 �equi B, we have A0 ;� B0.

PPDP'01, 5 September 2001 13

Properties of redu tion modulo lasses

� ;� generalises !g and !�: !� �!g�;� �=�.� �� and =� are equivalent: A �� B i� A =� B.� ;;� is Chur h Rosser:If A;;� B and A;;� C, then for some D: B ;;� D and C ;;� D.� Classes preserve SN!�: If A 2 SN!� and A0 2 [A℄ then A0 2 SN!�.� Classes preserve SN;�: If A 2 SN;� and A0 2 [A℄ then A0 2 SN;�.� SN!� and SN;� are equivalent: A 2 SN;� i� A 2 SN!�.PPDP'01, 5 September 2001 14

Using Item Notation in Type Systems

� Now, all items are written inside () instead of using () and [℄.� (�x:x)y is written as: (yÆ)(�x)x instead of (y)[x℄x.� �z:�:(�x:z:x)y is written as: (��z)(yÆ)(z�x)x.

PPDP'01, 5 September 2001 15

The Barendregt Cube in item notation and lass redu tion

� The formulation is the same ex ept that terms are written in item notation:

� T = � j2 j V j (T Æ)T j (T �V )T j (T �V )T .

� The typing rules don't hange although we do lass redu tion ;� instead ofnormal �-redu tion !� .

� The typing rules don't hange be ause =� is the same as ��.PPDP'01, 5 September 2001 16

������������������������������������������������

�����������������! �P

�2 �P2�! �P!

�C�!

t ttt

t ttt

-6

��������1 (�;2) 2 R(2;2) 2 R(2; �) 2 R

Figure 1: The Barendregt Cube

PPDP'01, 5 September 2001 17

Subje t Redu tion fails

� Most properties in luding SN hold for all systems of the ube extended with lass redu tion. However, SR only holds in �! (�; �) and �! (2;2).� SR fails in �P (�;2) (and hen e in �P2; �P! and �C). Example in paper.� SR also fails in �2 (2; �) (and hen e in �P2; �! and �C):

PPDP'01, 5 September 2001 18

Why does Subje t Redu tion fails

� (y0Æ)(�Æ)(���)(��y)(yÆ)(��x)x ;�(�Æ)(���)(y0Æ)(��x)x.� (��:�:�y:�:(�x:�:x)y)�y0 ;�(��:�:(�x:�:x)y0)�� � : �; y0 : � `�2(��:�:�y:�:(�x:�:x)y)�y0: �� Yet, � : �; y0 : � 6`�2(��:�:(�x:�:x)y0)� : � for any � .� the information that y0 : � has repla ed y : � is lost in (��:�:(�x:�:x)y0)�.� But we need y0 : � to be able to type the subterm (�x:�:x)y0 of(��:�:(�x:�:x)y0)� and hen e to type � : �; y0 : � ` (��:�:(�x:�:x)y0)� : �.PPDP'01, 5 September 2001 19

Solution to Subje t Redu tion: Use \letexpressions/de�nitions"

� De�nitions/let expressions are of the form: let x : A = B and are added to ontexts exa tly like the de larations y : C.� (def rule) �; let x : A = B ` C : D� ` (�x:A:C)B : D[x := A℄� we de�ne � ` � =def � to be the equivalen e relation generated by:{ if A =� B then � ` A =def B{ if let x : M = N is in � and if B arises from A by substituting oneparti ular o urren e of x in A by N , then � ` A =def B.

PPDP'01, 5 September 2001 20

The (simpli�ed) Cube with de�nitions and lass redu tion

(axiom) (app) (abs) and (form) are un hanged.

(start) � ` A : s�; x:A ` x : A � ` A : s � ` B : A�; let x : A = B ` x : A x fresh

(weak) � ` D : E � ` A : s�; x:A ` D : E � ` A : s � ` B : A � ` D : E�; let x : A = B ` D : E x fresh

( onv) � ` A : B � ` B0 : S � ` B =def B0� ` A : B0(def) �; let x : A = B ` C : D� ` (�x:A:C)B : D[x := A℄PPDP'01, 5 September 2001 21

Table 1: De�nitions solve subje t redu tion1: � : �; y0 : �; let � : � = � ` y0 : �2: � : �; y0 : �; let � : �= � ` � =def �3: � : �; y0 : �; let � : � = � ` y0 : � (from 1 and 2)4: � : �; y0 : �; let � : � = �; let x : � = y0 ` x : �5: � : �; y0 : �; let � : � = � ` (�x:�:x)y0 : �[x := y0℄ = �� : �; y0 : � ` (��:�:(�x:�:x)y0)� : �[� := �℄ = �

PPDP'01, 5 September 2001 22

Properties of the Cube with de�nitions and lass Redu tion� ` is a generalisation of `: If � ` A : B then � ` A : B.� Equivalent terms have same types:If � ` A : B and A0 2 [A℄, B0 2 [B℄ then � ` A0 : B0.� Subje t Redu tion for ` and ;;�:If � ` A : B and A;;� A0 then � ` A0 : B.� Uni ity of Types for ` :{ If � ` A : B and � ` A : B0 then � ` B =def B0{ If � ` A : B and � ` A0 : B0 and � ` A =� A0 then � ` B =def B0.� Strong Normalisation of ;;�:In the Cube, every legal term is strongly normalising with respe t to ;;�.PPDP'01, 5 September 2001 23

BibliographyZ.M. Ariola, M. Felleisen, J. Maraist, M. Odersky, and P. Wadler. A all by need lambda al ulus. 22nd ACMSymposium on Prin iples of Programming Languages, 1995.Roel Bloo, Fairouz Kamareddine, and Rob Nederpelt. The Barendregt ube with de�nitions and generalised redu tion.Inform. & Comput., 126(2):123{143, May 1996.Philippe de Groote. The onservation theorem revisited. In Pro . Int'l Conf. Typed Lambda Cal uli and Appli ations,pages 163{178. Springer-Verlag, 1993.F. Kamareddine, R. Bloo, and R. Nederpelt. On �- onversion in the �- ube and the ombination with abbreviations.Ann. Pure Appl. Logi , 97(1{3):27{45, 1999.F. Kamareddine and A. R��os. Relating the ��- and �s-styles of expli it substitutions. J. Logi Comput., 10(3):399{431, 2000.Fairouz Kamareddine. Postponement, onservation and preservation of strong normalisation for generalised redu tion.J. Logi Comput., 10(5):721{738, 2000.PPDP'01, 5 September 2001 24

Fairouz Kamareddine and Rob Nederpelt. On stepwise expli it substitution. Int'l J. Foundations Comput. S i., 4(3):197{240, 1993.Fairouz Kamareddine and Rob Nederpelt. Re�ning redu tion in the �- al ulus. J. Fun t. Programming, 5(4):637{651,O tober 1995.Fairouz Kamareddine and Rob Nederpelt. A useful �-notation. Theoret. Comput. S i., 155(1):85{109, 1996.Fairouz Kamareddine and Alejandro R��os. A �- al ulus �a la de Bruijn with expli it substitution. In 7th Int'l Symp.Prog. Lang.: Implem., Logi s & Programs, volume 982 of LNCS, pages 45{62. Springer-Verlag, 1995.Fairouz Kamareddine and Alejandro R��os. Extending a �- al ulus with expli it substitution whi h preserves strongnormalisation into a on uent al ulus on open terms. J. Fun t. Programming, 7(4):395{420, 1997.Fairouz Kamareddine, Alejandro R��os, and J. B. Wells. Cal uli of generalised �-redu tion and expli it substitutions:The type free and simply typed versions. J. Fun t. Logi Programming, 1998(5), June 1998.A. J. Kfoury and J. B. Wells. A dire t algorithm for type inferen e in the rank-2 fragment of the se ond-order�- al ulus. In Pro . 1994 ACM Conf. LISP Fun t. Program., pages 196{207, 1994. ISBN 0-89791-643-3.PPDP'01, 5 September 2001 25

A. J. Kfoury and J. B. Wells. New notions of redu tion and non-semanti proofs of �-strong normalization in typed�- al uli. In Pro . 10th Ann. IEEE Symp. Logi in Computer S i., pages 311{321, 1995. ISBN 0-8186-7050-9.Assaf J. Kfoury, Jerzy Tiuryn, and Pawe l Urzy zyn. An analysis of ML typability. J. ACM, 41(2):368{398, Mar h1994.Rob Nederpelt. Strong Normalization in a Typed Lambda Cal ulus With Lambda Stru tured Types. PhD thesis,Eindhoven, 1973.L. Regnier. Lambda al ul et r�eseaux. PhD thesis, University Paris 7, 1992.

PPDP'01, 5 September 2001 26