Download data/lean/OAI/Computability/RandomMean/Control.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 23.1 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/RandomMean/Control.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/RandomMean/Control.lean
-
curl -L -o Control.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/RandomMean/Control.lean
23.1 kB
| import OAI.Computability.RandomMean.Orientation | |
| namespace OAI | |
| section | |
| namespace MeanPayoff.TreeDevice.Certified | |
| open BinaryData Code | |
| local infixl:80 " β«β " => Code.comp | |
| local infixr:70 " ββ " => Code.pair | |
| namespace Code | |
| variable {Ξ± Ξ² : Type} [Encoding Ξ±] [Encoding Ξ²] | |
| end Code | |
| namespace RawControl | |
| abbrev Orient := RawOrientation.Data | |
| abbrev Tuple := RawBudget.DataΓRawBox.DataΓCountΓList WΓList WΓList (List W)ΓOrientΓList Orient | |
| structure Pack where | |
| p : RawBudget.Data | |
| b : RawBox.Data | |
| t : Count | |
| q : List W | |
| r : List W | |
| vs : List (List W) | |
| o : Orient | |
| os : List Orient | |
| def Pack.tuple (z : Pack) : Tuple := (z.p,z.b,z.t,z.q,z.r,z.vs,z.o,z.os) | |
| instance : Encoding Pack := β¨fun z => encode z.tupleβ© | |
| def zeroBudget : RawBudget.Data := ((Array.zero,Array.zero),(Array.zero,Array.zero),[],[]) | |
| def zeroBox : RawBox.Data := (Array.zero,[],[]) | |
| def Pack.zero : Pack := β¨zeroBudget,zeroBox,[],[],[],[],(false,[]),[]β© | |
| noncomputable def proj {Ξ± : Type} [Encoding Ξ±] (f : Code Tuple Ξ±) : Code Pack Ξ± := | |
| f.recode Pack.tuple (fun z => f z.tuple) (fun _ => rfl) (fun _ => rfl) | |
| noncomputable def p : Code Pack RawBudget.Data := proj fst | |
| noncomputable def b : Code Pack RawBox.Data := proj (snd β«β fst) | |
| noncomputable def t : Code Pack Count := proj (snd β«β snd β«β fst) | |
| noncomputable def q : Code Pack (List W) := proj (snd β«β snd β«β snd β«β fst) | |
| noncomputable def r : Code Pack (List W) := proj (snd β«β snd β«β snd β«β snd β«β fst) | |
| noncomputable def vs : Code Pack (List (List W)) := proj (snd β«β snd β«β snd β«β snd β«β snd β«β fst) | |
| noncomputable def o : Code Pack Orient := proj (snd β«β snd β«β snd β«β snd β«β snd β«β snd β«β fst) | |
| noncomputable def os : Code Pack (List Orient) := proj (snd β«β snd β«β snd β«β snd β«β snd β«β snd β«β snd) | |
| @[simp] theorem p_eval (z : Pack) : p z=z.p := rfl | |
| @[simp] theorem b_eval (z : Pack) : b z=z.b := rfl | |
| @[simp] theorem t_eval (z : Pack) : t z=z.t := rfl | |
| @[simp] theorem q_eval (z : Pack) : q z=z.q := rfl | |
| @[simp] theorem r_eval (z : Pack) : r z=z.r := rfl | |
| @[simp] theorem vs_eval (z : Pack) : vs z=z.vs := rfl | |
| @[simp] theorem o_eval (z : Pack) : o z=z.o := rfl | |
| @[simp] theorem os_eval (z : Pack) : os z=z.os := rfl | |
| noncomputable def pack {Ξ± : Type} [Encoding Ξ±] | |
| (p : Code Ξ± RawBudget.Data := const zeroBudget) | |
| (b : Code Ξ± RawBox.Data := const zeroBox) | |
| (t : Code Ξ± Count := const []) | |
| (q r : Code Ξ± (List W) := const []) | |
| (vs : Code Ξ± (List (List W)) := const []) | |
| (o : Code Ξ± Orient := const (false,[])) | |
| (os : Code Ξ± (List Orient) := const []) : Code Ξ± Pack := | |
| (p ββ b ββ t ββ q ββ r ββ vs ββ o ββ os).recode _root_.id | |
| (fun x => β¨p x,b x,t x,q x,r x,vs x,o x,os xβ©) (fun _ => rfl) (fun _ => rfl) | |
| @[simp] theorem pack_eval {Ξ± : Type} [Encoding Ξ±] | |
| (p : Code Ξ± RawBudget.Data) (b : Code Ξ± RawBox.Data) (t : Code Ξ± Count) | |
| (q r : Code Ξ± (List W)) (vs : Code Ξ± (List (List W))) (o : Code Ξ± Orient) (os : Code Ξ± (List Orient)) (x : Ξ±) : | |
| pack p b t q r vs o os x=β¨p x,b x,t x,q x,r x,vs x,o x,os xβ© := rfl | |
| abbrev Cell := CountΓPack | |
| abbrev State := CellΓList Cell | |
| abbrev Env := RawBasic.ArenaΓCountΓCountΓCountΓCount | |
| noncomputable def arena : Code Env RawBasic.Arena := fst | |
| noncomputable def exponent : Code Env Count := snd β«β fst | |
| noncomputable def samples : Code Env Count := snd β«β snd β«β fst | |
| noncomputable def trials : Code Env Count := snd β«β snd β«β snd β«β fst | |
| noncomputable def basicSteps : Code Env Count := snd β«β snd β«β snd β«β snd | |
| abbrev Input := EnvΓCountΓState | |
| noncomputable def env : Code Input Env := fst | |
| noncomputable def random : Code Input Count := snd β«β fst | |
| noncomputable def state : Code Input State := snd β«β snd | |
| noncomputable def current : Code Input Pack := state β«β fst β«β snd | |
| noncomputable def stack : Code Input (List Cell) := state β«β snd | |
| noncomputable def caller : Code Input Pack := stack β«β head ([],Pack.zero) β«β snd | |
| noncomputable def rest : Code Input (List Cell) := stack β«β tail | |
| noncomputable def makeCell {Ξ± : Type} [Encoding Ξ±] (tag : β) (c : Code Ξ± Pack) : Code Ξ± Cell := | |
| const (List.replicate tag ()) ββ c | |
| noncomputable def call {Ξ± : Type} [Encoding Ξ±] (tag : β) (c : Code Ξ± Pack) (k : Code Ξ± (List Cell)) : Code Ξ± State := | |
| makeCell tag c ββ k | |
| noncomputable def ret {Ξ± : Type} [Encoding Ξ±] (c : Code Ξ± Pack) (k : Code Ξ± (List Cell)) : Code Ξ± State := call 10 c k | |
| noncomputable def push {Ξ± : Type} [Encoding Ξ±] (tag : β) (c : Code Ξ± Pack) (k : Code Ξ± (List Cell)) : Code Ξ± (List Cell) := | |
| (makeCell tag c ββ k) β«β cons | |
| noncomputable def save (tag : β) : Code Input (List Cell) := push tag current stack | |
| noncomputable def smallWidth (x : Code Input RawBox.Data) : Code Input Bool := | |
| ((x β«β RawBox.width) ββ (env β«β samples β«β Counter.word β«β RawBudget.times 128)) β«β Word.le | |
| noncomputable def basic (x : Code Input RawBox.Data) : Code Input (List W) := | |
| (((env β«β arena) ββ x) ββ (env β«β basicSteps)) β«β RawBasic.solve | |
| noncomputable def narrow (x : Code Input RawBox.Data) (v : Code Input (List W)) : Code Input RawBox.Data := | |
| (((x ββ (((env β«β exponent) ββ const (List.replicate 5 ())) β«β Counter.add)) β«β RawBox.dividedWidth) ββ v) β«β RawBox.centered | |
| noncomputable def wide (x : Code Input RawBox.Data) (v : Code Input (List W)) : Code Input RawBox.Data := | |
| (((x ββ const (List.replicate 3 ())) β«β RawBox.dividedWidth) ββ v) β«β RawBox.centered | |
| noncomputable def delta (x : Code Input RawBox.Data) : Code Input W := | |
| (x ββ (((env β«β exponent) ββ const (List.replicate 2 ())) β«β Counter.add)) β«β RawBox.dividedWidth | |
| noncomputable def capWidth (x : Code Input RawBox.Data) : Code Input W := | |
| ((x β«β RawBox.width) ββ delta x) β«β Word.sub | |
| noncomputable def solveCase : Code Input State := | |
| Code.branch (current β«β p β«β RawBudget.small) | |
| (ret (pack (q:=((current β«β p) ββ (current β«β b)) β«β RawBox.smallVector)) stack) | |
| (Code.branch (smallWidth (current β«β b)) | |
| (ret (pack (q:=basic (current β«β b))) stack) | |
| (call 8 (pack (current β«β p) (current β«β b)) (save 15))) | |
| noncomputable def askCase : Code Input State := | |
| call 2 (pack (current β«β p) (current β«β b) (env β«β trials)) (save 2) | |
| noncomputable def trialsCase : Code Input State := | |
| Code.branch (current β«β t β«β empty) | |
| (ret (pack (vs:=const [])) stack) | |
| (call 0 current (push 0 (pack (current β«β p) (current β«β b) (current β«β t β«β tail)) stack)) | |
| noncomputable def updateCase : Code Input State := | |
| call 1 (pack (current β«β p β«β RawBudget.reduceK) (narrow (current β«β b) (current β«β q))) (save 3) | |
| noncomputable def centersCase : Code Input State := | |
| Code.branch (current β«β t β«β empty) | |
| (ret (pack (vs:=((current β«β q) ββ const []) β«β cons)) stack) | |
| (call 3 current (push 5 (pack (current β«β p) (current β«β b) (current β«β t β«β tail) (current β«β q)) stack)) | |
| noncomputable def orientCase : Code Input State := | |
| Code.branch (smallWidth (current β«β b)) | |
| (ret (pack (o:=((current β«β p) ββ (current β«β b) ββ basic (current β«β b)) β«β RawOrientation.base)) stack) | |
| (call 4 (pack (current β«β p) (current β«β b) (env β«β samples) (current β«β b β«β RawBox.midpoint)) (save 6)) | |
| noncomputable def orientTrialsCase : Code Input State := | |
| Code.branch (current β«β t β«β empty) (ret (pack (os:=const [])) stack) | |
| (call 5 current (push 8 (pack (current β«β p) (current β«β b) (current β«β t β«β tail)) stack)) | |
| noncomputable def orientPlusCase : Code Input State := | |
| call 6 (pack (current β«β p) (current β«β b) (env β«β trials)) (save 10) | |
| noncomputable def tightenCase : Code Input State := | |
| call 1 (pack (current β«β p β«β RawBudget.reduceK) (current β«β b)) (save 11) | |
| noncomputable def reweightCase : Code Input State := | |
| Code.branch (current β«β o β«β snd β«β empty) (ret (pack (vs:=const [])) stack) | |
| (call 1 (pack | |
| (Code.branch (current β«β o β«β fst) | |
| (((current β«β p) ββ (current β«β o β«β snd β«β head [])) β«β RawBudget.reweightM) | |
| (((current β«β p) ββ (current β«β o β«β snd β«β head [])) β«β RawBudget.reweightK)) | |
| (current β«β b)) | |
| (push 17 (pack (current β«β p) (current β«β b) | |
| (o:=(current β«β o β«β fst) ββ (current β«β o β«β snd β«β tail))) stack)) | |
| end RawControl | |
| end MeanPayoff.TreeDevice.Certified | |
| end | |
| section | |
| namespace MeanPayoff.TreeDevice.Certified | |
| open BinaryData Code | |
| local infixl:80 " β«β " => Code.comp | |
| local infixr:70 " ββ " => Code.pair | |
| namespace Array | |
| theorem fold_select_bound (f : Code (WΓW) W) (hf : β z, f z=z.1 β¨ f z=z.2) | |
| {N : β} {xs : List W} {xss : List (List W)} (h : Bounded xs N) | |
| (hs : β ysβxss, Bounded ys N) : | |
| Bounded (Fold.fold (zip zero zero f).eval xs xss) N β§ | |
| (Fold.fold (zip zero zero f).eval xs xss).length=xs.length := by | |
| induction xss generalizing xs with | |
| | nil => exact β¨h,rflβ© | |
| | cons ys yss ih => | |
| change Bounded (Fold.fold _ (zip zero zero f (xs,ys)) yss) N β§ _ | |
| have hh := ih (bounded_zip h (hs ys (by simp)) f hf) (fun zs hz => hs zs (by simp [hz])) | |
| exact β¨hh.1,hh.2.trans (zip_length f.eval zero xs ys)β© | |
| noncomputable def foldSelect (f : Code (WΓW) W) (hf : β z, f z=z.1 β¨ f z=z.2) : | |
| Code (List WΓList (List W)) (List W) := | |
| foldPrefix (zip zero zero f) 20 2 (by | |
| intro xs xss k _hk | |
| let S := treeSize (encode (xs,xss)) | |
| have hx : Bounded xs S := fun w hw => (digits_le_wordSize w).trans ((Size.mem hw).trans (Size.fst (xs,xss))) | |
| have hxs : β ysβxss.take k, Bounded ys S := by | |
| intro ys hy w hw | |
| exact (digits_le_wordSize w).trans ((Size.mem hw).trans | |
| ((Size.mem (List.mem_of_mem_take hy)).trans (Size.snd (xs,xss)))) | |
| have hb := fold_select_bound f hf hx hxs | |
| have ht := size_bound hb.1 | |
| rw [hb.2] at ht | |
| have hl := (Size.length xs).trans (Size.fst (xs,xss)) | |
| change xs.lengthβ€S at hl | |
| have hm := Nat.mul_le_mul_right (4*S+6) hl | |
| calc | |
| treeSize (encode (Fold.fold (zip zero zero f).eval xs (xss.take k))) β€ xs.length*(4*S+6)+1 := ht | |
| _ β€ 20*(S+1)^2 := by nlinarith) | |
| noncomputable def foldMin : Code (List WΓList (List W)) (List W) := foldSelect Word.min EdgeScan.low_mem | |
| noncomputable def foldMax : Code (List WΓList (List W)) (List W) := foldSelect Word.max EdgeScan.high_mem | |
| theorem foldMin_rep {n B : β} {I : SolveBox n B} (v : BoxVector I) {xs : List W} | |
| (hv : VectorRep v.val xs) {vs : List (BoxVector I)} {xss : List (List W)} | |
| (hs : VectorsRep (vs.map Subtype.val) xss) : | |
| VectorRep (vs.foldl I.minVector v).val (foldMin (xs,xss)) := by | |
| induction vs generalizing v xs xss with | |
| | nil => cases hs; exact hv | |
| | cons w ws ih => | |
| cases hs with | |
| | cons hw hws => | |
| exact ih (I.minVector v w) (Array.zip_rep Word.min Min.min (fun _ _ => Word.min_val _ _) hv hw) hws | |
| theorem foldMax_rep {n B : β} {I : SolveBox n B} (v : BoxVector I) {xs : List W} | |
| (hv : VectorRep v.val xs) {vs : List (BoxVector I)} {xss : List (List W)} | |
| (hs : VectorsRep (vs.map Subtype.val) xss) : | |
| VectorRep (vs.foldl I.maxVector v).val (foldMax (xs,xss)) := by | |
| induction vs generalizing v xs xss with | |
| | nil => cases hs; exact hv | |
| | cons w ws ih => | |
| cases hs with | |
| | cons hw hws => | |
| exact ih (I.maxVector v w) (Array.zip_rep Word.max Max.max (fun _ _ => Word.max_val _ _) hv hw) hws | |
| end Array | |
| end MeanPayoff.TreeDevice.Certified | |
| end | |
| section | |
| namespace MeanPayoff.TreeDevice.Certified.RawControl | |
| open BinaryData Code | |
| local infixl:80 " β«β " => Code.comp | |
| local infixr:70 " ββ " => Code.pair | |
| noncomputable def trialsHeadCase : Code Input State := | |
| call 2 (pack (caller β«β p) (caller β«β b) (caller β«β t)) | |
| (push 1 (pack (q:=current β«β q)) rest) | |
| noncomputable def vectorConsCase : Code Input State := | |
| ret (pack (vs:=((caller β«β q) ββ (current β«β vs)) β«β cons)) rest | |
| noncomputable def medianCase : Code Input State := | |
| ret (pack (q:=((caller β«β b) ββ (current β«β vs)) β«β RawMedian.boxed)) rest | |
| noncomputable def centerFirstCase : Code Input State := | |
| call 1 (pack (caller β«β p β«β RawBudget.reduceM) (narrow (caller β«β b) (caller β«β q))) | |
| (push 4 (pack (b:=caller β«β b) (r:=current β«β q)) rest) | |
| noncomputable def centerSecondCase : Code Input State := | |
| ret (pack (q:=((caller β«β b) ββ (caller β«β r) ββ (current β«β q)) β«β RawBox.averageClipped)) rest | |
| noncomputable def centersHeadCase : Code Input State := | |
| call 4 (pack (caller β«β p) (caller β«β b) (caller β«β t) (current β«β q)) | |
| (push 1 (pack (q:=caller β«β q)) rest) | |
| noncomputable def centerAt (index : Code Input Count) : Code Input (List W) := | |
| (((current β«β vs) ββ index) ββ (caller β«β b β«β RawBox.midpoint)) β«β getD [] | |
| noncomputable def lastPositive : Code Input (List Bool) := | |
| ((caller β«β b) ββ (env β«β samples β«β Counter.word) ββ centerAt (env β«β samples)) β«β RawOrientation.positives | |
| noncomputable def lastNegative : Code Input (List Bool) := | |
| ((caller β«β b) ββ (env β«β samples β«β Counter.word) ββ centerAt (env β«β samples)) β«β RawOrientation.negatives | |
| noncomputable def orientLoopCase : Code Input State := | |
| Code.branch (((caller β«β p) ββ lastPositive) β«β RawBudget.measureLarge) | |
| (ret (pack (o:=lastPositive β«β RawOrientation.trueComplement)) rest) | |
| (Code.branch (((caller β«β p) ββ lastNegative) β«β RawBudget.measureLarge) | |
| (ret (pack (o:=lastNegative β«β RawOrientation.falseComplement)) rest) | |
| (call 5 (pack (caller β«β p) (wide (caller β«β b) (centerAt random))) | |
| (push 7 (pack (o:=const false ββ ((lastPositive ββ ((lastNegative ββ const []) β«β cons)) β«β cons))) rest))) | |
| noncomputable def orientTailCase : Code Input State := | |
| ret (pack (o:=((current β«β o) ββ (caller β«β o β«β snd β«β head []) ββ | |
| (caller β«β o β«β snd β«β tail β«β head [])) β«β RawOrientation.extend)) rest | |
| noncomputable def orientHeadCase : Code Input State := | |
| call 6 (pack (caller β«β p) (caller β«β b) (caller β«β t)) | |
| (push 9 (pack (o:=current β«β o)) rest) | |
| noncomputable def orientConsCase : Code Input State := | |
| ret (pack (os:=((caller β«β o) ββ (current β«β os)) β«β cons)) rest | |
| noncomputable def combineCase : Code Input State := | |
| ret (pack (o:=current β«β os β«β RawOrientation.combine)) rest | |
| noncomputable def tightenFirstCase : Code Input State := | |
| Code.branch (((caller β«β b) ββ (current β«β q) ββ delta (caller β«β b)) β«β RawBox.movedFloor) | |
| (call 8 (pack (caller β«β p) (((caller β«β b) ββ (current β«β q)) β«β RawBox.withFloor)) | |
| (push 13 (pack (b:=caller β«β b) (q:=current β«β q)) rest)) | |
| (call 1 (pack (caller β«β p β«β RawBudget.reduceM) (caller β«β b)) (push 12 caller rest)) | |
| noncomputable def tightenSecondCase : Code Input State := | |
| Code.branch (((caller β«β b) ββ (current β«β q) ββ delta (caller β«β b)) β«β RawBox.movedCeiling) | |
| (call 8 (pack (caller β«β p) (((caller β«β b) ββ (current β«β q)) β«β RawBox.withCeiling)) | |
| (push 14 (pack (b:=caller β«β b) (q:=current β«β q)) rest)) | |
| (ret (pack (b:=caller β«β b)) rest) | |
| noncomputable def boxPassCase : Code Input State := ret (pack (b:=current β«β b)) rest | |
| noncomputable def solveTightCase : Code Input State := | |
| call 7 (pack (caller β«β p) (current β«β b)) | |
| (push 16 (pack (caller β«β p) (current β«β b)) (push 21 (const Pack.zero) rest)) | |
| noncomputable def solveOrientedCase : Code Input State := | |
| call 9 (pack (caller β«β p) (caller β«β b) (o:=current β«β o)) | |
| (push 18 (pack (caller β«β p) (caller β«β b) (o:=(current β«β o β«β fst) ββ const [])) rest) | |
| noncomputable def reweightHeadCase : Code Input State := | |
| call 9 (pack (caller β«β p) (caller β«β b) (o:=caller β«β o)) | |
| (push 1 (pack (q:=current β«β q)) rest) | |
| noncomputable def solveReweightedCase : Code Input State := | |
| Code.branch (caller β«β o β«β fst) | |
| (call 0 (pack (caller β«β p) (((caller β«β b) ββ capWidth (caller β«β b)) β«β RawBox.capHigh)) | |
| (push 19 (pack (b:=caller β«β b) (vs:=current β«β vs)) rest)) | |
| (call 0 (pack (caller β«β p) (((caller β«β b) ββ capWidth (caller β«β b)) β«β RawBox.capLow)) | |
| (push 20 (pack (b:=caller β«β b) (vs:=current β«β vs)) rest)) | |
| noncomputable def capHighCase : Code Input State := | |
| ret (pack (q:=((current β«β q) ββ (caller β«β vs)) β«β Array.foldMin)) rest | |
| noncomputable def capLowCase : Code Input State := | |
| ret (pack (q:=((current β«β q) ββ (caller β«β vs)) β«β Array.foldMax)) rest | |
| noncomputable def includeInnerCase : Code Input State := ret (pack (q:=current β«β q)) rest | |
| noncomputable def resume : Code Input State := | |
| Code.branch (stack β«β empty) state | |
| (select (stack β«β head ([],Pack.zero) β«β fst) | |
| [trialsHeadCase,vectorConsCase,medianCase,centerFirstCase,centerSecondCase,centersHeadCase, | |
| orientLoopCase,orientTailCase,orientHeadCase,orientConsCase,combineCase,tightenFirstCase, | |
| tightenSecondCase,boxPassCase,boxPassCase,solveTightCase,solveOrientedCase,reweightHeadCase, | |
| solveReweightedCase,capHighCase,capLowCase,includeInnerCase] state) | |
| noncomputable def dispatch : Code Input State := | |
| select (state β«β fst β«β fst) | |
| [solveCase,askCase,trialsCase,updateCase,centersCase,orientCase,orientTrialsCase,orientPlusCase, | |
| tightenCase,reweightCase] resume | |
| end MeanPayoff.TreeDevice.Certified.RawControl | |
| end | |
| section | |
| namespace MeanPayoff.SourceControl | |
| def sampledResume {G : Game} {B : β} {A C R : Result G B} (f : Frame G B A C) (v : A.Value) | |
| (k : Kont G B C R) (j : β) : State G B R := | |
| match f with | |
| | .trialsHead P I J => (.call (.trials P I J) (.push (.vectorCons v) k)) | |
| | .vectorCons a => (.ret k (a :: v)) | |
| | .median I => (.ret k (I.medianBox v)) | |
| | .centerFirst P _ I hB q => | |
| (.call (.ask P.reduceM (I.narrowCentered hB q.val)) (.push (.centerSecond I hB q v) k)) | |
| | .centerSecond I _ _ r => (.ret k (I.averageClipped r.val v.val)) | |
| | .centersHead P hR I hB t q => | |
| (.call (.centers P hR I hB t v) (.push (.vectorCons q) k)) | |
| | .orientLoop P hR I hB => | |
| let H := PositiveDisplacement I (v.getD (globalS B) I.midpoint) | |
| let N := NegativeDisplacement I (v.getD (globalS B) I.midpoint) | |
| if hH : 1 / 2 < P.measure H then | |
| (.ret k β¨true, [β¨HαΆ, by rw [P.measure_compl G.positive]; linarithβ©]β©) | |
| else if hN : 1 / 2 < P.measure N then | |
| (.ret k β¨false, [β¨NαΆ, by rw [P.measure_compl G.positive]; linarithβ©]β©) | |
| else | |
| .call (.orient P hR (I.wideCentered hB (v.getD j I.midpoint).val)) | |
| (.push (.orientTail β¨H, le_of_not_gt hHβ© β¨N, le_of_not_gt hNβ©) k) | |
| | .orientTail H N => (.ret k β¨v.chooseY, v.exceptions ++ [H, N]β©) | |
| | .orientHead P hR I J => (.call (.orientTrials P hR I J) (.push (.orientCons v) k)) | |
| | .orientCons O => (.ret k (O :: v)) | |
| | .combine _ => (.ret k (combineOrientations v)) | |
| | .tightenFirst P hR I hB => | |
| if _ : β i, (I.delta : β€) β€ v.val i - I.a i then | |
| (.call (.tighten P hR (I.withFloor v) hB) (.push (.floor I v) k)) | |
| else (.call (.ask P.reduceM I) (.push (.tightenSecond P hR I hB) k)) | |
| | .tightenSecond P hR I hB => | |
| if _ : β i, (I.delta : β€) β€ I.b i - v.val i then | |
| (.call (.tighten P hR (I.withCeiling v) hB) (.push (.ceiling I v) k)) | |
| else (.ret k β¨I, rfl, le_refl _, le_refl _β©) | |
| | .floor _ q => (.ret k β¨v.box, v.width_eq, q.property.1.trans v.floor_le, v.ceiling_leβ©) | |
| | .ceiling _ q => (.ret k β¨v.box, v.width_eq, v.floor_le, v.ceiling_le.trans q.property.2β©) | |
| | .solveTight P hR _ hB => | |
| have hK : 128 * globalS B < v.box.width := by rw [v.width_eq]; exact hB | |
| (.call (.orientPlus P hR v.box) (.push (.solveOriented P hR v.box hK) (.push (.includeInner v) k))) | |
| | .solveOriented P hR I hB => | |
| (.call (.reweight P hR I v.chooseY v.exceptions) (.push (.solveReweighted P hR I hB v.chooseY) k)) | |
| | .reweightHead P hR I side Hs => (.call (.reweight P hR I side Hs) (.push (.vectorCons v) k)) | |
| | .solveReweighted P _ I hB side => | |
| if side then (.call (.solve P (I.capHigh I.C I.C_positive (I.C_smaller hB).le)) (.push (.capHigh I hB v) k)) | |
| else (.call (.solve P (I.capLow I.C I.C_positive (I.C_smaller hB).le)) (.push (.capLow I hB v) k)) | |
| | .capHigh I hB rs => (.ret k (rs.foldl I.minVector (I.includeCapHigh I.C I.C_positive (I.C_smaller hB).le v))) | |
| | .capLow I hB rs => (.ret k (rs.foldl I.maxVector (I.includeCapLow I.C I.C_positive (I.C_smaller hB).le v))) | |
| | .includeInner T => (.ret k (T.include v)) | |
| def sampledStep {G : Game} {B : β} {R : Result G B} (j : β) : State G B R β State G B R | |
| | .ret .done v => (.ret .done v) | |
| | .ret (.push f k) v => sampledResume f v k j | |
| | .call job k => match job with | |
| | .solve P I => if hR : P.parameter < 1 then (.ret k (I.smallVector P)) | |
| else if hB : I.width β€ 128 * globalS B then (.ret k (I.exactVector G)) | |
| else (.call (.tighten P (le_of_not_gt hR) I (by omega)) (.push (.solveTight P (le_of_not_gt hR) I (by omega)) k)) | |
| | .ask P I => (.call (.trials P I (globalJ G.n B)) (.push (.median I) k)) | |
| | .trials P I J => match J with | |
| | 0 => (.ret k []) | |
| | J + 1 => (.call (.solve P I) (.push (.trialsHead P I J) k)) | |
| | .update P hR I hB q => | |
| (.call (.ask P.reduceK (I.narrowCentered hB q.val)) (.push (.centerFirst P hR I hB q) k)) | |
| | .centers P hR I hB t q => match t with | |
| | 0 => (.ret k [q]) | |
| | t + 1 => (.call (.update P hR I hB q) (.push (.centersHead P hR I hB t q) k)) | |
| | .orient P hR I => | |
| if hB : I.width β€ 128 * globalS B then (.ret k (orientBase G P I)) | |
| else (.call (.centers P hR I (by omega) (globalS B) I.midpoint) (.push (.orientLoop P hR I (by omega)) k)) | |
| | .orientTrials P hR I J => match J with | |
| | 0 => (.ret k []) | |
| | J + 1 => (.call (.orient P hR I) (.push (.orientHead P hR I J) k)) | |
| | .orientPlus P hR I => (.call (.orientTrials P hR I (globalJ G.n B)) (.push (.combine P) k)) | |
| | .tighten P hR I hB => (.call (.ask P.reduceK I) (.push (.tightenFirst P hR I hB) k)) | |
| | .reweight P hR I side Hs => match Hs with | |
| | [] => (.ret k []) | |
| | H :: Hs => | |
| (.call (.ask (if side then P.reweightM H.val else P.reweightK H.val) I) | |
| (.push (.reweightHead P hR I side Hs) k)) | |
| end MeanPayoff.SourceControl | |
| end | |
| end OAI | |