File size: 5,716 Bytes
4a56cd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import Mathlib
import OAI.Combinatorics.MatchingCount.Algorithm.TreeGeneratedUpdate
import OAI.Combinatorics.MatchingCount.Probability.OnlineSampleLaw

namespace OAI

namespace MatchingFPRAS.OnlineStage
open PhysicalStream TreeTyped ExecutableSource NumericLadder TreeFraction ExecutableScaling
open UnitRefresh Transport Enlargement TreeTyped.Numbered ExecutableAdaptive Variation

attribute [local instance] NumberedHierarchy.labelOrder
attribute [local instance] Transport.sym2Order Transport.bagEdgeOrder Transport.bagEdgeFintype
attribute [local instance] UnitRefresh.Computable.allowedDec Transport.prodOrder Transport.sumOrder

variable {n : β„•} [Nontrivial (Fin n)]
variable (w : Fin nβ†’Fin nβ†’β„š) (K D m : β„•)
abbrev vertexCount := Fintype.card (SourceVertex (Fin n) K)
abbrev labelCount := Fintype.card (RationalSource.Label w K)
abbrev edgeCount := Fintype.card (BagEdge (RationalSource.bags w K))
abbrev tierCount := Transport.endpoint (vertexCount (n:=n) K) D K Fintype.card_pos
abbrev copies := ladderQ (vertexCount (n:=n) K) D
abbrev scansCount := discreteLadderSteps (vertexCount (n:=n) K) D K (tierCount (n:=n) K D) m
abbrev choiceWidth (Ξ· : β„š) := bitPrecision (scansCount (n:=n) K D m *
  scanErrorNumerator (SourceVertex (Fin n) K) (RationalSource.Label w K) (RationalSource.bags w K)
    (tierCount (n:=n) K D) (copies (n:=n) K D)) Ξ·
abbrev markWidth (Ξ· : β„š) := bitPrecision (6*edgeCount w K) Ξ·
abbrev Raw (Ξ· : β„š) := OnlineSample.Random (vertexCount (n:=n) K) (choiceWidth w K D m Ξ·)
  (scansCount (n:=n) K D m) (edgeCount w K) (markWidth w K Ξ·)

def rawEquiv (Ξ· : β„š) :
    ((Fin (scansCount (n:=n) K D m*scanBitCount (vertexCount (n:=n) K) (choiceWidth w K D m Ξ·))β†’Bool) Γ—
      (BagEdge (RationalSource.bags w K)β†’Fin (markWidth w K Ξ·)β†’Bool)) ≃ Raw w K D m Ξ· :=
  Equiv.prodCongr (runBitsEquiv (SourceVertex (Fin n) K) (choiceWidth w K D m Ξ·) (scansCount (n:=n) K D m))
    (Equiv.arrowCongr (orderedEnum (BagEdge (RationalSource.bags w K))).symm (Equiv.refl _))
lemma raw_scan (Ξ· : β„š) (bs : Raw w K D m Ξ·) :
    runBitsEquiv (SourceVertex (Fin n) K) (choiceWidth w K D m Ξ·) (scansCount (n:=n) K D m)
      ((rawEquiv w K D m Ξ·).symm bs).1=bs.1 :=
  congrArg Prod.fst ((rawEquiv w K D m Ξ·).apply_symm_apply bs)
lemma raw_marks (Ξ· : β„š) (bs : Raw w K D m Ξ·) (e : BagEdge (RationalSource.bags w K)) :
    ((rawEquiv w K D m Ξ·).symm bs).2 e=bs.2 ((orderedEnum _).symm e) := rfl
noncomputable def rawDraw (hw : βˆ€ a b,0<w a b) (hD : 0<D)
    (hu : βˆ€ a b,aβ‰ bβ†’BottleneckAlgorithm.edge w a b≀(4:β„š)^K)
    (hq : 0<copies (n:=n) K D) (he : Even n) (Ξ· : β„š) : Raw w K D m Ξ·β†’RationalSource.Marked w K :=
  RationalSource.markedSampler w hw K D m hD Fintype.card_pos hu hq
    (RationalSource.startMatching w K he) η ∘ (rawEquiv w K D m η).symm

noncomputable def core (hw : βˆ€ a b,0<w a b) (hD : 0<D)
    (hu : βˆ€ a b,aβ‰ bβ†’BottleneckAlgorithm.edge w a b≀(4:β„š)^K) (he : Even n)
    (T q : β„•) (hq : 0<q) {k r km : β„•}
    (bits : Fin r→ScanBits (SourceVertex (Fin n) K) k)
    (mb : BagEdge (RationalSource.bags w K)→Fin km→Bool) : RationalSource.Marked w K :=
  TableMarking.reveal (BagEdge.Incident (bags:=RationalSource.bags w K))
    (ladderRun (RationalSource.bags_adjacent w K hu) (RationalSource.tree_acyclic w K)
      (fun l : RationalSource.Label w K=>l.1.val) (RationalSource.parent w K)
      (RationalSource.bags_ranked w K hu) (RationalSource.bags_nonempty w K)
      (RationalSource.parent_rank w K) hq (RationalSource.bagWeight w K D)
      (RationalSource.startMatching w K he) k r (fun _=>RationalSource.startMatching w K he) bits
      (topSlot T q hq))
    (fun e=>(RationalSource.markingTable w hw K D hD e).draw km (mb e))
lemma generated_eq_core (hw : βˆ€ a b,0<w a b) (hD : 0<D)
    (hu : βˆ€ a b,aβ‰ bβ†’BottleneckAlgorithm.edge w a b≀(4:β„š)^K) (he : Even n)
    (ft fq : List Bool) (hq : 0<fq.length) {k r km : β„•}
    (bits : Fin r→ScanBits (SourceVertex (Fin n) K) k)
    (mb : BagEdge (RationalSource.bags w K)→Fin km→Bool) :
    generatedSourceSample he w hw K D hD hu ft fq hq bits mb=
      core w K D hw hD hu he ft.length fq.length hq bits mb := rfl

lemma generated_eq_raw (hw : βˆ€ a b,0<w a b) (hD : 0<D)
    (hu : βˆ€ a b,aβ‰ bβ†’BottleneckAlgorithm.edge w a b≀(4:β„š)^K)
    (hq : 0<copies (n:=n) K D) (he : Even n) (Ξ· : β„š) (bs : Raw w K D m Ξ·) :
    generatedSourceSample he w hw K D hD hu
      (List.replicate (tierCount (n:=n) K D) false) (List.replicate (copies (n:=n) K D) false)
      (by simpa only [List.length_replicate] using hq) bs.1
      (fun e=>bs.2 ((orderedEnum (BagEdge (RationalSource.bags w K))).symm e)) =
    rawDraw w K D m hw hD hu hq he Ξ· bs := by
  rw [generated_eq_core]
  simp only [List.length_replicate]
  unfold core rawDraw RationalSource.markedSampler TableMarking.draw RationalSource.topSampler
    RationalSource.sampler finiteLadder ladderBitRun
  simp only [Function.comp_apply,raw_scan,raw_marks]

noncomputable local instance : Fintype (BagPM (RationalSource.bags w K)) := Fintype.ofFinite _
noncomputable local instance : Fintype (RationalSource.Marked w K) := Fintype.ofFinite _
lemma rawDraw_law (hw : βˆ€ a b,0<w a b) (hD : 0<D)
    (hu : βˆ€ a b,aβ‰ bβ†’BottleneckAlgorithm.edge w a b≀(4:β„š)^K)
    (hq : 0<copies (n:=n) K D) (he : Even n) (Ξ· : β„š) :
    imageLaw (rawDraw w K D m hw hD hu hq he Ξ·)=
      RationalSource.markedSamplerLaw w hw K D m hD Fintype.card_pos hu hq
        (RationalSource.startMatching w K he) Ξ· := by
  unfold rawDraw RationalSource.markedSamplerLaw
  apply Eq.trans (imageLaw_comp_equiv (rawEquiv w K D m Ξ·).symm _)
  exact imageLaw_instances _ _ _
end MatchingFPRAS.OnlineStage

end OAI