a type theory with equality based on setoids
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
3.6 KiB

  1. -- Equality with an explicit domain
  2. let
  3. Eq : (A : Type) (x y : A) -> Type;
  4. Eq A x y = x == y;
  5. -- Identity function with an explicit domain
  6. -- (works as a type annotation)
  7. let
  8. the : (A : Type) -> A -> A;
  9. the A x = x;
  10. -- Singleton types
  11. -- The subtype of A generated by "being equal to x : A"
  12. let
  13. singl : (A : Type) (x : A) -> Type;
  14. singl A x = (y : A) * x == y;
  15. -- Singletons are contractible
  16. let
  17. singlC : {A : Type} {a b : A} (p : a == b) -> Eq (singl A a) (a, refl) (b, p);
  18. singlC p = (p, ());
  19. -- Substitution follows from transport + congruence
  20. -- (just transport by the congruence under P)
  21. let
  22. subst : {A : Type} (P : A -> Type) {x y : A} (p : x == y) -> P x -> P y;
  23. subst P path px = coe (cong P path) px;
  24. let
  25. coe2 : {A B : Type} (p : A == B) → A → B;
  26. coe2 p = subst (λ x → x) p;
  27. -- Based path induction follows from contractibility of singletons +
  28. -- substitution
  29. let
  30. J : {A : Type} (a : A) (P : (b : A) -> a == b -> Type)
  31. (d : P a refl) (b : A) (p : a == b) -> P b p;
  32. J {A} a P d b p =
  33. subst {singl A a} (λ y → P y.1 y.2) (singlC p) d;
  34. let
  35. JComp : {A : Type} (a : A) (P : (b : A) -> a == b -> Type)
  36. (d : P a refl)
  37. → J {A} a P d a refl == d;
  38. JComp {A} a P d = refl;
  39. -- Symmetry follows from axiom J
  40. let
  41. symm : {A : Type} {x y : A} (p : x == y) -> y == x;
  42. symm {A} {x} {y} p = J x (λ y p -> y == x) refl y p;
  43. let
  44. symIsRefl : {A : Type} {a : A} → symm (refl {A} {a}) == refl {A} {a};
  45. symIsRefl = refl;
  46. let
  47. isContr : Type -> Type;
  48. isContr A = (x : A) * (y : A) -> y == x;
  49. let
  50. comp : {A : Type} {a b c : A} → a == b → b == c → a == c;
  51. comp {A} {a} p q = subst (λ x → a == x) q (subst (λ x → a == x) p (refl {A} {a}));
  52. let
  53. trans : {A : Type} {a b c : A} → b == c → a == b → a == c;
  54. trans {A} {a} p q = comp q p;
  55. let
  56. transSym : {A : Type} {a : A} → (p : a == a) → comp p (symm p) == refl;
  57. transSym p = refl;
  58. let
  59. existsOne : (A : Type) (B : A -> Type) -> ((x : A) × B x) -> isContr A -> (x : A) -> B x;
  60. existsOne A B prf contr it =
  61. subst B (comp (contr.2 prf.1) (sym (contr.2 it))) prf.2;
  62. let
  63. indOne : (P : ⊤ -> Type) -> P () -> (x : ⊤) -> P x;
  64. indOne P p x = subst P () p;
  65. let
  66. false : Type;
  67. false = (A : Type) → A;
  68. let
  69. exFalso : (P : Type) -> false -> P;
  70. exFalso P f = f P;
  71. let
  72. funExt : {A : Type} {B : A -> Type} {f g : (x : A) -> B x}
  73. -> ((x : A) -> f x == g x) -> f == g;
  74. funExt p = p;
  75. let
  76. hfunext : {A : Type} {B : A -> Type} {f g : (x : A) -> B x}
  77. -> ((x : A) -> f x == g x) == (f == g);
  78. hfunext = refl;
  79. let
  80. allAbsurd : {A : Type} (f g : false -> A) -> f == g;
  81. allAbsurd f g x = exFalso (f x == g x) x;
  82. let
  83. coerceR1 : {A : Type}
  84. → Eq (A == A → A → A)
  85. (λ p x → coe {A} {A} p x)
  86. (λ x y → y);
  87. coerceR1 = refl;
  88. let
  89. K : {A : Type} {x : A} (P : x == x → Type)
  90. → P refl → (p : x == x) → P p;
  91. K P p path = subst P (the (refl == path) ()) p;
  92. let
  93. foo : {A : Type} {B : A -> Type} {f : (x : A) -> B x}
  94. -> Eq (f == f) refl (λ x → refl);
  95. foo = K (λ e → (refl {_} {f}) == e) refl (λ x → refl);
  96. let
  97. coh : {A : Type} (p : A == A) (x : A) → coe p == (λ x → x);
  98. coh path elem x = refl;
  99. let
  100. coh2 : {A : Type} (p : A == A) (x : A) → coe p x == x;
  101. coh2 path elem = K (λ path → coe {A} {A} path elem == elem) refl path;
  102. -- let
  103. -- cohsAgree : {A : Type} (p : A == A) (x : A) → coh {A} p x == coh2 {A} p x;
  104. -- cohsAgree path elem = refl;
  105. let
  106. congComp : {A B : Type} (f : A -> B) {x : A}
  107. -> cong f (refl {A} {x}) == refl {B} {f x};
  108. congComp f = refl;
  109. coe