Skip to content

Commit 2257450

Browse files
jamesmckinnaandreasabel
authored andcommitted
Redefines Data.Nat.Base._≤″_ (#1948)
1 parent a2341cc commit 2257450

File tree

3 files changed

+101
-61
lines changed

3 files changed

+101
-61
lines changed

CHANGELOG.md

+28
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,32 @@ Non-backwards compatible changes
585585
Prime n = ∀ {d} → 2 ≤ d → d < n → d ∤ n
586586
```
587587

588+
### Change in the definition of `_≤″_` (issue #1919)
589+
590+
* The definition of `_≤″_` in `Data.Nat.Base` was previously:
591+
```agda
592+
record _≤″_ (m n : ℕ) : Set where
593+
constructor less-than-or-equal
594+
field
595+
{k} : ℕ
596+
proof : m + k ≡ n
597+
```
598+
which introduced a spurious additional definition, when this is in fact, modulo
599+
field names and implicit/explicit qualifiers, equivalent to the definition of left-
600+
divisibility, `_∣ˡ_` for the `RawMagma` structure of `_+_`. Since the addition of
601+
raw bundles to `Data.X.Base`, this definition can now be made directly. Knock-on
602+
consequences include the need to retain the old constructor name, now introduced
603+
as a pattern synonym, and introduction of (a function equivalent to) the former
604+
field name/projection function `proof` as `≤″-proof` in `Data.Nat.Properties`.
605+
606+
* Accordingly, the definition has been changed to:
607+
```agda
608+
_≤″_ : (m n : ℕ) → Set
609+
_≤″_ = _∣ˡ_ +-rawMagma
610+
611+
pattern less-than-or-equal {k} prf = k , prf
612+
```
613+
588614
### Renaming of `Reflection` modules
589615

590616
* Under the `Reflection` module, there were various impending name clashes
@@ -2584,6 +2610,8 @@ Additions to existing modules
25842610
<⇒<′ : m < n → m <′ n
25852611
<′⇒< : m <′ n → m < n
25862612
2613+
≤″-proof : (le : m ≤″ n) → let less-than-or-equal {k} _ = le in m + k ≡ n
2614+
25872615
m+n≤p⇒m≤p∸n : m + n ≤ p → m ≤ p ∸ n
25882616
m≤p∸n⇒m+n≤p : n ≤ p → m ≤ p ∸ n → m + n ≤ p
25892617

src/Data/Nat/Base.agda

+61-52
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
module Data.Nat.Base where
1313

1414
open import Algebra.Bundles.Raw using (RawMagma; RawMonoid; RawNearSemiring; RawSemiring)
15+
open import Algebra.Definitions.RawMagma using (_∣ˡ_)
1516
open import Data.Bool.Base using (Bool; true; false; T; not)
1617
open import Data.Parity.Base using (Parity; 0ℙ; 1ℙ)
18+
open import Data.Product.Base using (_,_)
1719
open import Level using (0ℓ)
1820
open import Relation.Binary.Core using (Rel)
1921
open import Relation.Binary.PropositionalEquality.Core
@@ -120,11 +122,59 @@ instance
120122
>-nonZero⁻¹ (suc n) = z<s
121123

122124
------------------------------------------------------------------------
123-
-- Arithmetic
125+
-- Raw bundles
124126

125127
open import Agda.Builtin.Nat public
126128
using (_+_; _*_) renaming (_-_ to _∸_)
127129

130+
+-rawMagma : RawMagma 0ℓ 0ℓ
131+
+-rawMagma = record
132+
{ _≈_ = _≡_
133+
; _∙_ = _+_
134+
}
135+
136+
+-0-rawMonoid : RawMonoid 0ℓ 0ℓ
137+
+-0-rawMonoid = record
138+
{ _≈_ = _≡_
139+
; _∙_ = _+_
140+
; ε = 0
141+
}
142+
143+
*-rawMagma : RawMagma 0ℓ 0ℓ
144+
*-rawMagma = record
145+
{ _≈_ = _≡_
146+
; _∙_ = _*_
147+
}
148+
149+
*-1-rawMonoid : RawMonoid 0ℓ 0ℓ
150+
*-1-rawMonoid = record
151+
{ _≈_ = _≡_
152+
; _∙_ = _*_
153+
; ε = 1
154+
}
155+
156+
+-*-rawNearSemiring : RawNearSemiring 0ℓ 0ℓ
157+
+-*-rawNearSemiring = record
158+
{ Carrier = _
159+
; _≈_ = _≡_
160+
; _+_ = _+_
161+
; _*_ = _*_
162+
; 0# = 0
163+
}
164+
165+
+-*-rawSemiring : RawSemiring 0ℓ 0ℓ
166+
+-*-rawSemiring = record
167+
{ Carrier = _
168+
; _≈_ = _≡_
169+
; _+_ = _+_
170+
; _*_ = _*_
171+
; 0# = 0
172+
; 1# = 1
173+
}
174+
175+
------------------------------------------------------------------------
176+
-- Arithmetic
177+
128178
open import Agda.Builtin.Nat
129179
using (div-helper; mod-helper)
130180

@@ -260,14 +310,12 @@ m >′ n = n <′ m
260310

261311
------------------------------------------------------------------------
262312
-- Another alternative definition of _≤_
313+
infix 4 _≤″_ _<″_ _≥″_ _>″_
263314

264-
record _≤″_ (m n : ℕ) : Set where
265-
constructor less-than-or-equal
266-
field
267-
{k} :
268-
proof : m + k ≡ n
315+
_≤″_ : (m n : ℕ) Set
316+
_≤″_ = _∣ˡ_ +-rawMagma
269317

270-
infix 4 _≤″_ _<″_ _≥″_ _>″_
318+
pattern less-than-or-equal {k} proof = k , proof
271319

272320
_<″_ : Rel ℕ 0ℓ
273321
m <″ n = suc m ≤″ n
@@ -316,51 +364,12 @@ compare (suc m) (suc n) with compare m n
316364
... | equal m = equal (suc m)
317365
... | greater n k = greater (suc n) k
318366

319-
------------------------------------------------------------------------
320-
-- Raw bundles
321-
322-
+-rawMagma : RawMagma 0ℓ 0ℓ
323-
+-rawMagma = record
324-
{ _≈_ = _≡_
325-
; _∙_ = _+_
326-
}
327-
328-
+-0-rawMonoid : RawMonoid 0ℓ 0ℓ
329-
+-0-rawMonoid = record
330-
{ _≈_ = _≡_
331-
; _∙_ = _+_
332-
; ε = 0
333-
}
334-
335-
*-rawMagma : RawMagma 0ℓ 0ℓ
336-
*-rawMagma = record
337-
{ _≈_ = _≡_
338-
; _∙_ = _*_
339-
}
340-
341-
*-1-rawMonoid : RawMonoid 0ℓ 0ℓ
342-
*-1-rawMonoid = record
343-
{ _≈_ = _≡_
344-
; _∙_ = _*_
345-
; ε = 1
346-
}
347367

348-
+-*-rawNearSemiring : RawNearSemiring 0ℓ 0ℓ
349-
+-*-rawNearSemiring = record
350-
{ Carrier = _
351-
; _≈_ = _≡_
352-
; _+_ = _+_
353-
; _*_ = _*_
354-
; 0# = 0
355-
}
368+
------------------------------------------------------------------------
369+
-- DEPRECATED NAMES
370+
------------------------------------------------------------------------
371+
-- Please use the new names as continuing support for the old names is
372+
-- not guaranteed.
356373

357-
+-*-rawSemiring : RawSemiring 0ℓ 0ℓ
358-
+-*-rawSemiring = record
359-
{ Carrier = _
360-
; _≈_ = _≡_
361-
; _+_ = _+_
362-
; _*_ = _*_
363-
; 0# = 0
364-
; 1# = 1
365-
}
374+
-- Version 2.0
366375

src/Data/Nat/Properties.agda

+12-9
Original file line numberDiff line numberDiff line change
@@ -2065,6 +2065,11 @@ m<ᵇ1+m+n m = <⇒<ᵇ (m≤m+n (suc m) _)
20652065
<″⇒<ᵇ : {m n} m <″ n T (m <ᵇ n)
20662066
<″⇒<ᵇ {m} (less-than-or-equal refl) = <⇒<ᵇ (m≤m+n (suc m) _)
20672067

2068+
-- equivalence to the old definition of _≤″_
2069+
2070+
≤″-proof : {m n} (le : m ≤″ n) let less-than-or-equal {k} _ = le in m + k ≡ n
2071+
≤″-proof (less-than-or-equal prf) = prf
2072+
20682073
-- equivalence to _≤_
20692074

20702075
≤″⇒≤ : _≤″_ ⇒ _≤_
@@ -2099,8 +2104,8 @@ _>″?_ = flip _<″?_
20992104
≤″-irrelevant : Irrelevant _≤″_
21002105
≤″-irrelevant {m} (less-than-or-equal eq₁)
21012106
(less-than-or-equal eq₂)
2102-
with +-cancelˡ-≡ m _ _ (trans eq₁ (sym eq₂))
2103-
... | refl = cong less-than-or-equal (≡-irrelevant eq₁ eq₂)
2107+
with refl +-cancelˡ-≡ m _ _ (trans eq₁ (sym eq₂))
2108+
= cong less-than-or-equal (≡-irrelevant eq₁ eq₂)
21042109

21052110
<″-irrelevant : Irrelevant _<″_
21062111
<″-irrelevant = ≤″-irrelevant
@@ -2116,17 +2121,15 @@ _>″?_ = flip _<″?_
21162121
------------------------------------------------------------------------
21172122

21182123
≤‴⇒≤″ : {m n} m ≤‴ n m ≤″ n
2119-
≤‴⇒≤″ {m = m} ≤‴-refl = less-than-or-equal {k = 0} (+-identityʳ m)
2120-
≤‴⇒≤″ {m = m} (≤‴-step x) = less-than-or-equal (trans (+-suc m _) (_≤″_.proof ind)) where
2121-
ind = ≤‴⇒≤″ x
2124+
≤‴⇒≤″ {m = m} ≤‴-refl = less-than-or-equal {k = 0} (+-identityʳ m)
2125+
≤‴⇒≤″ {m = m} (≤‴-step m≤n) = less-than-or-equal (trans (+-suc m _) (≤″-proof (≤‴⇒≤″ m≤n)))
21222126

21232127
m≤‴m+k : {m n k} m + k ≡ n m ≤‴ n
2124-
m≤‴m+k {m} {k = zero} refl = subst (λ z m ≤‴ z) (sym (+-identityʳ m)) (≤‴-refl {m})
2125-
m≤‴m+k {m} {k = suc k} proof
2126-
= ≤‴-step (m≤‴m+k {k = k} (trans (sym (+-suc m _)) proof))
2128+
m≤‴m+k {m} {k = zero} refl = subst (λ z m ≤‴ z) (sym (+-identityʳ m)) (≤‴-refl {m})
2129+
m≤‴m+k {m} {k = suc k} prf = ≤‴-step (m≤‴m+k {k = k} (trans (sym (+-suc m _)) prf))
21272130

21282131
≤″⇒≤‴ : {m n} m ≤″ n m ≤‴ n
2129-
≤″⇒≤‴ (less-than-or-equal {k} proof) = m≤‴m+k proof
2132+
≤″⇒≤‴ m≤n = m≤‴m+k (≤″-proof m≤n)
21302133

21312134
0≤‴n : {n} 0 ≤‴ n
21322135
0≤‴n {n} = m≤‴m+k refl

0 commit comments

Comments
 (0)