Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redefines Data.Nat.Base._≤″_ #1948

Merged
merged 20 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0adbbe8
introduced alternative definitions; revised one usage of previous one
jamesmckinna Apr 22, 2023
b62ef81
deprecated field name (NB tricky)
jamesmckinna Apr 22, 2023
8993f59
installed new definition
jamesmckinna Apr 22, 2023
7f09808
removed old definition; tidied up
jamesmckinna Apr 22, 2023
221ac92
`CHANGELOG` plus portable definition of the `proof` projection
jamesmckinna Apr 22, 2023
5935db4
`CHANGELOG`
jamesmckinna Apr 22, 2023
829ddd5
more explicit deprecation warning
jamesmckinna Apr 22, 2023
e9c7170
typo in `CHANGELOG`
jamesmckinna Apr 23, 2023
824dce6
exchnaged repeated recursive for a nested irrefutbale `with` pattern
jamesmckinna Apr 23, 2023
dbfb5a7
Merge branch 'issue1919' of https://github.com/jamesmckinna/agda-stdl…
jamesmckinna Apr 23, 2023
61ef3f0
Revert "Merge branch 'issue1919' of https://github.com/jamesmckinna/a…
jamesmckinna Apr 23, 2023
693270e
Revert "exchnaged repeated recursive for a nested irrefutbale `with` …
jamesmckinna Apr 23, 2023
f120c1e
tweaks
jamesmckinna Apr 25, 2023
c1edba4
Update CHANGELOG.md
jamesmckinna May 12, 2023
519dde4
removed deprecation wart in favour of new definition in `Data.Nat.Pro…
jamesmckinna Aug 4, 2023
9d451b9
resolved merge conflict
jamesmckinna Aug 4, 2023
1c94a46
removed now-spurious `hiding` directive
jamesmckinna Aug 4, 2023
b44100f
corrected `CHANGELOG`
jamesmckinna Aug 4, 2023
fd163b5
Merge branch 'master' into issue1919
jamesmckinna Aug 4, 2023
056fec1
make equivalence proof `≤″⇒≤‴` more lazy
jamesmckinna Aug 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,32 @@ Non-backwards compatible changes
Prime n = ∀ {d} → 2 ≤ d → d < n → d ∤ n
```

### Change in the definition of `_≤″_` (issue #1919)

* The definition of `_≤″_` in `Data.Nat.Base` was previously:
```agda
record _≤″_ (m n : ℕ) : Set where
constructor less-than-or-equal
field
{k} : ℕ
proof : m + k ≡ n
```
which introduced a spurious additional definition, when this is in fact, modulo
field names and implicit/explicit qualifiers, equivalent to the definition of left-
divisibility, `_∣ˡ_` for the `RawMagma` structure of `_+_`. Since the addition of
raw bundles to `Data.X.Base`, this definition can now be made directly. Knock-on
consequences include the need to retain the old constructor name, now introduced
as a pattern synonym, and introduction of (a function equivalent to) the former
field name/projection function `proof` as `≤″-proof` in `Data.Nat.Properties`.

* Accordingly, the definition has been changed to:
```agda
_≤″_ : (m n : ℕ) → Set
_≤″_ = _∣ˡ_ +-rawMagma

pattern less-than-or-equal {k} prf = k , prf
```

### Renaming of `Reflection` modules

* Under the `Reflection` module, there were various impending name clashes
Expand Down Expand Up @@ -2285,6 +2311,8 @@ Other minor changes
<⇒<′ : m < n → m <′ n
<′⇒< : m <′ n → m < n

≤″-proof : (le : m ≤″ n) → let less-than-or-equal {k} _ = le in m + k ≡ n

m+n≤p⇒m≤p∸n : m + n ≤ p → m ≤ p ∸ n
m≤p∸n⇒m+n≤p : n ≤ p → m ≤ p ∸ n → m + n ≤ p

Expand Down
113 changes: 61 additions & 52 deletions src/Data/Nat/Base.agda
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
module Data.Nat.Base where

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

------------------------------------------------------------------------
-- Arithmetic
-- Raw bundles

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

+-rawMagma : RawMagma 0ℓ 0ℓ
+-rawMagma = record
{ _≈_ = _≡_
; _∙_ = _+_
}

+-0-rawMonoid : RawMonoid 0ℓ 0ℓ
+-0-rawMonoid = record
{ _≈_ = _≡_
; _∙_ = _+_
; ε = 0
}

*-rawMagma : RawMagma 0ℓ 0ℓ
*-rawMagma = record
{ _≈_ = _≡_
; _∙_ = _*_
}

*-1-rawMonoid : RawMonoid 0ℓ 0ℓ
*-1-rawMonoid = record
{ _≈_ = _≡_
; _∙_ = _*_
; ε = 1
}

+-*-rawNearSemiring : RawNearSemiring 0ℓ 0ℓ
+-*-rawNearSemiring = record
{ Carrier = _
; _≈_ = _≡_
; _+_ = _+_
; _*_ = _*_
; 0# = 0
}

+-*-rawSemiring : RawSemiring 0ℓ 0ℓ
+-*-rawSemiring = record
{ Carrier = _
; _≈_ = _≡_
; _+_ = _+_
; _*_ = _*_
; 0# = 0
; 1# = 1
}

------------------------------------------------------------------------
-- Arithmetic

open import Agda.Builtin.Nat
using (div-helper; mod-helper)

Expand Down Expand Up @@ -260,14 +310,12 @@ m >′ n = n <′ m

------------------------------------------------------------------------
-- Another alternative definition of _≤_
infix 4 _≤″_ _<″_ _≥″_ _>″_

record _≤″_ (m n : ℕ) : Set where
constructor less-than-or-equal
field
{k} : ℕ
proof : m + k ≡ n
_≤″_ : (m n : ℕ) → Set
_≤″_ = _∣ˡ_ +-rawMagma

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

_<″_ : Rel ℕ 0ℓ
m <″ n = suc m ≤″ n
Expand Down Expand Up @@ -316,51 +364,12 @@ compare (suc m) (suc n) with compare m n
... | equal m = equal (suc m)
... | greater n k = greater (suc n) k

------------------------------------------------------------------------
-- Raw bundles

+-rawMagma : RawMagma 0ℓ 0ℓ
+-rawMagma = record
{ _≈_ = _≡_
; _∙_ = _+_
}

+-0-rawMonoid : RawMonoid 0ℓ 0ℓ
+-0-rawMonoid = record
{ _≈_ = _≡_
; _∙_ = _+_
; ε = 0
}

*-rawMagma : RawMagma 0ℓ 0ℓ
*-rawMagma = record
{ _≈_ = _≡_
; _∙_ = _*_
}

*-1-rawMonoid : RawMonoid 0ℓ 0ℓ
*-1-rawMonoid = record
{ _≈_ = _≡_
; _∙_ = _*_
; ε = 1
}

+-*-rawNearSemiring : RawNearSemiring 0ℓ 0ℓ
+-*-rawNearSemiring = record
{ Carrier = _
; _≈_ = _≡_
; _+_ = _+_
; _*_ = _*_
; 0# = 0
}
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.

+-*-rawSemiring : RawSemiring 0ℓ 0ℓ
+-*-rawSemiring = record
{ Carrier = _
; _≈_ = _≡_
; _+_ = _+_
; _*_ = _*_
; 0# = 0
; 1# = 1
}
-- Version 2.0

21 changes: 12 additions & 9 deletions src/Data/Nat/Properties.agda
Original file line number Diff line number Diff line change
Expand Up @@ -2057,6 +2057,11 @@ m<ᵇ1+m+n m = <⇒<ᵇ (m≤m+n (suc m) _)
<″⇒<ᵇ : ∀ {m n} → m <″ n → T (m <ᵇ n)
<″⇒<ᵇ {m} (less-than-or-equal refl) = <⇒<ᵇ (m≤m+n (suc m) _)

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

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

-- equivalence to _≤_

≤″⇒≤ : _≤″_ ⇒ _≤_
Expand Down Expand Up @@ -2091,8 +2096,8 @@ _>″?_ = flip _<″?_
≤″-irrelevant : Irrelevant _≤″_
≤″-irrelevant {m} (less-than-or-equal eq₁)
(less-than-or-equal eq₂)
with +-cancelˡ-≡ m _ _ (trans eq₁ (sym eq₂))
... | refl = cong less-than-or-equal (≡-irrelevant eq₁ eq₂)
with refl ← +-cancelˡ-≡ m _ _ (trans eq₁ (sym eq₂))
= cong less-than-or-equal (≡-irrelevant eq₁ eq₂)

<″-irrelevant : Irrelevant _<″_
<″-irrelevant = ≤″-irrelevant
Expand All @@ -2108,17 +2113,15 @@ _>″?_ = flip _<″?_
------------------------------------------------------------------------

≤‴⇒≤″ : ∀{m n} → m ≤‴ n → m ≤″ n
≤‴⇒≤″ {m = m} ≤‴-refl = less-than-or-equal {k = 0} (+-identityʳ m)
≤‴⇒≤″ {m = m} (≤‴-step x) = less-than-or-equal (trans (+-suc m _) (_≤″_.proof ind)) where
ind = ≤‴⇒≤″ x
≤‴⇒≤″ {m = m} ≤‴-refl = less-than-or-equal {k = 0} (+-identityʳ m)
≤‴⇒≤″ {m = m} (≤‴-step m≤n) = less-than-or-equal (trans (+-suc m _) (≤″-proof (≤‴⇒≤″ m≤n)))

m≤‴m+k : ∀{m n k} → m + k ≡ n → m ≤‴ n
m≤‴m+k {m} {k = zero} refl = subst (λ z → m ≤‴ z) (sym (+-identityʳ m)) (≤‴-refl {m})
m≤‴m+k {m} {k = suc k} proof
= ≤‴-step (m≤‴m+k {k = k} (trans (sym (+-suc m _)) proof))
m≤‴m+k {m} {k = zero} refl = subst (λ z → m ≤‴ z) (sym (+-identityʳ m)) (≤‴-refl {m})
m≤‴m+k {m} {k = suc k} prf = ≤‴-step (m≤‴m+k {k = k} (trans (sym (+-suc m _)) prf))

≤″⇒≤‴ : ∀{m n} → m ≤″ n → m ≤‴ n
≤″⇒≤‴ (less-than-or-equal {k} proof) = m≤‴m+k proof
≤″⇒≤‴ m≤n = m≤‴m+k (≤″-proof m≤n)

0≤‴n : ∀{n} → 0 ≤‴ n
0≤‴n {n} = m≤‴m+k refl
Expand Down