-
Notifications
You must be signed in to change notification settings - Fork 257
Added Z mod n as Fin #2073
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
Added Z mod n as Fin #2073
Changes from 1 commit
19566db
94d8aa9
c87e35a
af96faa
7e6a392
467b190
600035c
5cdbaf7
e64b543
d3d4770
1d28e8e
3773f2c
e853059
fccf44d
e7edaee
ab5493d
7ccd05e
644a8cb
417fa28
4d3a4ab
84cc27b
473ac6d
b539e70
aeb1c4a
bdf0651
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 | ||
---|---|---|---|---|
@@ -0,0 +1,107 @@ | ||||
------------------------------------------------------------------------ | ||||
-- The Agda standard library | ||||
-- | ||||
-- ℤ module n | ||||
------------------------------------------------------------------------ | ||||
|
||||
{-# OPTIONS --cubical-compatible --safe #-} | ||||
|
||||
module Data.Fin.Mod where | ||||
|
||||
open import Function using (_$_; _∘_) | ||||
open import Data.Bool using (true; false) | ||||
open import Data.Nat as ℕ using (ℕ; s≤s) | ||||
guilhermehas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
open import Data.Nat.Properties as ℕ | ||||
using (m≤n⇒m≤1+n; 1+n≰n; module ≤-Reasoning) | ||||
open import Data.Fin as F hiding (suc; pred; _+_; _-_) | ||||
guilhermehas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
open import Data.Fin.Properties | ||||
open import Relation.Nullary using (Dec; yes; no; contradiction) | ||||
guilhermehas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
open import Relation.Binary.PropositionalEquality | ||||
using (_≡_; _≢_; refl; sym; trans; cong; module ≡-Reasoning) | ||||
import Algebra.Definitions as ADef | ||||
|
||||
private variable | ||||
m n : ℕ | ||||
guilhermehas marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
|
||||
open module AD {n} = ADef {A = Fin n} _≡_ | ||||
|
||||
|
||||
private | ||||
hs : ∀ {i : Fin (ℕ.suc n)} → i ≢ fromℕ n → Fin (ℕ.suc n) | ||||
hs {i = i} i≢n = lower₁ (F.suc i) help | ||||
where | ||||
help : _ | ||||
help = i≢n ∘ sym ∘ toℕ-injective ∘ trans (toℕ-fromℕ _) ∘ cong ℕ.pred | ||||
|
||||
suc : Fin n → Fin n | ||||
suc {ℕ.suc n} i with i ≟ fromℕ n | ||||
... | yes _ = zero | ||||
... | no i≢n = hs i≢n | ||||
|
||||
|
||||
pred : Fin n → Fin n | ||||
pred zero = fromℕ _ | ||||
pred (F.suc i) = inject₁ i | ||||
|
||||
_ℕ+_ : ℕ → Fin n → Fin n | ||||
guilhermehas marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
ℕ.zero ℕ+ i = i | ||||
ℕ.suc n ℕ+ i = suc (n ℕ+ i) | ||||
|
||||
_+_ : Fin m → Fin n → Fin n | ||||
|
||||
i + j = toℕ i ℕ+ j | ||||
|
||||
_+‵_ : Fin n → Fin n → Fin n | ||||
|
_∘′_ : (B → C) → (A → B) → (A → C) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This suggests that opposite
is an inverse function for _+_
(which I agree it should be). Can you prove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, for a possible alternative (re-)definition of opposite
, see also #1923
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now, it is with the alternative re-definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Except that there's still an asymmetry. _+_
has heterogeneous sizes but _-_
is homogeneous?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made it assymmetric.
guilhermehas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
guilhermehas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
guilhermehas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be suc-pred
guilhermehas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proof of this seems very fiddly, but I admit I'm finding it harder to do better, even for the alternative definition of suc
. Hmmm...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this lemma not also provable in the case n = ℕ.zero
? By inversion of the hypothesis m ℕ.≤ n
, we would obtain m = ℕ.zero
, and then the proof is simply refl
... or am I missing something?
UPDATED: it seems I might be, after banging my head against your proof for a while...
Uh oh!
There was an error while loading. Please reload this page.