Higher Inductive Types (Hits) Are a New Type Former!
Total Page:16
File Type:pdf, Size:1020Kb
Git as a HIT Dan Licata Wesleyan University 1 1 Darcs Git as a HIT Dan Licata Wesleyan University 1 1 HITs 2 Generator for 2 equality of equality HITs Homotopy Type Theory is an extension of Agda/Coq based on connections with homotopy theory [Hofmann&Streicher,Awodey&Warren,Voevodsky,Lumsdaine,Garner&van den Berg] 2 Generator for 2 equality of equality HITs Homotopy Type Theory is an extension of Agda/Coq based on connections with homotopy theory [Hofmann&Streicher,Awodey&Warren,Voevodsky,Lumsdaine,Garner&van den Berg] Higher inductive types (HITs) are a new type former! 2 Generator for 2 equality of equality HITs Homotopy Type Theory is an extension of Agda/Coq based on connections with homotopy theory [Hofmann&Streicher,Awodey&Warren,Voevodsky,Lumsdaine,Garner&van den Berg] Higher inductive types (HITs) are a new type former! They were originally invented[Lumsdaine,Shulman,…] to model basic spaces (circle, spheres, the torus, …) and constructions in homotopy theory 2 Generator for 2 equality of equality HITs Homotopy Type Theory is an extension of Agda/Coq based on connections with homotopy theory [Hofmann&Streicher,Awodey&Warren,Voevodsky,Lumsdaine,Garner&van den Berg] Higher inductive types (HITs) are a new type former! They were originally invented[Lumsdaine,Shulman,…] to model basic spaces (circle, spheres, the torus, …) and constructions in homotopy theory But they have many other applications, including some programming ones! 2 Generator for 2 equality of equality Patches Patch a a 2c2 diff b d = < b c c --- > d 3 3 id a a b b c c 4 4 id a a b b c c a p a q a b d d c c e 4 4 id a a b b c c q o p a p a q a b d d c c e 4 4 id p a a a a b b b d c c c c q o p a p a q a b d d c c e 4 4 id p a a a a b b b d c c c c !p q o p a p a q a b d d c c e 4 4 id p a a a a b b b d c c c c !p q o p undo/rollback a p a q a b d d c c e 4 4 id p a a a a b b b d c c c c !p q o p undo/rollback a p a q a b d d c c e [Yorgey,Jacobson,…] 4 4 Simple Setup a u s s o i s a ↔ b at 0 a u s b u s a ↔ b at 0 5 5 Simple Setup “Repository” is a char vector of fixed length n a u s s o i s Basic patch is a ↔ b at i where i<n a ↔ b at 0 a u s b u s a ↔ b at 0 5 5 Domain-Specific Language 6 6 Domain-Specific Language 7 7 Domain-Specific Language swapat a b i v permutes a and b at position i in v 7 7 Domain-Specific Language Spec: ∀ p. interp p is a bijection: ∀ v. g (f v) = v where (f,g)=interp p ∀ v. f (g v) = v 8 8 Domain-Specific Language undo really un-does Spec: ∀ p. interp p is a bijection: ∀ v. g (f v) = v where (f,g)=interp p ∀ v. f (g v) = v 8 8 Domain-Specific Language undo really un-does Spec: ∀ p. interp p is a bijection: ∀ v. g (f v) = v where (f,g)=interp p ∀ v. f (g v) = v Can package this as: 8 8 Merging a p b q c a a d b c e 9 9 Merging a p b q c a a d b c e q’ a p’ d e 9 9 Merging p=b↔d at 1 a q=c↔e at 2 p b q c a a d b c e q’ a p’ d e 9 9 Merging p=b↔d at 1 a q=c↔e at 2 p b q c a a d b c e q’ a p’ d p’=p e q’=q 9 9 Merging p=b↔d at 1 a q=c↔e at 2 p b q c a a d b c = e q’ a p’ d p’=p e q’=q 9 9 Merging merge : (p q : Patch) ! "q’,p’:Patch. Maybe(q’ o p = p’ o q) 10 10 Merging merge : (p q : Patch) ! "q’,p’:Patch. Maybe(q’ o p = p’ o q) When are two patches equal? 10 10 Patch Equality (a↔b at i)o(c↔d at j) = (c↔d at j)o(a↔b at i) if i#j 11 11 Patch Equality (a↔b at i)o(c↔d at j) = (c↔d at j)o(a↔b at i) if i#j (a↔a at i) = id !(a↔b at i) = (a↔b at i) (a↔b at i) = (b↔a at i) 11 11 Patch Equality Basic Axioms: (a↔b at i)o(c↔d at j) = (c↔d at j)o(a↔b at i) if i#j (a↔a at i) = id !(a↔b at i) = (a↔b at i) (a↔b at i) = (b↔a at i) 11 11 Patch Equality Basic axioms: (a↔b at i)o(c↔d at j) =(c↔d at j)o(a↔b at i) 12 12 Patch Equality Basic axioms: Group laws: (a↔b at i)o(c↔d at j) id o p = p = p o id =(c↔d at j)o(a↔b at i) po(qor) = (poq)or !p o p = id = p o !p 12 12 Patch Equality Basic axioms: Group laws: (a↔b at i)o(c↔d at j) id o p = p = p o id =(c↔d at j)o(a↔b at i) po(qor) = (poq)or !p o p = id = p o !p Congruence: p=p !p = !p’ if p = p’ p=q if q=p p o q = p’ o q’ if p=r if p=q and q=r p = p’ and q = q’ 12 12 Patch as Quotient Type Elements: Equality: (a↔b at i)o(c↔d at j)~ (c↔d at j)o(a↔b at i) ... id o p ~ p ~ p o id po(qor) ~ (poq)or !p o p ~ id ~ p o !p p~p p~q if q~p p~r if p~q and q~r !p ~ !p’ if p ~ p’ p o q ~ p’ o q’ if p ~ p’ and q ~ q’ 13 13 Patch as Quotient Type Elements: Quotient Type: Patch := Patch’/~ Equality: (a↔b at i)o(c↔d at j)~ (c↔d at j)o(a↔b at i) ... id o p ~ p ~ p o id po(qor) ~ (poq)or !p o p ~ id ~ p o !p p~p p~q if q~p p~r if p~q and q~r !p ~ !p’ if p ~ p’ p o q ~ p’ o q’ if p ~ p’ and q ~ q’ 13 13 Patch as Quotient Type Elements: Quotient Type: Patch := Patch’/~ Equality: Elimination rule: (a↔b at i)o(c↔d at j)~ (c↔d at j)o(a↔b at i) ... id o p ~ p ~ p o id define on Patch’ as before, po(qor) ~ (poq)or then prove p ~ q implies !p o p ~ id ~ p o !p p~p interp p = interp q p~q if q~p for all 14+ rules for ~ p~r if p~q and q~r !p ~ !p’ if p ~ p’ p o q ~ p’ o q’ if p ~ p’ and q ~ q’ 13 13 Patches as a HIT 1.How do you define Patch using a higher inductive type? 2.What is the elimination rule? 3.How do you use the elim. rule to define interp? 14 14 Patches as a HIT 1.How do you define Patch using a higher inductive type? 2.What is the elimination rule? 3.How do you use the elim. rule to define interp? 15 15 Higher Inductive Type 16 Generator for 16 equality of equality Higher Inductive Type Type freely generated by constructors for elements, equalities, equalities between equalities, … 16 Generator for 16 equality of equality Higher Inductive Type Type freely generated by constructors for elements, equalities, equalities between equalities, … RepoDesc : Type 16 Generator for 16 equality of equality Higher Inductive Type Type freely generated by constructors for elements, equalities, equalities between equalities, … RepoDesc : Type vec : RepoDesc generator for element 16 Generator for 16 equality of equality Higher Inductive Type Type freely generated by constructors for elements, equalities, equalities between equalities, … RepoDesc : Type vec : RepoDesc generator for element (a↔b at i) : vec = vec generator for equality 16 Generator for 16 equality of equality Higher Inductive Type Type freely generated by constructors for elements, equalities, equalities between equalities, … RepoDesc : Type proof-relevant! vec : RepoDesc generator for element (a↔b at i) : vec = vec generator for equality 16 Generator for 16 equality of equality Higher Inductive Type Type freely generated by constructors for elements, equalities, equalities between equalities, … RepoDesc : Type proof-relevant! vec : RepoDesc generator for element (a↔b at i) : vec = vec generator for equality commute: generator for equality (a↔b at i)o(c↔d at j) between equalities =(c↔d at j)o(a↔b at i) 16 Generator for 16 equality of equality Type: Patch Elements: Equality: (a↔b at i)o(c↔d at j)= (c↔d at j)o(a↔b at i) ..