@@ -910,4 +910,45 @@ theorem eraseInduction [DecidableEq α] {p : Finset α → Prop}
910910 (H : (S : Finset α) → (∀ s ∈ S, p (S.erase s)) → p S) (S : Finset α) : p S :=
911911 S.strongInduction fun S ih => H S fun _ hs => ih _ (erase_ssubset hs)
912912
913+ /--
914+ Given a function `f` which sends the finite set `s` to itself, the sequence of images of `s` under
915+ iterates of `f` is eventually constant. Furthermore, the sequence of images stabilises in fewer
916+ than `#s` steps.
917+ -/
918+ theorem image_iterate_stabilises_lt_card [DecidableEq α] {f : α → α} {s : Finset α}
919+ (hs : Set.MapsTo f s s) (hs₀ : s.Nonempty) :
920+ ∃ n < #s, ∀ m, n ≤ m → s.image f^[m] = s.image f^[n] := by
921+ let g (i : ℕ) : Finset α := s.image f^[i]
922+ have : g 0 = s := by simp [g]
923+ have (i : ℕ) : #(g i) ≠ 0 := by simp [g, hs₀.ne_empty]
924+ let G (i : ℕ) : ℕ := #(g i) - 1
925+ have hg (i : ℕ) : g (i + 1 ) ⊆ g i := by
926+ simp only [g]
927+ rw [Function.iterate_succ, ← image_image]
928+ exact image_subset_image hs.finsetImage_subset
929+ replace hg : Antitone g := antitone_nat_of_succ_le hg
930+ have G_eq (i j : ℕ) : G i = G j ↔ g i = g j := by
931+ wlog hij : j ≤ i generalizing i j
932+ · grind
933+ exact ⟨fun h ↦ eq_of_subset_of_card_le (hg hij) (by grind), by grind⟩
934+ have hG : Antitone G := fun i j h ↦ by simp only [G]; gcongr #?_ - 1 ; exact hg h
935+ have hG₁ (m : ℕ) : G m = G (m + 1 ) → G (m + 1 ) = G (m + 2 ) := by
936+ simp only [G_eq, g, Function.iterate_succ', ← image_image]
937+ grind
938+ obtain ⟨n, hn, hn'⟩ := Nat.stabilises_of_antitone hG hG₁
939+ exact ⟨n, by grind, by grind⟩
940+
941+ /--
942+ Given a function `f` which sends the finite set `s` to itself, the sequence of images of `s` under
943+ iterates of `f` is eventually constant. Furthermore, the sequence of images stabilises in at most
944+ `#s` steps.
945+ -/
946+ theorem image_iterate_stabilises_le_card [DecidableEq α] {f : α → α} {s : Finset α}
947+ (hs : Set.MapsTo f s s) :
948+ ∃ n ≤ #s, ∀ m, n ≤ m → s.image f^[m] = s.image f^[n] := by
949+ obtain rfl | hs₀ := s.eq_empty_or_nonempty
950+ · simp
951+ obtain ⟨n, hn', hn⟩ := image_iterate_stabilises_lt_card hs hs₀
952+ exact ⟨n, hn'.le, hn⟩
953+
913954end Finset
0 commit comments