cfahlgren1/math / lean /ComparatorChallenges /MetricKMedian.lean
cfahlgren1's picture
download
raw
2.21 kB
import Mathlib
namespace OAI
section
section
namespace MetricKMedian
structure Instance where
n : ℕ
distance : Fin n → Fin n → ℚ
clients : Finset (Fin n)
facilities : Finset (Fin n)
k : ℕ
distance_nonneg : ∀ i j, 0 ≤ distance i j
distance_eq_zero : ∀ i j, distance i j = 0 ↔ i = j
distance_symm : ∀ i j, distance i j = distance j i
distance_triangle : ∀ i j h, distance i h ≤ distance i j + distance j h
k_pos : 1 ≤ k
k_le : k ≤ facilities.card
def encodeNat (n : ℕ) : List Bool :=
List.replicate n.bits.length true ++ [false] ++ n.bits
def encodeRat (q : ℚ) : List Bool :=
[decide (q.num < 0)] ++ encodeNat q.num.natAbs ++ encodeNat q.den
def encodeInstance (I : Instance) : List Bool :=
encodeNat I.n ++ encodeNat I.k ++
List.ofFn (fun i : Fin I.n => decide (i ∈ I.clients)) ++
List.ofFn (fun i : Fin I.n => decide (i ∈ I.facilities)) ++
(List.ofFn (fun i : Fin I.n =>
(List.ofFn (fun j : Fin I.n => encodeRat (I.distance i j))).flatten)).flatten
noncomputable def nearest (I : Instance) (j : Fin I.n) (S : Finset (Fin I.n)) : ℝ :=
if h : S.Nonempty then
(S.image (fun i => (I.distance j i : ℝ))).min' (h.image _)
else 0
noncomputable def cost (I : Instance) (S : Finset (Fin I.n)) : ℝ :=
∑ j ∈ I.clients, nearest I j S
def feasibleSets (I : Instance) : Finset (Finset (Fin I.n)) :=
I.facilities.powerset.filter (fun S => S.Nonempty ∧ S.card ≤ I.k)
noncomputable def optimum (I : Instance) : ℝ :=
if h : (feasibleSets I).Nonempty then
((feasibleSets I).image (cost I)).min' (h.image _)
else 0
def Correct (epsilon : ℝ) (I : Instance) (output : List Bool) : Prop :=
∃ S : Finset (Fin I.n), S ⊆ I.facilities ∧ S.Nonempty ∧ S.card ≤ I.k ∧
output = List.ofFn (fun i : Fin I.n => decide (i ∈ S)) ∧
cost I S ≤ (1 + 2 / Real.exp 1 + epsilon) * optimum I
theorem main_finite_work : ∀ ε : ℝ, 0 < ε →
∃ (algorithm : Instance → List Bool) (P : Turing.TM2ComputableInPolyTime encodeInstance id algorithm),
(∀ k : P.tm.K, Finite (P.tm.Γ k)) ∧ ∀ I, Correct ε I (algorithm I) := by
sorry
end MetricKMedian
end
end
end OAI

Xet Storage Details

Size:
2.21 kB
·
Xet hash:
918bb138b06a69042038a763089b46ccf3e1980e27fe9e37e0ed383d36f7e60a

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.