File size: 5,419 Bytes
4a56cd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import OAI.Combinatorics.ContingencyTables.Rooted.ForestCut

namespace OAI

/-!
# Actual bipartite cell forests and their completion intervals

The graph vertices are the original row and column labels. Capacities
are attached to unordered row-column edges. The deletion-component cut
is constructed from the maximizing forest, so the hypotheses of the
physical cut estimate follow from actual graph properties.
-/

namespace ContingencyTables.ForestCapacity

open scoped BigOperators Classical
open SimpleGraph
open MaximumForest ForestCut

variable {I J : Type*} [Fintype I] [Fintype J]

def cellAdj (small : I β†’ J β†’ Bool) : IβŠ•J β†’ IβŠ•J β†’ Prop
  | .inl i,.inr j => small i j=false
  | .inr j,.inl i => small i j=false
  | _,_ => False

def cellGraph (small : I β†’ J β†’ Bool) : SimpleGraph (IβŠ•J) where
  Adj := cellAdj small
  symm := ⟨by intro v w; cases v <;> cases w <;> exact id⟩
  loopless := ⟨by intro v; cases v <;> exact id⟩

def pairCapacity (b : I β†’ J β†’ β„•) : IβŠ•J β†’ IβŠ•J β†’ β„•
  | .inl i,.inr j => b i j
  | .inr j,.inl i => b i j
  | _,_ => 0

def capacity (b : I β†’ J β†’ β„•) : Sym2 (IβŠ•J) β†’ β„• :=
  Sym2.lift ⟨pairCapacity b,by intro v w; cases v <;> cases w <;> rfl⟩

omit [Fintype I] [Fintype J] in
@[simp] lemma capacity_cell (b : I β†’ J β†’ β„•) (i : I) (j : J) :
    capacity b s(Sum.inl i,Sum.inr j)=b i j := rfl

omit [Fintype I] [Fintype J] in
lemma cell_edge_injective : Function.Injective
    (fun a : IΓ—J => s(Sum.inl a.1,Sum.inr a.2)) := by
  rintro ⟨i,j⟩ ⟨i',j'⟩ h
  simpa only [Sym2.eq_iff,Prod.mk.injEq,Sum.inl.injEq,Sum.inr.injEq,
    Sum.inl_ne_inr,Sum.inr_ne_inl,false_and,or_false] using h

noncomputable def treeCell (T : SimpleGraph (IβŠ•J)) (i : I) (j : J) : Bool :=
  decide (T.Adj (.inl i) (.inr j))

/-- The actual maximum-forest cut gives the source's displacement and
interval bounds for every solution of the selected nonroot equations. -/
theorem completion_interval (small : I β†’ J β†’ Bool) (b : I β†’ J β†’ β„•)
    (T : SimpleGraph (IβŠ•J)) (hTG : T≀cellGraph small) (hT : T.IsAcyclic)
    (hmax : βˆ€ F : SimpleGraph (IβŠ•J), F≀cellGraph small β†’ F.IsAcyclic β†’
      weight F (capacity b)≀weight T (capacity b))
    (iβ‚€ : I) (jβ‚€ : J) (ht : T.Adj (.inl iβ‚€) (.inr jβ‚€)) (root : IβŠ•J)
    (hroot : T.Reachable root (.inl iβ‚€))
    (x q z X : I β†’ J β†’ ℝ) (d : ℝ) (W : β„•)
    (hd : 1≀d) (hcard : (Fintype.card I*Fintype.card J:β„•)≀d)
    (hlarge : βˆ€ i j, small i j=false β†’ W≀b i j ∧ 1≀b i j)
    (hsmall : βˆ€ i j, small i j=true β†’ b i j<W ∧
      (0≀x i j ∧ x i j≀b i j) ∧ (0≀q i j ∧ q i j≀b i j))
    (hX : βˆ€ i j, 0≀X i j ∧ X i j≀b i j)
    (hfree : βˆ€ i j, small i j=false β†’ treeCell T i j=false β†’
      0≀z i j ∧ z i j≀b i j+1)
    (hr : βˆ€ i, T.Reachable root (.inl i) β†’ Sum.inl iβ‰ root β†’ rowDifference small x z X i=0)
    (hc : βˆ€ j, T.Reachable root (.inr j) β†’ Sum.inr jβ‰ root β†’ columnDifference small q z X j=0) :
    -10*d*b iβ‚€ j₀≀z iβ‚€ jβ‚€ ∧ z iβ‚€ j₀≀10*d*b iβ‚€ jβ‚€ := by
  let t : Sym2 (IβŠ•J) := s(Sum.inl iβ‚€,Sum.inr jβ‚€)
  let D := T.deleteEdges {t}
  obtain ⟨r,hrr,hrootSide,hcross⟩ := exists_root_avoiding_side T hT ht root hroot
  let rowU : I β†’ Bool := fun i => side D r (.inl i)
  let colU : J β†’ Bool := fun j => side D r (.inr j)
  have hsβ‚€ : small iβ‚€ jβ‚€=false := hTG ht
  have hB : (1:ℝ)≀b iβ‚€ jβ‚€ := by exact_mod_cast (hlarge iβ‚€ jβ‚€ hsβ‚€).2
  have hdisp : |z iβ‚€ jβ‚€-X iβ‚€ jβ‚€|≀4*d*b iβ‚€ jβ‚€ := by
    apply displacement_bound small (treeCell T) rowU colU x q z X
      (fun i j => (b i j:ℝ)) iβ‚€ jβ‚€ d hcard hB hsβ‚€ hcross
    Β· intro i hi
      change side D r (.inl i)=true at hi
      apply hr i
      Β· have hri : D.Reachable r (.inl i) := by
          simpa only [side,decide_eq_true_eq] using hi
        exact hrr.trans (hri.mono
          (T.deleteEdges_le {t}))
      Β· intro he
        have hbad : side D r root=true := by simpa only [he] using hi
        exact Bool.false_ne_true (hrootSide.symm.trans hbad)
    Β· intro j hj
      change side D r (.inr j)=true at hj
      apply hc j
      Β· have hrj : D.Reachable r (.inr j) := by
          simpa only [side,decide_eq_true_eq] using hj
        exact hrr.trans (hrj.mono
          (T.deleteEdges_le {t}))
      Β· intro he
        have hbad : side D r root=true := by simpa only [he] using hj
        exact Bool.false_ne_true (hrootSide.symm.trans hbad)
    Β· exact hX
    Β· intro i j hs
      have hcap : b i j≀b iβ‚€ jβ‚€ := (Nat.le_of_lt (hsmall i j hs).1).trans
        (hlarge iβ‚€ jβ‚€ hsβ‚€).1
      exact ⟨by exact_mod_cast hcap,(hsmall i j hs).2⟩
    Β· intro i j htree hne
      apply side_eq_of_tree_edge T t r
      Β· exact of_decide_eq_true htree
      Β· exact fun he => hne (cell_edge_injective he)
    Β· intro i j hs htree
      refine ⟨hfree i j hs htree,?_⟩
      intro hcut
      have hgraph : (cellGraph small).Adj (.inl i) (.inr j) := hs
      have hcap := crossing_free_edge_le (cellGraph small) T (capacity b)
        hTG hT hmax t (by simpa [t] using ht) r hgraph
        (by simpa only [treeCell,decide_eq_false_iff_not] using htree) hcut
      exact_mod_cast hcap
  exact physical_interval_of_displacement d (b iβ‚€ jβ‚€) (X iβ‚€ jβ‚€) (z iβ‚€ jβ‚€)
    hd (Nat.cast_nonneg _) (hX iβ‚€ jβ‚€) hdisp

end ContingencyTables.ForestCapacity

end OAI