Download data/lean/OAI/Computability/MeanPayoff/RawLabels.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 15.7 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/MeanPayoff/RawLabels.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/MeanPayoff/RawLabels.lean
-
curl -L -o RawLabels.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/MeanPayoff/RawLabels.lean
15.7 kB
| import OAI.Computability.MeanPayoff.RawMass | |
| namespace OAI | |
| namespace MeanPayoff.TreeDevice.Certified | |
| open BinaryData Code | |
| local infixl:80 " β«β " => Code.comp | |
| local infixr:70 " ββ " => Code.pair | |
| namespace Code | |
| @[simp] theorem any_ofFn {Ξ± : Type} [Encoding Ξ±] {n : β} (f : Code Ξ± Bool) (xs : Fin n β Ξ±) : | |
| any f (List.ofFn xs) = decide (β i, f (xs i)=true) := by | |
| simp only [any,comp_eval,filter_eval,empty_eval,not_eval] | |
| apply Bool.eq_iff_iff.mpr | |
| simp [List.filter_eq_nil_iff] | |
| end Code | |
| namespace DetRaw | |
| abbrev Input := (W Γ List W) Γ DetMass.Pair | |
| noncomputable def width : Code Input W := fst β«β fst | |
| noncomputable def lower : Code Input (List W) := fst β«β snd | |
| noncomputable def masses : Code Input DetMass.Pair := snd | |
| noncomputable def a : Code Input DetMass.Data := masses β«β fst | |
| noncomputable def b : Code Input DetMass.Data := masses β«β snd | |
| noncomputable def box : Code Input RawBox.Data := | |
| width ββ lower ββ ((width ββ lower) β«β Array.translate) | |
| noncomputable def small : Code Input Bool := (width ββ Word.constant 4096) β«β Word.lt | |
| noncomputable def base : Code Input Bool := masses β«β DetMass.base | |
| noncomputable def baseLabels : Code Input (List Bool) := b β«β DetMass.labels | |
| noncomputable def piece (k : β) : Code Input W := | |
| (width ββ const (List.replicate k ())) β«β Word.shiftRight | |
| noncomputable def amount (r : β€) : Code Input W := piece 12 β«β RawBudget.times r | |
| noncomputable def center : Code Input (List W) := ((piece 1) ββ lower) β«β Array.translate | |
| noncomputable def child (up : Bool) : Code (Input Γ List W) Input := | |
| ((fst β«β piece 7) ββ (((fst β«β piece 8 β«β Word.neg) ββ snd) β«β Array.translate)) ββ | |
| (if up then ((fst β«β a β«β DetMass.scale 4 3) ββ (fst β«β b)) | |
| else ((fst β«β a) ββ (fst β«β b β«β DetMass.scale 4 3))) | |
| noncomputable def provisional : Code (Input Γ List W) Input := | |
| ((fst β«β piece 1) ββ (((fst β«β piece 2 β«β Word.neg) ββ snd) β«β Array.translate)) ββ | |
| (fst β«β masses) | |
| noncomputable def continuation : Code (Input Γ List Bool) Input := | |
| (fst β«β fst) ββ | |
| ((((fst β«β a) ββ snd) β«β DetMass.reweight) ββ | |
| (((fst β«β b) ββ (snd β«β Array.complement)) β«β DetMass.reweight)) | |
| noncomputable def lowerCap : Code Input (List W) := (amount 1536 ββ lower) β«β Array.translate | |
| noncomputable def upperCap : Code Input (List W) := (amount 2560 ββ lower) β«β Array.translate | |
| noncomputable def minus : Code (Input Γ List W) (List W) := | |
| ((((fst β«β piece 12 β«β Word.neg) ββ snd) β«β Array.translate) ββ (fst β«β lowerCap)) β«β Array.max | |
| noncomputable def plus : Code (Input Γ List W) (List W) := | |
| ((((fst β«β piece 12) ββ snd) β«β Array.translate) ββ (fst β«β upperCap)) β«β Array.min | |
| abbrev Update := Input Γ List W Γ List Bool | |
| noncomputable def down : Code Update (List W) := | |
| ((snd β«β snd) ββ (snd β«β fst) ββ ((fst ββ (snd β«β fst)) β«β minus)) β«β Array.choose | |
| noncomputable def up : Code Update (List W) := | |
| ((snd β«β snd) ββ ((fst ββ (snd β«β fst)) β«β plus) ββ (snd β«β fst)) β«β Array.choose | |
| noncomputable def equalWord : Code (W Γ W) Bool := (Word.le ββ (swap β«β Word.le)) β«β Code.and | |
| noncomputable def different : Code (List W Γ List W) Bool := | |
| zip Array.zero Array.zero (equalWord β«β Code.not) β«β any Code.id | |
| noncomputable def changed (u : Bool) : Code Update Bool := | |
| ((if u then up else down) ββ (snd β«β fst)) β«β different | |
| noncomputable def lowMark : Code (Input Γ List W) (List Bool) := | |
| (snd ββ (((fst β«β amount 1920) ββ (fst β«β lower)) β«β Array.translate)) β«β Array.lt | |
| noncomputable def highMark : Code (Input Γ List W) (List Bool) := | |
| ((((fst β«β amount 2176) ββ (fst β«β lower)) β«β Array.translate) ββ snd) β«β Array.lt | |
| noncomputable def selectBool : Code (Bool Γ Bool Γ Bool) Bool := Code.branch fst (snd β«β fst) (snd β«β snd) | |
| noncomputable def chooseBool : Code (List Bool Γ List Bool Γ List Bool) (List Bool) := | |
| (fst ββ (snd β«β zip false false (fst ββ snd))) β«β zip false (false,false) selectBool | |
| abbrev Finish := Input Γ List W Γ List W Γ List Bool | |
| noncomputable def highFinish : Code Finish (List Bool) := | |
| (((fst ββ (snd β«β snd β«β fst)) β«β highMark) ββ | |
| ((snd β«β snd β«β snd) β«β map (const true)) ββ (snd β«β snd β«β snd)) β«β chooseBool | |
| noncomputable def finish : Code Finish (List Bool) := | |
| (((fst ββ (snd β«β fst)) β«β lowMark) ββ | |
| ((snd β«β snd β«β snd) β«β map (const false)) ββ highFinish) β«β chooseBool | |
| noncomputable def widthLabels : Code (Input Γ List W) (List Bool) := | |
| ((((fst β«β width) ββ (fst β«β lower β«β map Word.double)) β«β Array.translate) ββ | |
| (snd β«β map Word.double)) β«β Array.lt | |
| noncomputable def basicCount : Code Input Count := | |
| (const (List.replicate 4096 ()) ββ (lower β«β count)) β«β Counter.mul | |
| noncomputable def basic : Code (RawBasic.Arena Γ Input) (List Bool) := | |
| (snd ββ (((fst ββ (snd β«β box)) ββ (snd β«β basicCount)) β«β RawBasic.solve)) β«β widthLabels | |
| structure Rep {n : β} (A : Fin n β β€) (d : β) (a b : Fin n β β) (x : Input) : Prop where | |
| width : x.1.1.val=(2:β€)^d | |
| lower : VectorRep A x.1.2 | |
| a : DetMass.Rep a x.2.1 | |
| b : DetMass.Rep b x.2.2 | |
| variable {n : β} {A : Fin n β β€} {d : β} {a b : Fin n β β} {x : Input} | |
| @[simp] theorem equalWord_eq (p : W Γ W) : equalWord p=decide (p.1.val=p.2.val) := by | |
| change (if Word.le p then Word.le (p.2,p.1) else false) = _ | |
| rw [Word.le_eval,Word.le_eval] | |
| by_cases h : p.1.val β€ p.2.val | |
| Β· by_cases h' : p.2.val β€ p.1.val | |
| Β· simp [le_antisymm h h'] | |
| Β· have hn : p.1.val β p.2.val := fun he => h' (by rw [he]) | |
| simp [h,h',hn] | |
| Β· have hn : p.1.val β p.2.val := fun he => h (by rw [he]) | |
| simp [h,hn] | |
| theorem different_eq {v w : Fin n β β€} {vs ws : List W} | |
| (hv : VectorRep v vs) (hw : VectorRep w ws) : | |
| different (vs,ws)=decide (vβ w) := by | |
| obtain β¨as,rfl,haβ© := hv | |
| obtain β¨bs,rfl,hbβ© := hw | |
| simp only [different,Code.comp_eval,Code.zip_eval,Array.zip_ofFn,Code.any_ofFn,Code.id_eval, | |
| equalWord_eq,Code.not_eval,βdecide_not,ha,hb,decide_eq_true_eq] | |
| exact decide_eq_decide.mpr Function.ne_iff.symm | |
| theorem base_eq (h : Rep A d a b x) : base x=decide (β i, 1<a i*b i) := | |
| DetMass.base_eq h.a h.b | |
| theorem baseLabels_eq (h : Rep A d a b x) : baseLabels x=List.ofFn (Label.massLabels b) := | |
| DetMass.labels_eq h.b | |
| theorem small_eq (h : Rep A d a b x) : small x=decide (d<12) := by | |
| change Word.lt (x.1.1,_) = _ | |
| rw [Word.lt_eval] | |
| have hc : (Word.constant 4096 x).val = (4096:β€) := Word.constant_val 4096 x | |
| rw [hc,h.width] | |
| apply decide_eq_decide.mpr | |
| have he : (4096:β€)=(2:β€)^12 := by norm_num | |
| rw [he] | |
| exact pow_lt_pow_iff_rightβ (by norm_num) | |
| theorem piece_val (h : Rep A d a b x) (k : β) (hk : kβ€d) : | |
| (piece k x).val=(2:β€)^(d-k) := by | |
| change (Word.shiftRight (x.1.1,List.replicate k ())).val=_ | |
| rw [Word.shiftRight_val,List.length_replicate,h.width] | |
| rw [show d=(d-k)+k by omega,pow_add,Int.mul_ediv_cancel _ (by positivity : (2:β€)^kβ 0)] | |
| congr 1 | |
| omega | |
| theorem amount_val (h : Rep A d a b x) (hd : 12β€d) (c : β€) : | |
| (amount c x).val=c*(2:β€)^(d-12) := by | |
| simp only [amount,Code.comp_eval,RawBudget.times,Code.pair_eval,Code.id_eval,Word.mul_val,Word.constant_val] | |
| rw [piece_val h 12 hd,mul_comm] | |
| theorem box_rep (h : Rep A d a b x) : | |
| RawBox.Rep (show SolveBox n (2^d) from | |
| { a:=A, b:=shift A ((2:β€)^d), width:=2^d, | |
| ordered:=fun i => le_add_of_nonneg_right (by positivity), | |
| positive:=by positivity, bounded:=le_rfl, | |
| width_bound:=fun i => by simp [shift] }) (box x) := by | |
| refine β¨?_,h.lower,?_β© | |
| Β· exact_mod_cast h.width | |
| Β· convert Array.translate_rep h.lower x.1.1 using 1 <;> try rfl | |
| funext i | |
| simp only [shift,h.width,add_comm] | |
| theorem center_rep (h : Rep A d a b x) (hd : 12β€d) : | |
| VectorRep (Label.gridPivot A ((2:β€)^(d-12)) Label.gridCenter) (center x) := by | |
| rw [Label.gridPivot_center] | |
| convert Array.translate_rep h.lower (piece 1 x) using 1 <;> try rfl | |
| funext i | |
| rw [piece_val h 1 (by omega),(Label.dyadic_splits hd).2.2] | |
| ring | |
| theorem child_rep (h : Rep A d a b x) (hd : 12β€d) (u : Bool) | |
| {v : Fin n β β€} {vs : List W} (hv : VectorRep v vs) : | |
| Rep (fun i => v i-16*(2:β€)^(d-12)) (d-7) | |
| (if u then fun i => 4/3*a i else a) (if u then b else fun i => 4/3*b i) | |
| (child u (x,vs)) := by | |
| have hlow : VectorRep (fun i => v i-16*(2:β€)^(d-12)) | |
| (Array.translate (Word.neg (piece 8 x),vs)) := by | |
| convert Array.translate_rep hv (Word.neg (piece 8 x)) using 1 | |
| funext i | |
| rw [Word.neg_val,piece_val h 8 (by omega)] | |
| have he : (2:β€)^(d-8)=16*(2:β€)^(d-12) := by | |
| rw [show d-8=(d-12)+4 by omega,pow_add] | |
| norm_num | |
| ring | |
| rw [he] | |
| ring | |
| cases u | |
| Β· exact β¨piece_val h 7 (by omega),hlow,h.a,DetMass.scale_rep h.b (by norm_num) (by norm_num)β© | |
| Β· exact β¨piece_val h 7 (by omega),hlow,DetMass.scale_rep h.a (by norm_num) (by norm_num),h.bβ© | |
| theorem provisional_rep (h : Rep A d a b x) (hd : 12β€d) | |
| {v : Fin n β β€} {vs : List W} (hv : VectorRep v vs) : | |
| Rep (fun i => v i-1024*(2:β€)^(d-12)) (d-1) a b (provisional (x,vs)) := by | |
| refine β¨piece_val h 1 (by omega),?_,h.a,h.bβ© | |
| convert Array.translate_rep hv (Word.neg (piece 2 x)) using 1 <;> try rfl | |
| funext i | |
| rw [Word.neg_val,piece_val h 2 (by omega)] | |
| have he : (2:β€)^(d-2)=1024*(2:β€)^(d-12) := by | |
| rw [show d-2=(d-12)+10 by omega,pow_add] | |
| norm_num | |
| ring | |
| rw [he] | |
| ring | |
| theorem continuation_rep (h : Rep A d a b x) (ls : Fin n β Bool) : | |
| Rep A d (Label.reweight a ls) (Label.reweight b (fun i => !(ls i))) | |
| (continuation (x,List.ofFn ls)) := by | |
| refine β¨h.width,h.lower,DetMass.reweight_rep h.a ls,?_β© | |
| have hc : Array.complement (List.ofFn ls)=List.ofFn (fun i => !(ls i)) := by | |
| simp [Array.complement,Code.not,List.map_ofFn,Function.comp_def] | |
| change DetMass.Rep _ (DetMass.reweight (x.2.2,Array.complement (List.ofFn ls))) | |
| rw [hc] | |
| exact DetMass.reweight_rep h.b _ | |
| theorem minus_rep (h : Rep A d a b x) (hd : 12β€d) | |
| {v : Fin n β β€} {vs : List W} (hv : VectorRep v vs) : | |
| VectorRep (fun i => max (v i-(2:β€)^(d-12)) (A i+1536*(2:β€)^(d-12))) (minus (x,vs)) := by | |
| convert Array.zip_rep Word.max Max.max (fun _ _ => Word.max_val _ _) | |
| (Array.translate_rep hv (Word.neg (piece 12 x))) | |
| (Array.translate_rep h.lower (amount 1536 x)) using 1 <;> try rfl | |
| funext i | |
| rw [Word.neg_val,piece_val h 12 hd,amount_val h hd] | |
| congr 1 <;> ring | |
| theorem plus_rep (h : Rep A d a b x) (hd : 12β€d) | |
| {v : Fin n β β€} {vs : List W} (hv : VectorRep v vs) : | |
| VectorRep (fun i => min (v i+(2:β€)^(d-12)) (A i+2560*(2:β€)^(d-12))) (plus (x,vs)) := by | |
| convert Array.zip_rep Word.min Min.min (fun _ _ => Word.min_val _ _) | |
| (Array.translate_rep hv (piece 12 x)) | |
| (Array.translate_rep h.lower (amount 2560 x)) using 1 <;> try rfl | |
| funext i | |
| rw [piece_val h 12 hd,amount_val h hd] | |
| congr 1 <;> ring | |
| theorem choose_rep_bool {v w : Fin n β β€} {vs ws : List W} | |
| (hv : VectorRep v vs) (hw : VectorRep w ws) (ls : Fin n β Bool) : | |
| VectorRep (fun i => if ls i then v i else w i) (Array.choose (List.ofFn ls,vs,ws)) := by | |
| have hm : MaskRep (Finset.univ.filter (fun i => ls i=true)) (List.ofFn ls) := by | |
| simp [MaskRep] | |
| simpa using Array.choose_rep hm hv hw | |
| theorem down_rep (h : Rep A d a b x) (hd : 12β€d) | |
| {v : Fin n β β€} {vs : List W} (hv : VectorRep v vs) (ls : Fin n β Bool) : | |
| VectorRep (Label.downStep A ((2:β€)^(d-12)) v ls) (down (x,vs,List.ofFn ls)) := by | |
| convert choose_rep_bool hv (minus_rep h hd hv) ls using 1 <;> try rfl | |
| funext i | |
| simp only [Label.downStep,max_comm] | |
| theorem up_rep (h : Rep A d a b x) (hd : 12β€d) | |
| {v : Fin n β β€} {vs : List W} (hv : VectorRep v vs) (ls : Fin n β Bool) : | |
| VectorRep (Label.upStep A ((2:β€)^(d-12)) v ls) (up (x,vs,List.ofFn ls)) := by | |
| convert choose_rep_bool (plus_rep h hd hv) hv ls using 1 <;> try rfl | |
| funext i | |
| simp only [Label.upStep,min_comm] | |
| theorem lt_eq {v w : Fin n β β€} {vs ws : List W} | |
| (hv : VectorRep v vs) (hw : VectorRep w ws) : | |
| Array.lt (vs,ws)=List.ofFn (fun i => decide (v i<w i)) := by | |
| simpa [MaskRep] using Array.lt_rep hv hw | |
| theorem lowMark_eq (h : Rep A d a b x) (hd : 12β€d) | |
| {v : Fin n β β€} {vs : List W} (hv : VectorRep v vs) : | |
| lowMark (x,vs)=List.ofFn (fun i => decide (v i<A i+1920*(2:β€)^(d-12))) := by | |
| convert lt_eq hv (Array.translate_rep h.lower (amount 1920 x)) using 1 <;> try rfl | |
| congr 1 | |
| funext i | |
| rw [amount_val h hd,add_comm] | |
| theorem highMark_eq (h : Rep A d a b x) (hd : 12β€d) | |
| {v : Fin n β β€} {vs : List W} (hv : VectorRep v vs) : | |
| highMark (x,vs)=List.ofFn (fun i => decide (A i+2176*(2:β€)^(d-12)<v i)) := by | |
| convert lt_eq (Array.translate_rep h.lower (amount 2176 x)) hv using 1 <;> try rfl | |
| congr 1 | |
| funext i | |
| rw [amount_val h hd,add_comm] | |
| @[simp] theorem chooseBool_eq (m p q : Fin n β Bool) : | |
| chooseBool (List.ofFn m,List.ofFn p,List.ofFn q)= | |
| List.ofFn (fun i => if m i then p i else q i) := by | |
| change Zip.zip _ _ (List.ofFn _) (Zip.zip _ _ (List.ofFn _) (List.ofFn _)) = _ | |
| rw [Array.zip_ofFn,Array.zip_ofFn] | |
| rfl | |
| theorem finish_eq (h : Rep A d a b x) (hd : 12β€d) | |
| {vd vu : Fin n β β€} {ds us : List W} (hdv : VectorRep vd ds) (huv : VectorRep vu us) | |
| (ls : Fin n β Bool) : finish (x,ds,us,List.ofFn ls)= | |
| List.ofFn (Label.override A vd vu ((2:β€)^(d-12)) ls) := by | |
| change chooseBool (lowMark (x,ds),List.map (fun _ => false) (List.ofFn ls), | |
| chooseBool (highMark (x,us),List.map (fun _ => true) (List.ofFn ls),List.ofFn ls)) = _ | |
| rw [lowMark_eq h hd hdv,highMark_eq h hd huv,List.map_ofFn,List.map_ofFn,chooseBool_eq,chooseBool_eq] | |
| congr 1 | |
| funext i | |
| simp only [decide_eq_true_eq,Function.comp_apply,Label.override] | |
| theorem widthLabels_eq (h : Rep A d a b x) | |
| {v : Fin n β β€} {vs : List W} (hv : VectorRep v vs) : | |
| widthLabels (x,vs)=List.ofFn (Label.widthLabels A v ((2:β€)^d)) := by | |
| convert lt_eq (Array.translate_rep (Array.map_rep Word.double (2*Β·) Word.double_val h.lower) x.1.1) | |
| (Array.map_rep Word.double (2*Β·) Word.double_val hv) using 1 <;> try rfl | |
| congr 1 | |
| funext i | |
| simp only [Label.widthLabels,h.width,add_comm] | |
| theorem basic_eq (G : Game) {A : Fin G.n β β€} {d : β} {a b : Fin G.n β β} {x : Input} | |
| (h : Rep A d a b x) (hd : d<12) (w : Fin G.m β W) | |
| (hw : β e, (w e).val=transformed G e) : | |
| basic (Graph.codeVertices G w,x)=List.ofFn (Label.widthLabels A | |
| (MeanPayoff.basic G A (shift A ((2:β€)^d)) (fun i => by | |
| dsimp [shift]; exact le_add_of_nonneg_right (by positivity))).1 ((2:β€)^d)) := by | |
| apply widthLabels_eq h | |
| apply RawBasic.solve_rep G (box_rep h) w hw | |
| have hn : x.1.2.length=G.n := by obtain β¨ws,he,_β© := h.lower; simp [he] | |
| change G.n*2^d β€ (Counter.mul (List.replicate 4096 (), Code.count x.1.2)).length | |
| rw [Counter.mul_length] | |
| simp only [List.length_replicate,Code.count,Code.map_eval,List.length_map,hn] | |
| have hd' : 2^d β€ 4096 := by | |
| have hh := Nat.pow_le_pow_right (by omega : 1β€2) (show dβ€12 by omega) | |
| norm_num at hh β’ | |
| exact hh | |
| nlinarith | |
| end DetRaw | |
| end MeanPayoff.TreeDevice.Certified | |
| end OAI | |