src/HOL/Library/Linear_Temporal_Logic_on_Streams.thy
author hoelzl
Thu Nov 13 17:19:52 2014 +0100 (2014-11-13)
changeset 59000 6eb0725503fc
parent 58881 b9556a055632
child 60500 903bb1495239
permissions -rw-r--r--
import general theorems from AFP/Markov_Models
hoelzl@58627
     1
(*  Title:      HOL/Library/Linear_Temporal_Logic_on_Streams.thy
hoelzl@58627
     2
    Author:     Andrei Popescu, TU Muenchen
hoelzl@58627
     3
    Author:     Dmitriy Traytel, TU Muenchen
hoelzl@58627
     4
*)
hoelzl@58627
     5
wenzelm@58881
     6
section {* Linear Temporal Logic on Streams *}
hoelzl@58627
     7
hoelzl@58627
     8
theory Linear_Temporal_Logic_on_Streams
hoelzl@59000
     9
  imports Stream Sublist Extended_Nat Infinite_Set
hoelzl@58627
    10
begin
hoelzl@58627
    11
hoelzl@58627
    12
section{* Preliminaries *}
hoelzl@58627
    13
hoelzl@58627
    14
lemma shift_prefix:
hoelzl@58627
    15
assumes "xl @- xs = yl @- ys" and "length xl \<le> length yl"
hoelzl@58627
    16
shows "prefixeq xl yl"
hoelzl@58627
    17
using assms proof(induct xl arbitrary: yl xs ys)
hoelzl@58627
    18
  case (Cons x xl yl xs ys)
hoelzl@58627
    19
  thus ?case by (cases yl) auto
hoelzl@58627
    20
qed auto
hoelzl@58627
    21
hoelzl@58627
    22
lemma shift_prefix_cases:
hoelzl@58627
    23
assumes "xl @- xs = yl @- ys"
hoelzl@58627
    24
shows "prefixeq xl yl \<or> prefixeq yl xl"
hoelzl@58627
    25
using shift_prefix[OF assms] apply(cases "length xl \<le> length yl")
hoelzl@58627
    26
by (metis, metis assms nat_le_linear shift_prefix)
hoelzl@58627
    27
hoelzl@58627
    28
hoelzl@58627
    29
section{* Linear temporal logic *}
hoelzl@58627
    30
hoelzl@58627
    31
(* Propositional connectives: *)
hoelzl@58627
    32
abbreviation (input) IMPL (infix "impl" 60)
hoelzl@58627
    33
where "\<phi> impl \<psi> \<equiv> \<lambda> xs. \<phi> xs \<longrightarrow> \<psi> xs"
hoelzl@58627
    34
hoelzl@58627
    35
abbreviation (input) OR (infix "or" 60)
hoelzl@58627
    36
where "\<phi> or \<psi> \<equiv> \<lambda> xs. \<phi> xs \<or> \<psi> xs"
hoelzl@58627
    37
hoelzl@58627
    38
abbreviation (input) AND (infix "aand" 60)
hoelzl@58627
    39
where "\<phi> aand \<psi> \<equiv> \<lambda> xs. \<phi> xs \<and> \<psi> xs"
hoelzl@58627
    40
hoelzl@58627
    41
abbreviation (input) "not \<phi> \<equiv> \<lambda> xs. \<not> \<phi> xs"
hoelzl@58627
    42
hoelzl@58627
    43
abbreviation (input) "true \<equiv> \<lambda> xs. True"
hoelzl@58627
    44
hoelzl@58627
    45
abbreviation (input) "false \<equiv> \<lambda> xs. False"
hoelzl@58627
    46
hoelzl@58627
    47
lemma impl_not_or: "\<phi> impl \<psi> = (not \<phi>) or \<psi>"
hoelzl@58627
    48
by blast
hoelzl@58627
    49
hoelzl@58627
    50
lemma not_or: "not (\<phi> or \<psi>) = (not \<phi>) aand (not \<psi>)"
hoelzl@58627
    51
by blast
hoelzl@58627
    52
hoelzl@58627
    53
lemma not_aand: "not (\<phi> aand \<psi>) = (not \<phi>) or (not \<psi>)"
hoelzl@58627
    54
by blast
hoelzl@58627
    55
hoelzl@58627
    56
lemma non_not[simp]: "not (not \<phi>) = \<phi>" by simp
hoelzl@58627
    57
hoelzl@58627
    58
(* Temporal (LTL) connectives: *)
hoelzl@58627
    59
fun holds where "holds P xs \<longleftrightarrow> P (shd xs)"
hoelzl@58627
    60
fun nxt where "nxt \<phi> xs = \<phi> (stl xs)"
hoelzl@58627
    61
hoelzl@59000
    62
definition "HLD s = holds (\<lambda>x. x \<in> s)"
hoelzl@59000
    63
hoelzl@59000
    64
abbreviation HLD_nxt (infixr "\<cdot>" 65) where
hoelzl@59000
    65
  "s \<cdot> P \<equiv> HLD s aand nxt P"
hoelzl@59000
    66
hoelzl@58627
    67
inductive ev for \<phi> where
hoelzl@58627
    68
base: "\<phi> xs \<Longrightarrow> ev \<phi> xs"
hoelzl@58627
    69
|
hoelzl@58627
    70
step: "ev \<phi> (stl xs) \<Longrightarrow> ev \<phi> xs"
hoelzl@58627
    71
hoelzl@58627
    72
coinductive alw for \<phi> where
hoelzl@58627
    73
alw: "\<lbrakk>\<phi> xs; alw \<phi> (stl xs)\<rbrakk> \<Longrightarrow> alw \<phi> xs"
hoelzl@58627
    74
hoelzl@58627
    75
(* weak until: *)
hoelzl@58627
    76
coinductive UNTIL (infix "until" 60) for \<phi> \<psi> where
hoelzl@58627
    77
base: "\<psi> xs \<Longrightarrow> (\<phi> until \<psi>) xs"
hoelzl@58627
    78
|
hoelzl@58627
    79
step: "\<lbrakk>\<phi> xs; (\<phi> until \<psi>) (stl xs)\<rbrakk> \<Longrightarrow> (\<phi> until \<psi>) xs"
hoelzl@58627
    80
hoelzl@58627
    81
lemma holds_mono:
hoelzl@58627
    82
assumes holds: "holds P xs" and 0: "\<And> x. P x \<Longrightarrow> Q x"
hoelzl@58627
    83
shows "holds Q xs"
hoelzl@58627
    84
using assms by auto
hoelzl@58627
    85
hoelzl@58627
    86
lemma holds_aand:
hoelzl@58627
    87
"(holds P aand holds Q) steps \<longleftrightarrow> holds (\<lambda> step. P step \<and> Q step) steps" by auto
hoelzl@58627
    88
hoelzl@59000
    89
lemma HLD_iff: "HLD s \<omega> \<longleftrightarrow> shd \<omega> \<in> s"
hoelzl@59000
    90
  by (simp add: HLD_def)
hoelzl@59000
    91
hoelzl@59000
    92
lemma HLD_Stream[simp]: "HLD X (x ## \<omega>) \<longleftrightarrow> x \<in> X"
hoelzl@59000
    93
  by (simp add: HLD_iff)
hoelzl@59000
    94
hoelzl@58627
    95
lemma nxt_mono:
hoelzl@58627
    96
assumes nxt: "nxt \<phi> xs" and 0: "\<And> xs. \<phi> xs \<Longrightarrow> \<psi> xs"
hoelzl@58627
    97
shows "nxt \<psi> xs"
hoelzl@58627
    98
using assms by auto
hoelzl@58627
    99
hoelzl@59000
   100
declare ev.intros[intro]
hoelzl@59000
   101
declare alw.cases[elim]
hoelzl@59000
   102
hoelzl@59000
   103
lemma ev_induct_strong[consumes 1, case_names base step]:
hoelzl@59000
   104
  "ev \<phi> x \<Longrightarrow> (\<And>xs. \<phi> xs \<Longrightarrow> P xs) \<Longrightarrow> (\<And>xs. ev \<phi> (stl xs) \<Longrightarrow> \<not> \<phi> xs \<Longrightarrow> P (stl xs) \<Longrightarrow> P xs) \<Longrightarrow> P x"
hoelzl@59000
   105
  by (induct rule: ev.induct) auto
hoelzl@59000
   106
hoelzl@59000
   107
lemma alw_coinduct[consumes 1, case_names alw stl]:
hoelzl@59000
   108
  "X x \<Longrightarrow> (\<And>x. X x \<Longrightarrow> \<phi> x) \<Longrightarrow> (\<And>x. X x \<Longrightarrow> \<not> alw \<phi> (stl x) \<Longrightarrow> X (stl x)) \<Longrightarrow> alw \<phi> x"
hoelzl@59000
   109
  using alw.coinduct[of X x \<phi>] by auto
hoelzl@59000
   110
hoelzl@58627
   111
lemma ev_mono:
hoelzl@58627
   112
assumes ev: "ev \<phi> xs" and 0: "\<And> xs. \<phi> xs \<Longrightarrow> \<psi> xs"
hoelzl@58627
   113
shows "ev \<psi> xs"
hoelzl@58627
   114
using ev by induct (auto intro: ev.intros simp: 0)
hoelzl@58627
   115
hoelzl@58627
   116
lemma alw_mono:
hoelzl@58627
   117
assumes alw: "alw \<phi> xs" and 0: "\<And> xs. \<phi> xs \<Longrightarrow> \<psi> xs"
hoelzl@58627
   118
shows "alw \<psi> xs"
hoelzl@58627
   119
using alw by coinduct (auto elim: alw.cases simp: 0)
hoelzl@58627
   120
hoelzl@58627
   121
lemma until_monoL:
hoelzl@58627
   122
assumes until: "(\<phi>1 until \<psi>) xs" and 0: "\<And> xs. \<phi>1 xs \<Longrightarrow> \<phi>2 xs"
hoelzl@58627
   123
shows "(\<phi>2 until \<psi>) xs"
hoelzl@58627
   124
using until by coinduct (auto elim: UNTIL.cases simp: 0)
hoelzl@58627
   125
hoelzl@58627
   126
lemma until_monoR:
hoelzl@58627
   127
assumes until: "(\<phi> until \<psi>1) xs" and 0: "\<And> xs. \<psi>1 xs \<Longrightarrow> \<psi>2 xs"
hoelzl@58627
   128
shows "(\<phi> until \<psi>2) xs"
hoelzl@58627
   129
using until by coinduct (auto elim: UNTIL.cases simp: 0)
hoelzl@58627
   130
hoelzl@58627
   131
lemma until_mono:
hoelzl@58627
   132
assumes until: "(\<phi>1 until \<psi>1) xs" and
hoelzl@58627
   133
0: "\<And> xs. \<phi>1 xs \<Longrightarrow> \<phi>2 xs" "\<And> xs. \<psi>1 xs \<Longrightarrow> \<psi>2 xs"
hoelzl@58627
   134
shows "(\<phi>2 until \<psi>2) xs"
hoelzl@58627
   135
using until by coinduct (auto elim: UNTIL.cases simp: 0)
hoelzl@58627
   136
hoelzl@58627
   137
lemma until_false: "\<phi> until false = alw \<phi>"
hoelzl@58627
   138
proof-
hoelzl@58627
   139
  {fix xs assume "(\<phi> until false) xs" hence "alw \<phi> xs"
hoelzl@58627
   140
   apply coinduct by (auto elim: UNTIL.cases)
hoelzl@58627
   141
  }
hoelzl@58627
   142
  moreover
hoelzl@58627
   143
  {fix xs assume "alw \<phi> xs" hence "(\<phi> until false) xs"
hoelzl@58627
   144
   apply coinduct by (auto elim: alw.cases)
hoelzl@58627
   145
  }
hoelzl@58627
   146
  ultimately show ?thesis by blast
hoelzl@58627
   147
qed
hoelzl@58627
   148
hoelzl@58627
   149
lemma ev_nxt: "ev \<phi> = (\<phi> or nxt (ev \<phi>))"
hoelzl@58627
   150
apply(rule ext) by (metis ev.simps nxt.simps)
hoelzl@58627
   151
hoelzl@58627
   152
lemma alw_nxt: "alw \<phi> = (\<phi> aand nxt (alw \<phi>))"
hoelzl@58627
   153
apply(rule ext) by (metis alw.simps nxt.simps)
hoelzl@58627
   154
hoelzl@58627
   155
lemma ev_ev[simp]: "ev (ev \<phi>) = ev \<phi>"
hoelzl@58627
   156
proof-
hoelzl@58627
   157
  {fix xs
hoelzl@58627
   158
   assume "ev (ev \<phi>) xs" hence "ev \<phi> xs"
hoelzl@58627
   159
   by induct (auto intro: ev.intros)
hoelzl@58627
   160
  }
hoelzl@58627
   161
  thus ?thesis by (auto intro: ev.intros)
hoelzl@58627
   162
qed
hoelzl@58627
   163
hoelzl@58627
   164
lemma alw_alw[simp]: "alw (alw \<phi>) = alw \<phi>"
hoelzl@58627
   165
proof-
hoelzl@58627
   166
  {fix xs
hoelzl@58627
   167
   assume "alw \<phi> xs" hence "alw (alw \<phi>) xs"
hoelzl@58627
   168
   by coinduct (auto elim: alw.cases)
hoelzl@58627
   169
  }
hoelzl@58627
   170
  thus ?thesis by (auto elim: alw.cases)
hoelzl@58627
   171
qed
hoelzl@58627
   172
hoelzl@58627
   173
lemma ev_shift:
hoelzl@58627
   174
assumes "ev \<phi> xs"
hoelzl@58627
   175
shows "ev \<phi> (xl @- xs)"
hoelzl@58627
   176
using assms by (induct xl) (auto intro: ev.intros)
hoelzl@58627
   177
hoelzl@58627
   178
lemma ev_imp_shift:
hoelzl@58627
   179
assumes "ev \<phi> xs"  shows "\<exists> xl xs2. xs = xl @- xs2 \<and> \<phi> xs2"
hoelzl@58627
   180
using assms by induct (metis shift.simps(1), metis shift.simps(2) stream.collapse)+
hoelzl@58627
   181
hoelzl@58627
   182
lemma alw_ev_shift: "alw \<phi> xs1 \<Longrightarrow> ev (alw \<phi>) (xl @- xs1)"
hoelzl@58627
   183
by (auto intro: ev_shift ev.intros)
hoelzl@58627
   184
hoelzl@58627
   185
lemma alw_shift:
hoelzl@58627
   186
assumes "alw \<phi> (xl @- xs)"
hoelzl@58627
   187
shows "alw \<phi> xs"
hoelzl@58627
   188
using assms by (induct xl) (auto elim: alw.cases)
hoelzl@58627
   189
hoelzl@58627
   190
lemma ev_ex_nxt:
hoelzl@58627
   191
assumes "ev \<phi> xs"
hoelzl@58627
   192
shows "\<exists> n. (nxt ^^ n) \<phi> xs"
hoelzl@58627
   193
using assms proof induct
hoelzl@58627
   194
  case (base xs) thus ?case by (intro exI[of _ 0]) auto
hoelzl@58627
   195
next
hoelzl@58627
   196
  case (step xs)
hoelzl@58627
   197
  then obtain n where "(nxt ^^ n) \<phi> (stl xs)" by blast
hoelzl@58627
   198
  thus ?case by (intro exI[of _ "Suc n"]) (metis funpow.simps(2) nxt.simps o_def)
hoelzl@58627
   199
qed
hoelzl@58627
   200
hoelzl@58627
   201
lemma alw_sdrop:
hoelzl@58627
   202
assumes "alw \<phi> xs"  shows "alw \<phi> (sdrop n xs)"
hoelzl@58627
   203
by (metis alw_shift assms stake_sdrop)
hoelzl@58627
   204
hoelzl@58627
   205
lemma nxt_sdrop: "(nxt ^^ n) \<phi> xs \<longleftrightarrow> \<phi> (sdrop n xs)"
hoelzl@58627
   206
by (induct n arbitrary: xs) auto
hoelzl@58627
   207
hoelzl@58627
   208
definition "wait \<phi> xs \<equiv> LEAST n. (nxt ^^ n) \<phi> xs"
hoelzl@58627
   209
hoelzl@58627
   210
lemma nxt_wait:
hoelzl@58627
   211
assumes "ev \<phi> xs"  shows "(nxt ^^ (wait \<phi> xs)) \<phi> xs"
hoelzl@58627
   212
unfolding wait_def using ev_ex_nxt[OF assms] by(rule LeastI_ex)
hoelzl@58627
   213
hoelzl@58627
   214
lemma nxt_wait_least:
hoelzl@58627
   215
assumes ev: "ev \<phi> xs" and nxt: "(nxt ^^ n) \<phi> xs"  shows "wait \<phi> xs \<le> n"
hoelzl@58627
   216
unfolding wait_def using ev_ex_nxt[OF ev] by (metis Least_le nxt)
hoelzl@58627
   217
hoelzl@58627
   218
lemma sdrop_wait:
hoelzl@58627
   219
assumes "ev \<phi> xs"  shows "\<phi> (sdrop (wait \<phi> xs) xs)"
hoelzl@58627
   220
using nxt_wait[OF assms] unfolding nxt_sdrop .
hoelzl@58627
   221
hoelzl@58627
   222
lemma sdrop_wait_least:
hoelzl@58627
   223
assumes ev: "ev \<phi> xs" and nxt: "\<phi> (sdrop n xs)"  shows "wait \<phi> xs \<le> n"
hoelzl@58627
   224
using assms nxt_wait_least unfolding nxt_sdrop by auto
hoelzl@58627
   225
hoelzl@58627
   226
lemma nxt_ev: "(nxt ^^ n) \<phi> xs \<Longrightarrow> ev \<phi> xs"
hoelzl@58627
   227
by (induct n arbitrary: xs) (auto intro: ev.intros)
hoelzl@58627
   228
hoelzl@58627
   229
lemma not_ev: "not (ev \<phi>) = alw (not \<phi>)"
hoelzl@58627
   230
proof(rule ext, safe)
hoelzl@58627
   231
  fix xs assume "not (ev \<phi>) xs" thus "alw (not \<phi>) xs"
hoelzl@58627
   232
  by (coinduct) (auto intro: ev.intros)
hoelzl@58627
   233
next
hoelzl@58627
   234
  fix xs assume "ev \<phi> xs" and "alw (not \<phi>) xs" thus False
hoelzl@58627
   235
  by (induct) (auto elim: alw.cases)
hoelzl@58627
   236
qed
hoelzl@58627
   237
hoelzl@58627
   238
lemma not_alw: "not (alw \<phi>) = ev (not \<phi>)"
hoelzl@58627
   239
proof-
hoelzl@58627
   240
  have "not (alw \<phi>) = not (alw (not (not \<phi>)))" by simp
hoelzl@58627
   241
  also have "... = ev (not \<phi>)" unfolding not_ev[symmetric] by simp
hoelzl@58627
   242
  finally show ?thesis .
hoelzl@58627
   243
qed
hoelzl@58627
   244
hoelzl@58627
   245
lemma not_ev_not[simp]: "not (ev (not \<phi>)) = alw \<phi>"
hoelzl@58627
   246
unfolding not_ev by simp
hoelzl@58627
   247
hoelzl@58627
   248
lemma not_alw_not[simp]: "not (alw (not \<phi>)) = ev \<phi>"
hoelzl@58627
   249
unfolding not_alw by simp
hoelzl@58627
   250
hoelzl@58627
   251
lemma alw_ev_sdrop:
hoelzl@58627
   252
assumes "alw (ev \<phi>) (sdrop m xs)"
hoelzl@58627
   253
shows "alw (ev \<phi>) xs"
hoelzl@58627
   254
using assms
hoelzl@58627
   255
by coinduct (metis alw_nxt ev_shift funpow_swap1 nxt.simps nxt_sdrop stake_sdrop)
hoelzl@58627
   256
hoelzl@58627
   257
lemma ev_alw_imp_alw_ev:
hoelzl@58627
   258
assumes "ev (alw \<phi>) xs"  shows "alw (ev \<phi>) xs"
hoelzl@58627
   259
using assms apply induct
hoelzl@58627
   260
  apply (metis (full_types) alw_mono ev.base)
hoelzl@58627
   261
  by (metis alw alw_nxt ev.step)
hoelzl@58627
   262
hoelzl@58627
   263
lemma alw_aand: "alw (\<phi> aand \<psi>) = alw \<phi> aand alw \<psi>"
hoelzl@58627
   264
proof-
hoelzl@58627
   265
  {fix xs assume "alw (\<phi> aand \<psi>) xs" hence "(alw \<phi> aand alw \<psi>) xs"
hoelzl@58627
   266
   by (auto elim: alw_mono)
hoelzl@58627
   267
  }
hoelzl@58627
   268
  moreover
hoelzl@58627
   269
  {fix xs assume "(alw \<phi> aand alw \<psi>) xs" hence "alw (\<phi> aand \<psi>) xs"
hoelzl@58627
   270
   by coinduct (auto elim: alw.cases)
hoelzl@58627
   271
  }
hoelzl@58627
   272
  ultimately show ?thesis by blast
hoelzl@58627
   273
qed
hoelzl@58627
   274
hoelzl@58627
   275
lemma ev_or: "ev (\<phi> or \<psi>) = ev \<phi> or ev \<psi>"
hoelzl@58627
   276
proof-
hoelzl@58627
   277
  {fix xs assume "(ev \<phi> or ev \<psi>) xs" hence "ev (\<phi> or \<psi>) xs"
hoelzl@58627
   278
   by (auto elim: ev_mono)
hoelzl@58627
   279
  }
hoelzl@58627
   280
  moreover
hoelzl@58627
   281
  {fix xs assume "ev (\<phi> or \<psi>) xs" hence "(ev \<phi> or ev \<psi>) xs"
hoelzl@58627
   282
   by induct (auto intro: ev.intros)
hoelzl@58627
   283
  }
hoelzl@58627
   284
  ultimately show ?thesis by blast
hoelzl@58627
   285
qed
hoelzl@58627
   286
hoelzl@58627
   287
lemma ev_alw_aand:
hoelzl@58627
   288
assumes \<phi>: "ev (alw \<phi>) xs" and \<psi>: "ev (alw \<psi>) xs"
hoelzl@58627
   289
shows "ev (alw (\<phi> aand \<psi>)) xs"
hoelzl@58627
   290
proof-
hoelzl@58627
   291
  obtain xl xs1 where xs1: "xs = xl @- xs1" and \<phi>\<phi>: "alw \<phi> xs1"
hoelzl@58627
   292
  using \<phi> by (metis ev_imp_shift)
hoelzl@58627
   293
  moreover obtain yl ys1 where xs2: "xs = yl @- ys1" and \<psi>\<psi>: "alw \<psi> ys1"
hoelzl@58627
   294
  using \<psi> by (metis ev_imp_shift)
hoelzl@58627
   295
  ultimately have 0: "xl @- xs1 = yl @- ys1" by auto
hoelzl@58627
   296
  hence "prefixeq xl yl \<or> prefixeq yl xl" using shift_prefix_cases by auto
hoelzl@58627
   297
  thus ?thesis proof
hoelzl@58627
   298
    assume "prefixeq xl yl"
hoelzl@58627
   299
    then obtain yl1 where yl: "yl = xl @ yl1" by (elim prefixeqE)
hoelzl@58627
   300
    have xs1': "xs1 = yl1 @- ys1" using 0 unfolding yl by simp
hoelzl@58627
   301
    have "alw \<phi> ys1" using \<phi>\<phi> unfolding xs1' by (metis alw_shift)
hoelzl@58627
   302
    hence "alw (\<phi> aand \<psi>) ys1" using \<psi>\<psi> unfolding alw_aand by auto
hoelzl@58627
   303
    thus ?thesis unfolding xs2 by (auto intro: alw_ev_shift)
hoelzl@58627
   304
  next
hoelzl@58627
   305
    assume "prefixeq yl xl"
hoelzl@58627
   306
    then obtain xl1 where xl: "xl = yl @ xl1" by (elim prefixeqE)
hoelzl@58627
   307
    have ys1': "ys1 = xl1 @- xs1" using 0 unfolding xl by simp
hoelzl@58627
   308
    have "alw \<psi> xs1" using \<psi>\<psi> unfolding ys1' by (metis alw_shift)
hoelzl@58627
   309
    hence "alw (\<phi> aand \<psi>) xs1" using \<phi>\<phi> unfolding alw_aand by auto
hoelzl@58627
   310
    thus ?thesis unfolding xs1 by (auto intro: alw_ev_shift)
hoelzl@58627
   311
  qed
hoelzl@58627
   312
qed
hoelzl@58627
   313
hoelzl@58627
   314
lemma ev_alw_alw_impl:
hoelzl@58627
   315
assumes "ev (alw \<phi>) xs" and "alw (alw \<phi> impl ev \<psi>) xs"
hoelzl@58627
   316
shows "ev \<psi> xs"
hoelzl@58627
   317
using assms by induct (auto intro: ev.intros elim: alw.cases)
hoelzl@58627
   318
hoelzl@58627
   319
lemma ev_alw_stl[simp]: "ev (alw \<phi>) (stl x) \<longleftrightarrow> ev (alw \<phi>) x"
hoelzl@58627
   320
by (metis (full_types) alw_nxt ev_nxt nxt.simps)
hoelzl@58627
   321
hoelzl@58627
   322
lemma alw_alw_impl_ev:
hoelzl@58627
   323
"alw (alw \<phi> impl ev \<psi>) = (ev (alw \<phi>) impl alw (ev \<psi>))" (is "?A = ?B")
hoelzl@58627
   324
proof-
hoelzl@58627
   325
  {fix xs assume "?A xs \<and> ev (alw \<phi>) xs" hence "alw (ev \<psi>) xs"
hoelzl@58627
   326
   apply coinduct using ev_nxt by (auto elim: ev_alw_alw_impl alw.cases intro: ev.intros)
hoelzl@58627
   327
  }
hoelzl@58627
   328
  moreover
hoelzl@58627
   329
  {fix xs assume "?B xs" hence "?A xs"
hoelzl@58627
   330
   apply coinduct by (auto elim: alw.cases intro: ev.intros)
hoelzl@58627
   331
  }
hoelzl@58627
   332
  ultimately show ?thesis by blast
hoelzl@58627
   333
qed
hoelzl@58627
   334
hoelzl@58627
   335
lemma ev_alw_impl:
hoelzl@58627
   336
assumes "ev \<phi> xs" and "alw (\<phi> impl \<psi>) xs"  shows "ev \<psi> xs"
hoelzl@58627
   337
using assms by induct (auto intro: ev.intros elim: alw.cases)
hoelzl@58627
   338
hoelzl@58627
   339
lemma ev_alw_impl_ev:
hoelzl@58627
   340
assumes "ev \<phi> xs" and "alw (\<phi> impl ev \<psi>) xs"  shows "ev \<psi> xs"
hoelzl@58627
   341
using ev_alw_impl[OF assms] by simp
hoelzl@58627
   342
hoelzl@58627
   343
lemma alw_mp:
hoelzl@58627
   344
assumes "alw \<phi> xs" and "alw (\<phi> impl \<psi>) xs"
hoelzl@58627
   345
shows "alw \<psi> xs"
hoelzl@58627
   346
proof-
hoelzl@58627
   347
  {assume "alw \<phi> xs \<and> alw (\<phi> impl \<psi>) xs" hence ?thesis
hoelzl@58627
   348
   apply coinduct by (auto elim: alw.cases)
hoelzl@58627
   349
  }
hoelzl@58627
   350
  thus ?thesis using assms by auto
hoelzl@58627
   351
qed
hoelzl@58627
   352
hoelzl@58627
   353
lemma all_imp_alw:
hoelzl@58627
   354
assumes "\<And> xs. \<phi> xs"  shows "alw \<phi> xs"
hoelzl@58627
   355
proof-
hoelzl@58627
   356
  {assume "\<forall> xs. \<phi> xs"
hoelzl@58627
   357
   hence ?thesis by coinduct auto
hoelzl@58627
   358
  }
hoelzl@58627
   359
  thus ?thesis using assms by auto
hoelzl@58627
   360
qed
hoelzl@58627
   361
hoelzl@58627
   362
lemma alw_impl_ev_alw:
hoelzl@58627
   363
assumes "alw (\<phi> impl ev \<psi>) xs"
hoelzl@58627
   364
shows "alw (ev \<phi> impl ev \<psi>) xs"
hoelzl@58627
   365
using assms by coinduct (auto elim: alw.cases dest: ev_alw_impl intro: ev.intros)
hoelzl@58627
   366
hoelzl@58627
   367
lemma ev_holds_sset:
hoelzl@58627
   368
"ev (holds P) xs \<longleftrightarrow> (\<exists> x \<in> sset xs. P x)" (is "?L \<longleftrightarrow> ?R")
hoelzl@58627
   369
proof safe
hoelzl@58627
   370
  assume ?L thus ?R by induct (metis holds.simps stream.set_sel(1), metis stl_sset)
hoelzl@58627
   371
next
hoelzl@58627
   372
  fix x assume "x \<in> sset xs" "P x"
hoelzl@58627
   373
  thus ?L by (induct rule: sset_induct) (simp_all add: ev.base ev.step)
hoelzl@58627
   374
qed
hoelzl@58627
   375
hoelzl@58627
   376
(* LTL as a program logic: *)
hoelzl@58627
   377
lemma alw_invar:
hoelzl@58627
   378
assumes "\<phi> xs" and "alw (\<phi> impl nxt \<phi>) xs"
hoelzl@58627
   379
shows "alw \<phi> xs"
hoelzl@58627
   380
proof-
hoelzl@58627
   381
  {assume "\<phi> xs \<and> alw (\<phi> impl nxt \<phi>) xs" hence ?thesis
hoelzl@58627
   382
   apply coinduct by(auto elim: alw.cases)
hoelzl@58627
   383
  }
hoelzl@58627
   384
  thus ?thesis using assms by auto
hoelzl@58627
   385
qed
hoelzl@58627
   386
hoelzl@58627
   387
lemma variance:
hoelzl@58627
   388
assumes 1: "\<phi> xs" and 2: "alw (\<phi> impl (\<psi> or nxt \<phi>)) xs"
hoelzl@58627
   389
shows "(alw \<phi> or ev \<psi>) xs"
hoelzl@58627
   390
proof-
hoelzl@58627
   391
  {assume "\<not> ev \<psi> xs" hence "alw (not \<psi>) xs" unfolding not_ev[symmetric] .
hoelzl@58627
   392
   moreover have "alw (not \<psi> impl (\<phi> impl nxt \<phi>)) xs"
hoelzl@58627
   393
   using 2 by coinduct (auto elim: alw.cases)
hoelzl@58627
   394
   ultimately have "alw (\<phi> impl nxt \<phi>) xs" by(auto dest: alw_mp)
hoelzl@58627
   395
   with 1 have "alw \<phi> xs" by(rule alw_invar)
hoelzl@58627
   396
  }
hoelzl@58627
   397
  thus ?thesis by blast
hoelzl@58627
   398
qed
hoelzl@58627
   399
hoelzl@58627
   400
lemma ev_alw_imp_nxt:
hoelzl@58627
   401
assumes e: "ev \<phi> xs" and a: "alw (\<phi> impl (nxt \<phi>)) xs"
hoelzl@58627
   402
shows "ev (alw \<phi>) xs"
hoelzl@58627
   403
proof-
hoelzl@58627
   404
  obtain xl xs1 where xs: "xs = xl @- xs1" and \<phi>: "\<phi> xs1"
hoelzl@58627
   405
  using e by (metis ev_imp_shift)
hoelzl@58627
   406
  have "\<phi> xs1 \<and> alw (\<phi> impl (nxt \<phi>)) xs1" using a \<phi> unfolding xs by (metis alw_shift)
hoelzl@58627
   407
  hence "alw \<phi> xs1" by(coinduct xs1 rule: alw.coinduct) (auto elim: alw.cases)
hoelzl@58627
   408
  thus ?thesis unfolding xs by (auto intro: alw_ev_shift)
hoelzl@58627
   409
qed
hoelzl@58627
   410
hoelzl@58627
   411
hoelzl@59000
   412
inductive ev_at :: "('a stream \<Rightarrow> bool) \<Rightarrow> nat \<Rightarrow> 'a stream \<Rightarrow> bool" for P :: "'a stream \<Rightarrow> bool" where
hoelzl@59000
   413
  base: "P \<omega> \<Longrightarrow> ev_at P 0 \<omega>"
hoelzl@59000
   414
| step:"\<not> P \<omega> \<Longrightarrow> ev_at P n (stl \<omega>) \<Longrightarrow> ev_at P (Suc n) \<omega>"
hoelzl@59000
   415
hoelzl@59000
   416
inductive_simps ev_at_0[simp]: "ev_at P 0 \<omega>"
hoelzl@59000
   417
inductive_simps ev_at_Suc[simp]: "ev_at P (Suc n) \<omega>"
hoelzl@59000
   418
hoelzl@59000
   419
lemma ev_at_imp_snth: "ev_at P n \<omega> \<Longrightarrow> P (sdrop n \<omega>)"
hoelzl@59000
   420
  by (induction n arbitrary: \<omega>) auto
hoelzl@59000
   421
hoelzl@59000
   422
lemma ev_at_HLD_imp_snth: "ev_at (HLD X) n \<omega> \<Longrightarrow> \<omega> !! n \<in> X"
hoelzl@59000
   423
  by (auto dest!: ev_at_imp_snth simp: HLD_iff)
hoelzl@59000
   424
hoelzl@59000
   425
lemma ev_at_HLD_single_imp_snth: "ev_at (HLD {x}) n \<omega> \<Longrightarrow> \<omega> !! n = x"
hoelzl@59000
   426
  by (drule ev_at_HLD_imp_snth) simp
hoelzl@59000
   427
hoelzl@59000
   428
lemma ev_at_unique: "ev_at P n \<omega> \<Longrightarrow> ev_at P m \<omega> \<Longrightarrow> n = m"
hoelzl@59000
   429
proof (induction arbitrary: m rule: ev_at.induct)
hoelzl@59000
   430
  case (base \<omega>) then show ?case
hoelzl@59000
   431
    by (simp add: ev_at.simps[of _ _ \<omega>])
hoelzl@59000
   432
next
hoelzl@59000
   433
  case (step \<omega> n) from step.prems step.hyps step.IH[of "m - 1"] show ?case
hoelzl@59000
   434
    by (auto simp add: ev_at.simps[of _ _ \<omega>])
hoelzl@59000
   435
qed
hoelzl@59000
   436
hoelzl@59000
   437
lemma ev_iff_ev_at: "ev P \<omega> \<longleftrightarrow> (\<exists>n. ev_at P n \<omega>)"
hoelzl@59000
   438
proof
hoelzl@59000
   439
  assume "ev P \<omega>" then show "\<exists>n. ev_at P n \<omega>"
hoelzl@59000
   440
    by (induction rule: ev_induct_strong) (auto intro: ev_at.intros)
hoelzl@59000
   441
next
hoelzl@59000
   442
  assume "\<exists>n. ev_at P n \<omega>"
hoelzl@59000
   443
  then obtain n where "ev_at P n \<omega>"
hoelzl@59000
   444
    by auto
hoelzl@59000
   445
  then show "ev P \<omega>"
hoelzl@59000
   446
    by induction auto
hoelzl@59000
   447
qed
hoelzl@59000
   448
hoelzl@59000
   449
lemma ev_at_shift: "ev_at (HLD X) i (stake (Suc i) \<omega> @- \<omega>' :: 's stream) \<longleftrightarrow> ev_at (HLD X) i \<omega>"
hoelzl@59000
   450
  by (induction i arbitrary: \<omega>) (auto simp: HLD_iff)
hoelzl@59000
   451
hoelzl@59000
   452
lemma ev_iff_ev_at_unqiue: "ev P \<omega> \<longleftrightarrow> (\<exists>!n. ev_at P n \<omega>)"
hoelzl@59000
   453
  by (auto intro: ev_at_unique simp: ev_iff_ev_at)
hoelzl@59000
   454
hoelzl@59000
   455
lemma alw_HLD_iff_streams: "alw (HLD X) \<omega> \<longleftrightarrow> \<omega> \<in> streams X"
hoelzl@59000
   456
proof
hoelzl@59000
   457
  assume "alw (HLD X) \<omega>" then show "\<omega> \<in> streams X"
hoelzl@59000
   458
  proof (coinduction arbitrary: \<omega>)
hoelzl@59000
   459
    case (streams \<omega>) then show ?case by (cases \<omega>) auto
hoelzl@59000
   460
  qed
hoelzl@59000
   461
next
hoelzl@59000
   462
  assume "\<omega> \<in> streams X" then show "alw (HLD X) \<omega>"
hoelzl@59000
   463
  proof (coinduction arbitrary: \<omega>)
hoelzl@59000
   464
    case (alw \<omega>) then show ?case by (cases \<omega>) auto
hoelzl@59000
   465
  qed
hoelzl@59000
   466
qed
hoelzl@59000
   467
hoelzl@59000
   468
lemma not_HLD: "not (HLD X) = HLD (- X)"
hoelzl@59000
   469
  by (auto simp: HLD_iff)
hoelzl@59000
   470
hoelzl@59000
   471
lemma not_alw_iff: "\<not> (alw P \<omega>) \<longleftrightarrow> ev (not P) \<omega>"
hoelzl@59000
   472
  using not_alw[of P] by (simp add: fun_eq_iff)
hoelzl@59000
   473
hoelzl@59000
   474
lemma not_ev_iff: "\<not> (ev P \<omega>) \<longleftrightarrow> alw (not P) \<omega>"
hoelzl@59000
   475
  using not_alw_iff[of "not P" \<omega>, symmetric]  by simp
hoelzl@59000
   476
hoelzl@59000
   477
lemma ev_Stream: "ev P (x ## s) \<longleftrightarrow> P (x ## s) \<or> ev P s"
hoelzl@59000
   478
  by (auto elim: ev.cases)
hoelzl@59000
   479
hoelzl@59000
   480
lemma alw_ev_imp_ev_alw:
hoelzl@59000
   481
  assumes "alw (ev P) \<omega>" shows "ev (P aand alw (ev P)) \<omega>"
hoelzl@59000
   482
proof -
hoelzl@59000
   483
  have "ev P \<omega>" using assms by auto
hoelzl@59000
   484
  from this assms show ?thesis
hoelzl@59000
   485
    by induct auto
hoelzl@59000
   486
qed
hoelzl@59000
   487
hoelzl@59000
   488
lemma ev_False: "ev (\<lambda>x. False) \<omega> \<longleftrightarrow> False"
hoelzl@59000
   489
proof
hoelzl@59000
   490
  assume "ev (\<lambda>x. False) \<omega>" then show False
hoelzl@59000
   491
    by induct auto
hoelzl@59000
   492
qed auto
hoelzl@59000
   493
hoelzl@59000
   494
lemma alw_False: "alw (\<lambda>x. False) \<omega> \<longleftrightarrow> False"
hoelzl@59000
   495
  by auto
hoelzl@59000
   496
hoelzl@59000
   497
lemma ev_iff_sdrop: "ev P \<omega> \<longleftrightarrow> (\<exists>m. P (sdrop m \<omega>))"
hoelzl@59000
   498
proof safe
hoelzl@59000
   499
  assume "ev P \<omega>" then show "\<exists>m. P (sdrop m \<omega>)"
hoelzl@59000
   500
    by (induct rule: ev_induct_strong) (auto intro: exI[of _ 0] exI[of _ "Suc n" for n])
hoelzl@59000
   501
next
hoelzl@59000
   502
  fix m assume "P (sdrop m \<omega>)" then show "ev P \<omega>"
hoelzl@59000
   503
    by (induct m arbitrary: \<omega>) auto
hoelzl@59000
   504
qed
hoelzl@59000
   505
hoelzl@59000
   506
lemma alw_iff_sdrop: "alw P \<omega> \<longleftrightarrow> (\<forall>m. P (sdrop m \<omega>))"
hoelzl@59000
   507
proof safe
hoelzl@59000
   508
  fix m assume "alw P \<omega>" then show "P (sdrop m \<omega>)"
hoelzl@59000
   509
    by (induct m arbitrary: \<omega>) auto
hoelzl@59000
   510
next
hoelzl@59000
   511
  assume "\<forall>m. P (sdrop m \<omega>)" then show "alw P \<omega>"
hoelzl@59000
   512
    by (coinduction arbitrary: \<omega>) (auto elim: allE[of _ 0] allE[of _ "Suc n" for n])
hoelzl@59000
   513
qed
hoelzl@59000
   514
hoelzl@59000
   515
lemma infinite_iff_alw_ev: "infinite {m. P (sdrop m \<omega>)} \<longleftrightarrow> alw (ev P) \<omega>"
hoelzl@59000
   516
  unfolding infinite_nat_iff_unbounded_le alw_iff_sdrop ev_iff_sdrop
hoelzl@59000
   517
  by simp (metis le_Suc_ex le_add1)
hoelzl@59000
   518
hoelzl@59000
   519
lemma alw_inv:
hoelzl@59000
   520
  assumes stl: "\<And>s. f (stl s) = stl (f s)"
hoelzl@59000
   521
  shows "alw P (f s) \<longleftrightarrow> alw (\<lambda>x. P (f x)) s"
hoelzl@59000
   522
proof
hoelzl@59000
   523
  assume "alw P (f s)" then show "alw (\<lambda>x. P (f x)) s"
hoelzl@59000
   524
    by (coinduction arbitrary: s rule: alw_coinduct)
hoelzl@59000
   525
       (auto simp: stl)
hoelzl@59000
   526
next
hoelzl@59000
   527
  assume "alw (\<lambda>x. P (f x)) s" then show "alw P (f s)"
hoelzl@59000
   528
    by (coinduction arbitrary: s rule: alw_coinduct) (auto simp: stl[symmetric])
hoelzl@59000
   529
qed
hoelzl@59000
   530
hoelzl@59000
   531
lemma ev_inv:
hoelzl@59000
   532
  assumes stl: "\<And>s. f (stl s) = stl (f s)"
hoelzl@59000
   533
  shows "ev P (f s) \<longleftrightarrow> ev (\<lambda>x. P (f x)) s"
hoelzl@59000
   534
proof
hoelzl@59000
   535
  assume "ev P (f s)" then show "ev (\<lambda>x. P (f x)) s"
hoelzl@59000
   536
    by (induction "f s" arbitrary: s) (auto simp: stl)
hoelzl@59000
   537
next
hoelzl@59000
   538
  assume "ev (\<lambda>x. P (f x)) s" then show "ev P (f s)"
hoelzl@59000
   539
    by induction (auto simp: stl[symmetric])
hoelzl@59000
   540
qed
hoelzl@59000
   541
hoelzl@59000
   542
lemma alw_smap: "alw P (smap f s) \<longleftrightarrow> alw (\<lambda>x. P (smap f x)) s"
hoelzl@59000
   543
  by (rule alw_inv) simp
hoelzl@59000
   544
hoelzl@59000
   545
lemma ev_smap: "ev P (smap f s) \<longleftrightarrow> ev (\<lambda>x. P (smap f x)) s"
hoelzl@59000
   546
  by (rule ev_inv) simp
hoelzl@59000
   547
hoelzl@59000
   548
lemma alw_cong:
hoelzl@59000
   549
  assumes P: "alw P \<omega>" and eq: "\<And>\<omega>. P \<omega> \<Longrightarrow> Q1 \<omega> \<longleftrightarrow> Q2 \<omega>"
hoelzl@59000
   550
  shows "alw Q1 \<omega> \<longleftrightarrow> alw Q2 \<omega>"
hoelzl@59000
   551
proof -
hoelzl@59000
   552
  from eq have "(alw P aand Q1) = (alw P aand Q2)" by auto
hoelzl@59000
   553
  then have "alw (alw P aand Q1) \<omega> = alw (alw P aand Q2) \<omega>" by auto
hoelzl@59000
   554
  with P show "alw Q1 \<omega> \<longleftrightarrow> alw Q2 \<omega>"
hoelzl@59000
   555
    by (simp add: alw_aand)
hoelzl@59000
   556
qed
hoelzl@59000
   557
hoelzl@59000
   558
lemma ev_cong:
hoelzl@59000
   559
  assumes P: "alw P \<omega>" and eq: "\<And>\<omega>. P \<omega> \<Longrightarrow> Q1 \<omega> \<longleftrightarrow> Q2 \<omega>"
hoelzl@59000
   560
  shows "ev Q1 \<omega> \<longleftrightarrow> ev Q2 \<omega>"
hoelzl@59000
   561
proof -
hoelzl@59000
   562
  from P have "alw (\<lambda>xs. Q1 xs \<longrightarrow> Q2 xs) \<omega>" by (rule alw_mono) (simp add: eq)
hoelzl@59000
   563
  moreover from P have "alw (\<lambda>xs. Q2 xs \<longrightarrow> Q1 xs) \<omega>" by (rule alw_mono) (simp add: eq)
hoelzl@59000
   564
  moreover note ev_alw_impl[of Q1 \<omega> Q2] ev_alw_impl[of Q2 \<omega> Q1]
hoelzl@59000
   565
  ultimately show "ev Q1 \<omega> \<longleftrightarrow> ev Q2 \<omega>"
hoelzl@59000
   566
    by auto
hoelzl@59000
   567
qed
hoelzl@59000
   568
hoelzl@59000
   569
lemma alwD: "alw P x \<Longrightarrow> P x"
hoelzl@59000
   570
  by auto
hoelzl@59000
   571
hoelzl@59000
   572
lemma alw_alwD: "alw P \<omega> \<Longrightarrow> alw (alw P) \<omega>"
hoelzl@59000
   573
  by simp
hoelzl@59000
   574
hoelzl@59000
   575
lemma alw_ev_stl: "alw (ev P) (stl \<omega>) \<longleftrightarrow> alw (ev P) \<omega>"
hoelzl@59000
   576
  by (auto intro: alw.intros)
hoelzl@59000
   577
hoelzl@59000
   578
lemma holds_Stream: "holds P (x ## s) \<longleftrightarrow> P x"
hoelzl@59000
   579
  by simp
hoelzl@59000
   580
hoelzl@59000
   581
lemma holds_eq1[simp]: "holds (op = x) = HLD {x}"
hoelzl@59000
   582
  by rule (auto simp: HLD_iff)
hoelzl@59000
   583
hoelzl@59000
   584
lemma holds_eq2[simp]: "holds (\<lambda>y. y = x) = HLD {x}"
hoelzl@59000
   585
  by rule (auto simp: HLD_iff)
hoelzl@59000
   586
hoelzl@59000
   587
lemma not_holds_eq[simp]: "holds (- op = x) = not (HLD {x})"
hoelzl@59000
   588
  by rule (auto simp: HLD_iff)
hoelzl@59000
   589
hoelzl@59000
   590
text {* Strong until *}
hoelzl@59000
   591
hoelzl@59000
   592
inductive suntil (infix "suntil" 60) for \<phi> \<psi> where
hoelzl@59000
   593
  base: "\<psi> \<omega> \<Longrightarrow> (\<phi> suntil \<psi>) \<omega>"
hoelzl@59000
   594
| step: "\<phi> \<omega> \<Longrightarrow> (\<phi> suntil \<psi>) (stl \<omega>) \<Longrightarrow> (\<phi> suntil \<psi>) \<omega>"
hoelzl@59000
   595
hoelzl@59000
   596
inductive_simps suntil_Stream: "(\<phi> suntil \<psi>) (x ## s)"
hoelzl@59000
   597
hoelzl@59000
   598
lemma suntil_induct_strong[consumes 1, case_names base step]:
hoelzl@59000
   599
  "(\<phi> suntil \<psi>) x \<Longrightarrow>
hoelzl@59000
   600
    (\<And>\<omega>. \<psi> \<omega> \<Longrightarrow> P \<omega>) \<Longrightarrow>
hoelzl@59000
   601
    (\<And>\<omega>. \<phi> \<omega> \<Longrightarrow> \<not> \<psi> \<omega> \<Longrightarrow> (\<phi> suntil \<psi>) (stl \<omega>) \<Longrightarrow> P (stl \<omega>) \<Longrightarrow> P \<omega>) \<Longrightarrow> P x"
hoelzl@59000
   602
  using suntil.induct[of \<phi> \<psi> x P] by blast
hoelzl@59000
   603
hoelzl@59000
   604
lemma ev_suntil: "(\<phi> suntil \<psi>) \<omega> \<Longrightarrow> ev \<psi> \<omega>"
hoelzl@59000
   605
  by (induct rule: suntil.induct) (auto intro: ev.intros)
hoelzl@59000
   606
hoelzl@59000
   607
lemma suntil_inv:
hoelzl@59000
   608
  assumes stl: "\<And>s. f (stl s) = stl (f s)"
hoelzl@59000
   609
  shows "(P suntil Q) (f s) \<longleftrightarrow> ((\<lambda>x. P (f x)) suntil (\<lambda>x. Q (f x))) s"
hoelzl@59000
   610
proof
hoelzl@59000
   611
  assume "(P suntil Q) (f s)" then show "((\<lambda>x. P (f x)) suntil (\<lambda>x. Q (f x))) s"
hoelzl@59000
   612
    by (induction "f s" arbitrary: s) (auto simp: stl intro: suntil.intros)
hoelzl@59000
   613
next
hoelzl@59000
   614
  assume "((\<lambda>x. P (f x)) suntil (\<lambda>x. Q (f x))) s" then show "(P suntil Q) (f s)"
hoelzl@59000
   615
    by induction (auto simp: stl[symmetric] intro: suntil.intros)
hoelzl@59000
   616
qed
hoelzl@59000
   617
hoelzl@59000
   618
lemma suntil_smap: "(P suntil Q) (smap f s) \<longleftrightarrow> ((\<lambda>x. P (smap f x)) suntil (\<lambda>x. Q (smap f x))) s"
hoelzl@59000
   619
  by (rule suntil_inv) simp
hoelzl@59000
   620
hoelzl@59000
   621
lemma hld_smap: "HLD x (smap f s) = holds (\<lambda>y. f y \<in> x) s"
hoelzl@59000
   622
  by (simp add: HLD_def)
hoelzl@59000
   623
hoelzl@59000
   624
lemma suntil_mono:
hoelzl@59000
   625
  assumes eq: "\<And>\<omega>. P \<omega> \<Longrightarrow> Q1 \<omega> \<Longrightarrow> Q2 \<omega>" "\<And>\<omega>. P \<omega> \<Longrightarrow> R1 \<omega> \<Longrightarrow> R2 \<omega>"
hoelzl@59000
   626
  assumes *: "(Q1 suntil R1) \<omega>" "alw P \<omega>" shows "(Q2 suntil R2) \<omega>"
hoelzl@59000
   627
  using * by induct (auto intro: eq suntil.intros)
hoelzl@59000
   628
hoelzl@59000
   629
lemma suntil_cong:
hoelzl@59000
   630
  "alw P \<omega> \<Longrightarrow> (\<And>\<omega>. P \<omega> \<Longrightarrow> Q1 \<omega> \<longleftrightarrow> Q2 \<omega>) \<Longrightarrow> (\<And>\<omega>. P \<omega> \<Longrightarrow> R1 \<omega> \<longleftrightarrow> R2 \<omega>) \<Longrightarrow>
hoelzl@59000
   631
    (Q1 suntil R1) \<omega> \<longleftrightarrow> (Q2 suntil R2) \<omega>"
hoelzl@59000
   632
  using suntil_mono[of P Q1 Q2 R1 R2 \<omega>] suntil_mono[of P Q2 Q1 R2 R1 \<omega>] by auto
hoelzl@59000
   633
hoelzl@59000
   634
lemma ev_suntil_iff: "ev (P suntil Q) \<omega> \<longleftrightarrow> ev Q \<omega>"
hoelzl@59000
   635
proof
hoelzl@59000
   636
  assume "ev (P suntil Q) \<omega>" then show "ev Q \<omega>"
hoelzl@59000
   637
   by induct (auto dest: ev_suntil)
hoelzl@59000
   638
next
hoelzl@59000
   639
  assume "ev Q \<omega>" then show "ev (P suntil Q) \<omega>"
hoelzl@59000
   640
    by induct (auto intro: suntil.intros)
hoelzl@59000
   641
qed
hoelzl@59000
   642
hoelzl@59000
   643
lemma true_suntil: "((\<lambda>_. True) suntil P) = ev P"
hoelzl@59000
   644
  by (simp add: suntil_def ev_def)
hoelzl@59000
   645
hoelzl@59000
   646
lemma suntil_lfp: "(\<phi> suntil \<psi>) = lfp (\<lambda>P s. \<psi> s \<or> (\<phi> s \<and> P (stl s)))"
hoelzl@59000
   647
  by (simp add: suntil_def)
hoelzl@59000
   648
hoelzl@59000
   649
lemma sfilter_P[simp]: "P (shd s) \<Longrightarrow> sfilter P s = shd s ## sfilter P (stl s)"
hoelzl@59000
   650
  using sfilter_Stream[of P "shd s" "stl s"] by simp
hoelzl@59000
   651
hoelzl@59000
   652
lemma sfilter_not_P[simp]: "\<not> P (shd s) \<Longrightarrow> sfilter P s = sfilter P (stl s)"
hoelzl@59000
   653
  using sfilter_Stream[of P "shd s" "stl s"] by simp
hoelzl@59000
   654
hoelzl@59000
   655
lemma sfilter_eq: 
hoelzl@59000
   656
  assumes "ev (holds P) s"
hoelzl@59000
   657
  shows "sfilter P s = x ## s' \<longleftrightarrow>
hoelzl@59000
   658
    P x \<and> (not (holds P) suntil (HLD {x} aand nxt (\<lambda>s. sfilter P s = s'))) s"
hoelzl@59000
   659
  using assms
hoelzl@59000
   660
  by (induct rule: ev_induct_strong)
hoelzl@59000
   661
     (auto simp add: HLD_iff intro: suntil.intros elim: suntil.cases)
hoelzl@59000
   662
hoelzl@59000
   663
lemma sfilter_streams:
hoelzl@59000
   664
  "alw (ev (holds P)) \<omega> \<Longrightarrow> \<omega> \<in> streams A \<Longrightarrow> sfilter P \<omega> \<in> streams {x\<in>A. P x}"
hoelzl@59000
   665
proof (coinduction arbitrary: \<omega>)
hoelzl@59000
   666
  case (streams \<omega>)
hoelzl@59000
   667
  then have "ev (holds P) \<omega>" by blast
hoelzl@59000
   668
  from this streams show ?case
hoelzl@59000
   669
    by (induct rule: ev_induct_strong) (auto elim: streamsE)
hoelzl@59000
   670
qed
hoelzl@59000
   671
hoelzl@59000
   672
lemma alw_sfilter:
hoelzl@59000
   673
  assumes *: "alw (ev (holds P)) s"
hoelzl@59000
   674
  shows "alw Q (sfilter P s) \<longleftrightarrow> alw (\<lambda>x. Q (sfilter P x)) s"
hoelzl@59000
   675
proof
hoelzl@59000
   676
  assume "alw Q (sfilter P s)" with * show "alw (\<lambda>x. Q (sfilter P x)) s"
hoelzl@59000
   677
  proof (coinduction arbitrary: s rule: alw_coinduct)
hoelzl@59000
   678
    case (stl s) 
hoelzl@59000
   679
    then have "ev (holds P) s"
hoelzl@59000
   680
      by blast
hoelzl@59000
   681
    from this stl show ?case
hoelzl@59000
   682
      by (induct rule: ev_induct_strong) auto
hoelzl@59000
   683
  qed auto
hoelzl@59000
   684
next
hoelzl@59000
   685
  assume "alw (\<lambda>x. Q (sfilter P x)) s" with * show "alw Q (sfilter P s)"
hoelzl@59000
   686
  proof (coinduction arbitrary: s rule: alw_coinduct)
hoelzl@59000
   687
    case (stl s) 
hoelzl@59000
   688
    then have "ev (holds P) s"
hoelzl@59000
   689
      by blast
hoelzl@59000
   690
    from this stl show ?case
hoelzl@59000
   691
      by (induct rule: ev_induct_strong) auto
hoelzl@59000
   692
  qed auto
hoelzl@59000
   693
qed
hoelzl@59000
   694
hoelzl@59000
   695
lemma ev_sfilter:
hoelzl@59000
   696
  assumes *: "alw (ev (holds P)) s"
hoelzl@59000
   697
  shows "ev Q (sfilter P s) \<longleftrightarrow> ev (\<lambda>x. Q (sfilter P x)) s"
hoelzl@59000
   698
proof
hoelzl@59000
   699
  assume "ev Q (sfilter P s)" from this * show "ev (\<lambda>x. Q (sfilter P x)) s"
hoelzl@59000
   700
  proof (induction "sfilter P s" arbitrary: s rule: ev_induct_strong)
hoelzl@59000
   701
    case (step s)
hoelzl@59000
   702
    then have "ev (holds P) s"
hoelzl@59000
   703
      by blast
hoelzl@59000
   704
    from this step show ?case
hoelzl@59000
   705
      by (induct rule: ev_induct_strong) auto
hoelzl@59000
   706
  qed auto
hoelzl@59000
   707
next
hoelzl@59000
   708
  assume "ev (\<lambda>x. Q (sfilter P x)) s" then show "ev Q (sfilter P s)"
hoelzl@59000
   709
  proof (induction rule: ev_induct_strong)
hoelzl@59000
   710
    case (step s) then show ?case
hoelzl@59000
   711
      by (cases "P (shd s)") auto
hoelzl@59000
   712
  qed auto
hoelzl@59000
   713
qed
hoelzl@59000
   714
hoelzl@59000
   715
lemma holds_sfilter:
hoelzl@59000
   716
  assumes "ev (holds Q) s" shows "holds P (sfilter Q s) \<longleftrightarrow> (not (holds Q) suntil (holds (Q aand P))) s"
hoelzl@59000
   717
proof
hoelzl@59000
   718
  assume "holds P (sfilter Q s)" with assms show "(not (holds Q) suntil (holds (Q aand P))) s"
hoelzl@59000
   719
    by (induct rule: ev_induct_strong) (auto intro: suntil.intros)
hoelzl@59000
   720
next
hoelzl@59000
   721
  assume "(not (holds Q) suntil (holds (Q aand P))) s" then show "holds P (sfilter Q s)"
hoelzl@59000
   722
    by induct auto
hoelzl@59000
   723
qed
hoelzl@59000
   724
hoelzl@59000
   725
lemma suntil_aand_nxt:
hoelzl@59000
   726
  "(\<phi> suntil (\<phi> aand nxt \<psi>)) \<omega> \<longleftrightarrow> (\<phi> aand nxt (\<phi> suntil \<psi>)) \<omega>"
hoelzl@59000
   727
proof
hoelzl@59000
   728
  assume "(\<phi> suntil (\<phi> aand nxt \<psi>)) \<omega>" then show "(\<phi> aand nxt (\<phi> suntil \<psi>)) \<omega>"
hoelzl@59000
   729
    by induction (auto intro: suntil.intros)
hoelzl@59000
   730
next
hoelzl@59000
   731
  assume "(\<phi> aand nxt (\<phi> suntil \<psi>)) \<omega>"
hoelzl@59000
   732
  then have "(\<phi> suntil \<psi>) (stl \<omega>)" "\<phi> \<omega>"
hoelzl@59000
   733
    by auto
hoelzl@59000
   734
  then show "(\<phi> suntil (\<phi> aand nxt \<psi>)) \<omega>"
hoelzl@59000
   735
    by (induction "stl \<omega>" arbitrary: \<omega>)
hoelzl@59000
   736
       (auto elim: suntil.cases intro: suntil.intros)
hoelzl@59000
   737
qed
hoelzl@59000
   738
hoelzl@59000
   739
lemma alw_sconst: "alw P (sconst x) \<longleftrightarrow> P (sconst x)"
hoelzl@59000
   740
proof
hoelzl@59000
   741
  assume "P (sconst x)" then show "alw P (sconst x)"
hoelzl@59000
   742
    by coinduction auto
hoelzl@59000
   743
qed auto
hoelzl@59000
   744
hoelzl@59000
   745
lemma ev_sconst: "ev P (sconst x) \<longleftrightarrow> P (sconst x)"
hoelzl@59000
   746
proof
hoelzl@59000
   747
  assume "ev P (sconst x)" then show "P (sconst x)"
hoelzl@59000
   748
    by (induction "sconst x") auto
hoelzl@59000
   749
qed auto
hoelzl@59000
   750
hoelzl@59000
   751
lemma suntil_sconst: "(\<phi> suntil \<psi>) (sconst x) \<longleftrightarrow> \<psi> (sconst x)"
hoelzl@59000
   752
proof
hoelzl@59000
   753
  assume "(\<phi> suntil \<psi>) (sconst x)" then show "\<psi> (sconst x)"
hoelzl@59000
   754
    by (induction "sconst x") auto
hoelzl@59000
   755
qed (auto intro: suntil.intros)
hoelzl@59000
   756
hoelzl@59000
   757
lemma hld_smap': "HLD x (smap f s) = HLD (f -` x) s"
hoelzl@59000
   758
  by (simp add: HLD_def)
hoelzl@58627
   759
hoelzl@58627
   760
end