Debian Codegraph @

src/Data/Word64/Properties.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Properties of operations on machine words
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Data.Word64.Properties where
10
11 import Data.Nat.Base as ℕ
12 open import Data.Bool.Base using (Bool)
13 open import Data.Word64.Base using (_≈_; toℕ; Word64; _<_)
14 import Data.Nat.Properties as ℕ
15 open import Relation.Nullary.Decidable.Core using (map′; ⌊_⌋)
16 open import Relation.Binary
17 using ( _⇒_; Reflexive; Symmetric; Transitive; Substitutive
18 ; Decidable; DecidableEquality; IsEquivalence; IsDecEquivalence
19 ; Setoid; DecSetoid; StrictTotalOrder)
20 import Relation.Binary.Construct.On as On using (decidable; strictTotalOrder)
21 open import Relation.Binary.PropositionalEquality.Core
22 using (_≡_; refl; cong; sym; trans; subst)
23 open import Relation.Binary.PropositionalEquality.Properties
24 using (setoid; decSetoid)
25
26 ------------------------------------------------------------------------
27 -- Primitive properties
28
29 open import Agda.Builtin.Word.Properties
30 renaming (primWord64ToNatInjective to toℕ-injective)
31 public
32
33 ------------------------------------------------------------------------
34 -- Properties of _≈_
35
36 ≈⇒≡ : _≈_ ⇒ _≡_
37 ≈⇒≡ = toℕ-injective _ _
38
39 ≈-reflexive : _≡_ ⇒ _≈_
40 ≈-reflexive = cong toℕ
41
42 ≈-refl : Reflexive _≈_
43 ≈-refl = refl
44
45 ≈-sym : Symmetric _≈_
46 ≈-sym = sym
47
48 ≈-trans : Transitive _≈_
49 ≈-trans = trans
50
51 ≈-subst : ∀ {ℓ} → Substitutive _≈_ ℓ
52 ≈-subst P x≈y p = subst P (≈⇒≡ x≈y) p
53
54 infix 4 _≈?_
55 _≈?_ : Decidable _≈_
56 x ≈? y = toℕ x ℕ.≟ toℕ y
57
58 ≈-isEquivalence : IsEquivalence _≈_
59 ≈-isEquivalence = record
60 { refl = λ {i} → ≈-refl {i}
61 ; sym = λ {i j} → ≈-sym {i} {j}
62 ; trans = λ {i j k} → ≈-trans {i} {j} {k}
63 }
64
65 ≈-setoid : Setoid _ _
66 ≈-setoid = record
67 { isEquivalence = ≈-isEquivalence
68 }
69
70 ≈-isDecEquivalence : IsDecEquivalence _≈_
71 ≈-isDecEquivalence = record
72 { isEquivalence = ≈-isEquivalence
73 ; _≟_ = _≈?_
74 }
75
76 ≈-decSetoid : DecSetoid _ _
77 ≈-decSetoid = record
78 { isDecEquivalence = ≈-isDecEquivalence
79 }
80 ------------------------------------------------------------------------
81 -- Properties of _≡_
82
83 infix 4 _≟_
84 _≟_ : DecidableEquality Word64
85 x ≟ y = map′ ≈⇒≡ ≈-reflexive (x ≈? y)
86
87 ≡-setoid : Setoid _ _
88 ≡-setoid = setoid Word64
89
90 ≡-decSetoid : DecSetoid _ _
91 ≡-decSetoid = decSetoid _≟_
92
93 ------------------------------------------------------------------------
94 -- Boolean equality test.
95
96 infix 4 _==_
97 _==_ : Word64 → Word64 → Bool
98 w₁ == w₂ = ⌊ w₁ ≟ w₂ ⌋
99
100 ------------------------------------------------------------------------
101 -- Properties of _<_
102
103 infix 4 _<?_
104 _<?_ : Decidable _<_
105 _<?_ = On.decidable toℕ ℕ._<_ ℕ._<?_
106
107 <-strictTotalOrder-≈ : StrictTotalOrder _ _ _
108 <-strictTotalOrder-≈ = On.strictTotalOrder ℕ.<-strictTotalOrder toℕ