Debian Codegraph @

src/Data/Maybe/Relation/Binary/Connected.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Lifting a relation such that `nothing` is also related to `just`
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Data.Maybe.Relation.Binary.Connected where
10
11 open import Data.Maybe.Base using (Maybe; just; nothing)
12 open import Function.Bundles using (_⇔_; mk⇔)
13 open import Level using (Level; _⊔_)
14 open import Relation.Binary.Core using (REL; _⇒_)
15 open import Relation.Binary.Definitions using (Reflexive; Sym; Decidable)
16 open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_)
17 open import Relation.Nullary.Decidable as Dec using (yes; no; map)
18 open import Relation.Nullary.Negation.Core using (¬_)
19
20 private
21 variable
22 a b ℓ : Level
23 A : Set a
24 B : Set b
25 R S T : REL A B ℓ
26 x y : A
27
28 ------------------------------------------------------------------------
29 -- Definition
30
31 data Connected {A : Set a} {B : Set b} (R : REL A B ℓ)
32 : REL (Maybe A) (Maybe B) (a ⊔ b ⊔ ℓ) where
33 just : R x y → Connected R (just x) (just y)
34 just-nothing : Connected R (just x) nothing
35 nothing-just : Connected R nothing (just y)
36 nothing : Connected R nothing nothing
37
38 ------------------------------------------------------------------------
39 -- Properties
40
41 drop-just : Connected R (just x) (just y) → R x y
42 drop-just (just p) = p
43
44 just-equivalence : R x y ⇔ Connected R (just x) (just y)
45 just-equivalence = mk⇔ just drop-just
46
47 ------------------------------------------------------------------------
48 -- Relational properties
49
50 refl : Reflexive R → Reflexive (Connected R)
51 refl R-refl {just _} = just R-refl
52 refl R-refl {nothing} = nothing
53
54 reflexive : _≡_ ⇒ R → _≡_ ⇒ Connected R
55 reflexive reflexive ≡.refl = refl (reflexive ≡.refl)
56
57 sym : Sym R S → Sym (Connected R) (Connected S)
58 sym R-sym (just p) = just (R-sym p)
59 sym R-sym nothing-just = just-nothing
60 sym R-sym just-nothing = nothing-just
61 sym R-sym nothing = nothing
62
63 connected? : Decidable R → Decidable (Connected R)
64 connected? R? (just x) (just y) = Dec.map just-equivalence (R? x y)
65 connected? R? (just x) nothing = yes just-nothing
66 connected? R? nothing (just y) = yes nothing-just
67 connected? R? nothing nothing = yes nothing
68