Skip to content

Commit bf7c745

Browse files
jamesmckinnaandreasabel
authored andcommitted
Remove (almost!) all external use of _≤″_ beyond Data.Nat.* (#2262)
* additional proofs and patterns in `Data.Nat.Properties` * added two projections; refactored `pad*` operations * `CHANGELOG` * removed one more use * removed final uses of `<″-offset` outside `Data.Nat.Base|Properties` * rename `≤-proof` to `m≤n⇒∃[o]m+o≡n` * removed new pattern synonyms * interim commit: deprecate everything! * add guarded monus; make arguments more irrelevant * fixed up `CHANGELOG` * propagate use of irrelevance * tidy up deprecations; reinstate `s<″s⁻¹` for `Data.Fin.Properties` * tightened up the deprecation story * paragraph on use of `pattern` synonyms * removed `import` * Update CHANGELOG.md Fix refs to Algebra.Definitions.RawMagma * Update Base.agda Fix refs. to Algebra.Definitions.RawMagma * inlined guarded monus definition in property * remove comment about guarded monus
1 parent 25b3e87 commit bf7c745

File tree

8 files changed

+114
-53
lines changed

8 files changed

+114
-53
lines changed

CHANGELOG.md

+24-5
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ Deprecated names
9999
map-compose ↦ map-∘
100100
```
101101

102+
* In `Data.Nat.Base`: the following pattern synonyms and definitions are all
103+
deprecated in favour of direct pattern matching on `Algebra.Definitions.RawMagma._∣ˡ_._,_`
104+
```agda
105+
pattern less-than-or-equal {k} eq = k , eq
106+
pattern ≤″-offset k = k , refl
107+
pattern <″-offset k = k , refl
108+
s≤″s⁻¹
109+
```
110+
102111
* In `Data.Nat.Divisibility.Core`:
103112
```agda
104113
*-pres-∣ ↦ Data.Nat.Divisibility.*-pres-∣
@@ -663,12 +672,16 @@ Additions to existing modules
663672

664673
* Added new proofs in `Data.Nat.Properties`:
665674
```agda
666-
m≤n+o⇒m∸n≤o : ∀ m n {o} → m ≤ n + o → m ∸ n ≤ o
667-
m<n+o⇒m∸n<o : ∀ m n {o} → .{{NonZero o}} → m < n + o → m ∸ n < o
668-
pred-cancel-≤ : pred m ≤ pred n → (m ≡ 1 × n ≡ 0) ⊎ m ≤ n
669-
pred-cancel-< : pred m < pred n → m < n
675+
m≤n+o⇒m∸n≤o : ∀ m n {o} → m ≤ n + o → m ∸ n ≤ o
676+
m<n+o⇒m∸n<o : ∀ m n {o} → .{{NonZero o}} → m < n + o → m ∸ n < o
677+
pred-cancel-≤ : pred m ≤ pred n → (m ≡ 1 × n ≡ 0) ⊎ m ≤ n
678+
pred-cancel-< : pred m < pred n → m < n
670679
pred-injective : .{{NonZero m}} → .{{NonZero n}} → pred m ≡ pred n → m ≡ n
671-
pred-cancel-≡ : pred m ≡ pred n → ((m ≡ 0 × n ≡ 1) ⊎ (m ≡ 1 × n ≡ 0)) ⊎ m ≡ n
680+
pred-cancel-≡ : pred m ≡ pred n → ((m ≡ 0 × n ≡ 1) ⊎ (m ≡ 1 × n ≡ 0)) ⊎ m ≡ n
681+
682+
<⇒<″ : _<_ ⇒ _<″_
683+
m≤n⇒∃[o]m+o≡n : .(m ≤ n) → ∃ λ k → m + k ≡ n
684+
guarded-∸≗∸ : .(m≤n : m ≤ n) → let k , _ = m≤n⇒∃[o]m+o≡n m≤n in k ≡ n ∸ m
672685
```
673686

674687
* Added new proofs to `Data.Nat.Primality`:
@@ -769,6 +782,12 @@ Additions to existing modules
769782
Stable : Pred A ℓ → Set _
770783
```
771784

785+
* Added new functions in `Data.Vec.Bounded.Base`:
786+
```agda
787+
isBounded : (as : Vec≤ A n) → Vec≤.length as ≤ n
788+
toVec : (as : Vec≤ A n) → Vec A (Vec≤.length as)
789+
```
790+
772791
* In `Function.Bundles`, added `_⟶ₛ_` as a synonym for `Func` that can
773792
be used infix.
774793

doc/style-guide.md

+8
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,14 @@ Type formers:
657657

658658
#### Specific pragmatics/idiomatic patterns
659659

660+
## Use of `pattern` synonyms
661+
662+
In general, these are intended to be used to provide specialised
663+
constructors for `Data` types (and sometimes, inductive
664+
families/binary relations such as `Data.Nat.Divisibility._∣_`), and as
665+
such, their use should be restricted to `Base` or `Core` modules, and
666+
not pollute the namespaces of `Properties` or other modules.
667+
660668
## Use of `with` notation
661669

662670
Thinking on this has changed since the early days of the library, with

src/Data/Fin/Properties.agda

+3-3
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@ fromℕ<-injective (suc _) (suc _) {o = suc _} m<n n<o r
247247

248248
fromℕ<≡fromℕ<″ : (m<n : m ℕ.< n) (m<″n : m ℕ.<″ n)
249249
fromℕ< m<n ≡ fromℕ<″ m m<″n
250-
fromℕ<≡fromℕ<″ {m = zero} m<n (ℕ.<″-offset _) = refl
251-
fromℕ<≡fromℕ<″ {m = suc m} m<n (ℕ.<″-offset _)
252-
= cong suc (fromℕ<≡fromℕ<″ (ℕ.s<s⁻¹ m<n) (ℕ.<″-offset _))
250+
fromℕ<≡fromℕ<″ {m = zero} {n = suc _} _ _ = refl
251+
fromℕ<≡fromℕ<″ {m = suc m} {n = suc _} m<n m<″n
252+
= cong suc (fromℕ<≡fromℕ<″ (ℕ.s<s⁻¹ m<n) (ℕ.s<″s⁻¹ m<″n))
253253

254254
toℕ-fromℕ<″ : (m<n : m ℕ.<″ n) toℕ (fromℕ<″ m m<n) ≡ m
255255
toℕ-fromℕ<″ {m} {n} m<n = begin

src/Data/Nat/Base.agda

+24-13
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,6 @@ infix 4 _≤″_ _<″_ _≥″_ _>″_
363363
_≤″_ : (m n : ℕ) Set
364364
_≤″_ = _∣ˡ_ +-rawMagma
365365

366-
pattern less-than-or-equal {k} proof = k , proof
367-
368366
_<″_ : Rel ℕ 0ℓ
369367
m <″ n = suc m ≤″ n
370368

@@ -374,18 +372,10 @@ m ≥″ n = n ≤″ m
374372
_>″_ : Rel ℕ 0ℓ
375373
m >″ n = n <″ m
376374

377-
-- Smart constructors of _≤″_ and _<″_
378-
379-
pattern ≤″-offset k = less-than-or-equal {k = k} refl
380-
pattern <″-offset k = ≤″-offset k
381-
382-
-- Smart destructors of _<″_
383-
384-
s≤″s⁻¹ : {m n} suc m ≤″ suc n m ≤″ n
385-
s≤″s⁻¹ (≤″-offset k) = ≤″-offset k
375+
-- Smart destructor of _<″_
386376

387377
s<″s⁻¹ : {m n} suc m <″ suc n m <″ n
388-
s<″s⁻¹ (<″-offset k) = <″-offset k
378+
s<″s⁻¹ (k , refl) = k , refl
389379

390380
-- _≤‴_: this definition is useful for induction with an upper bound.
391381

@@ -429,5 +419,26 @@ compare (suc m) (suc n) with compare m n
429419
-- Please use the new names as continuing support for the old names is
430420
-- not guaranteed.
431421

432-
-- Version 2.0
422+
-- Version 2.1
423+
424+
-- Smart constructors of _≤″_ and _<″_
425+
pattern less-than-or-equal {k} eq = k , eq
426+
{-# WARNING_ON_USAGE less-than-or-equal
427+
"Warning: less-than-or-equal was deprecated in v2.1. Please match directly on proofs of ≤″ using constructor Algebra.Definitions.RawMagma._∣ˡ_._,_ instead. "
428+
#-}
429+
pattern ≤″-offset k = k , refl
430+
{-# WARNING_ON_USAGE ≤″-offset
431+
"Warning: ≤″-offset was deprecated in v2.1. Please match directly on proofs of ≤″ using pattern (_, refl) from Algebra.Definitions.RawMagma._∣ˡ_ instead. "
432+
#-}
433+
pattern <″-offset k = k , refl
434+
{-# WARNING_ON_USAGE <″-offset
435+
"Warning: <″-offset was deprecated in v2.1. Please match directly on proofs of ≤″ using pattern (_, refl) from Algebra.Definitions.RawMagma._∣ˡ_ instead. "
436+
#-}
437+
438+
-- Smart destructors of _<″_
433439

440+
s≤″s⁻¹ : {m n} suc m ≤″ suc n m ≤″ n
441+
s≤″s⁻¹ (k , refl) = k , refl
442+
{-# WARNING_ON_USAGE s≤″s⁻¹
443+
"Warning: s≤″s⁻¹ was deprecated in v2.1. Please match directly on proofs of ≤″ using pattern (_, refl) from Algebra.Definitions.RawMagma._∣ˡ_ instead. "
444+
#-}

src/Data/Nat/DivMod.agda

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ open import Data.Nat.DivMod.Core
1717
open import Data.Nat.Divisibility.Core
1818
open import Data.Nat.Induction
1919
open import Data.Nat.Properties
20+
open import Data.Product.Base using (_,_)
2021
open import Data.Sum.Base using (inj₁; inj₂)
2122
open import Function.Base using (_$_; _∘_)
2223
open import Relation.Binary.PropositionalEquality.Core
@@ -105,7 +106,7 @@ m%n≤m : ∀ m n .{{_ : NonZero n}} → m % n ≤ m
105106
m%n≤m m (suc n-1) = a[modₕ]n≤a 0 m n-1
106107

107108
m≤n⇒m%n≡m : m ≤ n m % suc n ≡ m
108-
m≤n⇒m%n≡m {m = m} m≤n with ≤″-offset k ≤⇒≤″ m≤n
109+
m≤n⇒m%n≡m {m = m} m≤n with k , refl m≤n⇒∃[o]m+o≡n m≤n
109110
= a≤n⇒a[modₕ]n≡a 0 (m + k) m k
110111

111112
m<n⇒m%n≡m : .{{_ : NonZero n}} m < n m % n ≡ m

src/Data/Nat/Properties.agda

+38-24
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module Data.Nat.Properties where
1414
open import Axiom.UniquenessOfIdentityProofs using (module Decidable⇒UIP)
1515
open import Algebra.Bundles using (Magma; Semigroup; CommutativeSemigroup;
1616
CommutativeMonoid; Monoid; Semiring; CommutativeSemiring; CommutativeSemiringWithoutOne)
17+
open import Algebra.Definitions.RawMagma using (_,_)
1718
open import Algebra.Morphism
1819
open import Algebra.Consequences.Propositional
1920
using (comm+cancelˡ⇒cancelʳ; comm∧distrʳ⇒distrˡ; comm∧distrˡ⇒distrʳ)
@@ -41,7 +42,7 @@ open import Relation.Binary
4142
open import Relation.Binary.Consequences using (flip-Connex)
4243
open import Relation.Binary.PropositionalEquality
4344
open import Relation.Nullary hiding (Irrelevant)
44-
open import Relation.Nullary.Decidable using (True; via-injection; map′)
45+
open import Relation.Nullary.Decidable using (True; via-injection; map′; recompute)
4546
open import Relation.Nullary.Negation.Core using (¬_; contradiction)
4647
open import Relation.Nullary.Reflects using (fromEquivalence)
4748

@@ -2106,31 +2107,46 @@ n≤′m+n (suc m) n = ≤′-step (n≤′m+n m n)
21062107
-- Properties of _≤″_ and _<″_
21072108
------------------------------------------------------------------------
21082109

2109-
m<ᵇn⇒1+m+[n-1+m]≡n : m n T (m <ᵇ n) suc m + (n ∸ suc m) ≡ n
2110-
m<ᵇn⇒1+m+[n-1+m]≡n m n lt = m+[n∸m]≡n (<ᵇ⇒< m n lt)
2110+
-- equivalence of _≤″_ to _≤_
21112111

2112-
m<ᵇ1+m+n : m {n} T (m <ᵇ suc (m + n))
2113-
m<ᵇ1+m+n m = <⇒<ᵇ (m≤m+n (suc m) _)
2112+
≤⇒≤″ : _≤_ ⇒ _≤″_
2113+
≤⇒≤″ = (_ ,_) ∘ m+[n∸m]≡n
21142114

2115-
<⇒<″ : T (m <ᵇ n) m <″ n
2116-
<⇒<″ {m} {n} leq = less-than-or-equal (m+[n∸m]≡n (<ᵇ⇒< m n leq))
2115+
<⇒<″ : _<_ ⇒ _<″_
2116+
<⇒<″ = ≤⇒≤″
21172117

2118-
<″⇒<ᵇ : {m n} m <″ n T (m <ᵇ n)
2119-
<″⇒<ᵇ {m} (<″-offset k) = <⇒<ᵇ (m≤m+n (suc m) k)
2118+
≤″⇒≤ : _≤″_ ⇒ _≤_
2119+
≤″⇒≤ (k , refl) = m≤m+n _ k
21202120

21212121
-- equivalence to the old definition of _≤″_
21222122

2123-
≤″-proof : {m n} (le : m ≤″ n) let less-than-or-equal {k} _ = le in m + k ≡ n
2124-
≤″-proof (less-than-or-equal prf) = prf
2123+
≤″-proof : (le : m ≤″ n) let k , _ = le in m + k ≡ n
2124+
≤″-proof (_ , prf) = prf
21252125

2126-
-- equivalence to _≤_
2126+
-- yielding analogous proof for _≤_
21272127

2128-
≤″⇒≤ : _≤″_ ⇒ _≤_
2129-
≤″⇒≤ {zero} (≤″-offset k) = z≤n {k}
2130-
≤″⇒≤ {suc m} (≤″-offset k) = s≤s (≤″⇒≤ (≤″-offset k))
2128+
m≤n⇒∃[o]m+o≡n : .(m ≤ n) λ k m + k ≡ n
2129+
m≤n⇒∃[o]m+o≡n m≤n = _ , m+[n∸m]≡n (recompute (_ ≤? _) m≤n)
21312130

2132-
≤⇒≤″ : _≤_ ⇒ _≤″_
2133-
≤⇒≤″ = less-than-or-equal ∘ m+[n∸m]≡n
2131+
-- whose witness is equal to monus
2132+
2133+
guarded-∸≗∸ : {m n} .(m≤n : m ≤ n)
2134+
let k , _ = m≤n⇒∃[o]m+o≡n m≤n in k ≡ n ∸ m
2135+
guarded-∸≗∸ m≤n = refl
2136+
2137+
-- equivalence of _<″_ to _<ᵇ_
2138+
2139+
m<ᵇn⇒1+m+[n-1+m]≡n : m n T (m <ᵇ n) suc m + (n ∸ suc m) ≡ n
2140+
m<ᵇn⇒1+m+[n-1+m]≡n m n lt = m+[n∸m]≡n (<ᵇ⇒< m n lt)
2141+
2142+
m<ᵇ1+m+n : m {n} T (m <ᵇ suc (m + n))
2143+
m<ᵇ1+m+n m = <⇒<ᵇ (m≤m+n (suc m) _)
2144+
2145+
<ᵇ⇒<″ : T (m <ᵇ n) m <″ n
2146+
<ᵇ⇒<″ {m} {n} = <⇒<″ ∘ (<ᵇ⇒< m n)
2147+
2148+
<″⇒<ᵇ : {m n} m <″ n T (m <ᵇ n)
2149+
<″⇒<ᵇ {m} (k , refl) = <⇒<ᵇ (m≤m+n (suc m) k)
21342150

21352151
-- NB: we use the builtin function `_<ᵇ_ : (m n : ℕ) → Bool` here so
21362152
-- that the function quickly decides whether to return `yes` or `no`.
@@ -2144,7 +2160,7 @@ _<″?_ : Decidable _<″_
21442160
m <″? n = map′ <ᵇ⇒<″ <″⇒<ᵇ (T? (m <ᵇ n))
21452161

21462162
_≤″?_ : Decidable _≤″_
2147-
zero ≤″? n = yes (≤″-offset n)
2163+
zero ≤″? n = yes (n , refl)
21482164
suc m ≤″? n = m <″? n
21492165

21502166
_≥″?_ : Decidable _≥″_
@@ -2154,10 +2170,9 @@ _>″?_ : Decidable _>″_
21542170
_>″?_ = flip _<″?_
21552171

21562172
≤″-irrelevant : Irrelevant _≤″_
2157-
≤″-irrelevant {m} (less-than-or-equal eq₁)
2158-
(less-than-or-equal eq₂)
2173+
≤″-irrelevant {m} (_ , eq₁) (_ , eq₂)
21592174
with refl +-cancelˡ-≡ m _ _ (trans eq₁ (sym eq₂))
2160-
= cong less-than-or-equal (≡-irrelevant eq₁ eq₂)
2175+
= cong (_ ,_) (≡-irrelevant eq₁ eq₂)
21612176

21622177
<″-irrelevant : Irrelevant _<″_
21632178
<″-irrelevant = ≤″-irrelevant
@@ -2173,8 +2188,8 @@ _>″?_ = flip _<″?_
21732188
------------------------------------------------------------------------
21742189

21752190
≤‴⇒≤″ : {m n} m ≤‴ n m ≤″ n
2176-
≤‴⇒≤″ {m = m} ≤‴-refl = less-than-or-equal {k = 0} (+-identityʳ m)
2177-
≤‴⇒≤″ {m = m} (≤‴-step m≤n) = less-than-or-equal (trans (+-suc m _) (≤″-proof (≤‴⇒≤″ m≤n)))
2191+
≤‴⇒≤″ {m = m} ≤‴-refl = 0 , +-identityʳ m
2192+
≤‴⇒≤″ {m = m} (≤‴-step m≤n) = _ , trans (+-suc m _) (≤″-proof (≤‴⇒≤″ m≤n))
21782193

21792194
m≤‴m+k : {m n k} m + k ≡ n m ≤‴ n
21802195
m≤‴m+k {m} {k = zero} refl = subst (λ z m ≤‴ z) (sym (+-identityʳ m)) (≤‴-refl {m})
@@ -2397,4 +2412,3 @@ open Data.Nat.Base public
23972412
{-# WARNING_ON_USAGE <-transˡ
23982413
"Warning: <-transˡ was deprecated in v2.0. Please use <-≤-trans instead. "
23992414
#-}
2400-

src/Data/Nat/WithK.agda

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88

99
module Data.Nat.WithK where
1010

11+
open import Algebra.Definitions.RawMagma using (_,_)
1112
open import Data.Nat.Base
1213
open import Relation.Binary.PropositionalEquality.WithK
1314

1415
≤″-erase : {m n} m ≤″ n m ≤″ n
15-
≤″-erase (less-than-or-equal eq) = less-than-or-equal (≡-erase eq)
16+
≤″-erase (_ , eq) = _ , ≡-erase eq

src/Data/Vec/Bounded/Base.agda

+13-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ open import Data.These.Base as These using (These)
2121
open import Function.Base using (_∘_; id; _$_)
2222
open import Level using (Level)
2323
open import Relation.Nullary.Decidable.Core using (recompute)
24-
open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_)
24+
open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_; refl)
2525
open import Relation.Binary.PropositionalEquality.Properties
2626
using (module ≡-Reasoning)
2727

@@ -43,20 +43,27 @@ record Vec≤ (A : Set a) (n : ℕ) : Set a where
4343
vec : Vec A length
4444
.bound : length ≤ n
4545

46+
-- projection to recompute irrelevant field
47+
isBounded : (as : Vec≤ A n) Vec≤.length as ≤ n
48+
isBounded as@(_ , m≤n) = recompute (_ ℕ.≤? _) m≤n
49+
4650
------------------------------------------------------------------------
4751
-- Conversion functions
4852

53+
toVec : (as : Vec≤ A n) Vec A (Vec≤.length as)
54+
toVec as@(vs , _) = vs
55+
4956
fromVec : Vec A n Vec≤ A n
5057
fromVec v = v , ℕ.≤-refl
5158

5259
padRight : A Vec≤ A n Vec A n
53-
padRight a (vs , m≤n)
54-
with ≤″-offset k recompute (_ ℕ.≤″? _) (ℕ.≤⇒≤″ m≤n)
60+
padRight a as@(vs , m≤n)
61+
with k , refl ℕ.m≤n⇒∃[o]m+o≡n m≤n
5562
= vs Vec.++ Vec.replicate k a
5663

5764
padLeft : A Vec≤ A n Vec A n
5865
padLeft a record { length = m ; vec = vs ; bound = m≤n }
59-
with ≤″-offset k recompute (_ ℕ.≤″? _) (ℕ.≤⇒≤″ m≤n)
66+
with k , refl ℕ.m≤n⇒∃[o]m+o≡n m≤n
6067
rewrite ℕ.+-comm m k
6168
= Vec.replicate k a Vec.++ vs
6269

@@ -72,7 +79,7 @@ private
7279

7380
padBoth : A A Vec≤ A n Vec A n
7481
padBoth aₗ aᵣ record { length = m ; vec = vs ; bound = m≤n }
75-
with ≤″-offset k recompute (_ ℕ.≤″? _) (ℕ.≤⇒≤″ m≤n)
82+
with k , refl ℕ.m≤n⇒∃[o]m+o≡n m≤n
7683
rewrite split m k
7784
= Vec.replicate ⌊ k /2⌋ aₗ
7885
Vec.++ vs
@@ -83,7 +90,7 @@ fromList : (as : List A) → Vec≤ A (List.length as)
8390
fromList = fromVec ∘ Vec.fromList
8491

8592
toList : Vec≤ A n List A
86-
toList = Vec.toList ∘ Vec≤.vec
93+
toList = Vec.toList ∘ toVec
8794

8895
------------------------------------------------------------------------
8996
-- Creating new Vec≤ vectors

0 commit comments

Comments
 (0)