File size: 3,271 Bytes
97c3405
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import OAI.Combinatorics.ContingencyTables.Machines.CellLowerTestProgram
import OAI.Combinatorics.ContingencyTables.Machines.BinarySearchProgram

namespace OAI

/-! # Computing an attained cell maximum by binary feasibility search

A finite maximum is used only to prove the result of the executed binary
search. The program never enumerates feasible tables.
-/

namespace ContingencyTables.CellMaximumProgram

open MatchingFPRAS.TreeTyped CellLowerTestProgram
open scoped Classical

def bound (z : Context) : ℕ := ResidualGraphProgram.capacityEntry (z.1.2,z.2)

def boundRealizer : Realizer bound :=
  composition (pair (composition first second) second) ResidualGraphProgram.capacityEntryRealizer

lemma polynomial_bound : PolynomialTime boundRealizer :=
  polynomial_composition (polynomial_pair
    (polynomial_composition polynomial_first polynomial_second) polynomial_second)
    ResidualGraphProgram.polynomial_capacityEntry

def maximum (z : Context) : ℕ := BinarySearchProgram.search test (z,bound z)

def maximumRealizer : Realizer maximum :=
  composition (f := fun z : Context=>(z,bound z))
    (g := BinarySearchProgram.search test)
    (pair identity boundRealizer) (BinarySearchProgram.searchRealizer test testRealizer)

lemma polynomial_maximum : PolynomialTime maximumRealizer :=
  polynomial_composition (polynomial_pair polynomial_identity polynomial_bound)
    (BinarySearchProgram.polynomial_search test testRealizer polynomial_test)

lemma bound_code {m n : ℕ} (r : Fin m→ℕ) (c : Fin n→ℕ) (b : Fin m→Fin n→ℕ)
    (i : Fin m) (j : Fin n) :
    bound (NetworkVertexCode.data r c b,(i.val,j.val))=b i j :=
  ResidualGraphProgram.capacityEntry_code b i j

/-- For every feasible instance the computed value is attained, and it
bounds the same coordinate of every other feasible table. -/
theorem maximum_correct {m n : ℕ} (hEK : PublishedEdmondsKarp.EdmondsKarp1972Theorem1)
    (r : Fin m→ℕ) (c : Fin n→ℕ) (b : Fin m→Fin n→ℕ)
    (i : Fin m) (j : Fin n)
    (hne : ∃ X,HasMargins X r c ∧ ∀ u v,X u v≤b u v) :
    ∃ X,HasMargins X r c ∧ (∀ u v,X u v≤b u v) ∧
      X i j=maximum (NetworkVertexCode.data r c b,(i.val,j.val)) ∧
      ∀ Y,HasMargins Y r c → (∀ u v,Y u v≤b u v) → Y i j≤X i j := by
  let S : Finset (BoundedTable r c b) := Finset.univ
  have hS : S.Nonempty := by
    obtain ⟨X,hm,hb⟩ := hne
    exact ⟨⟨⟨X,hm⟩,hb⟩,Finset.mem_univ _⟩
  obtain ⟨M,hM,hmax⟩ := Finset.exists_max_image S
    (fun X : BoundedTable r c b=>X.val.val i j) hS
  have ht (t : ℕ) :
      test ((NetworkVertexCode.data r c b,(i.val,j.val)),t)=true ↔ t≤M.val.val i j := by
    rw [CellLowerTestProgram.test_correct hEK]
    constructor
    · rintro ⟨X,hm,hb,hx⟩
      exact hx.trans (hmax ⟨⟨X,hm⟩,hb⟩ (Finset.mem_univ _))
    · intro hx
      exact ⟨M.val.val,M.val.property,M.property,hx⟩
  have he : maximum (NetworkVertexCode.data r c b,(i.val,j.val))=M.val.val i j := by
    unfold maximum
    rw [bound_code]
    exact BinarySearchProgram.search_eq test _ _ _ ht (M.property i j)
  exact ⟨M.val.val,M.val.property,M.property,he.symm,
    fun Y hm hb=>hmax ⟨⟨Y,hm⟩,hb⟩ (Finset.mem_univ _)⟩

end ContingencyTables.CellMaximumProgram

end OAI