Skip to content

Commit 3eb0bc2

Browse files
urkuderic-wieser
andcommitted
feat: port Archive.Imo.Imo1987Q1 (leanprover-community#5091)
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
1 parent 26f645a commit 3eb0bc2

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

Archive.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Archive.Imo.Imo1972Q5
99
import Archive.Imo.Imo1975Q1
1010
import Archive.Imo.Imo1977Q6
1111
import Archive.Imo.Imo1981Q3
12+
import Archive.Imo.Imo1987Q1
1213
import Archive.Imo.Imo1994Q1
1314
import Archive.Imo.Imo2001Q2
1415
import Archive.Imo.Imo2001Q6

Archive/Imo/Imo1987Q1.lean

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/-
2+
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Yury Kudryashov
5+
6+
! This file was ported from Lean 3 source module imo.imo1987_q1
7+
! leanprover-community/mathlib commit 5f25c089cb34db4db112556f23c50d12da81b297
8+
! Please do not edit these lines, except to modify the commit id
9+
! if you have ported upstream changes.
10+
-/
11+
import Mathlib.Data.Fintype.BigOperators
12+
import Mathlib.Data.Fintype.Perm
13+
import Mathlib.Data.Fintype.Prod
14+
import Mathlib.Dynamics.FixedPoints.Basic
15+
16+
/-!
17+
# Formalization of IMO 1987, Q1
18+
19+
Let $p_{n, k}$ be the number of permutations of a set of cardinality `n ≥ 1` that fix exactly `k`
20+
elements. Prove that $∑_{k=0}^n k p_{n,k}=n!$.
21+
22+
To prove this identity, we show that both sides are equal to the cardinality of the set
23+
`{(x : α, σ : perm α) | σ x = x}`, regrouping by `card (fixed_points σ)` for the left hand side and
24+
by `x` for the right hand side.
25+
26+
The original problem assumes `n ≥ 1`. It turns out that a version with `n * (n - 1)!` in the RHS
27+
holds true for `n = 0` as well, so we first prove it, then deduce the original version in the case
28+
`n ≥ 1`. -/
29+
30+
31+
variable (α : Type _) [Fintype α] [DecidableEq α]
32+
33+
open scoped BigOperators Nat
34+
35+
open Equiv Fintype Function
36+
37+
open Finset (range sum_const)
38+
39+
open Set (Iic)
40+
41+
namespace Imo1987Q1
42+
43+
/-- The set of pairs `(x : α, σ : perm α)` such that `σ x = x` is equivalent to the set of pairs
44+
`(x : α, σ : perm {x}ᶜ)`. -/
45+
def fixedPointsEquiv : { σx : α × Perm α // σx.2 σx.1 = σx.1 } ≃ Σ x : α, Perm ({x}ᶜ : Set α) :=
46+
calc
47+
{ σx : α × Perm α // σx.2 σx.1 = σx.1 } ≃ Σ x : α, { σ : Perm α // σ x = x } :=
48+
setProdEquivSigma _
49+
_ ≃ Σ x : α, { σ : Perm α // ∀ y : ({x} : Set α), σ y = Equiv.refl (↥({x} : Set α)) y } :=
50+
(sigmaCongrRight fun x => Equiv.Set.ofEq <| by simp only [SetCoe.forall]; dsimp; simp)
51+
_ ≃ Σ x : α, Perm ({x}ᶜ : Set α) := sigmaCongrRight fun x => by apply Equiv.Set.compl
52+
#align imo1987_q1.fixed_points_equiv Imo1987Q1.fixedPointsEquiv
53+
54+
theorem card_fixed_points :
55+
card { σx : α × Perm α // σx.2 σx.1 = σx.1 } = card α * (card α - 1)! := by
56+
simp [card_congr (fixedPointsEquiv α), card_perm, Finset.filter_not, Finset.card_sdiff,
57+
Finset.filter_eq', Finset.card_univ]
58+
#align imo1987_q1.card_fixed_points Imo1987Q1.card_fixed_points
59+
60+
/-- Given `α : Type*` and `k : ℕ`, `fiber α k` is the set of permutations of `α` with exactly `k`
61+
fixed points. -/
62+
def fiber (k : ℕ) : Set (Perm α) :=
63+
{σ : Perm α | card (fixedPoints σ) = k}
64+
#align imo1987_q1.fiber Imo1987Q1.fiber
65+
66+
instance : Fintype (fiber α k) := by unfold fiber; infer_instance
67+
68+
@[simp]
69+
theorem mem_fiber {σ : Perm α} {k : ℕ} : σ ∈ fiber α k ↔ card (fixedPoints σ) = k :=
70+
Iff.rfl
71+
#align imo1987_q1.mem_fiber Imo1987Q1.mem_fiber
72+
73+
/-- `p α k` is the number of permutations of `α` with exactly `k` fixed points. -/
74+
def p (k : ℕ) :=
75+
card (fiber α k)
76+
#align imo1987_q1.p Imo1987Q1.p
77+
78+
/-- The set of triples `(k ≤ card α, σ ∈ fiber α k, x ∈ fixed_points σ)` is equivalent
79+
to the set of pairs `(x : α, σ : perm α)` such that `σ x = x`. The equivalence sends
80+
`(k, σ, x)` to `(x, σ)` and `(x, σ)` to `(card (fixed_points σ), σ, x)`.
81+
82+
It is easy to see that the cardinality of the LHS is given by
83+
`∑ k : fin (card α + 1), k * p α k`. -/
84+
def fixedPointsEquiv' :
85+
(Σ (k : Fin (card α + 1)) (σ : fiber α k), fixedPoints σ.1) ≃
86+
{ σx : α × Perm α // σx.2 σx.1 = σx.1 } where
87+
toFun p := ⟨⟨p.2.2, p.2.1⟩, p.2.2.2
88+
invFun p :=
89+
⟨⟨card (fixedPoints p.1.2), (card_subtype_le _).trans_lt (Nat.lt_succ_self _)⟩, ⟨p.1.2, rfl⟩,
90+
⟨p.1.1, p.2⟩⟩
91+
left_inv := fun ⟨⟨k, hk⟩, ⟨σ, hσ⟩, ⟨x, hx⟩⟩ => by
92+
simp only [mem_fiber, Fin.val_mk] at hσ
93+
subst k; rfl
94+
right_inv := fun ⟨⟨x, σ⟩, h⟩ => rfl
95+
#align imo1987_q1.fixed_points_equiv' Imo1987Q1.fixedPointsEquiv'
96+
97+
/-- Main statement for any `(α : Type*) [fintype α]`. -/
98+
theorem main_fintype : ∑ k in range (card α + 1), k * p α k = card α * (card α - 1)! := by
99+
have A : ∀ (k) (σ : fiber α k), card (fixedPoints (↑σ : Perm α)) = k := fun k σ => σ.2
100+
simpa [A, ← Fin.sum_univ_eq_sum_range, -card_ofFinset, Finset.card_univ, card_fixed_points,
101+
mul_comm] using card_congr (fixedPointsEquiv' α)
102+
#align imo1987_q1.main_fintype Imo1987Q1.main_fintype
103+
104+
/-- Main statement for permutations of `fin n`, a version that works for `n = 0`. -/
105+
theorem main₀ (n : ℕ) : ∑ k in range (n + 1), k * p (Fin n) k = n * (n - 1)! := by
106+
simpa using main_fintype (Fin n)
107+
#align imo1987_q1.main₀ Imo1987Q1.main₀
108+
109+
/-- Main statement for permutations of `fin n`. -/
110+
theorem main {n : ℕ} (hn : 1 ≤ n) : ∑ k in range (n + 1), k * p (Fin n) k = n ! := by
111+
rw [main₀, Nat.mul_factorial_pred (zero_lt_one.trans_le hn)]
112+
#align imo1987_q1.main Imo1987Q1.main
113+
114+
end Imo1987Q1
115+

0 commit comments

Comments
 (0)