File size: 2,506 Bytes
4a56cd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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