Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

p-swap local search for metric k-median has locality gap at most 3+2/p3 + 2/p3+2/p

Proved
LocalSearchFL.MultiSwap.multiswap_locality_gap

by mikedeng1 · Sep 27, 2026 · Mathlib 0df444a (Lean v4.33.1)

approximation-algorithmsfacility-locationk-medianlocal-searchp2o-batch-p100ap2o-gran-per-chapterp2o-plan-paperp2o-v1

Consider a metric instance with clients CCC, facilities FFF and service costs cjic_{ji}cji​ (nonnegative, symmetric, satisfying the triangle inequality), and the k-median cost cost(S)=∑j∈Cmin⁡i∈Scji\mathrm{cost}(S) = \sum_{j\in C} \min_{i \in S} c_{ji}cost(S)=∑j∈C​mini∈S​cji​ of a nonempty set SSS of open facilities.

Let p≥1p \ge 1p≥1 and k≥1k \ge 1k≥1 be integers, and let S⊆FS \subseteq FS⊆F with ∣S∣=k|S| = k∣S∣=k be locally optimum for the ppp-swap neighbourhood

B(S)={(S∖A)∪B∣A⊆S, B⊆F, ∣A∣=∣B∣≤p},\mathcal B(S) = \{(S \setminus A) \cup B \mid A \subseteq S,\ B \subseteq F,\ |A| = |B| \le p\},B(S)={(S∖A)∪B∣A⊆S, B⊆F, ∣A∣=∣B∣≤p},

that is, cost(S)≤cost(S′)\mathrm{cost}(S) \le \mathrm{cost}(S')cost(S)≤cost(S′) for every S′∈B(S)S' \in \mathcal B(S)S′∈B(S). Then for every nonempty set O⊆FO \subseteq FO⊆F with ∣O∣≤k|O| \le k∣O∣≤k,

cost(S)≤(3+2p)cost(O).\mathrm{cost}(S) \le \left(3 + \frac{2}{p}\right) \mathrm{cost}(O).cost(S)≤(3+p2​)cost(O).

In the language of local search: the locality gap of the k-median problem with respect to ppp-swaps is at most 3+2/p3 + 2/p3+2/p. As ppp grows the bound approaches 333; the paper gives a tight example (§3.5) for p=2p = 2p=2.

Formalization Note The bound is stated for every feasible OOO, not only an optimum (the proof never uses optimality), and multiplied out, so that cost(O)=0\mathrm{cost}(O) = 0cost(O)=0 causes no division. The constant is computed in R\mathbb RR as 3 + 2 / (p : ℝ). The case p=1p = 1p=1 is Theorem 3.2 of the paper (bound 555); §3.3 introduces multiswaps for p>1p > 1p>1, while the abstract and §3.5 allow every p≥1p \ge 1p≥1.

Preamble
import Mathlib
import Definitions.Def_LocalSearchFL_MultiSwap_kmCost
Formal statement
namespace LocalSearchFL.MultiSwap

/-- §3.4, p. 553 (announced §3.3, p. 551): p-swap local search for the metric k-median problem
has locality gap at most `3 + 2/p`. If `p ≥ 1` and `S` is a set of `k` facilities that is locally
optimum for the neighbourhood (3), then `cost(S) ≤ (3 + 2/p) · cost(O)` for every nonempty set
`O` of at most `k` facilities. -/
theorem multiswap_locality_gap {Cl Fa : Type} [Fintype Cl] [DecidableEq Cl]
    [Fintype Fa] [DecidableEq Fa]
    (I : LocalSearchFL.Shared.MetricInstance Cl Fa) (p : ℕ) (hp : 1 ≤ p)
    (k : ℕ) (S : Finset Fa) (hS : S.Nonempty) (hSk : S.card = k)
    (hloc : IsPSwapLocalOpt I p S hS)
    (O : Finset Fa) (hO : O.Nonempty) (hOk : O.card ≤ k) :
    kmCost I S hS ≤ (3 + 2 / (p : ℝ)) * kmCost I O hO := by sorry

end LocalSearchFL.MultiSwap
Source
Arya, Garg, Khandekar, Meyerson, Munagala, Pandit, Local Search Heuristics for k-Median and Facility Location Problems, SIAM J. Comput. 33(3), 2004, p. 553, §3.4 (announced §3.3, p. 551)
Read-back

What the Lean code literally says, in plain math · claude-opus-5-5

The statement concerns two finite types:

  • C\mathcal{C}C (the Lean type Cl), whose elements the names suggest are clients.
  • F\mathcal{F}F (the Lean type Fa), whose elements the names suggest are facilities.

Both types are required to be finite and to have decidable equality. The statement is also universally quantified over these arguments:

  • an object III of type LocalSearchFL.Shared.MetricInstance built on C\mathcal{C}C and F\mathcal{F}F;
  • a natural number ppp;
  • a natural number kkk;
  • a finite set S⊆FS \subseteq \mathcal{F}S⊆F;
  • a finite set O⊆FO \subseteq \mathcal{F}O⊆F.

None of the three definitions it uses (MetricInstance, IsPSwapLocalOpt and kmCost) is shown in the code given here. They come from an imported definitions module. So the read-back can only name them; it cannot say what they contain:

  • III is a value of type MetricInstance on C\mathcal{C}C and F\mathcal{F}F. What data it holds (for example distances), and what conditions it imposes (for example non-negativity, symmetry or a triangle inequality), cannot be seen here.
  • cost⁡I(T)\operatorname{cost}_I(T)costI​(T) stands for kmCost I T. It is a real number defined for a finite set T⊆FT \subseteq \mathcal{F}T⊆F together with a proof that TTT is nonempty. Its formula cannot be seen here.
  • LocOptp(I,S)\mathrm{LocOpt}_p(I, S)LocOptp​(I,S) stands for IsPSwapLocalOpt I p S. It is a proposition that also takes the proof that SSS is nonempty. What it requires, including what neighbourhood of SSS it compares against, cannot be seen here.

The hypotheses are:

  1. p≥1p \ge 1p≥1;
  2. SSS is nonempty;
  3. ∣S∣=k|S| = k∣S∣=k;
  4. LocOptp(I,S)\mathrm{LocOpt}_p(I, S)LocOptp​(I,S) holds;
  5. OOO is nonempty;
  6. ∣O∣≤k|O| \le k∣O∣≤k.

Under these hypotheses the statement asserts

cost⁡I(S)  ≤  (3+2p)⋅cost⁡I(O),\operatorname{cost}_I(S) \;\le\; \left(3 + \frac{2}{p}\right)\cdot \operatorname{cost}_I(O),costI​(S)≤(3+p2​)⋅costI​(O),

where ppp is converted to a real number, so 2/p2/p2/p is ordinary real division. The number kkk appears only in hypotheses 3 and 6. Its only role is to require ∣O∣≤∣S∣|O| \le |S|∣O∣≤∣S∣, because hypothesis 3 fixes kkk as the size of SSS. Nothing requires OOO to differ from SSS, to be disjoint from it or to be related to it in any way. Nothing gives ppp an upper bound; in particular ppp may exceed kkk.

Degenerate cases:

  • Division by ppp. Hypothesis 1 rules out p=0p = 0p=0, so the default value of 2/02/02/0 never arises. The factor 3+2/p3 + 2/p3+2/p lies in the interval (3,5](3, 5](3,5]. It equals 555 when p=1p = 1p=1.
  • Facilities. Hypothesis 2 forces F\mathcal{F}F to be nonempty and k≥1k \ge 1k≥1. If F\mathcal{F}F has one element, then SSS and OOO must both be that single facility. The claim then reads cost⁡I(S)≤(3+2/p)cost⁡I(S)\operatorname{cost}_I(S) \le (3 + 2/p)\operatorname{cost}_I(S)costI​(S)≤(3+2/p)costI​(S). Whether that holds depends on whether cost⁡I\operatorname{cost}_IcostI​ can be negative, which the unseen definition decides.
  • Clients. C\mathcal{C}C may be empty. What cost⁡I\operatorname{cost}_IcostI​ equals in that case, for example an empty sum of 000, cannot be seen here.
  • Local optimality. Whether hypothesis 4 can be satisfied at all, or whether it holds trivially in some cases (for example when ppp exceeds ∣S∣|S|∣S∣ or ∣F∣|\mathcal{F}|∣F∣), depends entirely on the unseen definition. If it can never hold, the statement is vacuous.
  • Unused docstring. The docstring describes a metric kkk-median problem and a "neighbourhood (3)". This read-back does not rely on it, because nothing in the visible code establishes those meanings.
Human review
  • Endorsed by Shuze Chen · Sep 28, 2026

    Confirmed by the moderator at approval.

  • Endorsed by mikedeng1 · Sep 28, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me