File size: 2,639 Bytes
dd14c26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import Mathlib

namespace OAI

noncomputable section

open scoped BigOperators

namespace SparsePaths

attribute [local instance] Classical.propDecidable

lemma walk_sum_abs {W : Type*} (G : SimpleGraph W) (h : W → ℝ)
    {x y : W} (p : G.Walk x y) :
    |h x-h y| ≤ (p.darts.map (fun e => |h e.fst-h e.snd|)).sum := by
  induction p with
  | nil => simp
  | @cons x y z hxy p ih =>
    simpa only [SimpleGraph.Walk.darts_cons,List.map_cons,List.sum_cons] using
      (abs_sub_le (h x) (h y) (h z)).trans (add_le_add le_rfl ih)

def dartsMap {W E : Type*} {G : SimpleGraph W} (v : W → E) (e : G.Dart) : E × E :=
  (v e.fst, v e.snd)

lemma dartsMap_injective {W E : Type*} {G : SimpleGraph W} (v : W → E)
    (hv : Function.Injective v) : Function.Injective (dartsMap (G := G) v) := by
  intro e f hef
  apply SimpleGraph.Dart.ext
  exact Prod.ext (hv (congrArg Prod.fst hef)) (hv (congrArg Prod.snd hef))

def edges {W E : Type*} [DecidableEq E] {G : SimpleGraph W} (v : W → E)
    {x y : W} (p : G.Walk x y) : Finset (E × E) :=
  (p.darts.map (dartsMap v)).toFinset

lemma card_edges {W E : Type*} [DecidableEq E] {G : SimpleGraph W}
    (v : W → E) (hv : Function.Injective v) {x y : W}
    (p : G.Walk x y) (hp : p.IsPath) : (edges v p).card = p.length := by
  rw [edges,List.toFinset_card_of_nodup]
  · simp
  · exact (p.darts_nodup_of_support_nodup hp.support_nodup).map (dartsMap_injective v hv)

lemma sum_edges {W E : Type*} [DecidableEq E] {G : SimpleGraph W}
    (v : W → E) (hv : Function.Injective v) {x y : W}
    (p : G.Walk x y) (hp : p.IsPath) (h : E → ℝ) :
    |h (v x)-h (v y)| ≤ ∑ e ∈ edges v p, |h e.1-h e.2| := by
  have hn := (p.darts_nodup_of_support_nodup hp.support_nodup).map (dartsMap_injective v hv)
  rw [edges,List.sum_toFinset _ hn]
  simpa only [List.map_map,Function.comp_def,dartsMap] using walk_sum_abs G (h ∘ v) p

lemma cap_count {E : Type*} [DecidableEq E] (F : Finset E) (a : E → ℝ)
    (ε : ℝ) (hε : 0 < ε) (ha : ∀ e ∈ F, a e ≤ 1)
    (hbad : (1-ε/2)*(F.card : ℝ) < ∑ e ∈ F, a e) :
    (F.card : ℝ)/2 ≤ ((F.filter (fun e => 1-ε ≤ a e)).card : ℝ) := by
  have hup : ∑ e ∈ F, a e ≤ (1-ε)*(F.card : ℝ) +
      ε*((F.filter (fun e => 1-ε ≤ a e)).card : ℝ) := by
    calc
      _ ≤ ∑ e ∈ F, ((1-ε) + if 1-ε ≤ a e then ε else 0) := by
        apply Finset.sum_le_sum
        intro e he
        split_ifs with hh
        · linarith [ha e he]
        · linarith
      _ = _ := by
        simp [Finset.sum_add_distrib,Finset.sum_ite,Finset.sum_const,mul_comm]
        ring
  nlinarith

end SparsePaths

end

end OAI