File size: 5,118 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import OAI.Combinatorics.EditApproximation.Binary.BinaryOptimizerSpace
import OAI.Combinatorics.EditApproximation.Binary.BinaryReductionSpace
import OAI.Combinatorics.EditApproximation.Binary.BinaryBandInputs

namespace OAI

namespace EditApproximation.BinaryFraction

def bandCoordinateAllocation {M : ℕ} {σ : Type*} [DecidableEq σ]
    (mass : Vector BinaryFraction M) (total : BinaryFraction)
    (action : Fin M → σ) (coordinate : Fin M × σ) : ℕ :=
  if coordinate.2 = action coordinate.1 then divAllocation (mass.get coordinate.1) total else 0

def bandCoordinateInvocations {M : ℕ} {σ : Type*} [DecidableEq σ]
    (mass : Vector BinaryFraction M) (total : BinaryFraction)
    (action : Fin M → σ) (coordinate : Fin M × σ) : ℕ :=
  if coordinate.2 = action coordinate.1 then divInvocations (mass.get coordinate.1) total else 1

theorem bandCoordinateAllocation_le_work {M : ℕ} {σ : Type*} [DecidableEq σ]
    (mass : Vector BinaryFraction M) (total : BinaryFraction)
    (action : Fin M → σ) (coordinate : Fin M × σ) :
    bandCoordinateAllocation mass total action coordinate ≤ (bandCoordinateWithWork mass total action coordinate).2 := by
  unfold bandCoordinateAllocation bandCoordinateWithWork
  split_ifs
  · exact divAllocation_le_work _ _
  · exact Nat.zero_le _

theorem bandCoordinateInvocations_le_work {M : ℕ} {σ : Type*} [DecidableEq σ]
    (mass : Vector BinaryFraction M) (total : BinaryFraction)
    (action : Fin M → σ) (coordinate : Fin M × σ) :
    bandCoordinateInvocations mass total action coordinate ≤ (bandCoordinateWithWork mass total action coordinate).2 := by
  unfold bandCoordinateInvocations bandCoordinateWithWork
  split_ifs
  · exact divInvocations_le_work _ _
  · exact le_refl _

def bandVerticesAllocation {M d : ℕ} {σ : Type*} [DecidableEq σ]
    (coordinates : Vector (Fin M × σ) d) (mass : Vector BinaryFraction M)
    (band : List (Fin M → σ)) : ℕ :=
  bandMassAllocation mass +
    (band.map fun action => vectorMapAllocation d fun i =>
      bandCoordinateAllocation mass (bandMassTotalWithWork mass).1 action (coordinates.get i)).sum +
    3 * band.length

def bandVerticesInvocations {M d : ℕ} {σ : Type*} [DecidableEq σ]
    (coordinates : Vector (Fin M × σ) d) (mass : Vector BinaryFraction M)
    (band : List (Fin M → σ)) : ℕ :=
  bandMassInvocations mass +
    (band.map fun action => vectorMapInvocations d fun i =>
      bandCoordinateInvocations mass (bandMassTotalWithWork mass).1 action (coordinates.get i)).sum +
    3 * band.length + 1

theorem bandVerticesAllocation_le_work {M d : ℕ} {σ : Type*} [DecidableEq σ]
    (coordinates : Vector (Fin M × σ) d) (mass : Vector BinaryFraction M)
    (band : List (Fin M → σ)) :
    bandVerticesAllocation coordinates mass band ≤ (bandVerticesWithWork coordinates mass band).2 := by
  have hm := bandMassAllocation_le_work mass
  have hs : (band.map fun action => vectorMapAllocation d fun i =>
      bandCoordinateAllocation mass (bandMassTotalWithWork mass).1 action (coordinates.get i)).sum ≤
      (band.map fun action => (vectorMapWithWork d fun i =>
        bandCoordinateWithWork mass (bandMassTotalWithWork mass).1 action (coordinates.get i)).2).sum := by
    induction band with
    | nil => simp
    | cons a rest ih =>
      have h := vectorMapAllocation_le_work d
        (fun i => bandCoordinateWithWork mass (bandMassTotalWithWork mass).1 a (coordinates.get i))
        (fun i => bandCoordinateAllocation mass (bandMassTotalWithWork mass).1 a (coordinates.get i))
        (fun i => bandCoordinateAllocation_le_work _ _ _ _)
      simp only [List.map_cons, List.sum_cons]
      omega
  unfold bandVerticesAllocation bandVerticesWithWork
  simp only [List.map_map, Function.comp_def]
  omega

theorem bandVerticesInvocations_le_work_add_one {M d : ℕ} {σ : Type*} [DecidableEq σ]
    (coordinates : Vector (Fin M × σ) d) (mass : Vector BinaryFraction M)
    (band : List (Fin M → σ)) :
    bandVerticesInvocations coordinates mass band ≤ (bandVerticesWithWork coordinates mass band).2 + 1 := by
  have hm := bandMassInvocations_le_work mass
  have hs : (band.map fun action => vectorMapInvocations d fun i =>
      bandCoordinateInvocations mass (bandMassTotalWithWork mass).1 action (coordinates.get i)).sum ≤
      (band.map fun action => (vectorMapWithWork d fun i =>
        bandCoordinateWithWork mass (bandMassTotalWithWork mass).1 action (coordinates.get i)).2).sum + band.length := by
    induction band with
    | nil => simp
    | cons a rest ih =>
      have h := vectorMapInvocations_le_work_add_one d
        (fun i => bandCoordinateWithWork mass (bandMassTotalWithWork mass).1 a (coordinates.get i))
        (fun i => bandCoordinateInvocations mass (bandMassTotalWithWork mass).1 a (coordinates.get i))
        (fun i => bandCoordinateInvocations_le_work _ _ _ _)
      simp only [List.map_cons, List.sum_cons, List.length_cons]
      omega
  unfold bandVerticesInvocations bandVerticesWithWork
  simp only [List.map_map, Function.comp_def]
  omega

end EditApproximation.BinaryFraction

end OAI