introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
6.91 kB
import OAI.LinearAlgebra.MatrixMultiplication.JointExtraction.CoarseAssignment
namespace OAI
/-! Joint tensor extraction, compatibility and entropy estimates. -/
noncomputable section
namespace MatrixMultiplication.JointAssignmentLoss
open JointExtraction JointCoarseAssignment
attribute [local instance] Classical.propDecidable
variable {A B C I V Ξ© : Type*}
theorem uniqueAssignment_of_unique (candidates : Finset I)
(compatible : I β†’ V β†’ Prop) (v : V) (i : I)
(hi : i ∈ candidates) (hc : compatible i v)
(hu : βˆ€ j, j ∈ candidates β†’ compatible j v β†’ j = i) :
uniqueAssignment candidates compatible v = some i := by
classical
have hex : βˆƒ j, j ∈ candidates ∧ compatible j v ∧
βˆ€ k, k ∈ candidates β†’ compatible k v β†’ k = j := ⟨i, hi, hc, hu⟩
unfold uniqueAssignment
rw [dite_eq_left hex]
exact congrArg some (hu _ (Classical.choose_spec hex).1 (Classical.choose_spec hex).2.1)
theorem assignUseful_of_unique (candidates : Finset I)
(compatible useful : I β†’ V β†’ Prop) (v : V) (i : I)
(hi : i ∈ candidates) (hc : compatible i v) (huse : useful i v)
(hu : βˆ€ j, j ∈ candidates β†’ compatible j v β†’ j = i) :
assignUseful candidates compatible useful v = some i := by
have hassign := uniqueAssignment_of_unique candidates compatible v i hi hc hu
have hkeep : βˆƒ j, uniqueAssignment candidates compatible v = some j ∧ useful j v :=
⟨i, hassign, huse⟩
simp only [assignUseful, retainAssignment, ite_eq_left hkeep]
exact hassign
def ambientXCollision (ambient : Finset (Triple A B C))
(hx : A β†’ Prop) (hy : B β†’ Prop) (hz : C β†’ Prop) (e : Triple A B C) : Prop :=
βˆƒ f ∈ ambient, f β‰  e ∧ survives hx hy hz f ∧ f.1 = e.1
def targetCompatibleCollision (targets : Finset (Triple A B C))
(hx : A β†’ Prop) (hy : B β†’ Prop) (hz : C β†’ Prop)
(compatible : Triple A B C β†’ V β†’ Prop) (e : Triple A B C) (v : V) : Prop :=
βˆƒ f ∈ targets, f β‰  e ∧ survives hx hy hz f ∧ compatible f v
theorem eligible_of_no_ambientXCollision
(ambient targets : Finset (Triple A B C))
(hx : A β†’ Prop) (hy : B β†’ Prop) (hz : C β†’ Prop) (e : Triple A B C)
(ha : e ∈ ambient) (ht : e ∈ targets) (hs : survives hx hy hz e)
(hno : Β¬ ambientXCollision ambient hx hy hz e) :
e ∈ eligible ambient targets hx hy hz := by
apply (mem_eligible_iff ambient targets hx hy hz e).2
refine ⟨ha, ht, hs, ?_⟩
intro f hf hfs hfx
by_contra hne
exact hno ⟨f, hf, hne, hfs, hfx⟩
theorem not_eligible_iff_ambientXCollision
(ambient targets : Finset (Triple A B C))
(hx : A β†’ Prop) (hy : B β†’ Prop) (hz : C β†’ Prop) (e : Triple A B C)
(ha : e ∈ ambient) (ht : e ∈ targets) (hs : survives hx hy hz e) :
e βˆ‰ eligible ambient targets hx hy hz ↔ ambientXCollision ambient hx hy hz e := by
constructor
Β· intro h
by_contra hno
exact h (eligible_of_no_ambientXCollision ambient targets hx hy hz e ha ht hs hno)
· rintro ⟨f, hf, hne, hfs, hfx⟩ he
exact hne (((mem_eligible_iff ambient targets hx hy hz e).1 he).2.2.2 f hf hfs hfx)
theorem assignUseful_of_no_targetCollision
(ambient targets : Finset (Triple A B C))
(hx : A β†’ Prop) (hy : B β†’ Prop) (hz : C β†’ Prop)
(compatible useful : Triple A B C β†’ V β†’ Prop) (e : Triple A B C) (v : V)
(he : e ∈ eligible ambient targets hx hy hz)
(hc : compatible e v) (hu : useful e v)
(hno : Β¬ targetCompatibleCollision targets hx hy hz compatible e v) :
assignUseful (eligible ambient targets hx hy hz) compatible useful v = some e := by
apply assignUseful_of_unique _ _ _ _ _ he hc hu
intro f hf hcf
have hfe := (mem_eligible_iff ambient targets hx hy hz f).1 hf
by_contra hne
exact hno ⟨f, hfe.2.1, hne, hfe.2.2.1, hcf⟩
theorem assignment_failure_implies_collision
(ambient targets : Finset (Triple A B C))
(hx : A β†’ Prop) (hy : B β†’ Prop) (hz : C β†’ Prop)
(compatible useful : Triple A B C β†’ V β†’ Prop) (e : Triple A B C) (v : V)
(ha : e ∈ ambient) (ht : e ∈ targets) (hs : survives hx hy hz e)
(hc : compatible e v) (hu : useful e v)
(hfail : assignUseful (eligible ambient targets hx hy hz) compatible useful v β‰  some e) :
ambientXCollision ambient hx hy hz e ∨
targetCompatibleCollision targets hx hy hz compatible e v := by
by_cases hX : ambientXCollision ambient hx hy hz e
Β· exact Or.inl hX
apply Or.inr
by_contra hC
have he := eligible_of_no_ambientXCollision ambient targets hx hy hz e ha ht hs hX
exact hfail (assignUseful_of_no_targetCollision ambient targets hx hy hz
compatible useful e v he hc hu hC)
theorem retained_assignment_of_no_collision
(ambient targets : Finset (Triple A B C))
(hx : A β†’ Prop) (hy : B β†’ Prop) (hz : C β†’ Prop)
(compatible useful : Triple A B C β†’ V β†’ Prop) (keep : V β†’ Prop)
(e : Triple A B C) (v : V)
(ha : e ∈ ambient) (ht : e ∈ targets) (hs : survives hx hy hz e)
(hc : compatible e v) (hu : useful e v) (hk : keep v)
(hX : Β¬ ambientXCollision ambient hx hy hz e)
(hC : Β¬ targetCompatibleCollision targets hx hy hz compatible e v) :
retainAssignment (assignUseful (eligible ambient targets hx hy hz) compatible useful)
keep v = some e := by
have he := eligible_of_no_ambientXCollision ambient targets hx hy hz e ha ht hs hX
have hassign := assignUseful_of_no_targetCollision ambient targets hx hy hz
compatible useful e v he hc hu hC
simpa only [retainAssignment, ite_eq_left hk] using hassign
theorem passing_assignment_failure_subset
(samples : Finset Ξ©) (ambient targets : Finset (Triple A B C))
(hx : Ξ© β†’ A β†’ Prop) (hy : Ξ© β†’ B β†’ Prop) (hz : Ξ© β†’ C β†’ Prop)
(compatible useful : Triple A B C β†’ V β†’ Prop) (keep : V β†’ Prop)
(e : Triple A B C) (v : V) (ha : e ∈ ambient) (ht : e ∈ targets)
(hc : compatible e v) (hu : useful e v) (hk : keep v) :
samples.filter (fun Ο‰ => survives (hx Ο‰) (hy Ο‰) (hz Ο‰) e ∧
retainAssignment
(assignUseful (eligible ambient targets (hx Ο‰) (hy Ο‰) (hz Ο‰)) compatible useful)
keep v β‰  some e) βŠ†
samples.filter (fun Ο‰ => survives (hx Ο‰) (hy Ο‰) (hz Ο‰) e ∧
(ambientXCollision ambient (hx Ο‰) (hy Ο‰) (hz Ο‰) e ∨
targetCompatibleCollision targets (hx Ο‰) (hy Ο‰) (hz Ο‰) compatible e v)) := by
intro ω hω
obtain ⟨hΟ‰s, hs, hfail⟩ := Finset.mem_filter.1 hΟ‰
apply Finset.mem_filter.2
refine ⟨hΟ‰s, hs, ?_⟩
have hfail' : assignUseful (eligible ambient targets (hx Ο‰) (hy Ο‰) (hz Ο‰))
compatible useful v β‰  some e := by
simpa only [retainAssignment, ite_eq_left hk] using hfail
exact assignment_failure_implies_collision ambient targets (hx Ο‰) (hy Ο‰) (hz Ο‰)
compatible useful e v ha ht hs hc hu hfail'
end MatrixMultiplication.JointAssignmentLoss
end
end OAI