File size: 6,571 Bytes
dd14c26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import OAI.Probability.MatroidProphet.Main
import Mathlib.Data.Fintype.EquivFin

namespace OAI

/-!
# Timestamp representations of finite insertion orders

The marked-pivot proof uses injective natural-number timestamps, whereas the
manuscript speaks about positions in a finite interleaving. We prove that
timestamps can be normalized to a permutation of the finite position set
without changing any prefix, first-spanning pivot, or recorded mark vector.
No bound on gaps between timestamps is imposed.
-/

namespace MatroidProphet.Pivots

open Set Finset

variable {α β : Type*} [Fintype β]

/-- The position of an occurrence is the number of its strict predecessors. -/
noncomputable def orderPosition (time : β → ℕ) (o : β) : ℕ := by
  classical
  exact (Finset.univ.filter (fun p => time p < time o)).card

lemma orderPosition_mono (time : β → ℕ) {o p : β} (h : time o ≤ time p) :
    orderPosition time o ≤ orderPosition time p := by
  classical
  apply Finset.card_le_card
  intro a ha
  exact Finset.mem_filter.mpr ⟨Finset.mem_univ _,
    lt_of_lt_of_le (Finset.mem_filter.mp ha).2 h⟩

lemma orderPosition_strict (time : β → ℕ) {o p : β} (h : time o < time p) :
    orderPosition time o < orderPosition time p := by
  classical
  apply Finset.card_lt_card
  apply Finset.ssubset_iff_subset_ne.mpr
  constructor
  · intro a ha
    exact Finset.mem_filter.mpr ⟨Finset.mem_univ _,
      lt_trans (Finset.mem_filter.mp ha).2 h⟩
  · intro heq
    have ho : o ∈ Finset.univ.filter (fun a => time a < time p) := by simp [h]
    rw [← heq] at ho
    simp at ho

lemma orderPosition_lt_iff (time : β → ℕ) (o p : β) :
    orderPosition time o < orderPosition time p ↔ time o < time p := by
  refine ⟨?_, orderPosition_strict time⟩
  intro h
  by_contra hn
  exact (not_lt_of_ge (orderPosition_mono time (Nat.le_of_not_gt hn))) h

lemma orderPosition_le_iff (time : β → ℕ) (o p : β) :
    orderPosition time o ≤ orderPosition time p ↔ time o ≤ time p := by
  simp only [← not_lt, orderPosition_lt_iff]

lemma orderPosition_lt_card (time : β → ℕ) (o : β) :
    orderPosition time o < Fintype.card β := by
  classical
  change (Finset.univ.filter (fun p => time p < time o)).card < Fintype.card β
  rw [← Finset.card_univ]
  apply Finset.card_lt_card
  apply Finset.ssubset_iff_subset_ne.mpr
  refine ⟨Finset.filter_subset _ _, ?_⟩
  intro heq
  have ho : o ∈ (Finset.univ : Finset β) := Finset.mem_univ _
  rw [← heq] at ho
  simp at ho

/-- The normalized timestamp lies in the actual finite position set. -/
noncomputable def finiteOrderPosition (time : β → ℕ) (o : β) : Fin (Fintype.card β) :=
  ⟨orderPosition time o, orderPosition_lt_card time o⟩

lemma finiteOrderPosition_injective (time : β → ℕ) (htime : Function.Injective time) :
    Function.Injective (finiteOrderPosition time) := by
  intro o p heq
  apply htime
  have hval := congrArg Fin.val heq
  change orderPosition time o = orderPosition time p at hval
  apply Nat.le_antisymm
  · exact (orderPosition_le_iff time o p).mp hval.le
  · exact (orderPosition_le_iff time p o).mp hval.ge

lemma finiteOrderPosition_bijective (time : β → ℕ) (htime : Function.Injective time) :
    Function.Bijective (finiteOrderPosition time) := by
  rw [Fintype.bijective_iff_injective_and_card]
  exact ⟨finiteOrderPosition_injective time htime, by simp⟩

omit [Fintype β] in
/-- Only the relative occurrence order, not the timestamp magnitudes, matters. -/
lemma isPivot_iff_of_same_order (M : Matroid α) (label : β → α)
    (time time' : β → ℕ) (horder : ∀ o p, time o < time p ↔ time' o < time' p)
    (e : α) (o : β) : IsPivot M label time e o ↔ IsPivot M label time' e o := by
  have hbefore : {p | time p < time o} = {p | time' p < time' o} := by
    ext p
    exact horder p o
  have hthrough : {p | time p ≤ time o} = {p | time' p ≤ time' o} := by
    ext p
    simp only [mem_ofPred_eq, ← not_lt, horder o p]
  simp only [IsPivot, hbefore, hthrough]

lemma isPivot_orderPosition_iff (M : Matroid α) (label : β → α)
    (time : β → ℕ) (e : α) (o : β) :
    IsPivot M label (orderPosition time) e o ↔ IsPivot M label time e o :=
  isPivot_iff_of_same_order M label (orderPosition time) time
    (orderPosition_lt_iff time) e o

lemma recordsPivots_orderPosition_iff {r q n : ℕ} (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)) :
    RecordsPivots M label test (orderPosition time) oldMark movableMark t ↔
      RecordsPivots M label test time oldMark movableMark t := by
  simp only [RecordsPivots, isPivot_orderPosition_iff]

lemma oldOrdered_orderPosition_iff {r q : ℕ} (time : Occurrence r q → ℕ) :
    OldOrdered (orderPosition time) ↔ OldOrdered time := by
  simp only [OldOrdered, orderPosition_lt_iff]

/-- The counted family is exactly the family obtained from genuine finite
interleavings. Arbitrary natural-number gaps neither add nor remove patterns. -/
lemma mem_markedPivotPatterns_iff_finite_order [Fintype α] {r q n : ℕ}
    (M : Matroid α) (b : ℕ → α) (a : Fin q → α) (test : Fin n → α)
    (oldMark : Fin r → Bool) (t : Finset (Fin n)) :
    t ∈ markedPivotPatterns M b a test oldMark ↔
      ∃ position : Occurrence r q ≃ Fin (Fintype.card (Occurrence r q)),
        OldOrdered (fun o => (position o).val) ∧
          ∃ movableMark : Fin q → Bool,
            RecordsPivots M (occurrenceLabel b a) test (fun o => (position o).val)
              oldMark movableMark t := by
  classical
  constructor
  · intro ht
    obtain ⟨time, horder, htime, movableMark, hrecords⟩ := (Finset.mem_filter.mp ht).2
    let position := Equiv.ofBijective (finiteOrderPosition time)
      (finiteOrderPosition_bijective time htime)
    refine ⟨position, ?_, movableMark, ?_⟩
    · change OldOrdered (orderPosition time)
      exact (oldOrdered_orderPosition_iff time).mpr horder
    · change RecordsPivots M (occurrenceLabel b a) test (orderPosition time)
        oldMark movableMark t
      exact (recordsPivots_orderPosition_iff M (occurrenceLabel b a) test time
        oldMark movableMark t).mpr hrecords
  · rintro ⟨position, horder, movableMark, hrecords⟩
    exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, (fun o => (position o).val),
      horder, (fun o p h => position.injective (Fin.ext h)), movableMark, hrecords⟩

end MatroidProphet.Pivots

end OAI