File size: 4,325 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
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
87
88
89
90
91
92
import OAI.Combinatorics.EditApproximation.Numerics.GradientStorageBits
import OAI.Combinatorics.EditApproximation.Geometry.BandOptimizerWork
import OAI.Combinatorics.EditApproximation.Numerics.OptimizerWorkspace

namespace OAI

/-! The probability vectors actually stored for band actions have polynomial
encodings in the input child masses. No accuracy event is needed. -/

namespace EditApproximation

open Finset

def bandVertexEncodingBudget (M V B : β„•) : β„• :=
  B + (Nat.size (M * V) + 2 * (M * B + 1) + 1) + 3

theorem actionVector_encoding_le {M : β„•} {Οƒ : Type*} [DecidableEq Οƒ]
    (mass : Fin M β†’ β„š) (action : Fin M β†’ Οƒ) (coordinate : Fin M Γ— Οƒ)
    (V B : β„•) (habs : βˆ€ i, |mass i| ≀ V)
    (hbits : βˆ€ i, rationalEncodingBits (mass i) ≀ B) :
    rationalEncodingBits (actionVector mass action coordinate) ≀ bandVertexEncodingBudget M V B := by
  have hsum := rational_finite_sum_encoding_le (univ : Finset (Fin M)) mass V B
    (fun i _ => habs i) (fun i _ => (by
      unfold rationalEncodingBits at hbits
      have h := hbits i
      omega))
  simp only [Finset.card_univ, Fintype.card_fin] at hsum
  unfold actionVector
  split_ifs
  Β· have hdiv := rationalEncodingBits_div (mass coordinate.1) (βˆ‘ i, mass i)
    have hmass := hbits coordinate.1
    unfold bandVertexEncodingBudget
    omega
  Β· norm_num [rationalEncodingBits, bandVertexEncodingBudget]

theorem actionVector_zero_one {M : β„•} {Οƒ : Type*} [DecidableEq Οƒ]
    (mass : Fin M β†’ β„š) (action : Fin M β†’ Οƒ) (coordinate : Fin M Γ— Οƒ)
    (hpos : βˆ€ i, 0 < mass i) :
    0 ≀ actionVector mass action coordinate ∧ actionVector mass action coordinate ≀ 1 := by
  have hsum : 0 < βˆ‘ i, mass i :=
    (hpos coordinate.1).trans_le (Finset.single_le_sum (fun i _ => (hpos i).le) (mem_univ _))
  unfold actionVector
  split_ifs
  · exact ⟨(div_pos (hpos _) hsum).le,
      (div_le_oneβ‚€ hsum).2 (single_le_sum (fun i _ => (hpos i).le) (mem_univ _))⟩
  Β· norm_num

def storedBandVertices {M : β„•} {Οƒ : Type*} [DecidableEq Οƒ]
    (band : List (Fin M β†’ Οƒ)) (mass : Fin M β†’ β„š) :
    List (Vector β„š (listedBandCoordinates band).length) :=
  band.map fun action => restrictOptimizerVector (listedBandCoordinateVector band) (actionVector mass action)

theorem storedBandVertices_nonempty {M : β„•} {Οƒ : Type*} [DecidableEq Οƒ]
    (band : List (Fin M β†’ Οƒ)) (mass : Fin M β†’ β„š) (hband : band β‰  []) :
    storedBandVertices band mass β‰  [] := by
  intro hempty
  exact hband (List.map_eq_nil_iff.mp hempty)

theorem storedBandVertices_input_bounds {M : β„•} {Οƒ : Type*} [DecidableEq Οƒ]
    (band : List (Fin M β†’ Οƒ)) (mass : Fin M β†’ β„š) (V B : β„•)
    (hpos : βˆ€ i, 0 < mass i) (habs : βˆ€ i, |mass i| ≀ V)
    (hbits : βˆ€ i, rationalEncodingBits (mass i) ≀ B)
    (vertex : Vector β„š (listedBandCoordinates band).length)
    (hvertex : vertex ∈ storedBandVertices band mass)
    (i : Fin (listedBandCoordinates band).length) :
    (0 ≀ vertex.get i ∧ vertex.get i ≀ 1) ∧
      Nat.size (vertex.get i).den ≀ bandVertexEncodingBudget M V B := by
  obtain ⟨action, _, rfl⟩ := List.mem_map.mp hvertex
  rw [restrictOptimizerVector_get]
  constructor
  Β· exact actionVector_zero_one mass action _ hpos
  Β· have h := actionVector_encoding_le mass action
      ((listedBandCoordinateVector band).get i) V B habs hbits
    unfold rationalEncodingBits at h
    omega

theorem storedBandOptimizer_history_bits {M : β„•} {Οƒ : Type*} [DecidableEq Οƒ]
    (band : List (Fin M β†’ Οƒ)) (hband : band β‰  []) (mass : Fin M β†’ β„š)
    (linear : Fin M Γ— Οƒ β†’ β„š) (G K V B : β„•)
    (hpos : βˆ€ i, 0 < mass i) (habs : βˆ€ i, |mass i| ≀ V)
    (hbits : βˆ€ i, rationalEncodingBits (mass i) ≀ B) :
    rationalVectorListStorageBits (optimizerStoredHistory (storedBandVertices band mass)
      (restrictOptimizerVector (listedBandCoordinateVector band) linear) G K) ≀
      (K + 1) * ((listedBandCoordinates band).length *
        (2 * ((K + 1) * (2 * Nat.size (K + 1) + 2 + bandVertexEncodingBudget M V B) + 1) + 1)) := by
  exact optimizerStoredHistory_storage_le _ _ G K _ (storedBandVertices_nonempty band mass hband)
    (fun vertex hvertex i => storedBandVertices_input_bounds band mass V B hpos habs hbits vertex hvertex i)

end EditApproximation

end OAI