/-- **The Erdős–Szekeres recursion** `R(s + 1, t + 1) ≤ R(s, t + 1) + R(s + 1, t)`.
Proof, as in the lesson: pick a vertex `v ∈ W` and split the other `|W| − 1 ≥ a + b − 1` vertices
into neighbours `N` and non-neighbours `M`. By pigeonhole `|N| ≥ a` or `|M| ≥ b`. In `N` we find
an `s`-clique (add `v` to get an `(s + 1)`-clique) or an independent `(t + 1)`-set; in `M` an
`(s + 1)`-clique or an independent `t`-set (add `v`). -/
theorem ramsey_step {α : Type*} [DecidableEq α] {s t a b : ℕ}
(hA : RamseyProp α s (t + 1) a) (hB : RamseyProp α (s + 1) t b) (hab : 0 < a + b) :
RamseyProp α (s + 1) (t + 1) (a + b) := by
classical
intro G W hW
obtain ⟨v, hv⟩ : W.Nonempty := Finset.card_pos.mp (by omega)
-- neighbours and non-neighbours of `v` in `W`
set N := (W.erase v).filter (G.Adj v) with hN
set M := (W.erase v).filter (fun w => ¬ G.Adj v w) with hM
have hcard : N.card + M.card = W.card - 1 := by
rw [hN, hM, Finset.card_filter_add_card_filter_not, Finset.card_erase_of_mem hv]
have hNW : N ⊆ W := (Finset.filter_subset _ _).trans (Finset.erase_subset _ _)
have hMW : M ⊆ W := (Finset.filter_subset _ _).trans (Finset.erase_subset _ _)
by_cases hNa : a ≤ N.card
· obtain ⟨S, hSN, hS | hS⟩ := hA G N hNa
· -- an `s`-clique of neighbours, plus `v`
refine ⟨insert v S, Finset.insert_subset hv (hSN.trans hNW), Or.inl ?_⟩
exact hS.insert fun w hw => (Finset.mem_filter.mp (hSN hw)).2
· exact ⟨S, hSN.trans hNW, Or.inr hS⟩
· -- pigeonhole: otherwise `M` is large
have hMb : b ≤ M.card := by omega
obtain ⟨S, hSM, hS | hS⟩ := hB G M hMb
· exact ⟨S, hSM.trans hMW, Or.inl hS⟩
· -- an independent `t`-set of non-neighbours, plus `v`
refine ⟨insert v S, Finset.insert_subset hv (hSM.trans hMW), Or.inr ?_⟩
refine hS.insert fun w hw => ?_
have hw' := Finset.mem_filter.mp (hSM hw)
rw [SimpleGraph.compl_adj]
exact ⟨fun h => (Finset.ne_of_mem_erase hw'.1) h.symm, hw'.2⟩