-
Notifications
You must be signed in to change notification settings - Fork 251
Modular arithmetic in terms of ideals #2729
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
base: master
Are you sure you want to change the base?
Conversation
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 new Kernel file looks nice.
Would you want some help to get this further along? |
Yes, actually. I've been working on a module for the special case of ideals of the ring of integers, and I've been struggling to prove that (for a non-zero modulus) it's finite, which I think it important for the "yes this is modular arithmetic as you know it" feel. I'll post a WIP commit shortly |
Ok, once my students make further progress on the ones they are currently working on, I'll get them to look at this. |
Some errors thrown up by checking with
|
@jamesmckinna I've merged in master, are those two errors fixed now? |
ι : RawGroup.Carrier N → Carrier | ||
ι-monomorphism : IsGroupMonomorphism N rawGroup ι | ||
-- every element of N commutes in G | ||
normal : ∀ n g → ∃[ n′ ] g ∙ ι n ∙ g ⁻¹ ≈ ι n′ |
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.
So... I was a bit surprised that this was an 'easier' formulation than
normal : ∀ n g → ∃[ n′ ] g ∙ ι n ∙ g ⁻¹ ≈ ι n′ | |
normal : ∀ n g → ∃[ n′ ] g ∙ ι n ≈ ι n′ ∙ g |
which I wondered as to whether
- it would be easier/smoother to show gives rise to an equivalence relation on the quotient?
- it would generalise (better) to
Loop
,Quasigroup
or evenMagma
/Semigroup
? - for commutative operation, every subgroup is automatically
normal
...
Cf. comments elsewhere from @JacquesCarette about defining 'ideal' via 'sink'...
x * r * a ≈⟨ *-assoc x r a ⟩ | ||
x * (r * a) ≈⟨ *-congˡ (*-comm r a) ⟩ | ||
x * (a * r) ≈⟨ *-assoc x a r ⟨ | ||
x * a * r ∎ |
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 kind of argument occurs in Algebra.Properties.CommutativeSemigroup
, and might usefully be re-used here?
x * a * r ∎ | ||
} | ||
} | ||
; injective = λ p → p |
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.
; injective = λ p → p | |
; injective = id |
???
infix 0 _by_ | ||
|
||
data _≋_ (x y : Carrier) : Set (c ⊔ ℓ ⊔ c′) where | ||
_by_ : ∀ g → x // y ≈ ι g → x ≋ y |
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.
Similarly to the type of NormalSubgroup.normal
, is it 'easier' to write
_by_ : ∀ g → x // y ≈ ι g → x ≋ y | |
_by_ : ∀ g → x ≈ ι g ∙ y → x ≋ y |
???
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.
Yielding:
≋-refl : Reflexive _≋_
≋-refl {x} = N.ε by begin
x ≈⟨ identityˡ _ ⟨
ε ∙ x ≈⟨ ∙-congʳ (ι.ε-homo) ⟨
ι N.ε ∙ x ∎
≋-sym : Symmetric _≋_
≋-sym {x} {y} (g by x≈ιg∙y) = g N.⁻¹ by begin
y ≈⟨ y≈x\\z _ _ _ (sym x≈ιg∙y) ⟩
ι g ⁻¹ ∙ x ≈⟨ ∙-congʳ (ι.⁻¹-homo g) ⟨
ι (g N.⁻¹) ∙ x ∎
≋-trans : Transitive _≋_
≋-trans {x} {y} {z} (g by x≈ιg∙y) (h by y≈ιh∙z) = g N.∙ h by begin
x ≈⟨ x≈ιg∙y ⟩
ι g ∙ y ≈⟨ ∙-congˡ y≈ιh∙z ⟩
ι g ∙ (ι h ∙ z) ≈⟨ assoc _ _ _ ⟨
ι g ∙ ι h ∙ z ≈⟨ ∙-congʳ (ι.∙-homo g h) ⟨
ι (g N.∙ h) ∙ z ∎
and thus being admissible in any Quasigroup
Monoid
(an associative Loop
is a group)? (Well, refl
and trans
at least...)
Indeed, these are properties (modulo ι
) of the abstract Divisibility
relations on Magma
and their properties... as structure is successively enriched to Semigroup
(for trans
) and Monoid
(for refl
)! So we should add Group
divisibility to inherit those, with sym
becoming provable...?
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.
It's a shame that the iota means I can't reuse the divisibility machinery...
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.
Yes, and I'm not sure we're quite ready to embrace the least common generalisation of the two... but one day perhaps!?
x // z ≈⟨ ∙-congʳ (identityʳ x) ⟨ | ||
x ∙ ε // z ≈⟨ ∙-congʳ (∙-congˡ (inverseˡ y)) ⟨ | ||
x ∙ (y \\ y) // z ≈⟨ ∙-congʳ (assoc x (y ⁻¹) y) ⟨ | ||
(x // y) ∙ y // z ≈⟨ assoc (x // y) y (z ⁻¹) ⟩ | ||
(x // y) ∙ (y // z) ≈⟨ ∙-cong x//y≈ιg y//z≈ιh ⟩ |
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.
Already covered (in part) by Algebra.Properties.Monoid
...? And if not, could/should be added?
Or: see above!
module _ .{{_ : NonZero m}} where | ||
|
||
from-% : ∀ {x y} → x % m ≡ y % m → x ≋ y | ||
from-% {x} {y} x%m≡y%m = x / m - y / m by begin |
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.
How much of this argument recapitulates concretely reasoning steps already used abstractly in CRT?
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.
Or better (?): on my revised account of equality in the quotient:
module ℤ/mℤ = Ring quotientRing
-- todo:
-- * chinese remainder theorem specialized to integers
-- * finiteness: for non-zero
module _ .{{_ : NonZero m}} where
module _ z where
private
z%m = + (z % m)
z/m = z / m
z≋z%m : z ≋ z%m
z≋z%m = z/m by begin
z ≡⟨ a≡a%n+[a/n]*n z m ⟩
z%m + z/m * m ≡⟨ +-comm z%m (z/m * m) ⟩
z/m * m + z%m ∎
where open ≡-Reasoning
from-% : ∀ {x y} → x % m ≡ y % m → x ≋ y
from-% {x} {y} x%m≡y%m = begin
x ≈⟨ z≋z%m x ⟩
+ (x % m) ≈⟨ ℤ/mℤ.reflexive (≡.cong +_ x%m≡y%m) ⟩
+ (y % m) ≈⟨ z≋z%m y ⟨
y ∎
where open ≈-Reasoning ℤ/mℤ.setoid
This kind of argument can doubtless be generalised: z ≋ π z
in the quotient, for any such, while π z ≡ z % m
for the particular case ℤ/mℤ
?
≈⇒≋ {x} {y} x≈y = N.ε by begin | ||
x // y ≈⟨ x≈y⇒x∙y⁻¹≈ε x≈y ⟩ | ||
ε ≈⟨ ι.ε-homo ⟨ | ||
ι N.ε ∎ |
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.
Similarly
≈⇒≋ {x} {y} x≈y = N.ε by begin
x ≈⟨ x≈y ⟩
y ≈⟨ identityˡ _ ⟨
ε ∙ y ≈⟨ ∙-congʳ (ι.ε-homo) ⟨
ι N.ε ∙ y ∎
Have suggested some possible refactorings to make the constructions/lemmas more reusable, and to be able to reuse |
So for the 'ALT' version of open import Algebra.Bundles using (Group; RawGroup)
module Algebra.NormalSubgroupALT {c ℓ} (G : Group c ℓ) where
open import Algebra.Structures using (IsGroup)
open import Algebra.Morphism.Structures
import Algebra.Morphism.GroupMonomorphism as GM
open import Data.Product.Base
open import Level using (suc; _⊔_)
private
module G = Group G
open G using (_≈_; _∙_)
record NormalSubgroup c′ ℓ′ : Set (c ⊔ ℓ ⊔ suc (c′ ⊔ ℓ′)) where
-- firstly: N is a subgroup of G
field
N : RawGroup c′ ℓ′
module N = RawGroup N
field
ι : N.Carrier → G.Carrier
ι-monomorphism : IsGroupMonomorphism N G.rawGroup ι
module ι = IsGroupMonomorphism ι-monomorphism
isGroup : IsGroup N._≈_ N._∙_ N.ε N._⁻¹
isGroup = GM.isGroup ι-monomorphism G.isGroup
group : Group _ _
group = record { isGroup = isGroup }
-- secondly: every element of N commutes in G
field
normal : ∀ n g → ∃[ n′ ] g ∙ ι n ≈ ι n′ ∙ g |
... and for open import Algebra.Bundles using (Group; RawGroup)
open import Algebra.NormalSubgroupALT using (NormalSubgroup)
module Algebra.Construct.Quotient.GroupALT
{c ℓ} (G : Group c ℓ) {c′ ℓ′} (N : NormalSubgroup G c′ ℓ′) where
open import Algebra.Morphism.Structures
open import Algebra.Structures using (IsGroup)
open import Data.Product.Base
open import Level using (_⊔_)
open import Relation.Binary.Core using (_⇒_)
open import Relation.Binary.Definitions using (Reflexive; Symmetric; Transitive)
open import Relation.Binary.Structures using (IsEquivalence)
import Algebra.Definitions as AlgDefs
import Relation.Binary.Reasoning.Setoid as ≈-Reasoning
open import Algebra.Properties.Group G
private
module G = Group G
open G using (_≈_; _∙_; ε; _⁻¹)
open import Algebra.Properties.Monoid G.monoid
module N = NormalSubgroup N
open N using (ι; normal; module N)
open ≈-Reasoning G.setoid
infix 0 _by_
data _≋_ (x y : G.Carrier) : Set (c ⊔ ℓ ⊔ c′) where
_by_ : ∀ n → x ≈ ι n ∙ y → x ≋ y
quotientRawGroup : RawGroup _ _
quotientRawGroup = record { _≈_ = _≋_ ; _∙_ = _∙_ ; ε = ε ; _⁻¹ = _⁻¹ }
≈⇒≋ : _≈_ ⇒ _≋_
≈⇒≋ {x} {y} x≈y = N.ε by begin
x ≈⟨ x≈y ⟩
y ≈⟨ G.identityˡ _ ⟨
ε ∙ y ≈⟨ G.∙-congʳ (ι.ε-homo) ⟨
ι N.ε ∙ y ∎
≋-refl : Reflexive _≋_
≋-refl {x} = ≈⇒≋ G.refl
≋-sym : Symmetric _≋_
≋-sym {x} {y} (g by x≈ιg∙y) = g N.⁻¹ by begin
y ≈⟨ y≈x\\z _ _ _ (G.sym x≈ιg∙y) ⟩
ι g ⁻¹ ∙ x ≈⟨ G.∙-congʳ (ι.⁻¹-homo g) ⟨
ι (g N.⁻¹) ∙ x ∎
≋-trans : Transitive _≋_
≋-trans {x} {y} {z} (g by x≈ιg∙y) (h by y≈ιh∙z) = g N.∙ h by begin
x ≈⟨ x≈ιg∙y ⟩
ι g ∙ y ≈⟨ G.∙-congˡ y≈ιh∙z ⟩
ι g ∙ (ι h ∙ z) ≈⟨ G.assoc _ _ _ ⟨
ι g ∙ ι h ∙ z ≈⟨ G.∙-congʳ (ι.∙-homo g h) ⟨
ι (g N.∙ h) ∙ z ∎
≋-isEquivalence : IsEquivalence _≋_
≋-isEquivalence = record
{ refl = ≋-refl
; sym = ≋-sym
; trans = ≋-trans
}
open AlgDefs _≋_
≋-∙-cong : Congruent₂ _∙_
≋-∙-cong {x} {y} {u} {v} (g by x≈ιg∙y) (h by u≈ιh∙v) =
let k , y∙ιh≈ιk∙y = normal h y in g N.∙ k by begin
x ∙ u ≈⟨ G.∙-cong x≈ιg∙y u≈ιh∙v ⟩
(ι g ∙ y) ∙ (ι h ∙ v) ≈⟨ uv≈w⇒xu∙vy≈x∙wy y∙ιh≈ιk∙y _ _ ⟩
ι g ∙ ((ι k ∙ y) ∙ v) ≈⟨ G.assoc _ _ _ ⟨
ι g ∙ (ι k ∙ y) ∙ v ≈⟨ G.∙-congʳ (G.assoc _ _ _) ⟨
ι g ∙ ι k ∙ y ∙ v ≈⟨ G.assoc _ _ _ ⟩
(ι g ∙ ι k) ∙ (y ∙ v) ≈⟨ G.∙-congʳ (ι.∙-homo g k) ⟨
ι (g N.∙ k) ∙ (y ∙ v) ∎
≋-⁻¹-cong : Congruent₁ _⁻¹
≋-⁻¹-cong {x} {y} (g by x≈ιg∙y) =
let h , y⁻¹∙ιg⁻¹≈ιh∙y⁻¹ = normal (g N.⁻¹) (y ⁻¹)
in h by begin
x ⁻¹ ≈⟨ G.⁻¹-cong x≈ιg∙y ⟩
(ι g ∙ y) ⁻¹ ≈⟨ ⁻¹-anti-homo-∙ _ _ ⟩
y ⁻¹ ∙ ι g ⁻¹ ≈⟨ G.∙-congˡ (ι.⁻¹-homo _) ⟨
y ⁻¹ ∙ ι (g N.⁻¹) ≈⟨ y⁻¹∙ιg⁻¹≈ιh∙y⁻¹ ⟩
ι h ∙ y ⁻¹ ∎
quotientIsGroup : IsGroup _≋_ _∙_ ε _⁻¹
quotientIsGroup = record
{ isMonoid = record
{ isSemigroup = record
{ isMagma = record
{ isEquivalence = ≋-isEquivalence
; ∙-cong = ≋-∙-cong
}
; assoc = λ x y z → ≈⇒≋ (G.assoc x y z)
}
; identity = record
{ fst = λ x → ≈⇒≋ (G.identityˡ x)
; snd = λ x → ≈⇒≋ (G.identityʳ x)
}
}
; inverse = record
{ fst = λ x → ≈⇒≋ (G.inverseˡ x)
; snd = λ x → ≈⇒≋ (G.inverseʳ x)
}
; ⁻¹-cong = ≋-⁻¹-cong
}
quotientGroup : Group c (c ⊔ ℓ ⊔ c′)
quotientGroup = record { isGroup = quotientIsGroup }
module _/_ = Group quotientGroup
η : G.Carrier → _/_.Carrier
η x = x -- because we do all the work in the relation
η-isHomomorphism : IsGroupHomomorphism G.rawGroup quotientRawGroup η
η-isHomomorphism = record
{ isMonoidHomomorphism = record
{ isMagmaHomomorphism = record
{ isRelHomomorphism = record
{ cong = ≈⇒≋
}
; homo = λ _ _ → ≋-refl
}
; ε-homo = ≋-refl
}
; ⁻¹-homo = λ _ → ≋-refl
} In each case, feel free to adapt as you see fit. (I'm almost tempted to inline Also: |
N-isGroup : IsGroup N._≈_ N._∙_ N.ε N._⁻¹ | ||
N-isGroup = GM.isGroup ι-monomorphism isGroup |
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 there also be a Group
defined?
N-isGroup : IsGroup N._≈_ N._∙_ N.ε N._⁻¹ | |
N-isGroup = GM.isGroup ι-monomorphism isGroup | |
N-isGroup : IsGroup N._≈_ N._∙_ N.ε N._⁻¹ | |
N-isGroup = GM.isGroup ι-monomorphism isGroup | |
N-group : Group _ _ | |
N-group = record { isGroup = N-isgroup } |
plus: what should be exported public
ly from this module?
And for ≋-*-cong : Congruent₂ _*_
≋-*-cong {x} {y} {u} {v} (j by x≈ιj+y) (k by u≈ιk+v) = j I.*ᵣ u I.+ᴹ y I.*ₗ k by begin
x * u ≈⟨ *-congʳ x≈ιj+y ⟩
(ι j + y) * u ≈⟨ distribʳ _ _ _ ⟩
ι j * u + y * u ≈⟨ +-congˡ (*-congˡ u≈ιk+v) ⟩
ι j * u + y * (ι k + v) ≈⟨ +-congˡ (distribˡ _ _ _) ⟩
ι j * u + (y * ι k + y * v) ≈⟨ +-assoc _ _ _ ⟨
(ι j * u + y * ι k) + y * v ≈⟨ +-congʳ (+-cong (ι.*ᵣ-homo u j) (ι.*ₗ-homo y k)) ⟨
ι (j I.*ᵣ u) + ι (y I.*ₗ k) + y * v ≈⟨ +-congʳ (ι.+ᴹ-homo (j I.*ᵣ u) (y I.*ₗ k)) ⟨
ι (j I.*ᵣ u I.+ᴹ y I.*ₗ k) + y * v ∎ |
Suggested refactoring for
|
(x / m - y / m) * m ∎ | ||
where open ≡-Reasoning | ||
|
||
to-% : ∀ {x y} → x ≋ y → x % m ≡ y % m |
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.
On whatever account of _≋_
and π
as the quotient map from R
to R / I
, this is the composition of π-cong
(which ought generally to be provable, plus π z ≡ z % m
? or is there more to this?
; 0# = 0# | ||
; 1# = 1# | ||
} | ||
|
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 insert here that the quotient map on the underlying additive subgroup of the module in fact extends to a ring homomorphism from R
to R / I
...
... which given that the underlying map is id
is pretty easy by hand.
Opening this PR to share my WIP. I've got a messy proof of the Chinese remainder theorem for arbitrary rings, but in porting it from my standalone library to this I've somehow made some parameters not infer properly