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