Moment.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Wed, 13 Jan 2016 13:20:45 +0000
changeset 69 1dc801552dfd
parent 67 25fd656667a7
child 70 92ca2410b3d9
permissions -rw-r--r--
simplified Moment.thy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
theory Moment
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
imports Main
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
69
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
     5
definition moment :: "nat \<Rightarrow> 'a list \<Rightarrow> 'a list"
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
     6
where "moment n s = rev (take n (rev s))"
67
25fd656667a7 Correctness simplified a great deal.
zhangx
parents: 35
diff changeset
     7
69
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
     8
value "moment 3 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9::int]"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
definition restm :: "nat \<Rightarrow> 'a list \<Rightarrow> 'a list"
69
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    11
where "restm n s = rev (drop n (rev s))"
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    12
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    13
value "restm 3 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9::int]"
0
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
definition from_to :: "nat \<Rightarrow> nat \<Rightarrow> 'a list \<Rightarrow> 'a list"
69
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    16
  where "from_to i j s = take (j - i) (drop i s)"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
definition down_to :: "nat \<Rightarrow> nat \<Rightarrow> 'a list \<Rightarrow> 'a list"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
where "down_to j i s = rev (from_to i j (rev s))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
value "down_to 6 2 [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
value "from_to 2 6 [0, 1, 2, 3, 4, 5, 6, 7]"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
value "from_to 0 2 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] @ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
       from_to 2 5 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"
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
69
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    28
lemma moment_restm_s: "(restm n s) @ (moment n s) = s"
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    29
  unfolding restm_def moment_def
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    30
by (metis append_take_drop_id rev_append rev_rev_ident)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
69
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    32
declare drop.simps [simp del] 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
69
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    34
lemma length_take_le: 
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    35
  "n \<le> length s \<Longrightarrow> length (take n s) = n"
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    36
by (metis length_take min.absorb2)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
lemma length_moment_le:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
  assumes le_k: "k \<le> length s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
  shows "length (moment k s) = k"
69
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    41
using le_k unfolding moment_def by auto
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
lemma length_moment_ge:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
  assumes le_k: "length s \<le> k"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
  shows "length (moment k s) = (length s)"
69
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    46
using assms unfolding moment_def by simp
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
69
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    48
lemma length_take: 
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    49
  "(length (take n s) = length s) \<or> (length (take n s) = n)"
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    50
by (metis length_take min_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
69
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    52
lemma take_conc: 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
  assumes le_mn: "m \<le> n"
69
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    54
  shows "take m s = take m (take n  s)"
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    55
using assms by (metis min.absorb1 take_take) 
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
(*
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    58
value "down_to 2 0 [5, 4, 3, 2, 1, 0]"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
value "moment 2 [5, 4, 3, 2, 1, 0]"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
*)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
69
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    62
lemma from_to_take: "from_to 0 k s = take k s"
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    63
by (simp add:from_to_def drop.simps)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    65
lemma moment_app [simp]:
69
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    66
  assumes ile: "i \<le> length s"
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    67
  shows "moment i (s'@s) = moment i s"
69
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    68
using assms unfolding moment_def by simp
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    70
lemma moment_eq [simp]: "moment (length s) (s'@s) = s"
69
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    71
  unfolding moment_def by simp
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    72
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    73
lemma moment_ge [simp]: "length s \<le> n \<Longrightarrow> moment n s = s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
  by (unfold moment_def, simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
lemma moment_zero [simp]: "moment 0 s = []"
69
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    77
  by (simp add:moment_def)
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    78
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    79
lemma p_split_gen: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    80
  "\<lbrakk>Q s; \<not> Q (moment k s)\<rbrakk> \<Longrightarrow>
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    81
  (\<exists> i. i < length s \<and> k \<le> i \<and> \<not> Q (moment i s) \<and> (\<forall> i' > i. Q (moment i' s)))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    82
proof (induct s, simp)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    83
  fix a s
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    84
  assume ih: "\<lbrakk>Q s; \<not> Q (moment k s)\<rbrakk>
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    85
           \<Longrightarrow> \<exists>i<length s. k \<le> i \<and> \<not> Q (moment i s) \<and> (\<forall>i'>i. Q (moment i' s))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    86
    and nq: "\<not> Q (moment k (a # s))" and qa: "Q (a # s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    87
  have le_k: "k \<le> length s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    88
  proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    89
    { assume "length s < k"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    90
      hence "length (a#s) \<le> k" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    91
      from moment_ge [OF this] and nq and qa
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    92
      have "False" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    93
    } thus ?thesis by arith
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    94
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    95
  have nq_k: "\<not> Q (moment k s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    96
  proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    97
    have "moment k (a#s) = moment k s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    98
    proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    99
      from moment_app [OF le_k, of "[a]"] show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   100
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   101
    with nq show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   102
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   103
  show "\<exists>i<length (a # s). k \<le> i \<and> \<not> Q (moment i (a # s)) \<and> (\<forall>i'>i. Q (moment i' (a # s)))"
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
    { assume "Q s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   106
      from ih [OF this nq_k]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   107
      obtain i where lti: "i < length s" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   108
        and nq: "\<not> Q (moment i s)" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   109
        and rst: "\<forall>i'>i. Q (moment i' s)" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   110
        and lki: "k \<le> i" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   111
      have ?thesis 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   112
      proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   113
        from lti have "i < length (a # s)" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   114
        moreover have " \<not> Q (moment i (a # s))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   115
        proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   116
          from lti have "i \<le> (length s)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   117
          from moment_app [OF this, of "[a]"]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   118
          have "moment i (a # s) = moment i s" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   119
          with nq show ?thesis by auto
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
        moreover have " (\<forall>i'>i. Q (moment i' (a # s)))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   122
        proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   123
          {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   124
            fix i'
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   125
            assume lti': "i < i'"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   126
            have "Q (moment i' (a # s))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   127
            proof(cases "length (a#s) \<le> i'")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   128
              case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   129
              from True have "moment i' (a#s) = a#s" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   130
              with qa show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   131
            next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   132
              case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   133
              from False have "i' \<le> length s" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   134
              from moment_app [OF this, of "[a]"]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   135
              have "moment i' (a#s) = moment i' s" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   136
              with rst lti' show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   137
            qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   138
          } thus ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   139
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   140
        moreover note lki
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   141
        ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   142
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   143
    } moreover {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   144
      assume ns: "\<not> Q s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   145
      have ?thesis
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   146
      proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   147
        let ?i = "length s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   148
        have "\<not> Q (moment ?i (a#s))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   149
        proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   150
          have "?i \<le> length s" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   151
          from moment_app [OF this, of "[a]"]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   152
          have "moment ?i (a#s) = moment ?i s" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   153
          moreover have "\<dots> = s" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   154
          ultimately show ?thesis using ns by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   155
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   156
        moreover have "\<forall> i' > ?i. Q (moment i' (a#s))" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   157
        proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   158
          { fix i'
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   159
            assume "i' > ?i"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   160
            hence "length (a#s) \<le> i'" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   161
            from moment_ge [OF this] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   162
            have " moment i' (a # s) = a # s" .
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   163
            with qa have "Q (moment i' (a#s))" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   164
          } thus ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   165
        qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   166
        moreover have "?i < length (a#s)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   167
        moreover note le_k
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   168
        ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   169
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   170
    } ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   171
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   172
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   173
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   174
lemma p_split: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   175
  "\<And> s Q. \<lbrakk>Q s; \<not> Q []\<rbrakk> \<Longrightarrow> 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   176
       (\<exists> i. i < length s \<and> \<not> Q (moment i s) \<and> (\<forall> i' > i. Q (moment i' s)))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   177
proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   178
  fix s Q
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   179
  assume qs: "Q s" and nq: "\<not> Q []"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   180
  from nq have "\<not> Q (moment 0 s)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   181
  from p_split_gen [of Q s 0, OF qs this]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   182
  show "(\<exists> i. i < length s \<and> \<not> Q (moment i s) \<and> (\<forall> i' > i. Q (moment i' s)))"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   183
    by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   184
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   185
69
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   186
(*
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   187
value "from_to 2 5 [0, 1, 2, 3, 4]"
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   188
value "drop 2  [0, 1, 2, 3, 4]"
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   189
*)
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   190
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   191
(*
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   192
lemma down_to_moment: "down_to k 0 s = moment k s"
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   193
proof -
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   194
  have "rev (from_to 0 k (rev s)) = rev (take k (rev s))" 
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   195
    using from_to_take by metis
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   196
  thus ?thesis by (simp add:down_to_def moment_def)
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   197
qed
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   198
*)
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   199
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   200
lemma moment_plus_split:
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   201
  shows "moment (m + i) s = moment m (restm i s) @ moment i s"
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   202
unfolding moment_def restm_def
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   203
by (metis add.commute rev_append rev_rev_ident take_add)
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   204
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   205
lemma moment_prefix: 
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   206
  "(moment i t @ s) = moment (i + length s) (t @ s)"
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   207
proof -
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   208
  from moment_plus_split [of i "length s" "t@s"]
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   209
  have " moment (i + length s) (t @ s) = moment i (restm (length s) (t @ s)) @ moment (length s) (t @ s)"
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   210
    by auto
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   211
  have "moment (i + length s) (t @ s) = moment i t @ moment (length s) (t @ s)" 
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   212
    by (simp add: moment_def)
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   213
  with moment_app show ?thesis by auto
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   214
qed
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   215
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   216
lemma length_down_to_in: 
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   217
  assumes le_ij: "i \<le> j"
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   218
    and le_js: "j \<le> length s"
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   219
  shows "length (down_to j i s) = j - i"
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   220
using assms
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   221
unfolding down_to_def from_to_def
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   222
by (simp)
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   223
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   224
lemma moment_head: 
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   225
  assumes le_it: "Suc i \<le> length t"
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   226
  obtains e where "moment (Suc i) t = e#moment i t"
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   227
proof -
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   228
  have "i \<le> Suc i" by simp
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   229
  from length_down_to_in [OF this le_it]
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   230
  have a: "length (down_to (Suc i) i t) = 1" by auto
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   231
  then obtain e where "down_to (Suc i) i t = [e]"
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   232
    apply (cases "(down_to (Suc i) i t)") by auto
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   233
  moreover have "down_to (Suc i) 0 t = down_to (Suc i) i t @ down_to i 0 t"
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   234
    unfolding down_to_def from_to_def rev_append[symmetric]
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   235
    apply(simp del: rev_append)
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   236
    by (metis One_nat_def Suc_eq_plus1_left add.commute take_add)
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   237
  ultimately have eq_me: "moment (Suc i) t = e # (moment i t)"
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   238
    by(simp add: moment_def down_to_def from_to_def)
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   239
  from that [OF this] show ?thesis .
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   240
qed
1dc801552dfd simplified Moment.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   241
0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   242
lemma moment_plus: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   243
  "Suc i \<le> length s \<Longrightarrow> moment (Suc i) s = (hd (moment (Suc i) s)) # (moment i s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   244
proof(induct s, simp+)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   245
  fix a s
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   246
  assume ih: "Suc i \<le> length s \<Longrightarrow> moment (Suc i) s = hd (moment (Suc i) s) # moment i s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   247
    and le_i: "i \<le> length s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   248
  show "moment (Suc i) (a # s) = hd (moment (Suc i) (a # s)) # moment i (a # s)"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   249
  proof(cases "i= length s")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   250
    case True
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   251
    hence "Suc i = length (a#s)" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   252
    with moment_eq have "moment (Suc i) (a#s) = a#s" by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   253
    moreover have "moment i (a#s) = s"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   254
    proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   255
      from moment_app [OF le_i, of "[a]"]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   256
      and True show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   257
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   258
    ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   259
  next
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   260
    case False
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   261
    from False and le_i have lti: "i < length s" by arith
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   262
    hence les_i: "Suc i \<le> length s" by arith
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   263
    show ?thesis 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   264
    proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   265
      from moment_app [OF les_i, of "[a]"]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   266
      have "moment (Suc i) (a # s) = moment (Suc i) s" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   267
      moreover have "moment i (a#s) = moment i s" 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   268
      proof -
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   269
        from lti have "i \<le> length s" by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   270
        from moment_app [OF this, of "[a]"] show ?thesis by simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   271
      qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   272
      moreover note ih [OF les_i]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   273
      ultimately show ?thesis by auto
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   274
    qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   275
  qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   276
qed
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   277
35
92f61f6a0fe7 added a bit more text to the paper and separated a theory about Max
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 0
diff changeset
   278
end