Proof.agda 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. -- IIRDg is expressible in IIRDr + Identity
  2. module Proof where
  3. open import LF
  4. open import IIRD
  5. open import IIRDr
  6. open import DefinitionalEquality
  7. open import Identity
  8. open import Proof.Setup
  9. import Logic.ChainReasoning as Chain
  10. -- We can then define general IIRDs using the ε function from Proof.Setup.
  11. Ug : {I : Set}{D : I -> Set1} -> OPg I D -> I -> Set
  12. Ug γ = Ur (ε γ)
  13. Tg : {I : Set}{D : I -> Set1}(γ : OPg I D)(i : I) -> Ug γ i -> D i
  14. Tg γ = Tr (ε γ)
  15. introg : {I : Set}{D : I -> Set1}(γ : OPg I D)(a : Gu γ (Ug γ) (Tg γ)) ->
  16. Ug γ (Gi γ (Ug γ) (Tg γ) a)
  17. introg γ a = intror (G→H γ (Ug γ) (Tg γ) a)
  18. -- To prove the reduction behviour of Tg we first have to prove that the
  19. -- top-level reduction of the encoding behaves as it should. At bit simplified
  20. -- that Ht (ε γ) (Gi a) ≡ Gt γ a
  21. Tg-eq : {I : Set}{D : I -> Set1}(γ : OPg I D)(U : I -> Set)(T : (i : I) -> U i -> D i)
  22. (a : Gu γ U T) ->
  23. Ht (ε γ) U T (Gi γ U T a) (G→H γ U T a) ≡₁ Gt γ U T a
  24. Tg-eq {I}{D} (ι < i | e >') U T ★ = refl-≡₁
  25. Tg-eq (σ A γ) U T < a | b > = Tg-eq (γ a) U T b
  26. Tg-eq (δ A i γ) U T < g | b > = Tg-eq (γ (T « i × g »)) U T b
  27. -- The statement we're interested in is a special case of the more general
  28. -- lemma above.
  29. Tg-equality : {I : Set}{D : I -> Set1}(γ : OPg I D)(a : Gu γ (Ug γ) (Tg γ)) ->
  30. Tg γ (Gi γ (Ug γ) (Tg γ) a) (introg γ a) ≡₁ Gt γ (Ug γ) (Tg γ) a
  31. Tg-equality γ a = Tg-eq γ (Ug γ) (Tg γ) a
  32. -- The elimination rule for generalised IIRDs.
  33. -- It's basically the elimination of the encoding followed by the elimination
  34. -- of the proof the the index is the right one.
  35. Rg : {I : Set}{D : I -> Set1}(γ : OPg I D)(F : (i : I) -> Ug γ i -> Set1)
  36. (h : (a : Gu γ (Ug γ) (Tg γ)) -> KIH γ (Ug γ) (Tg γ) F a -> F (Gi γ (Ug γ) (Tg γ) a) (introg γ a))
  37. (i : I)(u : Ug γ i) -> F i u
  38. Rg {I}{D} γ F h = Rr (ε γ) F \i a ih ->
  39. G→H∘H→G-subst γ U T
  40. (\i a -> F i (intror a))
  41. i a (lem1 i a ih)
  42. where
  43. U = Ug γ
  44. T = Tg γ
  45. lem1 : (i : I)(a : Hu (ε γ) U T i) ->
  46. KIH (ε γ i) U T F a ->
  47. F (Gi γ U T (H→G γ U T i a))
  48. (intror (G→H γ U T (H→G γ U T i a)))
  49. lem1 i a ih = h (H→G γ U T i a) (\v -> εIArg-subst γ U T F i a v (ih (εIArg γ U T i a v)))
  50. open module Chain-≡ = Chain.Poly.Heterogenous1 _≡₁_ (\x -> refl-≡₁) trans-≡₁
  51. open module Chain-≡₀ = Chain.Poly.Heterogenous _≡_ (\x -> refl-≡) trans-≡
  52. renaming (chain>_ to chain>₀_; _===_ to _===₀_; _by_ to _by₀_)
  53. -- Again we have to generalise
  54. Rg-eq : {I : Set}{D : I -> Set1}(γ : OPg I D)(U : I -> Set)(T : (i : I) -> U i -> D i)
  55. (F : (i : I) -> U i -> Set1)(intro : (a : Gu γ U T) -> U (Gi γ U T a))
  56. (g : (i : I)(u : U i) -> F i u)
  57. (h : (a : Gu γ U T) -> KIH γ U T F a -> F (Gi γ U T a) (intro a))
  58. (a : Gu γ U T) ->
  59. let i = Gi γ U T a
  60. a' = G→H γ U T a
  61. in h (H→G γ U T i a')
  62. (\v -> εIArg-subst γ U T F i a' v
  63. (Kmap (ε γ i) U T F g a' (εIArg γ U T i a' v)))
  64. ≡₁ h a (Kmap γ U T F g a)
  65. Rg-eq {I}{D} γ U T F intro g h a = app-≡₁
  66. (cong-≡₁⁰ h (H→G∘G→H-identity γ U T a))
  67. (η-≡₁⁰ \x y p ->
  68. chain> εIArg-subst γ U T F i a' x (Kmap (ε γ i) U T F g a' (εIArg γ U T i a' x))
  69. === Kmap (ε γ i) U T F g a' (εIArg γ U T i a' x)
  70. by εIArg-identity γ U T F a x (Kmap (ε γ i) U T F g a' (εIArg γ U T i a' x))
  71. === Kmap γ U T F g a y
  72. by app-≡₁⁰
  73. (cong-≡₁⁰ g
  74. (chain>₀ KIArg→I (ε γ i) U T a' (εIArg γ U T i a' x)
  75. ===₀ KIArg→I γ U T (H→G γ U T i a') x by₀ εIArg→I-identity γ U T i a' x
  76. ===₀ KIArg→I γ U T a y by₀
  77. app-≡₀ (cong-≡' (KIArg→I γ U T)
  78. (H→G∘G→H-identity γ U T a)
  79. ) p
  80. )
  81. )
  82. (chain>₀ KIArg→U (ε γ i) U T a' (εIArg γ U T i a' x)
  83. ===₀ KIArg→U γ U T (H→G γ U T i a') x by₀ εIArg→U-identity γ U T i a' x
  84. ===₀ KIArg→U γ U T a y by₀
  85. app-≡₀ (cong-≡' (KIArg→U γ U T)
  86. (H→G∘G→H-identity γ U T a)
  87. ) p
  88. )
  89. )
  90. where
  91. i = Gi γ U T a
  92. a' = G→H γ U T a
  93. Rg-equality : {I : Set}{D : I -> Set1}(γ : OPg I D)(F : (i : I) -> Ug γ i -> Set1)
  94. (h : (a : Gu γ (Ug γ) (Tg γ)) -> KIH γ (Ug γ) (Tg γ) F a -> F (Gi γ (Ug γ) (Tg γ) a) (introg γ a))
  95. (a : Gu γ (Ug γ) (Tg γ)) ->
  96. Rg γ F h (Gi γ (Ug γ) (Tg γ) a) (introg γ a)
  97. ≡₁ h a (Kmap γ (Ug γ) (Tg γ) F (Rg γ F h) a)
  98. Rg-equality {I}{D} γ F h a =
  99. chain> Rg γ F h (Gi γ U T a) (introg γ a)
  100. === h'' i a' ih by refl-≡₁
  101. === G→H∘H→G-subst γ U T F' i a' (h' i a' ih)
  102. by refl-≡₁
  103. === h' i a' ih by G→H∘H→G-identity γ U T F' a (h' i a' ih)
  104. === h (H→G γ U T i a') (\v -> εIArg-subst γ U T F i a' v (ih (εIArg γ U T i a' v)))
  105. by refl-≡₁
  106. === h a (Kmap γ U T F (Rg γ F h) a) by Rg-eq γ U T F (introg γ) (Rg γ F h) h a
  107. where
  108. U = Ug γ
  109. T = Tg γ
  110. F' = \i a -> F i (intror a)
  111. i = Gi γ U T a
  112. a' = G→H γ U T a
  113. h' : (i : I)(a : Hu (ε γ) U T i) -> KIH (ε γ i) U T F a -> F _ _
  114. h' = \i a ih -> h (H→G γ U T i a) \v ->
  115. εIArg-subst γ U T F i a v
  116. (ih (εIArg γ U T i a v))
  117. h'' = \i a ih -> G→H∘H→G-subst γ U T F' i a (h' i a ih)
  118. ih = Kmap (ε γ i) U T F (Rg γ F h) a'