Documentation

Archive.Imo.Imo2024Q3

IMO 2024 Q3 #

Let $a_1, a_2, a_3, \ldots$ be an infinite sequence of positive integers, and let $N$ be a positive integer. Suppose that, for each $n > N$, $a_n$ is equal to the number of times $a_{n-1}$ appears in the list $a_1, a_2, \ldots, a_{n-1}$.

Prove that at least one of the sequences $a_1, a_3, a_5, \ldots$ and $a_2, a_4, a_6, \ldots$ is eventually periodic.

We follow Solution 1 from the official solutions. We show that the positive integers up to some positive integer $k$ (referred to as small numbers) all appear infinitely often in the given sequence while all larger positive integers appear only finitely often and then that the sequence eventually alternates between small numbers and larger integers. A further detailed analysis of the eventual behavior of the sequence ends up showing that the sequence of small numbers is eventually periodic with period at most $k$ (in fact exactly $k$).

def Imo2024Q3.Condition (a : ) (N : ) :

The condition of the problem. Following usual Lean conventions, this is expressed with indices starting from 0, rather than from 1 as in the informal statment (but N remains as the index of the last term for which a n is not defined in terms of previous terms).

Equations
Instances For

    The property of a sequence being eventually periodic.

    Equations
    Instances For

      Definitions and lemmas about the sequence that do not actually need the condition of #

      the problem

      def Imo2024Q3.M (a : ) (N : ) :

      A number greater than any of the initial terms a 0 through a N (otherwise arbitrary).

      Equations
      Instances For
        theorem Imo2024Q3.M_pos (a : ) (N : ) :
        0 < M a N
        theorem Imo2024Q3.one_le_M (a : ) (N : ) :
        1 M a N
        theorem Imo2024Q3.apply_lt_M_of_le_N (a : ) {N i : } (h : i N) :
        a i < M a N
        theorem Imo2024Q3.N_lt_of_M_le_apply {a : } {N i : } (h : M a N a i) :
        N < i
        theorem Imo2024Q3.ne_zero_of_M_le_apply {a : } {N i : } (h : M a N a i) :
        i 0
        theorem Imo2024Q3.apply_lt_of_M_le_apply {a : } {N i j : } (hi : M a N a i) (hj : j N) :
        a j < a i
        theorem Imo2024Q3.apply_ne_of_M_le_apply {a : } {N i j : } (hi : M a N a i) (hj : j N) :
        a j a i
        theorem Imo2024Q3.toFinset_card_pos {a : } {i : } (hf : {j : | a j = a i}.Finite) :
        theorem Imo2024Q3.apply_nth_zero (a : ) (i : ) :
        a (Nat.nth (fun (x : ) => a x = a i) 0) = a i
        theorem Imo2024Q3.map_add_one_range (p : Prop) [DecidablePred p] (n : ) (h0 : ¬p 0) :
        Finset.map { toFun := fun (x : ) => x + 1, inj' := } (Finset.filter (fun (x : ) => p (x + 1)) (Finset.range n)) = Finset.filter (fun (x : ) => p x) (Finset.range (n + 1))

        The basic structure of the sequence, eventually alternating small and large numbers #

        theorem Imo2024Q3.Condition.pos {a : } {N : } (hc : Condition a N) (n : ) :
        0 < a n
        @[simp]
        theorem Imo2024Q3.Condition.apply_ne_zero {a : } {N : } (hc : Condition a N) (n : ) :
        a n 0
        theorem Imo2024Q3.Condition.one_le_apply {a : } {N : } (hc : Condition a N) (n : ) :
        1 a n
        theorem Imo2024Q3.Condition.apply_eq_card {a : } {N : } (hc : Condition a N) {n : } (h : N < n) :
        a n = (Finset.filter (fun (i : ) => a i = a (n - 1)) (Finset.range n)).card
        theorem Imo2024Q3.Condition.apply_add_one_eq_card {a : } {N : } (hc : Condition a N) {n : } (h : N n) :
        a (n + 1) = (Finset.filter (fun (i : ) => a i = a n) (Finset.range (n + 1))).card
        @[simp]
        theorem Imo2024Q3.Condition.nth_apply_eq_zero {a : } {N : } (hc : Condition a N) (n : ) :
        Nat.nth (fun (x : ) => a x = 0) n = 0
        theorem Imo2024Q3.Condition.nth_apply_add_one_eq {a : } {N : } (hc : Condition a N) {n : } (h : N n) :
        Nat.nth (fun (x : ) => a x = a n) (a (n + 1) - 1) = n
        theorem Imo2024Q3.Condition.apply_nth_add_one_eq {a : } {N : } (hc : Condition a N) {m n : } (hfc : ∀ (hf : {i : | a i = m}.Finite), n < hf.toFinset.card) (hn : N Nat.nth (fun (x : ) => a x = m) n) :
        a (Nat.nth (fun (x : ) => a x = m) n + 1) = n + 1
        theorem Imo2024Q3.Condition.apply_nth_add_one_eq_of_infinite {a : } {N : } (hc : Condition a N) {m n : } (hi : {i : | a i = m}.Infinite) (hn : N Nat.nth (fun (x : ) => a x = m) n) :
        a (Nat.nth (fun (x : ) => a x = m) n + 1) = n + 1
        theorem Imo2024Q3.Condition.apply_nth_add_one_eq_of_lt {a : } {N : } (hc : Condition a N) {m n : } (hn : N < Nat.nth (fun (x : ) => a x = m) n) :
        a (Nat.nth (fun (x : ) => a x = m) n + 1) = n + 1
        theorem Imo2024Q3.Condition.lt_toFinset_card {a : } {N : } (hc : Condition a N) {j : } (h : M a N a (j + 1)) (hf : {i : | a i = a j}.Finite) :
        M a N - 1 < hf.toFinset.card
        theorem Imo2024Q3.Condition.nth_ne_zero_of_M_le_of_lt {a : } {N : } (hc : Condition a N) {i k : } (hi : M a N a i) (hk : k < a (i + 1)) :
        Nat.nth (fun (x : ) => a x = a i) k 0
        theorem Imo2024Q3.Condition.apply_add_one_lt_of_apply_eq {a : } {N : } (hc : Condition a N) {i j : } (hi : N i) (hij : i < j) (ha : a i = a j) :
        a (i + 1) < a (j + 1)
        theorem Imo2024Q3.Condition.apply_add_one_ne_of_apply_eq {a : } {N : } (hc : Condition a N) {i j : } (hi : N i) (hj : N j) (hij : i j) (ha : a i = a j) :
        a (i + 1) a (j + 1)
        theorem Imo2024Q3.Condition.exists_infinite_setOf_apply_eq {a : } {N : } (hc : Condition a N) :
        ∃ (m : ), {i : | a i = m}.Infinite
        theorem Imo2024Q3.Condition.injOn_setOf_apply_add_one_eq_of_M_le {a : } {N : } (hc : Condition a N) {n : } (h : M a N n) :
        Set.InjOn a {i : | a (i + 1) = n}
        theorem Imo2024Q3.Condition.empty_consecutive_apply_ge_M {a : } {N : } (hc : Condition a N) :
        {i : | M a N a i M a N a (i + 1)} =
        theorem Imo2024Q3.Condition.card_lt_M_of_M_le {a : } {N : } (hc : Condition a N) {n : } (h : M a N n) :
        ∃ (hf : {i : | a i = n}.Finite), hf.toFinset.card < M a N
        theorem Imo2024Q3.Condition.infinite_setOf_apply_eq_anti {a : } {N : } (hc : Condition a N) {j k : } (hj : 0 < j) (hk : {i : | a i = k}.Infinite) (hjk : j k) :
        {i : | a i = j}.Infinite

        The definitions of small, medium and big numbers and the eventual alternation #

        noncomputable def Imo2024Q3.Condition.k (a : ) :

        The largest number to appear infinitely often.

        Equations
        Instances For

          Small numbers are those that are at most k (that is, those that appear infinitely often).

          Equations
          Instances For
            theorem Imo2024Q3.Condition.infinite_setOf_apply_eq_iff_small {a : } {N : } (hc : Condition a N) {j : } (hj : 0 < j) :
            {i : | a i = j}.Infinite Small a j
            theorem Imo2024Q3.Condition.finite_setOf_apply_eq_iff_not_small {a : } {N : } (hc : Condition a N) {j : } (hj : 0 < j) :
            {i : | a i = j}.Finite ¬Small a j
            theorem Imo2024Q3.Condition.finite_setOf_k_lt_card {a : } {N : } (hc : Condition a N) :
            {m : | ∀ (hf : {i : | a i = m}.Finite), k a < hf.toFinset.card}.Finite

            There are only finitely many m that appear more than k times.

            theorem Imo2024Q3.Condition.bddAbove_setOf_k_lt_card {a : } {N : } (hc : Condition a N) :
            BddAbove {m : | ∀ (hf : {i : | a i = m}.Finite), k a < hf.toFinset.card}
            theorem Imo2024Q3.Condition.k_pos {a : } {N : } (hc : Condition a N) :
            0 < k a
            theorem Imo2024Q3.Condition.small_one {a : } {N : } (hc : Condition a N) :
            Small a 1
            noncomputable def Imo2024Q3.Condition.l (a : ) :

            The largest number to appear more than k times.

            Equations
            Instances For

              Medium numbers are those that are more than k but at most l (and include all numbers appearing finitely often but more than k times).

              Equations
              Instances For
                def Imo2024Q3.Condition.Big (a : ) (j : ) :

                Big numbers are those greater than l (thus, appear at most k times).

                Equations
                Instances For
                  theorem Imo2024Q3.Condition.k_le_l {a : } {N : } (hc : Condition a N) :
                  k a l a
                  theorem Imo2024Q3.Condition.k_lt_of_big {a : } {N : } (hc : Condition a N) {j : } (h : Big a j) :
                  k a < j
                  theorem Imo2024Q3.Condition.pos_of_big {a : } {N : } (hc : Condition a N) {j : } (h : Big a j) :
                  0 < j
                  theorem Imo2024Q3.Condition.not_small_of_big {a : } {N : } (hc : Condition a N) {j : } (h : Big a j) :
                  theorem Imo2024Q3.Condition.exists_card_le_of_big {a : } {N : } (hc : Condition a N) {j : } (h : Big a j) :
                  ∃ (hf : {i : | a i = j}.Finite), hf.toFinset.card k a
                  noncomputable def Imo2024Q3.Condition.N'aux (a : ) (N : ) :

                  N'aux is such that, by position N'aux, every medium number has made all its appearances and every small number has appeared more than max(k, N+1) times.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    noncomputable def Imo2024Q3.Condition.N' (a : ) (N : ) :

                    N' is such that, by position N', every medium number has made all its appearances and every small number has appeared more than max(k, N+1) times; furthermore, a N' is small (which means that every subsequent big number is preceded by a small number).

                    Equations
                    Instances For
                      theorem Imo2024Q3.Condition.not_medium_of_N'aux_lt {a : } {N : } (hc : Condition a N) {j : } (h : N'aux a N < j) :
                      ¬Medium a (a j)
                      theorem Imo2024Q3.Condition.small_or_big_of_N'aux_lt {a : } {N : } (hc : Condition a N) {j : } (h : N'aux a N < j) :
                      Small a (a j) Big a (a j)
                      theorem Imo2024Q3.Condition.small_or_big_of_N'_le {a : } {N : } (hc : Condition a N) {j : } (h : N' a N j) :
                      Small a (a j) Big a (a j)
                      theorem Imo2024Q3.Condition.nth_sup_k_N_add_one_le_N'aux_of_small {a : } {N j : } (h : Small a j) :
                      Nat.nth (fun (x : ) => a x = j) (k a (N + 1)) N'aux a N
                      theorem Imo2024Q3.Condition.nth_sup_k_le_N'aux_of_small {a : } {N : } (hc : Condition a N) {j : } (h : Small a j) :
                      Nat.nth (fun (x : ) => a x = j) (k a) N'aux a N
                      theorem Imo2024Q3.Condition.nth_sup_N_add_one_le_N'aux_of_small {a : } {N : } (hc : Condition a N) {j : } (h : Small a j) :
                      Nat.nth (fun (x : ) => a x = j) (N + 1) N'aux a N
                      theorem Imo2024Q3.Condition.N_lt_N'aux {a : } {N : } (hc : Condition a N) :
                      N < N'aux a N
                      theorem Imo2024Q3.Condition.N_lt_N' {a : } {N : } (hc : Condition a N) :
                      N < N' a N

                      N is less than N'.

                      theorem Imo2024Q3.Condition.lt_card_filter_eq_of_small_nth_lt {a : } {N : } (hc : Condition a N) {i j t : } (hj0 : 0 < j) (h : Small a j) (ht : Nat.nth (fun (x : ) => a x = j) t < i) :
                      t < (Finset.filter (fun (m : ) => a m = j) (Finset.range i)).card
                      theorem Imo2024Q3.Condition.k_lt_card_filter_eq_of_small_of_N'aux_le {a : } {N : } (hc : Condition a N) {i j : } (hj0 : 0 < j) (h : Small a j) (hN'aux : N'aux a N < i) :
                      k a < (Finset.filter (fun (m : ) => a m = j) (Finset.range i)).card
                      theorem Imo2024Q3.Condition.N_add_one_lt_card_filter_eq_of_small_of_N'aux_le {a : } {N : } (hc : Condition a N) {i j : } (hj0 : 0 < j) (h : Small a j) (hN'aux : N'aux a N < i) :
                      N + 1 < (Finset.filter (fun (m : ) => a m = j) (Finset.range i)).card
                      theorem Imo2024Q3.Condition.N_add_one_lt_card_filter_eq_of_small_of_N'_le {a : } {N : } (hc : Condition a N) {i j : } (hj0 : 0 < j) (h : Small a j) (hN' : N' a N < i) :
                      N + 1 < (Finset.filter (fun (m : ) => a m = j) (Finset.range i)).card
                      theorem Imo2024Q3.Condition.apply_add_one_big_of_apply_small_of_N'aux_le {a : } {N : } (hc : Condition a N) {i : } (h : Small a (a i)) (hN'aux : N'aux a N i) :
                      Big a (a (i + 1))
                      theorem Imo2024Q3.Condition.apply_add_one_big_of_apply_small_of_N'_le {a : } {N : } (hc : Condition a N) {i : } (h : Small a (a i)) (hN' : N' a N i) :
                      Big a (a (i + 1))
                      theorem Imo2024Q3.Condition.apply_add_one_small_of_apply_big_of_N'aux_le {a : } {N : } (hc : Condition a N) {i : } (h : Big a (a i)) (hN'aux : N'aux a N i) :
                      Small a (a (i + 1))
                      theorem Imo2024Q3.Condition.apply_add_one_small_of_apply_big_of_N'_le {a : } {N : } (hc : Condition a N) {i : } (h : Big a (a i)) (hN' : N' a N i) :
                      Small a (a (i + 1))
                      theorem Imo2024Q3.Condition.apply_add_two_small_of_apply_small_of_N'_le {a : } {N : } (hc : Condition a N) {i : } (h : Small a (a i)) (hN' : N' a N i) :
                      Small a (a (i + 2))
                      theorem Imo2024Q3.Condition.small_apply_N' {a : } {N : } (hc : Condition a N) :
                      Small a (a (N' a N))

                      a (N' a N) is a small number.

                      theorem Imo2024Q3.Condition.small_apply_N'_add_iff_even {a : } {N : } (hc : Condition a N) {n : } :
                      Small a (a (N' a N + n)) Even n
                      theorem Imo2024Q3.Condition.small_apply_add_two_mul_iff_small {a : } {N : } (hc : Condition a N) {n : } (m : ) (hN' : N' a N n) :
                      Small a (a (n + 2 * m)) Small a (a n)
                      theorem Imo2024Q3.Condition.apply_sub_one_small_of_apply_big_of_N'_le {a : } {N : } (hc : Condition a N) {i : } (h : Big a (a i)) (hN' : N' a N i) :
                      Small a (a (i - 1))
                      theorem Imo2024Q3.Condition.apply_sub_one_big_of_apply_small_of_N'_lt {a : } {N : } (hc : Condition a N) {i : } (h : Small a (a i)) (hN' : N' a N < i) :
                      Big a (a (i - 1))
                      theorem Imo2024Q3.Condition.apply_sub_two_small_of_apply_small_of_N'_lt {a : } {N : } (hc : Condition a N) {i : } (h : Small a (a i)) (hN' : N' a N < i) :
                      Small a (a (i - 2))
                      theorem Imo2024Q3.Condition.N_add_one_lt_apply_of_apply_big_of_N'_le {a : } {N : } (hc : Condition a N) {i : } (h : Big a (a i)) (hN' : N' a N i) :
                      N + 1 < a i
                      theorem Imo2024Q3.Condition.setOf_apply_eq_of_apply_big_of_N'_le {a : } {N : } (hc : Condition a N) {i : } (h : Big a (a i)) (hN' : N' a N i) :
                      {j : | a j = a i} = {j : | N < j Small a (a (j - 1)) a i = (Finset.filter (fun (t : ) => a t = a (j - 1)) (Finset.range j)).card}
                      theorem Imo2024Q3.Condition.N_lt_of_apply_eq_of_apply_big_of_N'_le {a : } {N : } (hc : Condition a N) {i j : } (hj : a j = a i) (h : Big a (a i)) (hN' : N' a N i) :
                      N < j
                      theorem Imo2024Q3.Condition.small_apply_sub_one_of_apply_eq_of_apply_big_of_N'_le {a : } {N : } (hc : Condition a N) {i j : } (hj : a j = a i) (h : Big a (a i)) (hN' : N' a N i) :
                      Small a (a (j - 1))

                      The main lemmas leading to the required result #

                      theorem Imo2024Q3.Condition.apply_add_one_eq_card_small_le_card_eq {a : } {N : } (hc : Condition a N) {i : } (hi : N' a N < i) (hib : Big a (a i)) :
                      a (i + 1) = (Finset.filter (fun (m : ) => a i (Finset.filter (fun (j : ) => a j = m) (Finset.range i)).card) (Finset.range (k a + 1))).card

                      Lemma 1 from the informal solution.

                      theorem Imo2024Q3.Condition.apply_eq_card_small_le_card_eq_of_small {a : } {N : } (hc : Condition a N) {i : } (hi : N' a N + 1 < i) (his : Small a (a i)) :
                      a i = (Finset.filter (fun (m : ) => a (i - 1) (Finset.filter (fun (j : ) => a j = m) (Finset.range i)).card) (Finset.range (k a + 1))).card

                      Similar to Lemma 1 from the informal solution, but with a Small hypothesis instead of Big and considering a range one larger (the form needed for Lemma 2).

                      theorem Imo2024Q3.Condition.exists_apply_sub_two_eq_of_apply_eq {a : } {N : } (hc : Condition a N) {i j : } (hi : N' a N + 2 < i) (hijlt : i < j) (his : Small a (a i)) (hijeq : a i = a j) (hij1 : ∀ (t : ), Small a t(Finset.filter (fun (x : ) => a x = t) (Finset.Ico i j)).card 1) :
                      tFinset.Ico i j, a (i - 2) = a t

                      Lemma 2 from the informal solution.

                      def Imo2024Q3.Condition.pSet (a : ) (n : ) :

                      The indices, minus n, of small numbers appearing for the second or subsequent time at or after a n.

                      Equations
                      Instances For
                        noncomputable def Imo2024Q3.Condition.p (a : ) (n : ) :

                        The index, minus n, of the second appearance of the first small number to appear twice at or after a n. This is only used for small a n with N' a N + 2 < n.

                        Equations
                        Instances For
                          theorem Imo2024Q3.Condition.nonempty_pSet {a : } {N : } (hc : Condition a N) (n : ) :
                          theorem Imo2024Q3.Condition.exists_mem_Ico_small_and_apply_add_p_eq {a : } {N : } (hc : Condition a N) (n : ) :
                          iFinset.Ico n (n + p a n), Small a (a i) a (n + p a n) = a i
                          theorem Imo2024Q3.Condition.p_pos {a : } {N : } (hc : Condition a N) (n : ) :
                          0 < p a n
                          theorem Imo2024Q3.Condition.card_filter_apply_eq_Ico_add_p_le_one {a : } {N : } (hc : Condition a N) (n : ) {j : } (hjs : Small a j) :
                          (Finset.filter (fun (i : ) => a i = j) (Finset.Ico n (n + p a n))).card 1
                          theorem Imo2024Q3.Condition.apply_add_p_eq {a : } {N : } (hc : Condition a N) {n : } (hn : N' a N + 2 < n) (hs : Small a (a n)) :
                          a (n + p a n) = a n
                          theorem Imo2024Q3.Condition.even_p {a : } {N : } (hc : Condition a N) {n : } (hn : N' a N + 2 < n) (hs : Small a (a n)) :
                          Even (p a n)
                          theorem Imo2024Q3.Condition.p_le_two_mul_k {a : } {N : } (hc : Condition a N) {n : } (hn : N' a N + 2 < n) (hs : Small a (a n)) :
                          p a n 2 * k a
                          theorem Imo2024Q3.Condition.p_apply_sub_two_le_p_apply {a : } {N : } (hc : Condition a N) {n : } (hn : N' a N + 4 < n) (hs : Small a (a n)) :
                          p a (n - 2) p a n
                          theorem Imo2024Q3.Condition.p_apply_le_p_apply_add_two {a : } {N : } (hc : Condition a N) {n : } (hn : N' a N + 2 < n) (hs : Small a (a n)) :
                          p a n p a (n + 2)
                          theorem Imo2024Q3.Condition.exists_p_eq (a : ) (N : ) (hc : Condition a N) :
                          ∃ (b : ) (c : ), ∀ (n : ), b < np a (N' a N + 2 * n) = c
                          theorem Imo2024Q3.Condition.exists_a_apply_add_eq (a : ) (N : ) (hc : Condition a N) :
                          ∃ (b : ) (c : ), 0 < c ∀ (n : ), b < na (N' a N + 2 * n + 2 * c) = a (N' a N + 2 * n)
                          theorem Imo2024Q3.result {a : } {N : } (h : Condition a N) :
                          (EventuallyPeriodic fun (i : ) => a (2 * i)) EventuallyPeriodic fun (i : ) => a (2 * i + 1)