Skip to content

Commit b74b2eb

Browse files
authored
Implement ≤-total in terms of _≤?_ (#2440)
* Define Data.Nat.≰⇒≥ directly and earlier * Define Data.Nat.≤-total in terms of _≤?_ * Update changelog * Be a bit lazier
1 parent cceb530 commit b74b2eb

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ Bug-fixes
1212
Non-backwards compatible changes
1313
--------------------------------
1414

15+
* The implementation of `≤-total` in `Data.Nat.Properties` has been altered
16+
to use operations backed by primitives, rather than recursion, making it
17+
significantly faster. However, its reduction behaviour on open terms may have
18+
changed.
19+
1520
Minor improvements
1621
------------------
1722

src/Data/Nat/Properties.agda

+10-8
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ m ≟ n = map′ (≡ᵇ⇒≡ m n) (≡⇒≡ᵇ m n) (T? (m ≡ᵇ n))
162162
-- Properties of _≤_
163163
------------------------------------------------------------------------
164164

165+
≰⇒≥ : _≰_ ⇒ _≥_
166+
≰⇒≥ {m} {zero} m≰n = z≤n
167+
≰⇒≥ {zero} {suc n} m≰n = contradiction z≤n m≰n
168+
≰⇒≥ {suc m} {suc n} m≰n = s≤s (≰⇒≥ (m≰n ∘ s≤s))
169+
165170
------------------------------------------------------------------------
166171
-- Relational properties of _≤_
167172

@@ -180,11 +185,6 @@ m ≟ n = map′ (≡ᵇ⇒≡ m n) (≡⇒≡ᵇ m n) (T? (m ≡ᵇ n))
180185
≤-trans z≤n _ = z≤n
181186
≤-trans (s≤s m≤n) (s≤s n≤o) = s≤s (≤-trans m≤n n≤o)
182187

183-
≤-total : Total _≤_
184-
≤-total zero _ = inj₁ z≤n
185-
≤-total _ zero = inj₂ z≤n
186-
≤-total (suc m) (suc n) = Sum.map s≤s s≤s (≤-total m n)
187-
188188
≤-irrelevant : Irrelevant _≤_
189189
≤-irrelevant z≤n z≤n = refl
190190
≤-irrelevant (s≤s m≤n₁) (s≤s m≤n₂) = cong s≤s (≤-irrelevant m≤n₁ m≤n₂)
@@ -203,6 +203,11 @@ m ≤? n = map′ (≤ᵇ⇒≤ m n) ≤⇒≤ᵇ (T? (m ≤ᵇ n))
203203
_≥?_ : Decidable _≥_
204204
_≥?_ = flip _≤?_
205205

206+
≤-total : Total _≤_
207+
≤-total m n with m ≤? n
208+
... | true because m≤n = inj₁ (invert m≤n)
209+
... | false because m≰n = inj₂ (≰⇒≥ (invert m≰n))
210+
206211
------------------------------------------------------------------------
207212
-- Structures
208213

@@ -331,9 +336,6 @@ n≤1⇒n≡0∨n≡1 (s≤s z≤n) = inj₂ refl
331336
≰⇒> {suc m} {zero} _ = z<s
332337
≰⇒> {suc m} {suc n} m≰n = s<s (≰⇒> (m≰n ∘ s≤s))
333338

334-
≰⇒≥ : _≰_ ⇒ _≥_
335-
≰⇒≥ = <⇒≤ ∘ ≰⇒>
336-
337339
≮⇒≥ : _≮_ ⇒ _≥_
338340
≮⇒≥ {_} {zero} _ = z≤n
339341
≮⇒≥ {zero} {suc j} 1≮j+1 = contradiction z<s 1≮j+1

0 commit comments

Comments
 (0)