File size: 6,522 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import Mathlib
import OAI.Computability.VertexCover.Reduction.CompatibleSingleton

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.ClauseProjection
open UniqueGames.Foundations.Target

abbrev Pattern := {s : Fin 3 → Bool // ∃ k, s k = true}

instance : Fintype Pattern := inferInstanceAs (Fintype {s : Fin 3 → Bool // ∃ k, s k = true})

theorem pattern_card : Fintype.card Pattern = 7 := by decide

noncomputable def patternEquiv : Pattern ≃ Fin 7 :=
  (Fintype.equivFin Pattern).trans (finCongr pattern_card)

def flipSign (positive b : Bool) : Bool := if positive then b else !b

@[simp] theorem flipSign_flipSign (p b : Bool) : flipSign p (flipSign p b) = b := by
  cases p <;> cases b <;> rfl

def literalAt (F : Formula) (i : Fin F.clauses.length) (k : Fin 3) : Literal F.«variables» :=
  (F.clauses.get i)[k]

noncomputable def game (F : Formula) (hne : F.clauses ≠ []) : LabelCover where
  u := F.clauses.length
  v := F.«variables»
  qU := 7
  qV := 2
  M := F.clauses.length * 3
  qU_pos := by decide
  qV_pos := by decide
  M_pos := Nat.mul_pos (List.length_pos_iff.mpr hne) (by decide)
  left e := (finProdFinEquiv.symm e).1
  right e := (literalAt F (finProdFinEquiv.symm e).1 (finProdFinEquiv.symm e).2).variableIndex
  projection e label := finTwoEquiv.symm
    (flipSign (literalAt F (finProdFinEquiv.symm e).1 (finProdFinEquiv.symm e).2).positive
      ((patternEquiv.symm label).val (finProdFinEquiv.symm e).2))

def clauseValue (F : Formula) (a : Fin F.«variables» → Bool)
    (i : Fin F.clauses.length) (k : Fin 3) : Bool :=
  (literalAt F i k).eval a

theorem clause_eval_iff (F : Formula) (a : Fin F.«variables» → Bool)
    (i : Fin F.clauses.length) :
    (F.clauses.get i).eval a = true ↔ ∃ k : Fin 3, clauseValue F a i k = true := by
  simp only [Clause.eval, Bool.or_eq_true]
  constructor
  · rintro ((h | h) | h)
    · exact ⟨0, h⟩
    · exact ⟨1, h⟩
    · exact ⟨2, h⟩
  · rintro ⟨k, hk⟩
    fin_cases k
    · exact Or.inl (Or.inl hk)
    · exact Or.inl (Or.inr hk)
    · exact Or.inr hk

noncomputable def honestLabeling (F : Formula) (hne : F.clauses ≠ [])
    (a : Fin F.«variables» → Bool)
    (ha : ∀ clause ∈ F.clauses, clause.eval a = true) : (game F hne).Labeling :=
  (fun i => patternEquiv ⟨clauseValue F a i,
      (clause_eval_iff F a i).mp (ha _ (List.get_mem _ i))⟩,
   fun v => finTwoEquiv.symm (a v))

theorem honest_satisfies (F : Formula) (hne : F.clauses ≠ [])
    (a : Fin F.«variables» → Bool)
    (ha : ∀ clause ∈ F.clauses, clause.eval a = true) :
    ∀ e, (game F hne).Satisfies (honestLabeling F hne a ha) e := by
  intro e
  simp only [LabelCover.Satisfies, game, honestLabeling, Equiv.symm_apply_apply]
  congr 1
  change flipSign _ (flipSign _ _) = _
  exact flipSign_flipSign _ _

theorem perfect_complete (F : Formula) (hne : F.clauses ≠ []) (hF : F.Satisfiable) :
    ∃ A : (game F hne).Labeling, ∀ e, (game F hne).Satisfies A e := by
  obtain ⟨a, ha⟩ := hF
  exact ⟨honestLabeling F hne a ha, honest_satisfies F hne a ha⟩

noncomputable def assignmentOf (F : Formula) (hne : F.clauses ≠ [])
    (A : (game F hne).Labeling) (v : Fin F.«variables») : Bool := finTwoEquiv (A.2 v)

theorem satisfies_iff (F : Formula) (hne : F.clauses ≠ [])
    (A : (game F hne).Labeling) (i : Fin F.clauses.length) (k : Fin 3) :
    (game F hne).Satisfies A (finProdFinEquiv (i,k)) ↔
      (patternEquiv.symm (A.1 i)).val k = clauseValue F (assignmentOf F hne A) i k := by
  simp only [LabelCover.Satisfies, game, Equiv.symm_apply_apply]
  change finTwoEquiv.symm (flipSign (literalAt F i k).positive
    ((patternEquiv.symm (A.1 i)).val k)) = A.2 (literalAt F i k).variableIndex ↔
    (patternEquiv.symm (A.1 i)).val k =
      flipSign (literalAt F i k).positive (assignmentOf F hne A (literalAt F i k).variableIndex)
  constructor
  · intro h
    have hh := congrArg finTwoEquiv h
    simp only [Equiv.apply_symm_apply] at hh
    have hf := congrArg (flipSign (literalAt F i k).positive) hh
    simpa only [flipSign_flipSign, assignmentOf] using hf
  · intro h
    rw [h, flipSign_flipSign]
    exact finTwoEquiv.symm_apply_apply _

def unsatisfiedClauses (F : Formula) (a : Fin F.«variables» → Bool) :
    Finset (Fin F.clauses.length) :=
  Finset.univ.filter (fun i => (F.clauses.get i).eval a = false)

theorem reject_of_unsatisfied (F : Formula) (hne : F.clauses ≠ [])
    (A : (game F hne).Labeling) (i : Fin F.clauses.length)
    (hi : i ∈ unsatisfiedClauses F (assignmentOf F hne A)) :
    ∃ k : Fin 3, ¬(game F hne).Satisfies A (finProdFinEquiv (i,k)) := by
  obtain ⟨k, hk⟩ := (patternEquiv.symm (A.1 i)).property
  refine ⟨k, ?_⟩
  intro hsat
  have hclause := (clause_eval_iff F (assignmentOf F hne A) i).mpr
    ⟨k, (satisfies_iff F hne A i k).mp hsat ▸ hk⟩
  have hfalse := (Finset.mem_filter.mp hi).2
  rw [hfalse] at hclause
  cases hclause

theorem rejection_count (F : Formula) (hne : F.clauses ≠ [])
    (A : (game F hne).Labeling) :
    (unsatisfiedClauses F (assignmentOf F hne A)).card ≤
      (Finset.univ.filter (fun e => ¬(game F hne).Satisfies A e)).card := by
  classical
  let bad := unsatisfiedClauses F (assignmentOf F hne A)
  let witness : {i // i ∈ bad} → Fin 3 := fun i =>
    (reject_of_unsatisfied F hne A i.val i.property).choose
  let occurrence : {i // i ∈ bad} → Fin (game F hne).M :=
    fun i => finProdFinEquiv (i.val, witness i)
  have hmap : ∀ i, occurrence i ∈ Finset.univ.filter (fun e => ¬(game F hne).Satisfies A e) := by
    intro i
    exact Finset.mem_filter.mpr ⟨Finset.mem_univ _,
      (reject_of_unsatisfied F hne A i.val i.property).choose_spec⟩
  have hinj : Function.Injective occurrence := by
    intro i j hij
    exact Subtype.ext (congrArg Prod.fst (finProdFinEquiv.injective hij))
  have hcard := Fintype.card_le_of_injective
    (fun i => (⟨occurrence i, hmap i⟩ :
      {e // e ∈ Finset.univ.filter (fun e => ¬(game F hne).Satisfies A e)}))
    (fun i j hij => hinj (congrArg Subtype.val hij))
  simpa only [Fintype.card_coe] using hcard

end VertexCover.ClauseProjection


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