import Mathlib.Algebra.BigOperators.Associatedimport Mathlib.Data.Nat.Prime.Basicimport Mathlib.Tacticnamespace Erdos824Cycleprivate lemma tag_dvd_iff_mem {k i p : ℕ} (f : ℕ → ℕ) {S : Finset ℕ}(hS : S ⊆ Finset.range k) (hp : p.Prime) (htag : ∀ j<k, p ∣ f j ↔ j=i) :p ∣ ∏ j ∈ S, f j ↔ i∈S := byrw [hp.prime.dvd_finsetProd_iff]constructor· rintro ⟨j,hj,hdiv⟩rwa [← (htag j (Finset.mem_range.mp (hS hj))).mp hdiv]· intro hiexact ⟨i,hi,(htag i (Finset.mem_range.mp (hS hi))).mpr rfl⟩/-- If two lists of shifted primes have the column tags and successive rowtags of an alternating cycle, the only subproducts equal across the listsare the empty and the full products. The final wrap-around edge is redundantin this direction, since the path already forces constant membership. -/theorem equal_subproducts_trivial (k : ℕ) (f g cols rows : ℕ → ℕ)(hcols : ∀ i<k, (cols i).Prime)(hcf : ∀ i<k, ∀ j<k, cols i ∣ f j ↔ j=i)(hcg : ∀ i<k, ∀ j<k, cols i ∣ g j ↔ j=i)(hrows : ∀ i, i+1<k → (rows (i+1)).Prime)(hrf : ∀ i, i+1<k → ∀ j<k, rows (i+1) ∣ f j ↔ j=i+1)(hrg : ∀ i, i+1<k → ∀ j<k, rows (i+1) ∣ g j ↔ j=i)(S T : Finset ℕ) (hS : S⊆Finset.range k) (hT : T⊆Finset.range k)(he : (∏ i ∈ S, f i)=∏ j ∈ T, g j) :(S=∅ ∧ T=∅) ∨ (S=Finset.range k ∧ T=Finset.range k) := byhave hc : ∀ i<k, i∈S ↔ i∈T := byintro i hirw [← tag_dvd_iff_mem f hS (hcols i hi) (hcf i hi),← tag_dvd_iff_mem g hT (hcols i hi) (hcg i hi),he]have hST : S=T := byext iby_cases hi : i<k· exact hc i hi· have hnot : i ∉ Finset.range k := by simpa using hiexact ⟨fun h ↦ False.elim (hnot (hS h)), fun h ↦ False.elim (hnot (hT h))⟩have step : ∀ i, i+1<k → (i+1∈S ↔ i∈S) := byintro i hirw [← tag_dvd_iff_mem f hS (hrows i hi) (hrf i hi),(hc i (by omega)),← tag_dvd_iff_mem g hT (hrows i hi) (hrg i hi),he]have constant : ∀ i<k, i∈S ↔ 0∈S := byintro iinduction i with| zero => simp| succ i ih => intro hi; exact (step i hi).trans (ih (by omega))by_cases h0 : 0∈S· righthave hfull : S=Finset.range k := Finset.Subset.antisymm hS (byintro i hi; exact (constant i (Finset.mem_range.mp hi)).mpr h0)exact ⟨hfull,hST.symm.trans hfull⟩· lefthave hempty : S=∅ := Finset.eq_empty_iff_forall_notMem.mpr (byintro i hi; exact h0 ((constant i (Finset.mem_range.mp (hS hi))).mp hi))exact ⟨hempty,hST.symm.trans hempty⟩#print axioms equal_subproducts_trivialend Erdos824Cycle