introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
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