1
------------------------------------------------------------------------
2
-- An abstraction of various forms of recursion/induction
3
------------------------------------------------------------------------
5
{-# OPTIONS --universe-polymorphism #-}
7
-- Note: The types in this module can perhaps be easier to understand
8
-- if they are normalised. Note also that Agda can do the
9
-- normalisation for you.
11
module Induction where
14
open import Relation.Unary
16
-- A RecStruct describes the allowed structure of recursion. The
17
-- examples in Induction.Nat should explain what this is all about.
19
RecStruct : ∀ {a} → Set a → Set (suc a)
20
RecStruct {a} A = Pred A a → Pred A a
22
-- A recursor builder constructs an instance of a recursion structure
25
RecursorBuilder : ∀ {a} {A : Set a} → RecStruct A → Set _
26
RecursorBuilder Rec = ∀ P → Rec P ⊆′ P → Universal (Rec P)
28
-- A recursor can be used to actually compute/prove something useful.
30
Recursor : ∀ {a} {A : Set a} → RecStruct A → Set _
31
Recursor Rec = ∀ P → Rec P ⊆′ P → Universal P
33
-- And recursors can be constructed from recursor builders.
35
build : ∀ {a} {A : Set a} {Rec : RecStruct A} →
38
build builder P f x = f x (builder P f x)
40
-- We can repeat the exercise above for subsets of the type we are
43
SubsetRecursorBuilder : ∀ {a ℓ} {A : Set a} →
44
Pred A ℓ → RecStruct A → Set _
45
SubsetRecursorBuilder Q Rec = ∀ P → Rec P ⊆′ P → Q ⊆′ Rec P
47
SubsetRecursor : ∀ {a ℓ} {A : Set a} →
48
Pred A ℓ → RecStruct A → Set _
49
SubsetRecursor Q Rec = ∀ P → Rec P ⊆′ P → Q ⊆′ P
51
subsetBuild : ∀ {a ℓ} {A : Set a} {Q : Pred A ℓ} {Rec : RecStruct A} →
52
SubsetRecursorBuilder Q Rec →
54
subsetBuild builder P f x q = f x (builder P f x q)