IID-Proof.agda 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. module IID-Proof where
  2. import Logic.ChainReasoning as Chain
  3. open import LF
  4. open import Identity
  5. open import IID
  6. open import IIDr
  7. open import IID-Proof-Setup
  8. open import DefinitionalEquality
  9. Ug : {I : Set} -> OPg I -> I -> Set
  10. Ug γ i = Ur (ε γ) i
  11. introg : {I : Set}(γ : OPg I)(a : Args γ (Ug γ)) -> Ug γ (index γ (Ug γ) a)
  12. introg γ a = intror (g→rArgs γ (Ug γ) a)
  13. -- The elimination rule.
  14. elim-Ug : {I : Set}(γ : OPg I)(C : (i : I) -> Ug γ i -> Set) ->
  15. ((a : Args γ (Ug γ)) -> IndHyp γ (Ug γ) C a -> C (index γ (Ug γ) a) (introg γ a)) ->
  16. (i : I)(u : Ug γ i) -> C i u
  17. elim-Ug {I} γ C m = elim-Ur (ε γ) C step -- eliminate the restricted type
  18. where
  19. U = Ug γ
  20. -- we've got a method to take care of inductive occurrences for general families (m),
  21. -- but we need something to handle the restricted encoding.
  22. step : (i : I)(a : rArgs (ε γ) U i) -> IndHyp (ε γ i) U C a -> C i (intror a)
  23. step i a h = conclusion
  24. where
  25. -- First convert the argument to a general argument
  26. a' : Args γ U
  27. a' = r→gArgs γ U i a
  28. -- Next convert our induction hypothesis to an hypothesis for a general family
  29. h' : IndHyp γ U C a'
  30. h' = r→gIndHyp γ U C i a h
  31. -- Our method m can be applied to the converted argument and induction
  32. -- hypothesis. This gets us almost all the way.
  33. lem₁ : C (index γ U a') (intror (g→rArgs γ U a'))
  34. lem₁ = m a' h'
  35. -- Now we just have to use the fact that the computed index is the same
  36. -- as our input index, and that g→rArgs ∘ r→gArgs is the identity.
  37. -- r←→gArgs-subst will perform the elimination of the identity proof.
  38. conclusion : C i (intror a)
  39. conclusion = r←→gArgs-subst γ U (\i a -> C i (intror a)) i a lem₁
  40. open module Chain-≡ = Chain.Poly.Heterogenous _≡_ (\x -> refl-≡) trans-≡
  41. -- What remains is to prove that the reduction behaviour of the elimination
  42. -- rule is the correct one. I.e that
  43. -- elim-Ug C m (index a) (introg a) ≡ m a (induction C (elim-Ug C m) a)
  44. elim-Ug-reduction :
  45. {I : Set}(γ : OPg I)(C : (i : I) -> Ug γ i -> Set)
  46. (m : (a : Args γ (Ug γ)) -> IndHyp γ (Ug γ) C a -> C (index γ (Ug γ) a) (introg γ a))
  47. (a : Args γ (Ug γ)) ->
  48. elim-Ug γ C m (index γ (Ug γ) a) (introg γ a)
  49. ≡ m a (induction γ (Ug γ) C (elim-Ug γ C m) a)
  50. elim-Ug-reduction γ C m a =
  51. chain> elim-Ug γ C m (index γ (Ug γ) a) (introg γ a)
  52. -- Unfolding the definition of elim-Ug we get
  53. === r←→gArgs-subst γ U C' i ra
  54. (m gra (r→gih \hyp -> elim-Ug γ C m (r-ind-index hyp) (r-ind-value hyp)))
  55. by refl-≡
  56. -- Now (and this is the key step), since we started with a value in the
  57. -- generalised type we know that the identity proof is refl, so
  58. -- r←→gArgs-subst is the identity.
  59. === m gra (r→gih \hyp -> elim-Ug γ C m (r-ind-index hyp) (r-ind-value hyp))
  60. by r←→gArgs-subst-identity γ U C' a _
  61. -- We use congruence to prove separately that gra ≡ a and that the computed
  62. -- induction hypothesis is the one we need.
  63. === m a (\hyp -> elim-Ug γ C m (g-ind-index hyp) (g-ind-value hyp))
  64. by cong₂-≡' m (g←→rArgs-identity γ U a)
  65. -- The induction hypotheses match
  66. (η-≡ \hyp₀ hyp₁ hyp₀=hyp₁ ->
  67. chain> r→gih (\hyp -> elim-Ug γ C m (r-ind-index hyp) (r-ind-value hyp)) hyp₀
  68. -- Unfolding the definition of r→gih we get
  69. === g→rIndArg-subst γ U C i ra hyp₀
  70. (elim-Ug γ C m (r-ind-index (g→rIndArg γ U i ra hyp₀))
  71. (r-ind-value (g→rIndArg γ U i ra hyp₀))
  72. )
  73. by refl-≡
  74. -- g→rIndArg-subst is definitionally the identity.
  75. === elim-Ug γ C m (r-ind-index (g→rIndArg γ U i ra hyp₀))
  76. (r-ind-value (g→rIndArg γ U i ra hyp₀))
  77. by g→rIndArg-subst-identity γ U C i ra hyp₀ _
  78. -- We can turn the restricted inductive occurrence into a
  79. -- generalised occurrence.
  80. === elim-Ug γ C m (IndIndex γ U gra hyp₀) (Ind γ U gra hyp₀)
  81. by g→rIndArg-subst γ U
  82. (\j b -> elim-Ug γ C m (r-ind-index (g→rIndArg γ U i ra hyp₀))
  83. (r-ind-value (g→rIndArg γ U i ra hyp₀))
  84. ≡ elim-Ug γ C m j b
  85. ) i ra hyp₀ refl-≡
  86. -- Finally we have gra ≡ a and hyp₀ ≡ hyp₁ so we're done.
  87. === elim-Ug γ C m (IndIndex γ U a hyp₁) (Ind γ U a hyp₁)
  88. by cong₂-≡' (\a hyp -> elim-Ug γ C m (IndIndex γ U a hyp)
  89. (Ind γ U a hyp)
  90. ) (g←→rArgs-identity γ U a) hyp₀=hyp₁
  91. )
  92. -- Writing it in a nicer way:
  93. === m a (induction γ (Ug γ) C (elim-Ug γ C m) a)
  94. by refl-≡
  95. where
  96. U = Ug γ
  97. i = index γ U a
  98. ra = g→rArgs γ U a
  99. gra = r→gArgs γ U i ra
  100. r→gih = r→gIndHyp γ U C i ra
  101. r-ind-index = IndIndex (ε γ i) (Ur (ε γ)) ra
  102. r-ind-value = Ind (ε γ i) (Ur (ε γ)) ra
  103. g-ind-index = IndIndex γ U a
  104. g-ind-value = Ind γ U a
  105. C' = \i a -> C i (intror a)