File size: 4,960 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
97
98
import OAI.NumberTheory.Ostmann.Arithmetic.BulkSlotNodup
import OAI.NumberTheory.Ostmann.Arithmetic.FrozenFrequencyAverage

namespace OAI

/-! # The original arithmetic support forces distinct bulk primes -/

namespace Ostmann
open scoped Classical BigOperators

theorem prime_list_injective_of_pairwise {Οƒ : Type*} (value : Οƒ β†’ β„•)
    (L : List Οƒ) (hprime : βˆ€ i ∈ L, (value i).Prime)
    (hp : (L.map value).Pairwise Nat.Coprime) :
    βˆ€ i ∈ L, βˆ€ j ∈ L, value i = value j β†’ i = j := by
  have hn : (L.map value).Nodup := by
    apply hp.imp_of_mem
    intro a b ha hb hab
    obtain ⟨i, hi, rfl⟩ := List.mem_map.mp ha
    obtain ⟨j, hj, rfl⟩ := List.mem_map.mp hb
    exact (Nat.coprime_primes (hprime i hi) (hprime j hj)).mp hab
  exact fun i hi j hj hij => List.inj_on_of_nodup_map hn hi hj hij

theorem buildMovingSlotData_injective_of_support {Οƒ : Type*}
    (value : Οƒ β†’ β„•) (n m : β„•) (slot : (TreeLeafIndex n Γ— Fin m) β†ͺ Οƒ)
    (t : FrequencyTree β„€ n) (small : TreeLeafTuple (List Οƒ) n)
    (samples : MovingSampleSlots Οƒ n) (outside : List β„•)
    (hprime : βˆ€ i, (value i).Prime)
    (hs : movingRegularOutsidePairwise value outside
      (buildMovingSlotData n t small (bulkSlotLeaves n m slot) samples)) :
    Function.Injective (value ∘ slot) := by
  let T := buildMovingSlotData n t small (bulkSlotLeaves n m slot) samples
  have hp : (T.regularSlots.map value).Pairwise Nat.Coprime := by
    have hroot : (T.regularSlots.map value ++ outside).Pairwise Nat.Coprime := by
      cases hT : T with
      | leaf s L => simpa only [T, hT, movingRegularOutsidePairwise,
          MovingSlotData.regularSlots] using hs
      | node s CL CR u left right =>
        have hs' := hs
        change movingRegularOutsidePairwise value outside T at hs'
        rw [hT] at hs'
        exact hs'.1
    exact (List.pairwise_append.mp hroot).1
  have hm (j) : slot j ∈ T.regularSlots := by
    apply (buildMovingSlotData_regular_perm n t small (bulkSlotLeaves n m slot) samples).mem_iff.mpr
    exact List.mem_append_right _ ((mem_flatten_bulkSlotLeaves n m slot _).mpr ⟨j, rfl⟩)
  intro i j hij
  exact slot.injective (prime_list_injective_of_pairwise value T.regularSlots
    (fun i _ => hprime i) hp (slot i) (hm i) (slot j) (hm j) hij)

/-- The frequency factor vanishes on collisions before any averaging or
resampling is performed. -/
theorem movingFrequencyPageAverage_zero_of_bulk_collision {Οƒ : Type*}
    (value : Οƒ β†’ β„•) (n m : β„•) (slot : (TreeLeafIndex n Γ— Fin m) β†ͺ Οƒ)
    (t : FrequencyTree β„€ n) (small : TreeLeafTuple (List Οƒ) n)
    (samples : MovingSampleSlots Οƒ n) (outside : List β„•)
    (hprime : βˆ€ i, (value i).Prime) (hbad : Β¬Function.Injective (value ∘ slot))
    (F : Bool β†’ {k : β„•} β†’ MovingSlotData Οƒ k β†’ β„€ β†’ β„‚)
    (E : Bool β†’ {k : β„•} β†’ MovingSlotData Οƒ k β†’ β„€ β†’ β„€ β†’ β„€ β†’ ℝ)
    (T : Bool β†’ MovingSlotData Οƒ n)
    (hT : T false = buildMovingSlotData n t small (bulkSlotLeaves n m slot) samples)
    (nodes : Bool β†’ List MovingFormulaNode) (R : β„€)
    (r : β„•) [NeZero r] (input : PublishedProgressionInput) (Q : β„•) (y : ℝ) :
    movingFrequencyPageAverage value outside F E T nodes R r input Q y = 0 := by
  have hsupport : Β¬(βˆ€ b, movingRegularOutsidePairwise value outside (T b) ∧
      βˆ€ f ∈ nodes b, f.guard.frequencyBounds) := by
    intro hs
    apply hbad
    apply buildMovingSlotData_injective_of_support value n m slot t small samples outside hprime
    rw [← hT]
    exact (hs false).1
  rw [movingFrequencyPageAverage_core]
  simp only [hsupport, ite_false, zero_mul]

/-- Inserting the distinctness gate leaves the literal supported arithmetic
coefficient unchanged. -/
theorem movingFrequencyPageAverage_collision_gate {Οƒ : Type*}
    (value : Οƒ β†’ β„•) (n m : β„•) (slot : (TreeLeafIndex n Γ— Fin m) β†ͺ Οƒ)
    (t : FrequencyTree β„€ n) (small : TreeLeafTuple (List Οƒ) n)
    (samples : MovingSampleSlots Οƒ n) (outside : List β„•)
    (hprime : βˆ€ i, (value i).Prime)
    (F : Bool β†’ {k : β„•} β†’ MovingSlotData Οƒ k β†’ β„€ β†’ β„‚)
    (E : Bool β†’ {k : β„•} β†’ MovingSlotData Οƒ k β†’ β„€ β†’ β„€ β†’ β„€ β†’ ℝ)
    (T : Bool β†’ MovingSlotData Οƒ n)
    (hT : T false = buildMovingSlotData n t small (bulkSlotLeaves n m slot) samples)
    (nodes : Bool β†’ List MovingFormulaNode) (R : β„€)
    (r : β„•) [NeZero r] (input : PublishedProgressionInput) (Q : β„•) (y : ℝ) (A : β„‚) :
    movingFrequencyPageAverage value outside F E T nodes R r input Q y * A =
      if Function.Injective (value ∘ slot) then
        movingFrequencyPageAverage value outside F E T nodes R r input Q y * A else 0 := by
  by_cases h : Function.Injective (value ∘ slot)
  Β· simp only [h, ite_true]
  Β· rw [ite_eq_right h, movingFrequencyPageAverage_zero_of_bulk_collision value n m slot
      t small samples outside hprime h F E T hT nodes R r input Q y, zero_mul]

end Ostmann

end OAI