ebook img

Syntax and Semantics of Abstract Binding Trees PDF

0.34 MB·
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Syntax and Semantics of Abstract Binding Trees

Syntax and Semantics of Abstract Binding Trees JonathanSterlingandDarinMorrison 6 Abstractbindingtrees(abts)areageneralizationofabstractsyntaxtreeswhereoperators 1 0 mayexpressvariablebindingstructureaspartoftheirarities. Originallyformulatedby 2 PeterAczel[1],unisortedabtshavebeendeployedsuccessfullyastheuniformsyntactic n frameworkforseveralimplementationsofConstructiveTypeTheory,includingNuprl[3], a MetaPRL[13]andJonPRL[21]. J In Practical Foundations for Programming Languages [12], Robert Harper develops the 3 2 multi-sortedversionofabstractbindingtreesandproposesanextensiontoincludefamilies ofoperatorsindexedbysymbols,whichare,unlikevariables,subjecttoonlydistinctness- ] O preserving renaming and not substitution; furthermore, symbols do not appear in the L syntax of abts, and are only introduced as parameters to operators. This extension to . supportsymbolsisessentialforacorrecttreatmentofprogramminglanguageswithopen s c sums(e.g. ML’sexntype),aswellasassignablereferences. [ Inparallel,M. Fioreandhiscollaboratorshavedevelopedthecategoricalsemantics 1 forseveralvariationsofsecond-orderalgebraictheories[8,10,6,7];ofthese,thesimply v sortedvariantsareequivalenttoHarper’sabstractbindingtreesaugmentedwithanotion 8 9 ofsecond-ordervariable(metavariable). 2 The contribution of this paper is the development of the syntax and semantics of 6 0 multi-sorted nominal abts, an extension of second order universal algebra to support . symbol-indexedfamiliesofoperators. Additionally,wehavedevelopedthecategorical 1 0 semanticsforabtsformallyinConstructiveTypeTheoryusingtheAgdaproofassistant[18]; 6 we have also developed an implementation for abstract binding trees in Standard ML, 1 whichweintendtointegrateintotheJonPRLproofassistant[21]. : v i X 1 Categorical Preliminaries r a FixasetSofsorts;wewillsayτsortwhenτ S. Inthissection,wewilldevelopatheory ∈ ofsetsvaryingovercollectionsofS-sortedsymbols. Let I be the category of finite cardinals and their injective maps; then the comma construction I S, is the category ofcontexts ofsymbols whose objects are finite sets of ↓ symbols U and sort-assignments U s S, and whose morphisms are sort-preserving renamings;wewillwriteΥforasymbolcontext(U,s). 1 Remark1.1. Tobeprecise,I Sisanabuseofnotationforthecommacategory|−| ∆[S], ↓ I ↓ with|−| theforgetfulfunctorfromItoSet,and∆[S]( ) , Saconstantfunctorfrom1toSet. I ∗ Formally,anobjectofI Sis,then,atriple U, ,s withUanobjectinI, theuniqueobject ↓ h ∗ i ∗ in 1, andsafunction |U| S; an arrowρ : U, ,s V, ,t isacommuting triangle I h ∗ i h ∗ i likethefollowing: |ρ| |U| I |V| I I s t S Becausetheobject : 1isunique,wewillalwaysomititfromthedataofanobjectin ∗ I S. ↓ CopresheavesonI S ApresheafonacategoryCisacontravariantfunctorCop Set; ↓ whenC Dop,wecallthisacopresheaf (covariantpresheaf)onD. Therefore,acopresheaf ≡ onI SisafunctorI S Set;colloquially,suchacopresheafcanbethoughtofasaset ↓ ↓ thatvariesoversymbolcontexts. Thisleadstoaveryintuitivesettinginwhichtoconsidersetsthatvaryovercollections ρ ofS-sortedsymbols. Inparticular,foranymorphismΥ Υ0 inI S,anycopresheaf X : SetI↓S hasasymbol-renamingactionX(ρ) : X(Υ) X(Υ0). When↓thecopresheafXis clearfromcontext,wewillwritem ρforX(ρ)(m). Now, when m X(Υ) for a cop·resheaf X : SetI↓S, we can define the notion that m ∈ dependsonatmostasubcontextΥ ofΥ;thisiscalledsupport. 0 ρ Definition 1.2 (Support). When Υ Υ , we say that Υ supports m Υ (written 0 0 ∈ Υ I m)when,forallΥ ρ1,ρ2 Υ ,ifρ ρ = ρ ρthenm ρ = m ρ . ρ 0 00 1 2 1 2 ◦ ◦ · · Wecanalsoalwayscalculatetheleastsupportofatermm X(Υ ),writtensupp(m): 0 ∈ supp(m) , {Υ | Υ I m} ρ ρ Υ \ Υ 0 Intuitively,supp(m)istheexactsymbolcontextthatmdependson. 1.1 Sheavesontheatomicsite ρ When Υ Υ such that Υ I m for some m X(Υ ), we would expect that we can 0 ρ 0 ∈ workbackwardtoauniquem : Υsuchthatm ρ = m;whilstitisnotingeneralthecase 0 0 · forpresheavesX,thisispreciselythesheafconditionforcopresheavesonI Sunderthe ↓ atomictopology[16,p.126],whichwewilldefineinDefinition1.6. Thesheafconditionensuresthatthenotionofsupportiswell-behavedinthefollowing sense: ifsometermliesintwodifferentfibers,thenitmaybestrengtheneduniquelyintothe fiberofitssupport. 2 Definition1.3(Sievesandmatchingfamilies). AsieveSonanobjectCisasubfunctorof theYonedaembeddingy(C) , C[−,C],i.e. S y(C). ForapresheafXonthecategoryC,a v matchingfamilyforasieveSisanaturaltransformationφ : S X. Anamalgamationforφis anobjectm X(C)suchthatm f = φ (f)foreachf S(D),forallobjectsD. D ∈ · ∈ Definition1.4(Sitesandcoverages). Asiteisapair C,J ,withCacategoryof“worlds” h i andJaGrothendiecktopology(or“coverage”). AGrothendiecktopologyJ(orcoverage)is afamilyofsetsofsieves,indexedbyC-objects;thatis,foreachobjectC : C,J(C)istheset ofC-sieveswhichwillbesaidtocoverC. AtopologyJmustsatisfyseveralaxioms(see[16] fordetails). Definition1.5(Separationandsheafhood). Apresheafonasite C,J isapresheafonC; h i we saythatsucha presheafX is separated in case foreverysieve S J(C) andmatching ∈ familyφ : S X,thereisatmostoneamalgamationm X(C)forφ. Additionally,Xisa ∈ sheaf whenthereisexactlyonesuchamalgamation. Definition 1.6 (The atomic topology). The atomic coverage Jatm is the one in which all non-emptysievescover;inotherwords: Jatm(C) , {S v y(C) | DS(D)non-empty} Inthefuture,wewillwriteI[S]fortheGroSthendiecksite (I S)op,Jatm . Sheafhood ↓ ontheatomicsiteI[S]amountstothefollowingcondition,usingDefinition1.2: (cid:10) (cid:11) AcopresheafX : SetI↓S isasheafonI[S]justwhen,foralln X(Υ0),ifwehave ∈ ρ Υ Υ andΥ I n,thenthereisauniquem X(Υ)suchthatm ρ = n. 0 ρ ∈ · Therefore,asheafonI[S]isasetthatvariesoverS-sortedsymbolcontexts,whichhasa well-behavednotionofsupport. Anotherwaytoputitis,ifm X(Υ)only“uses”some ∈ ofthesymbolsavailableatworldΥ,there’sacanonicalwaytorestrictmtoaterminthe worldwhichcontainsonlythesymbolsthatituses. Constructionsonsheaves Everycategoryofsheavesonasitegivesrisetoatopos,which equipsuswithanumberofstandardconstructions,including(amongotherthings)the disjointunionofsheavesX Y,theproductofsheavesX Y,andtheterminalsheaf1. ⊕ ⊗ 2 Operators and signatures Avalence{~σ}[~τ].τspecifiesanexpressionofsortτwhichbindssymbolsin~σandvariables in~τ. τsort σi sort (i 6 m) τi sort (i 6 n) {σ ,...,σ }[τ ,...,τ ].τvalence 0 m 0 n 3 Anarity(~v)τspecifiesanoperatorofsortτwithargumentsofvalences~v. Wewillcall thesetofvalencesV ,andthesetofaritiesA . S S τsort vi valence (i 6 n) (v ,...,v )τarity 0 n FixafamilyofsheavesofoperatorsOa Sh(I[S]),indexedbyaritiesa AS;foreach ∈ ∈ Oa,arrowsinI Swilllifttorenamingsinoperators’symbolicparameters. Together,S ↓ andOaresaidtoformasignatureΣ , S,O . h i WewillwriteΥ(cid:13)ϑ : aincaseϑ O (Υ);notethatthisjudgmentenjoysthestructural a ∈ propertiesofweakeningandexchangeviafunctorialityofO, andstrengtheningviathe sheafcondition. Anoperatorsignatureisdefinedbyspecifying,foreacharitya,thesheaf O ,whose“elements”aretheoperatorsofaritya. a Examples Forinstance,consideraλ-calculuswithasinglesort,exp;wegiveitssignature Σ byassertingthefollowingaboutitsoperators: λ Υ(cid:13)lam : ([exp].exp)exp Υ(cid:13)fix : ([exp].exp)exp Υ(cid:13)ap : (.exp,.exp)exp TheserulescorrespondtothefollowingdefinitionofO: O([exp].exp)exp (cid:27) 1 1 ⊕ O(.exp,.exp)exp (cid:27) 1 Sofar,wehavemadenouseofsymbolsandparameters;however,considertheextension ofthecalculuswithassignables(references): Υ(cid:13)decl : (.exp,{exp}.exp)exp Υ,u : exp(cid:13)get[u] : ()exp Υ,u : exp(cid:13)set[u] : (.exp)exp LetS bethesheafofsymbolsofsortτ,asubobjectoftheYonedaembeddingofthe τ emptysymbolcontext,y( ): · S (Υ) , {u |Υ| | Υ(u) τ} τ ∈ ≡ Thentheaboverulescorrespondtothefollowingfamilyofsheaves: O(.exp,{exp}.exp)exp (cid:27) 1 O()exp (cid:27) Sexp O(.exp)exp (cid:27) Sexp 4 Declaringanewassignableconsistsinprovidinganinitialvalue,andanexpressionbind- ingasymbol(whichshallrepresenttheassignableinscope). NotethatthefunctorialityofO guaranteesforanyrenamingρ : Υ Υ ,afamilyofliftedmapsO (ρ) : O (Υ) O (Υ ) 0 a a a 0 natural in a, such that Υ (cid:13)O(ρ)(ϑ) : a when Υ(cid:13)ϑ : a. In particular, the renaming 0 Υ,u Υ,vshalltakeget[u]toget[v]. Inthefuture,wewillwriteϑ ρforO (ρ)(ϑ). a · 3 Contexts Ingeneral,wewillhavethreekindsofcontext: symbolic(parameter)contexts,variable contexts,andmetavariablecontexts. Thesymbolcontextshavealreadybeendefinedvia thecommaconstructionI S,buttheyalsoadmitasyntacticcharacterization, ↓ Υsctx τsort u < |Υ| sctx Υ,u : τsctx · Because,modulonotation,wehaveΥ I SjustwhenΥsctx,wewillusethesyntactic ∈ ↓ viewwhenitisconvenient. Contexts of variables are similar to contexts of symbols, except that they admit any renamings,notjusttheinjectiveones. Assuch,whenFisthecategoryoffinitecardinals andallfunctionsbetweenthem,thecommaconstructionF Sisthecategoryofvariable ↓ contexts. Asabove,wecangivethemanequivalentsyntactictreatment: Γ vctx τsort x < |Γ| vctx Γ,x : τvctx · A metavariable context consists of bindings of S-valences to metavariables; let VS , {v | vvalence} be the set of valences. Then, the category of metavariable contexts is the commaconstructionF VS,whichlikewiseadmitsanequivalentinductivedefinition: ↓ Θmctx vvalence m < |Θ| mctx Θ,m : vmctx · 4 Nominal Abstract Binding Trees LetthejudgmentΘ.Υ Γ M : τpresuppose1 Θmctx,Υsctx,Γ vctxandτsort,meaning k ‘ thatMisanabstractbindingtreeofsorts,withmetavariablesinΘ,parametersinΥ,and 1Inthejudgmentalmethod, aspioneeredbyPerMartin-Lo¨f, aformofjudgmentispropoundedfirstby specifyingitsrangeofsignificance(i.e. thecircumstancesunderwhichitshallhaveameaning),andthen, ameaningexplanation(definition)forthejudgmentisgiven. Therangeofsignificanceofajudgmentis calleditspresupposition,andthemeaningofthejudgmentmayproceedbyinductionontheevidencethat thepresuppositionobtains.See[20]foramoredetailedexplanationofpresuppositionsandthejudgmental method. 5 variablesinΓ. LetthejudgmentΘ.Υ Γ E : vpresupposevvalence. Then,thesyntaxof k ‘ abstractbindingtreesisinductivelydefinedinfourrules: Γ x : τ 3 var Θ.Υ Γ x : τ ‘ k ‘ Θ m : {σ ,...,σ }[τ ,...,τ ].τ 0 m 0 n 3 Υ ui : σi (i 6 m) 3 Θ.Υ Γ Mi : τi (i 6 n) k ‘ Θ.Υ Γ m{u ,...,u }(M ,...,M ) : τ ‘mvar 0 m 0 n k ‘ Υ(cid:13)ϑ : (v ,...,v )τ 1 n Θ.Υ Γ Ei : vi (i 6 n) k ‘ app Θ.Υ Γ ϑ(E ,...,E ) : τ ‘ 0 n k ‘ Θ.Υ,~u :~σ Γ,~x :~τ M : τ k ‘ Θ.Υ Γ λ{~u}[~x].M : {~σ}[~τ].τ ‘abs k ‘ Abtsareidentifieduptoα-equivalence. 4.1 Calculatingfreevariables Wecaneasilycalculatethevariablesfreeinanexpressionbyrecursiononitsstructure: FV FV(x) { {x} var FV(Mi) {~xi (i 6 n) FV mvar FV(m{~u}(M0,...,Mn)) { i6n~xi FV(Ei) {~xi (i 6 nS) FV app FV(ϑ(E0,...,En)) { i6n~xi FV(M) {~xS FV FV(λ{~u}[~y].M) {~x\~y abs Becausethisisatotalrelation,henceforthwewillwriteFV(M)for~xwhenFV(M) {~x. 4.2 Calculatingfreesymbols WhereasthecalculationoffreevariablespivotedontheFV rule,thecalculationoffree var symbolswillpivotontheFS andFS rules,becausetheonlywayasymbolcanbe app mvar introducedisasaparametertoanoperatororasaparametertoametavariable. 6 FS FS(x) { { } var FS(Mi) {~ui (i 6 n) FS FS(m{~u}(M0,...,Mn)) {~u∪ i6n~ui mvar FS(Ei) {~ui (i 6 n)S FS app FS(ϑ(E0,...,En)) { |supp(ϑ)|∪ i6n~ui FS(M) {~u S FS FS(λ{~v}[~x].M) {~u\~v abs Becausethisisatotalrelation,henceforthwewillwriteFS(M)for~uwhenFS(M) {~u. 4.3 Renamingofsymbols Theonlyplacethatsymbolsappearinourcalculusisasparameterstooperators(unlike variables, symbols are not terms). Therefore, the functorial action of the operatorsheaf canbeliftedintotermsbyrecursionontheirstructure,viaapairofjudgmentsM ρ { N · and E ρ { F, presupposing ρ : Υ Υ0, and Θ.Υ Γ M : τ and Θ.Υ Γ E : v · k ‘ k ‘ respectively: x ρ { x •var · ρ(~u) ~v Mi ρ { Ni (i 6 n) ≡ · mvar m{~u}(M0,...,Mn) ρ { m{~v}(N0,...,Nn) • · Ei ρ { Fi (i 6 n) · app ϑ(E0,...,En) ρ { ϑ ρ(F0,...,Fn) • · · M ρ\~u { N · abs λ{~u}[~x].M ρ { λ{~u}[~x].N • · Above,thenotationρ\~umeanstheomissionofthevariables~ufromtherenamingρ. Becausetermsareidentifieduptoα-equivalence,therenamingjudgmentisfunctionalin itsinput,andsowearejustifiedinwritingM ρforNwhenM ρ { N. · · 4.4 Substitutionofvariables Variablesubstitutioninabtsisdefinedinductivelybyapairofjudgments,[N/x]M { M0 and[N/x]E { F: 7 x = y x # y / / [N/x]y { N var1 [N/x]y { y var2 [N/x]Mi { Mi0 (i 6 n) / [N/x]m{~u}(M0,...,Mn) { m{~u}(M00,...,Mn0 ) mvar [N/x]Ei { Fi (i 6 n) / app [N/x]ϑ(E0,...,En) { ϑ(F0,...,Fn) x <~y ~u # FS(N) ~y # FV(N) [N/x]M { M0 / [N/x]λ{~u}[~y].M { λ{~u}[~y].M0 abs1 x ~y ~u # FS(N) ~y # FV(N) ∈ / [N/x]λ{~u}[~y].M { λ{~u}[~y].M abs2 Intheremainder,wewillwrite[N/x]MforM0 when[N/x]M { M0,and N~ /~x M forthesimultaneoussubstitutionofN~ for~xinM. h i 4.5 Substitutionofmetavariables Metavariablesaresubstitutedbyabstractions; sinceametavariablemayonlyappearin anapplicationexpressionm{ }( ),wewillinstantiatetheabstractionatthesupplied ··· ··· parametersandarguments. Substitutionformetavariablesisdefinedinductivelybythe judgments[E/m]M { Nand[E/m]F { F0: /meta [E/m]x { x var m # n [E/n]Mi { Ni (i 6 n) /meta [E/m]n{~u}(M0,...,Mn) { n{~u}(N0,...,Nn) mvar1 m = n M~ /~x N { N0 N0 ~u ~v { N00 · /meta [λh{~u}[~x].iN/m]n{~v}(M~ ) { N00 mvar2 [E/m]Fi { Fi0 (i 6 n) /meta app [E/m]ϑ(F0,...,Fn) { ϑ(F00,...,Fn0 ) ~u # FS(E) ~x # FV(E) [E/m]M { N /meta [E/m]λ{~u}[~x].M { λ{~u}[~x].N abs 8 Therulesformetavariablesubstitutionarereminiscentofthe“hereditarysubstitutions” firstdevisedfortheConcurrentLogicalFrameworkbyWatkinsin[22]. Asusual,wewill write[E/m]MforNwhen[E/m]M { N. 5 Model Theory Let H , (I S F S)op; then we fix the functor category HS as our semantic universe, usingtheno↓tat×iono↓ftheFrenchschool,C , SetCop. LetV (Υ Γ) , {x |Γ| | Γ(x) τ}be τ k ∈ ≡ calledthepresheafofvariables;additionally,wehaveaprebsheafofsymbolsS (Υ Γ) , τ k {u |Υ| | Υ(u) τ}. Lastly,wehavethebpresheafofoperatorswitharitya,O (Υ Γ) , a ∈ ≡ k O (Υ) a 5.1 Substitutionmonoidalstructures ForanobjectP : HS,wewillusethenotationP[Γ]tomean P ;likewise,S{Υ}shall x |Γ| Γ(x) ∈ mean S . ForapresheafA : Handasort-indexedfamilyofpresheavesP : HS, u |Υ| Υ(u) Q wehavea∈noperbationA P,definedasacoendinthefollowingway: Q • b b (A P)(Υ Γ) , (Υ0k∆)∈HA(Υ0 ∆) S{Υ0}(Υ Γ) P[∆](Υ Γ) • k k × k × k Z Intuitively,thecoendconstructionA P providesthedataofasuspendedsubstitution • ofanA-term’svariablesbyP-terms. Usingthis,wecandefineatensorP QforP,Q : HS (cid:12) asfollows: (P Q) , P Q (τ S) b (cid:12) τ τ• ∈ Then,V istheunittothistensor. WewillsaythatanobjectP : HS isaΣ-monoidincase itisequippedwiththefollowingnaturaltransformationswhereνembedsvariablesintoP andς equipsP withanoperationforsimultaneoussubstitutionsofbvariables. Furthermore, νandς inducemapsν andςτ : Γ Υ Γ k ν ς V P P P (cid:12) V[Γ] νΓ P[Γ] Pτy(ΥkΓ) S{Υ} P[Γ] ςΥτkΓ Pτ × × 5.2 Thesignatureendofunctoranditsalgebras ForeachsignatureΣ S,O ,wehaveanendofunctorF : HS HS,whichisdefinedas Σ ≡ h i follows: b b FΣ(X)τ , Xyτi(σ~kτ~) ϑ∈aO(~v)τ{σ~}[Yτ~].τi∈~v 9 Then, a Σ-model is a Σ-monoid P which is equipped with an algebra α : F (P) P, Σ whichshallinterpretapplicationsofeachoperator. 5.3 Interpretationofterms The metavariable, symbol and variable contexts are interpreted for a model P as an environmentpresheafinthefollowingway: Θ.Υ k Γ P ,  Pτy(σ~kτ~)×S{Υ}×V[Γ] (m:{σ~}Y[τ~].τ)∈Θ   Then,theinte(cid:18)rpretation(cid:19)ofaterminamodelP isamapfromitsenvironmenttoP: Θ.Υ Γ M : τ : Θ.Υ Γ P k ‘ P k P τ Variablesareinterpretedbythemap Θ.Υ Γ x : τ whichprojectsthemfromthe k ‘ P environmentandembe(cid:18)ds them into the m(cid:19)ode(cid:18)l. Metava(cid:19)riables are resolvedby the map Θ.Υ Γ m{~u}(M~ ) : τ (where Θ m : {~σ}[~τ].τ) which projects their interpretation (cid:18) (cid:19) k ‘ P 3 fromtheenvironmentandinstantiatesitviasubstitution: (cid:20) (cid:21) Θ.Υ Γ m{u~}(M~ ):τ ~Θ.Υ Γ x:τ(cid:127) P k ‘ P Θ.Υ Γ k ‘ P P τ k P τ Pτy(σ~kτ~ς)σ~τkτ~ S{σ~} P[τ~(cid:20)] hπmπ1,φπ(cid:21)2,ψi (cid:18) (cid:19) νΓπ3 P[Γπ]x × × P[τ~] ψ,h~Θ.ΥkΓ‘M:τ(cid:127)Pi(M,τ)∈(M~,τ~) Θ.Υ Γ S{Υ} φ,hπuiu∈u~ S{σ~} k P Interpretationofoperatorapplicationsisthemostcomplicated. Recallthat,unlikein standardtreatmentsofuniversalalgebra,ourope(cid:18)ratorsare(cid:19)indexedbysymbolcollections; therefore, operators must pass through suitable renamings in order to be used in the interpretation. LetusbeginbyconstructingforeachoperatorΥ(cid:13)ϑ : athemorphism~ϑ(cid:127) P whichshallrenametheparametersoftheoperatorusingtheenvironment: ~ϑ(cid:127)P Θ.Υ Γ S{Υ} O k P π2 Oa(π(−))(ϑ) a WewillproceedusingtheF -algebraα,asfollows,bycomposingitwithamorphism (cid:18) (cid:19)Σ β from the environment into the signature endofunctor, which interprets the syntax of operatorapplications: Θ.Υ Γ β F (P) ατ P k P Σ τ τ 10 (cid:18) (cid:19)

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.