cfahlgren1's picture
download
raw
12.8 kB
import Mathlib
import OAI.RepresentationTheory.Saxl.Main
import OAI.RepresentationTheory.UniversalSquare.Contraction.VectorDomainsCore
namespace OAI
/-! Compact Domains Core. -/
section
open scoped BigOperators
namespace Saxl.Columns
abbrev CompactDomain (n : ℕ) := Option (Equiv.Perm (Fin n) × Finset (Fin n))
def CompactDomain.describe {n : ℕ} : CompactDomain n → Finset (Equiv.Perm (Fin n))
| none => ∅
| some (π,s) => Finset.univ.filter (fun σ => ∀ i, i ∉ s → σ i = π i)
lemma CompactDomain.mem_describe {n : ℕ} (π σ : Equiv.Perm (Fin n)) (s : Finset (Fin n)) :
σ ∈ CompactDomain.describe (some (π,s)) ↔ ∀ i, i ∉ s → σ i = π i := by
simp [describe]
def CompactDomain.full (n : ℕ) : CompactDomain n := some (1,Finset.univ)
lemma CompactDomain.describe_full (n : ℕ) : (full n).describe = Finset.univ := by
ext σ; simp [full,mem_describe]
def CompactDomain.atValue {n : ℕ} : CompactDomain n → Fin n → ℕ → CompactDomain n
| none, _, _ => none
| some (π,s), i, j =>
if hj : j < n then
let k := π.symm ⟨j,hj⟩
if i ∈ s then
if k ∈ s then some (π * Equiv.swap i k,s.erase i) else none
else if (π i).val = j then some (π,s) else none
else none
lemma CompactDomain.describe_atValue {n : ℕ} (D : CompactDomain n) (i : Fin n) (j : ℕ) :
(D.atValue i j).describe = D.describe.filter (fun σ => (σ i).val = j) := by
cases D with
| none => simp [atValue,describe]
| some ds =>
rcases ds with ⟨π,s⟩
ext σ
simp only [Finset.mem_filter,mem_describe]
by_cases hj : j < n
· let k := π.symm ⟨j,hj⟩
have hk : π k = ⟨j,hj⟩ := π.apply_symm_apply _
by_cases hi : i ∈ s
· by_cases hks : k ∈ s
· simp only [atValue,dite_eq_left hj,ite_eq_left hi,show π.symm ⟨j,hj⟩ ∈ s from hks,
ite_true,mem_describe]
constructor
· intro h
constructor
· intro x hx
have hxi : x ≠ i := by intro he; subst x; exact hx hi
have hxk : x ≠ π.symm ⟨j,hj⟩ := by intro he; subst x; exact hx hks
simpa only [Equiv.Perm.mul_apply,Equiv.swap_apply_of_ne_of_ne hxi hxk] using
h x (by simp [hx])
· have hh := h i (by simp)
simpa [Equiv.Perm.mul_apply,k] using congrArg Fin.val hh
· rintro ⟨h,hv⟩ x hx
by_cases hxi : x = i
· subst x
simpa [Equiv.Perm.mul_apply,k] using (Fin.ext hv : σ i = ⟨j,hj⟩)
· have hxs : x ∉ s := by simpa [Finset.mem_erase,hxi] using hx
have hxk : x ≠ π.symm ⟨j,hj⟩ := by intro he; subst x; exact hxs hks
simpa only [Equiv.Perm.mul_apply,Equiv.swap_apply_of_ne_of_ne hxi hxk] using h x hxs
· simp only [atValue,dite_eq_left hj,ite_eq_left hi,show π.symm ⟨j,hj⟩ ∉ s from hks,
ite_false,describe,Finset.notMem_empty,false_iff,not_and]
intro h hv
have hki : k = i := σ.injective ((h k hks).trans (hk.trans (Fin.ext hv).symm))
exact hks (hki.symm ▸ hi)
· by_cases hv : (π i).val = j
· simp only [atValue,dite_eq_left hj,ite_eq_right hi,ite_eq_left hv,mem_describe]
exact ⟨fun h => ⟨h,(congrArg Fin.val (h i hi)).trans hv⟩,fun h => h.1⟩
· simp only [atValue,dite_eq_left hj,ite_eq_right hi,ite_eq_right hv,describe,Finset.notMem_empty,
false_iff,not_and]
intro h he
exact hv ((congrArg Fin.val (h i hi)).symm.trans he)
· simp only [atValue,dite_eq_right hj,describe,Finset.notMem_empty,false_iff,not_and]
intro h hv
exact hj (hv ▸ (σ i).isLt)
def CompactDomain.vanished {n : ℕ} (D : CompactDomain n) : Bool := D.isNone
lemma CompactDomain.describe_vanished {n : ℕ} (D : CompactDomain n) :
decide (D.describe = ∅) = D.vanished := by
cases D with
| none => rfl
| some ds =>
rcases ds with ⟨π,s⟩
have hh : π ∈ CompactDomain.describe (some (π,s)) := by simp only [mem_describe]; tauto
have hn := Finset.ne_empty_of_mem hh
simp only [hn,decide_false,vanished,Option.isNone_some]
lemma compact_sum_sign {n : ℕ} (π : Equiv.Perm (Fin n)) (s : Finset (Fin n)) :
(∑ σ ∈ CompactDomain.describe (some (π,s)), (Equiv.Perm.sign σ : ℤ)) =
if s.card ≤ 1 then (Equiv.Perm.sign π : ℤ) else 0 := by
by_cases hs : s.card ≤ 1
· rw [ite_eq_left hs]
have he : CompactDomain.describe (some (π,s)) = {π} := by
ext σ
rw [CompactDomain.mem_describe,Finset.mem_singleton]
constructor
· intro h
apply Equiv.ext
intro i
by_cases hi : i ∈ s
· let k := π.symm (σ i)
have hk : π k = σ i := π.apply_symm_apply _
by_cases hks : k ∈ s
· have hki : k = i := Finset.card_le_one.mp hs k hks i hi
exact (hki ▸ hk).symm
· have hki : k = i := σ.injective ((h k hks).trans hk)
exact (hki ▸ hk).symm
· exact h i hi
· rintro rfl i hi; rfl
simp only [he,Finset.sum_singleton]
· rw [ite_eq_right hs]
obtain ⟨i,hi,k,hk,hik⟩ := Finset.one_lt_card.mp (by omega : 1 < s.card)
let τ := Equiv.swap i k
have ht : Equiv.Perm.sign τ = -1 := Equiv.Perm.sign_swap hik
have hm (σ : Equiv.Perm (Fin n)) :
σ * τ ∈ CompactDomain.describe (some (π,s)) ↔
σ ∈ CompactDomain.describe (some (π,s)) := by
simp only [CompactDomain.mem_describe]
have hh (x : Fin n) (hx : x ∉ s) : τ x = x := by
apply Equiv.swap_apply_of_ne_of_ne
· intro he; subst x; exact hx hi
· intro he; subst x; exact hx hk
simp only [Equiv.Perm.mul_apply]
constructor <;> intro h x hx <;> simpa only [hh x hx] using h x hx
have he : (∑ σ ∈ CompactDomain.describe (some (π,s)), (Equiv.Perm.sign σ : ℤ)) =
∑ σ ∈ CompactDomain.describe (some (π,s)), (Equiv.Perm.sign (σ * τ) : ℤ) := by
apply Finset.sum_bij (fun σ _ => σ * τ)
· intro σ hσ; exact (hm σ).mpr hσ
· intro σ hσ ρ hρ h; exact mul_right_cancel h
· intro σ hσ
refine ⟨σ * τ,(hm σ).mpr hσ,?_⟩
simp [τ,mul_assoc]
· intro σ hσ
simp [τ,mul_assoc]
have hn : (∑ σ ∈ CompactDomain.describe (some (π,s)), (Equiv.Perm.sign (σ * τ) : ℤ)) =
-(∑ σ ∈ CompactDomain.describe (some (π,s)), (Equiv.Perm.sign σ : ℤ)) := by
simp only [Equiv.Perm.sign_mul,ht,Units.val_neg,mul_neg_one,
Finset.sum_neg_distrib]
omega
def CompactDomain.mass {n : ℕ} : CompactDomain n → ℤ
| none => 0
| some (π,s) => if s.card ≤ 1 then vectorSign n (permVector π) else 0
lemma CompactDomain.describe_mass {n : ℕ} (D : CompactDomain n) :
(∑ σ ∈ D.describe, (Equiv.Perm.sign σ : ℤ)) = D.mass := by
cases D with
| none => simp [describe,mass]
| some ds =>
rcases ds with ⟨π,s⟩
simp only [mass,vectorSign_perm,compact_sum_sign]
def CompactDomains : List ℕ → Type
| [] => Unit
| r :: rs => CompactDomain r × CompactDomains rs
def CompactDomains.full : (rs : List ℕ) → CompactDomains rs
| [] => ()
| r :: rs => (CompactDomain.full r,full rs)
def CompactDomains.describe : {rs : List ℕ} → CompactDomains rs → Domains rs
| [], _ => ()
| _ :: _, (s,D) => (s.describe,describe D)
def CompactDomains.atValue : {rs : List ℕ} → CompactDomains rs → Cells rs → ℕ → CompactDomains rs
| _ :: _, (s,D), .inl i, j => (s.atValue i j,D)
| _ :: _, (s,D), .inr c, j => (s,atValue D c j)
def CompactDomains.vanished : {rs : List ℕ} → CompactDomains rs → Bool
| [], _ => false
| _ :: _, (s,D) => s.vanished || vanished D
def CompactDomains.mass : {rs : List ℕ} → CompactDomains rs → ℤ
| [], _ => 1
| _ :: _, (s,D) => s.mass * mass D
lemma CompactDomains.describe_full (rs : List ℕ) : (full rs).describe = Domains.full rs := by
induction rs with
| nil => rfl
| cons r rs ih => simp only [full,describe,Domains.full,CompactDomain.describe_full,ih]; rfl
lemma CompactDomains.describe_atValue {rs : List ℕ} (D : CompactDomains rs) (c : Cells rs) (j : ℕ) :
(D.atValue c j).describe = D.describe.atValue c j := by
induction rs with
| nil => exact c.elim
| cons r rs ih =>
rcases D with ⟨s,D⟩
cases c with
| inl i => simp only [atValue,describe,Domains.atValue,CompactDomain.describe_atValue]; rfl
| inr c => simp only [atValue,describe,Domains.atValue,ih]; rfl
lemma CompactDomains.describe_vanished {rs : List ℕ} (D : CompactDomains rs) :
D.describe.vanished = D.vanished := by
induction rs with
| nil => rfl
| cons r rs ih =>
rcases D with ⟨s,D⟩
simp only [describe,Domains.vanished,vanished,CompactDomain.describe_vanished,ih]
lemma CompactDomains.describe_mass {rs : List ℕ} (D : CompactDomains rs) :
D.describe.mass = D.mass := by
induction rs with
| nil => rfl
| cons r rs ih =>
rcases D with ⟨s,D⟩
simp only [describe,Domains.mass,mass,CompactDomain.describe_mass,ih]
def compactEdgeOptions {rsT rsA rsB : List ℕ}
(D : CompactDomains rsT) (E : CompactDomains rsA) (F : CompactDomains rsB)
(c : Edge rsT rsA rsB) (flag : Finset (ℕ × ℕ × ℕ)) : Finset (ℕ × ℕ × ℕ) :=
flag.filter (fun v => (D.atValue c.1 v.1).vanished = false ∧
(E.atValue c.2.1 v.2.1).vanished = false ∧ (F.atValue c.2.2 v.2.2).vanished = false)
lemma compactEdgeOptions_describe {rsT rsA rsB : List ℕ}
(D : CompactDomains rsT) (E : CompactDomains rsA) (F : CompactDomains rsB)
(c : Edge rsT rsA rsB) (flag : Finset (ℕ × ℕ × ℕ)) :
edgeOptions D.describe E.describe F.describe c flag = compactEdgeOptions D E F c flag := by
simp only [compactEdgeOptions,edgeOptions,← CompactDomains.describe_atValue,
CompactDomains.describe_vanished]
def compactOrderEdges {rsT rsA rsB : List ℕ}
(D : CompactDomains rsT) (E : CompactDomains rsA) (F : CompactDomains rsB)
(edges : List (Edge rsT rsA rsB)) (flag : Finset (ℕ × ℕ × ℕ)) : List (Edge rsT rsA rsB) :=
bringBest (fun c => (compactEdgeOptions D E F c flag).card) edges
lemma compactOrderEdges_describe {rsT rsA rsB : List ℕ}
(D : CompactDomains rsT) (E : CompactDomains rsA) (F : CompactDomains rsB)
(edges : List (Edge rsT rsA rsB)) (flag : Finset (ℕ × ℕ × ℕ)) :
orderEdges D.describe E.describe F.describe edges flag = compactOrderEdges D E F edges flag := by
simp only [compactOrderEdges,orderEdges,compactEdgeOptions_describe]
def solveCompact {rsT rsA rsB : List ℕ} : ℕ → CompactDomains rsT → CompactDomains rsA →
CompactDomains rsB → List (Edge rsT rsA rsB) → Finset (ℕ × ℕ × ℕ) → ℤ
| fuel, D, E, F, edges, flag =>
if D.vanished || E.vanished || F.vanished then 0
else match compactOrderEdges D E F edges flag with
| [] => D.mass * E.mass * F.mass
| c :: cs => match fuel with
| 0 => 0
| k+1 => ∑ v ∈ compactEdgeOptions D E F c flag,
solveCompact k (D.atValue c.1 v.1) (E.atValue c.2.1 v.2.1)
(F.atValue c.2.2 v.2.2) cs flag
lemma solveCompact_describe {rsT rsA rsB : List ℕ} (fuel : ℕ)
(D : CompactDomains rsT) (E : CompactDomains rsA) (F : CompactDomains rsB)
(edges : List (Edge rsT rsA rsB)) (flag : Finset (ℕ × ℕ × ℕ)) :
solveDomains fuel D.describe E.describe F.describe edges flag = solveCompact fuel D E F edges flag := by
induction fuel generalizing D E F edges with
| zero =>
rw [solveCompact,solveDomains]
simp only [CompactDomains.describe_vanished,compactOrderEdges_describe,CompactDomains.describe_mass]
split <;> rfl
| succ fuel ih =>
rw [solveCompact,solveDomains]
simp only [CompactDomains.describe_vanished,compactOrderEdges_describe,CompactDomains.describe_mass]
split
· rfl
· cases he : compactOrderEdges D E F edges flag with
| nil => rfl
| cons c cs =>
simp only [compactEdgeOptions_describe,← CompactDomains.describe_atValue,ih]
lemma contractionInteger_compact {n : ℕ} (rsA rsB rsT : List ℕ)
(ea : Fin n ≃ Fin rsA.sum) (eb : Fin n ≃ Fin rsB.sum) (et : Fin n ≃ Fin rsT.sum)
(flag : Finset (ℕ × ℕ × ℕ)) :
contractionInteger rsA rsB rsT ea eb et (fun r a b => if (r,a,b) ∈ flag then 1 else 0) =
solveCompact n (.full rsT) (.full rsA) (.full rsB)
(certificateEdges rsA rsB rsT ea eb et) flag := by
rw [contractionInteger_solve,← CompactDomains.describe_full,← CompactDomains.describe_full,
← CompactDomains.describe_full,solveCompact_describe]
end Saxl.Columns
end
end OAI

Xet Storage Details

Size:
12.8 kB
·
Xet hash:
ca97e70bd61682d9821f4a3576c58480541a2c7f9bedbcc0ea8a35d0da067981

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