File size: 3,391 Bytes
5d5048e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import OAI.Combinatorics.LowSpaceSubsetSum.Representation.RepresentationQueryBound
import OAI.Combinatorics.LowSpaceSubsetSum.Compression.CompressionTrialLedger

namespace OAI

/-! # Actual parent-join counters through the full prefix tree

The full tree is only an accounting view. The executable search is depth
first and may return YES earlier. Invalid matching tuples remain charged.
-/

noncomputable section

namespace LowSpaceSubsetSum

namespace CompressionLedger

def add (a b : CompressionLedger) : CompressionLedger :=
  ⟨a.queries + b.queries, a.reports + b.reports,
    a.copies + b.copies, a.controls + b.controls⟩

end CompressionLedger

namespace RepresentationParentData

variable {n : ℕ} (D : RepresentationParentData n)

def localLedger (B : ℕ) : CompressionLedger :=
  ⟨(D.collect B).state.queries, (D.collect B).state.reports,
    (D.collect B).state.copies, (D.collect B).steps⟩

def prefixLedger (B : ℕ) : List (Fin n) → MaskRestriction n → CompressionLedger
  | [], P => ({ D with maskRestriction := P }).localLedger B
  | i :: order, P =>
    let task :=  ({ D with maskRestriction := P }).localLedger B
    if ({ D with maskRestriction := P }.collect B).state.user.keys.overflow then
      task.add ((prefixLedger B order (P.force i false)).add
        (prefixLedger B order (P.force i true)))
    else task

theorem prefixLedger_queries (B : ℕ) (order : List (Fin n)) (P : MaskRestriction n) :
    (D.prefixLedger B order P).queries = D.queryVisits B order P := by
  induction order generalizing P with
  | nil => rfl
  | cons i order ih =>
    simp only [prefixLedger, queryVisits]
    split <;> simp only [CompressionLedger.add, localLedger, ih, Nat.add_zero]

theorem prefixLedger_bounds (B : ℕ) (order : List (Fin n)) (P : MaskRestriction n) :
    (D.prefixLedger B order P).reports ≤ D.matchingVisits B order P ∧
      B * (D.prefixLedger B order P).copies ≤ 2 * D.matchingVisits B order P ∧
      (D.prefixLedger B order P).controls ≤ (D.prefixLedger B order P).queries := by
  induction order generalizing P with
  | nil =>
    have h := ({ D with maskRestriction := P }).collect_query_bounds B
    have hstep : ({ D with maskRestriction := P }.collect B).steps ≤
        ({ D with maskRestriction := P }.collect B).state.queries := by
      simpa only [RepresentationParentData.collect, StreamJoin.stopped_eq] using
        StreamJoin.stopped_steps_le_queries _ _ _ _ _ _ _ _ _ _ _ _
    exact ⟨h.2.1, h.2.2.1, hstep⟩
  | cons i order ih =>
    have h := ({ D with maskRestriction := P }).collect_query_bounds B
    have hstep : ({ D with maskRestriction := P }.collect B).steps ≤
        ({ D with maskRestriction := P }.collect B).state.queries := by
      simpa only [RepresentationParentData.collect, StreamJoin.stopped_eq] using
        StreamJoin.stopped_steps_le_queries _ _ _ _ _ _ _ _ _ _ _ _
    have h0 := ih (P.force i false)
    have h1 := ih (P.force i true)
    simp only [prefixLedger, matchingVisits]
    split <;> simp only [CompressionLedger.add, localLedger, Nat.mul_add]
    · exact ⟨Nat.add_le_add h.2.1 (Nat.add_le_add h0.1 h1.1),
        Nat.add_le_add h.2.2.1 (Nat.add_le_add h0.2.1 h1.2.1),
        Nat.add_le_add hstep (Nat.add_le_add h0.2.2 h1.2.2)⟩
    · simpa only [Nat.add_zero] using ⟨h.2.1, h.2.2.1, hstep⟩

end RepresentationParentData
end LowSpaceSubsetSum

end

end OAI