Debian Codegraph @

src/Data/W/Indexed.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Indexed W-types aka Petersson-Synek trees
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Data.W.Indexed where
10
11 open import Level using (Level; _⊔_)
12 open import Data.Container.Indexed.Core using (Container; ⟦_⟧; □)
13 open import Data.Product.Base using (_,_; Σ)
14 open import Relation.Unary using (Pred; _⊆_; _∩_; _∪_)
15
16 -- The family of indexed W-types.
17
18 module _ {ℓ c r} {O : Set ℓ} (C : Container O O c r) where
19
20 open Container C
21
22 data W (o : O) : Set (ℓ ⊔ c ⊔ r) where
23 sup : ⟦ C ⟧ W o → W o
24
25 -- Projections.
26
27 head : W ⊆ Command
28 head (sup (c , _)) = c
29
30 tail : ∀ {o} (w : W o) (r : Response (head w)) → W (next (head w) r)
31 tail (sup (_ , k)) r = k r
32
33 -- Induction, (primitive) recursion and iteration.
34
35 ind : ∀ {ℓ} (P : Pred (Σ O W) ℓ) →
36 (∀ {o} (cs : ⟦ C ⟧ W o) → □ C P (o , cs) → P (o , sup cs)) →
37 ∀ {o} (w : W o) → P (o , w)
38 ind P φ (sup (c , k)) = φ (c , k) (λ r → ind P φ (k r))
39
40 rec : ∀ {ℓ} {X : Pred O ℓ} → (⟦ C ⟧ (W ∩ X) ⊆ X) → W ⊆ X
41 rec φ (sup (c , k))= φ (c , λ r → (k r , rec φ (k r)))
42
43 iter : ∀ {ℓ} {X : Pred O ℓ} → (⟦ C ⟧ X ⊆ X) → W ⊆ X
44 iter φ (sup (c , k))= φ (c , λ r → iter φ (k r))