Debian Codegraph @

src/Function/Properties/Bijection.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Some basic properties of bijections.
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Function.Properties.Bijection where
10
11 open import Function.Bundles
12 using (Bijection; Inverse; Equivalence; _⤖_; _↔_; _⇔_)
13 open import Level using (Level)
14 open import Relation.Binary.Bundles using (Setoid)
15 open import Relation.Binary.Structures using (IsEquivalence)
16 open import Relation.Binary.Definitions using (Reflexive; Trans)
17 open import Relation.Binary.PropositionalEquality.Properties using (setoid)
18 open import Data.Product.Base using (_,_; proj₁; proj₂)
19 open import Function.Base using (_∘_)
20 open import Function.Properties.Surjection using (injective⇒to⁻-cong)
21 open import Function.Properties.Inverse using (Inverse⇒Equivalence)
22
23 import Function.Construct.Identity as Identity
24 import Function.Construct.Symmetry as Symmetry
25 import Function.Construct.Composition as Composition
26
27 private
28 variable
29 a b c ℓ ℓ₁ ℓ₂ ℓ₃ : Level
30 A B : Set a
31 T S : Setoid a ℓ
32
33 ------------------------------------------------------------------------
34 -- Setoid properties
35
36 refl : Reflexive (Bijection {a} {ℓ})
37 refl = Identity.bijection _
38
39 -- Can't prove full symmetry as we have no proof that the witness
40 -- produced by the surjection proof preserves equality
41 sym-≡ : Bijection S (setoid B) → Bijection (setoid B) S
42 sym-≡ = Symmetry.bijection-≡
43
44 trans : Trans (Bijection {a} {ℓ₁} {b} {ℓ₂}) (Bijection {b} {ℓ₂} {c} {ℓ₃}) Bijection
45 trans = Composition.bijection
46
47 ------------------------------------------------------------------------
48 -- Propositional properties
49
50 ⤖-isEquivalence : IsEquivalence {ℓ = ℓ} _⤖_
51 ⤖-isEquivalence = record
52 { refl = refl
53 ; sym = sym-≡
54 ; trans = trans
55 }
56
57 ------------------------------------------------------------------------
58 -- Conversion functions
59
60 Bijection⇒Inverse : Bijection S T → Inverse S T
61 Bijection⇒Inverse bij = record
62 { to = to
63 ; from = to⁻
64 ; to-cong = cong
65 ; from-cong = injective⇒to⁻-cong surjection injective
66 ; inverse = (λ y≈to⁻[x] → Eq₂.trans (cong y≈to⁻[x]) (to∘to⁻ _)) ,
67 (λ y≈to[x] → injective (Eq₂.trans (to∘to⁻ _) y≈to[x]))
68 }
69 where open Bijection bij; to∘to⁻ = proj₂ ∘ strictlySurjective
70
71 Bijection⇒Equivalence : Bijection T S → Equivalence T S
72 Bijection⇒Equivalence = Inverse⇒Equivalence ∘ Bijection⇒Inverse
73
74 ⤖⇒↔ : A ⤖ B → A ↔ B
75 ⤖⇒↔ = Bijection⇒Inverse
76
77 ⤖⇒⇔ : A ⤖ B → A ⇔ B
78 ⤖⇒⇔ = Bijection⇒Equivalence