src/HOL/Induct/SList.thy
author haftmann
Tue, 23 Sep 2008 18:11:42 +0200
changeset 28335 25326092cf9a
parent 23746 a455e69c31cc
child 30166 f47c812de07c
permissions -rw-r--r--
renamed rtype to typerep
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
     1
(* *********************************************************************** *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
     2
(*                                                                         *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
     3
(* Title:      SList.thy (Extended List Theory)                            *)
13079
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
     4
(* Based on:   $Id$      *)
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
     5
(* Author:     Lawrence C Paulson, Cambridge University Computer Laboratory*)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
     6
(* Author:     B. Wolff, University of Bremen                              *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
     7
(* Purpose:    Enriched theory of lists                                    *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
     8
(*	       mutual indirect recursive data-types                        *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
     9
(*                                                                         *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    10
(* *********************************************************************** *)
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    11
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    12
(* Definition of type 'a list (strict lists) by a least fixed point
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    13
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    14
We use          list(A) == lfp(%Z. {NUMB(0)} <+> A <*> Z)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    15
and not         list    == lfp(%Z. {NUMB(0)} <+> range(Leaf) <*> Z)
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    16
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    17
so that list can serve as a "functor" for defining other recursive types.
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    18
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    19
This enables the conservative construction of mutual recursive data-types
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    20
such as
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    21
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    22
datatype 'a m = Node 'a * ('a m) list
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    23
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    24
Tidied by lcp.  Still needs removal of nat_rec.
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    25
*)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    26
23235
eb365b39b36d authentic syntax for List.append
haftmann
parents: 23029
diff changeset
    27
theory SList
eb365b39b36d authentic syntax for List.append
haftmann
parents: 23029
diff changeset
    28
imports Sexp
eb365b39b36d authentic syntax for List.append
haftmann
parents: 23029
diff changeset
    29
begin
13079
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
    30
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
    31
(*Hilbert_Choice is needed for the function "inv"*)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
    32
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    33
(* *********************************************************************** *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    34
(*                                                                         *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    35
(* Building up data type                                                   *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    36
(*                                                                         *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    37
(* *********************************************************************** *)
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    38
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    39
13079
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
    40
(* Defining the Concrete Constructors *)
19736
wenzelm
parents: 18413
diff changeset
    41
definition
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
    42
  NIL  :: "'a item" where
20801
d3616b4abe1b proper import of Main HOL;
wenzelm
parents: 20770
diff changeset
    43
  "NIL = In0(Numb(0))"
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    44
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
    45
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
    46
  CONS :: "['a item, 'a item] => 'a item" where
20801
d3616b4abe1b proper import of Main HOL;
wenzelm
parents: 20770
diff changeset
    47
  "CONS M N = In1(Scons M N)"
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    48
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 23281
diff changeset
    49
inductive_set
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 23281
diff changeset
    50
  list :: "'a item set => 'a item set"
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 23281
diff changeset
    51
  for A :: "'a item set"
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 23281
diff changeset
    52
  where
13079
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
    53
    NIL_I:  "NIL: list A"
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 23281
diff changeset
    54
  | CONS_I: "[| a: A;  M: list A |] ==> CONS a M : list A"
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    55
5977
9f0c8869cf71 tidied up list definitions, using type 'a option instead of
paulson
parents: 5191
diff changeset
    56
9f0c8869cf71 tidied up list definitions, using type 'a option instead of
paulson
parents: 5191
diff changeset
    57
typedef (List)
20801
d3616b4abe1b proper import of Main HOL;
wenzelm
parents: 20770
diff changeset
    58
    'a list = "list(range Leaf) :: 'a item set" 
13079
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
    59
  by (blast intro: list.NIL_I)
5977
9f0c8869cf71 tidied up list definitions, using type 'a option instead of
paulson
parents: 5191
diff changeset
    60
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
    61
abbreviation "Case == Datatype.Case"
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
    62
abbreviation "Split == Datatype.Split"
20801
d3616b4abe1b proper import of Main HOL;
wenzelm
parents: 20770
diff changeset
    63
19736
wenzelm
parents: 18413
diff changeset
    64
definition
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
    65
  List_case :: "['b, ['a item, 'a item]=>'b, 'a item] => 'b" where
20801
d3616b4abe1b proper import of Main HOL;
wenzelm
parents: 20770
diff changeset
    66
  "List_case c d = Case(%x. c)(Split(d))"
5977
9f0c8869cf71 tidied up list definitions, using type 'a option instead of
paulson
parents: 5191
diff changeset
    67
  
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
    68
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
    69
  List_rec  :: "['a item, 'b, ['a item, 'a item, 'b]=>'b] => 'b" where
22267
ea31e6ea0e2e Adapted to changes in Transitive_Closure theory.
berghofe
parents: 21404
diff changeset
    70
  "List_rec M c d = wfrec (pred_sexp^+)
20801
d3616b4abe1b proper import of Main HOL;
wenzelm
parents: 20770
diff changeset
    71
                           (%g. List_case c (%x y. d x y (g y))) M"
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    72
5977
9f0c8869cf71 tidied up list definitions, using type 'a option instead of
paulson
parents: 5191
diff changeset
    73
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    74
(* *********************************************************************** *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    75
(*                                                                         *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    76
(* Abstracting data type                                                   *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    77
(*                                                                         *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    78
(* *********************************************************************** *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    79
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    80
(*Declaring the abstract list constructors*)
13079
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
    81
23235
eb365b39b36d authentic syntax for List.append
haftmann
parents: 23029
diff changeset
    82
(*<*)no_translations
20801
d3616b4abe1b proper import of Main HOL;
wenzelm
parents: 20770
diff changeset
    83
  "[x, xs]" == "x#[xs]"
d3616b4abe1b proper import of Main HOL;
wenzelm
parents: 20770
diff changeset
    84
  "[x]" == "x#[]"
d3616b4abe1b proper import of Main HOL;
wenzelm
parents: 20770
diff changeset
    85
no_syntax
d3616b4abe1b proper import of Main HOL;
wenzelm
parents: 20770
diff changeset
    86
  Nil :: "'a list"  ("[]")
23235
eb365b39b36d authentic syntax for List.append
haftmann
parents: 23029
diff changeset
    87
  Cons :: "'a \<Rightarrow> 'a list \<Rightarrow> 'a list"  (infixr "#" 65)(*>*)
20801
d3616b4abe1b proper import of Main HOL;
wenzelm
parents: 20770
diff changeset
    88
19736
wenzelm
parents: 18413
diff changeset
    89
definition
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
    90
  Nil       :: "'a list"                               ("[]") where
19736
wenzelm
parents: 18413
diff changeset
    91
   "Nil  = Abs_List(NIL)"
13079
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
    92
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
    93
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
    94
  "Cons"       :: "['a, 'a list] => 'a list"           (infixr "#" 65) where
19736
wenzelm
parents: 18413
diff changeset
    95
   "x#xs = Abs_List(CONS (Leaf x)(Rep_List xs))"
13079
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
    96
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
    97
definition
13079
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
    98
  (* list Recursion -- the trancl is Essential; see list.ML *)
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
    99
  list_rec  :: "['a list, 'b, ['a, 'a list, 'b]=>'b] => 'b" where
19736
wenzelm
parents: 18413
diff changeset
   100
   "list_rec l c d =
13079
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   101
      List_rec(Rep_List l) c (%x y r. d(inv Leaf x)(Abs_List y) r)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   102
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   103
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   104
  list_case :: "['b, ['a, 'a list]=>'b, 'a list] => 'b" where
19736
wenzelm
parents: 18413
diff changeset
   105
   "list_case a f xs = list_rec xs a (%x xs r. f x xs)"
14653
0848ab6fe5fc constdefs: proper order;
wenzelm
parents: 13612
diff changeset
   106
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   107
(* list Enumeration *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   108
translations
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   109
  "[x, xs]" == "x#[xs]"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   110
  "[x]"     == "x#[]"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   111
20770
2c583720436e fixed translations: CONST;
wenzelm
parents: 19736
diff changeset
   112
  "case xs of [] => a | y#ys => b" == "CONST list_case(a, %y ys. b, xs)"
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   113
20770
2c583720436e fixed translations: CONST;
wenzelm
parents: 19736
diff changeset
   114
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   115
(* *********************************************************************** *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   116
(*                                                                         *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   117
(* Generalized Map Functionals                                             *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   118
(*                                                                         *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   119
(* *********************************************************************** *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   120
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   121
  
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   122
(* Generalized Map Functionals *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   123
19736
wenzelm
parents: 18413
diff changeset
   124
definition
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   125
  Rep_map   :: "('b => 'a item) => ('b list => 'a item)" where
19736
wenzelm
parents: 18413
diff changeset
   126
   "Rep_map f xs = list_rec xs  NIL(%x l r. CONS(f x) r)"
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   127
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   128
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   129
  Abs_map   :: "('a item => 'b) => 'a item => 'b list" where
19736
wenzelm
parents: 18413
diff changeset
   130
   "Abs_map g M  = List_rec M Nil (%N L r. g(N)#r)"
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   131
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   132
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   133
(**** Function definitions ****)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   134
19736
wenzelm
parents: 18413
diff changeset
   135
definition
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   136
  null      :: "'a list => bool" where
19736
wenzelm
parents: 18413
diff changeset
   137
  "null xs  = list_rec xs True (%x xs r. False)"
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   138
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   139
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   140
  hd        :: "'a list => 'a" where
19736
wenzelm
parents: 18413
diff changeset
   141
  "hd xs    = list_rec xs (@x. True) (%x xs r. x)"
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   142
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   143
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   144
  tl        :: "'a list => 'a list" where
19736
wenzelm
parents: 18413
diff changeset
   145
  "tl xs    = list_rec xs (@xs. True) (%x xs r. xs)"
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   146
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   147
definition
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   148
  (* a total version of tl: *)
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   149
  ttl       :: "'a list => 'a list" where
19736
wenzelm
parents: 18413
diff changeset
   150
  "ttl xs   = list_rec xs [] (%x xs r. xs)"
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   151
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 23281
diff changeset
   152
(*<*)no_syntax
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 23281
diff changeset
   153
    member :: "'a \<Rightarrow> 'a list \<Rightarrow> bool" (infixl "mem" 55)(*>*)
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   154
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   155
  member :: "['a, 'a list] => bool"    (infixl "mem" 55) where
19736
wenzelm
parents: 18413
diff changeset
   156
  "x mem xs = list_rec xs False (%y ys r. if y=x then True else r)"
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   157
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   158
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   159
  list_all  :: "('a => bool) => ('a list => bool)" where
19736
wenzelm
parents: 18413
diff changeset
   160
  "list_all P xs = list_rec xs True(%x l r. P(x) & r)"
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   161
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   162
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   163
  map       :: "('a=>'b) => ('a list => 'b list)" where
19736
wenzelm
parents: 18413
diff changeset
   164
  "map f xs = list_rec xs [] (%x l r. f(x)#r)"
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   165
23235
eb365b39b36d authentic syntax for List.append
haftmann
parents: 23029
diff changeset
   166
(*<*)no_syntax
eb365b39b36d authentic syntax for List.append
haftmann
parents: 23029
diff changeset
   167
  "\<^const>List.append" :: "'a list => 'a list => 'a list" (infixr "@" 65)(*>*)
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   168
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   169
  append    :: "['a list, 'a list] => 'a list"   (infixr "@" 65) where
19736
wenzelm
parents: 18413
diff changeset
   170
  "xs@ys = list_rec xs ys (%x l r. x#r)"
5977
9f0c8869cf71 tidied up list definitions, using type 'a option instead of
paulson
parents: 5191
diff changeset
   171
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   172
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   173
  filter    :: "['a => bool, 'a list] => 'a list" where
19736
wenzelm
parents: 18413
diff changeset
   174
  "filter P xs = list_rec xs []  (%x xs r. if P(x)then x#r else r)"
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   175
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   176
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   177
  foldl     :: "[['b,'a] => 'b, 'b, 'a list] => 'b" where
19736
wenzelm
parents: 18413
diff changeset
   178
  "foldl f a xs = list_rec xs (%a. a)(%x xs r.%a. r(f a x))(a)"
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   179
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   180
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   181
  foldr     :: "[['a,'b] => 'b, 'b, 'a list] => 'b" where
19736
wenzelm
parents: 18413
diff changeset
   182
  "foldr f a xs     = list_rec xs a (%x xs r. (f x r))"
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   183
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   184
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   185
  length    :: "'a list => nat" where
19736
wenzelm
parents: 18413
diff changeset
   186
  "length xs = list_rec xs 0 (%x xs r. Suc r)"
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   187
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   188
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   189
  drop      :: "['a list,nat] => 'a list" where
19736
wenzelm
parents: 18413
diff changeset
   190
  "drop t n = (nat_rec(%x. x)(%m r xs. r(ttl xs)))(n)(t)"
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   191
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   192
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   193
  copy      :: "['a, nat] => 'a list"  where     (* make list of n copies of x *)
19736
wenzelm
parents: 18413
diff changeset
   194
  "copy t   = nat_rec [] (%m xs. t # xs)"
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   195
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   196
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   197
  flat      :: "'a list list => 'a list" where
19736
wenzelm
parents: 18413
diff changeset
   198
  "flat     = foldr (op @) []"
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   199
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   200
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   201
  nth       :: "[nat, 'a list] => 'a" where
19736
wenzelm
parents: 18413
diff changeset
   202
  "nth      = nat_rec hd (%m r xs. r(tl xs))"
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   203
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   204
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   205
  rev       :: "'a list => 'a list" where
19736
wenzelm
parents: 18413
diff changeset
   206
  "rev xs   = list_rec xs [] (%x xs xsa. xsa @ [x])"
5977
9f0c8869cf71 tidied up list definitions, using type 'a option instead of
paulson
parents: 5191
diff changeset
   207
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   208
(* miscellaneous definitions *)
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   209
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   210
  zipWith   :: "['a * 'b => 'c, 'a list * 'b list] => 'c list" where
19736
wenzelm
parents: 18413
diff changeset
   211
  "zipWith f S = (list_rec (fst S)  (%T.[])
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   212
                            (%x xs r. %T. if null T then [] 
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   213
                                          else f(x,hd T) # r(tl T)))(snd(S))"
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   214
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   215
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   216
  zip       :: "'a list * 'b list => ('a*'b) list" where
19736
wenzelm
parents: 18413
diff changeset
   217
  "zip      = zipWith  (%s. s)"
14653
0848ab6fe5fc constdefs: proper order;
wenzelm
parents: 13612
diff changeset
   218
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   219
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 20820
diff changeset
   220
  unzip     :: "('a*'b) list => ('a list * 'b list)" where
19736
wenzelm
parents: 18413
diff changeset
   221
  "unzip    = foldr(% (a,b)(c,d).(a#c,b#d))([],[])"
5977
9f0c8869cf71 tidied up list definitions, using type 'a option instead of
paulson
parents: 5191
diff changeset
   222
9f0c8869cf71 tidied up list definitions, using type 'a option instead of
paulson
parents: 5191
diff changeset
   223
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   224
consts take      :: "['a list,nat] => 'a list"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   225
primrec
13079
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   226
  take_0:  "take xs 0 = []"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   227
  take_Suc: "take xs (Suc n) = list_case [] (%x l. x # take l n) xs"
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   228
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   229
consts enum      :: "[nat,nat] => nat list"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   230
primrec
13079
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   231
  enum_0:   "enum i 0 = []"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   232
  enum_Suc: "enum i (Suc j) = (if i <= j then enum i j @ [j] else [])"
5977
9f0c8869cf71 tidied up list definitions, using type 'a option instead of
paulson
parents: 5191
diff changeset
   233
9f0c8869cf71 tidied up list definitions, using type 'a option instead of
paulson
parents: 5191
diff changeset
   234
20801
d3616b4abe1b proper import of Main HOL;
wenzelm
parents: 20770
diff changeset
   235
no_translations
23281
e26ec695c9b3 changed filter syntax from : to <-
nipkow
parents: 23235
diff changeset
   236
  "[x\<leftarrow>xs . P]" == "filter (%x. P) xs"
20801
d3616b4abe1b proper import of Main HOL;
wenzelm
parents: 20770
diff changeset
   237
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   238
syntax
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   239
  (* Special syntax for list_all and filter *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   240
  "@Alls"       :: "[idt, 'a list, bool] => bool"        ("(2Alls _:_./ _)" 10)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   241
5977
9f0c8869cf71 tidied up list definitions, using type 'a option instead of
paulson
parents: 5191
diff changeset
   242
translations
23281
e26ec695c9b3 changed filter syntax from : to <-
nipkow
parents: 23235
diff changeset
   243
  "[x\<leftarrow>xs. P]" == "CONST filter(%x. P) xs"
20770
2c583720436e fixed translations: CONST;
wenzelm
parents: 19736
diff changeset
   244
  "Alls x:xs. P" == "CONST list_all(%x. P)xs"
5977
9f0c8869cf71 tidied up list definitions, using type 'a option instead of
paulson
parents: 5191
diff changeset
   245
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   246
13079
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   247
lemma ListI: "x : list (range Leaf) ==> x : List"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   248
by (simp add: List_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   249
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   250
lemma ListD: "x : List ==> x : list (range Leaf)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   251
by (simp add: List_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   252
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   253
lemma list_unfold: "list(A) = usum {Numb(0)} (uprod A (list(A)))"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   254
  by (fast intro!: list.intros [unfolded NIL_def CONS_def]
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   255
           elim: list.cases [unfolded NIL_def CONS_def])
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   256
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   257
(*This justifies using list in other recursive type definitions*)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   258
lemma list_mono: "A<=B ==> list(A) <= list(B)"
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 23281
diff changeset
   259
apply (rule subsetI)
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 23281
diff changeset
   260
apply (erule list.induct)
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 23281
diff changeset
   261
apply (auto intro!: list.intros)
13079
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   262
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   263
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   264
(*Type checking -- list creates well-founded sets*)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   265
lemma list_sexp: "list(sexp) <= sexp"
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 23281
diff changeset
   266
apply (rule subsetI)
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 23281
diff changeset
   267
apply (erule list.induct)
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 23281
diff changeset
   268
apply (unfold NIL_def CONS_def)
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 23281
diff changeset
   269
apply (auto intro: sexp.intros sexp_In0I sexp_In1I)
13079
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   270
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   271
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   272
(* A <= sexp ==> list(A) <= sexp *)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   273
lemmas list_subset_sexp = subset_trans [OF list_mono list_sexp] 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   274
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   275
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   276
(*Induction for the type 'a list *)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   277
lemma list_induct:
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   278
    "[| P(Nil);    
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   279
        !!x xs. P(xs) ==> P(x # xs) |]  ==> P(l)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   280
apply (unfold Nil_def Cons_def) 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   281
apply (rule Rep_List_inverse [THEN subst])
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   282
			 (*types force good instantiation*)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   283
apply (rule Rep_List [unfolded List_def, THEN list.induct], simp)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   284
apply (erule Abs_List_inverse [unfolded List_def, THEN subst], blast) 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   285
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   286
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   287
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   288
(*** Isomorphisms ***)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   289
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   290
lemma inj_on_Abs_list: "inj_on Abs_List (list(range Leaf))"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   291
apply (rule inj_on_inverseI)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   292
apply (erule Abs_List_inverse [unfolded List_def])
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   293
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   294
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   295
(** Distinctness of constructors **)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   296
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   297
lemma CONS_not_NIL [iff]: "CONS M N ~= NIL"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   298
by (simp add: NIL_def CONS_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   299
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   300
lemmas NIL_not_CONS [iff] = CONS_not_NIL [THEN not_sym]
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   301
lemmas CONS_neq_NIL = CONS_not_NIL [THEN notE, standard]
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   302
lemmas NIL_neq_CONS = sym [THEN CONS_neq_NIL]
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   303
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   304
lemma Cons_not_Nil [iff]: "x # xs ~= Nil"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   305
apply (unfold Nil_def Cons_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   306
apply (rule CONS_not_NIL [THEN inj_on_Abs_list [THEN inj_on_contraD]])
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   307
apply (simp_all add: list.intros rangeI Rep_List [unfolded List_def])
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   308
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   309
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   310
lemmas Nil_not_Cons [iff] = Cons_not_Nil [THEN not_sym, standard]
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   311
lemmas Cons_neq_Nil = Cons_not_Nil [THEN notE, standard]
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   312
lemmas Nil_neq_Cons = sym [THEN Cons_neq_Nil]
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   313
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   314
(** Injectiveness of CONS and Cons **)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   315
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   316
lemma CONS_CONS_eq [iff]: "(CONS K M)=(CONS L N) = (K=L & M=N)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   317
by (simp add: CONS_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   318
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   319
(*For reasoning about abstract list constructors*)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   320
declare Rep_List [THEN ListD, intro] ListI [intro]
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   321
declare list.intros [intro,simp]
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   322
declare Leaf_inject [dest!]
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   323
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   324
lemma Cons_Cons_eq [iff]: "(x#xs=y#ys) = (x=y & xs=ys)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   325
apply (simp add: Cons_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   326
apply (subst Abs_List_inject)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   327
apply (auto simp add: Rep_List_inject)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   328
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   329
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   330
lemmas Cons_inject2 = Cons_Cons_eq [THEN iffD1, THEN conjE, standard]
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   331
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   332
lemma CONS_D: "CONS M N: list(A) ==> M: A & N: list(A)"
18413
50c0c118e96d removed obsolete/unused setup_induction;
wenzelm
parents: 16417
diff changeset
   333
  by (induct L == "CONS M N" set: list) auto
13079
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   334
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   335
lemma sexp_CONS_D: "CONS M N: sexp ==> M: sexp & N: sexp"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   336
apply (simp add: CONS_def In1_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   337
apply (fast dest!: Scons_D)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   338
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   339
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   340
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   341
(*Reasoning about constructors and their freeness*)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   342
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   343
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   344
lemma not_CONS_self: "N: list(A) ==> !M. N ~= CONS M N"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   345
by (erule list.induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   346
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   347
lemma not_Cons_self2: "\<forall>x. l ~= x#l"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   348
by (induct_tac "l" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   349
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   350
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   351
lemma neq_Nil_conv2: "(xs ~= []) = (\<exists>y ys. xs = y#ys)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   352
by (induct_tac "xs" rule: list_induct, auto)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   353
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   354
(** Conversion rules for List_case: case analysis operator **)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   355
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   356
lemma List_case_NIL [simp]: "List_case c h NIL = c"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   357
by (simp add: List_case_def NIL_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   358
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   359
lemma List_case_CONS [simp]: "List_case c h (CONS M N) = h M N"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   360
by (simp add: List_case_def CONS_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   361
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   362
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   363
(*** List_rec -- by wf recursion on pred_sexp ***)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   364
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   365
(* The trancl(pred_sexp) is essential because pred_sexp_CONS_I1,2 would not
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   366
   hold if pred_sexp^+ were changed to pred_sexp. *)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   367
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   368
lemma List_rec_unfold_lemma:
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   369
     "(%M. List_rec M c d) == 
22267
ea31e6ea0e2e Adapted to changes in Transitive_Closure theory.
berghofe
parents: 21404
diff changeset
   370
      wfrec (pred_sexp^+) (%g. List_case c (%x y. d x y (g y)))"
13079
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   371
by (simp add: List_rec_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   372
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   373
lemmas List_rec_unfold = 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   374
    def_wfrec [OF List_rec_unfold_lemma wf_pred_sexp [THEN wf_trancl], 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   375
               standard]
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   376
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   377
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   378
(** pred_sexp lemmas **)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   379
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   380
lemma pred_sexp_CONS_I1: 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   381
    "[| M: sexp;  N: sexp |] ==> (M, CONS M N) : pred_sexp^+"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   382
by (simp add: CONS_def In1_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   383
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   384
lemma pred_sexp_CONS_I2: 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   385
    "[| M: sexp;  N: sexp |] ==> (N, CONS M N) : pred_sexp^+"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   386
by (simp add: CONS_def In1_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   387
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   388
lemma pred_sexp_CONS_D: 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   389
    "(CONS M1 M2, N) : pred_sexp^+ ==>  
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   390
     (M1,N) : pred_sexp^+ & (M2,N) : pred_sexp^+"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   391
apply (frule pred_sexp_subset_Sigma [THEN trancl_subset_Sigma, THEN subsetD])
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   392
apply (blast dest!: sexp_CONS_D intro: pred_sexp_CONS_I1 pred_sexp_CONS_I2 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   393
                    trans_trancl [THEN transD])
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   394
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   395
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   396
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   397
(** Conversion rules for List_rec **)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   398
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   399
lemma List_rec_NIL [simp]: "List_rec NIL c h = c"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   400
apply (rule List_rec_unfold [THEN trans])
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   401
apply (simp add: List_case_NIL)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   402
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   403
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   404
lemma List_rec_CONS [simp]:
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   405
     "[| M: sexp;  N: sexp |] 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   406
      ==> List_rec (CONS M N) c h = h M N (List_rec N c h)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   407
apply (rule List_rec_unfold [THEN trans])
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   408
apply (simp add: pred_sexp_CONS_I2)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   409
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   410
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   411
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   412
(*** list_rec -- by List_rec ***)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   413
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   414
lemmas Rep_List_in_sexp =
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   415
    subsetD [OF range_Leaf_subset_sexp [THEN list_subset_sexp]
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   416
                Rep_List [THEN ListD]] 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   417
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   418
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   419
lemma list_rec_Nil [simp]: "list_rec Nil c h = c"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   420
by (simp add: list_rec_def ListI [THEN Abs_List_inverse] Nil_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   421
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   422
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   423
lemma list_rec_Cons [simp]: "list_rec (a#l) c h = h a l (list_rec l c h)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   424
by (simp add: list_rec_def ListI [THEN Abs_List_inverse] Cons_def
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   425
              Rep_List_inverse Rep_List [THEN ListD] inj_Leaf Rep_List_in_sexp)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   426
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   427
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   428
(*Type checking.  Useful?*)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   429
lemma List_rec_type:
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   430
     "[| M: list(A);      
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   431
         A<=sexp;         
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   432
         c: C(NIL);       
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   433
         !!x y r. [| x: A;  y: list(A);  r: C(y) |] ==> h x y r: C(CONS x y)  
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   434
      |] ==> List_rec M c h : C(M :: 'a item)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   435
apply (erule list.induct, simp) 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   436
apply (insert list_subset_sexp) 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   437
apply (subst List_rec_CONS, blast+)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   438
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   439
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   440
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   441
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   442
(** Generalized map functionals **)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   443
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   444
lemma Rep_map_Nil [simp]: "Rep_map f Nil = NIL"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   445
by (simp add: Rep_map_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   446
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   447
lemma Rep_map_Cons [simp]: 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   448
    "Rep_map f(x#xs) = CONS(f x)(Rep_map f xs)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   449
by (simp add: Rep_map_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   450
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   451
lemma Rep_map_type: "(!!x. f(x): A) ==> Rep_map f xs: list(A)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   452
apply (simp add: Rep_map_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   453
apply (rule list_induct, auto)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   454
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   455
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   456
lemma Abs_map_NIL [simp]: "Abs_map g NIL = Nil"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   457
by (simp add: Abs_map_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   458
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   459
lemma Abs_map_CONS [simp]: 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   460
    "[| M: sexp;  N: sexp |] ==> Abs_map g (CONS M N) = g(M) # Abs_map g N"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   461
by (simp add: Abs_map_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   462
19736
wenzelm
parents: 18413
diff changeset
   463
(*Eases the use of primitive recursion.*)
13079
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   464
lemma def_list_rec_NilCons:
19736
wenzelm
parents: 18413
diff changeset
   465
    "[| !!xs. f(xs) = list_rec xs c h  |] 
13079
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   466
     ==> f [] = c & f(x#xs) = h x xs (f xs)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   467
by simp 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   468
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   469
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   470
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   471
lemma Abs_map_inverse:
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   472
     "[| M: list(A);  A<=sexp;  !!z. z: A ==> f(g(z)) = z |]  
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   473
      ==> Rep_map f (Abs_map g M) = M"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   474
apply (erule list.induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   475
apply (insert list_subset_sexp) 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   476
apply (subst Abs_map_CONS, blast)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   477
apply blast 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   478
apply simp 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   479
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   480
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   481
(*Rep_map_inverse is obtained via Abs_Rep_map and map_ident*)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   482
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   483
(** list_case **)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   484
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   485
(* setting up rewrite sets *)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   486
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   487
text{*Better to have a single theorem with a conjunctive conclusion.*}
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   488
declare def_list_rec_NilCons [OF list_case_def, simp]
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   489
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   490
(** list_case **)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   491
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   492
lemma expand_list_case: 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   493
 "P(list_case a f xs) = ((xs=[] --> P a ) & (!y ys. xs=y#ys --> P(f y ys)))"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   494
by (induct_tac "xs" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   495
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   496
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   497
(**** Function definitions ****)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   498
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   499
declare def_list_rec_NilCons [OF null_def, simp]
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   500
declare def_list_rec_NilCons [OF hd_def, simp]
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   501
declare def_list_rec_NilCons [OF tl_def, simp]
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   502
declare def_list_rec_NilCons [OF ttl_def, simp]
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   503
declare def_list_rec_NilCons [OF append_def, simp]
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   504
declare def_list_rec_NilCons [OF member_def, simp]
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   505
declare def_list_rec_NilCons [OF map_def, simp]
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   506
declare def_list_rec_NilCons [OF filter_def, simp]
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   507
declare def_list_rec_NilCons [OF list_all_def, simp]
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   508
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   509
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   510
(** nth **)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   511
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   512
lemma def_nat_rec_0_eta:
19736
wenzelm
parents: 18413
diff changeset
   513
    "[| !!n. f = nat_rec c h |] ==> f(0) = c"
13079
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   514
by simp
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   515
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   516
lemma def_nat_rec_Suc_eta:
19736
wenzelm
parents: 18413
diff changeset
   517
    "[| !!n. f = nat_rec c h |] ==> f(Suc(n)) = h n (f n)"
13079
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   518
by simp
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   519
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   520
declare def_nat_rec_0_eta [OF nth_def, simp]
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   521
declare def_nat_rec_Suc_eta [OF nth_def, simp]
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   522
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   523
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   524
(** length **)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   525
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   526
lemma length_Nil [simp]: "length([]) = 0"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   527
by (simp add: length_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   528
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   529
lemma length_Cons [simp]: "length(a#xs) = Suc(length(xs))"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   530
by (simp add: length_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   531
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   532
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   533
(** @ - append **)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   534
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   535
lemma append_assoc [simp]: "(xs@ys)@zs = xs@(ys@zs)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   536
by (induct_tac "xs" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   537
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   538
lemma append_Nil2 [simp]: "xs @ [] = xs"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   539
by (induct_tac "xs" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   540
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   541
(** mem **)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   542
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   543
lemma mem_append [simp]: "x mem (xs@ys) = (x mem xs | x mem ys)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   544
by (induct_tac "xs" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   545
23281
e26ec695c9b3 changed filter syntax from : to <-
nipkow
parents: 23235
diff changeset
   546
lemma mem_filter [simp]: "x mem [x\<leftarrow>xs. P x ] = (x mem xs & P(x))"
13079
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   547
by (induct_tac "xs" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   548
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   549
(** list_all **)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   550
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   551
lemma list_all_True [simp]: "(Alls x:xs. True) = True"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   552
by (induct_tac "xs" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   553
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   554
lemma list_all_conj [simp]:
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   555
     "list_all p (xs@ys) = ((list_all p xs) & (list_all p ys))"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   556
by (induct_tac "xs" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   557
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   558
lemma list_all_mem_conv: "(Alls x:xs. P(x)) = (!x. x mem xs --> P(x))"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   559
apply (induct_tac "xs" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   560
apply blast 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   561
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   562
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   563
lemma nat_case_dist : "(! n. P n) = (P 0 & (! n. P (Suc n)))"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   564
apply auto
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   565
apply (induct_tac "n", auto)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   566
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   567
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   568
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   569
lemma alls_P_eq_P_nth: "(Alls u:A. P u) = (!n. n < length A --> P(nth n A))"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   570
apply (induct_tac "A" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   571
apply (rule trans)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   572
apply (rule_tac [2] nat_case_dist [symmetric], simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   573
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   574
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   575
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   576
lemma list_all_imp:
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   577
     "[| !x. P x --> Q x;  (Alls x:xs. P(x)) |] ==> (Alls x:xs. Q(x))"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   578
by (simp add: list_all_mem_conv)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   579
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   580
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   581
(** The functional "map" and the generalized functionals **)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   582
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   583
lemma Abs_Rep_map: 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   584
     "(!!x. f(x): sexp) ==>  
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   585
        Abs_map g (Rep_map f xs) = map (%t. g(f(t))) xs"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   586
apply (induct_tac "xs" rule: list_induct)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   587
apply (simp_all add: Rep_map_type list_sexp [THEN subsetD])
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   588
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   589
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   590
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   591
(** Additional mapping lemmas **)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   592
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   593
lemma map_ident [simp]: "map(%x. x)(xs) = xs"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   594
by (induct_tac "xs" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   595
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   596
lemma map_append [simp]: "map f (xs@ys) = map f xs  @ map f ys"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   597
by (induct_tac "xs" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   598
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   599
lemma map_compose: "map(f o g)(xs) = map f (map g xs)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   600
apply (simp add: o_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   601
apply (induct_tac "xs" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   602
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   603
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   604
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   605
lemma mem_map_aux1 [rule_format]:
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   606
     "x mem (map f q) --> (\<exists>y. y mem q & x = f y)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   607
by (induct_tac "q" rule: list_induct, simp_all, blast)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   608
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   609
lemma mem_map_aux2 [rule_format]: 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   610
     "(\<exists>y. y mem q & x = f y) --> x mem (map f q)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   611
by (induct_tac "q" rule: list_induct, auto)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   612
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   613
lemma mem_map: "x mem (map f q) = (\<exists>y. y mem q & x = f y)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   614
apply (rule iffI)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   615
apply (erule mem_map_aux1)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   616
apply (erule mem_map_aux2)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   617
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   618
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   619
lemma hd_append [rule_format]: "A ~= [] --> hd(A @ B) = hd(A)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   620
by (induct_tac "A" rule: list_induct, auto)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   621
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   622
lemma tl_append [rule_format]: "A ~= [] --> tl(A @ B) = tl(A) @ B"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   623
by (induct_tac "A" rule: list_induct, auto)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   624
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   625
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   626
(** take **)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   627
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   628
lemma take_Suc1 [simp]: "take [] (Suc x) = []"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   629
by simp
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   630
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   631
lemma take_Suc2 [simp]: "take(a#xs)(Suc x) = a#take xs x"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   632
by simp
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   633
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   634
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   635
(** drop **)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   636
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   637
lemma drop_0 [simp]: "drop xs 0 = xs"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   638
by (simp add: drop_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   639
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   640
lemma drop_Suc1 [simp]: "drop [] (Suc x) = []"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   641
apply (simp add: drop_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   642
apply (induct_tac "x", auto) 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   643
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   644
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   645
lemma drop_Suc2 [simp]: "drop(a#xs)(Suc x) = drop xs x"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   646
by (simp add: drop_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   647
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   648
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   649
(** copy **)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   650
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   651
lemma copy_0 [simp]: "copy x 0 = []"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   652
by (simp add: copy_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   653
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   654
lemma copy_Suc [simp]: "copy x (Suc y) = x # copy x y"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   655
by (simp add: copy_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   656
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   657
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   658
(** fold **)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   659
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   660
lemma foldl_Nil [simp]: "foldl f a [] = a"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   661
by (simp add: foldl_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   662
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   663
lemma foldl_Cons [simp]: "foldl f a(x#xs) = foldl f (f a x) xs"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   664
by (simp add: foldl_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   665
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   666
lemma foldr_Nil [simp]: "foldr f a [] = a"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   667
by (simp add: foldr_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   668
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   669
lemma foldr_Cons [simp]: "foldr f z(x#xs)  = f x (foldr f z xs)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   670
by (simp add: foldr_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   671
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   672
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   673
(** flat **)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   674
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   675
lemma flat_Nil [simp]: "flat [] = []"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   676
by (simp add: flat_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   677
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   678
lemma flat_Cons [simp]: "flat (x # xs) = x @ flat xs"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   679
by (simp add: flat_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   680
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   681
(** rev **)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   682
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   683
lemma rev_Nil [simp]: "rev [] = []"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   684
by (simp add: rev_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   685
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   686
lemma rev_Cons [simp]: "rev (x # xs) = rev xs @ [x]"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   687
by (simp add: rev_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   688
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   689
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   690
(** zip **)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   691
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   692
lemma zipWith_Cons_Cons [simp]:
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   693
     "zipWith f (a#as,b#bs)   = f(a,b) # zipWith f (as,bs)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   694
by (simp add: zipWith_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   695
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   696
lemma zipWith_Nil_Nil [simp]: "zipWith f ([],[])      = []"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   697
by (simp add: zipWith_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   698
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   699
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   700
lemma zipWith_Cons_Nil [simp]: "zipWith f (x,[])  = []"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   701
apply (simp add: zipWith_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   702
apply (induct_tac "x" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   703
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   704
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   705
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   706
lemma zipWith_Nil_Cons [simp]: "zipWith f ([],x) = []"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   707
by (simp add: zipWith_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   708
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   709
lemma unzip_Nil [simp]: "unzip [] = ([],[])"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   710
by (simp add: unzip_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   711
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   712
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   713
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   714
(** SOME LIST THEOREMS **)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   715
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   716
(* SQUIGGOL LEMMAS *)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   717
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   718
lemma map_compose_ext: "map(f o g) = ((map f) o (map g))"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   719
apply (simp add: o_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   720
apply (rule ext)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   721
apply (simp add: map_compose [symmetric] o_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   722
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   723
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   724
lemma map_flat: "map f (flat S) = flat(map (map f) S)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   725
by (induct_tac "S" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   726
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   727
lemma list_all_map_eq: "(Alls u:xs. f(u) = g(u)) --> map f xs = map g xs"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   728
by (induct_tac "xs" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   729
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   730
lemma filter_map_d: "filter p (map f xs) = map f (filter(p o f)(xs))"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   731
by (induct_tac "xs" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   732
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   733
lemma filter_compose: "filter p (filter q xs) = filter(%x. p x & q x) xs"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   734
by (induct_tac "xs" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   735
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   736
(* "filter(p, filter(q,xs)) = filter(q, filter(p,xs))",
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   737
   "filter(p, filter(p,xs)) = filter(p,xs)" BIRD's thms.*)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   738
 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   739
lemma filter_append [rule_format, simp]:
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   740
     "\<forall>B. filter p (A @ B) = (filter p A @ filter p B)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   741
by (induct_tac "A" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   742
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   743
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   744
(* inits(xs) == map(fst,splits(xs)), 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   745
 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   746
   splits([]) = []
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   747
   splits(a # xs) = <[],xs> @ map(%x. <a # fst(x),snd(x)>, splits(xs))
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   748
   (x @ y = z) = <x,y> mem splits(z)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   749
   x mem xs & y mem ys = <x,y> mem diag(xs,ys) *)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   750
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   751
lemma length_append: "length(xs@ys) = length(xs)+length(ys)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   752
by (induct_tac "xs" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   753
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   754
lemma length_map: "length(map f xs) = length(xs)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   755
by (induct_tac "xs" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   756
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   757
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   758
lemma take_Nil [simp]: "take [] n = []"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   759
by (induct_tac "n", simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   760
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   761
lemma take_take_eq [simp]: "\<forall>n. take (take xs n) n = take xs n"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   762
apply (induct_tac "xs" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   763
apply (rule allI)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   764
apply (induct_tac "n", auto)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   765
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   766
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   767
lemma take_take_Suc_eq1 [rule_format]:
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   768
     "\<forall>n. take (take xs(Suc(n+m))) n = take xs n"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   769
apply (induct_tac "xs" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   770
apply (rule allI)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   771
apply (induct_tac "n", auto)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   772
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   773
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   774
declare take_Suc [simp del]
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   775
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   776
lemma take_take_1: "take (take xs (n+m)) n = take xs n"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   777
apply (induct_tac "m")
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   778
apply (simp_all add: take_take_Suc_eq1)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   779
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   780
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   781
lemma take_take_Suc_eq2 [rule_format]:
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   782
     "\<forall>n. take (take xs n)(Suc(n+m)) = take xs n"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   783
apply (induct_tac "xs" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   784
apply (rule allI)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   785
apply (induct_tac "n", auto)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   786
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   787
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   788
lemma take_take_2: "take(take xs n)(n+m) = take xs n"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   789
apply (induct_tac "m")
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   790
apply (simp_all add: take_take_Suc_eq2)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   791
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   792
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   793
(* length(take(xs,n)) = min(n, length(xs)) *)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   794
(* length(drop(xs,n)) = length(xs) - n *)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   795
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   796
lemma drop_Nil [simp]: "drop  [] n  = []"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   797
by (induct_tac "n", auto)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   798
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   799
lemma drop_drop [rule_format]: "\<forall>xs. drop (drop xs m) n = drop xs(m+n)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   800
apply (induct_tac "m", auto) 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   801
apply (induct_tac "xs" rule: list_induct, auto) 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   802
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   803
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   804
lemma take_drop [rule_format]: "\<forall>xs. (take xs n) @ (drop xs n) = xs"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   805
apply (induct_tac "n", auto) 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   806
apply (induct_tac "xs" rule: list_induct, auto) 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   807
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   808
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   809
lemma copy_copy: "copy x n @ copy x m = copy x (n+m)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   810
by (induct_tac "n", auto)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   811
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   812
lemma length_copy: "length(copy x n)  = n"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   813
by (induct_tac "n", auto)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   814
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   815
lemma length_take [rule_format, simp]:
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   816
     "\<forall>xs. length(take xs n) = min (length xs) n"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   817
apply (induct_tac "n")
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   818
 apply auto
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   819
apply (induct_tac "xs" rule: list_induct)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   820
 apply auto
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   821
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   822
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   823
lemma length_take_drop: "length(take A k) + length(drop A k) = length(A)" 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   824
by (simp only: length_append [symmetric] take_drop)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   825
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   826
lemma take_append [rule_format]: "\<forall>A. length(A) = n --> take(A@B) n = A"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   827
apply (induct_tac "n")
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   828
apply (rule allI)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   829
apply (rule_tac [2] allI)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   830
apply (induct_tac "A" rule: list_induct)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   831
apply (induct_tac [3] "A" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   832
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   833
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   834
lemma take_append2 [rule_format]:
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   835
     "\<forall>A. length(A) = n --> take(A@B) (n+k) = A @ take B k"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   836
apply (induct_tac "n")
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   837
apply (rule allI)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   838
apply (rule_tac [2] allI)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   839
apply (induct_tac "A" rule: list_induct)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   840
apply (induct_tac [3] "A" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   841
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   842
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   843
lemma take_map [rule_format]: "\<forall>n. take (map f A) n = map f (take A n)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   844
apply (induct_tac "A" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   845
apply (rule allI)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   846
apply (induct_tac "n", simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   847
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   848
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   849
lemma drop_append [rule_format]: "\<forall>A. length(A) = n --> drop(A@B)n = B"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   850
apply (induct_tac "n")
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   851
apply (rule allI)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   852
apply (rule_tac [2] allI)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   853
apply (induct_tac "A" rule: list_induct)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   854
apply (induct_tac [3] "A" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   855
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   856
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   857
lemma drop_append2 [rule_format]:
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   858
     "\<forall>A. length(A) = n --> drop(A@B)(n+k) = drop B k"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   859
apply (induct_tac "n")
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   860
apply (rule allI)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   861
apply (rule_tac [2] allI)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   862
apply (induct_tac "A" rule: list_induct)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   863
apply (induct_tac [3] "A" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   864
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   865
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   866
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   867
lemma drop_all [rule_format]: "\<forall>A. length(A) = n --> drop A n = []"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   868
apply (induct_tac "n")
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   869
apply (rule allI)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   870
apply (rule_tac [2] allI)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   871
apply (induct_tac "A" rule: list_induct)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   872
apply (induct_tac [3] "A" rule: list_induct, auto)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   873
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   874
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   875
lemma drop_map [rule_format]: "\<forall>n. drop (map f A) n = map f (drop A n)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   876
apply (induct_tac "A" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   877
apply (rule allI)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   878
apply (induct_tac "n", simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   879
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   880
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   881
lemma take_all [rule_format]: "\<forall>A. length(A) = n --> take A n = A"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   882
apply (induct_tac "n")
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   883
apply (rule allI)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   884
apply (rule_tac [2] allI)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   885
apply (induct_tac "A" rule: list_induct)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   886
apply (induct_tac [3] "A" rule: list_induct, auto) 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   887
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   888
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   889
lemma foldl_single: "foldl f a [b] = f a b"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   890
by simp_all
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   891
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   892
lemma foldl_append [rule_format, simp]:
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   893
     "\<forall>a. foldl f a (A @ B) = foldl f (foldl f a A) B"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   894
by (induct_tac "A" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   895
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   896
lemma foldl_map [rule_format]:
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   897
     "\<forall>e. foldl f e (map g S) = foldl (%x y. f x (g y)) e S"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   898
by (induct_tac "S" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   899
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   900
lemma foldl_neutr_distr [rule_format]:
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   901
  assumes r_neutr: "\<forall>a. f a e = a" 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   902
      and r_neutl: "\<forall>a. f e a = a"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   903
      and assoc:   "\<forall>a b c. f a (f b c) = f(f a b) c"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   904
  shows "\<forall>y. f y (foldl f e A) = foldl f y A"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   905
apply (induct_tac "A" rule: list_induct)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   906
apply (simp_all add: r_neutr r_neutl, clarify) 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   907
apply (erule all_dupE) 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   908
apply (rule trans) 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   909
prefer 2 apply assumption
13612
55d32e76ef4e Adapted to new simplifier.
berghofe
parents: 13079
diff changeset
   910
apply (simp (no_asm_use) add: assoc [THEN spec, THEN spec, THEN spec, THEN sym])
55d32e76ef4e Adapted to new simplifier.
berghofe
parents: 13079
diff changeset
   911
apply simp
13079
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   912
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   913
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   914
lemma foldl_append_sym: 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   915
"[| !a. f a e = a; !a. f e a = a;           
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   916
    !a b c. f a (f b c) = f(f a b) c |]    
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   917
  ==> foldl f e (A @ B) = f(foldl f e A)(foldl f e B)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   918
apply (rule trans)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   919
apply (rule foldl_append)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   920
apply (rule sym) 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   921
apply (rule foldl_neutr_distr, auto)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   922
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   923
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   924
lemma foldr_append [rule_format, simp]:
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   925
     "\<forall>a. foldr f a (A @ B) = foldr f (foldr f a B) A"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   926
apply (induct_tac "A" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   927
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   928
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   929
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   930
lemma foldr_map [rule_format]: "\<forall>e. foldr f e (map g S) = foldr (f o g) e S"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   931
apply (simp add: o_def)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   932
apply (induct_tac "S" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   933
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   934
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   935
lemma foldr_Un_eq_UN: "foldr op Un {} S = (UN X: {t. t mem S}.X)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   936
by (induct_tac "S" rule: list_induct, auto)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   937
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   938
lemma foldr_neutr_distr:
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   939
     "[| !a. f e a = a; !a b c. f a (f b c) = f(f a b) c |]    
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   940
      ==> foldr f y S = f (foldr f e S) y"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   941
by (induct_tac "S" rule: list_induct, auto)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   942
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   943
lemma foldr_append2: 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   944
    "[| !a. f e a = a; !a b c. f a (f b c) = f(f a b) c |]
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   945
     ==> foldr f e (A @ B) = f (foldr f e A) (foldr f e B)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   946
apply auto
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   947
apply (rule foldr_neutr_distr, auto)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   948
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   949
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   950
lemma foldr_flat: 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   951
    "[| !a. f e a = a; !a b c. f a (f b c) = f(f a b) c |] ==>  
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   952
      foldr f e (flat S) = (foldr f e)(map (foldr f e) S)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   953
apply (induct_tac "S" rule: list_induct)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   954
apply (simp_all del: foldr_append add: foldr_append2)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   955
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   956
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   957
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   958
lemma list_all_map: "(Alls x:map f xs .P(x)) = (Alls x:xs.(P o f)(x))"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   959
by (induct_tac "xs" rule: list_induct, auto)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   960
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   961
lemma list_all_and: 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   962
     "(Alls x:xs. P(x)&Q(x)) = ((Alls x:xs. P(x))&(Alls x:xs. Q(x)))"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   963
by (induct_tac "xs" rule: list_induct, auto)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   964
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   965
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   966
lemma nth_map [rule_format]:
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   967
     "\<forall>i. i < length(A)  --> nth i (map f A) = f(nth i A)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   968
apply (induct_tac "A" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   969
apply (rule allI)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   970
apply (induct_tac "i", auto) 
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   971
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   972
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   973
lemma nth_app_cancel_right [rule_format]:
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   974
     "\<forall>i. i < length(A)  --> nth i(A@B) = nth i A"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   975
apply (induct_tac "A" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   976
apply (rule allI)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   977
apply (induct_tac "i", simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   978
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   979
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   980
lemma nth_app_cancel_left [rule_format]:
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   981
     "\<forall>n. n = length(A) --> nth(n+i)(A@B) = nth i B"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   982
by (induct_tac "A" rule: list_induct, simp_all)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   983
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   984
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   985
(** flat **)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   986
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   987
lemma flat_append [simp]: "flat(xs@ys) = flat(xs) @ flat(ys)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   988
by (induct_tac "xs" rule: list_induct, auto)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   989
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   990
lemma filter_flat: "filter p (flat S) = flat(map (filter p) S)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   991
by (induct_tac "S" rule: list_induct, auto)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   992
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   993
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   994
(** rev **)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   995
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   996
lemma rev_append [simp]: "rev(xs@ys) = rev(ys) @ rev(xs)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   997
by (induct_tac "xs" rule: list_induct, auto)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   998
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
   999
lemma rev_rev_ident [simp]: "rev(rev l) = l"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
  1000
by (induct_tac "l" rule: list_induct, auto)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
  1001
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
  1002
lemma rev_flat: "rev(flat ls) = flat (map rev (rev ls))"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
  1003
by (induct_tac "ls" rule: list_induct, auto)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
  1004
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
  1005
lemma rev_map_distrib: "rev(map f l) = map f (rev l)"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
  1006
by (induct_tac "l" rule: list_induct, auto)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
  1007
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
  1008
lemma foldl_rev: "foldl f b (rev l) = foldr (%x y. f y x) b l"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
  1009
by (induct_tac "l" rule: list_induct, auto)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
  1010
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
  1011
lemma foldr_rev: "foldr f b (rev l) = foldl (%x y. f y x) b l"
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
  1012
apply (rule sym)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
  1013
apply (rule trans)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
  1014
apply (rule_tac [2] foldl_rev, simp)
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
  1015
done
e7738aa7267f conversion of Induct/{Slist,Sexp} to Isar scripts
paulson
parents: 12169
diff changeset
  1016
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
  1017
end