Debian Codegraph @

src/Function/Consequences.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Relationships between properties of functions. See
5 -- `Function.Consequences.Propositional` for specialisations to
6 -- propositional equality.
7 ------------------------------------------------------------------------
8
9 {-# OPTIONS --cubical-compatible --safe #-}
10
11 module Function.Consequences where
12
13 open import Data.Product.Base as Product
14 open import Function.Definitions
15 open import Level using (Level)
16 open import Relation.Binary.Core using (Rel)
17 open import Relation.Binary.Bundles using (Setoid)
18 open import Relation.Binary.Definitions using (Reflexive; Symmetric; Transitive)
19 open import Relation.Nullary.Negation.Core using (¬_; contraposition)
20
21 private
22 variable
23 a b ℓ₁ ℓ₂ : Level
24 A B : Set a
25 ≈₁ ≈₂ : Rel A ℓ₁
26 f f⁻¹ : A → B
27
28 ------------------------------------------------------------------------
29 -- Injective
30
31 contraInjective : ∀ (≈₂ : Rel B ℓ₂) → Injective ≈₁ ≈₂ f →
32 ∀ {x y} → ¬ (≈₁ x y) → ¬ (≈₂ (f x) (f y))
33 contraInjective _ inj p = contraposition inj p
34
35 ------------------------------------------------------------------------
36 -- Inverseˡ
37
38 inverseˡ⇒surjective : ∀ (≈₂ : Rel B ℓ₂) →
39 Inverseˡ ≈₁ ≈₂ f f⁻¹ →
40 Surjective ≈₁ ≈₂ f
41 inverseˡ⇒surjective ≈₂ invˡ y = (_ , invˡ)
42
43 ------------------------------------------------------------------------
44 -- Inverseʳ
45
46 inverseʳ⇒injective : ∀ (≈₂ : Rel B ℓ₂) f →
47 Reflexive ≈₂ →
48 Symmetric ≈₁ →
49 Transitive ≈₁ →
50 Inverseʳ ≈₁ ≈₂ f f⁻¹ →
51 Injective ≈₁ ≈₂ f
52 inverseʳ⇒injective ≈₂ f refl sym trans invʳ {x} {y} fx≈fy =
53 trans (sym (invʳ refl)) (invʳ fx≈fy)
54
55 ------------------------------------------------------------------------
56 -- Inverseᵇ
57
58 inverseᵇ⇒bijective : ∀ (≈₂ : Rel B ℓ₂) →
59 Reflexive ≈₂ →
60 Symmetric ≈₁ →
61 Transitive ≈₁ →
62 Inverseᵇ ≈₁ ≈₂ f f⁻¹ →
63 Bijective ≈₁ ≈₂ f
64 inverseᵇ⇒bijective {f = f} ≈₂ refl sym trans (invˡ , invʳ) =
65 (inverseʳ⇒injective ≈₂ f refl sym trans invʳ , inverseˡ⇒surjective ≈₂ invˡ)
66
67 ------------------------------------------------------------------------
68 -- StrictlySurjective
69
70 surjective⇒strictlySurjective : ∀ (≈₂ : Rel B ℓ₂) →
71 Reflexive ≈₁ →
72 Surjective ≈₁ ≈₂ f →
73 StrictlySurjective ≈₂ f
74 surjective⇒strictlySurjective _ refl surj x =
75 Product.map₂ (λ v → v refl) (surj x)
76
77 strictlySurjective⇒surjective : Transitive ≈₂ →
78 Congruent ≈₁ ≈₂ f →
79 StrictlySurjective ≈₂ f →
80 Surjective ≈₁ ≈₂ f
81 strictlySurjective⇒surjective trans cong surj x =
82 Product.map₂ (λ fy≈x z≈y → trans (cong z≈y) fy≈x) (surj x)
83
84 ------------------------------------------------------------------------
85 -- StrictlyInverseˡ
86
87 inverseˡ⇒strictlyInverseˡ : ∀ (≈₁ : Rel A ℓ₁) (≈₂ : Rel B ℓ₂) →
88 Reflexive ≈₁ →
89 Inverseˡ ≈₁ ≈₂ f f⁻¹ →
90 StrictlyInverseˡ ≈₂ f f⁻¹
91 inverseˡ⇒strictlyInverseˡ _ _ refl sinv x = sinv refl
92
93 strictlyInverseˡ⇒inverseˡ : Transitive ≈₂ →
94 Congruent ≈₁ ≈₂ f →
95 StrictlyInverseˡ ≈₂ f f⁻¹ →
96 Inverseˡ ≈₁ ≈₂ f f⁻¹
97 strictlyInverseˡ⇒inverseˡ trans cong sinv {x} y≈f⁻¹x =
98 trans (cong y≈f⁻¹x) (sinv x)
99
100 ------------------------------------------------------------------------
101 -- StrictlyInverseʳ
102
103 inverseʳ⇒strictlyInverseʳ : ∀ (≈₁ : Rel A ℓ₁) (≈₂ : Rel B ℓ₂) →
104 Reflexive ≈₂ →
105 Inverseʳ ≈₁ ≈₂ f f⁻¹ →
106 StrictlyInverseʳ ≈₁ f f⁻¹
107 inverseʳ⇒strictlyInverseʳ _ _ refl sinv x = sinv refl
108
109 strictlyInverseʳ⇒inverseʳ : Transitive ≈₁ →
110 Congruent ≈₂ ≈₁ f⁻¹ →
111 StrictlyInverseʳ ≈₁ f f⁻¹ →
112 Inverseʳ ≈₁ ≈₂ f f⁻¹
113 strictlyInverseʳ⇒inverseʳ trans cong sinv {x} y≈f⁻¹x =
114 trans (cong y≈f⁻¹x) (sinv x)