Algebras and Coalgebras in dependent type theory Anton Setzer Swansea University 12 April 2012 1/ 30
From Algebras to Indexed Inductive Definitions Indexed Inductive-Recursive Definitions Induction-Induction Coalgebras 2/ 30
From the infamous “TPL Book” Alternatively, an algebra may be displayed expansively in the following way: algebra A carriers . . . , A s , . . . constant . . . a : → A s . . . operations . . . f : A s (1) × · · · × A s ( n ) → A s . . . 3/ 30
Notations ◮ We use functional notation f a 1 · · · a n ✿✿✿✿✿✿✿✿✿ instead of f ( a 1 , . . . , a n ). ◮ A 1 + · · · + A n ✿✿✿✿✿✿✿✿✿✿✿✿✿ is the disjoint union of A i . If there is a natural index i for A i (usually an operation) let ✿✿ : A i → A 1 + · · · + A n in i be the injection. ◮ We write a : A for a is of type A . ◮ Set ✿✿✿ denotes the type of sets, S → Set is the type of S -indexed sets. 4/ 30
Dependent Function/Sum Type ◮ We define the ✿✿✿✿✿✿✿✿✿✿✿✿ dependent ✿✿✿✿✿✿✿✿✿✿ function type ✿✿✿✿✿✿ ( a : A ) → B [ a ] ✿✿✿✿✿✿✿✿✿✿✿✿✿✿ of functions mapping a : A to an element of B [ a ]. ◮ We define the ✿✿✿✿✿✿✿✿✿✿✿✿ dependent ✿✿✿✿✿✿ sum ✿✿✿✿✿ type ( a : A ) × B [ a ] ✿✿✿✿✿✿✿✿✿✿✿✿✿ consisting of � a , b � s.t. a : A , b : B [ a ]. 5/ 30
From Algebras to Indexed Inductive Definitions From Algebras to Indexed Inductive Definitions Indexed Inductive-Recursive Definitions Induction-Induction Coalgebras 6/ 30
From Algebras to Indexed Inductive Definitions Single Sorted Case (Omit S) ◮ Let for a : → A , X : Set , F a ( X ) ✿✿✿✿✿✿ := {∗} So essentially a : F a ( A ) → A ◮ Let for f : A n → A , X : Set ✿✿✿✿✿✿ := X n F f ( X ) So f : F f ( A ) → A ◮ Let F ( X ) ✿✿✿✿✿ := F f 1 ( X ) + · · · + F f l ( X ) So � ✿ := [ f 1 , . . . , f n ] : F ( A ) → A f ◮ ( A ,� f ) is an ✿✿✿✿✿✿✿✿✿✿✿ F -algebra . 7/ 30
From Algebras to Indexed Inductive Definitions Multi Sorted Case, Restricted Version ◮ Let S ✿ := { s 1 , . . . , s n } be the set of all sorts. ◮ Consider A as of type A : S → Set . ◮ Assume now X : S → Set ◮ If a : → A s , let F a ( X ) ✿✿✿✿✿ := {∗} ◮ If f : A s (1) × · · · × A s ( n ) → A s , let F a ( X ) ✿✿✿✿✿ := X s (1) × · · · × X s ( n ) ◮ Let for s : S F s ( X ) ✿✿✿✿✿ := F f i 1 ( X ) + · · · + F f il ( X ) where f i 1 , . . . , f i l are the functions with target type A s . ◮ Define � ✿ : ( s : S ) → F s ( A ) → A s , f � f s ( in a ∗ ) = a , � f s ( in f � x 1 , . . . , x n � ) = f ( x 1 , . . . , x n ) ◮ Then ( A ,� F -algebra because of the type of � f ) is a ✿✿✿✿✿✿✿✿✿✿ restricted ✿✿✿✿✿✿✿✿✿✿✿ f . 8/ 30
From Algebras to Indexed Inductive Definitions Multi Sorted Case, Generalised Version ◮ Let S , A , F a , F f as before ◮ Let F ( X ) ✿✿✿✿✿ := F f 1 ( X ) + · · · + F f n ( X ) where f 1 , . . . , f l are all the constants and operations of A . ◮ Define ✿✿✿✿✿ : F ( X ) → S index where if f : A s 1 × · · · × A s n → A s , then index ( in f i � x 1 , . . . , x n � ) = s ◮ Define � ✿ : ( a : F ( A )) → A index s , f � f ( in a ∗ ) = a � f s ( in f � x 1 , . . . , x n � ) = f � x 1 , . . . , x n � ◮ Then ( A ,� F -algebra because of the type of � f ) is a ✿✿✿✿✿✿✿✿✿✿✿✿✿ generalised f . ✿✿✿✿✿✿✿✿✿✿✿✿ 9/ 30
From Algebras to Indexed Inductive Definitions Generalisation ◮ Up to now F ( X ) is the disjoint union of products of X i . ◮ We can throw in as basic sets as well some B : Set defined before. These will be called “ ✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿ non-inductive ✿✿✿✿✿✿✿✿✿✿✿✿✿ arguments ”. ◮ Used when forming algebras referring to other algebras. ◮ We can refer to many arguments of X s simultaneously. So we have arguments of type ( b : B ) → X s ( b ) where B : Set , s : B → S . These arguments are called “ ✿✿✿✿✿✿✿✿✿✿ inductive arguments ”. ✿✿✿✿✿✿✿✿✿✿✿✿✿ 10/ 30
From Algebras to Indexed Inductive Definitions Generalisation ◮ We can allow the type of later arguments depend on previous non-inductive arguments. ◮ We replace F f 1 ( X ) + · · · + F f n ( X ) by ( f : { f 1 , . . . , f n } ) × F f ( X ) so we need no disjoint union. ◮ We define polynomial functors for the general case, the restricted version is a special case of this. 11/ 30
From Algebras to Indexed Inductive Definitions Polynomial Functors ◮ The ✿✿✿ functors F : ( S → Set ) → Set together set of polynomial ✿✿✿✿✿✿✿✿✿✿ ✿✿✿ ✿✿✿✿✿✿✿✿✿✿✿✿✿✿ with index : F X ) → S is given by ◮ Base Case: The following is polynomial ( s : S ): F X = {∗} index ∗ = s ◮ Non-inductive Argument: Assume B : Set and that for b : B we have ( F b , index b ) is polynomial. The following is polynomial: F X = ( b : B ) × F b X index � b , x � = index b x 12/ 30
From Algebras to Indexed Inductive Definitions Polynomial Functors ◮ Inductive Argument: Assume B : Set , s : B → S , ( F ′ , index ′ ) is polynomial. The following is polynomial: F X = (( b : B ) → X s ( b ) ) × F ′ X index � x , y � = index ′ y 13/ 30
From Algebras to Indexed Inductive Definitions Restricted/Generalised Indexed Inductive Definitions ◮ Restricted indexed inductive definitions are initial algebras for polynomial functors F s : ( S → Set ) → Set , index s x = s and the introduction rule has the form intro : ( s : S ) → F s A → A s ◮ Generalised indexed inductive definitions are initial algebras for a polynomial functor F : ( S → Set ) → Set , index : F X → S and the introduction rule has the form intro : ( x : F A ) → A index x 14/ 30
Indexed Inductive-Recursive Definitions From Algebras to Indexed Inductive Definitions Indexed Inductive-Recursive Definitions Induction-Induction Coalgebras 15/ 30
Indexed Inductive-Recursive Definitions Asymmetry of Indexed Inductive Definitions ◮ Asymmetry of arguments: ◮ Only dependency on non-inductive arguments not on inductive arguments. ◮ Direct dependency not possible, since we don’t know what X is. ◮ Solution: instead of defining just X : S → Set define ◮ X : S → Set inductively together with ◮ T : ( s : S ) → X s → D [ s ] recursively for some type D [ s ]. ◮ Later arguments can depend on T applied to inductive arguments. 16/ 30
Indexed Inductive-Recursive Definitions Generalised Indexed Inductive Definitions ◮ Let Fam S ( D ) := ( X : S → Set ) × (( s : S ) → X s → D [ s ]). ◮ So define F : Fam S ( D ) → Set index : F X → S toD : ( x : F X ) → D [ index x ] ◮ The formation and introduction rules are now A : S → Set T : ( s : S ) → A s → D [ s ] intro : ( a : F � A , T � ) → A index a T ( index a ) ( intro a ) = toD a 17/ 30
Indexed Inductive-Recursive Definitions Polynomial Functors ◮ The ✿✿✿ set of polynomial ✿✿✿✿✿✿✿✿✿✿ functors with related functions ✿✿✿ ✿✿✿✿✿✿✿✿✿✿✿✿✿✿ F : Fam S ( D ) → Set index : F X → S toD : ( x : F X ) → D [ index x ] is defined as follows: ◮ Base Case: Let s : S , d : D [ s ]. The following is polynomial: F X = {∗} index ∗ = s toD ∗ = d 18/ 30
Indexed Inductive-Recursive Definitions Polynomial Functors ◮ Non-inductive Argument: Assume B : Set and for b : B we have ( F b , index b ) is polynomial. The following is polynomial: F X = ( b : B ) × F b X , � b , x � = index index b x , � b , x � = toD toD b x . 19/ 30
Indexed Inductive-Recursive Definitions Polynomial Functors ◮ Inductive Argument: Assume B : Set , s : B → S . Assume for t : ( b : B ) → D [ s b ] we have ( F t , index t , toD t ) are polynomial. The following is polynomial F � X , T � = ( f : ( b : B ) → X s b ) × F t ◦ f � X , t � , index � f , X � = index t ◦ f x , toD � f , X � = toD t ◦ f x . 20/ 30
Induction-Induction From Algebras to Indexed Inductive Definitions Indexed Inductive-Recursive Definitions Induction-Induction Coalgebras 21/ 30
Induction-Induction Induction-Induction ◮ PhD Project of Fredrik Forsberg. ◮ In single sorted Induction Recursion we defined ◮ A : Set inductively, while defining ◮ T : A → D recursively. ◮ In Induction Induction we define ◮ A : Set inductively, while defining ◮ B : A → Set inductively. 22/ 30
Induction-Induction Example Surreal Numbers ◮ We define the surreal numbers Surreal : Set together with relations x ≤ y : Set x �≤ y : Set for x , y : Surreal inductive-inductively. (Size problems required modifications, see paper). 23/ 30
Induction-Induction Example Surreal Numbers ◮ Assume X L , X R : P (Surreal) ∀ x ∈ X L . ∀ y ∈ X R . x �≤ y Then ( X L , X R ) : Surreal ◮ Assume X = ( X L , X R ) : Surreal Y = ( Y L , Y R ) : Surreal Assume ◮ ∀ x ∈ X L . Y �≤ x . ◮ ∀ y ∈ Y R . y �≤ X . Then X ≤ Y . 24/ 30
Recommend
More recommend