Download data/lean/OAI/Computability/VertexCover/Machines/Generic.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 4.93 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/VertexCover/Machines/Generic.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/VertexCover/Machines/Generic.lean
-
curl -L -o Generic.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/VertexCover/Machines/Generic.lean
4.93 kB
| import Mathlib | |
| import OAI.Computability.VertexCover.Machines.Serialization | |
| import OAI.Computability.VertexCover.Machines.TableBase | |
| import OAI.Computability.VertexCover.Machines.FixedOps | |
| 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 | |
| open UniqueGames.Foundations.PCP | |
| noncomputable def Poly.rawBooleans : Poly (listBits boolBits) id (id : List Bool β List Bool) := by | |
| let bit : Poly boolBits id (fun b => [b]) := | |
| (Poly.identity boolBits).encodeCongr id (fun _ => rfl) (fun _ => rfl) | |
| exact ((Poly.listMap boolBits id false [] bit).comp Poly.rawFlatten).congr (fun xs => by induction xs with | |
| | nil => rfl | |
| | cons b bs ih => simpa only [Function.comp_apply,id_eq,List.map_cons,List.flatten_cons,List.singleton_append] using congrArg (List.cons b) ih) | |
| noncomputable def Poly.vectorOfFn {Ξ± : Type} (ea : Ξ± β List Bool) (n : β) | |
| (f : Ξ± β Fin n β Bool) (cf : β i, Poly ea boolBits (fun a => f a i)) : | |
| Poly ea (fun v : Vector Bool n => v.toList) (fun a => Vector.ofFn (f a)) := by | |
| let c := (Poly.fixedList ea boolBits f cf (List.ofFn id)).comp Poly.rawBooleans | |
| exact c.encodeCongr id (fun _ => rfl) (fun a => by | |
| simp only [Function.comp_apply,id_eq,List.map_ofFn,Function.comp_def] | |
| apply List.ext_getElem | |
| Β· simp | |
| Β· intro i hβ hβ; simp) | |
| namespace GenericMachine | |
| open GenericGraphTables | |
| abbrev Row (q : β) := (β Γ β) Γ RelationTable q | |
| abbrev Data (q : β) := β Γ List (Row q) | |
| def relationCode {q : β} (r : RelationTable q) : List Bool := r.toList | |
| def rowCode {q : β} : Row q β List Bool := prodBits (prodBits natBits natBits) relationCode | |
| def dataCode {q : β} : Data q β List Bool := prodBits natBits (listBits rowCode) | |
| def rowData {q n m : β} (r : DartRow q n m) : Row q := ((r.tail.val,r.reverseIndex.val),r.relation) | |
| def erase {q : β} (T : Table q) : Data q := (T.vertices,T.rows.toList.map rowData) | |
| def code {q : β} (T : Table q) : List Bool := dataCode (erase T) | |
| def relationDefault (q : β) : RelationTable q := Vector.replicate (q*q) false | |
| def rowDefault (q : β) : Row q := ((0,0),relationDefault q) | |
| noncomputable def verticesPoly {q : β} : Poly (code (q := q)) natBits Table.vertices := | |
| (Poly.fst natBits (listBits rowCode)).encodeCongr erase (fun _ => rfl) (fun _ => rfl) | |
| noncomputable def rowsPoly {q : β} : Poly (code (q := q)) (listBits rowCode) (fun T => T.rows.toList.map rowData) := | |
| (Poly.snd natBits (listBits rowCode)).encodeCongr erase (fun _ => rfl) (fun _ => rfl) | |
| noncomputable def dartsPoly {q : β} : Poly (code (q := q)) natBits Table.darts := | |
| ((rowsPoly (q := q)).comp (Poly.listLength rowCode (rowDefault q))).congr (fun T => by simp) | |
| noncomputable def lookupPoly {q : β} : Poly (prodBits (code (q := q)) natBits) rowCode | |
| (fun p : Table q Γ β => (erase p.1).2.getD p.2 (rowDefault q)) := by | |
| let rows := (Poly.fst code natBits).comp (rowsPoly (q := q)) | |
| let idx := Poly.snd (code (q := q)) natBits | |
| exact ((idx.pair rows).comp (Poly.listGetD rowCode (rowDefault q))).congr (fun _ => by | |
| simp only [Function.comp_apply,List.headD_eq_head?_getD,List.head?_drop,List.getD_eq_getElem?_getD] | |
| rfl) | |
| theorem lookup_valid {q : β} (T : Table q) (i : Fin T.darts) : | |
| (erase T).2.getD i.val (rowDefault q) = rowData T.rows[i] := by | |
| simp only [erase,List.getD_eq_getElem?_getD,List.getElem?_map] | |
| rw [List.getElem?_eq_getElem (by simp)] | |
| rfl | |
| theorem materialize_source {Ξ± : Type} {q : β} (Q : Ξ± β Table q) (r : Ξ± Γ β β Row q) | |
| (hr : β a (i : Fin (Q a).darts), r (a,i.val) = rowData (Q a).rows[i]) (a : Ξ±) : | |
| ((Q a).vertices,(List.range (Q a).darts).map (fun i => r (a,i))) = erase (Q a) := by | |
| apply Prod.ext | |
| Β· rfl | |
| apply List.ext_getElem | |
| Β· simp [erase] | |
| Β· intro i hβ hβ | |
| simp only [erase,List.getElem_map,List.getElem_range,Vector.getElem_toList] | |
| exact hr a β¨i,by simpa using hββ© | |
| noncomputable def materializePoly {Ξ± : Type} (ea : Ξ± β List Bool) (aβ : Ξ±) {q : β} | |
| (Q : Ξ± β Table q) {r : Ξ± Γ β β Row q} | |
| (cn : Poly ea natBits (fun a => (Q a).vertices)) | |
| (cm : Poly ea natBits (fun a => (Q a).darts)) | |
| (cr : Poly (prodBits ea natBits) rowCode r) | |
| (hr : β a (i : Fin (Q a).darts), r (a,i.val) = rowData (Q a).rows[i]) : | |
| Poly ea code Q := by | |
| let rows := Poly.tabulate ea rowCode aβ (rowDefault q) cm cr | |
| exact (cn.pair rows).encodeCongr id (fun _ => rfl) (fun a => by | |
| exact congrArg dataCode (materialize_source Q r hr a)) | |
| end GenericMachine | |
| 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 | |