Theory Monitor
theory Monitor
imports Abstract_Monitor MFOTL Table
begin
section ‹Monitor implementation›
subsection ‹Monitorable formulas›
definition "mmonitorable φ ⟷ safe_formula φ ∧ MFOTL.future_reach φ ≠ ∞"
fun mmonitorable_exec :: "'a MFOTL.formula ⇒ bool" where
"mmonitorable_exec (MFOTL.Eq t1 t2) = (MFOTL.is_Const t1 ∨ MFOTL.is_Const t2)"
| "mmonitorable_exec (MFOTL.Neg (MFOTL.Eq (MFOTL.Const x) (MFOTL.Const y))) = True"
| "mmonitorable_exec (MFOTL.Neg (MFOTL.Eq (MFOTL.Var x) (MFOTL.Var y))) = (x = y)"
| "mmonitorable_exec (MFOTL.Pred e ts) = True"
| "mmonitorable_exec (MFOTL.Neg (MFOTL.Or (MFOTL.Neg φ) ψ)) = (mmonitorable_exec φ ∧
(mmonitorable_exec ψ ∧ MFOTL.fv ψ ⊆ MFOTL.fv φ ∨ (case ψ of MFOTL.Neg ψ' ⇒ mmonitorable_exec ψ' | _ ⇒ False)))"
| "mmonitorable_exec (MFOTL.Or φ ψ) = (MFOTL.fv ψ = MFOTL.fv φ ∧ mmonitorable_exec φ ∧ mmonitorable_exec ψ)"
| "mmonitorable_exec (MFOTL.Exists φ) = (mmonitorable_exec φ)"
| "mmonitorable_exec (MFOTL.Prev I φ) = (mmonitorable_exec φ)"
| "mmonitorable_exec (MFOTL.Next I φ) = (mmonitorable_exec φ ∧ right I ≠ ∞)"
| "mmonitorable_exec (MFOTL.Since φ I ψ) = (MFOTL.fv φ ⊆ MFOTL.fv ψ ∧
(mmonitorable_exec φ ∨ (case φ of MFOTL.Neg φ' ⇒ mmonitorable_exec φ' | _ ⇒ False)) ∧ mmonitorable_exec ψ)"
| "mmonitorable_exec (MFOTL.Until φ I ψ) = (MFOTL.fv φ ⊆ MFOTL.fv ψ ∧ right I ≠ ∞ ∧
(mmonitorable_exec φ ∨ (case φ of MFOTL.Neg φ' ⇒ mmonitorable_exec φ' | _ ⇒ False)) ∧ mmonitorable_exec ψ)"
| "mmonitorable_exec _ = False"
lemma plus_eq_enat_iff: "a + b = enat i ⟷ (∃j k. a = enat j ∧ b = enat k ∧ j + k = i)"
by (cases a; cases b) auto
lemma minus_eq_enat_iff: "a - enat k = enat i ⟷ (∃j. a = enat j ∧ j - k = i)"
by (cases a) auto
lemma safe_formula_mmonitorable_exec: "safe_formula φ ⟹ MFOTL.future_reach φ ≠ ∞ ⟹ mmonitorable_exec φ"
proof (induct φ rule: safe_formula.induct)
case (5 φ ψ)
then show ?case
unfolding safe_formula.simps future_reach.simps mmonitorable_exec.simps
by (fastforce split: formula.splits)
next
case (6 φ ψ)
then show ?case
unfolding safe_formula.simps future_reach.simps mmonitorable_exec.simps
by (fastforce split: formula.splits)
next
case (10 φ I ψ)
then show ?case
unfolding safe_formula.simps future_reach.simps mmonitorable_exec.simps
by (fastforce split: formula.splits)
next
case (11 φ I ψ)
then show ?case
unfolding safe_formula.simps future_reach.simps mmonitorable_exec.simps
by (fastforce simp: plus_eq_enat_iff split: formula.splits)
qed (auto simp add: plus_eq_enat_iff minus_eq_enat_iff)
lemma mmonitorable_exec_mmonitorable: "mmonitorable_exec φ ⟹ mmonitorable φ"
proof (induct φ rule: mmonitorable_exec.induct)
case (5 φ ψ)
then show ?case
unfolding mmonitorable_def mmonitorable_exec.simps safe_formula.simps
by (fastforce split: formula.splits)
next
case (10 φ I ψ)
then show ?case
unfolding mmonitorable_def mmonitorable_exec.simps safe_formula.simps
by (fastforce split: formula.splits)
next
case (11 φ I ψ)
then show ?case
unfolding mmonitorable_def mmonitorable_exec.simps safe_formula.simps
by (fastforce simp: one_enat_def split: formula.splits)
qed (auto simp add: mmonitorable_def one_enat_def)
lemma monitorable_formula_code[code]: "mmonitorable φ = mmonitorable_exec φ"
using mmonitorable_exec_mmonitorable safe_formula_mmonitorable_exec mmonitorable_def
by blast
subsection ‹The executable monitor›
type_synonym ts = nat
type_synonym 'a mbuf2 = "'a table list × 'a table list"
type_synonym 'a msaux = "(ts × 'a table) list"
type_synonym 'a muaux = "(ts × 'a table × 'a table) list"