Zulip Chat Archive
Stream: Is there code for X?
Topic: any element with correct order generates a cyclic group
Kenny Lau (Nov 17 2025 at 14:15):
import Mathlib
notation3 "IsGenerator" ζ => Function.Surjective fun x : ℤ ↦ ζ ^ x
example {G : Type*} [Group G] [Finite G]
(ζ : G) (hζ : orderOf ζ = Nat.card G) : IsGenerator ζ :=
sorry
(Update: removed IsCyclic hypothesis)
Kenny Lau (Nov 17 2025 at 14:21):
proof:
import Mathlib
notation3 "IsGenerator" ζ => Function.Surjective fun x : ℤ ↦ ζ ^ x
example {G : Type*} [Group G] [Finite G] (ζ : G) (hζ : orderOf ζ = Nat.card G) : IsGenerator ζ := by
unfold Function.Surjective
simp_rw [← Subgroup.mem_zpowers_iff, ← Subgroup.eq_top_iff', ← Subgroup.card_eq_iff_eq_top,
Nat.card_zpowers, hζ]
Damiano Testa (Nov 17 2025 at 14:30):
I thought that unfold Function.Surjective would have thrown an error and crashed your computer!
Kenny Lau (Nov 17 2025 at 14:30):
we should really look at these definitions that we have and fix them by adding the _def lemmas... It's a very very bad idea imo to rely on definitional unfolding!
Johan Commelin (Nov 17 2025 at 14:40):
It is not clear to me which definition you are complaining about.
Kenny Lau (Nov 17 2025 at 14:40):
/-- A function `f : α → β` is called surjective if every `b : β` is equal to `f a`
for some `a : α`. -/
@[expose]
def Surjective (f : α → β) : Prop :=
∀ b, Exists fun a => f a = b
Kenny Lau (Nov 17 2025 at 14:45):
here's a small script to print the 1693 definitions in Mathlib that are Prop-valued:
import Mathlib
def Test (f : Nat → Nat) : Prop := f 3 = 4
open Lean Elab Command
#eval show CommandElabM Unit from do
let env ← getEnv
for (name, val) in env.constants.toList do
let .defnInfo val := val | continue
let .regular _ := val.hints | continue
let .safe := val.safety | continue
if val.type.getForallBodyMaxDepth 100 == .sort 0 then
logInfo name
Andrew Yang (Nov 17 2025 at 14:45):
try Function.Surjective.eq_def
Johan Commelin (Nov 17 2025 at 14:46):
Kenny Lau said:
we should really look at these
definitionsthat we have and fix them by adding the_deflemmas... It's a very very bad idea imo to rely on definitional unfolding!
I think that relying on the defeq of Function.Surjective is not a problem. And very convenient!
Kenny Lau (Nov 17 2025 at 14:46):
that does work
Kenny Lau (Nov 17 2025 at 14:46):
@Johan Commelin yes, i'm saying that the lack of _def is the problem, not relying on defeq
Kenny Lau (Nov 17 2025 at 14:48):
anyway I'll stop here and make an RFC: #31745
Kevin Buzzard (Nov 17 2025 at 15:12):
I agree that not having surjective_def is a problem. When I'm doing live demos in front of undergraduates I usually choose a random thing to prove on the fly, sometimes asking the audience what mathematics they already know. Twice in October I spoke to undergraduates and in October the new ones don't know anything, except that most of them have heard of surjective, so I prove composite of two surjective functions is surjective (on the basis that it's a nice proof of something that everyone in the room understands) but I usually make a fool of myself trying to rw [surjective_def] and ultimately give up and just unfold Function.Surjective.
Kenny Lau (Nov 17 2025 at 15:15):
maybe this is an #xy problem, why does rw work with other definitions but not Function.Surjective?
@[expose]
def test : Nat → Nat := fun n ↦ 3
example : test 3 = 4 := by
rw [test]
Riccardo Brasca (Nov 17 2025 at 15:19):
This work, doesn't it?
def test : Nat → Nat := fun n ↦ 3
example : Function.Surjective test := by
rw [Function.Surjective]
Kenny Lau (Nov 17 2025 at 15:20):
why didn't it work in my code above?
Riccardo Brasca (Nov 17 2025 at 15:22):
Hmm, maybe I am confused, but rw [Surjective] in
def Surjective {α β : Type} (f : α → β) : Prop :=
∀ b, Exists fun a => f a = b
def test : Nat → Nat := fun n ↦ 3
example : Surjective test := by
rw [Surjective]
sorry
unfolds the definition as expected.
Etienne Marion (Nov 17 2025 at 15:26):
Kenny Lau said:
why didn't it work in my code above?
Are you referring to your first proof? This works in the web editor.
import Mathlib
notation3 "IsGenerator" ζ => Function.Surjective fun x : ℤ ↦ ζ ^ x
example {G : Type*} [Group G] [Finite G] (ζ : G) (hζ : orderOf ζ = Nat.card G) : IsGenerator ζ := by
rw [Function.Surjective]
simp_rw [← Subgroup.mem_zpowers_iff, ← Subgroup.eq_top_iff', ← Subgroup.card_eq_iff_eq_top,
Nat.card_zpowers, hζ]
Kenny Lau (Nov 17 2025 at 15:27):
hmm, that's very strange, maybe I just spelt it wrong the first time :melt:
Kenny Lau (Nov 17 2025 at 15:28):
in which case I apologise for the noise
Kevin Buzzard (Nov 17 2025 at 16:05):
Oh rw [Surjective] works for my situation too (although it is a little counterintuitive).
Last updated: Dec 20 2025 at 21:32 UTC