File size: 5,191 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import Mathlib
import OAI.Computability.VertexCover.PCP.PreprocessingTables
import OAI.Computability.VertexCover.Analysis.GraphComplete
import OAI.Computability.VertexCover.Machines.Cardinal

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
open Machine

namespace Approximation
variable {α : ℝ}

theorem coverNumber_le_length (A : Approximation α) (G : ExplicitGraph) :
    G.coverNumber ≤ (A.run G).length := by
  classical
  let L := (A.run G).toFinset
  let e : {n // n ∈ L} ↪ Fin G.n :=
    ⟨fun n => ⟨n.val,A.vertices G n.val (List.mem_toFinset.mp n.property)⟩,
      fun _ _ h => Subtype.ext (congrArg Fin.val h)⟩
  let S : Finset (Fin G.n) := L.attach.map e
  have memS (n : Fin G.n) (hn : n.val ∈ A.run G) : n ∈ S := by
    apply Finset.mem_map.mpr
    exact ⟨⟨n.val,List.mem_toFinset.mpr hn⟩,Finset.mem_attach _ _,Fin.ext rfl⟩
  have hc : G.Cover S := by
    intro p hp
    exact (A.covers G p hp).imp (memS p.1) (memS p.2)
  have hcard : S.card = (A.run G).length := by
    simp only [S,Finset.card_map,Finset.card_attach,L]
    exact List.toFinset_card_of_nodup (A.nodup G)
  simpa only [hcard] using ExplicitGraph.coverNumber_le S hc

noncomputable def cardPoly (A : Approximation α) :
    Machine.Poly ExplicitGraph.bits natBits (fun G => (A.run G).length) :=
  (⟨A.computation,A.finiteAlphabet⟩ : Machine.Poly ExplicitGraph.bits natListBits A.run).comp Machine.Poly.natListCard

def test (A : Approximation α) (m : ℕ) (G : ExplicitGraph) : Bool :=
  decide (m*(A.run G).length < (m-1)*G.n)

noncomputable def testPoly (A : Approximation α) (m : ℕ) :
    Machine.Poly ExplicitGraph.bits boolBits (A.test m) := by
  let lhs := ((Machine.Poly.const ExplicitGraph.bits natBits m).pair A.cardPoly).comp Machine.Poly.natMul
  let rhs := ((Machine.Poly.const ExplicitGraph.bits natBits (m-1)).pair Machine.Poly.graphCard).comp Machine.Poly.natMul
  exact (lhs.pair rhs).comp Machine.Poly.natLT

end Approximation

theorem rational_threshold (m n k : ℕ) (hm : 1 ≤ m) :
    m*k < (m-1)*n ↔ (k : ℝ) < (1-1/(m:ℝ))*(n:ℝ) := by
  have hmp : (0:ℝ) < m := by exact_mod_cast (by omega : 0 < m)
  have he : (1-1/(m:ℝ))*(n:ℝ) = (((m-1:ℕ):ℝ)*n)/(m:ℝ) := by
    rw [Nat.cast_sub hm,Nat.cast_one]
    field_simp
  rw [he,lt_div_iff₀ hmp]
  rw [mul_comm (k:ℝ) (m:ℝ)]
  exact_mod_cast Iff.rfl

theorem exists_separating_integer {α : ℝ} (hα : α < 2) :
    ∃ m : ℕ, 4 ≤ m ∧ α*(1/2+1/(m:ℝ)) < 1-1/(m:ℝ) := by
  have hden : 0 < 2-α := sub_pos.mpr hα
  obtain ⟨m,hm⟩ := exists_nat_gt (max (4:ℝ) (2*(α+1)/(2-α)))
  have hm4 : 4 ≤ m := by
    have h := (le_max_left (4:ℝ) (2*(α+1)/(2-α))).trans_lt hm
    exact_mod_cast h.le
  have hb : 2*(α+1) < (m:ℝ)*(2-α) :=
    (div_lt_iff₀ hden).mp ((le_max_right (4:ℝ) _).trans_lt hm)
  have hmp : (0:ℝ) < m := by exact_mod_cast (by omega : 0 < m)
  refine ⟨m,hm4,?_⟩
  apply (mul_lt_mul_iff_left₀ hmp).mp
  have hs : (1/2+1/(m:ℝ))*(m:ℝ) = (m:ℝ)/2+1 := by field_simp
  have hn : (1-1/(m:ℝ))*(m:ℝ) = (m:ℝ)-1 := by field_simp
  rw [mul_assoc,hs,hn]
  nlinarith

noncomputable def decisionOfGap {α : ℝ} (hα : 1 ≤ α) (m : ℕ) (hm : 4 ≤ m)
    (hsep : α*(1/2+1/(m:ℝ)) < 1-1/(m:ℝ))
    (R : GapReduction m) (A : Approximation α) : ThreeSATDecision := by
  let c : Machine.Poly id boolBits (fun input => A.test m (R.construct input)) :=
    (⟨R.computation,R.finiteAlphabet⟩ : Machine.Poly id ExplicitGraph.bits R.construct).comp (A.testPoly m)
  refine ⟨fun input => A.test m (R.construct input),c.computation,c.finiteAlphabet,?_⟩
  intro input
  let G := R.construct input
  have hm1 : 1 ≤ m := by omega
  change decide (m*(A.run G).length < (m-1)*G.n)=true ↔ ThreeSAT input
  rw [decide_eq_true_eq,rational_threshold m G.n (A.run G).length hm1]
  constructor
  · intro hout
    by_contra hno
    have hlow := R.soundness input hno
    have hcover := A.coverNumber_le_length G
    have hc : (G.coverNumber:ℝ) ≤ (A.run G).length := by exact_mod_cast hcover
    exact (not_lt_of_ge hc) (lt_trans hout hlow)
  · intro hyes
    have hhigh := R.completeness input hyes
    have hcp : (0:ℝ) ≤ G.coverNumber := Nat.cast_nonneg _
    have hn : (0:ℝ) < G.n := by
      have hn0 : G.n ≠ 0 := by
        intro hz
        change (G.coverNumber:ℝ) < _ at hhigh
        rw [hz,Nat.cast_zero,mul_zero] at hhigh
        exact (not_lt_of_ge hcp) hhigh
      exact Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn0)
    have hαp : 0 < α := lt_of_lt_of_le zero_lt_one hα
    have hc := (A.quality G).trans_lt (mul_lt_mul_of_pos_left hhigh hαp)
    have hs := mul_lt_mul_of_pos_right hsep hn
    change ((A.run G).length : ℝ) < _
    exact hc.trans (by simpa only [mul_assoc] using hs)

end VertexCover
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