IID.agda 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. -- The simpler case of index inductive definitions. (no induction-recursion)
  2. module IID where
  3. open import LF
  4. -- A code for an IID
  5. -- I - index set
  6. -- E = I for general IIDs
  7. -- E = One for restricted IIDs
  8. data OP (I : Set)(E : Set) : Set1 where
  9. ι : E -> OP I E
  10. σ : (A : Set)(γ : A -> OP I E) -> OP I E
  11. δ : (A : Set)(i : A -> I)(γ : OP I E) -> OP I E
  12. -- The type of constructor arguments. Parameterised over
  13. -- U - the inductive type
  14. -- This is the F of the simple polynomial type μF
  15. Args : {I : Set}{E : Set} -> OP I E ->
  16. (U : I -> Set) -> Set
  17. Args (ι e) U = One
  18. Args (σ A γ) U = A × \a -> Args (γ a) U
  19. Args (δ A i γ) U = ((a : A) -> U (i a)) × \_ -> Args γ U
  20. -- Computing the index
  21. index : {I : Set}{E : Set}(γ : OP I E)(U : I -> Set) -> Args γ U -> E
  22. index (ι e) U _ = e
  23. index (σ A γ) U a = index (γ (π₀ a)) U (π₁ a)
  24. index (δ A i γ) U a = index γ U (π₁ a)
  25. -- The assumptions of a particular inductive occurrence in a value.
  26. IndArg : {I : Set}{E : Set}
  27. (γ : OP I E)(U : I -> Set) ->
  28. Args γ U -> Set
  29. IndArg (ι e) U _ = Zero
  30. IndArg (σ A γ) U a = IndArg (γ (π₀ a)) U (π₁ a)
  31. IndArg (δ A i γ) U a = A + IndArg γ U (π₁ a)
  32. -- Given the assumptions of an inductive occurence in a value we can compute
  33. -- its index.
  34. IndIndex : {I : Set}{E : Set}
  35. (γ : OP I E)(U : I -> Set) ->
  36. (a : Args γ U) -> IndArg γ U a -> I
  37. IndIndex (ι e) U _ ()
  38. IndIndex (σ A γ) U arg c = IndIndex (γ (π₀ arg)) U (π₁ arg) c
  39. IndIndex (δ A i γ) U arg (inl a) = i a
  40. IndIndex (δ A i γ) U arg (inr a) = IndIndex γ U (π₁ arg) a
  41. -- Given the assumptions of an inductive occurrence in a value we can compute
  42. -- its value.
  43. Ind : {I : Set}{E : Set}
  44. (γ : OP I E)(U : I -> Set) ->
  45. (a : Args γ U)(v : IndArg γ U a) -> U (IndIndex γ U a v)
  46. Ind (ι e) U _ ()
  47. Ind (σ A γ) U arg c = Ind (γ (π₀ arg)) U (π₁ arg) c
  48. Ind (δ A i γ) U arg (inl a) = (π₀ arg) a
  49. Ind (δ A i γ) U arg (inr a) = Ind γ U (π₁ arg) a
  50. -- The type of induction hypotheses. Basically
  51. -- forall assumptions, the predicate holds for an inductive occurrence with
  52. -- those assumptions
  53. IndHyp : {I : Set}{E : Set}
  54. (γ : OP I E)(U : I -> Set) ->
  55. (F : (i : I) -> U i -> Set)(a : Args γ U) -> Set
  56. IndHyp γ U F a = (v : IndArg γ U a) -> F (IndIndex γ U a v) (Ind γ U a v)
  57. IndHyp₁ : {I : Set}{E : Set}
  58. (γ : OP I E)(U : I -> Set) ->
  59. (F : (i : I) -> U i -> Set1)(a : Args γ U) -> Set1
  60. IndHyp₁ γ U F a = (v : IndArg γ U a) -> F (IndIndex γ U a v) (Ind γ U a v)
  61. -- If we can prove a predicate F for any values, we can construct the inductive
  62. -- hypotheses for a given value.
  63. -- Termination note: g will only be applied to values smaller than a
  64. induction :
  65. {I : Set}{E : Set}
  66. (γ : OP I E)(U : I -> Set)
  67. (F : (i : I) -> U i -> Set)
  68. (g : (i : I)(u : U i) -> F i u)
  69. (a : Args γ U) -> IndHyp γ U F a
  70. induction γ U F g a = \hyp -> g (IndIndex γ U a hyp) (Ind γ U a hyp)
  71. induction₁ :
  72. {I : Set}{E : Set}
  73. (γ : OP I E)(U : I -> Set)
  74. (F : (i : I) -> U i -> Set1)
  75. (g : (i : I)(u : U i) -> F i u)
  76. (a : Args γ U) -> IndHyp₁ γ U F a
  77. induction₁ γ U F g a = \hyp -> g (IndIndex γ U a hyp) (Ind γ U a hyp)