Attic/Happen_within.thy
author zhangx
Mon, 08 Feb 2016 10:57:01 +0800
changeset 113 ce85c3c4e5bf
parent 1 c4783e4ef43f
permissions -rw-r--r--
More improvements in PIPBasics.thy and Implemenation.thy.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
theory Happen_within
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
imports Main Moment
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
begin
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
(* 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
  lemma 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
  fixes P :: "('a list) \<Rightarrow> bool"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
  and Q :: "('a list) \<Rightarrow> bool"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
  and k :: nat
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
  and f :: "('a list) \<Rightarrow> nat"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
  assumes "\<And> s t. \<lbrakk>P s; \<not> Q s; P (t@s); k < length t\<rbrakk> \<Longrightarrow> f (t@s) < f s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
  shows "\<And> s t. \<lbrakk> P s;  P(t @ s); f(s) * k < length t\<rbrakk> \<Longrightarrow> Q (t@s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
  sorry
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
*)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
text {* 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
  The following two notions are introduced to improve the situation.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
  *}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
definition all_future :: "(('a list) \<Rightarrow> bool) \<Rightarrow> (('a list) \<Rightarrow> bool) \<Rightarrow> ('a list) \<Rightarrow> bool"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
where "all_future G R s = (\<forall> t. G (t@s) \<longrightarrow> R t)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
definition happen_within :: "(('a list) \<Rightarrow> bool) \<Rightarrow> (('a list) \<Rightarrow> bool) \<Rightarrow> nat \<Rightarrow> ('a list) \<Rightarrow> bool"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
where "happen_within G R k s = all_future G (\<lambda> t. k < length t \<longrightarrow> 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
                                  (\<exists> i \<le> k. R (moment i t @ s) \<and> G (moment i t @ s))) s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
lemma happen_within_intro:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
  fixes P :: "('a list) \<Rightarrow> bool"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
  and Q :: "('a list) \<Rightarrow> bool"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
  and k :: nat
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
  and f :: "('a list) \<Rightarrow> nat"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
  assumes 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
  lt_k: "0 < k"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
  and step: "\<And> s. \<lbrakk>P s; \<not> Q s\<rbrakk> \<Longrightarrow> happen_within P (\<lambda> s'. f s' < f s) k s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
  shows "\<And> s. P s \<Longrightarrow> happen_within P Q ((f s + 1) * k) s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
  fix s
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
  assume "P s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
  thus "happen_within P Q ((f s + 1) * k) s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
  proof(induct n == "f s + 1" arbitrary:s rule:nat_less_induct)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
    fix s
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
    assume ih [rule_format]: "\<forall>m<f s + 1. \<forall>x. m = f x + 1 \<longrightarrow> P x 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
                                 \<longrightarrow> happen_within P Q ((f x + 1) * k) x"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
      and ps: "P s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
    show "happen_within P Q ((f s + 1) * k) s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
    proof(cases "Q s")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
      case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
      show ?thesis 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
      proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
        { fix t
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
          from True and ps have "0 \<le> ((f s + 1)*k) \<and> Q (moment 0 t @ s) \<and> P (moment 0 t @ s)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    52
          hence "\<exists>i\<le>(f s + 1) * k. Q (moment i t @ s) \<and> P (moment i t @ s)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
        } thus ?thesis by (auto simp: happen_within_def all_future_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    54
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
    next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
      case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
      from step [OF ps False] have kk: "happen_within P (\<lambda>s'. f s' < f s) k s" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    58
      show ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
      proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
        { fix t
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
          assume pts: "P (t @ s)" and ltk: "(f s + 1) * k < length t"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
          from ltk have lt_k_lt: "k < length t" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
          with kk pts obtain i 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
            where le_ik: "i \<le> k" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    65
            and lt_f: "f (moment i t @ s) < f s" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    66
            and p_m: "P (moment i t @ s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    67
            by (auto simp:happen_within_def all_future_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
          from ih [of "f (moment i t @ s) + 1" "(moment i t @ s)", OF _ _ p_m] and lt_f
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
          have hw: "happen_within P Q ((f (moment i t @ s) + 1) * k) (moment i t @ s)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    70
          have "(\<exists>j\<le>(f s + 1) * k. Q (moment j t @ s) \<and>  P (moment j t @ s))" (is "\<exists> j. ?T j")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    71
          proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    72
            let ?t = "restm i t"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    73
            have eq_t: "t = ?t @ moment i t" by (simp add:moment_restm_s) 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
            have h1: "P (restm i t @ moment i t @ s)" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
            proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
              from pts and eq_t have "P ((restm i t @ moment i t) @ s)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    77
              thus ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    78
            qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    79
            moreover have h2: "(f (moment i t @ s) + 1) * k < length (restm i t)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    80
            proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    81
              have h: "\<And> x y z. (x::nat) \<le> y \<Longrightarrow> x * z \<le> y * z" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    82
              from lt_f have "(f (moment i t @ s) + 1) \<le> f s " by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    83
              from h [OF this, of k]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    84
              have "(f (moment i t @ s) + 1) * k \<le> f s * k" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    85
              moreover from le_ik have "\<dots> \<le> ((f s) * k + k - i)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    86
              moreover from le_ik lt_k_lt and ltk have "(f s) * k + k - i < length t - i" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    87
              moreover have "length (restm i t) = length t - i" using length_restm by metis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    88
              ultimately show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    89
            qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    90
            from hw [unfolded happen_within_def all_future_def, rule_format, OF h1 h2]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    91
            obtain m where le_m: "m \<le> (f (moment i t @ s) + 1) * k"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    92
              and q_m: "Q (moment m ?t @ moment i t @ s)" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    93
              and p_m: "P (moment m ?t @ moment i t @ s)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    94
            have eq_mm: "moment m ?t @ moment i t @ s = (moment (m+i) t)@s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    95
            proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    96
              have "moment m (restm i t) @ moment i t = moment (m + i) t"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    97
                using moment_plus_split by metis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    98
              thus ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    99
            qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   100
            let ?j = "m + i"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   101
            have "?T ?j"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   102
            proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   103
              have "m + i \<le> (f s + 1) * k"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   104
              proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   105
                have h: "\<And> x y z. (x::nat) \<le> y \<Longrightarrow> x * z \<le> y * z" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   106
                from lt_f have "(f (moment i t @ s) + 1) \<le> f s " by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   107
                from h [OF this, of k]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   108
                have "(f (moment i t @ s) + 1) * k \<le> f s * k" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   109
                with le_m have "m \<le> f s * k" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   110
                hence "m + i \<le> f s * k + i" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   111
                with le_ik show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   112
              qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   113
              moreover from eq_mm q_m have " Q (moment (m + i) t @ s)" by metis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   114
              moreover from eq_mm p_m have " P (moment (m + i) t @ s)" by metis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   115
              ultimately show ?thesis by blast
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   116
            qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   117
            thus ?thesis by blast
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   118
          qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   119
        } thus ?thesis by  (simp add:happen_within_def all_future_def firstn.simps)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   120
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   121
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   122
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   123
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   124
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   125
end
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   126