forked from agda/agda-stdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConat.agda
69 lines (52 loc) · 2 KB
/
Conat.agda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
------------------------------------------------------------------------
-- The Agda standard library
--
-- Coinductive "natural" numbers
------------------------------------------------------------------------
{-# OPTIONS --safe --cubical-compatible --guardedness #-}
module Codata.Musical.Conat where
open import Codata.Musical.Notation
open import Data.Nat.Base using (ℕ; zero; suc)
open import Function.Base using (_∋_)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as P using (_≡_)
------------------------------------------------------------------------
-- Re-exporting the type and basic operations
open import Codata.Musical.Conat.Base public
------------------------------------------------------------------------
-- Some properties
module Coℕ-injective where
suc-injective : ∀ {m n} → (Coℕ ∋ suc m) ≡ suc n → m ≡ n
suc-injective P.refl = P.refl
fromℕ-injective : ∀ {m n} → fromℕ m ≡ fromℕ n → m ≡ n
fromℕ-injective {zero} {zero} eq = P.refl
fromℕ-injective {suc m} {suc n} eq = P.cong suc (fromℕ-injective (P.cong pred eq))
------------------------------------------------------------------------
-- Equality
infix 4 _≈_
data _≈_ : Coℕ → Coℕ → Set where
zero : zero ≈ zero
suc : ∀ {m n} (m≈n : ∞ (♭ m ≈ ♭ n)) → suc m ≈ suc n
module ≈-injective where
suc-injective : ∀ {m n p q} → (suc m ≈ suc n ∋ suc p) ≡ suc q → p ≡ q
suc-injective P.refl = P.refl
setoid : Setoid _ _
setoid = record
{ Carrier = Coℕ
; _≈_ = _≈_
; isEquivalence = record
{ refl = refl
; sym = sym
; trans = trans
}
}
where
refl : Reflexive _≈_
refl {zero} = zero
refl {suc n} = suc (♯ refl)
sym : Symmetric _≈_
sym zero = zero
sym (suc m≈n) = suc (♯ sym (♭ m≈n))
trans : Transitive _≈_
trans zero zero = zero
trans (suc m≈n) (suc n≈k) = suc (♯ trans (♭ m≈n) (♭ n≈k))