File size: 3,957 Bytes
e63eb7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
83
84
85
86
import OAI.Combinatorics.EditApproximation.Binary.BinaryCountedGroup

namespace OAI

/-! The count used by every sampled scale is at most the actual child
arity. Consequently the complete group counter is bounded from stored
input widths, without assuming estimates on its internal callbacks. -/

namespace EditApproximation
namespace BinaryFraction

private theorem sumStorage_mono {n m B : ℕ} (h : n ≤ m) :
    bandMassTotalStorageBudget n B ≤ bandMassTotalStorageBudget m B := by
  have hs := Nat.size_le_size h
  unfold bandMassTotalStorageBudget
  gcongr

private theorem storedSumWork_mono {n m B : ℕ} (h : n ≤ m) :
    storedSumBitBudget n B ≤ storedSumBitBudget m B := by
  have hs := Nat.size_le_size h
  unfold storedSumBitBudget storedSumWordBudget
  gcongr

def boundedScaleWordBudget (M B : ℕ) : ℕ :=
  4 * (4 * B + 4 + bandMassTotalStorageBudget M B) + 2

def boundedScaleBitBudget (M B : ℕ) : ℕ :=
  groupIndexBitBudget M B + (2100 * (B + 2) ^ 2 + 1) +
    2000 * (4 * B + 4 + bandMassTotalStorageBudget M B + 1) ^ 2 + 2 * B + 3

private theorem groupScale_budget_le (M k B : ℕ) (hk : k ≤ M) :
    groupScaleWordBudget M k B ≤ boundedScaleWordBudget M B ∧
      groupScaleBitBudget M k B ≤ boundedScaleBitBudget M B := by
  have ht : groupScaleTermCount M k ≤ M := by
    unfold groupScaleTermCount
    split_ifs <;> omega
  have hsum := sumStorage_mono (B := B) ht
  have hwork := storedSumWork_mono (B := B) ht
  constructor
  · unfold groupScaleWordBudget boundedScaleWordBudget
    omega
  · unfold groupScaleBitBudget boundedScaleBitBudget groupIndexBitBudget
    have hprod := Nat.mul_le_mul_right (2 * (1000 * (B + 1) ^ 2 + 1) + 6) ht
    have hsq := Nat.pow_le_pow_left (show
      4 * B + 4 + bandMassTotalStorageBudget (groupScaleTermCount M k) B + 1 ≤
        4 * B + 4 + bandMassTotalStorageBudget M B + 1 by omega) 2
    omega

def countedGroupBitBudget (M T B : ℕ) : ℕ :=
  T * (groupSampleCountBitBudget B + 6) +
    groupMemberBitBudget T B (boundedScaleBitBudget M B) (boundedScaleWordBudget M B) + 1

theorem countedGroupMemberWithWork_bounds {M T : ℕ} (Q b : ℕ) (scales : Fin T → BinaryFraction)
    (connection : BinaryFraction) (envelope values : Vector BinaryFraction M)
    (draw : ∀ t, Fin (groupSampleCount M Q b (scales t).value) → Fin M)
    (B : ℕ) (hB : 1 ≤ B) (hM : Nat.size M + 2 ≤ B) (hQ : Nat.size Q + 2 ≤ B)
    (hb : Nat.size b + 2 ≤ B) (hs : ∀ t, (scales t).width ≤ B)
    (hconn : connection.width ≤ B) (he : ∀ i, (envelope.get i).width ≤ B)
    (hv : ∀ i, (values.get i).width ≤ B) :
    (countedGroupMemberWithWork Q b scales connection envelope values draw).1.width ≤
        groupMemberWordBudget T B (boundedScaleWordBudget M B) ∧
      (countedGroupMemberWithWork Q b scales connection envelope values draw).2 ≤
        countedGroupBitBudget M T B := by
  have hk (t : Fin T) : groupSampleCount M Q b (scales t).value ≤ M := by
    exact min_le_left _ _
  have hscale (t : Fin T) := groupScaleWithWork_bounds
    (groupSampleCount M Q b (scales t).value) (scales t) envelope values (draw t) B
    hB (hs t) he hv hM ((Nat.add_le_add_right (Nat.size_le_size (hk t)) 2).trans hM)
  have hc (t : Fin T) := (hscale t).2.trans (groupScale_budget_le M _ B (hk t)).2
  have hw (t : Fin T) := (hscale t).1.trans (groupScale_budget_le M _ B (hk t)).1
  constructor
  · have hmember := (groupMemberWithWork_bounds scales
      (fun t => groupSampleCount M Q b (scales t).value) connection envelope values draw B
      (boundedScaleBitBudget M B) (boundedScaleWordBudget M B) hconn hc hw).1
    unfold countedGroupMemberWithWork
    dsimp only
    rw [groupMemberWithWork_transport]
    exact hmember
  · exact countedGroupMemberWithWork_cost Q b scales connection envelope values draw B
      (boundedScaleBitBudget M B) (boundedScaleWordBudget M B) hM hQ hb hs hconn hc hw

end BinaryFraction
end EditApproximation

end OAI