File size: 5,692 Bytes
9b6e014 | 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | import Mathlib
import OAI.Probability.BinarySweep.GridBounds.GridSplitWeights
namespace OAI
noncomputable section
open scoped BigOperators Classical
namespace BinaryCoordinateSweeps.GridSplit
variable {X Y : Type*}
def rowPerm (f : Y → Equiv.Perm X) : Equiv.Perm (X×Y) where
toFun xy := (f xy.2 xy.1,xy.2)
invFun xy := ((f xy.2).symm xy.1,xy.2)
left_inv xy := by simp
right_inv xy := by simp
def rowPermHom : (Y → Equiv.Perm X) →* Equiv.Perm (X×Y) where
toFun := rowPerm
map_one' := by ext xy <;> rfl
map_mul' f g := by ext xy <;> rfl
def columnPerm (f : X → Equiv.Perm Y) : Equiv.Perm (X×Y) where
toFun xy := (xy.1,f xy.1 xy.2)
invFun xy := (xy.1,(f xy.1).symm xy.2)
left_inv xy := by simp
right_inv xy := by simp
def columnPermHom : (X → Equiv.Perm Y) →* Equiv.Perm (X×Y) where
toFun := columnPerm
map_one' := by ext xy <;> rfl
map_mul' f g := by ext xy <;> rfl
variable {m n : ℕ} (bits : Fin (m+n) → ℕ)
lemma gridLayer_left (g : GridChoices bits) (j : Fin m) (x : GridSlot bits) :
(slotEquiv bits) (gridLayer bits g (j.castAdd n) x) =
(gridLayer (leftBits bits) (rowChoices bits g (rightSlot bits x)) j (leftSlot bits x),
rightSlot bits x) := by
apply Prod.ext
· simp only
funext i
change gridLayer bits g (j.castAdd n) x (i.castAdd n)=_
by_cases hi : i=j
· subst i
rw [gridLayer_at,gridLayer_at,rowChoices_at]
rfl
· rw [gridLayer_other bits g _ _ (fun he => hi (Fin.castAdd_injective m n he)),
gridLayer_other _ _ _ _ hi]
rfl
· funext i
exact gridLayer_other bits g _ _ (by
intro he
have hh := congrArg (fun i : Fin (m+n) => i.val) he
simp only [Fin.val_natAdd,Fin.val_castAdd] at hh; omega) x
lemma gridLayer_right (g : GridChoices bits) (j : Fin n) (x : GridSlot bits) :
(slotEquiv bits) (gridLayer bits g (j.natAdd m) x) =
(leftSlot bits x,
gridLayer (rightBits bits) (columnChoices bits g (leftSlot bits x)) j (rightSlot bits x)) := by
apply Prod.ext
· funext i
exact gridLayer_other bits g _ _ (by
intro he
have hh := congrArg (fun i : Fin (m+n) => i.val) he
simp only [Fin.val_natAdd,Fin.val_castAdd] at hh; omega) x
· simp only
funext i
change gridLayer bits g (j.natAdd m) x (i.natAdd m)=_
by_cases hi : i=j
· subst i
rw [gridLayer_at,gridLayer_at,columnChoices_at]
rfl
· rw [gridLayer_other bits g _ _ (fun he => hi (Fin.natAdd_injective n m he)),
gridLayer_other _ _ _ _ hi]
rfl
lemma layer_left_congr (g : GridChoices bits) (j : Fin m) :
(slotEquiv bits).permCongr (gridLayer bits g (j.castAdd n)) =
rowPerm (fun y => gridLayer (leftBits bits) (rowChoices bits g y) j) := by
apply Equiv.ext
intro xy
have he := gridLayer_left bits g j ((slotEquiv bits).symm xy)
change (slotEquiv bits) (gridLayer bits g (j.castAdd n) ((slotEquiv bits).symm xy))= _
rw [he]
have ht := (slotEquiv bits).apply_symm_apply xy
rw [show leftSlot bits ((slotEquiv bits).symm xy)=xy.1 from congrArg Prod.fst ht,
show rightSlot bits ((slotEquiv bits).symm xy)=xy.2 from congrArg Prod.snd ht]
rfl
lemma layer_right_congr (g : GridChoices bits) (j : Fin n) :
(slotEquiv bits).permCongr (gridLayer bits g (j.natAdd m)) =
columnPerm (fun x => gridLayer (rightBits bits) (columnChoices bits g x) j) := by
apply Equiv.ext
intro xy
have he := gridLayer_right bits g j ((slotEquiv bits).symm xy)
change (slotEquiv bits) (gridLayer bits g (j.natAdd m) ((slotEquiv bits).symm xy))= _
rw [he]
have ht := (slotEquiv bits).apply_symm_apply xy
rw [show leftSlot bits ((slotEquiv bits).symm xy)=xy.1 from congrArg Prod.fst ht,
show rightSlot bits ((slotEquiv bits).symm xy)=xy.2 from congrArg Prod.snd ht]
rfl
lemma prod_rows (L : List (Y → Equiv.Perm X)) :
(L.map rowPerm).prod=rowPerm (fun y => (L.map (fun f => f y)).prod) := by
induction L with
| nil => rfl
| cons f L ih =>
simp only [List.map_cons,List.prod_cons,ih]
apply Equiv.ext
intro xy
rfl
lemma prod_columns (L : List (X → Equiv.Perm Y)) :
(L.map columnPerm).prod=columnPerm (fun x => (L.map (fun f => f x)).prod) := by
induction L with
| nil => rfl
| cons f L ih =>
simp only [List.map_cons,List.prod_cons,ih]
apply Equiv.ext
intro xy
rfl
theorem gridSweep_split (g : GridChoices bits) :
(slotEquiv bits).permCongr (gridSweep bits g) =
columnPerm (fun x => gridSweep (rightBits bits) (columnChoices bits g x)) *
rowPerm (fun y => gridSweep (leftBits bits) (rowChoices bits g y)) := by
change (slotEquiv bits).permCongrHom (gridSweep bits g)=_
unfold gridSweep
rw [List.ofFn_add,List.reverse_append,List.prod_append]
rw [map_mul]
congr 1
· rw [map_list_prod (slotEquiv bits).permCongrHom,List.map_reverse,List.map_ofFn]
change (List.ofFn (fun j : Fin n => (slotEquiv bits).permCongr (gridLayer bits g (j.natAdd m)))).reverse.prod=_
simp_rw [layer_right_congr]
simpa only [List.map_reverse,List.map_ofFn,Function.comp_def] using
(prod_columns (List.ofFn (fun j : Fin n => fun x =>
gridLayer (rightBits bits) (columnChoices bits g x) j)).reverse)
· rw [map_list_prod (slotEquiv bits).permCongrHom,List.map_reverse,List.map_ofFn]
change (List.ofFn (fun j : Fin m => (slotEquiv bits).permCongr (gridLayer bits g (j.castAdd n)))).reverse.prod=_
simp_rw [layer_left_congr]
simpa only [List.map_reverse,List.map_ofFn,Function.comp_def] using
(prod_rows (List.ofFn (fun j : Fin m => fun y =>
gridLayer (leftBits bits) (rowChoices bits g y) j)).reverse)
end BinaryCoordinateSweeps.GridSplit
end
end OAI
|