Theory LinearTemporalLogic

theory LinearTemporalLogic
imports Traces AnswerIndexedFamilies Main
begin

chapter ‹Linear-time Temporal Logic›

datatype (atoms_ltl: 'a) ltl =
      True_ltl                             (truel)
    | Not_ltl 'a ltl                     (notl _› [85] 85)
    | Prop_ltl 'a                          (propl'(_'))
    | Or_ltl 'a ltl 'a ltl             (‹_ orl _› [82,82] 81)
    | And_ltl 'a ltl 'a ltl            (‹_ andl _  › [82,82] 81)
    | Next_ltl 'a ltl                    (Xl _› [88] 87)
    | Until_ltl 'a ltl 'a ltl          (‹_ Ul  _› [84,84] 83)

fun lsatisfying_AiF :: 'a  'a state infinite_trace AiF (lsat∙) where
lsat∙ x T = {t. x  L (t 0)} |
lsat∙ x F = {t. x  L (t 0)}

fun x_operator :: 'a infinite_trace AiF  'a infinite_trace AiF () where
 t T = {x | x. itdrop 1 x  (t T)}|
 t F = {x | x. itdrop 1 x  (t F)}

fun u_operator :: 'a infinite_trace AiF  'a infinite_trace AiF  'a infinite_trace AiF (infix  61) where
(a  b) T = {x | x. k. (i<k. itdrop i x  (a T))  itdrop k x  (b T)}|
(a  b) F = {x | x. k. (i<k. itdrop i x  (a F))  itdrop k x  (b F)}

fun ltl_semantics :: 'a ltl  'a state infinite_trace AiF (_l) where
 truel    l = T∙|
 notl φ   l = ¬·  φ l|
 propl(a) l = lsat∙ a|
 φ orl ψ  l =  φ l ∨·  ψ l|
 φ andl ψ l =  φ l ∧·  ψ l|
 Xl φ     l =   φ l|
 φ Ul ψ   l =  φ l   ψ l

lemma excluded_middle_ltl' : 
  shows (Γ  φl T)  (Γ  φl F)
  and   (Γ  φl F)  (Γ  φl T)
proof (induct φ arbitrary: Γ)
qed auto

lemma excluded_middle_ltl: Γ  φl T  Γ  φl F
  using excluded_middle_ltl' by blast

definition false_ltl (falsel) where
  false_ltl_def[simp]: falsel = notl truel

definition implies_ltl :: 'a ltl  'a ltl  'a ltl (infix impliesl 80)  where
  implies_ltl_def[simp]: φ impliesl ψ = (notl φ orl ψ)

definition final_ltl :: 'a ltl  'a ltl (Fl _›) where
  final_ltl_def[simp]: (Fl φ) = (truel Ul φ)

definition global_ltl :: 'a ltl  'a ltl (Gl _›) where
  global_ltl_def[simp]: (Gl φ) = (notl Fl (notl φ))

section ‹Linear temporal logic equivalence›

fun ltl_semantics' :: 'a state infinite_trace  'a ltl  bool (infix l 60) where
  Γ l truel    = True
| Γ l notl φ   = (¬ Γ l φ)
| Γ l propl(a) = (a  L (Γ 0))
| Γ l φ orl ψ  = (Γ l φ  Γ l ψ)
| Γ l φ andl ψ = (Γ l φ  Γ l ψ)
| Γ l (Xl φ)   = itdrop 1 Γ l φ
| Γ l (φ Ul ψ) = (k. (i<k. itdrop i Γ l φ)  itdrop k Γ l ψ)


section ‹Linear temporal logic lemmas›
lemma  Fl (Fl φ) l =  Fl φ l
proof (rule AiF_cases)
  show Fl Fl φl T = Fl φl T
    apply (clarsimp intro!: set_eqI, rule)
     apply auto[1]
    by (clarsimp, metis add_0)
next
  show Fl Fl φl F = Fl φl F
    apply (clarsimp intro!: set_eqI, rule)
     apply (clarsimp, metis add_0)
    by simp
qed

lemma ltl_equivalence: 
  shows Γ l φ  = (Γ   φ l T)
  and   (¬ Γ l φ) = (Γ   φ l F)
proof(induct φ arbitrary: Γ)
qed auto

end