File size: 8,497 Bytes
e5a97c6 | 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 | import Mathlib
import OAI.Combinatorics.MatchingCount.Tapes.TreeSparseStage
import OAI.Combinatorics.MatchingCount.Algorithm.TreeGeneratedCertificate
import OAI.Combinatorics.MatchingCount.Algorithm.TreeCertificate
namespace OAI
namespace MatchingFPRAS.ExecutableSource
open TreeTyped TreeFraction TreeTyped.Numbered ExecutableBottleneck ExecutableHierarchy ExecutableRefresh Enlargement RealGeometry NumericLadder
open ExecutableLadder UnitRefresh Replica.Ladder Transport NumericMarking ExecutableStatistics ExecutableScaling ExecutableAdaptive
attribute [local instance] NumberedHierarchy.labelOrder
attribute [local instance] Transport.sym2Order Transport.bagEdgeOrder Transport.bagEdgeFintype
attribute [local instance] UnitRefresh.Computable.allowedDec Transport.prodOrder Transport.sumOrder
abbrev CertificateMatrixInput := GraphData×Vector
def certificateCellData (x : CertificateMatrixInput) : CellData := ((x.1.2,(0,1)),x.2)
def certificateCellDataRealizer : Realizer certificateCellData :=
(TreeTyped.pair (TreeTyped.pair first.snd (constant (0,1))) second).congr (fun _=>rfl)
lemma polynomial_certificateCellData : PolynomialTime certificateCellDataRealizer := by
unfold certificateCellDataRealizer; apply polynomial_congr
dsimp only [Realizer.fst,Realizer.snd]
tree_cost
def certificateMatrix (x : CertificateMatrixInput) : Matrix :=
x.1.1.map (fun i=>stageRow ((certificateCellData x,x.1.1),i))
def certificateMatrixRealizer : Realizer certificateMatrix :=
(composition (TreeTyped.pair (TreeTyped.pair certificateCellDataRealizer first.fst) first.fst)
(mapWith stageRowRealizer)).congr (fun _=>rfl)
lemma polynomial_certificateMatrix : PolynomialTime certificateMatrixRealizer := by
unfold certificateMatrixRealizer; apply polynomial_congr
have := polynomial_certificateCellData
have := polynomial_stageRow
dsimp only [Realizer.fst,Realizer.snd]
tree_cost
lemma certificateMatrix_source {G : GraphInput} {j : ℕ} (s : FiniteTrial.ScaleState G j) :
certificateMatrix (graphRep G,vectorRep s.scale)=matrixRep s.certificateActivity := by
have hr (i j : Fin G.n) : (0:ℚ)≤ if (min i j,max i j)∈G.edges then 1 else 0 := by
split_ifs <;> norm_num
have hc (i j : Fin G.n) :
rawCell (certificateCellData (graphRep G,vectorRep s.scale),(i.val,j.val))=
TreeFraction.repr (if (min i j,max i j)∈G.edges then (1:ℚ) else 0) := by
unfold rawCell certificateCellData
dsimp only
simp only [edge_mem_graphRep]
split_ifs <;> rfl
unfold certificateMatrix stageRow matrixRep
change (List.range G.n).map _=List.ofFn _
rw [ExecutableDP.map_range_ofFn]
congr 1
funext i
change (List.range G.n).map _=List.ofFn _
rw [ExecutableDP.map_range_ofFn]
congr 1
funext j
unfold stageCell
rw [hc,show (certificateCellData (graphRep G,vectorRep s.scale)).2=vectorRep s.scale from rfl,
lookup_vectorRep s.scale i,lookup_vectorRep s.scale j,mul_repr (hr i j) (s.positive i).le,
mul_repr (mul_nonneg (hr i j) (s.positive i).le) (s.positive j).le]
rfl
def sparseCertificateMatrixArg (x : SparseStageData) : CertificateMatrixInput := (x.1.1.1,x.2)
def sparseCertificateMatrixArgRealizer : Realizer sparseCertificateMatrixArg :=
(TreeTyped.pair first.fst.fst second).congr (fun _=>rfl)
lemma polynomial_sparseCertificateMatrixArg : PolynomialTime sparseCertificateMatrixArgRealizer := by
unfold sparseCertificateMatrixArgRealizer; apply polynomial_congr
dsimp only [Realizer.fst,Realizer.snd]
tree_cost
def sparseCertificateData (x : SparseStageData) : GeneratedStageData :=
(sparseGeneratedInput x,certificateMatrix (sparseCertificateMatrixArg x))
def sparseCertificateDataRealizer : Realizer sparseCertificateData := (TreeTyped.pair
sparseGeneratedInputRealizer (composition sparseCertificateMatrixArgRealizer certificateMatrixRealizer)).congr (fun _=>rfl)
lemma polynomial_sparseCertificateData : PolynomialTime sparseCertificateDataRealizer := polynomial_congr _
(TreeTyped.polynomial_pair polynomial_sparseGeneratedInput
(polynomial_composition polynomial_sparseCertificateMatrixArg polynomial_certificateMatrix))
def sparseCertificate (x : SparseStageData×SampleBits) : Fraction := generatedCertificate (sparseCertificateData x.1,x.2)
def sparseCertificateRealizer : Realizer sparseCertificate := (composition
(TreeTyped.pair (composition first sparseCertificateDataRealizer) second) generatedCertificateRealizer).congr (fun _=>rfl)
lemma polynomial_sparseCertificate : PolynomialTime sparseCertificateRealizer := polynomial_congr _
(polynomial_composition (TreeTyped.polynomial_pair
(polynomial_composition polynomial_first polynomial_sparseCertificateData) polynomial_second) polynomial_generatedCertificate)
lemma sparseCertificateData_source {G : GraphInput} {j : ℕ} (s : FiniteTrial.ScaleState G j)
(K D : ℕ) (ft fq : List Bool) :
sparseCertificateData (((graphRep G,List.replicate j false),
(((List.replicate (2*K+2) false,List.replicate (2*K) false),D),(ft,fq))),vectorRep s.scale)=
((((((matrixRep s.activity,List.replicate (2*K+2) false),List.range G.n),List.replicate (2*K) false),D),(ft,fq)),
matrixRep s.certificateActivity) := by
unfold sparseCertificateData sparseGeneratedInput sparseBagInput sparseCurrentMatrix currentActivityArg sparseCertificateMatrixArg
dsimp only
rw [stageMatrix_rep G _ s.scale (fun i=>(s.positive i).le),certificateMatrix_source]
simp only [List.length_replicate]
rfl
lemma sparseCertificate_source {G : GraphInput} [Nontrivial (Fin G.n)] (hn : 2≤G.n)
(he : Even G.n) {j : ℕ} (s : FiniteTrial.ScaleState G j) (K D : ℕ) (hD : 0<D)
(hu : ∀ a b,a≠b→BottleneckAlgorithm.edge s.activity a b≤(4:ℚ)^K)
(ft fq : List Bool) (hq : 0<fq.length) {k r km : ℕ}
(bits : Fin r→ScanBits (SourceVertex (Fin G.n) K) k)
(mb : BagEdge (RationalSource.bags s.activity K)→Fin km→Bool) :
let keys := List.ofFn (orderedEnum (BagEdge (RationalSource.bags s.activity K)))
sparseCertificate
((((graphRep G,List.replicate j false),
(((List.replicate (2*K+2) false,List.replicate (2*K) false),D),(ft,fq))),vectorRep s.scale),
(List.ofFn (fun z=>(List.ofFn (bits z).1,localBitsRep (bits z).2)),
keys.map (fun e=>(index e,List.ofFn (mb e)))))=
TreeFraction.repr (RationalSource.observableD s.activity s.certificateActivity K
(generatedSourceSample he s.activity s.activity_pos K D hD hu ft fq hq bits mb)) := by
dsimp only
unfold sparseCertificate
rw [sparseCertificateData_source]
have hnonneg : ∀ a b,0 ≤ s.certificateActivity a b := by
intro a b
have h:=s.toReal.certificateActivity_nonneg a b
rw [←s.certificateActivity_cast] at h
change (0:ℝ) ≤ (s.certificateActivity a b:ℝ) at h
exact_mod_cast h
exact generatedCertificate_source hn he s.activity s.certificateActivity s.activity_pos hnonneg K D hD hu ft fq hq bits mb
lemma sparseCertificate_zero {G : GraphInput} [Nontrivial (Fin G.n)] (hn : 2≤G.n)
(he : Even G.n) {j : ℕ} (s : FiniteTrial.ScaleState G j) (hZ : Z G=0)
(K D : ℕ) (hD : 0<D)
(hu : ∀ a b,a≠b→BottleneckAlgorithm.edge s.activity a b≤(4:ℚ)^K)
(ft fq : List Bool) (hq : 0<fq.length) {k r km : ℕ}
(bits : Fin r→ScanBits (SourceVertex (Fin G.n) K) k)
(mb : BagEdge (RationalSource.bags s.activity K)→Fin km→Bool) :
let keys := List.ofFn (orderedEnum (BagEdge (RationalSource.bags s.activity K)))
sparseCertificate
((((graphRep G,List.replicate j false),
(((List.replicate (2*K+2) false,List.replicate (2*K) false),D),(ft,fq))),vectorRep s.scale),
(List.ofFn (fun z=>(List.ofFn (bits z).1,localBitsRep (bits z).2)),
keys.map (fun e=>(index e,List.ofFn (mb e)))))=TreeFraction.repr 0 := by
dsimp only
rw [sparseCertificate_source hn he s K D hD hu ft fq hq bits mb,
generated_certificate_zero he s hZ K D hD hu ft fq hq bits mb]
open TreePost Turing
theorem sparseCertificate_post : ∃ p : Polynomial ℕ,∀ x : SparseStageData×SampleBits,∀ t : ℕ,
p.eval (packed x).length≤t → ∀ coins : Fin t→Bool,
(run (machine sparseCertificateRealizer.program) (packed x) coins).state=none ∧
(run (machine sparseCertificateRealizer.program) (packed x) coins).tape.right₀=
ListBlank.mk (packed (sparseCertificate x)) :=
polynomial_compiles sparseCertificateRealizer polynomial_sparseCertificate
end MatchingFPRAS.ExecutableSource
end OAI
|