File size: 5,321 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
import Mathlib
import OAI.Computability.VertexCover.Reduction.RejectionCount

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

def Consistent (F : Formula) (i : Fin F.clauses.length) (P : Pattern) : Prop :=
  ∀ k l : Fin 3, (literalAt F i k).variableIndex = (literalAt F i l).variableIndex →
    flipSign (literalAt F i k).positive (P.val k) =
      flipSign (literalAt F i l).positive (P.val l)

instance (F : Formula) (i : Fin F.clauses.length) (P : Pattern) :
    Decidable (Consistent F i P) := inferInstanceAs (Decidable (∀ _k _l, _ → _))

theorem consistent_truth (F : Formula) (a : Fin F.«variables» → Bool)
    (i : Fin F.clauses.length) (hp : ∃ k, clauseValue F a i k = true) :
    Consistent F i ⟨clauseValue F a i, hp⟩ := by
  intro k l hkl
  change flipSign _ (flipSign _ _) = flipSign _ (flipSign _ _)
  simp only [flipSign_flipSign]
  rw [hkl]

def defaultAssignment (F : Formula) (i : Fin F.clauses.length)
    (v : Fin F.«variables») : Bool :=
  if v = (literalAt F i 0).variableIndex then (literalAt F i 0).positive else false

theorem default_true (F : Formula) (i : Fin F.clauses.length) :
    clauseValue F (defaultAssignment F i) i 0 = true := by
  simp only [clauseValue, Literal.eval, defaultAssignment, ↓reduceIte]
  cases (literalAt F i 0).positive <;> rfl

def defaultPattern (F : Formula) (i : Fin F.clauses.length) : Pattern :=
  ⟨clauseValue F (defaultAssignment F i) i, ⟨0, default_true F i⟩⟩

def normalizePattern (F : Formula) (i : Fin F.clauses.length) (P : Pattern) : Pattern :=
  if Consistent F i P then P else defaultPattern F i

theorem normalize_consistent (F : Formula) (i : Fin F.clauses.length) (P : Pattern) :
    Consistent F i (normalizePattern F i P) := by
  unfold normalizePattern
  split
  · assumption
  · exact consistent_truth F (defaultAssignment F i) i _

theorem normalize_truth (F : Formula) (a : Fin F.«variables» → Bool)
    (i : Fin F.clauses.length) (hp : ∃ k, clauseValue F a i k = true) :
    normalizePattern F i ⟨clauseValue F a i, hp⟩ = ⟨clauseValue F a i, hp⟩ := by
  exact ite_eq_left (consistent_truth F a i hp)

noncomputable def normalizeLabel (F : Formula) (i : Fin F.clauses.length) (l : Fin 7) : Fin 7 :=
  patternEquiv (normalizePattern F i (patternEquiv.symm l))

noncomputable def simpleGame (F : Formula) (hne : F.clauses ≠ []) : LabelCover :=
  { game F hne with projection := fun e label =>
      (game F hne).projection e (normalizeLabel F ((game F hne).left e) label) }

noncomputable def decodedLabeling (F : Formula) (hne : F.clauses ≠ [])
    (A : (simpleGame F hne).Labeling) : (game F hne).Labeling :=
  (fun i => normalizeLabel F i (A.1 i), A.2)

theorem simple_satisfies_iff (F : Formula) (hne : F.clauses ≠ [])
    (A : (simpleGame F hne).Labeling) (e : Fin (simpleGame F hne).M) :
    (simpleGame F hne).Satisfies A e ↔ (game F hne).Satisfies (decodedLabeling F hne A) e :=
  Iff.rfl

theorem simple_perfect_complete (F : Formula) (hne : F.clauses ≠ []) (hF : F.Satisfiable) :
    ∃ A : (simpleGame F hne).Labeling, ∀ e, (simpleGame F hne).Satisfies A e := by
  obtain ⟨a, ha⟩ := hF
  let A : (simpleGame F hne).Labeling := honestLabeling F hne a ha
  refine ⟨A, ?_⟩
  intro e
  change (game F hne).Satisfies (decodedLabeling F hne A) e
  have hdecode : decodedLabeling F hne A = honestLabeling F hne a ha := by
    apply Prod.ext
    · change (fun i : Fin F.clauses.length => normalizeLabel F i
        (patternEquiv ⟨clauseValue F a i, _⟩)) =
        (fun i : Fin F.clauses.length => patternEquiv ⟨clauseValue F a i, _⟩)
      funext i
      simp only [normalizeLabel, Equiv.symm_apply_apply, normalize_truth]
    · rfl
  rw [hdecode]
  exact honest_satisfies F hne a ha e

theorem simple_rejection_count (F : Formula) (hne : F.clauses ≠ [])
    (A : (simpleGame F hne).Labeling) :
    (unsatisfiedClauses F (assignmentOf F hne (decodedLabeling F hne A))).card ≤
      (Finset.univ.filter (fun e => ¬(simpleGame F hne).Satisfies A e)).card :=
  rejection_count F hne (decodedLabeling F hne A)

theorem simple_parallel (F : Formula) (hne : F.clauses ≠ [])
    (e e' : Fin (simpleGame F hne).M)
    (hl : (simpleGame F hne).left e = (simpleGame F hne).left e')
    (hr : (simpleGame F hne).right e = (simpleGame F hne).right e') :
    (simpleGame F hne).projection e = (simpleGame F hne).projection e' := by
  funext label
  change (finProdFinEquiv.symm e).1 = (finProdFinEquiv.symm e').1 at hl
  change (literalAt F (finProdFinEquiv.symm e).1 (finProdFinEquiv.symm e).2).variableIndex =
    (literalAt F (finProdFinEquiv.symm e').1 (finProdFinEquiv.symm e').2).variableIndex at hr
  simp only [simpleGame, game, normalizeLabel, Equiv.symm_apply_apply]
  rw [hl] at hr ⊢
  congr 1
  exact normalize_consistent F (finProdFinEquiv.symm e').1 (patternEquiv.symm label) _ _ hr

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