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