File size: 7,557 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 | import Mathlib
import OAI.Computability.VertexCover.Reduction.HonestLargeSumIndependent
import OAI.Computability.VertexCover.Machines.Primitives
import OAI.Computability.VertexCover.Machines.ProfileSlot
import OAI.Computability.VertexCover.Machines.ProfileCompat
import OAI.Computability.VertexCover.Machines.NormRepresentation
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.LabelCover
abbrev TracePos (d : ℕ) := Bool × Fin d
abbrev ProfileRep (a b d : ℕ) := TracePos d × Query.Profile a b d
abbrev TraceWeights (a b d : ℕ) := TracePos d → Fin ((max a b)^(d-1)) → Fin (2*d+1)
abbrev Descriptor (a b d : ℕ) :=
(ProfileRep a b d → Bool) × ((TracePos d × TracePos d → Bool) ×
((ProfileRep a b d × ProfileRep a b d → Bool) × TraceWeights a b d))
namespace Descriptor
variable {a b d : ℕ}
abbrev Rep (D : Descriptor a b d) := {r : ProfileRep a b d // D.1 r=true}
noncomputable def slot (D : Descriptor a b d) (r : ProfileRep a b d) : ℕ := by
classical
exact (Finset.univ.toList.filter (fun P => D.1 (r.1,P))).idxOf r.2
noncomputable def term (D : Descriptor a b d) (r : ProfileRep a b d) : ℝ :=
∑ x : TracePos d, if D.2.1 (x,r.1)=true then
if h : D.slot r < (max a b)^(d-1) then (gridRational d (D.2.2.2 x ⟨D.slot r,h⟩) : ℝ) else 0
else 0
def Good (D : Descriptor a b d) (S : Finset D.Rep) : Prop :=
(∀ r ∈ S, ∀ s ∈ S, D.2.1 (r.val.1,s.val.1)=true → r=s) ∧
(∀ r ∈ S, ∀ s ∈ S, D.2.2.1 (r.val,s.val)=true)
noncomputable def test (t : ℝ) (D : Descriptor a b d) : Bool := by
classical
exact decide (∀ S : Finset D.Rep, D.Good S → |∑ r ∈ S, D.term r.val| ≤ 2*t)
end Descriptor
variable {Φ : LabelCover} {d : ℕ}
def diagram (Q : TracePos d → Φ.Query d) (W : TraceWeights Φ.qU Φ.qV d) : Descriptor Φ.qU Φ.qV d :=
(fun r => decide ((Q r.1).ProfileValid r.2),
(fun xy => decide (Q xy.1=Q xy.2), (fun rs => decide (Query.ProfilePair (Q rs.1.1) (Q rs.2.1) rs.1.2 rs.2.2),W)))
noncomputable def diagramCoordinate (Q : TracePos d → Φ.Query d) (W : TraceWeights Φ.qU Φ.qV d)
(r : (diagram Q W).Rep) : Φ.Coordinate d :=
⟨Q r.val.1,(Q r.val.1).decode r.val.2 (of_decide_eq_true r.property)⟩
noncomputable def diagramSum (Q : TracePos d → Φ.Query d) (W : TraceWeights Φ.qU Φ.qV d) : Φ.Coordinate d → ℝ :=
∑ x, Φ.increment (Q x) (fun k => (gridRational d (W x ((Q x).slotPermutation k)) : ℝ))
theorem diagram_coordinate_encode (Q : TracePos d → Φ.Query d) (W : TraceWeights Φ.qU Φ.qV d)
(r : (diagram Q W).Rep) : (Q r.val.1).encode (diagramCoordinate Q W r).2=r.val.2 :=
(Q r.val.1).encode_decode r.val.2 (of_decide_eq_true r.property)
theorem diagram_slot (Q : TracePos d → Φ.Query d) (W : TraceWeights Φ.qU Φ.qV d)
(r : (diagram Q W).Rep) : (diagram Q W).slot r.val=((Q r.val.1).profileSlot (diagramCoordinate Q W r).2).val := by
classical
simp only [Descriptor.slot,diagram,Query.profileSlot,Query.profileLabels,diagram_coordinate_encode]
theorem diagram_term (Q : TracePos d → Φ.Query d) (W : TraceWeights Φ.qU Φ.qV d)
(r : (diagram Q W).Rep) : (diagram Q W).term r.val=diagramSum Q W (diagramCoordinate Q W r) := by
classical
rw [Descriptor.term]
simp only [diagramSum,Finset.sum_apply]
apply Finset.sum_congr rfl
intro x _
change (if decide (Q x=Q r.val.1)=true then
if h : (diagram Q W).slot r.val < Φ.WeightDimension d then
(gridRational d (W x ⟨_,h⟩) : ℝ) else 0 else 0)=_
simp only [decide_eq_true_eq]
by_cases h : Q x=Q r.val.1
· have hs := diagram_slot Q W r
have ht : (diagram Q W).slot r.val < Φ.WeightDimension d := hs.symm ▸ ((Q r.val.1).profileSlot _).isLt
rw [ite_eq_left h,dite_eq_left ht]
simp only [h,diagramCoordinate,increment_same,Query.slotPermutation_apply]
exact congrArg (fun k => (gridRational d (W x k) : ℝ)) (Fin.ext hs)
· rw [ite_eq_right h]
exact (Φ.increment_other (Q x) _ (diagramCoordinate Q W r) (Ne.symm h)).symm
theorem diagram_good (Q : TracePos d → Φ.Query d) (W : TraceWeights Φ.qU Φ.qV d)
(S : Finset (diagram Q W).Rep) :
(diagram Q W).Good S ↔ Set.InjOn (diagramCoordinate Q W) S ∧
Φ.Compatible (S.image (diagramCoordinate Q W)) := by
classical
have pair (r s : (diagram Q W).Rep) :
(diagram Q W).2.2.1 (r.val,s.val)=true ↔
Query.LabelPair (diagramCoordinate Q W r).1 (diagramCoordinate Q W s).1
(diagramCoordinate Q W r).2 (diagramCoordinate Q W s).2 := by
simp only [diagram,decide_eq_true_eq]
rw [← diagram_coordinate_encode Q W r,← diagram_coordinate_encode Q W s]
exact Query.profilePair_iff _ _ _ _
constructor
· rintro ⟨hu,hp⟩
have hi : Set.InjOn (diagramCoordinate Q W) S := by
intro r hr s hs he
exact hu r hr s hs (by simp only [diagram,decide_eq_true_eq]; exact congrArg Sigma.fst he)
refine ⟨hi,(Φ.compatible_pair_iff _).mpr ⟨?_,?_⟩⟩
· intro p hp' q hq' he
obtain ⟨r,hr,rfl⟩ := Finset.mem_image.mp hp'
obtain ⟨s,hs,rfl⟩ := Finset.mem_image.mp hq'
exact congrArg (diagramCoordinate Q W) (hu r hr s hs (by change Q r.val.1=Q s.val.1 at he; exact decide_eq_true he))
· intro p hp' q hq'
obtain ⟨r,hr,rfl⟩ := Finset.mem_image.mp hp'
obtain ⟨s,hs,rfl⟩ := Finset.mem_image.mp hq'
exact (pair r s).mp (hp r hr s hs)
· rintro ⟨hi,hc⟩
obtain ⟨hu,hp⟩ := (Φ.compatible_pair_iff _).mp hc
refine ⟨?_,?_⟩
· intro r hr s hs he
exact hi hr hs (hu _ (Finset.mem_image.mpr ⟨r,hr,rfl⟩) _ (Finset.mem_image.mpr ⟨s,hs,rfl⟩)
(by change decide (Q r.val.1=Q s.val.1)=true at he; exact of_decide_eq_true he))
· intro r hr s hs
exact (pair r s).mpr (hp _ (Finset.mem_image.mpr ⟨r,hr,rfl⟩) _ (Finset.mem_image.mpr ⟨s,hs,rfl⟩))
theorem diagram_test (Q : TracePos d → Φ.Query d) (W : TraceWeights Φ.qU Φ.qV d) (t : ℝ) :
(diagram Q W).test t=true ↔ Φ.compatibilityNorm (diagramSum Q W) ≤ 2*t := by
classical
let B := Finset.univ.image Q
have hz (p : Φ.Coordinate d) (hp : p.1 ∉ B) : diagramSum Q W p=0 := by
simp only [diagramSum,Finset.sum_apply]
apply Finset.sum_eq_zero
intro x _
exact Φ.increment_other _ _ _ (fun he => hp (Finset.mem_image.mpr ⟨x,Finset.mem_univ _,he.symm⟩))
have hc (p : Φ.Coordinate d) (hp : p.1 ∈ B) : ∃ r, diagramCoordinate Q W r=p := by
obtain ⟨x,_,hx⟩ := Finset.mem_image.mp hp
rcases p with ⟨i,A⟩
dsimp at hx
subst i
let r : (diagram Q W).Rep := ⟨(x,(Q x).encode A),decide_eq_true ((Q x).encode_valid A)⟩
refine ⟨r,?_⟩
change (⟨Q x,(Q x).decode ((Q x).encode A) _⟩ : Φ.Coordinate d)=⟨Q x,A⟩
congr 1
apply (Q x).encode_injective
exact (Q x).encode_decode _ _
rw [Φ.norm_le_representations (diagramCoordinate Q W) _ B hz hc]
simp only [Descriptor.test,decide_eq_true_eq,diagram_term]
constructor
· intro h S hi hs; exact h S ((diagram_good Q W S).mpr ⟨hi,hs⟩)
· intro h S hs
obtain ⟨hi,hc'⟩ := (diagram_good Q W S).mp hs
exact h S hi hc'
end VertexCover.LabelCover
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
|