File size: 3,866 Bytes
92416a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import Mathlib

namespace OAI

section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
section
namespace VertexCover.GridCoupling
open MeasureTheory ProbabilityTheory
open scoped ENNReal

noncomputable def midpoint (p : ℕ) (i : Fin p) : ℝ := -1 + (2*(i:ℝ)+1)/p

noncomputable def index (p : ℕ) (hp : 0 < p) (x : ℝ) : Fin p :=
  ⟨min ⌊(p:ℝ)*(x+1)/2⌋₊ (p-1), (min_le_right _ _).trans_lt (by omega)⟩

theorem index_measurable (p : ℕ) (hp : 0 < p) : Measurable (index p hp) := by
  let g : ℕ → Fin p := fun k => ⟨min k (p-1), (min_le_right _ _).trans_lt (by omega)⟩
  exact (measurable_of_countable g).comp
    (((measurable_const.mul (measurable_id.add_const 1)).div_const 2).nat_floor)

theorem floor_lt_on_interval (p : ℕ) (hp : 0 < p) {x : ℝ}
    (hx : x ∈ Set.Ico (-1 : ℝ) 1) : ⌊(p:ℝ)*(x+1)/2⌋₊ < p := by
  apply (Nat.floor_lt' (Nat.ne_of_gt hp)).mpr
  have hpR : (0:ℝ) < p := Nat.cast_pos.mpr hp
  nlinarith [mul_lt_mul_of_pos_left hx.2 hpR]

theorem index_val_on_interval (p : ℕ) (hp : 0 < p) {x : ℝ}
    (hx : x ∈ Set.Ico (-1 : ℝ) 1) : (index p hp x).val = ⌊(p:ℝ)*(x+1)/2⌋₊ := by
  exact min_eq_left (by have h := floor_lt_on_interval p hp hx; omega)

theorem index_eq_iff_on_interval (p : ℕ) (hp : 0 < p) {x : ℝ}
    (hx : x ∈ Set.Ico (-1 : ℝ) 1) (i : Fin p) :
    index p hp x = i ↔ -1 + 2*(i:ℝ)/p ≤ x ∧ x < -1 + 2*((i:ℝ)+1)/p := by
  have hz : 0 ≤ (p:ℝ)*(x+1)/2 := div_nonneg (mul_nonneg (Nat.cast_nonneg _) (by linarith [hx.1])) (by norm_num)
  have hpR : (0:ℝ) < p := Nat.cast_pos.mpr hp
  rw [Fin.ext_iff, index_val_on_interval p hp hx, Nat.floor_eq_iff hz]
  constructor
  · rintro ⟨hl, hu⟩
    constructor
    · have h : 2*(i:ℝ)/p ≤ x+1 := (div_le_iff₀ hpR).mpr (by nlinarith)
      linarith
    · have h : x+1 < 2*((i:ℝ)+1)/p := (lt_div_iff₀ hpR).mpr (by nlinarith)
      linarith
  · rintro ⟨hl, hu⟩
    have hL : 2*(i:ℝ) ≤ (x+1)*p := (div_le_iff₀ hpR).mp (by linarith)
    have hU : (x+1)*p < 2*((i:ℝ)+1) := (lt_div_iff₀ hpR).mp (by linarith)
    constructor <;> nlinarith

end VertexCover.GridCoupling
namespace VertexCover.GridCoupling
open MeasureTheory ProbabilityTheory
open scoped ENNReal

theorem cell_subset_interval (p : ℕ) (hp : 0 < p) (i : Fin p) :
    Set.Ico (-1 + 2*(i:ℝ)/p) (-1 + 2*((i:ℝ)+1)/p) ⊆ Set.Ico (-1:ℝ) 1 := by
  intro x hx
  have hpR : (0:ℝ) < p := Nat.cast_pos.mpr hp
  have hi : (i:ℝ)+1 ≤ p := by exact_mod_cast i.isLt
  have hz : 0 ≤ 2*(i:ℝ)/p := div_nonneg (mul_nonneg (by norm_num) (Nat.cast_nonneg _)) hpR.le
  have hu : 2*((i:ℝ)+1)/p ≤ 2 := (div_le_iff₀ hpR).mpr (by nlinarith)
  exact ⟨by linarith [hx.1], by linarith [hx.2]⟩

theorem preimage_cell (p : ℕ) (hp : 0 < p) (i : Fin p) :
    (index p hp ⁻¹' {i}) ∩ Set.Ico (-1:ℝ) 1 =
      Set.Ico (-1 + 2*(i:ℝ)/p) (-1 + 2*((i:ℝ)+1)/p) := by
  ext x
  constructor
  · rintro ⟨hi, hx⟩
    exact (index_eq_iff_on_interval p hp hx i).mp hi
  · intro hx
    have hx' := cell_subset_interval p hp i hx
    exact ⟨(index_eq_iff_on_interval p hp hx' i).mpr hx, hx'⟩

theorem rounding_error (p : ℕ) (hp : 0 < p) {x : ℝ}
    (hx : x ∈ Set.Ico (-1 : ℝ) 1) : |x - midpoint p (index p hp x)| ≤ 1/p := by
  have h := (index_eq_iff_on_interval p hp hx (index p hp x)).mp rfl
  unfold midpoint
  rw [abs_le]
  simp only [mul_add, mul_one, add_div] at h ⊢
  have he : (2:ℝ)/p = 2*(1/p) := by ring
  rw [he] at h
  constructor <;> linarith

end VertexCover.GridCoupling

end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end

end OAI