Type: Patch Type: RepoDesc Element: vec : RepoDesc Elements: Equality: Patch { a ↔ b at i : vec = vec Equality: Equality between equalities: (a ↔ b at i)o(c ↔ d at j)= commute : (c ↔ d at j)o(a ↔ b at i) (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 … basic axioms only! !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’ 17 17
Type: Patch Type: RepoDesc Element: vec : RepoDesc Elements: Equality: Patch { a ↔ b at i : vec = vec Equality: Equality between equalities: (a ↔ b at i)o(c ↔ d at j)= commute : (c ↔ d at j)o(a ↔ b at i) (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 … basic axioms only! !p o p = id = p o !p p=p Everything else comes p=q if q=p “for free” from p=r if p=q and q=r !p = !p’ if p = p’ the equality type! p o q = p’ o q’ if p = p’ and q = q’ 17 17
Typed Patches RepoDesc : Type vec : RepoDesc generators for elements compressed : RepoDesc a ↔ b at i : vec = vec generators for equalities gzip : vec = compressed 18 Generator for 18
Typed Patches RepoDesc : Type vec : RepoDesc generators for elements compressed : RepoDesc a ↔ b at i : vec = vec generators for equalities gzip : vec = compressed { Patch vec compressed 18 Generator for 18
Patches as a HIT 1.How do you define Patch using a higher inductive type? 2.What is the elimination rule for RepoDesc ? 3.How do you use the elim. rule to define interp ? 19 19
RepoDesc recursion To define a function RepoDesc � A it su ffi ces to 20 Generator for 20
RepoDesc recursion To define a function RepoDesc � A it su ffi ces to map the element generators of RepoDesc to elements of A 20 Generator for 20
RepoDesc recursion To define a function RepoDesc � A it su ffi ces to map the element generators of RepoDesc to elements of A map the equality generators of RepoDesc to equalities between the corresponding elements of A 20 Generator for 20
RepoDesc recursion To define a function RepoDesc � A it su ffi ces to map the element generators of RepoDesc to elements of A map the equality generators of RepoDesc to equalities between the corresponding elements of A map the equality-between-equality generators to equalities between the corresponding equalities in A 20 Generator for 20
RepoDesc recursion To define a function f : RepoDesc � A it su ffi ces to give 21 Generator for 21
RepoDesc recursion To define a function f : RepoDesc � A it su ffi ces to give f(vec) := … : A 21 Generator for 21
RepoDesc recursion To define a function f : RepoDesc � A it su ffi ces to give f(vec) := … : A f 1 (a ↔ b at i) := … : f(vec) = f(vec) 21 Generator for 21
RepoDesc recursion To define a function f : RepoDesc � A it su ffi ces to give f(vec) := … : A f 1 (a ↔ b at i) := … : f(vec) = f(vec) f 2 (compose a b c d i j i ≠ j) := … : f 1 ((a ↔ b at i)o(c ↔ d at j)) = f 1 ((c ↔ d at j)o(a ↔ b at j)) 21 Generator for 21
RepoDesc recursion To define a function f : RepoDesc � A it su ffi ces to give f(vec) := … : A f 1 (a ↔ b at i) := … : f(vec) = f(vec) f 2 (compose a b c d i j i ≠ j) := … : f 1 ((a ↔ b at i)o(c ↔ d at j)) = f 1 ((c ↔ d at j)o(a ↔ b at j)) You only specify f on generators, not id , o , ! ,group laws,congruence,… (1 patch and 4 basic axioms, instead of 4 and 14!) 21 Generator for 21
RepoDesc recursion To define a function f : RepoDesc � A it su ffi ces to give f(vec) := … : A f 1 (a ↔ b at i) := … : f(vec) = f(vec) f 2 (compose a b c d i j i ≠ j) := … : f 1 ((a ↔ b at i)o(c ↔ d at j)) = f 1 ((c ↔ d at j)o(a ↔ b at j)) 22 Generator for 22
RepoDesc recursion To define a function f : RepoDesc � A it su ffi ces to give f(vec) := … : A f 1 (a ↔ b at i) := … : f(vec) = f(vec) f 2 (compose a b c d i j i ≠ j) := … : f 1 ((a ↔ b at i)o(c ↔ d at j)) = f 1 ((c ↔ d at j)o(a ↔ b at j)) Type-generic equality rules say that functions act homomorphically on id , o , ! ,… 22 Generator for 22
RepoDesc recursion To define a function f : RepoDesc � A it su ffi ces to give =f 1 (a ↔ b at i)o f(vec) := … : A f 1 (c ↔ d at j) f 1 (a ↔ b at i) := … : f(vec) = f(vec) f 2 (compose a b c d i j i ≠ j) := … : f 1 ((a ↔ b at i)o(c ↔ d at j)) = f 1 ((c ↔ d at j)o(a ↔ b at j)) Type-generic equality rules say that functions act homomorphically on id , o , ! ,… 22 Generator for 22
RepoDesc recursion To define a function f : RepoDesc � A it su ffi ces to give f(vec) := … : A f 1 (a ↔ b at i) := … : f(vec) = f(vec) f 2 (compose a b c d i j i ≠ j) := … : f 1 ((a ↔ b at i)o(c ↔ d at j)) = f 1 ((c ↔ d at j)o(a ↔ b at j)) 23 Generator for 23
RepoDesc recursion To define a function f : RepoDesc � A it su ffi ces to give f(vec) := … : A f 1 (a ↔ b at i) := … : f(vec) = f(vec) f 2 (compose a b c d i j i ≠ j) := … : f 1 ((a ↔ b at i)o(c ↔ d at j)) = f 1 ((c ↔ d at j)o(a ↔ b at j)) All functions on RepoDesc respect patches All functions on patches respect patch equality 23 Generator for 23
Patches as a HIT 1.How do you define Patch using a higher inductive type? 2.What is the elimination rule for RepoDesc ? 3.How do you use the elim. rule to define interp ? 24 24
Interp Goal is to define: interp : vec = vec � Bijection (Vec Char n) (Vec Char n) interp(id) = ( λ x.x, …) interp(q o p) = (interp q) o b (interp p) interp(!p) = ! b (interp p) interp(a ↔ b at i) = swapat a b i 25 Generator for 25
Interp Goal is to define: interp : vec = vec � Bijection (Vec Char n) (Vec Char n) interp(id) = ( λ x.x, …) interp(q o p) = (interp q) o b (interp p) interp(!p) = ! b (interp p) interp(a ↔ b at i) = swapat a b i But only tool available is RepoDesc recursion: no direct recursion over proofs of equality 25 Generator for 25
interp : vec = vec � Bijection (Vec Char n) (Vec Char n) interp(a ↔ b at i) = swapat a b i Need to pick A and define f(vec) := … : A f 1 (a ↔ b at i) := … : f(vec) = f(vec) f 2 (compose) := … 26 Generator for 26
interp : vec = vec � Bijection (Vec Char n) (Vec Char n) interp(a ↔ b at i) = swapat a b i Key idea: pick A = Type and define f(vec) := … : Type f 1 (a ↔ b at i) := … : f(vec) = f(vec) f 2 (compose) := … 27 Generator for 27
interp : vec = vec � Bijection (Vec Char n) (Vec Char n) interp(a ↔ b at i) = swapat a b i Key idea: pick A = Type and define f(vec) := Vec Char n : Type f 1 (a ↔ b at i) := … : f(vec) = f(vec) f 2 (compose) := … 28 Generator for 28
interp : vec = vec � Bijection (Vec Char n) (Vec Char n) interp(a ↔ b at i) = swapat a b i Key idea: pick A = Type and define f(vec) := Vec Char n : Type f 1 (a ↔ b at i) := … : Vec Char n = Vec Char n f 2 (compose) := … 29 Generator for 29
interp : vec = vec � Bijection (Vec Char n) (Vec Char n) interp(a ↔ b at i) = swapat a b i Key idea: pick A = Type and define f(vec) := Vec Char n : Type f 1 (a ↔ b at i) := ua(swapat a b i) : Vec Char n = Vec Char n f 2 (compose) := … 30 Generator for 30
interp : vec = vec � Bijection (Vec Char n) (Vec Char n) interp(a ↔ b at i) = swapat a b i Key idea: pick A = Type and define f(vec) := Vec Char n : Type f 1 (a ↔ b at i) := ua(swapat a b i) : Vec Char n = Vec Char n f 2 (compose) := … Voevodky’s univalence axiom ⊃ bijective types are equal 30 Generator for 30
interp : vec = vec � Bijection (Vec Char n) (Vec Char n) interp(a ↔ b at i) = swapat a b i Key idea: pick A = Type and define f(vec) := Vec Char n : Type f 1 (a ↔ b at i) := ua(swapat a b i) : Vec Char n = Vec Char n f 2 (compose) := <proof about swapat as before> 31 Generator for 31
interp : vec = vec � Bijection (Vec Char n) (Vec Char n) interp(a ↔ b at i) = swapat a b i Key idea: pick A = Type and define I(vec) := Vec Char n : Type I 1 (a ↔ b at i) := ua(swapat a b i) : Vec Char n = Vec Char n I 2 (compose) := <proof about swapat as before> 32 Generator for 32
interp : vec = vec � Bijection (Vec Char n) (Vec Char n) interp(p) = ua -1 (I 1 (p)) Key idea: pick A = Type and define I(vec) := Vec Char n : Type I 1 (a ↔ b at i) := ua(swapat a b i) : Vec Char n = Vec Char n I 2 (compose) := <proof about swapat as before> 33 Generator for 33
interp : vec = vec � Bijection (Vec Char n) (Vec Char n) interp(p) = ua -1 (I 1 (p)) Satisfies the desired equations (as propositional equalities): interp(id) = ( λ x.x, …) interp(q o p) = (interp q) o b (interp p) interp(!p) = ! b (interp p) interp(a ↔ b at i) = swapat a b i 34 Generator for 34
Summary 35 Generator for 35
Summary I : RepoDesc � Type interprets RepoDesc ’s as Type s, patches as bijections, satisfying patch equalities 35 Generator for 35
Summary I : RepoDesc � Type interprets RepoDesc ’s as Type s, patches as bijections, satisfying patch equalities Higher inductive elim. defines functions that respect equality: you specify what happens on the generators; homomorphically extended to id , o , ! ,... 35 Generator for 35
Summary I : RepoDesc � Type interprets RepoDesc ’s as Type s, patches as bijections, satisfying patch equalities Higher inductive elim. defines functions that respect equality: you specify what happens on the generators; homomorphically extended to id , o , ! ,... Univalence lets you give a computational model of equality proofs (here, patches); guaranteed to satisfy laws 35 Generator for 35
Summary I : RepoDesc � Type interprets RepoDesc ’s as Type s, patches as bijections, satisfying patch equalities Higher inductive elim. defines functions that respect equality: you specify what happens on the generators; homomorphically extended to id , o , ! ,... Univalence lets you give a computational model of equality proofs (here, patches); guaranteed to satisfy laws Shorter definition and code than using quotients: 1 basic patch & 4 basic axioms of equality, instead of 4 patches & 14 equations 35 Generator for 35
Where does this programming technique come from? 36 Generator for 36
Homotopy type theory p b a 37 37
Homotopy type theory a space is a type A p b a 37 37
Homotopy type theory a space is a type A p b a points are elements a:A 37 37
Homotopy type theory a space is a type A p b a points are elements paths are a:A proofs of equality p : a = A b 37 37
Homotopy type theory a space is a type A path operations p b a points are elements paths are a:A proofs of equality p : a = A b 37 37
Homotopy type theory a space is a type A path operations id : a = a (refl) p id b a points are elements paths are a:A proofs of equality p : a = A b 37 37
Homotopy type theory a space is a type A path operations id : a = a (refl) p id !p !p : b = a (sym) b a points are elements paths are a:A proofs of equality p : a = A b 37 37
Homotopy type theory a space is a type A path operations id : a = a (refl) p id !p !p : b = a (sym) b a q o p : a = c (trans) q c points are elements paths are a:A proofs of equality p : a = A b 37 37
Homotopy type theory a space is a type A path operations id : a = a (refl) p id !p !p : b = a (sym) b a q o p : a = c (trans) q c homotopies id o p = p points are !p o p = id elements paths are r o (q o p) a:A proofs of equality = (r o q) o p p : a = A b 37 37
Recommend
More recommend