Debian Codegraph @

src/Data/Float/Properties.agda

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