Download data/lean/OAI/Computability/FourierCircuit/PiTensor.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 19.2 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/FourierCircuit/PiTensor.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/FourierCircuit/PiTensor.lean
-
curl -L -o PiTensor.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/FourierCircuit/PiTensor.lean
19.2 kB
| import OAI.Computability.FourierCircuit.WordScheduling | |
| namespace OAI | |
| section | |
| noncomputable section | |
| namespace ExactFourier.PiTensor | |
| variable {ΞΉ : Type} [Fintype ΞΉ] [DecidableEq ΞΉ] | |
| {D : ΞΉβType} [β i,Fintype (D i)] [β i,DecidableEq (D i)] | |
| def matrix (A : β i,Matrix (D i) (D i) β) : Matrix (β i,D i) (β i,D i) β := | |
| fun x y=>β i,A i (x i) (y i) | |
| @[simp] theorem one | |
| {ΞΉ : Type} [Fintype ΞΉ] [DecidableEq ΞΉ] {D : ΞΉ β Type} [(i : ΞΉ) β Fintype (D i)] [(i : ΞΉ) β DecidableEq (D i)] : matrix (1 : β i,Matrix (D i) (D i) β)=1 := by | |
| classical | |
| ext x y | |
| by_cases h : x=y | |
| Β· subst y; simp [matrix] | |
| Β· rw [Matrix.one_apply,ite_eq_right h] | |
| obtain β¨i,hiβ© := Function.ne_iff.mp h | |
| exact Finset.prod_eq_zero (Finset.mem_univ i) (by simp [hi]) | |
| theorem mul | |
| {ΞΉ : Type} [Fintype ΞΉ] [DecidableEq ΞΉ] {D : ΞΉ β Type} [(i : ΞΉ) β Fintype (D i)] [(i : ΞΉ) β DecidableEq (D i)] (A B : β i,Matrix (D i) (D i) β) : matrix (A*B)=matrix A*matrix B := by | |
| classical | |
| ext x y | |
| simp only [matrix,Pi.mul_apply,Matrix.mul_apply] | |
| simp_rw [β Finset.prod_mul_distrib] | |
| exact Fintype.prod_sum fun i j=>A i (x i) j*B i j (y i) | |
| def hom : (β i,Matrix (D i) (D i) β) β* Matrix (β i,D i) (β i,D i) β where | |
| toFun := matrix | |
| map_one' := one | |
| map_mul' := mul | |
| theorem unit (A : β i,Matrix (D i) (D i) β) (hA : β i,IsUnit (A i)) : IsUnit (matrix A) := | |
| by | |
| choose U hU using hA | |
| have he : A=fun i=>(U i : Matrix (D i) (D i) β) := by funext i; exact (hU i).symm | |
| rw [he] | |
| exact (Units.isUnit (show (β i,Matrix (D i) (D i) β)Λ£ from | |
| β¨fun i=>U i,fun i=>(U i)β»ΒΉ,by ext i; simp,by ext i; simpβ©)).map hom | |
| def axisCoordinates (i : ΞΉ) : (Ξ£ _ : β j : {j // jβ i},D j,D i) β (β j,D j) := | |
| (Equiv.sigmaEquivProd _ _).trans ((Equiv.prodComm _ _).trans (Equiv.piSplitAt i D).symm) | |
| @[simp] theorem axisCoordinates_symm | |
| {ΞΉ : Type} [Fintype ΞΉ] [DecidableEq ΞΉ] {D : ΞΉ β Type} [(i : ΞΉ) β Fintype (D i)] [(i : ΞΉ) β DecidableEq (D i)] (i : ΞΉ) (x : β j,D j) : | |
| (axisCoordinates i).symm x=β¨fun j=>x j,x iβ© := rfl | |
| theorem axis_matrix | |
| {ΞΉ : Type} [Fintype ΞΉ] [DecidableEq ΞΉ] {D : ΞΉ β Type} [(i : ΞΉ) β Fintype (D i)] [(i : ΞΉ) β DecidableEq (D i)] (i : ΞΉ) (A : Matrix (D i) (D i) β) : | |
| matrix (Function.update (1 : β j,Matrix (D j) (D j) β) i A)= | |
| Matrix.reindex (axisCoordinates i) (axisCoordinates i) (Matrix.blockDiagonal' (fun _=>A)) := by | |
| classical | |
| ext x y | |
| simp only [Matrix.reindex_apply,Matrix.submatrix_apply,axisCoordinates_symm] | |
| change (β j,(Function.update (1 : β j,Matrix (D j) (D j) β) i A) j (x j) (y j))=_ | |
| rw [Fintype.prod_eq_mul_prod_compl i] | |
| simp only [Finset.compl_eq_univ_sdiff] | |
| simp only [Function.update_self] | |
| by_cases h : (fun j : {j // jβ i}=>x j)=(fun j : {j // jβ i}=>y j) | |
| Β· have hp : (β j β Finset.univ \ {i}, | |
| Function.update (1 : β j,Matrix (D j) (D j) β) i A j (x j) (y j))=1 := by | |
| apply Finset.prod_eq_one | |
| intro j hj | |
| have hj' : jβ i := by simpa using (Finset.mem_sdiff.mp hj).2 | |
| have he := congrFun h β¨j,hj'β© | |
| simp [Function.update_of_ne hj',he] | |
| rw [hp,mul_one] | |
| simp [Matrix.blockDiagonal'_apply,h] | |
| Β· have hp : (β j β Finset.univ \ {i}, | |
| Function.update (1 : β j,Matrix (D j) (D j) β) i A j (x j) (y j))=0 := by | |
| obtain β¨j,hjβ© := Function.ne_iff.mp h | |
| apply Finset.prod_eq_zero (i := j.val) | |
| Β· simp [j.property] | |
| Β· simp [Function.update_of_ne j.property,hj] | |
| rw [hp,mul_zero] | |
| simp [Matrix.blockDiagonal'_apply,h] | |
| end ExactFourier.PiTensor | |
| end | |
| end | |
| section | |
| noncomputable section | |
| namespace ExactFourier.Packing | |
| variable {Ο : Type} {D : ΟβType} [β t,Fintype (D t)] [β t,DecidableEq (D t)] | |
| {A : β t,Matrix (D t) (D t) β} | |
| {ΞΉ : Type} [Fintype ΞΉ] [DecidableEq ΞΉ] | |
| {E : ΞΉβType} [β i,Fintype (E i)] [β i,DecidableEq (E i)] | |
| def Word.axis (i : ΞΉ) (W : Word D A (E i)) : Word D A (β i,E i) := | |
| (Word.blockSum (fun _ : β j : {j // jβ i},E j=>W)).reindex (PiTensor.axisCoordinates i) | |
| @[simp] theorem Word.matrix_axis (i : ΞΉ) (W : Word D A (E i)) : | |
| (W.axis i).matrix=PiTensor.matrix (Function.update (1 : β j,Matrix (E j) (E j) β) i W.matrix) := by | |
| rw [Word.axis,Word.matrix_reindex,Word.matrix_blockSum,PiTensor.axis_matrix] | |
| theorem Word.count_axis [DecidableEq Ο] (i : ΞΉ) (W : Word D A (E i)) (t : Ο) : | |
| (W.axis i).count t=Fintype.card (β j : {j // jβ i},E j)*W.count t := by | |
| rw [Word.axis,Word.count,Word.calls_reindex,β Word.count,Word.count_blockSum] | |
| simp | |
| def Word.tensor (W : β i,Word D A (E i)) : Word D A (β i,E i) := | |
| (Finset.univ.toList.map (fun i=>(W i).axis i)).flatten | |
| @[simp] theorem Word.matrix_tensor (W : β i,Word D A (E i)) : | |
| (Word.tensor W).matrix=PiTensor.matrix (fun i=>(W i).matrix) := by | |
| rw [Word.tensor,Word.matrix_flatten,List.map_map] | |
| simp only [Function.comp_def,Word.matrix_axis] | |
| let upd := fun i=>Function.update (1 : β i,Matrix (E i) (E i) β) i (W i).matrix | |
| change (Finset.univ.toList.map (fun i=>PiTensor.hom (upd i))).prod=_ | |
| have hm : Finset.univ.toList.map (fun i=>PiTensor.hom (upd i))= | |
| (Finset.univ.toList.map upd).map PiTensor.hom := (List.map_map ..).symm | |
| rw [hm,β map_list_prod] | |
| change PiTensor.matrix ((Finset.univ.toList.map upd).prod)=_ | |
| congr 1 | |
| funext i | |
| rw [Embedded.list_update_prod _ _ (Finset.nodup_toList _)] | |
| simp | |
| theorem Word.count_tensor [DecidableEq Ο] (W : β i,Word D A (E i)) (t : Ο) : | |
| (Word.tensor W).count t=β i,Fintype.card (β j : {j // jβ i},E j)*(W i).count t := by | |
| rw [Word.tensor,Word.count,Word.calls_flatten,List.count_flatten] | |
| simp only [List.map_map,Function.comp_def] | |
| change (Finset.univ.toList.map (fun i=>((W i).axis i).count t)).sum=_ | |
| simp [Word.count_axis] | |
| end ExactFourier.Packing | |
| end | |
| end | |
| section | |
| noncomputable section | |
| namespace ExactFourier.Packing | |
| variable {Ο : Type} {D : ΟβType} [β t,Fintype (D t)] [β t,DecidableEq (D t)] | |
| {A : β t,Matrix (D t) (D t) β} | |
| {Ξ± Ξ² : Type} [Fintype Ξ±] [Fintype Ξ²] [DecidableEq Ξ±] [DecidableEq Ξ²] | |
| def Word.leftTensor (W : Word D A Ξ±) : Word D A (Ξ±ΓΞ²) := | |
| (Word.blockSum (fun _ : Ξ²=>W)).reindex ((Equiv.sigmaEquivProd Ξ² Ξ±).trans (Equiv.prodComm Ξ² Ξ±)) | |
| def Word.rightTensor (V : Word D A Ξ²) : Word D A (Ξ±ΓΞ²) := | |
| (Word.blockSum (fun _ : Ξ±=>V)).reindex (Equiv.sigmaEquivProd Ξ± Ξ²) | |
| theorem Word.matrix_leftTensor (W : Word D A Ξ±) : | |
| (W.leftTensor (Ξ² := Ξ²)).matrix=Matrix.kronecker W.matrix (1 : Matrix Ξ² Ξ² β) := by | |
| rw [Word.leftTensor,Word.matrix_reindex,Word.matrix_blockSum] | |
| ext β¨a,bβ© β¨c,dβ© | |
| by_cases h : b=d | |
| Β· subst d; simp [Matrix.reindex_apply] | |
| Β· simp [Matrix.reindex_apply,Matrix.blockDiagonal'_apply,h] | |
| theorem Word.matrix_rightTensor (V : Word D A Ξ²) : | |
| (V.rightTensor (Ξ± := Ξ±)).matrix=Matrix.kronecker (1 : Matrix Ξ± Ξ± β) V.matrix := by | |
| rw [Word.rightTensor,Word.matrix_reindex,Word.matrix_blockSum] | |
| ext β¨a,bβ© β¨c,dβ© | |
| by_cases h : a=c | |
| Β· subst c; simp [Matrix.reindex_apply] | |
| Β· simp [Matrix.reindex_apply,Matrix.blockDiagonal'_apply,h] | |
| theorem Word.count_leftTensor [DecidableEq Ο] (W : Word D A Ξ±) (t : Ο) : | |
| (W.leftTensor (Ξ² := Ξ²)).count t=Fintype.card Ξ²*W.count t := by | |
| rw [Word.leftTensor,Word.count,Word.calls_reindex,β Word.count,Word.count_blockSum] | |
| simp | |
| theorem Word.count_rightTensor [DecidableEq Ο] (V : Word D A Ξ²) (t : Ο) : | |
| (V.rightTensor (Ξ± := Ξ±)).count t=Fintype.card Ξ±*V.count t := by | |
| rw [Word.rightTensor,Word.count,Word.calls_reindex,β Word.count,Word.count_blockSum] | |
| simp | |
| def Word.kronecker (W : Word D A Ξ±) (V : Word D A Ξ²) : Word D A (Ξ±ΓΞ²) := | |
| W.leftTensor++V.rightTensor | |
| @[simp] theorem Word.matrix_kronecker (W : Word D A Ξ±) (V : Word D A Ξ²) : | |
| (W.kronecker V).matrix=Matrix.kronecker W.matrix V.matrix := by | |
| rw [Word.kronecker,Word.matrix_append,Word.matrix_leftTensor,Word.matrix_rightTensor] | |
| simpa using (Matrix.mul_kronecker_mul W.matrix (1 : Matrix Ξ± Ξ± β) | |
| (1 : Matrix Ξ² Ξ² β) V.matrix).symm | |
| theorem Word.count_kronecker [DecidableEq Ο] (W : Word D A Ξ±) (V : Word D A Ξ²) (t : Ο) : | |
| (W.kronecker V).count t=Fintype.card Ξ²*W.count t+Fintype.card Ξ±*V.count t := by | |
| rw [Word.kronecker,Word.count_append,Word.count_leftTensor,Word.count_rightTensor] | |
| end ExactFourier.Packing | |
| end | |
| end | |
| section | |
| noncomputable section | |
| namespace ExactFourier.Packing | |
| variable {Ο : Type} [Fintype Ο] [DecidableEq Ο] | |
| {E : ΟβType} [β s,Fintype (E s)] [β s,DecidableEq (E s)] | |
| /-- The two tensor axes choose block-copy labels independently, even for repeated species. -/ | |
| def sectorCoordinates (k : Οββ) : | |
| (Ξ£ p : ΟΓΟ,(Fin (k p.1)ΓFin (k p.2))Γ(E p.1ΓE p.2)) β | |
| ((Ξ£ s,Fin (k s)ΓE s)Γ(Ξ£ s,Fin (k s)ΓE s)) where | |
| toFun x := (β¨x.1.1,x.2.1.1,x.2.2.1β©,β¨x.1.2,x.2.1.2,x.2.2.2β©) | |
| invFun x := β¨(x.1.1,x.2.1),(x.1.2.1,x.2.2.1),(x.1.2.2,x.2.2.2)β© | |
| left_inv := by rintro β¨β¨s,tβ©,β¨i,jβ©,a,bβ©; rfl | |
| right_inv := by rintro β¨β¨s,i,aβ©,β¨t,j,bβ©β©; rfl | |
| def speciesInventory (k : Οββ) (B : β s,Matrix (E s) (E s) β) : | |
| Matrix (Ξ£ s,Fin (k s)ΓE s) (Ξ£ s,Fin (k s)ΓE s) β := | |
| Matrix.blockDiagonal' fun s=>Matrix.kronecker (1 : Matrix (Fin (k s)) (Fin (k s)) β) (B s) | |
| def sectorMatrix (k : Οββ) (B : β s,Matrix (E s) (E s) β) : | |
| Matrix (Ξ£ p : ΟΓΟ,(Fin (k p.1)ΓFin (k p.2))Γ(E p.1ΓE p.2)) | |
| (Ξ£ p : ΟΓΟ,(Fin (k p.1)ΓFin (k p.2))Γ(E p.1ΓE p.2)) β := | |
| Matrix.blockDiagonal' fun p=>Matrix.kronecker (1 : Matrix (Fin (k p.1)ΓFin (k p.2)) _ β) | |
| (Matrix.kronecker (B p.1) (B p.2)) | |
| theorem inventory_tensor_sectors | |
| {Ο : Type} [Fintype Ο] [DecidableEq Ο] {E : Ο β Type} [(s : Ο) β Fintype (E s)] [(s : Ο) β DecidableEq (E s)] (k : Οββ) (B : β s,Matrix (E s) (E s) β) : | |
| Matrix.kronecker (speciesInventory k B) (speciesInventory k B)= | |
| Matrix.reindex (sectorCoordinates k) (sectorCoordinates k) (sectorMatrix k B) := by | |
| classical | |
| ext β¨β¨s,i,aβ©,β¨t,j,bβ©β© β¨β¨s',i',a'β©,β¨t',j',b'β©β© | |
| by_cases hs : s=s' | |
| Β· subst s' | |
| by_cases ht : t=t' | |
| Β· subst t' | |
| by_cases hi : i=i' | |
| Β· subst i'; by_cases hj : j=j' | |
| Β· subst j'; simp [speciesInventory,sectorMatrix,Matrix.reindex_apply,sectorCoordinates] | |
| Β· simp [speciesInventory,sectorMatrix,Matrix.reindex_apply,sectorCoordinates,hj] | |
| Β· simp [speciesInventory,sectorMatrix,Matrix.reindex_apply,sectorCoordinates,hi] | |
| Β· simp [speciesInventory,sectorMatrix,Matrix.reindex_apply,sectorCoordinates, | |
| Matrix.blockDiagonal'_apply,ht] | |
| Β· simp [speciesInventory,sectorMatrix,Matrix.reindex_apply,sectorCoordinates, | |
| Matrix.blockDiagonal'_apply,hs] | |
| end ExactFourier.Packing | |
| end | |
| end | |
| section | |
| noncomputable section | |
| namespace ExactFourier.Packing | |
| variable {Ο Ο Ο : Type} [Fintype Ο] [Fintype Ο] [DecidableEq Ο] [DecidableEq Ο] | |
| {D : ΟβType} [β t,Fintype (D t)] [β t,DecidableEq (D t)] | |
| {A : β t,Matrix (D t) (D t) β} | |
| def colorEquiv (u : ΟβΟ) (v : ΟβΟ) (e : ΟβΟ) (he : β p,u p=v (e p)) : | |
| (Ξ£ p,D (u p))β(Ξ£ r,D (v r)) := | |
| Equiv.sigmaCongr e (fun p=>Equiv.cast (congrArg D (he p))) | |
| @[simp] theorem colorEquiv_fst | |
| {Ο : Type} {Ο : Type} {Ο : Type} [Fintype Ο] [Fintype Ο] [DecidableEq Ο] [DecidableEq Ο] {D : Ο β Type} [(t : Ο) β Fintype (D t)] [(t : Ο) β DecidableEq (D t)] (u : ΟβΟ) (v : ΟβΟ) (e : ΟβΟ) (he : β p,u p=v (e p)) | |
| (x : Ξ£ p,D (u p)) : (colorEquiv u v e he x).1=e x.1 := rfl | |
| theorem color_cast_apply | |
| {Ο : Type} {D : Ο β Type} [(t : Ο) β Fintype (D t)] [(t : Ο) β DecidableEq (D t)] {A : (t : Ο) β Matrix (D t) (D t) β} {i j : Ο} (h : i=j) (a b : D i) : | |
| A j (cast (congrArg D h) a) (cast (congrArg D h) b)=A i a b := by cases h; rfl | |
| theorem coloredBlock_on | |
| {Ο : Type} {Ο : Type} {Ο : Type} [Fintype Ο] [Fintype Ο] [DecidableEq Ο] [DecidableEq Ο] {D : Ο β Type} [(t : Ο) β Fintype (D t)] [(t : Ο) β DecidableEq (D t)] {A : (t : Ο) β Matrix (D t) (D t) β} (u : ΟβΟ) (v : ΟβΟ) (e : ΟβΟ) (he : β p,u p=v (e p)) | |
| (x y : Ξ£ p,D (u p)) : | |
| Matrix.blockDiagonal' (fun r=>A (v r)) (colorEquiv u v e he x) (colorEquiv u v e he y)= | |
| Matrix.blockDiagonal' (fun p=>A (u p)) x y := by | |
| rcases x with β¨p,aβ©; rcases y with β¨q,bβ© | |
| by_cases h : p=q | |
| Β· subst q | |
| change Matrix.blockDiagonal' (fun r=>A (v r)) | |
| β¨e p,cast (congrArg D (he p)) aβ© β¨e p,cast (congrArg D (he p)) bβ©=_ | |
| rw [Matrix.blockDiagonal'_apply_eq,Matrix.blockDiagonal'_apply_eq] | |
| exact color_cast_apply (he p) a b | |
| Β· rw [Matrix.blockDiagonal'_apply_ne _ _ _ h] | |
| apply Matrix.blockDiagonal'_apply_ne | |
| exact fun hp=>h (e.injective hp) | |
| theorem coloredBlock_reindex (u : ΟβΟ) (v : ΟβΟ) (e : ΟβΟ) (he : β p,u p=v (e p)) : | |
| Matrix.reindex (colorEquiv u v e he) (colorEquiv u v e he) | |
| (Matrix.blockDiagonal' (fun p=>A (u p)))=Matrix.blockDiagonal' (fun r=>A (v r)) := by | |
| ext x y | |
| obtain β¨x,rflβ© := (colorEquiv u v e he).surjective x | |
| obtain β¨y,rflβ© := (colorEquiv u v e he).surjective y | |
| simp only [Matrix.reindex_apply,Matrix.submatrix_apply,Equiv.symm_apply_apply] | |
| exact (coloredBlock_on u v e he x y).symm | |
| /-- Equal multiplicities give an exact color-preserving matching of call blocks. -/ | |
| theorem exists_colorEquiv | |
| {Ο : Type} {Ο : Type} {Ο : Type} [Fintype Ο] [Fintype Ο] [DecidableEq Ο] [DecidableEq Ο] [Fintype Ο] [DecidableEq Ο] (u : ΟβΟ) (v : ΟβΟ) | |
| (h : β t,Fintype.card {p // u p=t}=Fintype.card {r // v r=t}) : | |
| β e : ΟβΟ,β p,u p=v (e p) := by | |
| let f := fun t=>Fintype.equivOfCardEq (h t) | |
| let e := (Equiv.sigmaFiberEquiv u).symm.trans | |
| ((Equiv.sigmaCongrRight f).trans (Equiv.sigmaFiberEquiv v)) | |
| refine β¨e,?_β© | |
| intro p | |
| exact (f (u p) β¨p,rflβ©).property.symm | |
| end ExactFourier.Packing | |
| end | |
| end | |
| section | |
| noncomputable section | |
| namespace ExactFourier.Packing | |
| variable {Ο : Type} [Fintype Ο] [DecidableEq Ο] {D : ΟβType} [β t,Fintype (D t)] [β t,DecidableEq (D t)] | |
| {A : β t,Matrix (D t) (D t) β} | |
| abbrev optionalDomain (D : ΟβType) : Option ΟβType | |
| | none => Empty | |
| | some t => D t | |
| instance optionalDomain_fintype (t : Option Ο) : Fintype (optionalDomain D t) := by | |
| cases t <;> dsimp [optionalDomain] <;> infer_instance | |
| instance optionalDomain_decEq (t : Option Ο) : DecidableEq (optionalDomain D t) := by | |
| cases t <;> dsimp [optionalDomain] <;> infer_instance | |
| def optionalMatrix (A : β t,Matrix (D t) (D t) β) : β t,Matrix (optionalDomain D t) (optionalDomain D t) β | |
| | none => 1 | |
| | some t => A t | |
| variable {Ξ± : Type} [Fintype Ξ±] [DecidableEq Ξ±] | |
| def Step.activeTuple : (s : Step D A Ξ±) β optionalDomain D s.kind βͺ Ξ± | |
| | .mono _ _ => β¨Empty.elim,by intro a; exact a.elimβ© | |
| | .call _ e => e | |
| def Step.monoPart : Step D A Ξ±βMatrix Ξ± Ξ± β | |
| | .mono M _ => M | |
| | .call _ _ => 1 | |
| theorem Step.monoPart_monomial | |
| {Ο : Type} [Fintype Ο] [DecidableEq Ο] {D : Ο β Type} [(t : Ο) β Fintype (D t)] [(t : Ο) β DecidableEq (D t)] {A : (t : Ο) β Matrix (D t) (D t) β} {Ξ± : Type} [Fintype Ξ±] [DecidableEq Ξ±] (s : Step D A Ξ±) : MonomialMatrix s.monoPart := by | |
| cases s with | |
| | mono M h => exact h | |
| | call t e => exact MonomialMatrix.one | |
| theorem Step.decompose | |
| {Ο : Type} [Fintype Ο] [DecidableEq Ο] {D : Ο β Type} [(t : Ο) β Fintype (D t)] [(t : Ο) β DecidableEq (D t)] {A : (t : Ο) β Matrix (D t) (D t) β} {Ξ± : Type} [Fintype Ξ±] [DecidableEq Ξ±] (s : Step D A Ξ±) : | |
| s.matrix=s.monoPart*Embedded.matrix s.activeTuple (optionalMatrix A s.kind) := by | |
| cases s with | |
| | mono M hm => | |
| let e : Empty βͺ Ξ± := β¨Empty.elim,by intro a; exact a.elimβ© | |
| change M=M*Embedded.matrix e (1 : Matrix Empty Empty β) | |
| rw [Embedded.matrix_one,mul_one] | |
| | call t e => | |
| change Embedded.matrix e (A t)=1*Embedded.matrix e (A t) | |
| rw [one_mul] | |
| variable {Ο : Type} [Fintype Ο] [DecidableEq Ο] | |
| abbrev CallIndex (u : ΟβOption Ο) := Ξ£ t,{p // u p=some t} | |
| def callSite (u : ΟβOption Ο) : CallIndex u βͺ Ο where | |
| toFun c := c.2.1 | |
| inj' := by | |
| rintro β¨i,β¨p,hpβ©β© β¨j,β¨q,hqβ©β© h | |
| change p=q at h; subst q | |
| have hij : i=j := Option.some.inj (hp.symm.trans hq) | |
| subst j; rfl | |
| def activeTo (u : ΟβOption Ο) (x : Ξ£ c : CallIndex u,D c.1) : Ξ£ p,optionalDomain D (u p) := | |
| β¨x.1.2.1,cast (congrArg (optionalDomain D) x.1.2.2.symm) x.2β© | |
| theorem activeTo_injective | |
| {Ο : Type} [Fintype Ο] [DecidableEq Ο] {D : Ο β Type} [(t : Ο) β Fintype (D t)] [(t : Ο) β DecidableEq (D t)] {Ο : Type} [Fintype Ο] [DecidableEq Ο] (u : ΟβOption Ο) : Function.Injective (activeTo (D := D) u) := by | |
| rintro β¨β¨i,p,hpβ©,aβ© β¨β¨j,q,hqβ©,bβ© h | |
| have hpq := congrArg Sigma.fst h | |
| change p=q at hpq | |
| subst q | |
| have hij : i=j := Option.some.inj (hp.symm.trans hq) | |
| subst j | |
| have hab := eq_of_heq (Sigma.mk.inj_iff.mp h).2 | |
| have ha : a=b := (Equiv.cast (congrArg (optionalDomain D) hp.symm)).injective hab | |
| subst b | |
| rfl | |
| theorem activeTo_surjective | |
| {Ο : Type} [Fintype Ο] [DecidableEq Ο] {D : Ο β Type} [(t : Ο) β Fintype (D t)] [(t : Ο) β DecidableEq (D t)] {Ο : Type} [Fintype Ο] [DecidableEq Ο] (u : ΟβOption Ο) : Function.Surjective (activeTo (D := D) u) := by | |
| rintro β¨p,aβ© | |
| have hh : β t,u p=some t := by | |
| cases h : u p with | |
| | none => exact (cast (congrArg (optionalDomain D) h) a : Empty).elim | |
| | some t => exact β¨t,rflβ© | |
| obtain β¨t,hpβ© := hh | |
| refine β¨β¨β¨t,p,hpβ©,cast (congrArg (optionalDomain D) hp) aβ©,?_β© | |
| simp [activeTo] | |
| def activeEquiv (u : ΟβOption Ο) : | |
| (Ξ£ c : CallIndex u,D c.1)β(Ξ£ p,optionalDomain D (u p)) := | |
| Equiv.ofBijective (activeTo u) β¨activeTo_injective u,activeTo_surjective uβ© | |
| @[simp] theorem activeEquiv_fst (u : ΟβOption Ο) (x : Ξ£ c : CallIndex u,D c.1) : | |
| (activeEquiv u x).1=x.1.2.1 := rfl | |
| theorem activeEquiv_on (u : ΟβOption Ο) (x y : Ξ£ c : CallIndex u,D c.1) : | |
| Matrix.blockDiagonal' (fun p=>optionalMatrix A (u p)) (activeEquiv u x) (activeEquiv u y)= | |
| Matrix.blockDiagonal' (fun c : CallIndex u=>A c.1) x y := by | |
| rcases x with β¨β¨i,p,hpβ©,aβ©; rcases y with β¨β¨j,q,hqβ©,bβ© | |
| by_cases hpq : p=q | |
| Β· subst q | |
| have hij : i=j := Option.some.inj (hp.symm.trans hq) | |
| subst j | |
| change Matrix.blockDiagonal' _ β¨p,_β© β¨p,_β©=_ | |
| rw [Matrix.blockDiagonal'_apply_eq,Matrix.blockDiagonal'_apply_eq] | |
| exact color_cast_apply (A := optionalMatrix A) hp.symm a b | |
| Β· rw [Matrix.blockDiagonal'_apply_ne _ _ _ (show (β¨i,p,hpβ© : CallIndex u)β β¨j,q,hqβ© from | |
| fun h=>hpq (congrArg (fun c : CallIndex u=>c.2.1) h))] | |
| exact Matrix.blockDiagonal'_apply_ne _ _ _ hpq | |
| theorem activeEquiv_reindex (u : ΟβOption Ο) : | |
| Matrix.reindex (activeEquiv (D := D) u) (activeEquiv u) | |
| (Matrix.blockDiagonal' (fun c : CallIndex u=>A c.1))= | |
| Matrix.blockDiagonal' (fun p=>optionalMatrix A (u p)) := by | |
| ext x y | |
| obtain β¨x,rflβ© := (activeEquiv (D := D) u).surjective x | |
| obtain β¨y,rflβ© := (activeEquiv (D := D) u).surjective y | |
| simp only [Matrix.reindex_apply,Matrix.submatrix_apply,Equiv.symm_apply_apply] | |
| exact (activeEquiv_on u x y).symm | |
| end ExactFourier.Packing | |
| end | |
| end | |
| end OAI | |