src/Tools/isac/ProgLang/ListC.thy
author Walther Neuper <neuper@ist.tugraz.at>
Wed, 25 Aug 2010 16:20:07 +0200
branchisac-update-Isa09-2
changeset 37947 22235e4dbe5f
parent 37944 src/Tools/isac/Scripts/ListG.thy@18794c7f43e2
child 37965 9c11005c33b8
permissions -rw-r--r--
renamed isac's directories and Build_Isac.thy

Scripts --> ProgLang
ME --> Interpret
IsacKnowledge --> Knowledge
neuper@37947
     1
(* use_thy_only"../ProgLang/ListC";
neuper@37947
     2
   use_thy_only"ProgLang/ListC";
neuper@37947
     3
   use_thy"ProgLang/ListC";
neuper@37906
     4
neuper@37947
     5
   use_thy_only"ListC";
neuper@37906
     6
   W.N. 8.01
neuper@37906
     7
   attaches identifiers to definition of listfuns,
neuper@37906
     8
   for storing them in list_rls
neuper@37906
     9
neuper@37906
    10
WN.29.4.03: 
neuper@37906
    11
*)
neuper@37906
    12
neuper@37947
    13
theory ListC imports Complex_Main
neuper@37906
    14
uses ("library.sml")("calcelems.sml")
neuper@37947
    15
("ProgLang/term.sml")("ProgLang/calculate.sml")
neuper@37947
    16
("ProgLang/rewrite.sml")
neuper@37906
    17
begin
neuper@37906
    18
use "library.sml"        (*indent,...*)
neuper@37906
    19
use "calcelems.sml"      (*str_of_type, Thm,...*)
neuper@37947
    20
use "ProgLang/term.sml"  (*num_str,...*)
neuper@37947
    21
use "ProgLang/calculate.sml" (*???*)
neuper@37947
    22
use "ProgLang/rewrite.sml"   (*?*** At command "end" (line 205../ListC.thy*)
neuper@37906
    23
neuper@37906
    24
text {* 'nat' in List.thy replaced by 'real' *}
neuper@37906
    25
neuper@37906
    26
primrec length_'   :: "'a list => real"
neuper@37906
    27
where
neuper@37906
    28
  LENGTH_NIL:	"length_' [] = 0"     (*length: 'a list => nat*)
neuper@37906
    29
| LENGTH_CONS: "length_' (x#xs) = 1 + length_' xs"
neuper@37906
    30
neuper@37906
    31
primrec del :: "['a list, 'a] => 'a list"
neuper@37906
    32
where
neuper@37906
    33
  del_base: "del [] x = []"
neuper@37906
    34
| del_rec:  "del (y#ys) x = (if x = y then ys else y#(del ys x))"
neuper@37906
    35
neuper@37906
    36
definition
neuper@37906
    37
  list_diff :: "['a list, 'a list] => 'a list"         (* as -- bs *)
neuper@37906
    38
              ("(_ --/ _)" [66, 66] 65)
neuper@37906
    39
  where "a -- b == foldl del a b"
neuper@37906
    40
  
neuper@37906
    41
consts nth_' ::  "[real, 'a list] => 'a"
neuper@37906
    42
axioms
neuper@37906
    43
 (*** more than one non-variable in pattern in "nth_ 1 [x] = x"--*)
neuper@37906
    44
  NTH_NIL:      "nth_' 1 (x#xs) = x"
neuper@37906
    45
(*  NTH_CONS:     "nth_' n (x#xs) = nth_' (n+ -1) xs"  *)
neuper@37906
    46
neuper@37906
    47
(*rewriter does not reach base case   ......    ;
neuper@37906
    48
  the condition involves another rule set (erls, eval_binop in Atools):*)
neuper@37906
    49
  NTH_CONS:     "1 < n ==> nth_' n (x#xs) = nth_' (n+ - 1) xs"
neuper@37906
    50
neuper@37906
    51
(*primrec from Isabelle/src/HOL/List.thy -- def.twice not allowed*)
neuper@37906
    52
(*primrec*)
neuper@37906
    53
  hd_thm:	"hd(x#xs) = x"
neuper@37906
    54
(*primrec*)
neuper@37906
    55
  tl_Nil:	"tl([])   = []"
neuper@37906
    56
  tl_Cons:		"tl(x#xs) = xs"
neuper@37906
    57
(*primrec*)
neuper@37906
    58
  null_Nil:	"null([])   = True"
neuper@37906
    59
  null_Cons:	"null(x#xs) = False"
neuper@37906
    60
(*primrec*)
neuper@37906
    61
  LAST:	"last(x#xs) = (if xs=[] then x else last xs)"
neuper@37906
    62
(*primrec*)
neuper@37906
    63
  butlast_Nil:	"butlast []    = []"
neuper@37906
    64
  butlast_Cons:	"butlast(x#xs) = (if xs=[] then [] else x#butlast xs)"
neuper@37906
    65
(*primrec*)
neuper@37906
    66
  mem_Nil:	"x mem []     = False"
neuper@37906
    67
  mem_Cons:	"x mem (y#ys) = (if y=x then True else x mem ys)"
neuper@37906
    68
(*primrec-------already named---
neuper@37906
    69
  "set [] = {}"
neuper@37906
    70
  "set (x#xs) = insert x (set xs)"
neuper@37906
    71
  primrec
neuper@37906
    72
  list_all_Nil  "list_all P [] = True"
neuper@37906
    73
  list_all_Cons "list_all P (x#xs) = (P(x) & list_all P xs)"
neuper@37906
    74
----------------*)
neuper@37906
    75
(*primrec*)
neuper@37906
    76
  map_Nil:	"map f []     = []"
neuper@37906
    77
  map_Cons:	"map f (x#xs) = f(x)#map f xs"
neuper@37906
    78
(*primrec*)
neuper@37906
    79
  append_Nil:  "[]    @ys = ys"
neuper@37906
    80
  append_Cons: "(x#xs)@ys = x#(xs@ys)"
neuper@37906
    81
(*primrec*)
neuper@37906
    82
  rev_Nil:	"rev([])   = []"
neuper@37906
    83
  rev_Cons:	"rev(x#xs) = rev(xs) @ [x]"
neuper@37906
    84
(*primrec*)
neuper@37906
    85
  filter_Nil:	"filter P []     = []"
neuper@37906
    86
  filter_Cons:	"filter P (x#xs) =(if P x then x#filter P xs else filter P xs)"
neuper@37906
    87
(*primrec-------already named---
neuper@37906
    88
  foldl_Nil  "foldl f a [] = a"
neuper@37906
    89
  foldl_Cons "foldl f a (x#xs) = foldl f (f a x) xs"
neuper@37906
    90
----------------*)
neuper@37906
    91
(*primrec*)
neuper@37906
    92
  foldr_Nil:	"foldr f [] a     = a"
neuper@37906
    93
  foldr_Cons:	"foldr f (x#xs) a = f x (foldr f xs a)"
neuper@37906
    94
(*primrec*)
neuper@37906
    95
  concat_Nil:	"concat([])   = []"
neuper@37906
    96
  concat_Cons:	"concat(x#xs) = x @ concat(xs)"
neuper@37906
    97
(*primrec-------already named---
neuper@37906
    98
  drop_Nil  "drop n [] = []"
neuper@37906
    99
  drop_Cons "drop n (x#xs) = (case n of 0 => x#xs | Suc(m) => drop m xs)"
neuper@37906
   100
  (* Warning: simpset does not contain this definition but separate theorems 
neuper@37906
   101
     for n=0 / n=Suc k*)
neuper@37906
   102
(*primrec*)
neuper@37906
   103
  take_Nil  "take n [] = []"
neuper@37906
   104
  take_Cons "take n (x#xs) = (case n of 0 => [] | Suc(m) => x # take m xs)"
neuper@37906
   105
  (* Warning: simpset does not contain this definition but separate theorems 
neuper@37906
   106
     for n=0 / n=Suc k*)
neuper@37906
   107
(*primrec*) 
neuper@37906
   108
  nth_Cons  "(x#xs)!n = (case n of 0 => x | (Suc k) => xs!k)"
neuper@37906
   109
  (* Warning: simpset does not contain this definition but separate theorems 
neuper@37906
   110
     for n=0 / n=Suc k*)
neuper@37906
   111
(*primrec*)
neuper@37906
   112
 "    [][i:=v] = []"
neuper@37906
   113
 "(x#xs)[i:=v] = (case i of 0     => v # xs 
neuper@37906
   114
			  | Suc j => x # xs[j:=v])"
neuper@37906
   115
----------------*)
neuper@37906
   116
(*primrec*)
neuper@37906
   117
  takeWhile_Nil:	"takeWhile P []     = []"
neuper@37906
   118
  takeWhile_Cons:
neuper@37906
   119
  "takeWhile P (x#xs) = (if P x then x#takeWhile P xs else [])"
neuper@37906
   120
(*primrec*)
neuper@37906
   121
  dropWhile_Nil:	"dropWhile P []     = []"
neuper@37906
   122
  dropWhile_Cons:
neuper@37906
   123
  "dropWhile P (x#xs) = (if P x then dropWhile P xs else x#xs)"
neuper@37906
   124
(*primrec*)
neuper@37906
   125
  zip_Nil:	"zip xs []     = []"
neuper@37906
   126
  zip_Cons:	"zip xs (y#ys) =(case xs of [] => [] | z#zs =>(z,y)#zip zs ys)"
neuper@37906
   127
  (* Warning: simpset does not contain this definition but separate theorems 
neuper@37906
   128
     for xs=[] / xs=z#zs *)
neuper@37906
   129
(*primrec
neuper@37906
   130
  upt_0   "[i..0(] = []"
neuper@37906
   131
  upt_Suc "[i..(Suc j)(] = (if i <= j then [i..j(] @ [j] else [])"
neuper@37906
   132
*)
neuper@37906
   133
(*primrec*)
neuper@37906
   134
  distinct_Nil:	"distinct []     = True"
neuper@37906
   135
  distinct_Cons:	"distinct (x#xs) = (x ~: set xs & distinct xs)"
neuper@37906
   136
(*primrec*)
neuper@37906
   137
  remdups_Nil:	"remdups [] = []"
neuper@37906
   138
  remdups_Cons:	"remdups (x#xs) =
neuper@37906
   139
		 (if x : set xs then remdups xs else x # remdups xs)"
neuper@37906
   140
(*primrec-------already named---
neuper@37906
   141
  replicate_0   "replicate  0      x = []"
neuper@37906
   142
  replicate_Suc "replicate (Suc n) x = x # replicate n x"
neuper@37906
   143
----------------*)
neuper@37906
   144
neuper@37906
   145
(** Lexicographic orderings on lists ...!!!**)
neuper@37906
   146
neuper@37947
   147
ML{* (*the former ListC.ML*)
neuper@37906
   148
(** rule set for evaluating listexpr in scripts **)
neuper@37906
   149
val list_rls = 
neuper@37906
   150
  Rls{id="list_rls",preconds = [], rew_ord = ("dummy_ord",dummy_ord), 
neuper@37906
   151
      erls = e_rls, srls = Erls, calc = [], (*asm_thm=[],*)
neuper@37906
   152
      rules = (*8.01: copied from*)
neuper@37906
   153
      [Thm ("refl", num_str refl),       (*'a<>b -> FALSE' by fun eval_equal*)
neuper@37906
   154
       Thm ("o_apply", num_str @{thm o_apply}),
neuper@37906
   155
neuper@37906
   156
       Thm ("NTH_CONS",num_str @{thm NTH_CONS}),(*erls for cond. in Atools.ML*)
neuper@37906
   157
       Thm ("NTH_NIL",num_str @{thm NTH_NIL}),
neuper@37906
   158
       Thm ("append_Cons",num_str @{thm append_Cons}),
neuper@37906
   159
       Thm ("append_Nil",num_str @{thm append_Nil}),
neuper@37906
   160
       Thm ("butlast_Cons",num_str @{thm butlast_Cons}),
neuper@37906
   161
       Thm ("butlast_Nil",num_str @{thm butlast_Nil}),
neuper@37906
   162
       Thm ("concat_Cons",num_str @{thm concat_Cons}),
neuper@37906
   163
       Thm ("concat_Nil",num_str @{thm concat_Nil}),
neuper@37906
   164
       Thm ("del_base",num_str @{thm del_base}),
neuper@37906
   165
       Thm ("del_rec",num_str @{thm del_rec}),
neuper@37906
   166
neuper@37906
   167
       Thm ("distinct_Cons",num_str @{thm distinct_Cons}),
neuper@37906
   168
       Thm ("distinct_Nil",num_str @{thm distinct_Nil}),
neuper@37906
   169
       Thm ("dropWhile_Cons",num_str @{thm dropWhile_Cons}),
neuper@37906
   170
       Thm ("dropWhile_Nil",num_str @{thm dropWhile_Nil}),
neuper@37906
   171
       Thm ("filter_Cons",num_str @{thm filter_Cons}),
neuper@37906
   172
       Thm ("filter_Nil",num_str @{thm filter_Nil}),
neuper@37906
   173
       Thm ("foldr_Cons",num_str @{thm foldr_Cons}),
neuper@37906
   174
       Thm ("foldr_Nil",num_str @{thm foldr_Nil}),
neuper@37906
   175
       Thm ("hd_thm",num_str @{thm hd_thm}),
neuper@37906
   176
       Thm ("LAST",num_str @{thm LAST}),
neuper@37906
   177
       Thm ("LENGTH_CONS",num_str @{thm LENGTH_CONS}),
neuper@37906
   178
       Thm ("LENGTH_NIL",num_str @{thm LENGTH_NIL}),
neuper@37906
   179
       Thm ("list_diff_def",num_str @{thm list_diff_def}),
neuper@37906
   180
       Thm ("map_Cons",num_str @{thm map_Cons}),
neuper@37906
   181
       Thm ("map_Nil",num_str @{thm map_Cons}),
neuper@37906
   182
       Thm ("mem_Cons",num_str @{thm mem_Cons}),
neuper@37906
   183
       Thm ("mem_Nil",num_str @{thm mem_Nil}),
neuper@37906
   184
       Thm ("null_Cons",num_str @{thm null_Cons}),
neuper@37906
   185
       Thm ("null_Nil",num_str @{thm null_Nil}),
neuper@37906
   186
       Thm ("remdups_Cons",num_str @{thm remdups_Cons}),
neuper@37906
   187
       Thm ("remdups_Nil",num_str @{thm remdups_Nil}),
neuper@37906
   188
       Thm ("rev_Cons",num_str @{thm rev_Cons}),
neuper@37906
   189
       Thm ("rev_Nil",num_str @{thm rev_Nil}),
neuper@37906
   190
       Thm ("take_Nil",num_str @{thm take_Nil}),
neuper@37906
   191
       Thm ("take_Cons",num_str @{thm take_Cons}),
neuper@37906
   192
       Thm ("tl_Cons",num_str @{thm tl_Cons}),
neuper@37906
   193
       Thm ("tl_Nil",num_str @{thm tl_Nil}),
neuper@37906
   194
       Thm ("zip_Cons",num_str @{thm zip_Cons}),
neuper@37906
   195
       Thm ("zip_Nil",num_str @{thm zip_Nil})
neuper@37906
   196
       ], scr = EmptyScr}:rls;
neuper@37906
   197
*}
neuper@37906
   198
neuper@37906
   199
ML{*
neuper@37906
   200
ruleset' := overwritelthy @{theory} (!ruleset',
neuper@37906
   201
  [("list_rls",list_rls)
neuper@37906
   202
   ]);
neuper@37906
   203
*}
neuper@37906
   204
end