File size: 2,729 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
import OAI.Combinatorics.EditApproximation.Queries.QueryScopedSourceCost
import OAI.Combinatorics.EditApproximation.Queries.QuerySharedInputCost

namespace OAI

/-! Shared-state generation using the actual gathered scalar buffer.
The lookup bound is instantiated at visited keys, including discarded cells. -/

namespace EditApproximation.BinaryFraction

def queryBufferedGroupReadBudget (M F exponent eM eF B V : ℕ) : ℕ :=
  queryGroupBufferReadBudget (queryGroupSourceKeysLength M F exponent eM eF B) B V

theorem querySharedInputsWithWork_buffered_bounds {nx ny M N F Q : ℕ} [NeZero M]
    (exponent eM eF B V : ℕ) (hMdef : M = 2 ^ eM) (hFdef : F = 2 ^ eF)
    (parent : TargetInterval nx) (a value : BinaryFraction) (q : TargetInterval ny)
    (words : List BinaryFraction)
    (hB : 7 ≤ B) (hN : Nat.size N ≤ B) (hF : Nat.size F + 2 ≤ B)
    (hM : Nat.size M + 2 ≤ B) (hQ : Nat.size Q + 2 ≤ B) (hes : eM + eF + 7 ≤ B)
    (he : exponent + 1 ≤ B) (hnx : Nat.size nx ≤ B) (hny : Nat.size ny ≤ B)
    (ha : a.width ≤ B) (hv : value.width ≤ B) (hw : 0 ≤ value.value)
    (hV : 2 ≤ V) (hwords : ∀ v ∈ words, v.width ≤ V) :
    let keys := (queryGroupSourceKeysWithWork M N F Q exponent eM eF hMdef hFdef a value q).1
    let result := querySharedInputsWithWork M N F Q exponent eM eF hMdef hFdef parent a value q
      (queryGroupDrawReadWithWork keys words)
    result.1.length ≤ querySharedInputsLength M F exponent eM eF B ∧
    result.2 ≤ querySharedInputsBitBudget M F exponent eM eF B
      (queryBufferedGroupReadBudget M F exponent eM eF B V) := by
  have hk := (queryGroupSourceKeysWithWork_bounds M N F Q exponent eM eF B hMdef hFdef a value q
    hB hN hF hM hQ hes he hny ha hv hw).1
  apply querySharedInputsWithWork_bounds_on M N F Q exponent eM eF B
    (queryBufferedGroupReadBudget M F exponent eM eF B V) hMdef hFdef parent a value q
    (queryGroupDrawReadWithWork _ words) hB hN hF hM hQ hes he hnx hny ha hv hw
  intro eb heb cell hcell scale sample
  have hguard : (refinementScaleGuardWithWork F (2 ^ eb) a value).1 = true := by
    have h := heb
    simp only [queryExponentsWithWork, filterWithWork_value, List.mem_filter] at h
    exact h.2
  have hrange : eb ∈ List.range (max 1 N.bits.length) := by
    have h := heb
    simp only [queryExponentsWithWork, filterWithWork_value, List.mem_filter] at h
    exact h.1
  have hc := queryGroupDrawReadWithWork_scoped_cost exponent eM eF B V hMdef hFdef a value q words
    hB hN hF (by omega) (by omega) he hny ha hv hw hV hwords eb hrange hguard cell hcell scale sample
  apply hc.trans
  unfold queryBufferedGroupReadBudget queryGroupBufferReadBudget
  gcongr

end EditApproximation.BinaryFraction

end OAI