Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: 11 additions & 17 deletions Cubical/Algebra/Group/Instances/IntMod.agda
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,7 @@ snd Bool≅ℤGroup/2 =
→ Path (Fin (suc n)) (-ₘ (1 mod (suc n) , <→<ᵗ (mod< n 1)))
(n mod (suc n) , <→<ᵗ (mod< n n))
-ₘ1-id zero = refl
-ₘ1-id (suc n) =
cong -ₘ_ (FinPathℕ {suc (suc n)} ((1 mod suc (suc n)) , <→<ᵗ (mod< (suc n) 1)) 1
(modIndBase (suc n) 1 (n , +-comm n 2)) .snd)
∙ Σ≡Prop (λ z → isProp<ᵗ {n = z} {m = suc (suc n)})
((+inductionBase (suc n) _
(λ x _ → ((suc (suc n)) ∸ x) mod (suc (suc n))) λ _ x → x) 1
(n , (+-comm n 2)))
-ₘ1-id (suc n) = refl

suc-ₘ1 : (n y : ℕ)
→ ((suc y mod suc n) , <→<ᵗ (mod< n (suc y))) -ₘ (1 mod (suc n) , <→<ᵗ (mod< n 1))
Expand Down Expand Up @@ -143,9 +137,9 @@ suc-ₘ1 (suc n) y =
sym (GroupTheory.invInv (ℤGroup/ (suc n)) _)
∙ cong -ₘ_
(GroupTheory.invDistr (ℤGroup/ (suc n))
(modInd n 1 , <→<ᵗ (mod< n 1)) (-ₘ (modInd n (suc y) , <→<ᵗ (mod< n (suc y))))
∙ cong (_-ₘ (modInd n 1 , <→<ᵗ (mod< n 1)))
(GroupTheory.invInv (ℤGroup/ (suc n)) (modInd n (suc y) , <→<ᵗ (mod< n (suc y))))
(1 mod suc n , <→<ᵗ (mod< n 1)) (-ₘ (suc y mod suc n , <→<ᵗ (mod< n (suc y))))
∙ cong (_-ₘ (1 mod suc n , <→<ᵗ (mod< n 1)))
(GroupTheory.invInv (ℤGroup/ (suc n)) (suc y mod suc n , <→<ᵗ (mod< n (suc y))))
∙ suc-ₘ1 n y)

isHomℤ→Fin : (n : ℕ) → IsGroupHom (snd ℤGroup) (ℤ→Fin n) (snd (ℤGroup/ (suc n)))
Expand All @@ -161,8 +155,8 @@ isHomℤ→Fin n =
∙∙ ℤ→Fin-presinv n (pos (suc x) +ℤ (pos (suc y)))
∙∙ cong -ₘ_ (pos+case (suc x) (pos (suc y)))
∙∙ GroupTheory.invDistr (ℤGroup/ (suc n))
(modInd n (suc x)
, <→<ᵗ (mod< n (suc x))) (modInd n (suc y) , <→<ᵗ (mod< n (suc y)))
(suc x mod suc n
, <→<ᵗ (mod< n (suc x))) (suc y mod suc n , <→<ᵗ (mod< n (suc y)))
∙∙ +ₘ-comm (ℤ→Fin n (negsuc y)) (ℤ→Fin n (negsuc x))}
where
+1case : (y : ℤ) → ℤ→Fin n (1 +ℤ y) ≡ ℤ→Fin n 1 +ₘ ℤ→Fin n y
Expand All @@ -172,7 +166,7 @@ isHomℤ→Fin n =
∙ Σ≡Prop (λ z → isProp<ᵗ {n = z} {suc n}) (mod+mod≡mod (suc n) 1 (suc y))
+1case (negsuc zero) =
Σ≡Prop (λ z → isProp<ᵗ {n = z} {suc n}) refl
∙ sym (GroupStr.·InvR (snd (ℤGroup/ (suc n))) (modInd n 1 , <→<ᵗ (mod< n 1)))
∙ sym (GroupStr.·InvR (snd (ℤGroup/ (suc n))) (1 mod suc n , <→<ᵗ (mod< n 1)))
+1case (negsuc (suc y)) =
Σ≡Prop (λ z → isProp<ᵗ {n = z} {suc n})
(cong fst (cong (ℤ→Fin n) (+Comm 1 (negsuc (suc y))))
Expand All @@ -191,13 +185,13 @@ isHomℤ→Fin n =
cong (ℤ→Fin n) (cong (_+ℤ y) (+Comm (pos (suc x)) 1)
∙ sym (+Assoc 1 (pos (suc x)) y))
∙∙ +1case (pos (suc x) +ℤ y)
∙∙ (cong ((modInd n 1 , <→<ᵗ (mod< n 1)) +ₘ_) (pos+case (suc x) y)
∙∙ sym (+ₘ-assoc (modInd n 1 , <→<ᵗ (mod< n 1))
(modInd n (suc x) , <→<ᵗ (mod< n (suc x))) (ℤ→Fin n y))
∙∙ (cong ((1 mod suc n , <→<ᵗ (mod< n 1)) +ₘ_) (pos+case (suc x) y)
∙∙ sym (+ₘ-assoc (1 mod suc n , <→<ᵗ (mod< n 1))
(suc x mod suc n , <→<ᵗ (mod< n (suc x))) (ℤ→Fin n y))
∙∙ cong (_+ₘ ℤ→Fin n y) (lem x))
where
lem : (x : ℕ)
→ (modInd n 1 , <→<ᵗ (mod< n 1)) +ₘ (modInd n (suc x) , <→<ᵗ (mod< n (suc x)))
→ (1 mod suc n , <→<ᵗ (mod< n 1)) +ₘ (suc x mod suc n , <→<ᵗ (mod< n (suc x)))
≡ ℤ→Fin n (pos (suc (suc x)))
lem x =
Σ≡Prop (λ z → isProp<ᵗ {n = z} {suc n}) (sym (mod+mod≡mod (suc n) 1 (suc x)))
Expand Down
2 changes: 1 addition & 1 deletion Cubical/Algebra/Group/ZAction.agda
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ module _ (f : GroupHom ℤGroup ℤGroup) where
∙∙ cong -_ (cong pos (≡remainder+quotient (suc n) (suc x))))) ∣₁})
BijectionIso.surj (ℤHom→ℤ/im≅ℤ/im1 n p) x =
∣ [ pos (fst x) ]
, (Σ≡Prop (λ _ → isProp<ᵗ) (modIndBase n (fst x) (<ᵗ→< (snd x)))) ∣₁
, (Σ≡Prop (λ _ → isProp<ᵗ) (<→mod≡id (fst x) (suc n) (<ᵗ→< (snd x)))) ∣₁

-- main result
ℤ/imIso : (f : GroupHom ℤGroup ℤGroup)
Expand Down
44 changes: 17 additions & 27 deletions Cubical/Data/Fin/Arithmetic.agda
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,8 @@ snd (_+ₘ_ {n = n} x y) = <→<ᵗ
(mod< n ((fst x) + (fst y)))

-ₘ_ : {n : ℕ} → (x : Fin (suc n)) → Fin (suc n)
fst (-ₘ_ {n = n} x) =
(+induction n _ (λ x _ → ((suc n) ∸ x) mod (suc n)) λ _ x → x) (fst x)
snd (-ₘ_ {n = n} x) = <→<ᵗ (lem (fst x))
where
≡<-trans : {x y z : ℕ} → x < y → x ≡ z → z < y
≡<-trans (k , p) q = k , cong (λ x → k + suc x) (sym q) ∙ p

lem : {n : ℕ} (x : ℕ)
→ (+induction n _ _ _) x < suc n
lem {n = n} =
+induction n _
(λ x p → ≡<-trans (mod< n (suc n ∸ x))
(sym (+inductionBase n _ _ _ x p)))
λ x p → ≡<-trans p
(sym (+inductionStep n _ _ _ x))
fst (-ₘ_ {n = n} x) = (suc n ∸ fst x) mod suc n
snd (-ₘ_ {n = n} x) = <→<ᵗ (mod< n (suc n ∸ fst x))

_-ₘ_ : {n : ℕ} → (x y : Fin (suc n)) → Fin (suc n)
_-ₘ_ x y = x +ₘ (-ₘ y)
Expand Down Expand Up @@ -63,31 +50,34 @@ snd (_·ₘ_ {n = n} x y) = <→<ᵗ (mod< n (fst x · fst y))
+ₘ-lUnit : {n : ℕ} (x : Fin (suc n)) → 0 +ₘ x ≡ x
+ₘ-lUnit {n = n} (x , p) =
Σ≡Prop (λ z → isProp<ᵗ {n = z} {suc n})
(+inductionBase n _ _ _ x (<ᵗ→< p))
(<→mod≡id x (suc n) (<ᵗ→< p))

+ₘ-rUnit : {n : ℕ} (x : Fin (suc n)) → x +ₘ 0 ≡ x
+ₘ-rUnit x = +ₘ-comm x 0 ∙ (+ₘ-lUnit x)

+ₘ-rCancel : {n : ℕ} (x : Fin (suc n)) → x -ₘ x ≡ 0
+ₘ-rCancel {n = n} x =
Σ≡Prop (λ z → isProp<ᵗ {n = z} {suc n})
(cong (λ z → (fst x + z) mod (suc n))
(+inductionBase n _ _ _ (fst x) (<ᵗ→< (snd x)))
∙∙ sym (mod-rCancel (suc n) (fst x) ((suc n) ∸ (fst x)))
∙∙ cong (_mod (suc n)) (+-comm (fst x) ((suc n) ∸ (fst x)))
∙∙ cong (_mod (suc n))
(≤-∸-+-cancel {m = fst x} {n = suc n}
(<-weaken (<ᵗ→< (snd x))))
∙∙ zero-charac (suc n))
+ₘ-rCancel {n = n} (k , p) =
Σ≡Prop (λ z → isProp<ᵗ {n = z} {suc n}) (
(k + (suc n ∸ k) mod suc n) mod suc n ≡⟨ sym (mod-rCancel (suc n) k _) ⟩
(k + (suc n ∸ k)) mod suc n ≡⟨ cong (_mod suc n) (+-comm k _) ⟩
((suc n ∸ k) + k) mod suc n ≡⟨ cong (_mod suc n) (≤-∸-+-cancel (<-weaken {k} {suc n} (<ᵗ→< p))) ⟩
suc n mod suc n ≡⟨ zero-charac (suc n) ⟩
0 ∎)

+ₘ-lCancel : {n : ℕ} (x : Fin (suc n)) → (-ₘ x) +ₘ x ≡ 0
+ₘ-lCancel {n = n} x = +ₘ-comm (-ₘ x) x ∙ +ₘ-rCancel x

-- -- TODO : Ring laws
-- TODO : Ring laws

private
test₁ : Path (Fin 11) (5 +ₘ 10) 4
test₁ = refl

test₂ : Path (Fin 11) (-ₘ 7 +ₘ 5 +ₘ 10) 8
test₂ = refl

test₃ : Path (Fin 1024) (1022 ·ₘ 1023) 2
test₃ = refl

test₄ : Path (Fin 8192) (-ₘ 32 ·ₘ 64 +ₘ 256) 6400
test₄ = refl
4 changes: 2 additions & 2 deletions Cubical/Data/Nat/GCD.agda
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ open import Cubical.Data.Nat.Properties
open import Cubical.Data.Nat.Order
open import Cubical.Data.Nat.Order.Inductive
open import Cubical.Data.Nat.Mod renaming (
quotient'_/_ to _/_ ; remainder'_/_ to _%_
; ≡remainder'+quotient' to ≡%+·/ ; mod'< to %< )
quotient_/_ to _/_ ; remainder_/_ to _%_
; ≡remainder+quotient to ≡%+·/ ; mod< to %< )
open import Cubical.Data.Nat.Divisibility

open import Cubical.Relation.Nullary
Expand Down
Loading