File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -47,4 +47,23 @@ See note [reducible non-instances]. -/
4747abbrev algebra (p : ℕ) [CharP R p] : Algebra (ZMod p) R :=
4848 algebra' R p dvd_rfl
4949
50+ /-- Any ring with a `ZMod p`-module structure can be upgraded to a `ZMod p`-algebra. Not an
51+ instance because this is usually not the default way, and this will cause typeclass search loop. -/
52+ def algebraOfModule (n : ℕ) (R : Type *) [Ring R] [Module (ZMod n) R] : Algebra (ZMod n) R :=
53+ Algebra.ofModule' (proof · ·|>.1 ) (proof · ·|>.2 ) where
54+ proof (r : ZMod n) (x : R) : r • 1 * x = r • x ∧ x * r • 1 = r • x := by
55+ obtain _ | n := n
56+ · obtain rfl : (inferInstanceAs (Module ℤ R)) = ‹_› := Subsingleton.elim _ _
57+ simp [ZMod, Int.cast_comm]
58+ · obtain ⟨r, rfl⟩ := ZMod.natCast_zmod_surjective r
59+ simp [Nat.cast_smul_eq_nsmul, Nat.cast_comm]
60+
61+ instance instIsScalarTower (n : ℕ) (R M : Type *) [Ring R] [AddCommGroup M]
62+ [Module (ZMod n) R] [m₁ : Module (ZMod n) M] [Module R M] :
63+ IsScalarTower (ZMod n) R M := by
64+ let := ZMod.algebraOfModule n R
65+ let m₂ := Module.compHom M (algebraMap (ZMod n) R)
66+ obtain rfl : m₁ = m₂ := Subsingleton.elim _ _
67+ exact ⟨fun x y z ↦ by rw [Algebra.smul_def, mul_smul]; rfl⟩
68+
5069end ZMod
Original file line number Diff line number Diff line change @@ -1296,3 +1296,12 @@ def Nat.residueClassesEquiv (N : ℕ) [NeZero N] : ℕ ≃ ZMod N × ℕ where
12961296 cast_id', id_eq, zero_add]
12971297 · simp only [add_comm p.1 .val, mul_add_div (NeZero.pos _),
12981298 (Nat.div_eq_zero_iff).2 <| .inr p.1 .val_lt, add_zero]
1299+
1300+ -- there is a faster proof with Module.toAddMonoidEnd
1301+ instance ZMod.instSubsingletonModule (n : ℕ) (M : Type *) [AddCommMonoid M] :
1302+ Subsingleton (Module (ZMod n) M) := by
1303+ obtain _ | n := n
1304+ · exact inferInstanceAs (Subsingleton (Module ℤ M))
1305+ refine ⟨fun m1 m2 ↦ Module.ext' _ _ fun r m ↦ ?_⟩
1306+ obtain ⟨r, rfl⟩ := ZMod.natCast_zmod_surjective r
1307+ rw [(letI := m1; Nat.cast_smul_eq_nsmul _ r m), Nat.cast_smul_eq_nsmul _ r m]
You can’t perform that action at this time.
0 commit comments