File size: 4,158 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import Mathlib
import OAI.Probability.CriticalPercolation.Exploration.Exhaustive

namespace OAI

section
section
open Set MeasureTheory ProbabilityTheory
open Set
open scoped BigOperators
open scoped Classical

namespace CriticalPercolation.LazyDFS
open scoped Classical

variable {V E : Type*} [DecidableEq V] [DecidableEq E]

lemma compile_sound (G : BondGraph V E) (order : List (Dart V E)) (B : Set V)
    (fuel : β„•) (st : State V E) (stack : List (Dart V E)) (Ο‰ : E β†’ Bool) (w : V)
    (hs : βˆ€ v ∈ st.reached, (G.openGraph {e | Ο‰ e = true}).Reachable w v) :
    βˆ€ v ∈ ((compile G order B fuel st stack).run Ο‰).reached,
      (G.openGraph {e | Ο‰ e = true}).Reachable w v := by
  induction fuel generalizing st stack with
  | zero => exact hs
  | succ n ih =>
    rw [compile.eq_def]
    dsimp only
    split_ifs with hh
    Β· exact hs
    Β· cases stack with
      | nil => exact hs
      | cons d rest =>
        dsimp only
        split_ifs with hd
        Β· exact ih st rest hs
        Β· rw [SearchTree.run]
          split_ifs with he
          Β· apply ih
            intro u hu
            rcases Finset.mem_insert.mp hu with rfl | hu
            Β· have hdec : d.2.2 βˆ‰ st.reached ∧ d.2.1 βˆ‰ st.read ∧ d.1 ∈ st.reached ∧
                  G.ends d.2.1 = s(d.1,d.2.2) := by
                push Not at hd
                exact hd
              exact (hs d.1 hdec.2.2.1).trans (openEdge_reachable G Ο‰ he hdec.2.2.2)
            Β· exact hs u hu
          Β· exact ih (st.closed d.2.1) rest hs

omit [DecidableEq V] [DecidableEq E] in
lemma reachable_mem_of_closed (H : SimpleGraph V) (S : Finset V)
    (hc : βˆ€ v ∈ S, βˆ€ t, H.Adj v t β†’ t ∈ S) {v t : V}
    (hr : H.Reachable v t) (hv : v ∈ S) : t ∈ S := by
  have hh : βˆ€ {u z : V}, H.Walk u z β†’ u ∈ S β†’ z ∈ S := by
    intro u z path
    induction path with
    | nil => exact id
    | cons ha _ ih => exact fun hu => ih (hc _ hu _ ha)
  exact hr.elim (fun path => hh path hv)

noncomputable def initial (w : V) : State V E := ⟨{w},βˆ…βŸ©

omit [DecidableEq E] in
lemma initial_frontier (G : BondGraph V E) (order : List (Dart V E))
    (ho : Exhaustive G order) (w : V) : Frontier G (initial w) (push G order w) := by
  intro v hv e t he _
  have hvw : v = w := Finset.mem_singleton.mp hv
  subst v
  exact Or.inr (List.mem_filter.mpr ⟨ho w e t he,by simpa only [decide_eq_true_eq,true_and] using he⟩)

omit [DecidableEq V] [DecidableEq E] in
lemma initial_consistent (G : BondGraph V E) (w : V) (Ο‰ : E β†’ Bool) :
    ReadConsistent G (initial w) Ο‰ := by
  intro e he
  exact (Finset.notMem_empty e he).elim

variable [Fintype V]

noncomputable def search (G : BondGraph V E) (order : List (Dart V E)) (w : V) (B : Set V) :
    SearchTree E (State V E) :=
  compile G order B (rank order (initial w) (push G order w)) (initial w) (push G order w)

theorem search_decides (G : BondGraph V E) (order : List (Dart V E))
    (ho : Exhaustive G order) (w : V) (B : Set V) (Ο‰ : E β†’ Bool) :
    (βˆƒ v ∈ ((search G order w B).run Ο‰).reached, v ∈ B) ↔
      βˆƒ v ∈ B, (G.openGraph {e | Ο‰ e = true}).Reachable w v := by
  have hs : βˆ€ v ∈ (initial (E := E) w).reached,
      (G.openGraph {e | Ο‰ e = true}).Reachable w v := by
    intro v hv
    have : v = w := Finset.mem_singleton.mp hv
    subst v
    exact .refl _
  constructor
  · rintro ⟨v,hv,hB⟩
    exact ⟨v,hB,compile_sound G order B _ _ _ Ο‰ w hs v hv⟩
  · rintro ⟨v,hB,hr⟩
    rcases compile_success_or_closed G order ho B _ (initial w) (push G order w) Ο‰
      (initial_frontier G order ho w) (initial_consistent G w Ο‰) le_rfl with h | h
    Β· exact h
    Β· have hw : w ∈ ((search G order w B).run Ο‰).reached :=
        (compile_mono G order B _ (initial w) (push G order w) Ο‰).1 (Finset.mem_singleton_self _)
      exact ⟨v,reachable_mem_of_closed _ _ h hr hw,hB⟩

theorem search_reads_nodup (G : BondGraph V E) (order : List (Dart V E))
    (w : V) (B : Set V) (Ο‰ : E β†’ Bool) : ((search G order w B).reads Ο‰).Nodup :=
  SearchTree.reads_nodup _ _ (compile_valid G order B _ _ _) Ο‰

end CriticalPercolation.LazyDFS

end
end

end OAI