cfahlgren1's picture
download
raw
12.2 kB
22
def regroupStep :
    ((D → ((T → S) × E)) × ((L × ((C → S) × B)) × O)) ≃
      (((D → E) × (L × O)) × (((D × T ⊕ C) → S) × B)) where
body · 17 lines
  toFun x :=
    ((fun d => (x.1 d).2, (x.2.1.1, x.2.2)),
      (fun call => match call with
        | .inl dt => (x.1 dt.1).1 dt.2
        | .inr c => x.2.1.2.1 c,
       x.2.1.2.2))
  invFun x :=
    ((fun d => (fun terminal => x.2.1 (.inl (d, terminal)), x.1.1 d)),
      ((x.1.2.1, (fun c => x.2.1 (.inr c), x.2.2)), x.1.2.2))
  left_inv x := rfl
  right_inv x := by
    apply Prod.ext
    · rfl
    · apply Prod.ext
      · funext call
        cases call <;> rfl
      · rfl
43
def prependUnit (A : Type*) : A ≃ Unit × A where
body · 4 lines
  toFun x := ((), x)
  invFun := Prod.snd
  left_inv _ := rfl
  right_inv x := by rcases x with ⟨u, x⟩; cases u; rfl
53
abbrev cutSlots (p : Path branch n m)
    (slots : Slots branch n → Fin t → MixedSupport.Slot) :
    Slots branch m → Fin t → MixedSupport.Slot :=
body · 1 line
  fun s => slots (p.slotEmbedding s)
58
def Exterior (rows repeats : Nat → Nat) :
    {n m : Nat} → (p : Path branch n (m + 1)) →
      (Slots branch n → Fin t → MixedSupport.Slot) → Type
body · 6 lines
  | _, _, .refl _, _ => Unit
  | n + 1, _, .step i p, slots =>
      (BucketSampler.Direction (rows (n + 1)) →
        OriginalTerminalSplit.ExteriorTape F2 repeats (.step i p) (LeafDomain slots)) ×
      (Exterior rows repeats p (childSlots slots i) ×
        ((j : RecursiveSampler.OffPath i) → Arrays (childSlots slots j.val) rows))
68
@[instance_reducible] def exteriorFintypeAux (rows repeats : Nat → Nat) :
    {n m : Nat} → (p : Path branch n (m + 1)) →
      (slots : Slots branch n → Fin t → MixedSupport.Slot) →
        Fintype (Exterior rows repeats p slots)
body · 9 lines
  | _, _, .refl _, _ => inferInstanceAs (Fintype Unit)
  | n + 1, _, .step i p, slots =>
      letI : Fintype (Exterior rows repeats p (childSlots slots i)) :=
        exteriorFintypeAux rows repeats p (childSlots slots i)
      inferInstanceAs (Fintype
        ((BucketSampler.Direction (rows (n + 1)) →
          OriginalTerminalSplit.ExteriorTape F2 repeats (.step i p) (LeafDomain slots)) ×
        (Exterior rows repeats p (childSlots slots i) ×
          ((j : RecursiveSampler.OffPath i) → Arrays (childSlots slots j.val) rows))))
82
instance exteriorFintype (rows repeats : Nat → Nat) (p : Path branch n (m + 1))
    (slots : Slots branch n → Fin t → MixedSupport.Slot) :
    Fintype (Exterior rows repeats p slots) := exteriorFintypeAux rows repeats p slots
86
def exteriorZero (rows repeats : Nat → Nat) :
    {n m : Nat} → (p : Path branch n (m + 1)) →
      (slots : Slots branch n → Fin t → MixedSupport.Slot) → Exterior rows repeats p slots
body · 4 lines
  | _, _, .refl _, _ => ()
  | _, _, .step i p, slots =>
      ((fun _ j => RecursiveSampler.zeroDraw F2 repeats (.step i p) (LeafDomain slots) j.val),
        (exteriorZero rows repeats p (childSlots slots i), fun _ _ _ => 0))
94
instance exteriorNonempty (rows repeats : Nat → Nat) (p : Path branch n (m + 1))
    (slots : Slots branch n → Fin t → MixedSupport.Slot) :
    Nonempty (Exterior rows repeats p slots) := ⟨exteriorZero rows repeats p slots⟩
98
abbrev BelowTape (rows repeats : Nat → Nat) (chosen : Fin (branch m))
    (q : Path branch m k) (slots : Slots branch (m + 1) → Fin t → MixedSupport.Slot) :=
body · 2 lines
  WholeArraySampler.Tape rows repeats q (childSlots slots chosen) ×
    ((j : RecursiveSampler.OffPath chosen) → Arrays (childSlots slots j.val) rows)
103
abbrev Calls (rows repeats : Nat → Nat) (p : Path branch n (m + 1))
    (chosen : Fin (branch m)) (q : Path branch m k)
    (slots : Slots branch n → Fin t → MixedSupport.Slot) :=
body · 2 lines
  OriginalCutCalls.Index rows repeats p →
    RecursiveSampler.Tape F2 repeats (.step chosen q) (LeafDomain (cutSlots p slots))
109
def splitTape (rows repeats : Nat → Nat) :
    {n m k : Nat} → (p : Path branch n (m + 1)) → (chosen : Fin (branch m)) →
      (q : Path branch m k) → (slots : Slots branch n → Fin t → MixedSupport.Slot) →
        WholeArraySampler.Tape rows repeats (p.append (.step chosen q)) slots ≃
          Exterior rows repeats p slots ×
            (Calls rows repeats p chosen q slots ×
              BelowTape rows repeats chosen q (cutSlots p slots))
body · 16 lines
  | _, _, _, .refl _, chosen, q, slots =>
      (WholeCutSampler.stepEquiv chosen
        (WholeArraySampler.RootTape rows repeats (.step chosen q) slots)
        (WholeArraySampler.Tape rows repeats q (childSlots slots chosen))
        (fun j => Arrays (childSlots slots j.val) rows)).symm.trans (prependUnit _)
  | n + 1, _, _, .step i p, chosen, q, slots =>
      (WholeCutSampler.stepEquiv i
        (WholeArraySampler.RootTape rows repeats (.step i (p.append (.step chosen q))) slots)
        (WholeArraySampler.Tape rows repeats (p.append (.step chosen q)) (childSlots slots i))
        (fun j => Arrays (childSlots slots j.val) rows)).symm.trans
        ((Equiv.prodCongr
          (Equiv.piCongrRight (fun _ : BucketSampler.Direction (rows (n + 1)) =>
            OriginalTerminalSplit.splitTape F2 repeats (.step i p) (.step chosen q)
              (LeafDomain slots)))
          (Equiv.prodCongr (splitTape rows repeats p chosen q (childSlots slots i))
            (Equiv.refl _))).trans regroupStep)
133
@[simp] theorem splitTape_refl (rows repeats : Nat → Nat) (chosen : Fin (branch m))
    (q : Path branch m k) (slots : Slots branch (m + 1) → Fin t → MixedSupport.Slot)
    (ω : WholeArraySampler.Tape rows repeats (.step chosen q) slots) :
    splitTape rows repeats (.refl (m + 1)) chosen q slots ω =
      ((), (ω (.inl ()), (ω (.inr (.inl ())), fun j => ω (.inr (.inr j))))) := rfl
139
@[simp] theorem splitTape_step_exterior (rows repeats : Nat → Nat) (i : Fin (branch n))
    (p : Path branch n (m + 1)) (chosen : Fin (branch m)) (q : Path branch m k)
    (slots : Slots branch (n + 1) → Fin t → MixedSupport.Slot)
    (ω : WholeArraySampler.Tape rows repeats ((Path.step i p).append (.step chosen q)) slots) :
    (splitTape rows repeats (.step i p) chosen q slots ω).1 =
      ((fun v => (OriginalTerminalSplit.splitTape F2 repeats (.step i p) (.step chosen q)
          (LeafDomain slots) (ω (.inl ()) v)).2),
        ((splitTape rows repeats p chosen q (childSlots slots i) (ω (.inr (.inl ())))).1,
          fun j => ω (.inr (.inr j)))) := rfl
149
@[simp] theorem splitTape_step_rootCall (rows repeats : Nat → Nat) (i : Fin (branch n))
    (p : Path branch n (m + 1)) (chosen : Fin (branch m)) (q : Path branch m k)
    (slots : Slots branch (n + 1) → Fin t → MixedSupport.Slot)
    (ω : WholeArraySampler.Tape rows repeats ((Path.step i p).append (.step chosen q)) slots)
    (v : BucketSampler.Direction (rows (n + 1)))
    (terminal : TerminalCalls.TerminalIndex repeats (.step i p)) :
    (splitTape rows repeats (.step i p) chosen q slots ω).2.1
        (OriginalCutCalls.rootCall rows repeats i p (v, terminal)) =
      (OriginalTerminalSplit.splitTape F2 repeats (.step i p) (.step chosen q)
        (LeafDomain slots) (ω (.inl ()) v)).1 terminal := rfl
160
@[simp] theorem splitTape_step_lowerCall (rows repeats : Nat → Nat) (i : Fin (branch n))
    (p : Path branch n (m + 1)) (chosen : Fin (branch m)) (q : Path branch m k)
    (slots : Slots branch (n + 1) → Fin t → MixedSupport.Slot)
    (ω : WholeArraySampler.Tape rows repeats ((Path.step i p).append (.step chosen q)) slots)
    (call : OriginalCutCalls.Index rows repeats p) :
    (splitTape rows repeats (.step i p) chosen q slots ω).2.1
        (OriginalCutCalls.lowerCall rows repeats i p call) =
      (splitTape rows repeats p chosen q (childSlots slots i) (ω (.inr (.inl ())))).2.1 call := rfl
169
@[simp] theorem splitTape_step_below (rows repeats : Nat → Nat) (i : Fin (branch n))
    (p : Path branch n (m + 1)) (chosen : Fin (branch m)) (q : Path branch m k)
    (slots : Slots branch (n + 1) → Fin t → MixedSupport.Slot)
    (ω : WholeArraySampler.Tape rows repeats ((Path.step i p).append (.step chosen q)) slots) :
    (splitTape rows repeats (.step i p) chosen q slots ω).2.2 =
      (splitTape rows repeats p chosen q (childSlots slots i) (ω (.inr (.inl ())))).2.2 := rfl
176
def exteriorLaw (rows repeats : Nat → Nat) (p : Path branch n (m + 1))
    (slots : Slots branch n → Fin t → MixedSupport.Slot) :
    FiniteDistribution (Exterior rows repeats p slots) := FiniteDistribution.uniform _
180
def callsLaw (rows repeats : Nat → Nat) (p : Path branch n (m + 1))
    (chosen : Fin (branch m)) (q : Path branch m k)
    (slots : Slots branch n → Fin t → MixedSupport.Slot) :
    FiniteDistribution (Calls rows repeats p chosen q slots) :=
body · 2 lines
  FiniteProduct.law (fun _ : OriginalCutCalls.Index rows repeats p =>
    RecursiveSampler.tapeLaw F2 repeats (.step chosen q) (LeafDomain (cutSlots p slots)))
187
def belowLaw (rows repeats : Nat → Nat) (chosen : Fin (branch m)) (q : Path branch m k)
    (slots : Slots branch (m + 1) → Fin t → MixedSupport.Slot) :
    FiniteDistribution (BelowTape rows repeats chosen q slots) :=
body · 3 lines
  (WholeArraySampler.tapeLaw rows repeats q (childSlots slots chosen)).product
    (FiniteProduct.law (fun j : RecursiveSampler.OffPath chosen =>
      FiniteDistribution.uniform (Arrays (childSlots slots j.val) rows)))
194
theorem callsLaw_uniform (rows repeats : Nat → Nat) (p : Path branch n (m + 1))
    (chosen : Fin (branch m)) (q : Path branch m k)
    (slots : Slots branch n → Fin t → MixedSupport.Slot) :
    callsLaw rows repeats p chosen q slots =
      FiniteDistribution.uniform (Calls rows repeats p chosen q slots) := by
proof · 1 line
  simp only [callsLaw, RecursiveSampler.tapeLaw_eq_uniform, UniformLinearImage.law_uniform]
201
theorem belowLaw_uniform (rows repeats : Nat → Nat) (chosen : Fin (branch m))
    (q : Path branch m k) (slots : Slots branch (m + 1) → Fin t → MixedSupport.Slot) :
    belowLaw rows repeats chosen q slots =
      FiniteDistribution.uniform (BelowTape rows repeats chosen q slots) := by
proof · 5 lines
  rw [belowLaw, WholeArraySubtreeSplit.tapeLaw_eq_uniform, UniformLinearImage.law_uniform]
  apply FiniteDistribution.eq_of_weight_eq
  intro x
  simp only [FiniteDistribution.product, FiniteDistribution.uniform,
    Fintype.card_prod, Nat.cast_mul, one_div_mul_one_div]
211
theorem split_tapeLaw (rows repeats : Nat → Nat) (p : Path branch n (m + 1))
    (chosen : Fin (branch m)) (q : Path branch m k)
    (slots : Slots branch n → Fin t → MixedSupport.Slot) :
    (WholeArraySampler.tapeLaw rows repeats (p.append (.step chosen q)) slots).pushforward
        (splitTape rows repeats p chosen q slots) =
      (exteriorLaw rows repeats p slots).product
        ((callsLaw rows repeats p chosen q slots).product
          (belowLaw rows repeats chosen q (cutSlots p slots))) := by
proof · 13 lines
  rw [WholeArraySubtreeSplit.tapeLaw_eq_uniform, FiniteDistribution.pushforward_equiv,
    callsLaw_uniform, belowLaw_uniform]
  unfold exteriorLaw
  apply FiniteDistribution.eq_of_weight_eq
  intro x
  change 1 / (Fintype.card
      (WholeArraySampler.Tape rows repeats (p.append (.step chosen q)) slots) : ℝ) =
    (1 / (Fintype.card (Exterior rows repeats p slots) : ℝ)) *
      ((1 / (Fintype.card (Calls rows repeats p chosen q slots) : ℝ)) *
        (1 / (Fintype.card (BelowTape rows repeats chosen q (cutSlots p slots)) : ℝ)))
  rw [Fintype.card_congr (splitTape rows repeats p chosen q slots),
    Fintype.card_prod, Fintype.card_prod]
  simp only [Nat.cast_mul, one_div, mul_inv]

Xet Storage Details

Size:
12.2 kB
·
Xet hash:
1244a18713c48e285b15161b01264b6ef459d0567193be8ee703157c29b8dba4

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.