Debian Codegraph @

src/Data/Tree/AVL/Map/Relation/Unary/Any.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- AVL trees where at least one element satisfies a given property
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 open import Relation.Binary.Bundles using (StrictTotalOrder)
10
11 module Data.Tree.AVL.Map.Relation.Unary.Any
12 {a ℓ₁ ℓ₂} (strictTotalOrder : StrictTotalOrder a ℓ₁ ℓ₂)
13 where
14
15 open import Data.Product.Base as Product using (_×_; ∃; _,_)
16 open import Function.Base using (_∘_; _∘′_; id)
17 open import Level using (Level; _⊔_)
18 open import Relation.Unary using (Pred; Decidable; Satisfiable; _⊆_; _∪_)
19
20 open StrictTotalOrder strictTotalOrder renaming (Carrier to Key)
21 open import Data.Tree.AVL.Map strictTotalOrder using (Map)
22 open import Data.Tree.AVL.Indexed strictTotalOrder using (toPair)
23 import Data.Tree.AVL.Relation.Unary.Any strictTotalOrder as Map
24
25 private
26 variable
27 v p q : Level
28 V : Set v
29 P : Pred V p
30 Q : Pred V q
31 m : Map V
32
33 ------------------------------------------------------------------------
34 -- Definition
35
36 -- Given a predicate P, Any P t describes a path in t to an element that
37 -- satisfies P. There may be others.
38 -- See `Relation.Unary` for an explanation of predicates.
39
40 Any : {V : Set v} → Pred (Key × V) p → Pred (Map V) (a ⊔ ℓ₂ ⊔ v ⊔ p)
41 Any P = Map.Any (P ∘′ toPair)
42
43 ------------------------------------------------------------------------
44 -- Operations on Any
45
46 map : P ⊆ Q → Any P ⊆ Any Q
47 map f = Map.map f
48
49 lookup : Any {V = V} P m → Key × V
50 lookup = toPair ∘′ Map.lookup
51
52 lookupKey : Any P m → Key
53 lookupKey = Map.lookupKey
54
55 -- If any element satisfies P, then P is satisfied.
56
57 satisfied : Any P m → ∃ P
58 satisfied = Product.map toPair id ∘′ Map.satisfied
59
60 ------------------------------------------------------------------------
61 -- Properties of predicates preserved by Any
62
63 any? : Decidable P → Decidable (Any P)
64 any? P? = Map.any? (P? ∘ toPair)
65
66 satisfiable : Satisfiable P → Satisfiable (Any P)
67 satisfiable ((k , v) , p) = Map.satisfiable k (v , p)