import Mathlib import OAI.Probability.LogConcave.Numerics.ScalarPicard namespace OAI section noncomputable section namespace LogConcaveSampling.OracleCompiler open MeanTree open scoped Classical variable {d : ℕ} def RoutineBudget (B : ℕ) (η₀ η₁ : ℝ) : {k : RoutineKind} → RoutineValue d k → Prop | .mean,M => ∀r σ,MeanBudget B r (M r σ) | .sample,S => ∀r η,η=η₀ ∨ η=η₁ → SampleBudget B r η (S r η) lemma RoutineBudget.mono {B C : ℕ} {η₀ η₁ : ℝ} {k : RoutineKind} {R : RoutineValue d k} (h : RoutineBudget B η₀ η₁ R) (hBC : B≤C) : RoutineBudget C η₀ η₁ R := by cases k with | mean => exact fun r σ => (h r σ).mono hBC | sample => exact fun r η hη => (h r η hη).mono hBC theorem constructRoutine_budget (C : CircuitParameters) {t : ℝ} (ht : 0 cases k with | mean => exact fun r σ => (terminalMeanProgram_budget r σ).mono (hp _) | sample => exact fun r η _ => (terminalReservedProgram_budget r η).mono (hp _) · intro L hL ih hcap let n := L.rank t-1 let B := 2*K^n have hi : (RoutineLabel.mk .mean (L.b-10*t) (L.p-1/4)).rank t cases k with | mean => have hf := child ⟨.mean,b+t,p⟩ (RoutineStep.meanFinal b p) have hi := child ⟨.mean,b-10*t,p-1/4⟩ (RoutineStep.internal .mean .mean b p) have hs' := child ⟨.sample,b-10*t,p-1/4⟩ (RoutineStep.internal .mean .sample b p) intro r σ have hh := C.meanFrom_budget hB hD hBD (constructRoutine d C ht hs ⟨.mean,b+t,p⟩) (constructRoutine d C ht hs ⟨.mean,b-10*t,p-1/4⟩) (constructRoutine d C ht hs ⟨.sample,b-10*t,p-1/4⟩) (fun s r σ _ => by cases s; exact hi r σ; exact hf r σ) (fun r _ => hs' r _ (Or.inl rfl)) r σ (hcm r σ) rw [show (40*c+40)*B=2*(40*c+40)^({kind:=RoutineKind.mean,b:=b,p:=p}:RoutineLabel).rank t from hbfinal] at hh exact hh | sample => have hf := child ⟨.mean,b,p⟩ (RoutineStep.sampleFinal b p) have hi := child ⟨.mean,b-10*t,p-1/4⟩ (RoutineStep.internal .sample .mean b p) intro r η hη have hh := C.sampleFrom_budget hB hD hBD (constructRoutine d C ht hs ⟨.mean,b,p⟩) (constructRoutine d C ht hs ⟨.mean,b-10*t,p-1/4⟩) (fun s r σ _ => by cases s; exact hi r σ; exact hf r σ) r η (fun _ hηpos hη1 => hcs r η hη hηpos hη1) rw [show (40*c+40)*B=2*(40*c+40)^({kind:=RoutineKind.sample,b:=b,p:=p}:RoutineLabel).rank t from hbfinal] at hh exact hh end LogConcaveSampling.OracleCompiler end end end OAI