src/Tools/isac/ProgLang/ListC.thy
author Walther Neuper <neuper@ist.tugraz.at>
Tue, 31 Jul 2012 15:16:47 +0200
changeset 42451 bc03b5d60547
parent 42211 51c3c007d7fd
child 42458 4d7502e18f18
permissions -rw-r--r--
prepared for fun stepToErrorPatterns

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