Download data/lean/OAI/Computability/MinUncut/Graphs/CanonicalSamplerGraph.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 10.4 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/MinUncut/Graphs/CanonicalSamplerGraph.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/MinUncut/Graphs/CanonicalSamplerGraph.lean
-
curl -L -o CanonicalSamplerGraph.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/MinUncut/Graphs/CanonicalSamplerGraph.lean
10.4 kB
| import Mathlib | |
| import OAI.Computability.MinUncut.Estimates.LiteralLocalTemplates | |
| import OAI.Computability.MinUncut.Estimates.ReversePrefixProgram | |
| import OAI.Computability.MinUncut.Encoding.RawGraphEncoding | |
| namespace OAI | |
| section | |
| open scoped BigOperators | |
| namespace MinUncut.PathRealization | |
| open MinUncut.FiniteProof MinUncutGames.Foundations.Hastad.SourceOccurrences | |
| lemma listFailure_map {V W : Type*} (f : V β W) (ds : List (Demand V)) (s : W β Bool) : | |
| listFailure (ds.map (Demand.map f)) s=listFailure ds (s β f) := by | |
| simp only [listFailure,List.map_map,Function.comp_def,failure_map] | |
| def listOutput {N : β} (ds : List (Demand (Fin N))) (k : β) (hk : 1β€k) : Output := | |
| canonicalOutput (fun i : Fin ds.length => ds[i]) k hk | |
| lemma listOutput_yes {N : β} (ds : List (Demand (Fin N))) (k : β) (hk : 1β€k) | |
| (s : Fin N β Bool) (hs : listFailure ds sβ€k) : (listOutput ds k hk).optβ€k := | |
| canonicalOutput_yes _ k hk s (by simpa only [β listFailure_eq] using hs) | |
| lemma listOutput_no {N : β} (ds : List (Demand (Fin N))) (k : β) (hk : 1β€k) | |
| (K : β) (hs : β s, K*k<listFailure ds s) : K*k<(listOutput ds k hk).opt := | |
| canonicalOutput_no _ k hk K (by simpa only [β listFailure_eq] using hs) | |
| lemma listFailure_weight {E V : Type} [Fintype E] (D : β) (w : E β β) | |
| (hw : βe,0β€w e) (hd : βe,(w e).denβ£D) (d : E β Demand V) | |
| (enc : Encoding E) (s : V β Bool) : | |
| (listFailure (demandList D w d enc) s:β)=(D:β)*βe,(w e:β)*(failure (d e) s:β) := by | |
| rw [listFailure_demandList,β expanded_failure] | |
| exact expanded_weight D w hw hd d s | |
| lemma listFailure_extend {V W : Type*} (f : V β W) (hf : Function.Injective f) | |
| (ds : List (Demand V)) (s : V β Bool) : | |
| listFailure (ds.map (Demand.map f)) (extendAssignment f s)=listFailure ds s := by | |
| simp only [listFailure,List.map_map,Function.comp_def,mapDemand_extend f hf] | |
| end MinUncut.PathRealization | |
| noncomputable section | |
| namespace MinUncut.Outer.Parameters | |
| open MinUncut.Inner MinUncut.FiniteProof MinUncut.PathRealization | |
| attribute [local instance] Classical.propDecidable | |
| variable {N s J : β} [Nonempty (Fin s)] | |
| def canonicalDemands (P : Parameters J) (eqs : Fin s β Equation (Fin N)) : | |
| List (Demand (Fin (paddedVariableEncoding N P.o.t).size)) := | |
| (demandList (P.denominator (Fin s)) (P.weight eqs) (P.demand eqs) | |
| (SampleEnumeration.all eqs P.o.k P.d.m P.d.n P.grid).encoding).map (Demand.map variableCode) | |
| def canonicalGraph (P : Parameters J) (eqs : Fin s β Equation (Fin N)) : Output := | |
| listOutput (P.canonicalDemands eqs) (5*P.denominator (Fin s)) | |
| (threshold_positive P.denominator_pos) | |
| lemma canonicalGraph_failure (P : Parameters J) (eqs : Fin s β Equation (Fin N)) | |
| (y : Fin (paddedVariableEncoding N P.o.t).size β Bool) : | |
| (listFailure (P.canonicalDemands eqs) y:β)= | |
| (P.denominator (Fin s):β)*βe,(P.weight eqs e:β)* | |
| (failure (P.demand eqs e) (y β variableCode):β) := by | |
| unfold canonicalDemands | |
| rw [listFailure_map] | |
| exact listFailure_weight _ _ (P.weight_nonneg eqs) (P.weight_den eqs) _ _ _ | |
| lemma canonicalGraph_yes (P : Parameters J) (eqs : Fin s β Equation (Fin N)) | |
| (y : FamilyVariable (Fin N) (Fin P.o.t) β Bool) | |
| (hy : βe,(P.weight eqs e:β)*(failure (P.demand eqs e) y:β)β€9/2) : | |
| (P.canonicalGraph eqs).optβ€(P.canonicalGraph eqs).threshold := by | |
| apply listOutput_yes _ _ _ (extendAssignment variableCode y) | |
| have hh := listFailure_weight (P.denominator (Fin s)) (P.weight eqs) | |
| (P.weight_nonneg eqs) (P.weight_den eqs) (P.demand eqs) | |
| (SampleEnumeration.all eqs P.o.k P.d.m P.d.n P.grid).encoding y | |
| have he : listFailure (P.canonicalDemands eqs) (extendAssignment variableCode y)= | |
| listFailure (demandList (P.denominator (Fin s)) (P.weight eqs) (P.demand eqs) | |
| (SampleEnumeration.all eqs P.o.k P.d.m P.d.n P.grid).encoding) y := | |
| listFailure_extend variableCode variableCode_injective _ y | |
| have hD : (0:β)<P.denominator (Fin s) := by exact_mod_cast P.denominator_pos | |
| have hs : (listFailure (P.canonicalDemands eqs) (extendAssignment variableCode y):β)β€ | |
| 5*P.denominator (Fin s) := by | |
| rw [he,hh] | |
| calc | |
| _ β€ (P.denominator (Fin s):β)*5 := | |
| mul_le_mul_of_nonneg_left (hy.trans (by norm_num)) hD.le | |
| _ = _ := mul_comm _ _ | |
| exact_mod_cast hs | |
| lemma canonicalGraph_no {K : β} (hK : 2β€K) (P : Parameters J) | |
| (eqs : Fin s β Equation (Fin N)) | |
| (hy : β y, 8*(K:β)-1/2 < βe,(P.weight eqs e:β)*(failure (P.demand eqs e) y:β)) : | |
| K*(P.canonicalGraph eqs).threshold<(P.canonicalGraph eqs).opt := by | |
| apply listOutput_no | |
| intro y | |
| have hh := P.canonicalGraph_failure eqs y | |
| have hK' : (2:β)β€K := by exact_mod_cast hK | |
| have hD : (0:β)<P.denominator (Fin s) := by exact_mod_cast P.denominator_pos | |
| have hg : 5*(K:β)<βe,(P.weight eqs e:β)*(failure (P.demand eqs e) (y β variableCode):β) := | |
| lt_trans (by linarith) (hy (y β variableCode)) | |
| have hs : (K:β)*(5*P.denominator (Fin s))< | |
| (listFailure (P.canonicalDemands eqs) y:β) := by | |
| rw [hh] | |
| have h := mul_lt_mul_of_pos_left hg hD | |
| simpa only [mul_assoc,mul_comm,mul_left_comm] using h | |
| exact_mod_cast hs | |
| end MinUncut.Outer.Parameters | |
| end | |
| end | |
| namespace MinUncut.Costed.GraphRegisters | |
| open MinUncut.PathRealization | |
| lemma finRange_vals (V : β) : (List.finRange V).map Fin.val=List.range V := by | |
| apply List.ext_getElem | |
| Β· simp | |
| Β· intro i hi hj | |
| simp | |
| def canonicalTable {N : β} (ds : List (Demand (Fin N))) : List Bool := | |
| (List.finRange (N+ds.length*3)).flatMap fun u=> | |
| (List.finRange (N+ds.length*3)).map fun v=>canonicalAdjacent (fun d:Fin ds.length=>ds[d]) u v | |
| lemma rawRow_pack {N : β} (ds : List (Demand (Fin N))) (u : Fin (N+ds.length*3)) : | |
| rawRow N ds.length (packDemands ds) u.val (N+ds.length*3)= | |
| ((List.finRange (N+ds.length*3)).map fun v=> | |
| canonicalAdjacent (fun d:Fin ds.length=>ds[d]) u v).map Bool.toNat := by | |
| rw [rawRow,βfinRange_vals,List.map_map,List.map_map] | |
| congr 1 | |
| funext v | |
| exact rawCell_canonical ds u v | |
| lemma rawTable_pack {N : β} (ds : List (Demand (Fin N))) : | |
| rawTable N ds.length (packDemands ds) (N+ds.length*3) (N+ds.length*3)= | |
| (canonicalTable ds).map Bool.toNat := by | |
| rw [rawTable,βfinRange_vals,List.flatMap_map,canonicalTable,List.map_flatMap] | |
| congr 1 | |
| funext u | |
| exact rawRow_pack ds u | |
| lemma listOutput_bits {N : β} (ds : List (Demand (Fin N))) (k : β) (hk : 1β€k) : | |
| (listOutput ds k hk).bits=MinUncutGames.BinaryEncoding.nameBits (N+ds.length*3)++ | |
| canonicalTable ds++MinUncutGames.BinaryEncoding.nameBits k := rfl | |
| end MinUncut.Costed.GraphRegisters | |
| noncomputable section | |
| namespace MinUncut.Costed.SourceWords | |
| open MinUncut.Inner MinUncut.Outer MinUncut.Outer.LocalTemplate | |
| open MinUncut.PathRealization MinUncutGames.Reduction MinUncut.SourceBridge | |
| open MinUncutGames.Foundations.Hastad.SourceOccurrences | |
| variable {t k m n : β} {g : MinUncut.FiniteGaussian.GridData} | |
| def demandExpressions (Ο Ξ· : β) (e : Index (Fin t) k m n g) : List AExpr := | |
| let T := indexQuery Ο Ξ· e | |
| [leftExpr T e.2.2.1,rightExpr T e.2.2.1,signExpr T e.2.2.1] | |
| def localExpressions (E : Enumeration (Index (Fin t) k m n g)) (a : β) | |
| (b : MinUncut.Outer.Test β β) (Ο Ξ· : β) : List AExpr := | |
| E.values.flatMap (fun e=>(List.replicate (repetitions a b e) (demandExpressions Ο Ξ· e)).flatten) | |
| def tupleDemands (input : SourceEncoding.Input) (u : Fin t β Fin input.equations.length) | |
| (E : Enumeration (Index (Fin t) k m n g)) (a : β) (b : MinUncut.Outer.Test β β) | |
| (Ο Ξ· : β) : List (Demand (Fin (paddedVariableEncoding input.Β«variablesΒ» t).size)) := | |
| E.values.flatMap (fun e=>List.replicate (repetitions a b e) | |
| ((allDemand (equations input) g Ο Ξ· (occurrence (equations input) (u,e))).map variableCode)) | |
| lemma demandExpressions_eval (input : SourceEncoding.Input) | |
| (u : Fin t β Fin input.equations.length) (e : Index (Fin t) k m n g) (Ο Ξ· : β) (rest : List β) : | |
| (demandExpressions Ο Ξ· e).map (fun x=>x.eval (inputTuple input u++rest))= | |
| GraphRegisters.packDemand ((allDemand (equations input) g Ο Ξ· | |
| (occurrence (equations input) (u,e))).map variableCode) := by | |
| change queryWords (indexQuery Ο Ξ· e) e.2.2.1 (inputTuple input u++rest)=_ | |
| rw [queryWords_append,queryWords_eq,occurrence_demand] | |
| rfl | |
| lemma localExpressions_eval (input : SourceEncoding.Input) | |
| (u : Fin t β Fin input.equations.length) (E : Enumeration (Index (Fin t) k m n g)) | |
| (a : β) (b : MinUncut.Outer.Test β β) (Ο Ξ· : β) (rest : List β) : | |
| (localExpressions E a b Ο Ξ·).map (fun x=>x.eval (inputTuple input u++rest))= | |
| GraphRegisters.packDemands (tupleDemands input u E a b Ο Ξ·) := by | |
| simp only [localExpressions,tupleDemands,GraphRegisters.packDemands,List.map_flatMap, | |
| List.map_flatten,List.flatMap_assoc] | |
| apply congrArg (List.flatMap Β· E.values) | |
| funext e | |
| simp only [List.map_replicate, demandExpressions_eval,List.flatMap_replicate] | |
| def tupleList (input : SourceEncoding.Input) (t : β) : List (Fin t β Fin input.equations.length) := | |
| (List.finRange (input.equations.length^t)).map finFunctionFinEquiv.symm | |
| def generatedDemands (input : SourceEncoding.Input) (E : Enumeration (Index (Fin t) k m n g)) | |
| (a : β) (b : MinUncut.Outer.Test β β) (Ο Ξ· : β) : | |
| List (Demand (Fin (paddedVariableEncoding input.Β«variablesΒ» t).size)) := | |
| (tupleList input t).flatMap (fun u=>tupleDemands input u E a b Ο Ξ·) | |
| lemma emitted_demands (input : SourceEncoding.Input) (E : Enumeration (Index (Fin t) k m n g)) | |
| (a : β) (b : MinUncut.Outer.Test β β) (Ο Ξ· : β) (rest : List β) : | |
| Blocks.emitted (localExpressions E a b Ο Ξ·) (input.equations.length^t) | |
| (SourceEncoding.inputWords input++rest)= | |
| GraphRegisters.packDemands (generatedDemands input E a b Ο Ξ·) := by | |
| rw [Blocks.emitted,βGraphRegisters.finRange_vals] | |
| simp only [generatedDemands,tupleList,List.flatMap_map,GraphRegisters.packDemands, | |
| List.flatMap_assoc] | |
| apply congrArg (List.flatMap Β· (List.finRange (input.equations.length^t))) | |
| funext z | |
| have h := localExpressions_eval input (finFunctionFinEquiv.symm z) E a b Ο Ξ· rest | |
| simpa only [Blocks.block,inputTuple,Equiv.apply_symm_apply,List.cons_append,GraphRegisters.packDemands] using h | |
| end MinUncut.Costed.SourceWords | |
| end | |
| end OAI | |