import Std/-! Li, Nešetřil and Yang, arXiv:2611.33681v1, §3.2, Problem 3.6.Finite simple graphs are edge lists on `Fin n`, with each edge listed once,smaller endpoint first. An orientation chooses a direction independently oneach edge. An order is a permutation listed from least to greatest. -/namespace LongtailProofs.LiNesetrilYang36abbrev Edges (n : Nat) := List (Fin n × Fin n)def orientations {n} : Edges n → List (Edges n)| [] => [[]]| (u,v) :: es => (orientations es).flatMap fun t => [(u,v)::t, (v,u)::t]def insertEverywhere (x : α) : List α → List (List α)| [] => [[x]]| y :: ys => (x :: y :: ys) :: (insertEverywhere x ys).map (y :: ·)def orders : List α → List (List α)| [] => [[]]| x :: xs => (orders xs).flatMap (insertEverywhere x)/-- Is there a simple directed path of at most `fuel` more arcs from `cur` to`x`? `seen` contains cur and its predecessors. Only intermediate verticesneed pass `internalOK`; the caller separately compares the two endpoints. -/def pathTo {n} (arcs : Edges n) (internalOK : Fin n → Bool) (x : Fin n) :Nat → Fin n → List (Fin n) → Bool| 0, cur, _ => cur == x| fuel+1, cur, seen => cur == x || arcs.any fun (u,v) =>u == cur && !seen.contains v && (v == x || internalOK v) &&pathTo arcs internalOK x fuel v (v :: seen)/-- `strong=false` selects weak reachability. `two=true` takes the unionof outgoing and incoming paths before counting reachable endpoints. -/def reachable {n} (arcs : Edges n) (order : List (Fin n)) (k : Nat)(strong two : Bool) (y x : Fin n) : Bool :=let rank := order.idxOflet ok := fun v => decide (rank x ≤ rank v) && (!strong || decide (rank y < rank v))decide (rank x ≤ rank y) && (pathTo arcs ok x k y [y] ||(two && pathTo (arcs.map Prod.swap) ok x k y [y]))def directedNumber {n} (arcs : Edges n) (k : Nat) (strong two : Bool) : Nat :=let vs := List.finRange n((orders vs).map fun order =>(vs.map fun y => vs.countP (reachable arcs order k strong two y)).foldl max 0).foldl min ndef graphNumber {n} (edges : Edges n) (k : Nat) (strong : Bool) : Nat :=((orientations edges).map fun d => directedNumber d k strong true).foldl max 0def halfUp (a : Nat) := (a+1)/2/-- The simultaneous-existence assertion of Problem 3.6. -/def Problem36 : Prop := ∀ (n : Nat) (edges : Edges n), edges.Nodup →(∀ e ∈ edges, e.1 < e.2) → ∀ k, 1 ≤ k → ∃ d ∈ orientations edges,directedNumber d k true false = halfUp (graphNumber edges k true) ∧directedNumber d k false false = halfUp (graphNumber edges k false)def p4 : Edges 4 := [(0,1), (1,2), (2,3)]set_option maxHeartbeats 5000000theorem enumeration_sizes : (orientations p4).Nodup ∧ (orientations p4).length = 8 ∧(orders (List.finRange 4)).Nodup ∧ (orders (List.finRange 4)).length = 24 := by decide/-- `p4` as an arc list is the coherent orientation 0 → 1 → 2 → 3. -/theorem coherent_weak : directedNumber p4 3 false true = 3 := by decidetheorem graph_values : graphNumber p4 3 true = 2 ∧ graphNumber p4 3 false = 3 := by decidetheorem plus_values : ∀ d ∈ orientations p4,directedNumber d 3 true false = 1 ∧ directedNumber d 3 false false = 1 := byhave h : (orientations p4).all (fun d => decide (directedNumber d 3 true false = 1 ∧directedNumber d 3 false false = 1)) = true := by decideintro d hdexact of_decide_eq_true (List.all_eq_true.mp h d hd)theorem not_problem36 : ¬ Problem36 := byintro hhave hlt : ∀ e ∈ p4, e.1 < e.2 := by simp [p4]obtain ⟨d, hd, _, hw⟩ := h 4 p4 (by decide) hlt 3 (by decide)rw [(plus_values d hd).2, graph_values.2] at hwexact (by decide : ¬ (1 = halfUp 3)) hw#print axioms graph_values#print axioms plus_values#print axioms not_problem36end LongtailProofs.LiNesetrilYang36