• Nenhum resultado encontrado

Explicit substitutions and all that

N/A
N/A
Protected

Academic year: 2021

Share "Explicit substitutions and all that"

Copied!
20
0
0

Texto

(1)

MauricioAyala-Rincon y

Cesar Mu~noz z

July 3, 2000

Abstract

Explicit substitution calculi are extensions of the -calculus where the substitution mechanism is

internalizedintothetheory. Thisfeaturemakesthemsuitableforimplementationandtheoreticalstudy

oflogicbasedtoolsasstronglytypedprogramminglanguagesandproofassistantsystems. Inthispaper

weexplorenewdevelopmentsontwoofthemostsuccessfulstylesofexplicitsubstitutioncalculi: the

-ands

e -calculi.

Keywords: Explicitsubstitution, higherorder uni cation,lambda-calculi,type andrewritingtheory

1 Introduction

Thispaperfocusesontheusesofexplicitsubstitutionsinthelanguageofthesimply-typed-calculus. Type

theorieswere usedatthebeginningofthetwentiethcenturyasaformalismtodealwiththemathematical

paradoxesstudied at that time and incorporatedin 1940 to the -calculus by A. Church [11]. The need

of strongerprogramminglanguagesguided typetheory to theinterest ofcomputerscientists in the1970's

and 1980's, when new languages based on type theories were developed. Probably the most relevant of

these languages is ML [42], developed by R. Milner. In the1990's, several proof assistant systemsbased

on higher-order logics, such as Coq [5], HOL [27], and PVS [52], were developed. The -calculus is the

simplest logical framework for reasoning about formal properties of all these systems and many of the

essentialtechniquesandcomputationalproceduresinvolvedinthesesystemshavebeendeveloped,analyzed,

and improved in the context of the typed-calculus before beingimplemented. These techniques include

simplemechanismsastypecheckingandtypeinference,andmorecomplexonesastheusedfordealingwith

theinhabitation problem and thehigher order uni cationproblem. Thebasic operationof the -calculus

is the -conversionthat wasoriginally de ned basedon an implicit notionof substitution were renaming

of variables was informallyassumed to avoid\clashes" and \captures". This implicitness of the notionof

substitution wasnotcriticalbefore thistheoretical framework wasused in othercontexts thantheones of

computerscience,but makingthenotionofsubstitutionexplicitisessentialwhencomputationalproperties

suchastimeandspacecomplexityshouldbeanalyzed.

Wewillfocusontwostylesofexplicitsubstitutions:  ands

e

. Thesecalculiuseaname-lessnotation

forvariables. Therefore,technicalnuisances dueto thehigherorder aspect of-calculus, asrenamingand

captureofvariables,areminimizedorcompletelyeliminatedinands

e

. Forthesecalculi,wewillmotivate

andillustratedi erenttechniquesdevelopedforimportantcomputationalproblemsandapplicationssuchas

higherorder uni cation, typeinference,and inhabitationproblem. These kindof problemsarise naturally

in many elds of computer science. Some of the current progress in the area of explicit substitution is

recorded in the seriesof \InternationalWorkshops on Explicit Substitutions: Theory and Applications to

ProgramsandProofs"-WESTAPPthatrunsyearlytogetherwiththeConferenceonRewritingTechniques

andApplications-RTA.Forothersurveysandtutorialsonexplicitsubstitutioncalculisee [38,57].



DepartamentodeMatematica,UniversidadedeBraslia,70910-900BrasliaD.F.,Brasil,ayala@mat.unb.br.

y

Workcarried outduring visitofthisauthorat the ULTRA Group,CEE, Heriot-WattUniversity,Edinburgh, Scotland

fundedbyCAPES(BEX0384/99-2)BrazilianFoundation.

z

InstituteforComputerApplicationsinScienceandEngineering,MailStop132C,NASALangleyResearchCenter,Hampton.

(2)

notation,itssimply-typedversion,andtheCurry-Howardisomorphism.Afterwards,insection3,wemotivate

explicitsubstitutionsandpresentthetwobefore mentionedcalculiofexplicitsubstitutionsalongwiththeir

simply-typed versions. In section 4, we explain brie y the applications of explicit substitutions before

concludinginsection5.

2 The -calculus

The -calculus was developed by Church around 1930 [12] as a formal language for the foundations of

mathematics and logic. Although that foundation was later revealed to be inconsistent, indeed Russell

paradox [59] can be encoded in it, the -calculus still provides a formal model of computability. Church

and Kleene [37, 10] proved that the class of -expressions and the class of partial-recursivefunctions are

thesame. This result, alongwith Turing's own work,showsthat the-calculus is asexpressiveasTuring

machines.

Thenotationconsistsofasetoftermsandrulestomanipulatethem. Thesetisbuiltonacountable

setofvariablesV =fx;y;:::ganditisinductivelyde nedasfollows: V ,ifM;N2then(M N)2,

andifx2V andM2thenx:M 2. Termsoftheform(M N)arecalledapplicationsandtermsofthe

formx:M arecalledabstractions. Abstractionsarebindingstructures. Asusualforthesekindofstructures,

anotionoffreeandboundvariablesisnecessary. Thesetoffreevariables ofM,denotedFV(M),isde ned

byFV(x)=fxg,FV((M N))=FV(M)[FV(N),and FV(x:M) =FV(M)nfxg. The variablex in

a termx:M is said to be bound. Names of bound variables are irrelevant. For instance, x:x and y:y

representthesame-term. Thisimplicitequivalenceiscalled -conversion. Formally,ifz62FV(M),then

x:M =

z:Mfz=xg,whereforanarbitrarytermN,MfN=xgdenotes theatomic substitutionof thefree

occurrencesofthevariablex inM byN.

Substitutionplaysaveryimportantrolein the-calculus. Infact,themain computationalrulein this

formalism, the -rule, is expressed as follows: (x:M N)

-MfN=xg. Informally, it statesthat the

applicationofafunctionx:M toanargumentN,resultsinatermMfN=xgwheretheformalparameterx

hasbeenreplacedbytheargumentNinM(thebodyofthefunction). Anadditionalrule,called,statesthat

abstractionscomputingthesamevalueforthesameargumentareconvertible. Formally,x:(M x) 

-M,

ifx62FV(M).

Theformalde nitionofsubstitutionisnotassimpleasitseems. Thefollowingone,commonlyusedin

im-plementations,iswrong: xfM=xg=M,yfM=xg=y,ify6=x,(M

1 M 2 )fM=xg=(M 1 fM=xg M 2 fM=xg),

(x:N) fM=xg = x:N, and (y:N) fM=xg = y:NfM=xg, if y 6= x. The problem arises in the last

case: the term M may contain a free variable y which becomes a bound variable when the substitution

is applied. A correct de nition should avoid this capture; for instance, by modifying the last case with

(y:N) fM=xg=z:Nfz=ygfM=xg, wherez62FV(M).

The-calculusisnotterminating. Indeed,atermlike(x:(x x) x:(x x)) -reduces toitselfandthen

itcanbealwaysreduced. However,the-calculussatis es,theChurch-Rosser property i.e.,ifM

1 =  M 2 ,

then there exists N such that M

1   -N and M 2   -N. 1

In consequence: (1) the -calculus is also

con uent and(2) normalforms,ittheyexist,areunique. Wereferto [3]foracomplete descriptionofthe

-calculusanditsproperties.

2.1 De Bruijn indices

Atthebeginningofthe seventies,deBruijn developedanamelessnotationforthe -calculus[19]. Inthat

notation,namesofbound variablesarereplacedwithindices.

De nition2.1 Theset

dB

of-terms indeBruijnindexnotationisde nedinductivelyas

M;N ::=nj(M N)jM

1

Asusual,ifRisa term rewritesystem,wedenote by R

-the relation induced byR andby R



-the re exive,

symmetric,andtransitiveclosureof R

-.Furthermore,theequationaltheoryassociatedtoRde nesacongruencedenoted

by=

R .

(3)

wheren2N .

An indexcountsthenumberof-symbolsin thebindingscopeofthebound variablethatitrepresents.

Forinstance, in deBruijnindex notation,the termx:xis written1 sincethebound variablex isin the

bindingscopeofone-symbol. Similarly,theterm x:(y:(x y) x) iswritten ((2 1) 1) . Note thatthe

sameindex appearing in di erent binding scopesrepresentsdi erent variables. Vice-versa, occurrencesof

thesamevariableappearingindi erentbindingscopesaredenoted bydi erentindices.

Free variables can also be represented by de Bruijn indices. In that case, it is necessary to x an

enumeration,namelyareferential, x

1 ;x

2 ;:::;x

n

, of freevariable names. Ifthe occurrenceofavariable is

denoted byanindexnand thenumberof-symbolsinthebindingscopeofthat occurrenceislessthann,

saym,thenthatoccurrenceofnrepresentsthefree-variablex

n m

ofthereferential. Forinstance,theterm

(x:(y x) z)canbeencodedas((2 1) 2)underthereferentialy;zandas((3 1) 1)underthereferential

z;y.

The formulation of the rules and  for 

dB

-terms requires the following functions for updating and

substitutionofindices.

De nition2.2 Let M2

dB

. The i-liftof M,denotedM +i

isde nedinductivelyas follows

1. (M 1 M 2 ) +i =(M +i 1 M +i 2 ); 2. (N) +i =N +(i+1) ; 3. n +i =  n+1; ifn>i n; ifni

The liftof atermM isits0-liftandisdenoted brie yas M +

.

De nition2.3 The application of the substitution with N at the depth n 1 on a term M, denoted

MfN=ng, isde nedinductivelyas follows

1. (M 1 M 2 )fN=ng=(M 1 fN=ng M 2 fN=ng); 2. (M)fN=ng=MfN + =n+1g; 3. mfN=ng= 8 < : m 1; ifm>n N; ifm=n m; ifm<n

De nition2.4 Therules and arede nedfor the setof 

dB -termsasfollows (M N) -MfN=1g (M 1)  -N; if N + =M

Example2.5 The -term (x:(y:(x z) x) (z z:(x z))) canbe translatedunder the referential x;y;z

intothe

dB

-term(((2 5) 1) (3 (2 1))). Furthermore,wehave

(x:(y:(x z) x) (z z:(x z)) )

-(y:((z z:(x z)) z) (z z:(x z))):

Weexaminein detailthestepsof thatreductionfor

dB -terms: (((2 5) 1) (3 (2 1))) -((2 5) 1) f(3 (2 1))=1g = (((2 5))f(3 (2 1) )=1g 1f(3 (2 1))=1g) = ((2 5) f(3 (2 1)) + =2g (3 (2 1)) ) = ((2 5) f(3 + (2 +1 1 +1 ) )=2g (3 (2 1) )) = ((2 5) f(4 (3 1))=2g (3 (2 1))) = ((2 f(4 (3 1)) =2g 5f(4 (3 1)) =2g) (3 (2 1) )) = (((4 (3 1)) 4) (3 (2 1) ))

(4)

dB

thegivenreferential. 

Example2.6 Noticethat

(((5 (1 2)) 4) 1)  -((4 (1 2)) 3) since ((4 (1 2)) 3) + = (((4 (1 2))) + 3 + ) = (((4 (1 2))) +1 3 + ) = ((4 (1 2) ) +2 3 + ) = ((4 +2 (1 2) +2 ) 3 + ) = ((4 +2 (1 +2 2 +2 )) 3 + ) = ((5 (1 2) ) 4)  2.2 Simply-typed -calculus

The-calculusisasimple,butyetpowerfulformalism. Aswesaidbefore,whenusedasalogicalframework,

the-calculusallowsto encodeparadoxes. Tosolvethatproblem, Church developedatypedversionofthe

-calculus[11]withhappenstobeasimpli cationoftheTypeTheoryofWhitehead-Russell[59].

Thee ectoftyped-calculuscanbeseenonatermsuchasx:(x x)whichisawellformedterminthe

untyped -calculus that represents theabstract concept of \self-application". The meaningfulness of this

concept maybe questioned and was involved in manyof thelogical paradoxesfrom thebeginning of the

twentiethcentury. ThinkingaboutxasafunctionalvariablefromAtoAorof\typeA!A",theapplication

(x x) is forbidden, sinceit's impossible to apply afunction of typeA! A to anargumentof typeA! A.

This coincideswith theconceptionof functionalobjectsassumedby mostmathematicians. Of course,ifz

is avariable of type A, the typed expressionx:(x (x z))makessense. Fora formal introduction to the

theoryofthesimply-typed-calculus plentifulofinterestinghistoricalremarkssee[30].

Inatyped-calculus,-termsarestrati edinseveralcategories,namelytypes. Atype,inthesimpletype

theory,canbeabasictypea;b;::: orafunctionaltypeA!B,whereAandBaretypes. Weuseupper-case

lettersA;B::: torangeovertypes. Onlytermsthatfollowatypedisciplineareconsideredtobevalid. The

typedisciplineisenforcedbyaset oftypingrules. Thanksto thetypingrules,Russell'sparadoxcannotbe

expressedinthesimpletypetheory.

Typed-terms areelementsofthesetof-termsexceptthat bound variablesin abstractionshavetype

annotations,i.e.,theyhavetheformx: A:M. Rules and aremodi edaccordingly:

(x:A :M N) -MfN=xg and x:A:(M x)  -M,ifx62FV(M)

A typingjudgment `M:Adenotesthat thetermM hastypeAin ,where isacontext,i.e.,alist

x 1 :A 1 ;:::;x n :A n

ofvariabledeclarations. Henceforth,weuseGreekletters ;;::: torangeovercontexts.

Figure1showsthetypingrulesofthesimply-typed-calculus. Wesaythat a-termM iswell typedin

ifandonlyif thereexists atypeA such that `M :A, andwesaythat atypeAis inhabitedin ifand

onlyifthere existsa-term M suchthat `M:A.

The presentation of the typed -calculus used in this paper corresponds to the Church-style. In this

presentation, typed -terms are elements of the set of -terms except for abstractions, which have type

annotations. An alternativepresentation,called Curry-style, considers typed-terms asstandard-terms

withouttypeannotations. Inthatcase,typevariables shouldbeconsidered. Indeed,inatyped-calculusa

laCurry,thetypeofx:xis ! where denotesanytype(See [4]).

Typecheckingisdecidableforthesimplytyped-calculus. Thatis,thereisamethodtodecidewhether

(5)

(Start) x:A; `x:A (Weak) x:A; `M :B x: A; `M :B (Abs) `x: A:M :A!B `M:A! B `N :A (Appl) `(M N):B

Figure 1: Thesimply-typed-calculus

1in (Var) A 1 :A 2 ::::A n `i:A i A: `M :B (Abs) ` A :M:A!B `M:A!B `N :A (Appl) `(M N):B

Figure2: Thesimply-typed-calculusfor

dB -terms

-calculus,thesimply-typed-calculusenjoystheChurch-Rosserpropertyandthereforeitisalsocon uent.

Furthermore,italsosatis esthefollowingproperties.

 Subject reduction, if `M:A andM 

-N,then `N :A;

 Typeuniqueness,if `M:Aand `M:B, thenA=B;

 Strongnormalization,ifMisawelltypedterm,thenMhasnoreductionsofin nitelength. Therefore,

due tothecon uenceproperty,normal-formsofwelltypedtermsalwaysexists andtheyareunique.

InthedeBruijnsettingofthesimplytyped-calculus, acontext isalistoftypesA

1 :::::A

n

whereA

i

isthetypeofthefree-variablerepresentedbytheindexi. Theemptycontextisdenotedby. Simply-typed



dB

-termsarede ned bythetypingrulesofFig.2.

2.3 Curry-Howard isomorphism

There is a strong relation between type theory and intuitionistic logic. Indeed, if we identify types with

propositions,whereanarrowtypeisanimplication,typingrulesofthesimply-typed-calculuscorresponds

oneto onetodeductionrulesofaminimalintuitionisticlogic. Inotherwords,typingrulesarelogicalrules

decoratedwithtyped-terms. ThisprincipleisknownastheCurry-Howardisomorphism.

Consideranintuitionisticminimallogicwherepropositionalformulasarebuiltfromatomicpropositions

a;b;::: andtheimplication,i.e.,ifAandB areformulasthenA!B isaformula. WeuseuppercaseGreek

letters to range overset of formulas. Wewrite ;A as ashorthand for [fAg. A judgment `

I A

denotes that A is a logical consequenceof . A judgment is said provable (in the minimal intuitionistic

logic)ifandonlyifitisderivedbytop-downapplication ofthefollowingrules:

(Axiom) ;A` I A ;A` I B (Intro) ` I A!B ` I A!B ` I A (Elim) ` I B

A formulaA isatautologyifandonlyifthejudgment`

I

Aisprovable. Forexample,theformula

A!((A! B)! B)isatautologysinceitcanbederivedasfollows:

(Axiom) A;A!B ` I A! B (Axiom) A;A! B` I A (Elim) A;A! B` I B (Intro) A` I (A! B)!B (Intro) ` I A! ((A! B)!A)

(6)

I

logicif and onlyif ` M :A is avalid typing judgmentin the simply-typed -calculus, where is alist

of variable declaration of propositions, seen as types, in . The term M is a-term that representsthe

proof derivation. Forinstance, thetermdecoration ofthe treederivation aboveresultsin thevalidtyping

judgment`x: A:y:A! B:(y x):A!((A! B)!A).

TheCurry-Howardisomorphismis extended to intuitionistic rst order and higher order logics and it

is widely studied in proof theory. It is at the base of mathematic formalizations where proofs are just

mathematical objects. Such languagesare the base of automaticsystemsfor proof construction, program

veri cationandprogramsynthesis.

3 Explicit Substitutions

ImplicitnessofsubstitutionistheAchillesheelofthe-calculus. Namely,the-calculusisaconvenientand

compactmodel ofthecomputablefunctions butit doesnotprovideanymechanismforobservingessential

operational properties of these functions as time and space complexity. The reason of this is that the

substitution involvedin -reductionsdoesnotbelong inthecalculus,but ratherin aninformalmeta-level.

Inthepractice, -reductionisnotaprimitiveoperationandisimplementedbasedonasubstitutiongenerally

elaboratedbyrenamingvariablesand/or maintainingsomevariable convention. That makesimpossibleto

determineorboundin timeandspacethe -reduction.

The-calculus was the rst one presentedformally asa mechanism for making explicit substitution

in the -calculus [1]. But before this, today widely considered seminal work, many empiric and theoretic

e ortswere realizedin order to solvetheproblem of implicitness ofthe substitution operation. Fromthe

theoreticalpointofview, theCombinatory Logic of CurryandFeys[18]proposed the rstsolutionto this

problem. However,this setting doesnot remaincloseto the-calculus and thenumberof primitivesteps

canbeextensivelylargerthantherequiredbyexplicitsubstitutioncalculi. Fromtheempiricalpointofview,

perhaps the person who provide the foundations to take care of this problem wasde Bruijn itself, when

developinghissystemAUTOMATHfromthemiddleofthe1960's. Partofhisprimaryconceptionswasthe

previouslyherementionednicenamelessnotationforthe-calculus[19] andhislegacyiscollectedin[51].

Since the-calculus was introduced in [1], several other variants of explicit substitution calculihave

beenproposed(see,forexample,[55,38,32,7,39,17,35,43,24,44]). Thesecalculiimplementseveralstyles

ofexplicitsubstitutions.

Wewillfocusourattentionontwoofthesestyles: the-andthes

e

-styles.Bothofthemuseanameless

notationbasedonthedeBruijnindexnotation,whichiscompletelyinsensitiveto -conversion. Thatallows

aclean and elegantmeta-theoreticalstudy of thecalculi which makethem suitable forimplementation of

declarativeprogramminglanguages,higherorderproofassistants,andautomateddeductivesystems. Both

styleswereshownincomparablein[34].

The-calculusanditsvariantshavebeenproposedasageneralframeworkforhigherorderuni cation

andtermsynthesis[21,22,9,36,45,47,46,6]. Furthermore,calculiofthe-familyhavebeenincorporated

with success into programming languages and proof assistants. For example, an algorithm for pattern

uni cation fordependent types, basedon, hasbeenimplemented in theTwelf system [53]. It hasalso

beenrelevantin theimprovementoftheexplicitsubstitutionfortherewritecalculus(-calculus[14])ofthe

ELAN system,which provides alanguagebasedon rewriterules for specifying and prototyping deductive

systems[13].

Thes

e

-calculus[32,33]wasdevelopedmorerecentlythanthe-calculusanditsmainclaimed

advan-tageover the-calculus is that it remainsas close as possible to the -calculus havingonly one sort of

objects. There is acloserelation, untilnowonly subjectively purposed,between thes

e

-calculusand the

rewriterulesdevelopedbyNadathurandWilson intheearly1990'sandused intheimplementationofthe

higherorderlogicprogramminglanguageProlog[41]. Forinstance thelazinessin thesubstitutionneeded

inimplementationsof -reduction,thatarisesnaturallyinthes

e

-calculus,isprovidedastheinformalbut

empiricalconceptofsuspensionofsubstitutionsbyNadathurandWilsonrewriterules,beingtheirnotionof

substitutionmoregeneralthanthes

e

one. Morerecentlytheirrewriteruleswerepublishedinthecontext

ofexplicitsubstitutionasthesuspensioncalculus[49,50]. Establishingformallytherelationsanddi erences

betweenthes

e

(7)

(M N)[S] ! (M[S] N[S]) (App) (M)[S] ! M[1(SÆ")] (Abs) M[S][T] ! M[SÆT] (Clos) 1[MS] ! M (VarCons) M[id] ! M (Id) (S 1 ÆS 2 )ÆT ! S 1 Æ(S 2 ÆT) (Assoc) (MS)ÆT ! M[T](SÆT) (Map) idÆS ! S (IdL) SÆid ! S (IdR) "Æ(MS) ! S (ShiftCons) 1" ! id (VarShift) 1[S]("ÆS) ! S (SCons) (M 1) ! N if M=  N["] (Eta)

Figure 3: The-calculus[1]

3.1 The -calculus

The -calculus is a rst order rewrite system with twosorts of expressions: termsand substitutions. In

fact,substitutionsinherenttothe -rulein deBruijnindexnotation,(M N)

-MfN=1g,aredelayed

andrecordedinthe-calculusas(M N)

-M[N id]. Here,M[Nid]isa-expressionrepresenting

M witharecordedsubstitutionNid. Additionalrulesarenecessaryforapplyingtherecordedsubstitution

to the term M, i.e., replacing all the the free occurrences of the de Bruijn index 1 at M with N and

decrementing by one all the rest of free de Bruijn indices over M. Delaying application of substitution

is widely used in implementations of functional and logical programming languages, because performing

immediatelysubstitutionmaygiverisetoasizeexplosionoftheexpressions.

De nition3.1 (-calculus) The -calculus isde nedby the rewrite systemdepictedin Fig.3where

Terms M;N ::= 1jM j(M N)jM[S]

Substitutions S;T ::= idj " jMSjSÆT

The rewrite systemobtainedby dropping rules (Beta)and(Eta) of iscalled.

In,deBruijnindicesareencodedbymeansoftheconstant1andthesubstitution". Wewrite" n

as

ashorthandfor

n-times

z }| {

"Æ:::Æ". Weoverloadthenotationitorepresentthe-term correspondingtotheindex

i,i.e., i=  1 ifi=1 1[" n ] ifi=n+1:

This one-shift encoding is interesting because involving a built-in deduction mechanism for arithmetic in

implementationsofsystemsbasedonthe-calculusmakesitdiÆculttheanalysisoftimeandspace

quan-titativeperformance. Butin anyconceivableimplementation oneshould use fullindices at the meta-level

insteadof theone-shiftencoding.

An explicit substitution denotes amapping from indices to terms. Thus, id maps each index i to the

termi, "maps each indexi tothetermi+1, SÆT isthecompositionofthemappingdenoted byT with

themappingdenoted byS (noticethat thecompositionofsubstitutionfollowsareverseorderwithrespect

to the usual notation of function composition), and nally, MS maps the index 1 to the term M, and

(8)

(M N) ! M[N" ] (Beta) (M)[S] ! M[1(SÆ" 1 )] (Abs) (M N)[S] ! (M[S]N[S]) (App) M[S][T] ! M[SÆT] (Clos) 1[MS] ! M (VarCons) M[" 0 ] ! M (Id) (M S)ÆT ! M[T](SÆT) (Map) " 0 ÆS ! S (IdS) " n+1 Æ(MS) ! " n ÆS (ShiftCons) " n+1 Æ" m ! " n Æ" m+1 (ShiftShift) 1" 1 ! " 0 (Shift0) 1[" n+1 ]" n+2 ! " n+1 (ShiftS) (M 1) ! N if M = L N[" 1 ] (Eta)

Figure4: Therewritesystem

L

The-calculusisnotacon uentrewritesystem[17],howeveritiscon uentongroundexpressions[1]

and con uentonsubstitution-closed expressions (i.e., expressions withoutsubstitution variables) [55]. On

theotherhand,the-calculus,i.e., without(Beta), iscon uentandterminating[1].

Aterm iscalled pureif itdoesnotcontainsubstitutions. Notice that theset of pure termsin  and

the set of 

dB

-termsare identi able. Furthermore, the -calculus simulates the -calculus [17], i.e., the

relationsinducedby -and (Beta) - 

-(onestepof(Beta)followedbya-normalization)coincide

on pureterms. However,the-calculusdoesnotpreservestrong-normalizationofthe-calculus[40], i.e.,

stronglynormalizing-terms canbereducedforeverin .

3.2 The 

L

-calculus

As pointed out before, the one-shift encoding of indices in  is a theoretically convenient feature, but

impracticalforimplementations. Nadathuralsoremarkedin[48]thatthenon-left-linearruleof,namely

(SCons),isdiÆculttohandle inrealimplementations. Insteadofrule(SCons),hesuggestedthemeta-rule

1[" n ]" n+1 -" n . Since" n

isashorthandin ,anin nitesetofrulesisrepresentedbythisscheme.

Non-left-linear rules are not only annoying to implement, but they are usually responsible for

non-con uence and typing problems. Indeed,  is not con uent [17] and it does not preserve typing in a

dependent-typesystem[45],bothproblemsbecauseofthenon-left-linearityofthecalculus.

The

L

-calculus [44]is aleft-linearvariantof  where " n

isa rst-classsubstitution. Thisallowsthe

formulationoftherulesuggestedbyNadathurasaregular rstorderrule. Infact,insteadof (SCons),the

the

L

-calculushasthefollowingrule: 1[" n+1 ]" n+2 -" n+1 . De nition3.2 ( L -calculus) The L

-calculus isde nedbythe rewrite systemdepicted inFig.4where

Naturalnumbers n ::= 0jn+1

Terms M;N ::= 1jM j(M N)jM[S]

Substitutions S;T ::= " n

jMSjSÆT

The L-rewrite systemisobtainedby dropping rule(Beta) from

L .

Weadoptthenotationiasashorthandfor1[" n

]wheni=n+1. Substitutionsidand"arewrittenin

L as" 0 and" 1 , respectively. Ingeneral," n

denotesthemappingof eachindex ito thetermi+n. Using" n

,

theschemeof ruleproposed byNadathurcanbeencodedin a rstorderrewritesystem. Natural numbers

areconstructedwith0andn+1. Arithmeticcalculationsonindicesareembeddedin therewritesystem.

The

L

-calculusiscon uentonsubstitution-closedexpressionand itsimulatesthe-calculus [45]. Just

(9)

(M N) ! M N (-generation) (M) i N ! (M i+1 N) (--transition) (M 1 M 2 ) i N ! ((M 1  i N) (M 2  i N)) (-app-transition) n i N ! 8 < : n 1 if n>i ' i 0 N if n=i n if n<i (-destruction) ' i k (M) ! (' i k +1 M) ('--transition) ' i k (M 1 M 2 ) ! ((' i k M 1 ) (' i k M 2 )) ('-app-transition) ' i k n !  n+i 1 if n>k n if nk ('-destruction) (M 1  i M 2 ) j N ! (M 1  j+1 N) i (M 2  j i+1 N) if ij (--transition) (' i k M) j N ! ' i 1 k M if k<j<k+i (-'-transition1) (' i k M) j N ! ' i k (M j i+1 N) if k+ij (-'-transition2) ' i k (M j N) ! (' i k +1 M) j (' i k +1 j N) if jk+1 ('--transition) ' i k (' j l M) ! ' j l (' i k +1 j M) if l+jk ('-'-transition1) ' i k (' j l M) ! ' j+i 1 l M if lk<l+j ('-'-transition2) (M 1) ! N if M= se ' 2 0 N (Eta)

Figure5: Rewritingsystemofthes

e

-calculus

Another left-linear variant of  is the 

*

-calculus [17]. The 

*

-calculus is a con uent rst order

rewrite system, i.e., it is con uent on presence of both term and substitution variables. However, 

*

raises some technical problem with -conversions due to the fact that substitutions id and 1" are not

 * -convertible. 3.3 The s e -calculus The s e

-calculusavoids introducing two di erent sets of entities as the -calculusdoes, insisting in this

wayonremainingclosetothesyntaxofthe-calculus. Nexttoabstractionandapplication,thes

e

-calculus

introducessubstitution ()andupdating(')operators.

De nition3.3 (s

e

-calculus) Thes

e

-calculusisgivenby therewritesysteminFig.5andthe grammar

M;N ::=nj(M N)jM jM j Nj' i k M for n;j;i1 and k0:

The calculus of substitutions associated with the s

e

-calculus, namely s

e

, isthe rewriting systemgenerated

bythe set ofrules s

e =s

e

f-generation ;Etag.

Intuitively, the substitution operator, , initiates (rule (-generation)) one-step of -reduction, from

(M N),propagatingtheassociatedsubstitutioninnermost(rules(-)and(-app-transition)). Oncethis

propagationis nished,whennecessary,theupdatingoperator,',isintroducedtomaketheappropriatelift

overN (rule(-destruction)). Otherwiseeither freedeBruijn indicesare decrementedbyoneorbounded

maintained.

Thes

e

-calculussimulates -reductionandis con uent[33]. Itdoesnotpreservestrongnormalization

[28].

3.4 Simply-typed calculi of explicit substitutions

Inthis section, weonly include theessential notationof thesimply-typed 

L

-and s

e

-calculi. Properties

canbefoundindetailin[44] and[32],respectively. Typingrulesinbothcalculifollowtheschemeasthose

(10)

(Var) A: `1:A (Lambda) ` A :N :A!B `M :A!B `N :A (App) `(M N):B `S. `M:A (Clos) `M[S]:A (Id) `" 0 . `" n . (Shift) A: `" n+1 . `M :A `S. (Cons) `MS.A: `T . 2  2 `S . 1 (Comp) `SÆT. 1

Figure6: Typingrulesforthe

L -calculus (Var) A: `1:A `n:B (Varn) A: `n+1:B A: `N :B (Lambda) ` A :N :A! B `N:A! B `M:A (App) `(N M):B i `N:B <i :B: i `M:A (Sigma) `M i N :A k : k +i `M:A (Phi) `' i k M:A

Figure7: Typingrulesforthes

e

-calculus

Therewrite rulesofthetyped

L

- ands

e

-calculiarede ned byadding totheirrespectiveset ofrules

thenecessarytypinginformation. Thus,forthesimply-typed

L

-calculuswehavethetypedrules:

( A :M N) ! M[N" 0 ] (Beta) ( A :M)[S] !  A :M[1(SÆ" 1 )] (Abs)  A :(M 1) ! N if M= L N[" 1 ] (Eta)

andforthetypeds

e -calculus: ( A :M N) ! M 1 N (-generation) ( A :M) i N !  A :(M i+1 N) (--transition) ' i k ( A :M) !  A :(' i k +1 M) ('--transition)  A :(M 1) ! N if M= se ' 2 0 N (Eta)

Typingrulesforthe

L

-calculusandthes

e

-calculusarepresentedin theFigures6and7,respectively.

Notice that in the case of the 

L

-calculus, substitutions receive contexts as types. This is denoted as

`S .. Let be acontextof theform A

1 :A

2 :::A

n

:. We usethenotation

k and k fordenoting thecontextsA 1 :::A k andA k :::A n

:,respectively. Thisnotationisextendedfor\<"and\>"intheobvious

manner.

Example3.4 Inorder toillustrate theuseofthetypingrules, weshowhowtoinferthetypeoftheterm

 A! B : B!C : A :(2 (3 1))in s e .

Forshort,let =A:B!C:A!B. Firstly,observethat

(Var) (1) `1:A (Var) B! C:A!B`1:B!C (Varn) (2) `2:B!C (Var) A!B`1:A!B (Varn) B!C:A! B`2:A! B (Varn) (3) `3:A!B

(11)

(2) (3) (1) (App) `(3 1):B (App) `(2 (3 1)):C

Finally,noticethat

`(2 (3 1)):C (Lambda) B! C:A!B` A :(2 (3 1)):A!C (Lambda) A!B` B! C : A :(2 (3 1) ):(B! C)!(A! C) (Lambda) ` A! B : B!C : A :(2 (3 1) ):(A! B)!((B! C)!(A! C)) Forthe L

-calculustheinferenceisidenticalexceptforthe rststeps;forinstance,noticethat

(Id) B!C:A! B`" 0 .B!C:A!B (Shift) `" 1 .B!C:A!B (Id) A!B`" 0 .A!B (Shift) B!C:A! B`" 1 .A!B (Comp) `" 2 .A! B Then, `" 2 .A! B (Var) A! B`1:A! B (Clos) `3:A!B

Rememberthat thelanguageof the

L

-calculusonlyincludes thedeBruijnindex 1and theothersare

simulatedusingthe" n

. 

The simply-typed versions of the 

L

- and s

e

-calculus satisfy, among others, the properties of subject

reductionandtypeuniqueness. Additionally,theyareWeaklyNormalizing(WN)andChurch-Rosser(CR).

4 Applications

Althoughinanintuitionisticlogic,theconceptsofpropositionsandtypesareidenti ed,proofconstructionand

termsynthesisdonotnecessarilygointhesamedirection.Forinstance,toprovethepropositionA!(B!A),

onemayassume A as an hypothesis and then, recursively, tryto prove(B!A). Eventually, one getsthe

axiomA;B `A andtheproof derivationis completed. Ontheother hand,theproof synthesisprocedure,

decorateswith -terms the proof-treederivation from the axioms,to set upthe variable declarations,i.e.,

x: A;y:B `x:A,downtotheconclusion.

Inordertosynthesizea-termatthesametimeasaproofisbeingdeveloped,itisnecessarytorepresent

incomplete-proofs. Assume,forexample,thepropositionA!(B!A). Thebottom-upapplicationoftherule

(Abs) resultsin aterm x: A:X where X is atermto beconstructed oftype (B!A). A term asx: A:X

iscalled anopen term and theplace-holderX denotesaholeto be lled withaterm ofthe righttype, in

thiscaseoftype(B!A). Place-holdersarealsocalledmeta-variables todistinguishthemfromthevariables

ofthe-calculus. Meta-variablesarewrittenasuppercase (X;Y;:::)last lettersoftheLatinalphabet. At

somemomentduringtheproofderivation,wegetthetypingjudgmentx:A; `y:B:x:(B!A). Hence,to

obtainacloseterm,i.e.,atermwithoutmeta-variables,wecaninstantiatethemeta-variableXwiththeterm

y:B:x. Thisresultsinx: A:y:B:x . Incontrasttosubstitutionofvariables,instantiationofmeta-variables

isa rstorderreplacementthatdoesnotcareofrenamingofbound variablesorcaptureoffree-variables.

Notice, however, that open terms are not -terms. In fact, (1) instantiation and -reduction do not

commute,and(2)instantiationandtypingdonotcommute. Toillustratethe rstpoint,taketheopenterm

(x:X y) and the instantiation of X with x. The instantiation results in (x:x y), which -reduces to

(12)

C,where X isameta-variable oftypeA. IfweinstantiateX withthevariable x of , thenweobtainthe

ill-typedterm(z x: B:x ).

Meta-variablescanbeencodedin classical-calculus byusing atechniquetaken fromthe higherorder

uni cation tradition [31]. This techniqueuses a functional handle of scope. Forinstance, the open term

x: A:Y, where Y is a meta-variable of type B, is encoded as the -term x: A:(y x), where y is a fresh

variable oftype A!B. In thiscase, theinformation that thevariable x canindeed occurin asubsequent

substitutionofyistakingintoaccountbytheapplication(y x). Thus,aninstantiationofY withM inthe

originalproblemistranslatedasasubstitutionofybyx: A! B:M in the-calculus. Notice,howeverthat

themeta-variableY hasthetypeB whilethecorrespondingvariabley hasthetypeA! B.

Explicitsubstitutions andde Bruijnindices allowasimpleandnaturalnotationfor openterms. First,

inadeBruijnsetting,meta-variablesarejustvariablesofthefreealgebraofterms. Noticethatboundand

freevariables of the-calculus are representedasindices. Andsecond,explicit substitution calculias,



L

,ands

e

,arecon uentonopenterms(inthecaseof and

L

,onsubstitution-closedterms). Thus,in

thesecalculi,commutationofinstantiationandthe -reductionisforfree.

Wewillconsider meta-variablesoveraset X.

De nition4.1 Theset

dB

(X)of-terms indeBruijnindexnotationwithmeta-variables overthe setX

isde nedinductively as

M;N ::=njX j(M N)jM

wheren2N >0

;X 2X.

De nition4.2 Avaluationisamapping fromX to

dB

(X). Thehomeomorphic extensionofavaluation,

,from itsdomainX tothe domain 

dB

(X)iscalled thegrafting of .

AsusualvaluationsandtheircorrespondinggraftingsaredenotedbythesameGreekletters. Application

ofagraftingtoatermM willbewritteninpost xnotationM. Forexplicitrepresentationofavaluation

and its corresponding grafting , weuse the notation  = fX 7! X j X 2 Dom()g. A grafting is the

formalconceptformeta-variableinstantiation.

The set of -, 

L

-, and s

e

-terms with meta-variables, and their respective grafting notion, can be

de nedin asimilar way. Thetypingrule formeta-variablesinthesesystemsis[21]:

(Meta X ) X `X:A X whereA X and X

are,respectively,auniquetypeandauniquecontextassociatetoeachmeta-variable. By

usingthisrule,typingandinstantiation ofmeta-variablescommute[21].

4.1 Higher order uni cation

Higher order uni cation (HOU) is essential in automated reasoning, where it has formed the basis for

generalizationsof theResolution Principle in higher order logics, being asine quanon mechanism in the

implementationof higherorderproof assistantsand higherorderlogic programminglanguagesasthe ones

previouslyreferenced. ForaverysimplepresentationofHOUsee[58]andforadetailed introductioninthe

contextofdeclarativeprogrammingsee[54]. Asforthe rstordercase,substitutionisthekeyoperationfor

HOUanditsimplicitnessmakesdiÆculttheanalysisofimportantcomputationalproperties. Therefore,use

ofcalculiofexplicitsubstitutionin theformalimplementationofHOUproceduresis relevant.

HOUproblemsareexpressedin thelanguageofthesimply-typed-calculusin deBruijnindicesovera

set of meta-variables X, denoted 

dB

(X). Meta-variables play the role of uni cation variables. A simple

exampleofaHOUproblemistosearchforfunctionsolutionsFoftheequalityF(f(a))= ?

f(F(a)). Thatcan

bewrittenin

dB

(X)as(X (2 1) ) = ?



(2 (X 1)),wherebothX and2areoffunctionaltype,sayA! A

and 1of atomic typeA. A solution forX is thefunction identity, 

A :1but f A :(3 1) ; A :(3 (3 1) );:::g (correspondingly,fF =f;F=f 2

(13)

becauseherealizedthat togeneralizeRobinson rstorderResolutionPrinciple[56]tohigherordertheories

itisusefultoverifytheexistenceofuni erswithoutcomputingthemexplicitly. Huet'salgorithmisa

semi-decisiononethatmayneverstopwhentheinputuni cationproblemhasnouni ers,butwhentheproblem

hasasolutionitalwayspresentsanexplicituni er.Uni cationforsecond-orderlogicwasprovedundecidable

in generalby Goldfarb[26]. Goldfarb'sproof is basedonareductionfrom Hilbert's TenthProblem. This

resultshowsthat therearearbitraryhigherordertheorieswhere uni cationisundecidable, butthere exist

particularhigherorderlanguagesofpracticalinterestthathaveadecidableuni cationproblem. Inparticular,

forthesecond-ordercase,uni cationisdecidable,whenthelanguageisrestrictedtomonadicfunctions[23].

AnotherproblemofHOU isthatthenotionofmostgeneraluni erdoesnotapplyand thatanotionmore

complexthanthe oneof complete setof uni ersisnecessary. Huet hasshowedthat equationsofthe form

(x:F a)= ?

(x:G b)(called ex- ex)ofthird-ordermaynothaveminimalcomplete sets ofuni ersand

that there may exist anin nitechainof uni ers,onemoregeneral thantheother, without havingamost

generalone (forreferencesseesection4.1in [54]).

The general method of HOU via calculi of explicit substitutions was introduced in [21] (for the

-calculus)andconsistsmainlyin: rstly,atranslationor\pre-cooking"fromHOUproblemsin

dB

(X)into

thelanguageofacalculusofexplicitsubstitutions. Secondly,anapplicationof( rstorder)uni cationinthe

selectedcalculusof explicitsubstitutionsto solvethe translatedproblems. Finally,translationbackofthe

givengraftingsolutionsintosubstitutionsolutionsoftheoriginalHOUproblem. InthiswayHOUproblems

aresolvedvia rstorder uni cationinthelanguageofcalculiofexplicitsubstitution. Wewillexplainwith

exampleshowreductionrelationsfromthesimply-typed-calculusands

e

-calculusofexplicitsubstitutions

areusedtosolveHOUproblemsin 

dB

(X). Foraformalpresentationofthemethodsconsult[21]and[2].

De nition4.3 Let  = fX 1 7! a 1 ;:::;X n 7! a n

g be a valuation from the set of meta-variables X to



dB

(X). The corresponding substitution, fa

1 =X 1 ;:::;a n =X n

g, also denoted by  but written in a pre x

notation,isde nedinductivelyasfollows

1. (m)=m, form2N; 2. (X)=XfX 1 7!a 1 ;:::;X n 7!a n g, for X2X; 3. (a 1 a 2 )=((a 1 ) (a 2 )); 4. (a 1 )= + (a 1 ); where +

denotes the substitutioncorresponding tothe valuation  + =fX 1 7!a + 1 ;:::;X n 7!a + n g.

Unifying two terms M and N in 

dB

(X) consists in nding a grafting  such that its corresponding

substitution satis es (M) =



(N). Notice that application of a grafting has a di erent e ect to the

applicationofitscorrespondingsubstitution. Forinstance,although(X) fX7!Mg=M,auni erofthe

problemX= ?  M isnotfM=Xg,since(X) fM=Xg=(XfM + =Xg)=M + . However,bytranslating appropriatelythe dB

(X)-termsM;N,theHOUproblemM = ?



N canbereducedto rstorderuni cation

eitherin the-orin thes

e

-calculus. Essentially,thepre-cookingtranslationfromtermsin

dB

(X)into

thelanguage ofthe -calculusreplaceseach occurrenceof ameta-variableX with X[" k

], where k is the

numberofabstractorsabovetheoccurrenceofX. Forthecaseofthes

e

-calculusthepre-cookingtranslates

eachoccurrenceofameta-variableX into' k +1

0

X,wherekisasbefore.

Example4.4 Considerthe problem2= ?



(X 2)being2of typeA andX of typeA!A. Introducinga

freshmeta-variableY oftypeAtheproblemistranslatedinto2= ?  (Y 2)^X = ?  Y. Inthes e

-calculustheproblemisnormalizedinto2= ? se Y 1 2^X = ? se

Y,whosesolutionsaref1=Yg

andf3=Yggivingasresultthesolutionsf1=Xgandf3=Xg.

Inthe-calculustheproblem isnormalizedinto2= ?



Y[2:id]^X = ?



Y, from where weinferthe

(14)

Example4.5 Nowconsider theHOUproblem 2=



(Z 2),where2andZ areoftypeA.

In thes

e

-calculustheproblem is pre-cookedinto 2= ?

se ('

2

0

Z 2) andthen transformedinto 2= ? se (' 2 0 Z) 1

2andsubsequentlyinto2= ?

se '

1

0

Z bynormalization. ThesolepossiblesolutiongivenisfZ7!2g.

Observe,ontheoneside,that (' 2 0 Z 2)fZ 7!2g=(' 2 0 2 2)= s e (3 2)= s e 3 1 2= s e 2. Ontheother

side, turning backthe pre-cooking transformation, this corresponds to thesubstitution solutionf2=Zgfor

the original problem. Infact, (Z 2)f2=Zg =((Z) f2=Zg 2f2=Zg) =((Zf2 +

=Zg) 2) = (3 2). The

previousterm -reduces into2.

Inthe -calculustheproblemis pre-cookedinto 1["]= ?



(Z["] 1["])which-reduces into1["]= ?



(Z["])[1["]:id]andsubsequentlyinto1["]= ?



Z["Æ(1["]:id)]andinto1["]= ?



Z[id]and nallyinto1["]= ?



Z giving the corresponding sole solution fZ 7! 1["]g. This corresponds to the above grafting solution in

s

e

. On theone side,(Z["] 1["])fZ7!1["]g=(((1 ["])["]) 1["])=

 (1[" 2 ] 1["])=  1[" 2 ][1["]:id]=  1[" 2 Æ(1["]:id)] = 

1["]. Onthe otherside, turningback thepre-cooking transformation,this corresponds

tothesubstitutionsolutionf2=Zgfortheoriginalproblemin

dB

(X)asabove.

Notice that f1=Zgis notasubstitutionsolutionofthe previousproblem, sincefor anyde Bruijnindex

nwehave(Z) fn=Zg=(Zfn +

=Zg)=(n+1). 

Thefollowingexampleillustrateswhypre-cookingof-termsbeforeapplyinguni cationrulesisessential.

Example4.6 (Continuing example 4.5) In the s

e

-calculus, when normalizingthe HOU problem 2 = ?



(Z 2)beforepre-cookingweobtain2= ?

se Z

1

2,whosesolutionsarethegraftingsfZ7!1gandfZ7!3g.

Aspreviouslymentionedf1=ZgisnotasubstitutionsolutionoftheoriginalHOUproblem. Analogously,in

the-calculus,whennormalizingthecorrespondingproblem1["]= ?  (Z 1["])weobtain1["]= ?  Z[1["

]:id],whosesolutionsarefZ7!1gandfZ7!1[" 2

]ggivenrisetothesameproblem. 

4.2 Type inference

Inordertoinfertypesof-terms (or-termsors

e

-terms)wedealwithnewsetsoftypevariables

i and

context variables

i

, i2 N. Essentially, wewill take asinputof a typeinference problem atermwithout

knowingitstypeandcontextandasoutputwewillformulatea rstorderuni cationproblem ontypeand

context variables. Well-typedness of the input term will then corresponds to solvabilityof the generated

rstorder uni cationproblem. Hereweillustratethegeneralmethod abovementionedusing thelanguage

of thes

e

-calculus. Simplemodi cationsaccordingtothe typing rulesof theselectedlanguagewill adapt

thismethod toothersettings.

Let M be a s

e

-term. Initially, we introduce new variables for the type and for the context of each

subterm of M. Then M canbeseenas a newterm M 0

with allits subterms decoratedwith one di erent

typevariableassubscriptandone di erentcontextvariableassuperscript.

Example4.7 ( A :( B :( C :(2 1 1 (3 2 2 1 3 3 ) 4 4 ) 5 5 ) 6 6 ) 7 7 ) 8 8 , where  i and i

, i = 1;:::;8 are new mutually

di erenttypeandcontextvariables,isthedecoratedversionofthe-term 

A : B : C :(2 (3 1)). 

Afterwards,weapplythesetoftransformation rulesinTable1forpairsoftheformhR ;Ei,whereR is

aset ofdecorated termsand E aset of equationsontype andcontext variables. Theapplication of these

transformationrulesbeginfromtheparhR

0

;;i, whereR

0

isthesetofalldecoratedsubtermsofM 0

.

Noticethat thetransformation rules in theTable 1are builtaccordingto thetyping rulesof the s

e

-calculus. Afterthe application of each of thetransformation rulesthe size of thecurrentset of decorated

subterms R decreasesbyone. Consequently,theapplication of these rulesbeginningfrom thepairhR

0 ;;i

nishesafter a nitenumberofsteps(exactly asmanystepsassubtermsin M)givingasresultanempty

setofdecoratedtermsandasetE

f

ofequationontypeandcontextvariables. E

f

isa rstorderuni cation

problemontypeandcontextvariables.

Finally,ouralgorithmterminatesbyapplyingany rstorderuni cationalgorithmtoE

f

. Iftheuni cation

algorithmfailsthenourtermisill-typed. Otherwise,iftheuni cationalgorithmsucceeds,themostgeneral

(15)

e (Var) hR[f1  g;Ei ! hR ;E[f =: 0 gi, where 0

isafreshcontextvariable;

(Varn) hR[fn  g;Ei ! hR ;E[f = 0 1 ::: 0 n 1 :: 0 gi, where 0 and 0 1 ;:::; 0 n 1 are

freshcontextandtypevariables;

(Lambda) hR[f( A :M 1  1 ) 2  2 g;Ei ! hR ;E[f 2 =A! 1 ; 1 =A: 2 gi; (App) hR[f(M 1  1 N 2  2 ) 3  3 g;Ei ! hR ;E[f 1 = 2 ; 2 = 3 ; 1 = 2 ! 3 gi; (Sigma) hR[f(M 1  1  i N 2  2 ) 3  3 g;Ei ! hR ;E[f 1 =  3 ; 1 =  0 1 ::: 0 i 1 : 2 : 2 ; 3 =  0 1 ::: 0 i 1 : 2 gi, where  0 1 ;:::; 0 i 1

are fresh type variables and in the case

thati=1thesequence 0 1 ::: 0 i 1 isempty; (Phi) hR[f(' i k M 1  1 ) 2  2 g;Ei ! hR ;E[f 1 =  2 ; 2 =  0 1 ::: 0 k +i 1 : 0 ; 1 =  0 1 ::: 0 k 1 : 0 gi, where 0 and 0 1 ;:::; 0 k +i 1

arefreshcontextandtype

vari-ables and in the case that k  1 respectivelyk = 0 and

i = 1 the sequences  0 1 ::: 0 k 1 respectively  0 1 ::: 0 k +i 1 are empty; (Meta) hR[fX  g;Ei ! hR ;E[f = X ; =A X gi, where X `X :A X ;

the constructionof and A is donefrom thebindings given in the resultinguni er corresponding to the

outermostcontextandtypevariablesselectedin thedecorationofM.

Correctness and completeness of this method is a direct consequence from the correctness and

com-pleteness of the rst order uni cation and of the typing rules of the s

e

-calculus used to construct the

transformationrulesinTable1.

Example4.8 (ContinuingExample4.7)TheinitialinputforthesetofinferencerulesishR

0 ;;i,whereR 0 = f2 1  1 ;3 2  2 ;1 3  3 ;(3 2  2 1 3  3 ) 4  4 ;(2 1  1 (3 2  2 1 3  3 ) 4  4 ) 5  5 ;( C :(2 1  1 (3 2  2 1 3  3 ) 4  4 ) 5  5 ) 6  6 ;( B :( C :(2 1  1 (3 2  2 1 3  3 ) 4  4 ) 5  5 ) 6  6 ) 7  7 ; ( A :( B :( C :(2 1  1 (3 2  2 1 3  3 ) 4  4 ) 5  5 ) 6  6 ) 7  7 ) 8  8 g.

In the sequel, we show the steps of the application of the transformation rules. For convenience we

apply the rules in an speci c order (from smaller to bigger subterms), but the application of the rules is

nondeterministic. Applyingtherulesinanyorderwewillobtaindi erentsetsofequationsthatcorrespond

tothesameuni cationproblem.

hR 0 ;;i ! Var hR 1 =R 0 nf1 3 3 g;E 1 =f 3 = 3 : 0 1 gi ! Varn hR 2 =R 1 nf2 1 1 g;E 2 =E 1 [f 1 = 0 1 : 1 : 0 2 gi ! Varn hR 3 =R 2 nf3 2 2 g;E 3 =E 2 [f 2 = 0 2 : 0 3 : 2 : 0 3 gi ! App hR 4 =R 3 nf(3 2  2 1 3  3 ) 4  4 g;E 4 =E 3 [f 2 = 3 ; 3 = 4 ; 2 = 3 ! 4 gi ! App hR 5 =R 4 nf(2 1 1 (3 2 2 1 3 3 ) 4 4 ) 5 5 g;E 5 =E 4 [f 1 = 4 ; 4 = 5 ; 1 = 4 ! 5 gi ! Lambda hR 6 =R 5 nf( C :(2 1 1 (3 2 2 1 3 3 ) 4 4 ) 5 5 ) 6 6 g;E 6 =E 5 [f 6 =C! 5 ; 5 =C : 6 gi ! Lambda hR 7 =R 6 nf( B :( C :(2 1 1 (3 2 2 1 3 3 ) 4 4 ) 5 5 ) 6 6 ) 7 7 g;E 7 =E 6 [f 7 =B! 6 ; 6 =B: 7 gi ! Lambda h;=R 7 nf( A :( B :( C :(2 1 1 (3 2 2 1 3 3 ) 4 4 ) 5 5 ) 6 6 ) 7 7 ) 8 8 g;E 8 =E 7 [f 8 =A!  7 ; 7 =A: 8 gi

Nowthereaderisinvitedtoapplyhis/herpreferred rstorderuni cationalgorithmforresolvingthe

uni -cationproblemE 8 =f 3 = 3 : 0 1 ; 1 = 0 1 : 1 : 0 2 ; 2 = 0 2 : 0 3 : 2 : 0 3 ; 2 = 3 ; 3 = 4 ; 2 = 3 ! 4 ; 1 = 4 ; 4 = 5 ; 1 = 4 ! 5 ; 6 =C! 5 ; 5 =C : 6 ; 7 =B! 6 ; 6 =B: 7 ; 8 =A! 7 ; 7 =A: 8

gandthen to resolve

the bindings of the resulting uni er (if it exists) for givingappropriate contexts and types for the input

-term. 

4.3 Inhabitation and higher order logics

GivenatypeAandacontextofvariabledeclarations ,theinhabitationproblemconsistin ndingaterm

M such that ` M : A. Using the open term approach, the problem can be formulated as nding a

(16)

(Abs)

`x: A:M :x: A:B

(Appl)

`(M N):BfN=xg

Figure8: Rules(Abs)and(Apl)fortheCC typesystem

constructedatthesametimeastheproofderivationofAisdonebyapplyingthetypingrulesinabottom-up

mannerandintroducingnewmeta-variablesfortheunknownterms.

For the simply-typed -calculus this problem is decidable. In fact, since provability in the minimal

propositionalintuitionisticlogicisdecidable,thetermMcanbebuiltdirectlyfromtheproof-treederivation

of`

I

A, whereis theset oftypesin ,asexplainedbefore. However,whenwemovetoa rstorderor

ahigherorder intuitionisticlogicand,in consequence,weextendthetypesystemto handlequanti cation,

the problem becomes much more complicated. In [47], it has been presented a semi-algorithm to solve

the inhabitation problem via the 

L

-calculus and open terms. It uses the fact that 

L

is con uent on

substitution-closedtermsandweaklynormalizing,evenfordependenttypesettingsofthecalculus.

Although rst and higher order logics are out of the scope of this paper, we give some hints of the

inhabitationproblemforthesekindoflogics. See[20]foracompletedescriptionofatermsynthesisalgorithm

intheCubeofTypeSystemsand[47]forasimilaralgorithmviaexplicitsubstitutionsandopenterms.

TheDependentTypetheory,namely[29],isaconservativeextensionofthesimply-typed-calculus.

It allowsa nerstrati cation ofterms bygeneralizingthefunction spacetype. In fact,in , thetypeof

afunction x: A:M is x: A:B where B (the typeof M)maydepend on x. Hence,the typeA! B of the

simply-typed -calculus isjust anotation in for the product x: A:B where x doesnot appear free in

B. The Calculusof Constructions, namely CC, [15, 16] extends the-calculus with polymorphismand

constructionsoftypes. Fromalogicalpointofview,andCC allowrepresentationofproofsin the rst

andhigherorderintuitionisticlogic, respectively. Viathetypes-as-proofsprinciple,atermoftypex: A:B

isaproof-termoftheproposition8x:A:B.

Terms in these calculi can be variables, applications, or abstractions, like in classical -calculus, or

twonew kindof terms: products (x: A:B), and sorts (Type;Kind). Term and typesbelong to the same

syntacticalcategory. Thus, x: A:B is aterm, aswell as x: A:M. However,termsarestrati ed in several

levels according to a type discipline. For instance, given an appropriate context of variable declarations,

x: A::M :x: A::B, x: A::B : Type,and Type: Kind. The termKind cannotbe typedin any context,

but it isnecessarysince acirculartyping as Type: Typeleads to theGirard'sparadox[25]. In Fig.8we

giverules(Abs)and(Appl)fortheCC typesystem.

The 

L

-calculus has been extended with products for the  and CC-type systems in [45]. These

variants satisfy the same properties as the simply-typed version: con uent on substitution-closed terms,

weakly-normalizing,andsubjectreduction. Forfurtherdetails wereferto [45].

Example4.9 We can proof the rst order predicate (8x:(P x))! (P c) by nding a term X of type

(x: A:(P x))! (P c) in acontext where the termc has thetype A and P has thetype A! Type. The

bottom-upapplicationofrule (Abs)resultsinatermX havingtheformy:(x: A:(P x)) :Y where Y isa

term oftype (P c) in acontext where the variabley hasthe typex: A:(P x) . IfweinstantiateY with

the term (y c), which is a well typed term of type(P c), we obtainthe term y:(x: A:(P x)) :(y c) of

typex:(x: A:(P x) ):(P c) . Notice that in this examplewehaveused themeta-variablesX andY and

theinstantiationmechanismofmeta-variablestobuildincrementallyaproof. 

Typing ofmeta-variables is morecomplicatedin dependent-typesystemsthan in thesimply-typecase.

Sincemeta-variablescanappearin terms,types,andcontexts,thetypingrulesshould takecareofpossible

circulardependences.

5 Conclusion

The -calculus usesan externaland atomic operationto compute thesubstitutions of variables byterms.

(17)

L e *  d Con uence Mv Mv  ^  ^  ^ Gnd Gnd Gnd Gnd Normalization Wk Wk Wk Wk PSN PSN PSN PSN PSN Composition  ^  ^  _  ^  _  _   ?  _  _ Finitary 1 st -order  ^  ^  _  ^  ^  ^  ^  _  _ Variables dB dB dB dB dB dB dB Nm Lv Numberof rules 13 12 13 y 19 13 8 19 6 10 y -reduction  ^  ^  ^  ^   z  ^  ^  ^  ^ Reference [1] [44] [32] [17] [43] [38] [35] [8] [39] 

^ : Thegeneralpropertyholds.



_ : Thepropertydoesnothold.



 : Thepropertyholdswithrestrictions.

Mv : Con uenceonsemi-openexpressions,i.e. onlywithmeta-variablesofterms.

Gnd : Con uenceongroundexpressions.

Wk : Weaknormalizationontypedterms.

PSN : Preservationofstrongnormalization.

dB : DeBruijnindicesnotationofvariables.

Nm : Variablenames.

Lv : DeBruijnlevelsnotationwithvariablenames.

? : Restrictedcomposition. Inparticular,the

d

-calculusdoesnotallowsimultaneous

substitutions.

y : Numberofschemes. These-calculusisnot nitary.

z : Big-stepsemanticof -reduction. The



-calculusdoesnotsimulateeachstepof

-reduction.

Figure9: Somecalculiofexplicitsubstitutions

of theformallanguageby meansofspecial constructorsand reductionrules. There areseveral versions of

calculiof explicit substitutions. Figure 9 summarizesthe main characteristics of someof them. All these

calculiimplementthe -reductionbymeansofalazy mechanismofreductionofsubstitutions.

Inthis paperwehaveexplored newdevelopmentsandapplications ontwoofthemostsuccessfulstyles

ofexplicitsubstitution: and s

e .

References

[1] M. Abadi, L. Cardelli, P.-L. Curien, and J.-J. Levy. Explicit Substitutions. Journal of Functional

Programming,1(4):375{416,1991.

[2] M. Ayala-Rincon and F. Kamareddine. Uni cation via s

e

-Style of Explicit Substitution. In 2nd

International Conference on Principles and Practice of Declarative Programming, Montreal, Canada,

September2000.ACM Press.

[3] H.P. Barendregt. The LambdaCalculus : Its SyntaxandSemantics (revisededition). NorthHolland,

1984.

[4] H.P.Barendregt. -calculiwithtypes. Handbook of Logic inComputer Science,II,1992.

[5] B.Barras,S.Boutin,C.Cornes,J.Courant,J.C.Filliatre,E.Gimenez,H.Herbelin,G.Huet,C.Mu~noz,

C.Murthy,C.Parent,C.Paulin,A. Sabi,andB.Werner. TheCoqProofAssistantReferenceManual

(18)

ferenceonRewritingTechniquesandApplications(RTA'2000),July2000.

[7] R.Bloo.PreservationofTerminationforExplicitSubstitution.PhDthesis,DepartmentofMathematics

andComputingScience,EindhovenUniversityofTechnology,1997.

[8] R. Bloo and K.H. Rose. Preservation ofstrong normalisation in named lambda calculiwith explicit

substitutionandgarbagecollection.InProc. CSN-95: Computer ScienceintheNetherlands,November

1995.

[9] D. Briaud. Higher order uni cation asatyped narrowing. Technical report, CRIN report 96-R-112,

1996.

[10] A. Church. An unsolvableproblem of elementary numbertheory. American Journal of Mathematics,

58:345{363,1936.

[11] A.Church. Aformulationofthesimpletheoryoftypes. JournalofSymbolicLogic,5:56{68,1940.

[12] A.Church. The Calculi ofLambda-Conversion. PrincetonUniversityPress,1941.

[13] H.CirsteaandC.Kirchner. CombiningHigher-OrderandFirst-OrderComputationUsingp-Calculus:

Towardsa Semanticsof ELAN. In D. M. Gabbay and M. de Rijke, editors, Frontiers of Combining

Systems2,StudiesonLogicandComputation,7,chapter6,pages95{121.ResearchStudiesPress/Wiley,

1999.

[14] H.CirsteaandC.Kirchner.IntroductiontotheRewritingCalculus.RapportdeRecherche3818,INRIA,

December1999.

[15] T.Coquand. Une Theorie de Constructions. Thesededoctorat,U.ParisVII,1985.

[16] T.Coquand and G.Huet. TheCalculus ofConstructions. Information and Computation, 76:96{120,

1988.

[17] P.-L.Curien,T.Hardin,andJ.-J.Levy. Con uencePropertiesof WeakandStrongCalculiofExplicit

Substitutions. Journal of the ACM, 43(2):362{397,1996. AlsoasRapportde Recherche INRIA 1617,

1992.

[18] H.B.CurryandR. Feys. Combinatory Logic, volume1. NorthHolland,1958.

[19] N.G. de Bruijn. Lambda-CalculusNotation with Nameless Dummies, aToolfor Automatic Formula

Manipulation,withApplicationto theChurch-RosserTheorem. Indag. Mat.,34(5):381{392,1972.

[20] G. Dowek. A complete proof synthesis method for type systems of the cube. Journal of Logic and

Computation,3(3):287{315,June1993.

[21] G.Dowek,T.Hardin,andC.Kirchner.Higher-orderUni cationviaExplicitSubstitutions.Information

andComputation,157(1/2):183{235,2000.

[22] G.Dowek, T. Hardin,C. Kirchner, and F. Pfenning. Uni cationvia explicitsubstitutions: Thecase

of higher-orderpatterns. In M.Maher, editor, Proceedings of the Joint International Conference and

Symposiumon Logic Programming,Bonn,Germany,September1996. MITPress.

[23] W. Farmer. A Uni cation Algorithm forSecond-Order Monadic Terms. Annals of Pure andApplied

Logic, 39:131{174,1988.

[24] M.C.F.Ferreira,D. Kesner,andL.Puel. Lambda-calculiwithexplicitsubstitutions andcomposition

which preservebeta-strong normalization. In Michael Hanus and Mario Rodrguez-Artalejo, editors,

AlgebraicandLogicProgramming,5th InternationalConference,ALP'96, volume1139ofLNCS,pages

(19)

[25] Jean-Yves Girard. Interpretation Fonctionelle et Elimination des Compures de l'Arithmetic d'Ordre

Superieur. Thesededoctorat,UniversiteParisVII,1972.

[26] W. Goldfarb. The Undecidability of the Second-Order Uni cation Problem. Theoretical Computer

Science,13(2):225{230,1981.

[27] M.J.C.Gordonand T.F.Melham. Introduction toHOL: ATheorem Proving Environmentfor Higher

OrderLogic. CambridgeUniversityPress,1993.

[28] B.Guillaume. Thes

e

-calculusDoesNot PreserveStrongNormalization. Journal of Functional

Pro-gramming,1999. Toappear.

[29] R.Harper,F.Honsell,andG.Plotkin. Aframeworkforde ninglogics. Journalofthe Association for

ComputingMachinery,40(1):143{184,1993.

[30] J.R. Hindley. Basic Simple Type Theory. Number42 in Cambridge Tracts in TheoreticalComputer

Science.CambridgeUniversityPress,1997.

[31] G.Huet. AUni cationAlgorithmforTyped-Calculus. TheoreticalComputer Science,1:27{57,1975.

[32] F. Kamareddine and A. Ros. A -calculus a la de Bruijn with Explicit Substitutions. In Proc. of

PLILP'95, volume982ofLNCS,pages45{62.Springer,1995.

[33] F.KamareddineandA.Ros.Extendinga-calculuswithExplicitSubstitutionwhichPreservesStrong

Normalisationinto aCon uentCalculus onOpenTerms. Journalof Functional Programming,7:395{

420,1997.

[34] F.KamareddineandA.Ros.Relatingthe-ands-StylesofExplicitSubstitutions.JournalofLogic

andComputation,10(3):349{380,2000.

[35] D. Kesner. Con uence properties of extensional and non-extensional-calculi with explicit

substitu-tions(extended abstract). In H. Ganzinger, editor, Proceedings of the Seventh International

Confer-enceon Rewriting Techniques andApplications (RTA-96),volume1103ofLNCS,pages184{199,New

Brunswick,NewJersey,1996.Springer-Verlag.

[36] C.KirchnerandC.Ringeissen.Higher-orderEquationalUni cationviaExplicitSubstitutions.InProc.

Algebraic andLogic Programming,volume1298ofLNCS,pages61{75.Springer,1997.

[37] S.C.Kleene. -de nabilityandrecursiveness. DukeMathematical Journal,2:340{353,1936.

[38] P. Lescanne. From  to  aJourney Through Calculiof Explicit Substitutions. InProceedings of

the21stAnnualACMSIGPLAN-SIGACTSymposiumonPrinciplesofProgrammingLanguages,pages

60{69,January1994.

[39] P. Lescanne and J. Rouyer-Degli. Explicit substitutions with de Bruijn's levels. In J. Hsiang,

edi-tor, Proceedings of the International Conference on Rewriting Techniques and Applications (RTA-95),

volume914ofLNCS,pages294{308,ChapelHill,NorthCarolina,1995.Springer-Verlag.

[40] P.-A.Mellies.Typed-calculiwithexplicitsubstitutionsmaynotterminateinProceedingsofTLCA'95.

LNCS,902,1995.

[41] D. Miller. Prolog: An Introductionto the Languageandits Logic. Draft, DepartmentofComputer

ScienceandEngineering,ThePennsylvaniaStateUniversity,1998.

[42] RobinMilner,M.Tofte,andR.Harper. TheDe nition ofStandardML. MITPress,Cambridge,MA,

1991.

[43] C. Mu~noz. Con uence and preservation of strong normalisation in an explicit substitutions calculus

(extended abstract). In Proceedings of the Eleventh Annual IEEE Symposium on Logic in Computer

(20)

1298ofLNCS,pages224{234,Southampton (England),September1997.Springer.

[45] C.Mu~noz. Un calcul de substitutions pourla representation de preuves partielles en theorie de types.

PhDthesis,UniversiteParis7,1997. Englishversionin Rapportde recherche INRIARR-3309,1997.

[46] C.Mu~noz. Dependenttypesandexplicitsubstitutions. Acceptedforpublicationin thejournal

Mathe-maticalStructuresin ComputerScience.It alsoappearsasreportNASA/CR-1999-209722ICASENo.

99-43.,1999.

[47] C. Mu~noz. Proof-term synthesison dependent-type systemsvia explicit substitutions. Accepted for

publication in the journal Theoretical Computer Science. It also appears asreport

NASA/CR-1999-209730ICASENo.99-47.andwaspresentedintheInternationalWorkshop onExplicitSubstitutions:

TheoryandApplicationstoProgramsand Proofs-WESTAPP98,Tsukuba,Japan,2000.

[48] G.Nadathur. A ne-grainednotationforlambdatermsanditsuseinintensionaloperations. Technical

ReportTR-96-13,DepartmentofComputerScience,UniversityofChicago,May301996. Acceptedfor

publicationinJournalof Functional andLogicProgramming.

[49] G. Nadathur and D. S. Wilson. A Notation for Lambda Terms A Generalization of Environments.

Theoretical ComputerScience,198:49{98,1998.

[50] G.NadathurandD.S.Wilson. AFine-GrainedNotationforLambdaTermsandItsUsein Intensional

Operations. The Journalof Functional andLogic Programming,1999(2):1{62,1999.

[51] R. P. Nederpelt, J. H. Geuvers, and R. C. de Vrijer. Selected papers on Automath. North-Holland,

Amsterdam,1994.

[52] S.Owre,J.M.Rushby,andN.Shankar.PVS:Aprototypeveri cationsystem.InD.Kapur,editor,11th

International Conference onAutomatedDeduction (CADE),volume607ofLectureNotesin Arti cial

Intelligence,pages748{752,Saratoga,NY,June1992.Springer-Verlag.

[53] F.PfenningandC.Schurmann. Twelfuser'sguide,1.2. edition. TechnicalReportCMU-CS-1998-173,

CarnegieMellonUniversity,September1998.

[54] C.Prehofer. Progressin TheoreticalComputer Science. InR. V. Book, editor, Solving Higher-Order

Equations: FromLogic toProgramming.Birkhauser,1997.

[55] A. Ros. Contributions a l'etude de -calculs avec des substitutions explicites. These de doctorat,

UniversiteParisVII,1993.

[56] J. A. Robinson. A Machine-oriented Logic Based onthe Resolution Principle. Journal of the ACM,

12(1):23{41,January1965.

[57] K.H. Rose. ExplicitSubstitution -Tutorial&Survey. BRICS, LectureSeriesLS-96-3,Departmentof

ComputerScience, UniversityofAarhus, 1996.

[58] W. Snyder and J. Gallier. Higher-Order Uni cation Revisited: Complete Sets of Transformations.

JournalofSymbolic Computation,8:101{140,1989.

[59] A. N. Whitehead and B. Russell. Principia Mathematica. Cambridge University Press, Cambridge,

Imagem

Figure 3: The -calculus [1]
Figure 4: The rewrite system
Figure 5: Rewriting system of the s
Figure 7: Typing rules for the s
+2

Referências

Documentos relacionados

Figures 2 and 3 show pressure contours obtained by both Jameson and Mavriplis explicit scheme (1986) and Frink, Parikh and Pirzadeh explicit scheme (1991), respectively.. A CFL

En este sentido, el propósito del presente trabajo consiste en realizar un análisis textual de producciones fílmicas experimentales de cortometraje argentino –en el período

A concentração do leite, as fabricações do queijo prato e as análises sensoriais foram realizadas nos laboratórios de tecnologia e de análise sensorial do

In affective empathy, all indices (total, explicit, and implicit scores for both positive and negative stimuli) were significantly higher in the manic patients compared to those in

Explicit- water molecular dynamics (MD) computer simulations of hydrophobic solutes, for instance, give evidence of capil- lary evaporation on nanometer scales, i.e., the formation

And in order to test the method efficiency, a microindentation experiment that represents a severe contact problem was simulated using explicit and implicit time

They do not use explicit substitutions, nor n-ary contractions, while they use interaction nets (so no explicit axioms and cut link) and small-step exponential rules.. Both

The efficiency of explicit high-order compact scheme and efficient Mehrstellen - based V-cycle multigrid acceleration for the Poisson equation are combined together