introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
8.86 kB
import Mathlib.Analysis.SpecialFunctions.Log.Basic
import Mathlib.Data.Fintype.Powerset
import Mathlib.Data.Nat.Cast.Order.Field
import Mathlib.Order.Filter.AtTopBot.Basic
import OAI.Combinatorics.BalancedRyser.Construction.Construction
namespace OAI
namespace Balanced.Local
open scoped BigOperators
open Filter
universe u
noncomputable section
attribute [local instance] Classical.propDecidable
abbrev TupleCode (F : Type u) := (Fin 4 β†’ Direction F) Γ— (Fin 4 β†’ Bool)
abbrev ChoiceCode (F : Type u) := Line F Γ— TupleCode F
abbrev Output (F : Type u) := Slot F β†’ ChoiceCode F
def decodeTuple {F : Type u} (t : TupleCode F) : FourTuple F := ⟨t.1, t.2⟩
def decodeChoice {F : Type u} (c : ChoiceCode F) : SplitChoice F :=
⟨c.1, decodeTuple c.2⟩
def configuration {F : Type u} (M : MergedPairs F) (v : Output F) : Configuration F :=
⟨M, fun s => decodeChoice (v s)⟩
variable {F : Type u} [Field F] [Fintype F] [DecidableEq F]
def constituentMultiplicity (M : MergedPairs F) (p : Point F) : β„• :=
(Finset.univ.filter (fun ds : Direction F Γ— Bool =>
OnLine p (constituent M ds.1 ds.2))).card
def logBudget (F : Type u) [Fintype F] : β„• := Nat.ceil (Real.log (Fintype.card F))
def offsetProbability (E : MergedPairs F β†’ Prop) : ℝ :=
(βˆ‘ M : MergedPairs F, if E M then (1 : ℝ) else 0) /
Fintype.card (MergedPairs F)
def conditionedOffsetProbability (A E : MergedPairs F β†’ Prop) : ℝ :=
offsetProbability (fun M => A M ∧ E M) / offsetProbability A
structure RetentionRule (F : Type u) [Field F] [Fintype F] [DecidableEq F] where
candidates : MergedPairs F β†’ Direction F β†’ Finset (ChoiceCode F)
valid : βˆ€ M g c, c ∈ candidates M g β†’ ValidChoice M g (decodeChoice c)
uniqueLine : βˆ€ M g c d, c ∈ candidates M g β†’ d ∈ candidates M g β†’
c.1 = d.1 β†’ c = d
complete : βˆ€ M g c, ValidChoice M g (decodeChoice c) β†’
βˆƒ d ∈ candidates M g, d.1 = c.1
abbrev Kernel (F : Type u) := MergedPairs F β†’ Output F β†’ ℝ
def KernelConditions (Q : RetentionRule F) (w : Kernel F) (K : ℝ) : Prop :=
(βˆ€ M v, 0 ≀ w M v) ∧
(βˆ€ M, βˆ‘ v, w M v ≀ 1) ∧
(βˆ€ M v, 0 < w M v β†’
(configuration M v).Valid ∧ (configuration M v).Compatible ∧
(βˆ€ s, v s ∈ Q.candidates M s.1) ∧
(βˆ€ p, constituentMultiplicity M p ≀ logBudget F)) ∧
(βˆ€ M (S : Finset (Slot F)) (t : Slot F β†’ TupleCode F),
(βˆ‘ v, if (βˆ€ s ∈ S, (v s).2 = t s) then w M v else 0) ≀
(K / Fintype.card F) ^ S.card)
def selectedProbability (w : Kernel F) (E : Configuration F β†’ Prop) : ℝ :=
(βˆ‘ M : MergedPairs F, βˆ‘ v : Output F,
if E (configuration M v) then w M v else 0) /
Fintype.card (MergedPairs F)
def generatorUnionAt (C : Configuration F) (p : Point F) : Finset (Direction F) :=
(Finset.univ.filter (fun s => OnLine p (C.choice s).line)).biUnion
(fun s => generatorSet (C.choice s).tuple)
def reuseCount (C : Configuration F) (p : Point F) : β„• :=
4 * C.splitMultiplicity p - (generatorUnionAt C p).card
structure EqualityPattern (b ΞΊ : β„•) where
classOf : Fin b β†’ Fin 4 β†’ Fin (4 * b - ΞΊ)
everyClass : Function.Surjective (fun ij : Fin b Γ— Fin 4 => classOf ij.1 ij.2)
withinTuple : βˆ€ i, Function.Injective (classOf i)
pairOverlap : βˆ€ i j, i β‰  j β†’
((Finset.univ.image (classOf i)) ∩ (Finset.univ.image (classOf j))).card ≀ 1
abbrev DirectionAssignment (F : Type u) (b ΞΊ : β„•) :=
(Fin b β†’ Direction F) Γ— (Fin (4 * b - ΞΊ) β†’ Direction F)
abbrev Bits (b : β„•) := Fin b β†’ Fin 4 β†’ Bool
def Eligible {b ΞΊ : β„•} (P : EqualityPattern b ΞΊ)
(a : DirectionAssignment F b ΞΊ) : Prop :=
Function.Injective a.1 ∧ Function.Injective a.2 ∧
βˆ€ i j, a.2 (P.classOf i j) β‰  a.1 i
def prescribedTuple {b ΞΊ : β„•} (P : EqualityPattern b ΞΊ)
(a : DirectionAssignment F b ΞΊ) (bits : Bits b) (i : Fin b) : FourTuple F :=
⟨fun j => a.2 (P.classOf i j), bits i⟩
def prescribedPoint {b ΞΊ : β„•} (P : EqualityPattern b ΞΊ)
(a : DirectionAssignment F b ΞΊ) (bits : Bits b)
(M : MergedPairs F) (ij : Fin b Γ— Fin 4) : Point F :=
tuplePoint M (prescribedTuple P a bits ij.1) ij.2
def Aligned {b ΞΊ : β„•} (P : EqualityPattern b ΞΊ)
(a : DirectionAssignment F b ΞΊ) (bits : Bits b) (p : Point F)
(M : MergedPairs F) : Prop :=
βˆ€ ij, OnLine (prescribedPoint P a bits M ij) (lineThrough (a.1 ij.1) p)
def Admissible {b ΞΊ : β„•} (P : EqualityPattern b ΞΊ)
(a : DirectionAssignment F b ΞΊ) (bits : Bits b) (p : Point F)
(M : MergedPairs F) : Prop :=
Aligned P a bits p M ∧ Function.Injective (prescribedPoint P a bits M) ∧
(βˆ€ ij, prescribedPoint P a bits M ij β‰  p) ∧
(βˆ€ i, lineThrough (a.1 i) p βˆ‰ constituentLines M) ∧
(βˆ€ x, constituentMultiplicity M x ≀ logBudget F)
def prescribedDesignated {b ΞΊ : β„•} (P : EqualityPattern b ΞΊ)
(a : DirectionAssignment F b ΞΊ) (bits : Bits b) (M : MergedPairs F) :
Finset (Point F) := Finset.univ.image (prescribedPoint P a bits M)
def prescribedPartners {b ΞΊ : β„•} (P : EqualityPattern b ΞΊ)
(a : DirectionAssignment F b ΞΊ) (bits : Bits b) (p : Point F)
(M : MergedPairs F) : Finset (Point F) :=
(prescribedDesignated P a bits M).filter (fun x =>
βˆƒ ds : Direction F Γ— Bool, OnLine p (constituent M ds.1 ds.2) ∧
OnLine x (constituent M ds.1 (!ds.2)))
def piecePoints (M : MergedPairs F) : LocalPiece F β†’ Finset (Point F)
| Sum.inl U => U
| Sum.inr (Sum.inl l) => linePoints l
| Sum.inr (Sum.inr d) => mergedPoints M d
def AllowedPiece {b ΞΊ : β„•} (a : DirectionAssignment F b ΞΊ) (p : Point F)
(M : MergedPairs F) : LocalPiece F β†’ Prop
| Sum.inl U => U.card ≀ 2
| Sum.inr (Sum.inl l) =>
l βˆ‰ (Finset.univ.image (fun i => lineThrough (a.1 i) p)) βˆͺ constituentLines M
| Sum.inr (Sum.inr _) => True
def BadCover {b ΞΊ : β„•} (P : EqualityPattern b ΞΊ)
(a : DirectionAssignment F b ΞΊ) (bits : Bits b) (p : Point F)
(M : MergedPairs F) : Prop :=
βˆƒ A : Finset (LocalPiece F), A.card ≀ b - 1 ∧
(βˆ€ x ∈ A, AllowedPiece a p M x) ∧
prescribedDesignated P a bits M βŠ†
prescribedPartners P a bits p M βˆͺ A.biUnion (piecePoints M)
def AdmissibleBadCover {b ΞΊ : β„•} (P : EqualityPattern b ΞΊ)
(a : DirectionAssignment F b ΞΊ) (bits : Bits b) (p : Point F)
(M : MergedPairs F) : Prop :=
Admissible P a bits p M ∧ BadCover P a bits p M
def PencilLocalResult : Prop :=
βˆ€ K : ℝ, 0 < K β†’ βˆƒ Ξ΅ : β„• β†’ ℝ,
Tendsto Ξ΅ atTop (nhds 0) ∧ (βˆ€ q, 0 ≀ Ξ΅ q) ∧
βˆƒ qβ‚€ : β„•, βˆ€ (F : Type u) [Field F] [Fintype F] [DecidableEq F],
qβ‚€ ≀ Fintype.card F β†’ βˆ€ (Q : RetentionRule F) (w : Kernel F),
KernelConditions Q w K β†’
selectedProbability w (fun C => Β¬ C.LocalCondition) ≀ Ξ΅ (Fintype.card F)
def PencilReuseResult : Prop :=
βˆ€ K : ℝ, 0 < K β†’ βˆƒ C : ℝ, 0 < C ∧ βˆƒ qβ‚€ : β„•,
βˆ€ (F : Type u) [Field F] [Fintype F] [DecidableEq F],
qβ‚€ ≀ Fintype.card F β†’ βˆ€ (Q : RetentionRule F) (w : Kernel F),
KernelConditions Q w K β†’ βˆ€ p : Point F,
selectedProbability w (fun X => 2 ≀ X.splitMultiplicity p ∧ 3 ≀ reuseCount X p) ≀
C / (Fintype.card F : ℝ) ^ 3
def AlignmentNormalizationResult : Prop :=
βˆ€ (F : Type u) [Field F] [Fintype F] [DecidableEq F],
βˆ€ b ΞΊ : β„•, 3 ≀ b β†’ b ≀ logBudget F β†’ ΞΊ ≀ 2 β†’
βˆ€ (P : EqualityPattern b ΞΊ) (a : DirectionAssignment F b ΞΊ), Eligible P a β†’
βˆ€ (bits : Bits b) (p : Point F),
offsetProbability (Aligned P a bits p) = 1 / (Fintype.card F : ℝ) ^ (4 * b)
def PencilSmallReuseResult : Prop :=
AlignmentNormalizationResult.{u} ∧
βˆƒ C : ℝ, 0 < C ∧ βˆƒ d qβ‚€ : β„•,
βˆ€ (F : Type u) [Field F] [Fintype F] [DecidableEq F],
qβ‚€ ≀ Fintype.card F β†’ βˆ€ b ΞΊ : β„•, 3 ≀ b β†’ b ≀ logBudget F β†’ ΞΊ ≀ 1 β†’
βˆ€ (P : EqualityPattern b ΞΊ) (a : DirectionAssignment F b ΞΊ), Eligible P a β†’
βˆ€ (bits : Bits b) (p : Point F),
conditionedOffsetProbability (Aligned P a bits p) (AdmissibleBadCover P a bits p) ≀
C * (b : ℝ) ^ d * (2 * (logBudget F : ℝ) / Fintype.card F) ^ (3 - ΞΊ)
def PencilTwoReusesResult : Prop :=
βˆƒ C : ℝ, 0 < C ∧ βˆƒ qβ‚€ : β„•,
βˆ€ (F : Type u) [Field F] [Fintype F] [DecidableEq F],
qβ‚€ ≀ Fintype.card F β†’ βˆ€ b : β„•, 3 ≀ b β†’ b ≀ logBudget F β†’
βˆ€ (P : EqualityPattern b 2) (bits : Bits b) (p : Point F),
(βˆ‘ a : DirectionAssignment F b 2,
if Eligible P a then offsetProbability (fun M =>
Aligned P a bits p M ∧ AdmissibleBadCover P a bits p M) else 0) ≀
((Fintype.card F + 1 : β„•) : ℝ) ^ (5 * b - 2) /
(Fintype.card F : ℝ) ^ (4 * b) * (C * (b : ℝ) ^ 3 / Fintype.card F)
end
end Balanced.Local
end OAI