Zulip Chat Archive
Stream: new members
Topic: Simplifying hidden function coercion mess
Gareth Ma (Jun 06 2024 at 23:22):
I have the following proof:
import Mathlib.RepresentationTheory.Character
import Mathlib.RingTheory.RootsOfUnity.Basic
/- import Mathlib.RingTheory.SimpleModule -/
open LinearMap Module Submodule Representation FiniteDimensional Function Pointwise CategoryTheory
MonoidAlgebra
variable {n : β} (hn : 1 < n) {π : Type} [Field π] {ΞΆ : π} (hΞΆ : ΞΆ β primitiveRoots n π)
example {k : β} : (FGModuleCat.of π π) β (FGModuleCat.of π π) :=
-- Without the cast rfl it doesn't work, even when marking as (x : π)
fun x β¦ (cast rfl x : π) * (ΞΆ : π) ^ k
-- this is very weird
theorem aux (f : (FGModuleCat.of π π).obj ββ[π] (FGModuleCat.of π π).obj) :
f = (1 : End (FGModuleCat.of π π)) β f.toFun = _root_.id := by
constructor <;> intro h
Β· subst h; ext; simp; exact CategoryTheory.id_apply _
Β· ext; change f.toFun _ = _; rw [h]; rfl
-- what?
@[ext] theorem af (f g : End (FGModuleCat.of π π)) (h : f.toFun = g.toFun) : f = g := by
cases f; cases g; congr!; simpa using h
lemma zeta_pow_mod_eq {k : β} : ΞΆ ^ (k % n) = ΞΆ ^ k := by
nth_rw 2 [β Nat.mod_add_div k n]
rw [mem_primitiveRoots (zero_lt_one.trans hn)] at hΞΆ
rw [pow_add, pow_mul, hΞΆ.pow_eq_one, one_pow, mul_one]
def cyc_rep : FdRep π (Multiplicative (ZMod n)) where
V := FGModuleCat.of π π
Ο := by
refine MonCat.ofHom <| MonoidHom.mk (OneHom.mk ?_ ?_) ?_
Β· intro k
refine β¨β¨fun x β¦ (cast rfl x : π) * ΞΆ ^ k.val, ?_β©, ?_β©
Β· intros; simp [add_mul]
Β· intros; simp [β mul_assoc]
Β· have : (1 : Multiplicative (ZMod n)).val = 0 := (ZMod.val_eq_zero _).mpr rfl
rw [aux]; ext; simp [this]
Β· -- this proof is disgusting
intro x y
ext z
simp [obj_carrier]
have : ΞΆ ^ (x * y).val = ΞΆ ^ y.val * ΞΆ ^ x.val := by
have : x * y = Multiplicative.toAdd x + Multiplicative.toAdd y := by rw [β toAdd_mul]; rfl
rw [this, mul_comm, @ZMod.val_add _ β¨by omegaβ©, zeta_pow_mod_eq hn hΞΆ, pow_add]
rfl
-- I still don't know what this is doing
rw [LinearMap.mul_apply, this, β mul_assoc]
rfl
And this is currently sorry-free, but I feel like I did it the "wrong way", as in there is a lot of weird function coercion steps in the middle in some weird ways, as commented above. If anyone has some extra time can someone try to simplify the proof and/or point out how this could've been better
Gareth Ma (Jun 06 2024 at 23:25):
Also this top example
example {k : β} : (FGModuleCat.of π π) β (FGModuleCat.of π π) :=
-- Without the cast rfl it doesn't work, even when marking as (x : π)
fun x β¦ (cast rfl x : π) * (ΞΆ : π) ^ k
is very confusing to me, but I can't tell if it's a bug or not
Gareth Ma (Jun 06 2024 at 23:31):
(I have a way shorter definition now, but I still want to use the categorical definition just as demonstration)
def cyc_rep' : Multiplicative (ZMod n) β* (π ββ[π] π) where
toFun := fun k β¦ {
toFun := fun x β¦ x * ΞΆ ^ k.val
map_add' := by intros; simp [add_mul]
map_smul' := by intros; simp [β mul_assoc]
}
map_one' := by ext; simp; convert pow_zero ΞΆ; simp only [ZMod.val_eq_zero]; rfl
map_mul' := by
intros x y
ext
have : x * y = Multiplicative.toAdd x + Multiplicative.toAdd y := by rw [β toAdd_mul]; rfl
simp
rw [this, mul_comm, @ZMod.val_add _ β¨by omegaβ©, zeta_pow_mod_eq hn hΞΆ, pow_add]
rfl
noncomputable def cyc_rep'' : FdRep π (Multiplicative (ZMod n)) := FdRep.of (cyc_rep' hn hΞΆ)
Kevin Buzzard (Jun 09 2024 at 08:34):
Gareth Ma said:
Also this top example
example {k : β} : (FGModuleCat.of π π) β (FGModuleCat.of π π) := -- Without the cast rfl it doesn't work, even when marking as (x : π) fun x β¦ (cast rfl x : π) * (ΞΆ : π) ^ k
is very confusing to me, but I can't tell if it's a bug or not
How about
example {k : β} : (FGModuleCat.of π π) β (FGModuleCat.of π π) :=
fun x β¦ (ΞΆ : π) ^ k β’ x
?
Kevin Buzzard (Jun 09 2024 at 08:38):
-- this is very weird
theorem aux (f : (FGModuleCat.of π π).obj ββ[π] (FGModuleCat.of π π).obj) :
f = (1 : End (FGModuleCat.of π π)) β f.toFun = _root_.id := by
I think f.toFun
is a code smell, whatever you're trying to do. Use coercions to function.
Gareth Ma (Jun 09 2024 at 08:47):
I can replace it with f.toAddHom = AddHom.id _
, is that better?
Gareth Ma (Jun 09 2024 at 08:50):
How about
example {k : β} : (FGModuleCat.of π π) β (FGModuleCat.of π π) :=
fun x β¦ (ΞΆ : π) ^ k β’ x
Oh! That's why *
doesn't work. I changed my proof below but that doesn't shorten the proof
Gareth Ma (Jun 09 2024 at 08:50):
At least it makes more sense
Eric Wieser (Jun 09 2024 at 08:50):
Or write βf = _root_.id
Gareth Ma (Jun 09 2024 at 08:51):
Ahh,. I see
Kevin Buzzard (Jun 09 2024 at 09:07):
Here's my effort to make the fdRep:
import Mathlib.RepresentationTheory.Character
import Mathlib.RingTheory.RootsOfUnity.Basic
/- import Mathlib.RingTheory.SimpleModule -/
open LinearMap Module Submodule Representation FiniteDimensional Function Pointwise CategoryTheory
MonoidAlgebra
variable {n : β} (hn : 1 < n) {π : Type} [Field π] {ΞΆ : π} (hΞΆ : ΞΆ β primitiveRoots n π)
-- this proof should work with just `NeZero n`
lemma zeta_pow_mod_eq {k : β} : ΞΆ ^ (k % n) = ΞΆ ^ k := by
nth_rw 2 [β Nat.mod_add_div k n]
rw [mem_primitiveRoots (zero_lt_one.trans hn)] at hΞΆ
rw [pow_add, pow_mul, hΞΆ.pow_eq_one, one_pow, mul_one]
-- and what you really want is ΞΆ ^ a = ΞΆ ^ b β a % n = b % n
-- missing API?
lemma foo (a b : ZMod n) : (a + b).val % n = (a.val + b.val) % n := by
have : NeZero n := β¨by omegaβ© -- that should be the assumption
simp [β ZMod.natCast_eq_natCast_iff']
open Multiplicative in
def Representation.cyc_rep : Representation π (Multiplicative (ZMod n)) π where
toFun mk := lsmul π π (ΞΆ ^ (toAdd mk).val)
map_one' := by ext; simp
map_mul' x y := by
ext
simp
rw [β pow_add, β zeta_pow_mod_eq hn hΞΆ, foo hn, zeta_pow_mod_eq hn hΞΆ]
noncomputable def cyc_rep :
FdRep π (Multiplicative (ZMod n)) :=
FdRep.of (Representation.cyc_rep hn hΞΆ)
Gareth Ma (Jun 09 2024 at 09:17):
Damn, I look back at my original attempt and I have no idea what I'm doing. This is a lot cleaner, thanks
YaΓ«l Dillies (Jun 09 2024 at 09:18):
Are you looking for docs#ZMod.cast_add, Kevin?
Eric Wieser (Jun 09 2024 at 09:34):
I'd split that further and go with
/-- Like `zpowersHom` but for `ZMod` and primitive roots. -/
@[simps]
def zmodpowersHom {ΞΆ : π} (hΞΆ : ΞΆ β primitiveRoots n π) : Multiplicative (ZMod n) β* π where
toFun := fun mk => (ΞΆ ^ mk.toAdd.val)
map_one' := by simp
map_mul' := fun x y => by
simp
rw [β pow_add, β zeta_pow_mod_eq hn hΞΆ, foo hn, zeta_pow_mod_eq hn hΞΆ]
open Multiplicative in
def Representation.cyc_rep : Representation π (Multiplicative (ZMod n)) π :=
(Algebra.lsmul π π π).toMonoidHom.comp (zmodpowersHom hn hΞΆ)
Last updated: May 02 2025 at 03:31 UTC