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