File size: 3,884 Bytes
e5a97c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
77
78
79
80
81
82
83
import Mathlib
import OAI.Combinatorics.MatchingCount.Machines.TreeMatrix
import OAI.Combinatorics.MatchingCount.Machines.TreeEnumeration
import OAI.Combinatorics.MatchingCount.Machines.TreeClosureReindex

namespace OAI

namespace MatchingFPRAS.ExecutableSource
open TreeTyped TreeFraction ExecutableBottleneck Enlargement RealGeometry

attribute [local instance] Transport.prodOrder Transport.sumOrder

lemma vertices_eq_ofFn_length (n : ℕ) (fuel : List Bool) (m : ℕ) (h : 4*fuel.length=m) :
    vertices (List.range n,fuel)=List.ofFn (fun i=>vertexRepr
      (UnitRefresh.orderedEnum (Vertex (Fin n) (LogicalEdge (Fin n)) m) i)) := by
  subst m
  exact vertices_eq_ofFn n fuel

abbrev BuildInput := (Matrix×List Bool)×List Nat

def prepare (x : BuildInput) : PathTableInput := (((x.1.1,close x.1.1),x.1.2),x.2)
def prepareRealizer : Realizer prepare := (pair (pair (pair first.fst
  (composition first.fst closeRealizer)) first.snd) second).congr (fun _=>rfl)
lemma polynomial_prepare : PolynomialTime prepareRealizer := by
  unfold prepareRealizer
  apply polynomial_congr
  have := polynomial_close
  dsimp only [Realizer.fst,Realizer.snd]
  tree_cost

def buildMatrix (x : BuildInput) : Matrix := materialize (prepare x)
def buildMatrixRealizer : Realizer buildMatrix := composition prepareRealizer materializeRealizer
lemma polynomial_buildMatrix : PolynomialTime buildMatrixRealizer :=
  polynomial_composition polynomial_prepare polynomial_materialize

def buildClosure (x : BuildInput) : Matrix := close (buildMatrix x)
def buildClosureRealizer : Realizer buildClosure := composition buildMatrixRealizer closeRealizer
lemma polynomial_buildClosure : PolynomialTime buildClosureRealizer :=
  polynomial_composition polynomial_buildMatrix polynomial_close

lemma source_activity_nonneg {n : ℕ} [Nontrivial (Fin n)] (hn : 2≤n) (w : Fin n→Fin n→ℚ)
    (hw : ∀ i j,0≤w i j) (K : ℕ) (a b : SourceVertex (Fin n) K) :
    0≤RationalSource.activity w K a b := by
  unfold RationalSource.activity
  apply Finset.sum_nonneg
  intro q _
  split_ifs
  · exact pathActivity_nonneg hn w hw K q.1 q.2
  · exact le_rfl

lemma buildMatrix_repr {n : ℕ} [Nontrivial (Fin n)] (hn : 2≤n)
    (w : Fin n→Fin n→ℚ) (hw : ∀ i j,0≤w i j) (K : ℕ) :
    buildMatrix ((matrixRep w,List.replicate (2*K+2) false),List.range n)=
      matrixRep (fun i j=>RationalSource.activity w K
        (UnitRefresh.orderedEnum (SourceVertex (Fin n) K) i)
        (UnitRefresh.orderedEnum (SourceVertex (Fin n) K) j)) := by
  unfold buildMatrix prepare materialize
  rw [close_matrixRep w hw]
  rw [show BottleneckAlgorithm.close w n=RationalSource.logicalB w by simp [RationalSource.logicalB]]
  change activityMatrix (pathTable (((matrixRep w,matrixRep (RationalSource.logicalB w)),
    List.replicate (2*K+2) false),List.range n),
    vertices (List.range n,List.replicate (2*K+2) false))=_
  have hv : vertices (List.range n,List.replicate (2*K+2) false)=
      List.ofFn (fun i=>vertexRepr (UnitRefresh.orderedEnum (SourceVertex (Fin n) K) i)) := by
    exact vertices_eq_ofFn_length n _ _ (by simp)
  rw [hv]
  exact activityMatrix_source_repr hn w hw K _ (List.length_replicate ..) _

lemma buildClosure_repr {n : ℕ} [Nontrivial (Fin n)] (hn : 2≤n)
    (w : Fin n→Fin n→ℚ) (hw : ∀ i j,0≤w i j) (K : ℕ) :
    buildClosure ((matrixRep w,List.replicate (2*K+2) false),List.range n)=
      matrixRep (fun i j=>RationalSource.realB w K
        (UnitRefresh.orderedEnum (SourceVertex (Fin n) K) i)
        (UnitRefresh.orderedEnum (SourceVertex (Fin n) K) j)) := by
  unfold buildClosure
  rw [buildMatrix_repr hn w hw K,close_matrixRep _ (fun _ _=>source_activity_nonneg hn w hw K _ _)]
  rw [BottleneckAlgorithm.close_reindex (UnitRefresh.orderedEnum (SourceVertex (Fin n) K))
    UnitRefresh.orderedEnum_lt]
  rfl
end MatchingFPRAS.ExecutableSource

end OAI