src/HOL/Library/Subarray.thy
author wenzelm
Thu Oct 16 22:44:24 2008 +0200 (2008-10-16)
changeset 28615 4c8fa015ec7f
parent 27656 d4f6e64ee7cc
permissions -rw-r--r--
explicit SORT_CONSTRAINT for proofs depending implicitly on certain sorts;
bulwahn@27656
     1
theory Subarray
bulwahn@27656
     2
imports Array Sublist
bulwahn@27656
     3
begin
bulwahn@27656
     4
bulwahn@27656
     5
definition subarray :: "nat \<Rightarrow> nat \<Rightarrow> ('a::heap) array \<Rightarrow> heap \<Rightarrow> 'a list"
bulwahn@27656
     6
where
bulwahn@27656
     7
  "subarray n m a h \<equiv> sublist' n m (get_array a h)"
bulwahn@27656
     8
bulwahn@27656
     9
lemma subarray_upd: "i \<ge> m \<Longrightarrow> subarray n m a (Heap.upd a i v h) = subarray n m a h"
bulwahn@27656
    10
apply (simp add: subarray_def Heap.upd_def)
bulwahn@27656
    11
apply (simp add: sublist'_update1)
bulwahn@27656
    12
done
bulwahn@27656
    13
bulwahn@27656
    14
lemma subarray_upd2: " i < n  \<Longrightarrow> subarray n m a (Heap.upd a i v h) = subarray n m a h"
bulwahn@27656
    15
apply (simp add: subarray_def Heap.upd_def)
bulwahn@27656
    16
apply (subst sublist'_update2)
bulwahn@27656
    17
apply fastsimp
bulwahn@27656
    18
apply simp
bulwahn@27656
    19
done
bulwahn@27656
    20
bulwahn@27656
    21
lemma subarray_upd3: "\<lbrakk> n \<le> i; i < m\<rbrakk> \<Longrightarrow> subarray n m a (Heap.upd a i v h) = subarray n m a h[i - n := v]"
bulwahn@27656
    22
unfolding subarray_def Heap.upd_def
bulwahn@27656
    23
by (simp add: sublist'_update3)
bulwahn@27656
    24
bulwahn@27656
    25
lemma subarray_Nil: "n \<ge> m \<Longrightarrow> subarray n m a h = []"
bulwahn@27656
    26
by (simp add: subarray_def sublist'_Nil')
bulwahn@27656
    27
bulwahn@27656
    28
lemma subarray_single: "\<lbrakk> n < Heap.length a h \<rbrakk> \<Longrightarrow> subarray n (Suc n) a h = [get_array a h ! n]" 
bulwahn@27656
    29
by (simp add: subarray_def Heap.length_def sublist'_single)
bulwahn@27656
    30
bulwahn@27656
    31
lemma length_subarray: "m \<le> Heap.length a h \<Longrightarrow> List.length (subarray n m a h) = m - n"
bulwahn@27656
    32
by (simp add: subarray_def Heap.length_def length_sublist')
bulwahn@27656
    33
bulwahn@27656
    34
lemma length_subarray_0: "m \<le> Heap.length a h \<Longrightarrow> List.length (subarray 0 m a h) = m"
bulwahn@27656
    35
by (simp add: length_subarray)
bulwahn@27656
    36
bulwahn@27656
    37
lemma subarray_nth_array_Cons: "\<lbrakk> i < Heap.length a h; i < j \<rbrakk> \<Longrightarrow> (get_array a h ! i) # subarray (Suc i) j a h = subarray i j a h"
bulwahn@27656
    38
unfolding Heap.length_def subarray_def
bulwahn@27656
    39
by (simp add: sublist'_front)
bulwahn@27656
    40
bulwahn@27656
    41
lemma subarray_nth_array_back: "\<lbrakk> i < j; j \<le> Heap.length a h\<rbrakk> \<Longrightarrow> subarray i j a h = subarray i (j - 1) a h @ [get_array a h ! (j - 1)]"
bulwahn@27656
    42
unfolding Heap.length_def subarray_def
bulwahn@27656
    43
by (simp add: sublist'_back)
bulwahn@27656
    44
bulwahn@27656
    45
lemma subarray_append: "\<lbrakk> i < j; j < k \<rbrakk> \<Longrightarrow> subarray i j a h @ subarray j k a h = subarray i k a h"
bulwahn@27656
    46
unfolding subarray_def
bulwahn@27656
    47
by (simp add: sublist'_append)
bulwahn@27656
    48
bulwahn@27656
    49
lemma subarray_all: "subarray 0 (Heap.length a h) a h = get_array a h"
bulwahn@27656
    50
unfolding Heap.length_def subarray_def
bulwahn@27656
    51
by (simp add: sublist'_all)
bulwahn@27656
    52
bulwahn@27656
    53
lemma nth_subarray: "\<lbrakk> k < j - i; j \<le> Heap.length a h \<rbrakk> \<Longrightarrow> subarray i j a h ! k = get_array a h ! (i + k)"
bulwahn@27656
    54
unfolding Heap.length_def subarray_def
bulwahn@27656
    55
by (simp add: nth_sublist')
bulwahn@27656
    56
bulwahn@27656
    57
lemma subarray_eq_samelength_iff: "Heap.length a h = Heap.length a h' \<Longrightarrow> (subarray i j a h = subarray i j a h') = (\<forall>i'. i \<le> i' \<and> i' < j \<longrightarrow> get_array a h ! i' = get_array a h' ! i')"
bulwahn@27656
    58
unfolding Heap.length_def subarray_def by (rule sublist'_eq_samelength_iff)
bulwahn@27656
    59
bulwahn@27656
    60
lemma all_in_set_subarray_conv: "(\<forall>j. j \<in> set (subarray l r a h) \<longrightarrow> P j) = (\<forall>k. l \<le> k \<and> k < r \<and> k < Heap.length a h \<longrightarrow> P (get_array a h ! k))"
bulwahn@27656
    61
unfolding subarray_def Heap.length_def by (rule all_in_set_sublist'_conv)
bulwahn@27656
    62
bulwahn@27656
    63
lemma ball_in_set_subarray_conv: "(\<forall>j \<in> set (subarray l r a h). P j) = (\<forall>k. l \<le> k \<and> k < r \<and> k < Heap.length a h \<longrightarrow> P (get_array a h ! k))"
bulwahn@27656
    64
unfolding subarray_def Heap.length_def by (rule ball_in_set_sublist'_conv)
bulwahn@27656
    65
bulwahn@27656
    66
end