introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
5.73 kB
import OAI.Probability.MatroidProphet.Pivots.Arbitrary
import OAI.Probability.MatroidProphet.Pivots.Encoding
import OAI.Probability.MatroidProphet.Pivots.OccurrenceSupport
import OAI.Probability.MatroidProphet.Pivots.Scores
import OAI.Probability.MatroidProphet.Pivots.Sign
import Mathlib.LinearAlgebra.Dimension.Constructions
namespace OAI
namespace MatroidProphet
namespace Pivots
open Set Finset
open scoped BigOperators
variable {Ξ± : Type*} [Fintype Ξ±] {r q n : β„•}
def occurrenceMark (oldMark : Fin r β†’ Bool) (movableMark : Fin q β†’ Bool) :
Occurrence r q β†’ Bool := Sum.elim oldMark movableMark
noncomputable def markedScore (s : β„•) (time : Occurrence r q β†’ β„•)
(oldMark : Fin r β†’ Bool) (movableMark : Fin q β†’ Bool) (o : Occurrence r q) : ℝ :=
if occurrenceMark oldMark movableMark o then (2 : ℝ) ^ scoreExponent s time o
else -(2 : ℝ) ^ scoreExponent s time o
lemma abs_markedScore (s : β„•) (time : Occurrence r q β†’ β„•)
(oldMark : Fin r β†’ Bool) (movableMark : Fin q β†’ Bool) (o : Occurrence r q) :
|markedScore s time oldMark movableMark o| = (2 : ℝ) ^ scoreExponent s time o := by
unfold markedScore
split <;> simp [abs_of_nonneg (pow_nonneg (by norm_num : (0 : ℝ) ≀ 2) _)]
noncomputable def fixedOldScore (s : β„•) (oldMark : Fin r β†’ Bool) (i : Fin r) : ℝ :=
if oldMark i then (2 : ℝ)^((s+1)*(i.val+1)) else -(2 : ℝ)^((s+1)*(i.val+1))
noncomputable def constantScore (s : β„•) (oldMark : Fin r β†’ Bool) : Occurrence r q β†’ ℝ :=
Sum.elim (fixedOldScore s oldMark) (fun _ => 0)
noncomputable def coordinateScore : Occurrence r q β†’ ((Fin q β†’ ℝ) β†’β‚—[ℝ] ℝ) :=
Sum.elim (fun _ => 0) (fun i => LinearMap.proj i)
noncomputable def patternLinear (M : Matroid Ξ±) (label : Occurrence r q β†’ Ξ±)
(J : Finset (Occurrence r q)) (e : Ξ±) : (Fin q β†’ ℝ) β†’β‚—[ℝ] ℝ :=
βˆ‘ o ∈ occurrenceSupport M label J e, coordinateScore o
noncomputable def patternConstant (M : Matroid Ξ±) (label : Occurrence r q β†’ Ξ±)
(J : Finset (Occurrence r q)) (e : Ξ±) (s : β„•) (oldMark : Fin r β†’ Bool) : ℝ :=
βˆ‘ o ∈ occurrenceSupport M label J e, constantScore s oldMark o
lemma affineScore_eq_sum
{Ξ± : Type u_1} [Fintype Ξ±] {r : β„•} {q : β„•} (M : Matroid Ξ±) (label : Occurrence r q β†’ Ξ±)
(J : Finset (Occurrence r q)) (e : Ξ±) (s : β„•) (time : Occurrence r q β†’ β„•)
(oldMark : Fin r β†’ Bool) (movableMark : Fin q β†’ Bool) :
patternLinear M label J e (fun i => markedScore s time oldMark movableMark (Sum.inr i)) +
patternConstant M label J e s oldMark =
βˆ‘ o ∈ occurrenceSupport M label J e, markedScore s time oldMark movableMark o := by
simp only [patternLinear, patternConstant, LinearMap.sum_apply, ← Finset.sum_add_distrib]
apply Finset.sum_congr rfl
intro o _
cases o <;> simp [coordinateScore, constantScore, fixedOldScore, markedScore,
occurrenceMark, scoreExponent]
all_goals rfl
def RecordsPivots (M : Matroid Ξ±) (label : Occurrence r q β†’ Ξ±)
(test : Fin n β†’ Ξ±) (time : Occurrence r q β†’ β„•)
(oldMark : Fin r β†’ Bool) (movableMark : Fin q β†’ Bool) (t : Finset (Fin n)) : Prop :=
βˆ€ f, βˆƒ o, IsPivot M label time (test f) o ∧
(occurrenceMark oldMark movableMark o = true ↔ f ∈ t)
lemma recordsPivots_affine (M : Matroid Ξ±) (b : β„• β†’ Ξ±) (a : Fin q β†’ Ξ±)
(test : Fin n β†’ Ξ±) (s : β„•) (hqs : q ≀ s)
(oldMark : Fin r β†’ Bool) (movableMark : Fin q β†’ Bool)
(time : Occurrence r q β†’ β„•) (horder : OldOrdered time) (htime : Function.Injective time)
(hground : βˆ€ o : Occurrence r q, occurrenceLabel b a o ∈ M.E) (t : Finset (Fin n))
(hrecords : RecordsPivots M (occurrenceLabel b a) test time oldMark movableMark t) :
βˆƒ x, RealizesSigns
(fun f => patternLinear M (occurrenceLabel b a) (retained M b a time) (test f))
(fun f => patternConstant M (occurrenceLabel b a) (retained M b a time) (test f) s oldMark)
t x := by
classical
let label : Occurrence r q β†’ Ξ± := occurrenceLabel b a
let J := retained M b a time
let w := markedScore s time oldMark movableMark
let exponent := scoreExponent s time
refine ⟨fun i => w (Sum.inr i), ?_⟩
intro f
rw [affineScore_eq_sum]
obtain ⟨o, hpivot, hmark⟩ := hrecords f
have hp := pivot_mem_support_and_max M label time hground htime hpivot
change o ∈ occurrenceSupport M label J (test f) ∧
(βˆ€ p ∈ occurrenceSupport M label J (test f), time p ≀ time o) at hp
have hmax : βˆ€ p ∈ occurrenceSupport M label J (test f), p β‰  o β†’ exponent p < exponent o := by
intro p hp' hne
apply scoreExponent_preserves_order s hqs time horder
exact lt_of_le_of_ne (hp.2 p hp') (fun heq => hne (htime heq))
have hexp := scoreExponent_injective s hqs time horder htime
have habs : βˆ€ p ∈ occurrenceSupport M label J (test f), |w p| = 2 ^ exponent p :=
fun p _ => abs_markedScore s time oldMark movableMark p
have hpos := sum_positive_iff_max_exponent _ w exponent hexp hp.1 hmax habs
have hneg := sum_positive_iff_max_exponent _ (fun p => -w p) exponent hexp hp.1 hmax
(by intro p hp'; simpa using habs p hp')
simp only [Finset.sum_neg_distrib, neg_pos] at hneg
have hpow : (0 : ℝ) < 2 ^ exponent o := pow_pos (by norm_num) _
by_cases hf : f ∈ t
Β· simp only [hf, ↓reduceIte]
apply hpos.mpr
have hm := hmark.mpr hf
simp [w, markedScore, hm]
Β· simp only [hf, ↓reduceIte]
apply hneg.mpr
have hm : occurrenceMark oldMark movableMark o = false := by
cases h : occurrenceMark oldMark movableMark o
Β· rfl
Β· exact False.elim (hf (hmark.mp h))
simp [w, markedScore, hm]
end Pivots
end MatroidProphet
end OAI