File size: 3,796 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 | import Mathlib
import OAI.Computability.VertexCover.PCP.PoweringAddresses
import OAI.Computability.VertexCover.Machines.Walk
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.Machine
namespace FixedSearch
def run {α ι β : Type} (p : α → ι → Bool) (f : α → ι → β) (z : β) : List ι → α → β
| [], _ => z
| i::xs, a => if p a i then f a i else run p f z xs a
noncomputable def poly {α ι β : Type} (ea : α → List Bool) (eb : β → List Bool)
(p : α → ι → Bool) (f : α → ι → β) (z : β)
(cp : ∀ i, Poly ea boolBits (fun a => p a i))
(cf : ∀ i, Poly ea eb (fun a => f a i)) :
(xs : List ι) → Poly ea eb (run p f z xs)
| [] => Poly.const ea eb z
| i::xs => (cp i).ite (cf i) (poly ea eb p f z cp cf xs)
theorem eq_scan {ι β : Type} (p : ι → Prop) [DecidablePred p] (f : ι → β) (z : β) :
∀ (xs : List ι) (h : ∃ i ∈ xs, p i),
run (fun (_ : Unit) i => decide (p i)) (fun _ i => f i) z xs () =
f (UniqueGames.Foundations.PCP.PoweringLabels.scanWitness p xs h).val := by
intro xs
induction xs with
| nil => intro h; simp at h
| cons i xs ih =>
intro h
by_cases hp : p i
· simp [run,UniqueGames.Foundations.PCP.PoweringLabels.scanWitness,hp]
· simp only [run,decide_eq_true_eq,hp,↓reduceIte,
UniqueGames.Foundations.PCP.PoweringLabels.scanWitness,↓reduceDIte]
exact ih _
end FixedSearch
namespace AddressMachine
open UniqueGames.Foundations.PCP
open PoweringLabels PoweringAddresses WalkMachine
def search {d : ℕ} (t : ℕ) (a : PaddedLabel (Fin d) t GraphTables.Label)
(x : State d × ℕ) : GraphTables.Label :=
FixedSearch.run (fun x w => decide ((word w.1.val w.2 x.1).2.val=x.2))
(fun _ w => a w) 0 (allAddresses d t) x
noncomputable def searchPoly {d : ℕ} (t : ℕ) (a : PaddedLabel (Fin d) t GraphTables.Label) :
Poly (prodBits (code (d := d)) natBits) finCode (search t a) := by
exact FixedSearch.poly (prodBits code natBits) finCode _ _ 0
(fun w => ((((Poly.fst code natBits).comp (wordPoly w.1.val w.2)).comp vertexPoly).pair
(Poly.snd code natBits)).comp Poly.natEq)
(fun w => Poly.const _ finCode (a w)) (allAddresses d t)
theorem search_decode {d : ℕ} (T : PortTables.Input d) (t : ℕ) (v : Fin T.1)
(u : Ball (PortTables.portGraph T.2) t v) (a : PaddedLabel (Fin d) t GraphTables.Label) :
search t a ((⟨T,v⟩ : State d),u.val.val) =
decode (finitePortSelector (PortTables.portGraph T.2) t v) a u := by
let p := fun w : PortWords (Fin d) t =>
(wordToBall (PortTables.portGraph T.2) t v w).val = u.val
have h : ∃ w ∈ allAddresses d t, p w := by
obtain ⟨w,hw⟩ := wordToBall_surjective (PortTables.portGraph T.2) t v u
exact ⟨w,mem_allAddresses d t w,congrArg Subtype.val hw⟩
have hs := FixedSearch.eq_scan p a 0 (allAddresses d t) h
change _ = a (scanWitness p (allAddresses d t) h).val
rw [← hs]
unfold search
generalize allAddresses d t = xs
induction xs with
| nil => rfl
| cons w xs ih =>
dsimp only [FixedSearch.run]
have hp : decide ((word w.1.val w.2 (⟨T,v⟩ : State d)).2.val = u.val.val) = decide (p w) := by
simp only [p,word,wordToBall,Fin.val_inj]
rfl
exact if_congr (Iff.of_eq (congrArg (fun c : Bool => c=true) hp))
rfl ih
end AddressMachine
end VertexCover.Machine
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
|