src/HOL/Induct/SList.thy
author huffman
Sun, 04 Sep 2011 10:29:38 -0700
changeset 44712 1e490e891c88
parent 39246 9e58f0499f57
child 45605 a89b4bc311a5
permissions -rw-r--r--
replace lemma expi_imaginary with reoriented lemma cis_conv_exp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35247
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
     1
(*  Title:      HOL/Induct/SList.thy
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
     3
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
     4
This theory is strictly of historical interest. It illustrates how
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
     5
recursive datatypes can be constructed in higher-order logic from
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
     6
first principles. Isabelle's datatype package automates a
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
     7
construction of this sort.
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
     8
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
     9
Enriched theory of lists; mutual indirect recursive data-types.
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    10
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    11
Definition of type 'a list (strict lists) by a least fixed point
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    12
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    13
We use          list(A) == lfp(%Z. {NUMB(0)} <+> A <*> Z)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    14
and not         list    == lfp(%Z. {NUMB(0)} <+> range(Leaf) <*> Z)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    15
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    16
so that list can serve as a "functor" for defining other recursive types.
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    17
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    18
This enables the conservative construction of mutual recursive data-types
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    19
such as
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    20
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    21
datatype 'a m = Node 'a * ('a m) list
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    22
*)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    23
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    24
header {* Extended List Theory (old) *}
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    25
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    26
theory SList
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    27
imports Sexp
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    28
begin
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    29
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    30
(*Hilbert_Choice is needed for the function "inv"*)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    31
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    32
(* *********************************************************************** *)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    33
(*                                                                         *)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    34
(* Building up data type                                                   *)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    35
(*                                                                         *)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    36
(* *********************************************************************** *)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    37
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    38
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    39
(* Defining the Concrete Constructors *)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    40
definition
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    41
  NIL  :: "'a item" where
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    42
  "NIL = In0(Numb(0))"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    43
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    44
definition
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    45
  CONS :: "['a item, 'a item] => 'a item" where
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    46
  "CONS M N = In1(Scons M N)"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    47
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    48
inductive_set
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    49
  list :: "'a item set => 'a item set"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    50
  for A :: "'a item set"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    51
  where
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    52
    NIL_I:  "NIL: list A"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    53
  | CONS_I: "[| a: A;  M: list A |] ==> CONS a M : list A"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    54
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    55
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    56
typedef (List)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    57
    'a list = "list(range Leaf) :: 'a item set" 
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    58
  by (blast intro: list.NIL_I)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    59
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    60
abbreviation "Case == Datatype.Case"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    61
abbreviation "Split == Datatype.Split"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    62
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    63
definition
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    64
  List_case :: "['b, ['a item, 'a item]=>'b, 'a item] => 'b" where
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    65
  "List_case c d = Case(%x. c)(Split(d))"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    66
  
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    67
definition
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    68
  List_rec  :: "['a item, 'b, ['a item, 'a item, 'b]=>'b] => 'b" where
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    69
  "List_rec M c d = wfrec (pred_sexp^+)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    70
                           (%g. List_case c (%x y. d x y (g y))) M"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    71
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    72
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    73
(* *********************************************************************** *)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    74
(*                                                                         *)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    75
(* Abstracting data type                                                   *)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    76
(*                                                                         *)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    77
(* *********************************************************************** *)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    78
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    79
(*Declaring the abstract list constructors*)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    80
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    81
no_translations
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    82
  "[x, xs]" == "x#[xs]"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    83
  "[x]" == "x#[]"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    84
no_notation
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    85
  Nil  ("[]") and
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    86
  Cons (infixr "#" 65)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    87
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    88
definition
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    89
  Nil       :: "'a list"                               ("[]") where
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    90
   "Nil  = Abs_List(NIL)"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    91
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    92
definition
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    93
  "Cons"       :: "['a, 'a list] => 'a list"           (infixr "#" 65) where
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    94
   "x#xs = Abs_List(CONS (Leaf x)(Rep_List xs))"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    95
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    96
definition
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    97
  (* list Recursion -- the trancl is Essential; see list.ML *)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    98
  list_rec  :: "['a list, 'b, ['a, 'a list, 'b]=>'b] => 'b" where
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
    99
   "list_rec l c d =
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   100
      List_rec(Rep_List l) c (%x y r. d(inv Leaf x)(Abs_List y) r)"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   101
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   102
definition
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   103
  list_case :: "['b, ['a, 'a list]=>'b, 'a list] => 'b" where
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   104
   "list_case a f xs = list_rec xs a (%x xs r. f x xs)"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   105
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   106
(* list Enumeration *)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   107
translations
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   108
  "[x, xs]" == "x#[xs]"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   109
  "[x]"     == "x#[]"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   110
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   111
  "case xs of [] => a | y#ys => b" == "CONST list_case(a, %y ys. b, xs)"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   112
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   113
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   114
(* *********************************************************************** *)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   115
(*                                                                         *)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   116
(* Generalized Map Functionals                                             *)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   117
(*                                                                         *)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   118
(* *********************************************************************** *)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   119
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   120
  
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   121
(* Generalized Map Functionals *)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   122
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   123
definition
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   124
  Rep_map   :: "('b => 'a item) => ('b list => 'a item)" where
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   125
   "Rep_map f xs = list_rec xs  NIL(%x l r. CONS(f x) r)"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   126
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   127
definition
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   128
  Abs_map   :: "('a item => 'b) => 'a item => 'b list" where
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   129
   "Abs_map g M  = List_rec M Nil (%N L r. g(N)#r)"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   130
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   131
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   132
definition
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   133
  map       :: "('a=>'b) => ('a list => 'b list)" where
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   134
  "map f xs = list_rec xs [] (%x l r. f(x)#r)"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   135
39246
9e58f0499f57 modernized primrec
haftmann
parents: 35247
diff changeset
   136
primrec take :: "['a list,nat] => 'a list" where
35247
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   137
  take_0:  "take xs 0 = []"
39246
9e58f0499f57 modernized primrec
haftmann
parents: 35247
diff changeset
   138
| take_Suc: "take xs (Suc n) = list_case [] (%x l. x # take l n) xs"
35247
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   139
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   140
lemma ListI: "x : list (range Leaf) ==> x : List"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   141
by (simp add: List_def)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   142
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   143
lemma ListD: "x : List ==> x : list (range Leaf)"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   144
by (simp add: List_def)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   145
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   146
lemma list_unfold: "list(A) = usum {Numb(0)} (uprod A (list(A)))"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   147
  by (fast intro!: list.intros [unfolded NIL_def CONS_def]
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   148
           elim: list.cases [unfolded NIL_def CONS_def])
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   149
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   150
(*This justifies using list in other recursive type definitions*)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   151
lemma list_mono: "A<=B ==> list(A) <= list(B)"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   152
apply (rule subsetI)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   153
apply (erule list.induct)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   154
apply (auto intro!: list.intros)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   155
done
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   156
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   157
(*Type checking -- list creates well-founded sets*)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   158
lemma list_sexp: "list(sexp) <= sexp"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   159
apply (rule subsetI)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   160
apply (erule list.induct)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   161
apply (unfold NIL_def CONS_def)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   162
apply (auto intro: sexp.intros sexp_In0I sexp_In1I)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   163
done
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   164
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   165
(* A <= sexp ==> list(A) <= sexp *)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   166
lemmas list_subset_sexp = subset_trans [OF list_mono list_sexp] 
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   167
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   168
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   169
(*Induction for the type 'a list *)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   170
lemma list_induct:
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   171
    "[| P(Nil);    
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   172
        !!x xs. P(xs) ==> P(x # xs) |]  ==> P(l)"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   173
apply (unfold Nil_def Cons_def) 
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   174
apply (rule Rep_List_inverse [THEN subst])
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   175
(*types force good instantiation*)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   176
apply (rule Rep_List [unfolded List_def, THEN list.induct], simp)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   177
apply (erule Abs_List_inverse [unfolded List_def, THEN subst], blast) 
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   178
done
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   179
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   180
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   181
(*** Isomorphisms ***)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   182
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   183
lemma inj_on_Abs_list: "inj_on Abs_List (list(range Leaf))"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   184
apply (rule inj_on_inverseI)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   185
apply (erule Abs_List_inverse [unfolded List_def])
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   186
done
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   187
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   188
(** Distinctness of constructors **)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   189
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   190
lemma CONS_not_NIL [iff]: "CONS M N ~= NIL"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   191
by (simp add: NIL_def CONS_def)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   192
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   193
lemmas NIL_not_CONS [iff] = CONS_not_NIL [THEN not_sym]
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   194
lemmas CONS_neq_NIL = CONS_not_NIL [THEN notE, standard]
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   195
lemmas NIL_neq_CONS = sym [THEN CONS_neq_NIL]
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   196
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   197
lemma Cons_not_Nil [iff]: "x # xs ~= Nil"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   198
apply (unfold Nil_def Cons_def)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   199
apply (rule CONS_not_NIL [THEN inj_on_Abs_list [THEN inj_on_contraD]])
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   200
apply (simp_all add: list.intros rangeI Rep_List [unfolded List_def])
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   201
done
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   202
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   203
lemmas Nil_not_Cons [iff] = Cons_not_Nil [THEN not_sym, standard]
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   204
lemmas Cons_neq_Nil = Cons_not_Nil [THEN notE, standard]
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   205
lemmas Nil_neq_Cons = sym [THEN Cons_neq_Nil]
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   206
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   207
(** Injectiveness of CONS and Cons **)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   208
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   209
lemma CONS_CONS_eq [iff]: "(CONS K M)=(CONS L N) = (K=L & M=N)"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   210
by (simp add: CONS_def)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   211
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   212
(*For reasoning about abstract list constructors*)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   213
declare Rep_List [THEN ListD, intro] ListI [intro]
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   214
declare list.intros [intro,simp]
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   215
declare Leaf_inject [dest!]
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   216
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   217
lemma Cons_Cons_eq [iff]: "(x#xs=y#ys) = (x=y & xs=ys)"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   218
apply (simp add: Cons_def)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   219
apply (subst Abs_List_inject)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   220
apply (auto simp add: Rep_List_inject)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   221
done
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   222
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   223
lemmas Cons_inject2 = Cons_Cons_eq [THEN iffD1, THEN conjE, standard]
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   224
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   225
lemma CONS_D: "CONS M N: list(A) ==> M: A & N: list(A)"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   226
  by (induct L == "CONS M N" set: list) auto
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   227
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   228
lemma sexp_CONS_D: "CONS M N: sexp ==> M: sexp & N: sexp"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   229
apply (simp add: CONS_def In1_def)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   230
apply (fast dest!: Scons_D)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   231
done
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   232
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   233
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   234
(*Reasoning about constructors and their freeness*)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   235
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   236
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   237
lemma not_CONS_self: "N: list(A) ==> !M. N ~= CONS M N"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   238
apply (erule list.induct) apply simp_all done
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   239
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   240
lemma not_Cons_self2: "\<forall>x. l ~= x#l"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   241
by (induct l rule: list_induct) simp_all
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   242
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   243
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   244
lemma neq_Nil_conv2: "(xs ~= []) = (\<exists>y ys. xs = y#ys)"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   245
by (induct xs rule: list_induct) auto
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   246
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   247
(** Conversion rules for List_case: case analysis operator **)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   248
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   249
lemma List_case_NIL [simp]: "List_case c h NIL = c"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   250
by (simp add: List_case_def NIL_def)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   251
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   252
lemma List_case_CONS [simp]: "List_case c h (CONS M N) = h M N"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   253
by (simp add: List_case_def CONS_def)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   254
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   255
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   256
(*** List_rec -- by wf recursion on pred_sexp ***)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   257
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   258
(* The trancl(pred_sexp) is essential because pred_sexp_CONS_I1,2 would not
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   259
   hold if pred_sexp^+ were changed to pred_sexp. *)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   260
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   261
lemma List_rec_unfold_lemma:
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   262
     "(%M. List_rec M c d) == 
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   263
      wfrec (pred_sexp^+) (%g. List_case c (%x y. d x y (g y)))"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   264
by (simp add: List_rec_def)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   265
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   266
lemmas List_rec_unfold = 
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   267
    def_wfrec [OF List_rec_unfold_lemma wf_pred_sexp [THEN wf_trancl], 
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   268
               standard]
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   269
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   270
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   271
(** pred_sexp lemmas **)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   272
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   273
lemma pred_sexp_CONS_I1: 
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   274
    "[| M: sexp;  N: sexp |] ==> (M, CONS M N) : pred_sexp^+"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   275
by (simp add: CONS_def In1_def)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   276
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   277
lemma pred_sexp_CONS_I2: 
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   278
    "[| M: sexp;  N: sexp |] ==> (N, CONS M N) : pred_sexp^+"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   279
by (simp add: CONS_def In1_def)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   280
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   281
lemma pred_sexp_CONS_D: 
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   282
    "(CONS M1 M2, N) : pred_sexp^+ ==>  
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   283
     (M1,N) : pred_sexp^+ & (M2,N) : pred_sexp^+"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   284
apply (frule pred_sexp_subset_Sigma [THEN trancl_subset_Sigma, THEN subsetD])
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   285
apply (blast dest!: sexp_CONS_D intro: pred_sexp_CONS_I1 pred_sexp_CONS_I2 
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   286
                    trans_trancl [THEN transD])
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   287
done
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   288
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   289
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   290
(** Conversion rules for List_rec **)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   291
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   292
lemma List_rec_NIL [simp]: "List_rec NIL c h = c"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   293
apply (rule List_rec_unfold [THEN trans])
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   294
apply (simp add: List_case_NIL)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   295
done
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   296
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   297
lemma List_rec_CONS [simp]:
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   298
     "[| M: sexp;  N: sexp |] 
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   299
      ==> List_rec (CONS M N) c h = h M N (List_rec N c h)"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   300
apply (rule List_rec_unfold [THEN trans])
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   301
apply (simp add: pred_sexp_CONS_I2)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   302
done
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   303
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   304
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   305
(*** list_rec -- by List_rec ***)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   306
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   307
lemmas Rep_List_in_sexp =
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   308
    subsetD [OF range_Leaf_subset_sexp [THEN list_subset_sexp]
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   309
                Rep_List [THEN ListD]] 
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   310
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   311
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   312
lemma list_rec_Nil [simp]: "list_rec Nil c h = c"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   313
by (simp add: list_rec_def ListI [THEN Abs_List_inverse] Nil_def)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   314
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   315
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   316
lemma list_rec_Cons [simp]: "list_rec (a#l) c h = h a l (list_rec l c h)"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   317
by (simp add: list_rec_def ListI [THEN Abs_List_inverse] Cons_def
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   318
              Rep_List_inverse Rep_List [THEN ListD] inj_Leaf Rep_List_in_sexp)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   319
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   320
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   321
(*Type checking.  Useful?*)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   322
lemma List_rec_type:
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   323
     "[| M: list(A);      
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   324
         A<=sexp;         
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   325
         c: C(NIL);       
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   326
         !!x y r. [| x: A;  y: list(A);  r: C(y) |] ==> h x y r: C(CONS x y)  
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   327
      |] ==> List_rec M c h : C(M :: 'a item)"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   328
apply (erule list.induct, simp) 
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   329
apply (insert list_subset_sexp) 
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   330
apply (subst List_rec_CONS, blast+)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   331
done
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   332
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   333
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   334
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   335
(** Generalized map functionals **)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   336
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   337
lemma Rep_map_Nil [simp]: "Rep_map f Nil = NIL"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   338
by (simp add: Rep_map_def)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   339
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   340
lemma Rep_map_Cons [simp]: 
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   341
    "Rep_map f(x#xs) = CONS(f x)(Rep_map f xs)"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   342
by (simp add: Rep_map_def)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   343
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   344
lemma Rep_map_type: "(!!x. f(x): A) ==> Rep_map f xs: list(A)"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   345
apply (simp add: Rep_map_def)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   346
apply (rule list_induct, auto)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   347
done
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   348
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   349
lemma Abs_map_NIL [simp]: "Abs_map g NIL = Nil"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   350
by (simp add: Abs_map_def)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   351
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   352
lemma Abs_map_CONS [simp]: 
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   353
    "[| M: sexp;  N: sexp |] ==> Abs_map g (CONS M N) = g(M) # Abs_map g N"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   354
by (simp add: Abs_map_def)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   355
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   356
(*Eases the use of primitive recursion.*)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   357
lemma def_list_rec_NilCons:
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   358
    "[| !!xs. f(xs) = list_rec xs c h  |] 
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   359
     ==> f [] = c & f(x#xs) = h x xs (f xs)"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   360
by simp 
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   361
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   362
lemma Abs_map_inverse:
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   363
     "[| M: list(A);  A<=sexp;  !!z. z: A ==> f(g(z)) = z |]  
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   364
      ==> Rep_map f (Abs_map g M) = M"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   365
apply (erule list.induct, simp_all)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   366
apply (insert list_subset_sexp) 
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   367
apply (subst Abs_map_CONS, blast)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   368
apply blast 
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   369
apply simp 
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   370
done
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   371
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   372
(*Rep_map_inverse is obtained via Abs_Rep_map and map_ident*)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   373
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   374
(** list_case **)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   375
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   376
(* setting up rewrite sets *)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   377
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   378
text{*Better to have a single theorem with a conjunctive conclusion.*}
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   379
declare def_list_rec_NilCons [OF list_case_def, simp]
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   380
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   381
(** list_case **)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   382
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   383
lemma expand_list_case: 
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   384
 "P(list_case a f xs) = ((xs=[] --> P a ) & (!y ys. xs=y#ys --> P(f y ys)))"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   385
by (induct xs rule: list_induct) simp_all
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   386
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   387
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   388
(**** Function definitions ****)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   389
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   390
declare def_list_rec_NilCons [OF map_def, simp]
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   391
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   392
(** The functional "map" and the generalized functionals **)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   393
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   394
lemma Abs_Rep_map: 
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   395
     "(!!x. f(x): sexp) ==>  
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   396
        Abs_map g (Rep_map f xs) = map (%t. g(f(t))) xs"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   397
apply (induct xs rule: list_induct)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   398
apply (simp_all add: Rep_map_type list_sexp [THEN subsetD])
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   399
done
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   400
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   401
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   402
(** Additional mapping lemmas **)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   403
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   404
lemma map_ident [simp]: "map(%x. x)(xs) = xs"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   405
by (induct xs rule: list_induct) simp_all
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   406
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   407
lemma map_compose: "map(f o g)(xs) = map f (map g xs)"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   408
apply (simp add: o_def)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   409
apply (induct xs rule: list_induct)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   410
apply simp_all
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   411
done
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   412
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   413
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   414
(** take **)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   415
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   416
lemma take_Suc1 [simp]: "take [] (Suc x) = []"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   417
by simp
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   418
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   419
lemma take_Suc2 [simp]: "take(a#xs)(Suc x) = a#take xs x"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   420
by simp
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   421
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   422
lemma take_Nil [simp]: "take [] n = []"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   423
by (induct n) simp_all
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   424
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   425
lemma take_take_eq [simp]: "\<forall>n. take (take xs n) n = take xs n"
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   426
apply (induct xs rule: list_induct)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   427
apply simp_all
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   428
apply (rule allI)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   429
apply (induct_tac n)
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   430
apply auto
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   431
done
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   432
0831bd85eee5 moved reduced Induct/SList back from AFP.
nipkow
parents:
diff changeset
   433
end