Algebraic theories in the presence of binding operators, substitution, etc. Chung Kil Hur Joint work with Marcelo Fiore Computer Laboratory University of Cambridge 20th March 2006
Overview First order syntax: modelled by algebras on Set First order syntax with bindings: modelled by subst-algebras (binding-algebras) on Set F First order syntax with equations: modelled by algebraic theories (lawvere theories, or variety of algebras). First oder syntax with bindings and equations: equational theories by Kelly and Power (problematic). New equational theories.
1 Abstract Syntax with Binding First order syntax without binding First order syntax with binding Substitution Algebras 2 Equational Theories Classical approach New view on equations Examples of equations
Definition and Example Signature for First Order Syntax S = (O, a) O is a set of operators a is an arity function from O to N Terms built from Signature Term V := V V is a set of variables f (Term 1 V,..., Termn V ) f O, a(f ) = n Example: Group O = {e, i, m} a(e) = 0, a(i) = 1, a(m) = 2 V = {x, y, z,...} Term V = {x, e, m(x, m(y, z)), m(e, m(i(x), y)),...}
Categorical Construction Base Category: Set of sets and functions. Endofunctor: ΣX = f O X a(f ) Example: Group ΣX = 1 + X + X 2 State Set Depth Group S 0 S 1 V + ΣS 0 0 x, y, z,..., e S 2 V + ΣS 1 1 x, e, i(e), i(x), m(e, x),... S 3 V + ΣS 2 2 x, e, i(x), m(e, x), m(x, i(e)),....... S Term V <..., m(i(i(x)), m(x, i(e))),... Free Monad of Σ: TX = µa.x + ΣA with X + ΣTX =[η X,τ X] TX
Algebras Definition of Σ-alg objects: (X, s : ΣX X) where X, s in Set morphisms: f : (X, s) (Y, t) where f : X Y in Set satisfying ΣX s X Σf f ΣY t Y Example: Group objects: (X, 1 + X + X 2 [e,i,m] X) morphisms: f : (X, e, i, m) (Y, e, i, m ) where f : X Y 1 e X id 1 f Y e X i X f f Y Y i X 2 m X f 2 f Y 2 m Y
Free Algebras Free Algebras and Free monads (TX, ΣTX τx TX) F X Σ-alg F Set Free monad T = uf u (X, s) X u Universal property ΣTX Σ(i,r) # ΣY ΣTTX Σµ X ΣTX τ X η X TX X (i,r) # i Y r τ TX η TX τ X µ X TTX TX id TX
1 Abstract Syntax with Binding First order syntax without binding First order syntax with binding Substitution Algebras 2 Equational Theories Classical approach New view on equations Examples of equations
Definition and Example Signature for First Order Syntax with Binding S = (O, a) O is a set of operators a is an arity function from O to N, i.e.a(f ) = (a 1,..., a k ) Terms built from Signature Term({x 1,..., x n }) := {x 1,..., x n } f (x n+1,..., x n+a1.term({x 1,..., x n+a1 }),. x n+1,..., x n+ak.term({x 1,..., x n+ak })) where f O, a(f ) = (a 1,..., a k ) Example: Untyped λ-calculus O = {lam, app} a(lam) = (1), a(app) = (0, 0) Term(x 1, x 2 ) = {x 1, app(x 1, x 2 ), lam(x 3.app(x 1, app(x 2, x 3 )))...} Term({x 1,..., x n }) = {[t] α FV(t) {x 1,..., x n } in untyped λ-calculus}
Category of Presheaves Definitions F objects finite cardinals, i.e., {x 1 }, {x 1, x 2 },... let n be {x 1,..., x n } morphisms set functions from n to m Set F objects functors from F to Set morphisms natural transformations between functors Interpretations X Set F : a language. X(n): set of terms in context {x 1,..., x n }, i.e.{t x 1,..., x n t} X(n) X(ρ) X(m): x 1,..., x n t x 1,..., x m t[x ρ(1) /x 1,..., x ρ(n) /x n ] Presheaf of variables and Type constructor for context extension V Set F : V(n) = {x 1,..., x n }, V(ρ) = ρ δ : Set F Set F : (δx)(n) = X(n + 1), (δx)(ρ) = X(ρ + 1)
Categorical Construction Base Category: Set F Endofunctor: Σ(X) def = f O 1 i k a(f )=(a i) 1 i k Example: λ-calculus ΣX = δx + X 2 δ ai X State Set {x 1 } {x 1, x 2 } S 0 S 1 V + ΣS 0 x 1 x 1, x 2 S 2 V + ΣS 1 λx 1.x 1 x 1, x 1 x 1, λx 2.x 1, λx 2.x 2 x 1, x 2, x 1 x 2, λx 3.x 3,... S 3 V + ΣS 2 (λx 1.x 1 )(λx 1.x 1 ), λx 1.λx 2.x 1,... x 1,(x 1 x 1 )(λx 2.x 2 ), λx 2.λx 3.x 3,... x 2,(x 1 x 2 )(λx 3.x 3 ), λx 3.λx 4.x 3,........ S Term Term( ) Term({x 1 }) Term({x 1, x 2 }) Free Monad of Σ: TX = µa.x + ΣA with X + ΣTX =[η X,τ X] TX
Algebras Example: λ-calculus objects: (X, δx + X 2 [lam,app] X) morphisms: f : (X, lam, app) (Y, lam, app ) where f : X Y δx lam X δf f δy Y lam X 2 app X f 2 f Y 2 app Y Universality δtv + TV 2 δ(i,lam,app) # +(i,lam,app) #2 δy + Y 2 τ V η V TV V (i,lam,app) # i Y [lam,app]
1 Abstract Syntax with Binding First order syntax without binding First order syntax with binding Substitution Algebras 2 Equational Theories Classical approach New view on equations Examples of equations
Motivations for substitution as an algebraic operation We can express operations involving substitution, e.g.β equations in λ-calculus. It ensures semantics substitution lemma, i.e.compositionality of substitution. It automatically verifies some structural rules related to substitution, e.g.syntactic substitution lemma and admissibility of cut.
Substitutions on concrete terms σ k,n : (x 1,..., x k t); (x 1,..., x n u 1,..., u k ) x 1,..., x n t[u 1 /x 1,..., u k /x k ] Example: λ-calculus σ k,n (t[x 1,..., x k ]; u 1,..., u k ) = u i if t = x i (σ k,n (t 1 ; u 1,..., u k ))(σ k,n (t 2 ; u 1,..., u k )) if t = t 1 t 2 λx n+1.σ k+1,n+1 (t 1 [x 1,..., x k+1 ]; u 1,..., u k, x n+1 ) if t = λx k+1.t 1 [x 1,..., x k+1 ]
Categorical Construction Substitution: Function from Substitutable Pairs to Term Substitutable Pair: (x 1,..., x k t); (x 1,..., x n u 1,..., u k ) Type Constructor for Substitutable Pairs (X Y)({x 1,..., x n }) def = k N X({x 1,..., x k }) (Y({x 1,..., x n })) k / = {(t; u) k N, t X({x 1,..., x k }), u (Y({x 1,..., x n })) k }/ where is the equivalence relation generated by (t; u 1,..., u k ) (t ; u 1,..., u k ) iff r:k k X(r)(t) = t u i = u r(i) The tensor : Set F Set F Set F forms a closed monoidal structure with a unit V and suitable natural transformations α, λ, ρ.
Categorical Construction st X,e:V Y : ΣX Y Σ(X Y) is a natural transformation between two functors of type Set F V Set F Set F. Example: λ-calculus: st X,e:V Y : (δx + X X) Y = (δx) Y + (X X) Y δ(x Y) + (X Y) (X Y) σ : X X X is defined in the following way. ΣTV TV st TV,ηV :V TV Σ(TV TV) Σσ ΣTV τ id σ TV TV TV λ TV V TV η V id τ
Initial Algebra Semantics Category of S-subst-algebras Objects: (X, e : V X, h : ΣX X, sub : X X X) where (X, e, sub) is a monoid in Set F and (X, h) is an Σ-algebra such that the following diagram commutes. ΣX X st X,e:V X Σ(X X) Σ(sub) ΣX h id X X sub X h Morphisms: maps of Set F which are both Σ-algebra and monoid homomorphisms. Initial Object: (TV, η V : V TV, τ : ΣTV TV, σ : TV TV TV)
Abstract Theory Definition (Category of Σ-subst-algebras) Monoidal closed category C = (C,, I) Strong endofunctor Σ with a strength a st Objects: X = (X, e, h, sub), where (X, e, sub) is a monoid in C and (X, h) is a Σ-algebra such that the following diagram commutes. ΣX X st X,X Σ(X X) Σ(sub) ΣX h id X X sub X h Morphisms: maps of C which are both Σ-algebra and monoid homomorphisms. a A strength for Σ is a natural transformation of type Σ(X) Y Σ(X Y) satisfying some coherence conditions.
Abstract Theory Theorem If Σ has a free monad T then (TI, η I, σ, τ) is an initial Σ-subst-algebra, where τ : ΣTI TI is the free Σ-algebra of I and σ is given as follows: σ : TI TI st I,TI T(I TI) Tλ TI TTI µ I TI, where st : TX Y T(X Y) is the lifting of the strength st of Σ to its free monad T.
Abstract Theory Definition (Category of Σ-ptd-subst-algebras) Monoidal closed category C = (C,, I) u-strong endofunctor Σ with a u-strength a st for the forgetful functor u from I C Objects: X = (X, e, h, sub), where (X, e, sub) is a monoid in C and (X, h) is a Σ-algebra such that the following diagram commutes. ΣX X st X,e:I X Σ(X X) Σ(sub) ΣX h id X X sub X h Morphisms: maps of C which are both Σ-algebra and monoid homomorphisms. a A u-strength for Σ is a natural transformation of type Σ(X) uy Σ(X uy) satisfying some coherence conditions.
Abstract Theory Theorem (TI, η I, σ, µ I ) is an initial Σ-ptd-subst-algebra, where σ is given by the following composite: TI TI = TI u(η I : I TI) st I,ηI T(I u(η I )) = T(I TI) Tλ TI TTI µ I TI.
1 Abstract Syntax with Binding First order syntax without binding First order syntax with binding Substitution Algebras 2 Equational Theories Classical approach New view on equations Examples of equations
Motivation for equations Group Axioms Given a group algebra (X, e, i, m), (G1) x, y, z X m(m(x, y), z) = m(x, m(y, z)) (G2) x X m(e, x) = x (G3) x X m(i(x), x) = e β, η equations for λ-calculus Given a λ-calculus algebra (X, e, lam, app, sub), (β-eqn) t δx(n), u X(n) (η-eqn) t X(n) app(lam(x n+1.t), u) = sub(t; (x 1,..., x n, u)) lam(x n+1.app(t, x n+1 )) = t
Kelly & Power equational theories KP Theory Groups Sig S : C fp C Sig S : N Set (0, 1, 2) (1, 1, 1) ΣX = a C fp C(a, X) S(a) ΣX = a N Xa S(a) = 1 + X + X 2 TX = µa.x + ΣA TX = µa.x + ΣA TX = all terms freely generated from X TX = all group terms freely generated from a variable set X (Equation) (Equation) D : C fp C together with D : N Set : (1, 3) (2, 1) a C fp D(a) EL(a) T(a) E R(a) D(1) = 2 EL(1) T(1) E R(1) E L (1)(1) = m(e, x 1 ), E R (1)(1) = x 1 E L (1)(2) = m(i(x 1 ), x 1 ), E R (1)(2) = e D(3) = 1 EL(3) E R(3) T(3) E L (3)(1) = m(m(x 1, x 2 ), x 3 ), E R (3)(1) = m(x 1, m(x 2, x 3 ))
Free Constructions KP Theory There exists a finitary monad T such that T -Alg = Σ-alg/ EL=E R F C where Σ-alg/ EL=E R is a full subcategory of Σ-alg whose objects are Σ-algebras satisfying the equations. u Groups There exists a finitary monad T such that T -Alg = Σ-alg/ EL=E R F Set where Σ-alg/ EL=E R is a full subcategory of Σ-alg whose objects are group-algebras, i.e.(x, e, i, m) satisfying the group axioms G1, G2, and G3 u
Problems with applying K.P. theory to subst-algebras Recall: subst-algebras for λ-calculus Objects: (X, e : V X, lam : δx X, app : X 2 X, sub : X X X) satisfying V X e id X X λ X X sub X V id e X X ρ X X sub (X X) X sub id X X sub α X,X,X X (X X) sub X X X id sub (δx + X 2 ) X st X,e:V X δ(x X) + (X X) 2 δsub+sub 2 δx + X 2 [lam,app] id X X sub X [lam,app]
1 Abstract Syntax with Binding First order syntax without binding First order syntax with binding Substitution Algebras 2 Equational Theories Classical approach New view on equations Examples of equations
A new view on equational theories: Observation Example: Group Given a group algebra (X, 1 + X + X 2 [e,i,m] X), (G1) x, y, z X m(m(x, y), z) = m(x, m(y, z)) (G2) x X m(e, x) = x (G3) x X m(i(x), x) = e X X X m id X X X i,id X X id m X X G1 m X m! 1 e G3 X m X 1 X X X!,id e id id G2 X m
A new view on equational theories Observation Σ-alg 1 + X + X 2 [e,i,m] X D-alg X 3 + X + X E L X E R Definition (Equations for algebras) a category C and an endofunctor Σ Equation: a domain endofunctor D with functors E L and E R from Σ-alg to D-alg preserving base-objects of algebras, i.e.u E L = u and u E R = u. Σ-alg u C E L E R u D-alg
Free constructions Theorem If either (Cond1) C is cocomplete and Σ, D preserve colimits of ω-chains. (Cond2) C is cocomplete and well-copowered, and Σ preserves epimorphisms. then L E 1 Σ-Alg/ E1=E 2 Σ-Alg D-Alg K E 2 u u =uk u C
Free constructions Theorem If either (Cond1) C has coequalizers, pushouts and colimits of chains whose cardinals are less than or equal to a regular cardinal λ, and Σ, D preserve colimits of chains whose cardinals are equal to λ. (Cond2) C has coequalizers, pushouts and colimits of chains (whose cardinals are less than a regular cardinal λ) and is (λ-)well-copowered, and Σ preserves epimorphisms. then L E 1 Σ-Alg/ E1=E 2 Σ-Alg D-Alg K E 2 u u =uk u C
Sketch of the Proof ΣX X h
Sketch of the Proof ΣX 0 h 0 X 0
Sketch of the Proof ΣX 0 E Lh 0 E Rh 0 DX 0 X 0 h 0
Sketch of the Proof ΣX 0 X 0 X0 1 E Lh 0 E Rh 0 DX 0 h 0
Sketch of the Proof ΣX 0 ΣX 1 0 X 0 X0 1 E Lh 0 E Rh 0 DX 0 h 0
Sketch of the Proof ΣX 0 ΣX0 1 X 0 X0 1 E Lh 0 E Rh 0 DX 0 h 0 X 2 0
Sketch of the Proof ΣX 0 ΣX0 1 ΣX 0 2 X 0 X0 1 E Lh 0 E Rh 0 DX 0 h 0 X 2 0
Sketch of the Proof ΣX 0 ΣX0 1 ΣX 0 2 X 0 X0 1 E Lh 0 E Rh 0 DX 0 h 0 X 2 0 X 3 0
Sketch of the Proof ΣX 0 ΣX0 1 ΣX 2 0 ΣX 0 3 ΣX 1 X 0 X0 1 E Lh 0 E Rh 0 DX 0 h 0 X 2 0 X 3 0 X 1
Sketch of the Proof ΣX 0 ΣX0 1 ΣX 2 0 ΣX 0 3 ΣX 1 X 0 X0 1 E Lh 0 E Rh 0 DX 0 h 0 X 2 0 X 3 0 X 1 h 1
Sketch of the Proof ΣX 0 ΣX 1 X 0 X 1 E Lh 0 E Rh 0 DX 0 h 0 h 1
Sketch of the Proof ΣX 0 ΣX 1 X 0 X 1 E Lh 0 E Lh 1 E Rh 0 E DX 0 Rh 1 DX 1 h 0 h 1
Sketch of the Proof ΣX 0 ΣX 1 ΣX 2 h 0 X 0 X 1 X 2 E Lh 0 E Lh 1 E Lh 2 E Rh 0 E Rh 1 DX 0 E DX 1 Rh 2 DX 2 h 1 h 2
Sketch of the Proof ΣX 0 ΣX 1 ΣX 2 ΣX ω h 0 X 0 X 1 X 2 X ω E Lh 0 E Lh 1 E Lh 2 E Lh ω E Rh 0 E Rh 1 DX 0 E Rh 2 E DX 1 Rh ω DX 2 DXω h 1 h 2 h ω
1 Abstract Syntax with Binding First order syntax without binding First order syntax with binding Substitution Algebras 2 Equational Theories Classical approach New view on equations Examples of equations
Examples of Equations subst-algebras for λ-calculus Objects: (X, e : V X, lam : δx X, app : X 2 X, sub : X X X) satisfying V X e id X X λ X X sub X V id e X X ρ X X sub (X X) X sub id X X sub α X,X,X X (X X) sub X X X id sub (δx + X 2 ) X st X,e:V X δ(x X) + (X X) 2 δsub+sub 2 δx + X 2 [lam,app] id X X sub X [lam,app]
Examples of Equations Example: λ-calculus (β-eqn) t δx(n), u X(n) app(lam(x n+1.t), u) = sub(t; (x 1,..., x n, u)) δx X emb X X lam id sub X X X app (η-eqn) t X(n) lam(x n+1.app(t, x n+1 )) = t X id,! X 1 id up λe δx δx δ(x X) δapp δx X lam
Examples of Equations π-calculus Base category Set I ν : δx X, where δx = (V X) νx.νy.t = νy.νx.t t δ 2 X(n) νx n+1.νx n+2.t = νx n+1.νx n+2.t[x n+2 /x n+1, x n+1 /x n+2 ] δδx swap δδx δν δν δx δx ν ν X
Future Work Modelling DILL (Dual Intuitionistic Linear Logic) Modelling Dependent type languages. Develop the equational theories in pre-ordered setting, and apply them to Term Rewriting Systems. Find more applications of the equational theories. Example: the free-algebra models for the π-calculus by Ian Stark.