File size: 5,979 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
93
94
95
96
import OAI.Combinatorics.EditApproximation.Coarse.CoarseArrayControlSpace
import OAI.Combinatorics.EditApproximation.Coarse.CoarseIndexedChildren

namespace OAI

namespace EditApproximation
namespace BinaryFraction

/-- Invocation count follows the same child sequence, thresholds, recursive calls,
penalty sweeps and accumulated array as the indexed evaluator. -/
def coarseIndexChildrenInvocations {B : β„•} (q L : β„•) (two : BinaryFraction)
    (width : Fin B β†’ β„•)
    (evaluate : Fin B β†’ BinaryFraction β†’ β„• β†’ CoarseBinaryArray Γ— β„•)
    (allocation : Fin B β†’ BinaryFraction β†’ β„• β†’ β„•)
    (draw : Fin B β†’ Fin B) (allowance : BinaryFraction) : List (Fin B) β†’ β„• β†’ β„•
  | [], _ => 1
  | i :: rest, start =>
    let threshold := coarseChildThresholdWithWork B q allowance (draw i)
    let childAllowance := coarseChildAllowanceWithWork L threshold.1
    let evaluated := evaluate i childAllowance.1 start
    let penalty := coarseBinaryPenaltyWithWork two evaluated.1
    let scale := coarseChildAllowanceWithWork q allowance
    let contribution := coarseBinaryMapWithWork (coarseContributionWithWork threshold.1 scale.1) penalty.1
    let remainder := coarseIndexChildren 0 q L two width evaluate draw allowance rest (start + width i)
    coarseChildThresholdInvocations B q allowance (draw i) +
      coarseChildAllowanceInvocations L threshold.1 + allocation i childAllowance.1 start +
      coarseBinaryPenaltyInvocations two evaluated.1 + coarseChildAllowanceInvocations q allowance +
      coarseBinaryMapInvocations (coarseContributionInvocations threshold.1 scale.1) penalty.1 +
      coarseIndexChildrenInvocations q L two width evaluate allocation draw allowance rest (start + width i) +
      coarseBinaryAddInvocations contribution.1 remainder.1 + 1

/-- The loop's first argument does not contribute to its runtime control space. -/
private theorem coarseIndexChildren_unused_k {B : β„•} (k q L : β„•) (two : BinaryFraction)
    (width : Fin B β†’ β„•) (evaluate : Fin B β†’ BinaryFraction β†’ β„• β†’ CoarseBinaryArray Γ— β„•)
    (draw : Fin B β†’ Fin B) (allowance : BinaryFraction) (indices : List (Fin B)) (start : β„•) :
    coarseIndexChildren k q L two width evaluate draw allowance indices start =
      coarseIndexChildren 0 q L two width evaluate draw allowance indices start := by
  induction indices generalizing start with
  | nil => rfl
  | cons i rest ih => simp only [coarseIndexChildren, ih]

theorem coarseIndexChildrenInvocations_le_work {B : β„•} (k q L : β„•) (two : BinaryFraction)
    (width : Fin B β†’ β„•)
    (evaluate : Fin B β†’ BinaryFraction β†’ β„• β†’ CoarseBinaryArray Γ— β„•)
    (allocation : Fin B β†’ BinaryFraction β†’ β„• β†’ β„•)
    (hallocation : βˆ€ i a start, allocation i a start ≀ 2 * (evaluate i a start).2 + 1)
    (draw : Fin B β†’ Fin B) (allowance : BinaryFraction) (indices : List (Fin B)) (start : β„•) :
    coarseIndexChildrenInvocations q L two width evaluate allocation draw allowance indices start ≀
      2 * (coarseIndexChildren k q L two width evaluate draw allowance indices start).2 + 1 := by
  rw [coarseIndexChildren_unused_k]
  induction indices generalizing start with
  | nil => exact Nat.le_refl 1
  | cons i rest ih =>
    let threshold := coarseChildThresholdWithWork B q allowance (draw i)
    let childAllowance := coarseChildAllowanceWithWork L threshold.1
    let evaluated := evaluate i childAllowance.1 start
    let penalty := coarseBinaryPenaltyWithWork two evaluated.1
    let scale := coarseChildAllowanceWithWork q allowance
    let contribution := coarseBinaryMapWithWork (coarseContributionWithWork threshold.1 scale.1) penalty.1
    let remainder := coarseIndexChildren 0 q L two width evaluate draw allowance rest (start + width i)
    have ht := coarseChildThresholdInvocations_le_work B q allowance (draw i)
    have ha := coarseChildAllowanceInvocations_le_work L threshold.1
    have he := hallocation i childAllowance.1 start
    have hp := coarseBinaryPenaltyInvocations_le_work two evaluated.1
    have hs := coarseChildAllowanceInvocations_le_work q allowance
    have hm := coarseBinaryMapInvocations_le_work
      (coarseContributionWithWork threshold.1 scale.1)
      (coarseContributionInvocations threshold.1 scale.1)
      (coarseContributionInvocations_le_work threshold.1 scale.1) penalty.1
    have hr := ih (start + width i)
    have had := coarseBinaryAddInvocations_le_work contribution.1 remainder.1
    change coarseChildThresholdInvocations B q allowance (draw i) +
      coarseChildAllowanceInvocations L threshold.1 + allocation i childAllowance.1 start +
      coarseBinaryPenaltyInvocations two evaluated.1 + coarseChildAllowanceInvocations q allowance +
      coarseBinaryMapInvocations (coarseContributionInvocations threshold.1 scale.1) penalty.1 +
      coarseIndexChildrenInvocations q L two width evaluate allocation draw allowance rest (start + width i) +
      coarseBinaryAddInvocations contribution.1 remainder.1 + 1 ≀
      2 * (threshold.2 + childAllowance.2 + evaluated.2 + penalty.2 + scale.2 + contribution.2 +
        remainder.2 + (coarseBinaryAddWithWork contribution.1 remainder.1).2 +
        Nat.size start + Nat.size (width i) + 9) + 1
    change coarseChildThresholdInvocations B q allowance (draw i) ≀ threshold.2 at ht
    change coarseChildAllowanceInvocations L threshold.1 ≀ childAllowance.2 at ha
    change allocation i childAllowance.1 start ≀ 2 * evaluated.2 + 1 at he
    change coarseBinaryPenaltyInvocations two evaluated.1 ≀ 2 * penalty.2 + 9 at hp
    change coarseChildAllowanceInvocations q allowance ≀ scale.2 at hs
    change coarseBinaryMapInvocations (coarseContributionInvocations threshold.1 scale.1) penalty.1 ≀
      contribution.2 + 2 at hm
    change coarseIndexChildrenInvocations q L two width evaluate allocation draw allowance rest (start + width i) ≀
      2 * remainder.2 + 1 at hr
    omega

end BinaryFraction
end EditApproximation

end OAI