src/Tools/isac/ProgLang/ListC.thy
author Walther Neuper <neuper@ist.tugraz.at>
Sun, 16 Jun 2013 12:31:41 +0200
changeset 48880 ea0c337066d9
parent 48761 4162c4f6f897
child 52122 904bac7df4f6
permissions -rw-r--r--
Isabelle2011 --> 2012 intermediate

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