File size: 3,793 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
import OAI.Combinatorics.EditApproximation.Coarse.CoarseBinaryEvaluation
import OAI.Combinatorics.EditApproximation.Coarse.CoarseArraySimulation

namespace OAI

namespace EditApproximation
namespace BinaryFraction

 theorem coarseBinaryChildren_grid {B d : ℕ} {α : Type*} (k q L : ℕ) (two : BinaryFraction)
    (evaluate : CoarseSourceTree B α d → CoarseThresholdDraws B d → BinaryFraction → ℕ →
      CoarseBinaryArray × ℕ) (allowance : BinaryFraction)
    (children : List (CoarseSourceTree B α d × Fin B × CoarseThresholdDraws B d)) (start : ℕ)
    (ha : allowance.representation.den = two.representation.den)
    (he : ∀ child draw below, (child, draw, below) ∈ children → ∀ (a : BinaryFraction) (s : ℕ),
      a.representation.den = two.representation.den → CoarseArrayOnGrid two.representation.den
        (evaluate child below a s).1) :
    CoarseArrayOnGrid two.representation.den
      (coarseBinaryChildren k q L two evaluate allowance children start).1 := by
  induction children generalizing start with
  | nil => intro values hv; cases hv
  | cons data rest ih =>
    obtain ⟨child, draw, below⟩ := data
    have ht := (coarseChildThresholdWithWork_den B q allowance draw).trans ha
    have hc := (coarseChildAllowanceWithWork_den L (coarseChildThresholdWithWork B q allowance draw).1).trans ht
    have hev := he child draw below List.mem_cons_self
      (coarseChildAllowanceWithWork L (coarseChildThresholdWithWork B q allowance draw).1).1 start hc
    have hp := coarseBinaryPenalty_grid two _ hev
    have hs := (coarseChildAllowanceWithWork_den q allowance).trans ha
    have hm := coarseBinaryMap_grid
      (coarseContributionWithWork (coarseChildThresholdWithWork B q allowance draw).1
        (coarseChildAllowanceWithWork q allowance).1)
      (coarseBinaryPenaltyWithWork two
        (evaluate child below (coarseChildAllowanceWithWork L
          (coarseChildThresholdWithWork B q allowance draw).1).1 start).1).1
      two.representation.den hp (by
        intro z hz
        exact (coarseContributionWithWork_den _ _ z (hs.trans hz.symm)).trans hz)
    have hr := ih (start + child.word.length)
      (fun child draw below hmem => he child draw below (List.mem_cons_of_mem _ hmem))
    exact coarseBinaryAdd_grid _ _ _ hm hr

 theorem coarseBinaryEval_grid {B d : ℕ} {α : Type*} [DecidableEq α]
    (k q L : ℕ) (frame : List (Option α)) (two : BinaryFraction)
    (tree : CoarseSourceTree B α d) (draws : CoarseThresholdDraws B d)
    (allowance : BinaryFraction) (start : ℕ)
    (ha : allowance.representation.den = two.representation.den) :
    CoarseArrayOnGrid two.representation.den
      (coarseBinaryEval k q L frame two tree draws allowance start).1 := by
  induction tree generalizing allowance start with
  | leaf letter =>
    rw [coarseBinaryEval]
    split_ifs
    · intro values hv; cases hv
    · intro values hv a hamem
      have heq : (arithmeticMapWithWork (fun shift : Fin (2 * k + 1) =>
          coarseGridNatWithWork allowance.denominator allowance.denominator_pos
            (coarseShiftCost k frame (.leaf (B := B) letter) start shift))
          (List.finRange (2 * k + 1))).1 = values := Option.some.inj hv
      rw [← heq, arithmeticMapWithWork_value] at hamem
      obtain ⟨shift, _, rfl⟩ := List.mem_map.mp hamem
      exact (coarseGridNatWithWork_den _ _ _).trans ha
  | branch children ih =>
    obtain ⟨draws, below⟩ := draws
    rw [coarseBinaryEval]
    split_ifs
    · intro values hv; cases hv
    · apply coarseBinaryChildren_grid k q L two _ allowance _ start ha
      intro child draw childBelow hmem a s hag
      obtain ⟨i, hi⟩ := List.mem_ofFn.mp hmem
      cases hi
      exact ih i (below i) a s hag

end BinaryFraction
end EditApproximation

end OAI