An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A...

34
Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion Laboratoire de Math´ ematiques Universit´ e de Savoie UMR 5127 An algebraic approach to higher-order theories and rewriting Tom Hirschowitz Brno, August 2010 Hirschowitz Algebraic higher-order rewriting 1/34

Transcript of An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A...

Page 1: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

Laboratoire de MathematiquesUniversite de Savoie UMR 5127

An algebraic approach to higher-order theoriesand rewriting

Tom Hirschowitz

Brno, August 2010

Hirschowitz Algebraic higher-order rewriting 1/34

Page 2: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

Original motivation

Understood from a talk by Fiore in Lyon:I will to explain variable binding by a λ-calculus limited to 2nd

order;I complex categorical picture.

Alternative point of view:I the λ-calculus perfectly explains variable binding;I simple categorical picture: cartesian closed categories.

Hirschowitz Algebraic higher-order rewriting 2/34

Page 3: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

Introduction

Here:

A categorical semantics forI higher-order rewriting (Klop, Nipkow, Wolfram), andI permutation equivalence (Bruggink).

In cartesian closed 2-categories.

Corollary: a semantics for variable binding in cartesian closedcategories.

Hirschowitz Algebraic higher-order rewriting 3/34

Page 4: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

Related work

Cartesian closed sketches (Kinoshita, Power, Takeyama andWells).

Bruggink’s permutation equivalence, Hilken’s 2-λ-calculus,Jacobs’ book.

Capriotti’s semantics for flat permutation equivalence insesqui-categories.

By extension, Fiore et al., my father and Maggesi.

Hirschowitz Algebraic higher-order rewriting 4/34

Page 5: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

Plan

1 Introduction.

2 The known case:I rewrite systems as fp 2-signatures,I their fp 2-categorical semantics.

3 Sketch of the cartesian closed case.

Hirschowitz Algebraic higher-order rewriting 5/34

Page 6: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

Types

Given a set X , let L0(X ) be the set of formulas, as generated bythe grammar:

A,B ::= 1 | x | A× B.

Proposition

This extends to a monad on Set with substitution as multiplication.

Definition

Let S0(X ) = L0(X )∗ × L0(X ) be the set of sequents over X .

Hirschowitz Algebraic higher-order rewriting 6/34

Page 7: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

1-Signatures

Definition

A 1-signature Σ = (X0,X1) consists of:

a set X0 of sorts,

a map X1 → S0(X0) of operations.

The latter amounts to a set indexed by sequents in S0(X0).

Hirschowitz Algebraic higher-order rewriting 7/34

Page 8: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

Example: combinatory logic

One sort X0 = {t}.Three operations X1 = {K ,S ,A}:

I K ,S : 1→ t,

I A : t, t → t,i.e.,

I K ,S 7→ ([], t),

I A 7→ ([t, t], t).

Hirschowitz Algebraic higher-order rewriting 8/34

Page 9: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

Non-example: the λ-calculus

Arity of λ: “tt → t”.

Not expressible by our arities.

Workarounds do exist.

Hirschowitz Algebraic higher-order rewriting 9/34

Page 10: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

A category of 1-signatures

Consider 1-signatures Σ = (X0,X1) and Σ′ = (Y0,Y1).A morphism Σ→ Σ′ consists of:

a map f0 : X0 → Y0,

a map f1 : X1 → Y1 making

X1 Y1

S0(X0) S0(Y0)

f1

S0(f0)

commute.

Hirschowitz Algebraic higher-order rewriting 10/34

Page 11: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

A category of 1-signatures

Proposition

This yields a category Sig1 of 1-signatures.

Hirschowitz Algebraic higher-order rewriting 11/34

Page 12: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

The term monad

Given a 1-signature Σ = (X0,X1), let L1(Σ) be the 1-signaturewith:

sorts X0,

operations A1, . . . ,An → A the termsx1 : A1, . . . , xn : An ` M : A in the language generated by Σ.

Proposition

L1 extends to a monad on Sig1.

Hirschowitz Algebraic higher-order rewriting 12/34

Page 13: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

Parallel operations

For a 1-signature Σ = (X0,X1), let Σ|| be the pullback:

Σ|| X1

X1 S0(X0).

Example: L1(Σ)|| is the set of parallel terms over Σ.

Proposition

This extends to a functor (−)|| : Sig1 → Set.

Hirschowitz Algebraic higher-order rewriting 13/34

Page 14: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

Rewrite systems = 2-signatures

Definition

A rewrite system, or a 2-signature, X consists of:

a 1-signature Σ = (X0,X1),

a map X2 → L1(Σ)|| of rewrite rules.

Definition

The rewrite relation generated by X is the smallest congruencegenerated by the rewrite rules.

A bit more general than the original definition.

Hirschowitz Algebraic higher-order rewriting 14/34

Page 15: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

Example: combinatory logic

Remember K , S ,A.

Two rewrite rules (with usual shorthand):

Kxy → x Sxyz → xy(xz).

Hirschowitz Algebraic higher-order rewriting 15/34

Page 16: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

A category of 2-signatures

A morphism X → Y of 2-signatures consists of

a morphism (f0, f1) : (X0,X1)→ (Y0,Y1) of 1-signatures,

a map f2 : X2 → Y2 making

X2 Y2

L1(X )|| L1(Y )||

f2

L1(f1)||

commute.

Hirschowitz Algebraic higher-order rewriting 16/34

Page 17: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

A category of 2-signatures

Proposition

This yields a category Sig.

Hirschowitz Algebraic higher-order rewriting 17/34

Page 18: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

Reductions and permutation equivalence

We now define a monad L on Sig.

We then use L to construct adjunctions

Sig ⊥ L-Alg ⊥ 2FPCat.

L

U

F

V

Reminiscent of multigraphs a monoidal categories throughmulticategories.

Though missing the language for representable L-algebras.

Hirschowitz Algebraic higher-order rewriting 18/34

Page 19: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

Reductions and permutation equivalence

L preserves underlying 1-signature.

The rewrite rules of L(X ) are the reductions, modulopermutation equivalence, which we now define.

Along the way, we sketch:I how L(X ) yields an fp 2-category,I how any fp 2-category yields an L-algebra.

Hirschowitz Algebraic higher-order rewriting 19/34

Page 20: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

Reductions

First, for (r ∈ X (G ` M,N : t)), we have the formation rule:

. . . Γ ` Pi : Mi → Ni : Gi . . .

Γ ` r(P1, . . . ,Pn) : M[M1, . . . ,Mn]→ N[N1, . . . ,Nn] : A·

2-categorically:

∏Γ

∏G A,

(M1, . . . ,Mn)

(N1, . . . ,Nn)

M

N

rP with P = (P1, . . . ,Pn).

Hirschowitz Algebraic higher-order rewriting 20/34

Page 21: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

Reductions

There is a rule for sequential composition:

Γ ` P : M1 → M2 : A Γ ` Q : M2 → M3 : A

Γ ` P ;M2 Q : M1 → M3 : A·

2-categorically:

∏G A.

M1

M3

P

Q

Hirschowitz Algebraic higher-order rewriting 21/34

Page 22: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

Reductions

Plus a few other rules:

for empty reductions, i.e., identities,

for reductions in context, i.e., making reductions into acongruence.

Hirschowitz Algebraic higher-order rewriting 22/34

Page 23: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

Permutation equivalence

We then quotient out reductions by permutation equivalence.

Also inductively defined.

Permutation actually happens in the rules equating

C B A,r with C B A

C B Ar

and the other way around. Namely:

r(P ;N2 Q) ≡ M1[P] ;M1[N2] r(Q).

Hirschowitz Algebraic higher-order rewriting 23/34

Page 24: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

The monad

Theorem

This defines a functor L : Sig→ Sig, which is a monad withsubstitution as multiplication.

Hirschowitz Algebraic higher-order rewriting 24/34

Page 25: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

The adjunction

We use L to construct an adjunction

Sig ⊥ 2FPCat

H

W

as the composite

Sig ⊥ L-Alg ⊥ 2FPCat.

L

U

F

V

Hirschowitz Algebraic higher-order rewriting 25/34

Page 26: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

Soundness and completeness

Proposition

Given a 2-signature X , form the fp 2-category X ∗ with:

objects: tuples of sorts,

morphisms: tuples of terms,

preordered hom-categories:I X ∗(M,N) = 1 iff M →∗ N,I X ∗(M,N) = ∅ otherwise.

Hirschowitz Algebraic higher-order rewriting 26/34

Page 27: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

Soundness and completeness

Theorem

For all sorts t1, . . . , tn, t, there is a functor

H(X )(Πti , t)→ X ∗(Πti , t),

which is full and identity-on-objects (to a preorder).

Hence:

If P : M → N in H(X ) then M →∗ N in the standard sense.

Conversely.

Hirschowitz Algebraic higher-order rewriting 27/34

Page 28: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

Cartesian closedness

Up to now: first-order rewriting.

2-categorical semantics known, or at least folklore.

New presentation as far as I know.

Now, sketch for higher-order rewriting.

Hirschowitz Algebraic higher-order rewriting 28/34

Page 29: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

2-signatures

Types: A,B ::= 1 | x | A× B | BA.

L1(Σ): simply-typed λ-calculus on Σ.

2-signature: set indexed by pairs of parallel λ-terms inβ-normal, η-long form.

Hirschowitz Algebraic higher-order rewriting 29/34

Page 30: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

Example

Signature Σ: ` : tt → t a : t × t → t.

Pure λ-terms with variables in n in bijection with

L1(Σ)(t, . . . , t︸ ︷︷ ︸n times

→ t).

One rule β : a(`(Mtt),Nt)→ MN, i.e.,

t × t

tt × t t.

`× t a

ev

β

Hirschowitz Algebraic higher-order rewriting 30/34

Page 31: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

Reductions and permutations

As before, plus formation rules

Γ, x : A ` P : M → N : B

Γ ` λx : A.P : λx : A.M → λx : A.N : BA

Γ ` P : M → M ′ : BA Γ ` Q : N → N ′ : A

Γ ` PQ : MN → M ′N ′ : B

with equations for βη.

Hirschowitz Algebraic higher-order rewriting 31/34

Page 32: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

Soundness and completeness

From any 2-signature X , higher-order rewriting yields a reductionrelation between terms on the underlying 1-signature.

Proposition

M →∗ N iff there exists a reduction P : M → N.

Hirschowitz Algebraic higher-order rewriting 32/34

Page 33: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

Corollary

Cartesian closed categories are locally discrete cartesian closed

2-categories: 2CCCat ⊥ CCCat.

Composing with the above: Sig ⊥ CCCat.

K

Fiore and Hur’s syntactic category on X is a full subcategoryof K(X ).

More objects in K(X ), e.g., ttt.

Hirschowitz Algebraic higher-order rewriting 33/34

Page 34: An algebraic approach to higher-order theories and rewriting€¦ · Introduction Here: A categorical semantics for I higher-order rewriting (Klop, Nipkow, Wolfram), and I permutation

Introduction Rewrite systems as 2-signatures 2-categorical semantics Cartesian closed case Conclusion

Uncaught

The π-calculus (and all calculi with a structural congruence).

Would need to incorporate equations between reductions.

Even with that, no efficient presentation of π yet.

Hirschowitz Algebraic higher-order rewriting 34/34