Debian Codegraph @

src/Relation/Binary/PropositionalEquality.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Propositional (intensional) equality
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Relation.Binary.PropositionalEquality where
10
11 open import Axiom.UniquenessOfIdentityProofs
12 open import Function.Base using (id; _∘_)
13 import Function.Dependent.Bundles as Dependent using (Func)
14 open import Function.Indexed.Relation.Binary.Equality using (≡-setoid)
15 open import Level using (Level; _⊔_)
16 open import Relation.Nullary.Irrelevant using (Irrelevant)
17 open import Relation.Nullary.Decidable using (yes; no; dec-yes-irr; dec-no)
18 open import Relation.Binary.Bundles using (Setoid)
19 open import Relation.Binary.Definitions using (DecidableEquality)
20 open import Relation.Binary.Indexed.Heterogeneous
21 using (IndexedSetoid)
22 import Relation.Binary.Indexed.Heterogeneous.Construct.Trivial
23 as Trivial using (indexedSetoid)
24
25 private
26 variable
27 a b c ℓ p : Level
28 A B C : Set a
29
30 ------------------------------------------------------------------------
31 -- Re-export contents modules that make up the parts
32
33 open import Relation.Binary.PropositionalEquality.Core public
34 open import Relation.Binary.PropositionalEquality.Properties public
35 open import Relation.Binary.PropositionalEquality.Algebra public
36
37 ------------------------------------------------------------------------
38 -- Pointwise equality
39
40 _→-setoid_ : ∀ (A : Set a) (B : Set b) → Setoid _ _
41 A →-setoid B = ≡-setoid A (Trivial.indexedSetoid (setoid B))
42
43 :→-to-Π : ∀ {A : Set a} {B : IndexedSetoid A b ℓ} →
44 ((x : A) → IndexedSetoid.Carrier B x) →
45 Dependent.Func (setoid A) B
46 :→-to-Π {B = B} f = record
47 { to = f
48 ; cong = λ { refl → IndexedSetoid.refl B }
49 }
50
51 →-to-⟶ : ∀ {A : Set a} {B : Setoid b ℓ} →
52 (A → Setoid.Carrier B) →
53 Dependent.Func (setoid A) (Trivial.indexedSetoid B)
54 →-to-⟶ = :→-to-Π
55
56 ------------------------------------------------------------------------
57 -- More complex rearrangement lemmas
58
59 -- A lemma that is very similar to Lemma 2.4.3 from the HoTT book.
60
61 naturality : ∀ {x y} {x≡y : x ≡ y} {f g : A → B}
62 (f≡g : ∀ x → f x ≡ g x) →
63 trans (cong f x≡y) (f≡g y) ≡ trans (f≡g x) (cong g x≡y)
64 naturality {x = x} {x≡y = refl} f≡g =
65 f≡g x ≡⟨ sym (trans-reflʳ _) ⟩
66 trans (f≡g x) refl ∎
67 where open ≡-Reasoning
68
69 -- A lemma that is very similar to Corollary 2.4.4 from the HoTT book.
70
71 cong-≡id : ∀ {f : A → A} {x : A} (f≡id : ∀ x → f x ≡ x) →
72 cong f (f≡id x) ≡ f≡id (f x)
73 cong-≡id {f = f} {x} f≡id = begin
74 cong f fx≡x ≡⟨ sym (trans-reflʳ _) ⟩
75 trans (cong f fx≡x) refl ≡⟨ cong (trans _) (sym (trans-symʳ fx≡x)) ⟩
76 trans (cong f fx≡x) (trans fx≡x (sym fx≡x)) ≡⟨ sym (trans-assoc (cong f fx≡x)) ⟩
77 trans (trans (cong f fx≡x) fx≡x) (sym fx≡x) ≡⟨ cong (λ p → trans p (sym _)) (naturality f≡id) ⟩
78 trans (trans f²x≡x (cong id fx≡x)) (sym fx≡x) ≡⟨ cong (λ p → trans (trans f²x≡x p) (sym fx≡x)) (cong-id _) ⟩
79 trans (trans f²x≡x fx≡x) (sym fx≡x) ≡⟨ trans-assoc f²x≡x ⟩
80 trans f²x≡x (trans fx≡x (sym fx≡x)) ≡⟨ cong (trans _) (trans-symʳ fx≡x) ⟩
81 trans f²x≡x refl ≡⟨ trans-reflʳ _ ⟩
82 f≡id (f x) ∎
83 where open ≡-Reasoning; fx≡x = f≡id x; f²x≡x = f≡id (f x)
84
85 module _ (_≟_ : DecidableEquality A) {x y : A} where
86
87 ≡-≟-identity : (eq : x ≡ y) → x ≟ y ≡ yes eq
88 ≡-≟-identity eq = dec-yes-irr (x ≟ y) (Decidable⇒UIP.≡-irrelevant _≟_) eq
89
90 ≢-≟-identity : (x≢y : x ≢ y) → x ≟ y ≡ no x≢y
91 ≢-≟-identity = dec-no (x ≟ y)
92
93
94 ------------------------------------------------------------------------
95 -- Inspect
96
97 -- Inspect can be used when you want to pattern match on the result r
98 -- of some expression e, and you also need to "remember" that r ≡ e.
99
100 -- See README.Inspect for an explanation of how/why to use this.
101
102 -- Normally (but not always) the new `with ... in` syntax described at
103 -- https://agda.readthedocs.io/en/v2.6.4/language/with-abstraction.html#with-abstraction-equality
104 -- can be used instead."
105
106 record Reveal_·_is_ {A : Set a} {B : A → Set b}
107 (f : (x : A) → B x) (x : A) (y : B x) :
108 Set (a ⊔ b) where
109 constructor [_]
110 field eq : f x ≡ y
111
112 inspect : ∀ {A : Set a} {B : A → Set b}
113 (f : (x : A) → B x) (x : A) → Reveal f · x is f x
114 inspect f x = [ refl ]
115
116
117 ------------------------------------------------------------------------
118 -- DEPRECATED NAMES
119 ------------------------------------------------------------------------
120 -- Please use the new names as continuing support for the old names is
121 -- not guaranteed.
122
123 -- Version 2.0
124
125 isPropositional : Set a → Set a
126 isPropositional = Irrelevant
127
128 {-# WARNING_ON_USAGE isPropositional
129 "Warning: isPropositional was deprecated in v2.0.
130 Please use Relation.Nullary.Irrelevant instead. "
131 #-}
132