Skip to content

Commit 293041f

Browse files
committed
feat: add card_units_add_one lemma (#5738)
A lemma to reexpress card_units without subtraction.
1 parent 5dcd1aa commit 293041f

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

Mathlib/Data/Fintype/Units.lean

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Authors: Mario Carneiro
66
import Mathlib.Data.Fintype.Prod
77
import Mathlib.Data.Fintype.Sum
88
import Mathlib.Data.Int.Units
9+
import Mathlib.SetTheory.Cardinal.Finite
910

1011
#align_import data.fintype.units from "leanprover-community/mathlib"@"509de852e1de55e1efa8eacfa11df0823f26f226"
1112

@@ -33,11 +34,19 @@ instance [Monoid α] [Fintype α] [DecidableEq α] : Fintype αˣ :=
3334

3435
instance [Monoid α] [Finite α] : Finite αˣ := Finite.of_injective _ Units.ext
3536

36-
theorem Fintype.card_units [GroupWithZero α] [Fintype α] [Fintype αˣ] :
37-
Fintype.card αˣ = Fintype.card α - 1 := by
37+
theorem Fintype.card_eq_card_units_add_one [GroupWithZero α] [Fintype α] [DecidableEq α] :
38+
Fintype.card α = Fintype.card αˣ + 1 := by
39+
rw [eq_comm, Fintype.card_congr (unitsEquivNeZero α)]
40+
have := Fintype.card_congr (Equiv.sumCompl (· = (0 : α)))
41+
rwa [Fintype.card_sum, add_comm, Fintype.card_subtype_eq] at this
42+
43+
theorem Nat.card_eq_card_units_add_one [GroupWithZero α] [Finite α] :
44+
Nat.card α = Nat.card αˣ + 1 := by
45+
have : Fintype α := Fintype.ofFinite α
3846
classical
39-
rw [eq_comm, Nat.sub_eq_iff_eq_add (Fintype.card_pos_iff.2 ⟨(0 : α)⟩),
40-
Fintype.card_congr (unitsEquivNeZero α)]
41-
have := Fintype.card_congr (Equiv.sumCompl (· = (0 : α))).symm
42-
rwa [Fintype.card_sum, add_comm, Fintype.card_subtype_eq] at this
47+
rw [Nat.card_eq_fintype_card, Nat.card_eq_fintype_card, Fintype.card_eq_card_units_add_one]
48+
49+
theorem Fintype.card_units [GroupWithZero α] [Fintype α] [DecidableEq α] :
50+
Fintype.card αˣ = Fintype.card α - 1 := by
51+
rw [@Fintype.card_eq_card_units_add_one α, Nat.add_sub_cancel]
4352
#align fintype.card_units Fintype.card_units

Mathlib/FieldTheory/Finite/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ theorem forall_pow_eq_one_iff (i : ℕ) : (∀ x : Kˣ, x ^ i = 1) ↔ q - 1 ∣
181181

182182
/-- The sum of `x ^ i` as `x` ranges over the units of a finite field of cardinality `q`
183183
is equal to `0` unless `(q - 1) ∣ i`, in which case the sum is `q - 1`. -/
184-
theorem sum_pow_units [Fintype Kˣ] (i : ℕ) :
184+
theorem sum_pow_units [DecidableEq K] (i : ℕ) :
185185
(∑ x : Kˣ, (x ^ i : K)) = if q - 1 ∣ i then -1 else 0 := by
186186
let φ : Kˣ →* K :=
187187
{ toFun := fun x => x ^ i

0 commit comments

Comments
 (0)