IID-Proof-Setup.agda 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. module IID-Proof-Setup where
  2. open import LF
  3. open import Identity
  4. open import IID
  5. open import IIDr
  6. open import DefinitionalEquality
  7. OPg : Set -> Set1
  8. OPg I = OP I I
  9. -- Encoding indexed inductive types as non-indexed types.
  10. ε : {I : Set}(γ : OPg I) -> OPr I
  11. ε (ι i) j = σ (i == j) (\_ -> ι ★)
  12. ε (σ A γ) j = σ A (\a -> ε (γ a) j)
  13. ε (δ H i γ) j = δ H i (ε γ j)
  14. -- Adds a reflexivity proof.
  15. g→rArgs : {I : Set}(γ : OPg I)(U : I -> Set)
  16. (a : Args γ U) ->
  17. rArgs (ε γ) U (index γ U a)
  18. g→rArgs (ι e) U arg = (refl , ★)
  19. g→rArgs (σ A γ) U arg = (π₀ arg , g→rArgs (γ (π₀ arg)) U (π₁ arg))
  20. g→rArgs (δ H i γ) U arg = (π₀ arg , g→rArgs γ U (π₁ arg))
  21. -- Strips the equality proof.
  22. r→gArgs : {I : Set}(γ : OPg I)(U : I -> Set)
  23. (i : I)(a : rArgs (ε γ) U i) ->
  24. Args γ U
  25. r→gArgs (ι i) U j _ = ★
  26. r→gArgs (σ A γ) U j arg = (π₀ arg , r→gArgs (γ (π₀ arg)) U j (π₁ arg))
  27. r→gArgs (δ H i γ) U j arg = (π₀ arg , r→gArgs γ U j (π₁ arg))
  28. -- Converting an rArgs to a gArgs and back is (provably, not definitionally)
  29. -- the identity.
  30. r←→gArgs-subst :
  31. {I : Set}(γ : OPg I)(U : I -> Set)
  32. (C : (i : I) -> rArgs (ε γ) U i -> Set)
  33. (i : I)(a : rArgs (ε γ) U i) ->
  34. (C (index γ U (r→gArgs γ U i a))
  35. (g→rArgs γ U (r→gArgs γ U i a))
  36. ) -> C i a
  37. r←→gArgs-subst {I} (ι i) U C j arg m =
  38. elim== i (\k q -> C k (q , ★)) m j (π₀ arg)
  39. r←→gArgs-subst (σ A γ) U C j arg m =
  40. r←→gArgs-subst (γ (π₀ arg)) U (\i c -> C i (π₀ arg , c)) j (π₁ arg) m
  41. r←→gArgs-subst (δ H i γ) U C j arg m =
  42. r←→gArgs-subst γ U (\i c -> C i (π₀ arg , c)) j (π₁ arg) m
  43. -- r←→gArgs-subst eliminates the identity proof stored in the rArgs. If this proof is
  44. -- by reflexivity r←→gArgs-subst is a definitional identity. This is the case
  45. -- when a = g→rArgs a'
  46. r←→gArgs-subst-identity :
  47. {I : Set}(γ : OPg I)(U : I -> Set)
  48. (C : (i : I) -> rArgs (ε γ) U i -> Set)
  49. (a' : Args γ U) ->
  50. let a = g→rArgs γ U a'
  51. i = index γ U a' in
  52. (h : C (index γ U (r→gArgs γ U i a))
  53. (g→rArgs γ U (r→gArgs γ U i a))
  54. ) -> r←→gArgs-subst γ U C i a h ≡ h
  55. r←→gArgs-subst-identity (ι i) U C _ h = refl-≡
  56. r←→gArgs-subst-identity (σ A γ) U C arg h = r←→gArgs-subst-identity (γ (π₀ arg)) U C' (π₁ arg) h
  57. where C' = \i c -> C i (π₀ arg , c)
  58. r←→gArgs-subst-identity (δ H i γ) U C arg h = r←→gArgs-subst-identity γ U C' (π₁ arg) h
  59. where C' = \i c -> C i (π₀ arg , c)
  60. -- Going the other way around is definitionally the identity.
  61. g←→rArgs-identity :
  62. {I : Set}(γ : OPg I)(U : I -> Set)
  63. (a : Args γ U) ->
  64. r→gArgs γ U (index γ U a) (g→rArgs γ U a) ≡ a
  65. g←→rArgs-identity (ι i) U _ = refl-≡
  66. g←→rArgs-identity (σ A γ) U arg = cong-≡ (\ ∙ -> (π₀ arg , ∙)) (g←→rArgs-identity (γ (π₀ arg)) U (π₁ arg))
  67. g←→rArgs-identity (δ H i γ) U arg = cong-≡ (\ ∙ -> (π₀ arg , ∙)) (g←→rArgs-identity γ U (π₁ arg))
  68. -- Corresponding conversion functions for assumptions to inductive occurrences.
  69. -- Basically an identity function.
  70. g→rIndArg : {I : Set}(γ : OPg I)(U : I -> Set)
  71. (i : I)(a : rArgs (ε γ) U i) ->
  72. IndArg γ U (r→gArgs γ U i a) -> IndArg (ε γ i) U a
  73. g→rIndArg (ι j) U i _ ()
  74. g→rIndArg (σ A γ) U i arg v = g→rIndArg (γ (π₀ arg)) U i (π₁ arg) v
  75. g→rIndArg (δ A j γ) U i arg (inl a) = inl a
  76. g→rIndArg (δ A j γ) U i arg (inr v) = inr (g→rIndArg γ U i (π₁ arg) v)
  77. -- Basically we can substitute general inductive occurences for the encoded
  78. -- restricted inductive occurrences.
  79. g→rIndArg-subst :
  80. {I : Set}(γ : OPg I)(U : I -> Set)
  81. (C : (i : I) -> U i -> Set)
  82. (i : I)(a : rArgs (ε γ) U i)
  83. (v : IndArg γ U (r→gArgs γ U i a)) ->
  84. C (IndIndex (ε γ i) U a (g→rIndArg γ U i a v))
  85. (Ind (ε γ i) U a (g→rIndArg γ U i a v)) ->
  86. C (IndIndex γ U (r→gArgs γ U i a) v)
  87. (Ind γ U (r→gArgs γ U i a) v)
  88. g→rIndArg-subst (ι j) U C i _ () h
  89. g→rIndArg-subst (σ A γ) U C i arg v h = g→rIndArg-subst (γ (π₀ arg)) U C i (π₁ arg) v h
  90. g→rIndArg-subst (δ A j γ) U C i arg (inl a) h = h
  91. g→rIndArg-subst (δ A j γ) U C i arg (inr v) h = g→rIndArg-subst γ U C i (π₁ arg) v h
  92. -- g→rIndArg-subst is purely book-keeping. On the object level it's definitional identity.
  93. g→rIndArg-subst-identity :
  94. {I : Set}(γ : OPg I)(U : I -> Set)
  95. (C : (i : I) -> U i -> Set)
  96. (i : I)(a : rArgs (ε γ) U i)
  97. (v : IndArg γ U (r→gArgs γ U i a))
  98. (h : C (IndIndex (ε γ i) U a (g→rIndArg γ U i a v))
  99. (Ind (ε γ i) U a (g→rIndArg γ U i a v))
  100. ) -> g→rIndArg-subst γ U C i a v h ≡ h
  101. g→rIndArg-subst-identity (ι j) U C i _ () h
  102. g→rIndArg-subst-identity (σ A γ) U C i arg v h =
  103. g→rIndArg-subst-identity (γ (π₀ arg)) U C i (π₁ arg) v h
  104. g→rIndArg-subst-identity (δ A j γ) U C i arg (inl a) h = refl-≡
  105. g→rIndArg-subst-identity (δ A j γ) U C i arg (inr v) h =
  106. g→rIndArg-subst-identity γ U C i (π₁ arg) v h
  107. -- And finally conversion of induction hypotheses. This goes the other direction.
  108. r→gIndHyp :
  109. {I : Set}(γ : OPg I)(U : I -> Set)
  110. (C : (i : I) -> U i -> Set)
  111. (i : I)(a : rArgs (ε γ) U i) ->
  112. IndHyp (ε γ i) U C a -> IndHyp γ U C (r→gArgs γ U i a)
  113. r→gIndHyp γ U C i a h v = g→rIndArg-subst γ U C i a v (h (g→rIndArg γ U i a v))