math / data /lean /OAI /Combinatorics /LowSpaceSubsetSum /Counting /CountedReplayPotential.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
2.51 kB
import OAI.Combinatorics.LowSpaceSubsetSum.Counting.CountedReplay
namespace OAI
/-! # Telescoping callback costs through a stopped replay
The callback may itself contain a replay. A potential on its returned state
charges that actual inner work; a uniform worst-case inner fuel bound is not
multiplied by the outer stream length.
-/
namespace LowSpaceSubsetSum.CountedReplay
universe u v w
variable {Ξ± : Type u} {Οƒ : Type v} {Ο„ : Type w}
theorem runAcc_work_potential
(read : Οƒ β†’ Option (Ξ± Γ— Οƒ) Γ— β„•) (key : Ξ± β†’ β„€ Γ— β„•) (K : β„€)
(report : Ξ± β†’ Ο„ β†’ (Ο„ Γ— Bool) Γ— β„•) (potential : Ο„ β†’ β„•) (R L C : β„•)
(hr : βˆ€ s, (read s).2 ≀ R) (hk : βˆ€ x, (key x).2 ≀ L)
(hc : βˆ€ x a, (report x a).2 + potential a ≀ potential (report x a).1.1 + C)
(fuel : β„•) (s : Οƒ) (a : Ο„) (q r : β„•) :
(runAcc read key K report fuel s a q r).2 + (R + L + C + 8) * q + potential a ≀
(R + L + C + 8) * (runAcc read key K report fuel s a q r).1.queries +
potential (runAcc read key K report fuel s a q r).1.state + 1 := by
induction fuel generalizing s a q r with
| zero => simp only [runAcc]; omega
| succ fuel ih =>
have hread := hr s
cases hv : (read s).1 with
| none => simp only [runAcc, hv, Nat.mul_add, Nat.mul_one]; omega
| some z =>
rcases z with ⟨x, s'⟩
have hkey := hk x
simp only [runAcc, hv]
split
Β· have hcallback := hc x a
split
Β· simp only [Nat.mul_add, Nat.mul_one]; omega
Β· have hrest := ih s' (report x a).1.1 (q + 1) (r + 1)
simp only [Nat.mul_add, Nat.mul_one] at hrest
dsimp only
omega
Β· simp only [Nat.mul_add, Nat.mul_one]; omega
theorem run_work_potential
(read : Οƒ β†’ Option (Ξ± Γ— Οƒ) Γ— β„•) (key : Ξ± β†’ β„€ Γ— β„•) (K : β„€)
(report : Ξ± β†’ Ο„ β†’ (Ο„ Γ— Bool) Γ— β„•) (potential : Ο„ β†’ β„•) (R L C : β„•)
(hr : βˆ€ s, (read s).2 ≀ R) (hk : βˆ€ x, (key x).2 ≀ L)
(hc : βˆ€ x a, (report x a).2 + potential a ≀ potential (report x a).1.1 + C)
(fuel : β„•) (s : Οƒ) (a : Ο„) :
(run read key K report fuel s a).2 + potential a ≀
(R + L + C + 8) * (run read key K report fuel s a).1.queries +
potential (run read key K report fuel s a).1.state + 1 := by
simpa only [run, Nat.mul_zero, Nat.add_zero, Nat.zero_add] using
runAcc_work_potential read key K report potential R L C hr hk hc fuel s a 0 0
end LowSpaceSubsetSum.CountedReplay
end OAI