File size: 5,161 Bytes
f205175 | 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 | import Mathlib
import OAI.Probability.CriticalPercolation.Exploration.TargetSearch
namespace OAI
section
section
open Set MeasureTheory ProbabilityTheory
open Set
open scoped BigOperators
open scoped Classical
namespace CriticalPercolation.LazyDFS
open scoped Classical
open FiniteProduct SearchTree BondGraph
variable {V E : Type*} [DecidableEq V] [DecidableEq E]
lemma compile_empty_reads (G : BondGraph V E) (order : List (Dart V E)) (B : Set V)
(fuel : ℕ) (st : State V E) (ω : E → Bool) :
(compile G order B fuel st []).reads ω = [] := by
cases fuel with
| zero => rfl
| succ n =>
rw [compile.eq_def]
dsimp only
split_ifs <;> rfl
variable [Fintype V]
theorem compile_reads_rank_independent (G : BondGraph V E) (order : List (Dart V E)) (B : Set V)
(fuel fuel' : ℕ) (st : State V E) (stack : List (Dart V E)) (ω : E → Bool)
(hr : rank order st stack ≤ fuel) (hr' : rank order st stack ≤ fuel') :
(compile G order B fuel st stack).reads ω = (compile G order B fuel' st stack).reads ω := by
induction fuel generalizing fuel' st stack with
| zero =>
have hnil : stack = [] := by
have : stack.length = 0 := by unfold rank at hr; omega
exact List.length_eq_zero_iff.mp this
subst stack
rw [compile_empty_reads,compile_empty_reads]
| succ n ih =>
cases fuel' with
| zero =>
have hnil : stack = [] := by
have : stack.length = 0 := by unfold rank at hr'; omega
exact List.length_eq_zero_iff.mp this
subst stack
rw [compile_empty_reads,compile_empty_reads]
| succ m =>
rw [compile.eq_def,compile.eq_def]
dsimp only
split_ifs with hh
· rfl
· cases stack with
| nil => rfl
| cons d rest =>
dsimp only
split_ifs with hd
· have hpop := rank_pop order st d rest
exact ih m st rest (by omega) (by omega)
· rw [reads,reads]
congr 1
split_ifs with hω
· have hopen := rank_opened G order st d rest (fun h => hd (Or.inl h))
exact ih m _ _ (by omega) (by omega)
· have hclosed := rank_closed order st d rest
exact ih m _ _ (by omega) (by omega)
omit [Fintype V] [DecidableEq E] in
lemma push_goodDarts (G : BondGraph V E) (order : List (Dart V E)) (v : V) :
GoodDarts G (push G order v) := by
intro d hd
have hh := (List.mem_filter.mp hd).2
exact (of_decide_eq_true hh).2
omit [Fintype V] [DecidableEq V] [DecidableEq E] in
lemma goodDarts_append (G : BondGraph V E) (l r : List (Dart V E))
(hl : GoodDarts G l) (hr : GoodDarts G r) : GoodDarts G (l++r) := by
intro d hd
exact (List.mem_append.mp hd).elim (hl d) (hr d)
omit [Fintype V] in
theorem compile_reads_targetWiring (G : BondGraph V E) (B : Set V)
(order : List (Dart V E)) (horder : GoodDarts G order) (fuel : ℕ)
(st : State V E) (stack : List (Dart V E)) (hs : GoodDarts G stack)
(ω : E → Bool) :
(compile G order B fuel st stack).reads ω =
(compile (G.wireTargets B) (order.map (mapDart B)) {none} fuel (mapState B st)
(stack.map (mapDart B))).reads ω := by
induction fuel generalizing st stack with
| zero => rfl
| succ n ih =>
rw [compile.eq_def,compile.eq_def]
dsimp only
simp only [target_hit_map]
split_ifs with hh
· rfl
· cases stack with
| nil => rfl
| cons d rest =>
have hd := hs d (List.mem_cons_self ..)
have hd' := mapDart_ends G B d hd
have hr : GoodDarts G rest := fun d h => hs d (List.mem_cons_of_mem _ h)
simp only [List.map_cons]
have hmem := mapState_mem B st hh
have hRead : (mapState B st).read = st.read := rfl
have hEnds : (G.wireTargets B).ends d.2.1 =
s(collapseTarget B d.1, collapseTarget B d.2.2) := hd'
simp only [mapDart, hRead, hEnds, hd, ne_eq, not_true_eq_false, or_false, hmem]
split_ifs with hbad
· exact ih st rest hr
· rw [reads,reads]
congr 1
split_ifs with hbit
· by_cases hzB : d.2.2 ∈ B
· have hstop := compile_stop G order B n (st.opened d.2.1 d.2.2)
(push G order d.2.2++rest) ⟨d.2.2,Finset.mem_insert_self _ _,hzB⟩
have hzNone := (collapseTarget_eq_none B d.2.2).mpr hzB
have hstop' := compile_stop (G.wireTargets B) (order.map (mapDart B)) {none} n
((mapState B st).opened d.2.1 (collapseTarget B d.2.2))
(push (G.wireTargets B) (order.map (mapDart B)) (collapseTarget B d.2.2) ++
rest.map (mapDart B))
⟨none,by simp [State.opened,hzNone],Set.mem_singleton none⟩
rw [hstop,hstop']; rfl
· have hnew := ih (st.opened d.2.1 d.2.2) (push G order d.2.2++rest)
(goodDarts_append G _ _ (push_goodDarts G order d.2.2) hr)
rw [mapState_opened,List.map_append,push_mapTarget G B order horder d.2.2 hzB] at hnew
exact hnew
· exact ih (st.closed d.2.1) rest hr
end CriticalPercolation.LazyDFS
end
end
end OAI
|