Debian Codegraph @

src/Axiom/UniquenessOfIdentityProofs.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Results concerning uniqueness of identity proofs
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Axiom.UniquenessOfIdentityProofs where
10
11 open import Level using (Level)
12 open import Relation.Nullary.Decidable.Core
13 using (recompute; recompute-constant)
14 open import Relation.Binary.Core using (Rel; _⇒_)
15 open import Relation.Binary.Definitions
16 using (Sym; Irrelevant; DecidableEquality)
17 open import Relation.Binary.PropositionalEquality.Core
18 using (_≡_; refl; trans; sym; cong)
19 open import Relation.Binary.PropositionalEquality.Properties
20
21 private
22 variable
23 a : Level
24 A : Set a
25 x y : A
26
27 ------------------------------------------------------------------------
28 -- Definition
29 --
30 -- Uniqueness of Identity Proofs (UIP) states that all proofs of
31 -- equality are themselves equal. In other words, the equality relation
32 -- is irrelevant. Here we define UIP relative to a given type.
33
34 UIP : (A : Set a) → Set a
35 UIP A = Irrelevant {A = A} _≡_
36
37 ------------------------------------------------------------------------
38 -- Properties
39
40 -- UIP always holds when using axiom K
41 -- (see `Axiom.UniquenessOfIdentityProofs.WithK`).
42
43 -- The existence of a constant function over proofs of equality for
44 -- elements in A is enough to prove UIP for A. Indeed, we can relate any
45 -- proof to its image via this function which we then know is equal to
46 -- the image of any other proof.
47
48 module Constant⇒UIP
49 (f : _≡_ {A = A} ⇒ _≡_)
50 (f-constant : ∀ {x y} (p q : x ≡ y) → f p ≡ f q)
51 where
52
53 ≡-canonical : (p : x ≡ y) → trans (sym (f refl)) (f p) ≡ p
54 ≡-canonical refl = trans-symˡ (f refl)
55
56 ≡-irrelevant : UIP A
57 ≡-irrelevant p q = begin
58 p ≡⟨ sym (≡-canonical p) ⟩
59 trans (sym (f refl)) (f p) ≡⟨ cong (trans _) (f-constant p q) ⟩
60 trans (sym (f refl)) (f q) ≡⟨ ≡-canonical q ⟩
61 q ∎
62 where open ≡-Reasoning
63
64 -- If equality is decidable for a given type, then we can prove UIP for
65 -- that type. Indeed, the decision procedure allows us to define a
66 -- function over proofs of equality which is constant: it returns the
67 -- proof produced by the decision procedure.
68
69 module Decidable⇒UIP (_≟_ : DecidableEquality A)
70 where
71
72 ≡-normalise : _≡_ {A = A} ⇒ _≡_
73 ≡-normalise {x} {y} x≡y = recompute (x ≟ y) x≡y
74
75 ≡-normalise-constant : (p q : x ≡ y) → ≡-normalise p ≡ ≡-normalise q
76 ≡-normalise-constant {x = x} {y = y} = recompute-constant (x ≟ y)
77
78 ≡-irrelevant : UIP A
79 ≡-irrelevant = Constant⇒UIP.≡-irrelevant ≡-normalise ≡-normalise-constant