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

[fixes #1711] Refactoring Data.Nat.Divisibility and Data.Nat.DivMod #2182

Merged
merged 91 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
e6c6116
added new definitions to `_∣_`
jamesmckinna Oct 25, 2023
29c3cb7
`CHANGELOG`
jamesmckinna Oct 25, 2023
c4804d1
don't declare `quotient≢0` as an `instance`
jamesmckinna Oct 25, 2023
a37b99e
replace use of `subst` with one of `trans`
jamesmckinna Oct 25, 2023
4edc8f8
what's sauce for the goose...
jamesmckinna Oct 25, 2023
6d592b3
switch to a `rewrite`-based solution...
jamesmckinna Oct 25, 2023
86a6058
tightened `import`s
jamesmckinna Oct 25, 2023
5e636a8
simplified dependenciess
jamesmckinna Oct 25, 2023
99a121c
simplified dependencies; `CHANGELOG`
jamesmckinna Oct 25, 2023
21b8ca7
removed `module` abstractions
jamesmckinna Oct 25, 2023
fdf6b66
delegated proof of `quotient≢0` to `Data.Nat.Properties`
jamesmckinna Oct 27, 2023
305d34b
removed redundant property
jamesmckinna Oct 27, 2023
c20e98b
cosmetic review changes; others to follow
jamesmckinna Oct 28, 2023
b71b014
better proof of `quotient>1`
jamesmckinna Oct 28, 2023
2405ab9
`where` clause layout
jamesmckinna Oct 28, 2023
60a111e
leaving in the flipped equality; moved everything else
jamesmckinna Oct 30, 2023
8d6cbf6
new lemmas moved from `Core`; knock-on consequences; lots of tidying up
jamesmckinna Oct 30, 2023
f1f91a9
tidying up; `CHANGELOG`
jamesmckinna Oct 30, 2023
a081792
cosmetic tweaks
jamesmckinna Oct 30, 2023
9ad6bfd
reverted to simple version
jamesmckinna Oct 31, 2023
8fad669
problems with exporting `quotient`
jamesmckinna Oct 31, 2023
3a0d881
added last lemma: defining equation for `_/_`
jamesmckinna Oct 31, 2023
f7a9cb6
improved `CHANGELOG`
jamesmckinna Oct 31, 2023
8dc3901
revert: simplified imports
jamesmckinna Nov 1, 2023
d05b959
improved `CHANGELOG`
jamesmckinna Nov 1, 2023
33ebce9
endpoint of simplifying the proof of `*-pres-∣`
jamesmckinna Nov 2, 2023
a03b552
simplified the proof of `n/m≡quotient`
jamesmckinna Nov 2, 2023
4f438cf
simplified the proof of `∣m+n∣m⇒∣n`
jamesmckinna Nov 2, 2023
2ff5f79
simplified the proof of `∣m∸n∣n⇒∣m`
jamesmckinna Nov 2, 2023
a3756c9
simplified `import`s
jamesmckinna Nov 2, 2023
efd0b20
simplified a lot of proofs, esp. wrt `divides-refl` and `NonZero` rea…
jamesmckinna Nov 2, 2023
82f37d0
simplified more proofs, esp. wrt `divides-refl` reasoning
jamesmckinna Nov 2, 2023
a9b0827
simplified `import`s
jamesmckinna Nov 2, 2023
17ac388
moved `equalityᵒ` proof out of `Core`
jamesmckinna Nov 2, 2023
72c93a8
`CHANGELOG`
jamesmckinna Nov 2, 2023
6d819ae
temporary fix: further `NonZero` refactoring advised!
jamesmckinna Nov 2, 2023
54a4444
regularised use of instance brackets
jamesmckinna Nov 6, 2023
2970fc3
further instance simplification
jamesmckinna Nov 6, 2023
3bbf57f
further streamlining
jamesmckinna Nov 6, 2023
8f2ce92
tidied up `CHANGELOG`
jamesmckinna Nov 6, 2023
4afc16d
simplified `NonZero` pattern matching
jamesmckinna Nov 6, 2023
eeee16a
regularised use of instance brackets
jamesmckinna Nov 6, 2023
7fc10e9
simplified proof of `/-*-interchange`
jamesmckinna Nov 10, 2023
b2df609
simplified proof of `/-*-interchange`
jamesmckinna Nov 10, 2023
b2c0406
... permitting the migration of `*-pres-∣` to `Data.Nat.Divisibility`
jamesmckinna Nov 10, 2023
700aacc
tweaked proof of `/-*-interchange`
jamesmckinna Nov 10, 2023
ffed96a
narrowed `import`s
jamesmckinna Nov 10, 2023
053cbc3
Merge branch 'agda:master' into issue1711
jamesmckinna Nov 16, 2023
50bb165
simplified proof; renamed new proofs
jamesmckinna Nov 16, 2023
76c5946
Capitalisation
jamesmckinna Nov 17, 2023
16a14d9
streamlined `import`s; streamlined proof of decidability
jamesmckinna Nov 24, 2023
5503e09
Merge branch 'master' into issue1711
jamesmckinna Nov 24, 2023
7c2d70c
spurious duplication after merge
jamesmckinna Nov 24, 2023
08f8f57
missing symbol import
jamesmckinna Nov 24, 2023
671cb02
replaced one use of `1 < m` with `{{NonTrivial m}}`
jamesmckinna Nov 24, 2023
f775e43
fixed `CHANGELOG`
jamesmckinna Nov 24, 2023
36771c5
removed use of identifier `k`
jamesmckinna Nov 24, 2023
44a1f1b
Merge branch 'agda:master' into issue1711
jamesmckinna Nov 27, 2023
de4ac18
refactoring: more use of `NonTrivial` instances
jamesmckinna Nov 27, 2023
449513a
knock-on consequences: simplified function
jamesmckinna Nov 27, 2023
abff148
two new lemmas
jamesmckinna Nov 27, 2023
c7c8c75
refactoring: use of `connex` in proofs
jamesmckinna Nov 27, 2023
e4bbcd3
new lemmas about `pred`
jamesmckinna Nov 27, 2023
71dc385
new lemmas about monus
jamesmckinna Nov 27, 2023
5b879bd
refactoring: use of the new properties, simplifying pattern analysis
jamesmckinna Nov 27, 2023
9504548
whitespace
jamesmckinna Nov 27, 2023
f7a966f
questionable? revision after comments on #2221
jamesmckinna Dec 4, 2023
d83f222
silly argument name typo; remove parens
jamesmckinna Dec 12, 2023
f9b3cc0
tidied up imports of `Relation.Nullary`
jamesmckinna Dec 13, 2023
117e6b4
removed spurious `instance`
jamesmckinna Dec 13, 2023
41c2856
localised appeals to `Reasoning`
jamesmckinna Dec 13, 2023
e48835f
further use of `variable`s
jamesmckinna Dec 13, 2023
a98c02b
tidied up `record` name in comment
jamesmckinna Dec 13, 2023
320aec8
cosmetic
jamesmckinna Dec 13, 2023
6f3946f
reconciled implicit/explicit arguments in various monus lemmas
jamesmckinna Dec 13, 2023
feca9d7
fixed knock-on change re monus; reverted change to `m/n<m`
jamesmckinna Dec 13, 2023
bb08e6c
reverted change to `m/n≢0⇒n≤m`
jamesmckinna Dec 13, 2023
f4e1f53
reverted breaking changes involving `NonZero` inference
jamesmckinna Dec 13, 2023
d731717
revised `CHANGELOG`
jamesmckinna Dec 13, 2023
fac8e6c
Merge branch 'master' into issue1711
jamesmckinna Dec 13, 2023
5062d3e
restored deleted proof
jamesmckinna Dec 13, 2023
ec4c543
fix whitespace
jamesmckinna Dec 13, 2023
032506d
renaming: `DivMod.nonZeroDivisor`
jamesmckinna Dec 13, 2023
850cb99
localised use of `≤-Reasoning`
jamesmckinna Dec 14, 2023
9708ca8
reverted export; removed anonymous module
jamesmckinna Dec 14, 2023
2935137
Merge branch 'master' into issue1711
jamesmckinna Dec 14, 2023
ca0bdc8
revert commit re `yes/no`
jamesmckinna Dec 14, 2023
e5006e3
renamed flipped equality
jamesmckinna Dec 14, 2023
9838568
tweaked comment
jamesmckinna Dec 14, 2023
70c43b4
added alias for `equality`
jamesmckinna Dec 14, 2023
b6f2ada
Merge branch 'master' into issue1711
jamesmckinna Dec 14, 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
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2753,9 +2753,15 @@ Additions to existing modules
<-asym : Asymmetric _<_
```

* Added a new pattern synonym to `Data.Nat.Divisibility.Core`:
* Added new definitions and a new pattern synonym to `Data.Nat.Divisibility.Core`:
```agda
pattern divides-refl q = divides q refl

quotient≡0⇒n≡0 : quotient ≡ 0 → n ≡ 0
quotient≢0 : .{{NonZero n}} → NonZero quotient
n≡m*quotient : n ≡ m * quotient
quotient>1 : (1<m : 1 < m) → (m<n : m < n) → 1 < quotient
quotient< : (1<m : 1 < m) → .{{NonZero n}} → quotient < n
```

* Added new definitions and proofs to `Data.Nat.Primality`:
Expand Down
48 changes: 44 additions & 4 deletions src/Data/Nat/Divisibility/Core.agda
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

module Data.Nat.Divisibility.Core where

open import Data.Nat.Base using (ℕ; _*_)
open import Data.Nat.Base using (ℕ; _*_; NonZero; ≢-nonZero; ≢-nonZero⁻¹; _<_)
open import Data.Nat.Properties
open import Level using (0ℓ)
open import Relation.Nullary.Negation using (¬_)
open import Relation.Nullary.Negation using (¬_; contraposition)
open import Relation.Binary.Core using (Rel)
open import Relation.Binary.PropositionalEquality
using (_≡_; refl; sym; cong₂; module ≡-Reasoning)
using (_≡_; refl; cong; cong₂; subst; module ≡-Reasoning)

------------------------------------------------------------------------
-- Definition
Expand All @@ -35,15 +35,55 @@ record _∣_ (m n : ℕ) : Set where
constructor divides
field quotient : ℕ
equality : n ≡ quotient * m
open _∣_ using (quotient) public
MatthewDaggitt marked this conversation as resolved.
Show resolved Hide resolved

quotient≡0⇒n≡0 : quotient ≡ 0 → n ≡ 0
quotient≡0⇒n≡0 q≡0 = subst (λ q → n ≡ q * m) q≡0 equality
JacquesCarette marked this conversation as resolved.
Show resolved Hide resolved

quotient≢0 : .{{NonZero n}} → NonZero quotient
jamesmckinna marked this conversation as resolved.
Show resolved Hide resolved
quotient≢0 = ≢-nonZero (contraposition quotient≡0⇒n≡0 (≢-nonZero⁻¹ n))

n≡m*quotient : n ≡ m * quotient
n≡m*quotient = begin
n ≡⟨ equality ⟩
quotient * m ≡⟨ *-comm quotient m ⟩
m * quotient ∎ where open ≡-Reasoning

module _ (1<m : 1 < m) where

open ≤-Reasoning

quotient>1 : (m<n : m < n) → 1 < quotient
jamesmckinna marked this conversation as resolved.
Show resolved Hide resolved
quotient>1 m<n = ≰⇒> λ q≤1 → n≮n n (begin-strict
n ≡⟨ equality ⟩
quotient * m ≤⟨ *-monoˡ-≤ m q≤1 ⟩
1 * m ≡⟨ *-identityˡ m ⟩
m <⟨ m<n ⟩
n ∎)

quotient< : .{{NonZero n}} → quotient < n
quotient< = begin-strict
quotient <⟨ m<m*n quotient m 1<m ⟩
quotient * m ≡⟨ equality ⟨
n ∎ where instance _ = quotient≢0

_∤_ : Rel ℕ 0ℓ
m ∤ n = ¬ (m ∣ n)

-- smart constructor

pattern divides-refl q = divides q refl

-- smart destructor

module _ {m n} (m∣n : m ∣ n) (open _∣_ m∣n) where

quotient∣ : quotient ∣ n
quotient∣ = divides m n≡m*quotient

-- exports

open _∣_ using (quotient; quotient≢0; quotient>1; quotient<) public

------------------------------------------------------------------------
-- Basic properties

Expand Down