-
Notifications
You must be signed in to change notification settings - Fork 268
[ add ] injectivity of suc for relation m ≡ n (mod o) for {{NonZero o}}
#2971
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
Changes from 9 commits
4701dc5
c9ca2f0
0ce7a21
6752397
48310db
5cd81df
7306ee7
42b955d
dae4bf3
02a916a
4fdec64
6b7f7d8
135b3d9
fd375b6
49d6c58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,9 +17,12 @@ open import Data.Nat.DivMod.Core | |
| open import Data.Nat.Divisibility.Core | ||
| open import Data.Nat.Induction | ||
| open import Data.Nat.Properties | ||
| open import Data.Product.Base using (_,_) | ||
| open import Data.Product.Base using (_,_; ∃) | ||
| open import Data.Sum.Base using (inj₁; inj₂) | ||
| open import Function.Base using (_$_; _∘_) | ||
| open import Function.Base using (id; _$_; _∘_; _on_) | ||
| open import Relation.Binary.Core using (Rel; _⇒_) | ||
| open import Relation.Binary.Construct.Closure.Symmetric | ||
| as SymClosure using (SymClosure; fwd; bwd) | ||
| open import Relation.Binary.PropositionalEquality.Core | ||
| using (_≡_; cong; cong₂; refl; trans; _≢_; sym) | ||
| open import Relation.Nullary.Negation using (contradiction) | ||
|
|
@@ -463,6 +466,86 @@ m%n*o≡m*o%[n*o] m n o = begin-equality | |
| p-1 * n + n ≡⟨ +-comm (p-1 * n) n ⟩ | ||
| pn ∎ | ||
|
|
||
| -- Lemmas characterising the relation `m ≡ n (mod o)` | ||
|
|
||
| -- Definition of an alternative, *asymmetric* version of that notion | ||
| -- whose `Relation.Binary.Construct.Closure.Symmetric` gives us an | ||
| -- equivalent of the above relation. | ||
|
|
||
| infix 4 _≲%[_]_ _≅%[_]_ | ||
| _≲%[_]_ _≅%[_]_ : ∀ m o n → Set _ | ||
|
|
||
| m ≲%[ o ] n = ∃ λ k → n ≡ m + k * o | ||
| m ≅%[ o ] n = SymClosure _≲%[ o ]_ m n | ||
|
|
||
| infix 4 _≡%[_]_ | ||
| _≡%[_]_ : ∀ m o .{{_ : NonZero o}} n → Set _ | ||
| m ≡%[ o ] n = m % o ≡ n % o | ||
|
|
||
| -- Equivalence between _≅%[_]_ and _≡[_]%_ | ||
|
|
||
| module _ .{{_ : NonZero o}} where | ||
|
|
||
| ≲%[o]⇒≡[o]% : _≲%[ o ]_ ⇒ _≡%[ o ]_ | ||
| ≲%[o]⇒≡[o]% {x = m} {y = n} (k , eq) = begin-equality | ||
| m % o ≡⟨ [m+kn]%n≡m%n m k o ⟨ | ||
| (m + k * o) % o ≡⟨ cong (_% o) eq ⟨ | ||
| n % o ∎ | ||
|
|
||
| ≅%[o]⇒≡[o]% : _≅%[ o ]_ ⇒ _≡%[ o ]_ | ||
| ≅%[o]⇒≡[o]% = SymClosure.fold sym ≲%[o]⇒≡[o]% | ||
|
|
||
| ≡[o]%⇒≲%[o] : m % o ≡ n % o → m ≤ n → m ≲%[ o ] n | ||
| ≡[o]%⇒≲%[o] {m = m} {n = n} eq m≤n = k , (begin-equality | ||
| n ≡⟨ m≡m%n+[m/n]*n n o ⟩ | ||
| n % o + n / o * o ≡⟨ cong (_+ n / o * o) eq ⟨ | ||
| m % o + n / o * o ≡⟨ cong ((m % o +_) ∘ (_* o)) (m+[n∸m]≡n (/-monoˡ-≤ o m≤n)) ⟨ | ||
| m % o + (m / o + k) * o ≡⟨ cong (m % o +_) (*-distribʳ-+ o (m / o) k) ⟩ | ||
| m % o + (m / o * o + k * o) ≡⟨ +-assoc (m % o) _ _ ⟨ | ||
| (m % o + m / o * o) + k * o ≡⟨ cong (_+ k * o) (m≡m%n+[m/n]*n m o) ⟨ | ||
| m + k * o ∎) | ||
| where k = n / o ∸ m / o | ||
|
|
||
| ≡[o]%⇒≅%[o] : _≡%[ o ]_ ⇒ _≅%[ o ]_ | ||
| ≡[o]%⇒≅%[o] {x = m} {y = n} eq with ≤-total m n | ||
|
jamesmckinna marked this conversation as resolved.
Outdated
|
||
| ... | inj₁ m≤n = fwd (≡[o]%⇒≲%[o] eq m≤n) | ||
| ... | inj₂ n≤m = bwd (≡[o]%⇒≲%[o] (sym eq) n≤m) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This proof could be refactored in terms of
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Notwithstanding that
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And now, in terms of |
||
|
|
||
|
|
||
| private | ||
|
|
||
| -- Example application, originally proposed by Jacques Carette, taken from | ||
| -- https://agda.zulipchat.com/#narrow/channel/264623-stdlib/topic/suc.20injective.20under.20_.25_/with/582024092 | ||
|
|
||
| CarettesLemma : ∀ o .{{_ : NonZero o}} → Set _ | ||
|
jamesmckinna marked this conversation as resolved.
Outdated
|
||
| CarettesLemma o = (_≡%[ o ]_ on suc) ⇒ _≡%[ o ]_ | ||
|
|
||
| carettesLemma : .{{_ : NonZero o}} → CarettesLemma o | ||
| carettesLemma {o = o} = ≅%[o]⇒≡[o]% ∘ lemma-≅% ∘ ≡[o]%⇒≅%[o] | ||
| where | ||
| lemma-≲% : (_≲%[ o ]_ on suc) ⇒ _≲%[ o ]_ | ||
| lemma-≲% (k , eq) = k , cong pred eq | ||
|
|
||
| lemma-≅% : (_≅%[ o ]_ on suc) ⇒ _≅%[ o ]_ | ||
| lemma-≅% = SymClosure.hmap suc id lemma-≲% | ||
|
|
||
| -- Alex Rice's optimised proof | ||
| carettesLemma′ : .{{_ : NonZero o}} → CarettesLemma o | ||
| carettesLemma′ {o = o@(suc d)} {x = m} {y = n} eq = begin-equality | ||
|
jamesmckinna marked this conversation as resolved.
Outdated
|
||
| m % o ≡⟨ lemma m ⟩ | ||
| (suc m % o + d % o) % o ≡⟨ cong (λ a → (a + d % o) % o) eq ⟩ | ||
| (suc n % o + d % o) % o ≡⟨ lemma n ⟨ | ||
| n % o ∎ | ||
| where | ||
| lemma : ∀ n → n % o ≡ (suc n % o + d % o) % o | ||
| lemma n = begin-equality | ||
| n % o ≡⟨ [m+n]%n≡m%n n o ⟨ | ||
| (n + o) % o ≡⟨⟩ | ||
| (n + suc d) % o ≡⟨ %-congˡ (+-suc n d) ⟩ | ||
| (suc n + d) % o ≡⟨ %-distribˡ-+ (suc n) d o ⟩ | ||
| (suc n % o + d % o) % o ∎ | ||
|
|
||
|
|
||
| ------------------------------------------------------------------------ | ||
| -- A specification of integer division. | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.