src/Tools/isac/ProgLang/ListC.thy
author Walther Neuper <wneuper@ist.tugraz.at>
Thu, 08 Sep 2016 13:28:36 +0200
changeset 59244 6870ee668115
parent 59234 d12736878a81
child 59252 7d3dbc1171ff
permissions -rw-r--r--
insertion sort: changed delimiter

Note: libisabelle is disturbed by [||..||] but not with {||..||}
     1 (* Title:  functions on lists for Programs
     2    Author: Walther Neuper 0108
     3    (c) due to copyright terms
     4 *)
     5 
     6 theory ListC 
     7 imports "~~/src/Tools/isac/KEStore"
     8 begin
     9 
    10 ML_file "~~/src/Tools/isac/ProgLang/termC.sml"
    11 ML_file "~~/src/Tools/isac/ProgLang/calculate.sml"
    12 ML_file "~~/src/Tools/isac/ProgLang/rewrite.sml"
    13 
    14 subsection {* Notes on Isac's programming language *}
    15 text {*
    16   Isac's programming language combines tacticals (TRY, etc) and 
    17   tactics (Rewrite, etc) with list processing.
    18 
    19   In order to distinguish list expressions of the meta (programming)
    20   language from the object language in Lucas-Interpretation, a 
    21   new 'type xlist' is introduced.
    22   TODO: Switch the role of 'xlist' and 'list' (the former only used
    23   by InsSort.thy)
    24 
    25   Isac's programming language preceeded the function package
    26   in 2002. For naming "axiomatization" is used for reasons of uniformity
    27   with the other replacements for "axioms".
    28   Another reminiscence from Isabelle2002 are Isac-specific numerals,
    29   introduced in order to have floating point numerals at a time, 
    30   when Isabelle did not consider that requirement. For the sake of uniformity
    31   'nat' from List.thy is replaced by 'real' by 'fun parse',
    32   however, 'fun parseNEW' has started to replace this fix (after finishing
    33   this fix, there will be a 'rename all parseNEW --> parse).
    34 
    35   Note: *one* "axiomatization" over all equations caused strange "'a list list"
    36   types.
    37 *}
    38 
    39 subsection {* Type 'xlist' for Lucas-Interpretation *}
    40 (*TODO: ask for shorter deliminters in xlist *)
    41 datatype 'a xlist =
    42     XNil    ("{|| ||}")
    43   | XCons 'a  "'a xlist"    (infixr "@#" 65)
    44 
    45 syntax
    46   -- {* list Enumeration *}
    47   "_xlist" :: "args => 'a xlist"    ("{|| (_) ||}")
    48 
    49 translations
    50   "{||x, xs||}" == "x@#{||xs||}"
    51   "{||x||}" == "x@#{|| ||}"
    52 
    53 term "{|| ||}"
    54 term "{||1,2,3||}"
    55 
    56 subsection {* Functions for 'xlist' *}
    57 (* TODO: 
    58 (1) revise, if definition of identifiers like LENGTH_NIL are still required.
    59 (2) switch the role of 'xlist' and 'list' in the functions below, in particular for
    60   'foldr', 'foldr_Nil', 'foldr_Cons' and 'xfoldr', 'xfoldr_Nil', 'xfoldr_Cons'.
    61   For transition phase just outcomment InsSort.thy and inssort.sml.
    62 *)
    63 
    64 primrec xfoldr :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'a xlist \<Rightarrow> 'b \<Rightarrow> 'b" where
    65 xfoldr_Nil:  "xfoldr f {|| ||} = id" |
    66 xfoldr_Cons: "xfoldr f (x @# xs) = f x \<circ> xfoldr f xs"
    67 
    68 primrec LENGTH   :: "'a list => real"
    69 where
    70 LENGTH_NIL:	"LENGTH [] = 0" |
    71 LENGTH_CONS: "LENGTH (x#xs) = 1 + LENGTH xs"
    72 
    73 consts NTH ::  "[real, 'a list] => 'a"
    74 axiomatization where
    75 NTH_NIL: "NTH 1 (x # xs) = x" and
    76 NTH_CONS: (*NO primrec, fun ..*)"1 < n ==> NTH n (x # xs) = NTH (n + -1) xs"
    77 
    78 axiomatization where
    79 hd_thm:	"hd (x # xs) = x"
    80 
    81 axiomatization where
    82 tl_Nil:	"tl []  = []" and
    83 tl_Cons: "tl (x # xs) = xs"
    84 
    85 axiomatization where
    86 LAST:	"last (x # xs) = (if xs = [] then x else last xs)"
    87 
    88 axiomatization where
    89 butlast_Nil: "butlast []    = []" and
    90 butlast_Cons:	"butlast (x # xs) = (if xs = [] then [] else x # butlast xs)"
    91 
    92 axiomatization where
    93 map_Nil:"map f [] = []" and
    94 map_Cons:	"map f (x # xs) = f x  #  map f xs"
    95 
    96 axiomatization where
    97 rev_Nil: "rev [] = []" and
    98 rev_Cons:	"rev (x # xs) = rev xs @ [x]"
    99 
   100 axiomatization where
   101 filter_Nil:	"filter P [] = []" and
   102 filter_Cons: "filter P (x # xs) = (if P x then x # filter P xs else filter P xs)" 
   103 
   104 axiomatization where
   105 concat_Nil:	"concat [] = []" and
   106 concat_Cons: "concat (x # xs) = x @ concat xs"
   107 
   108 axiomatization where
   109 takeWhile_Nil: "takeWhile P []     = []" and
   110 takeWhile_Cons: "takeWhile P (x # xs) = (if P x then x # takeWhile P xs else [])"
   111 
   112 axiomatization where
   113 dropWhile_Nil: "dropWhile P [] = []" and
   114 dropWhile_Cons: "dropWhile P (x # xs) = (if P x then dropWhile P xs else x#xs)"
   115 
   116 axiomatization where
   117 zip_Nil: "zip xs [] = []" and
   118 zip_Cons:	"zip xs (y # ys) = (case xs of [] => [] | z # zs => (z,y) # zip zs ys)"
   119 
   120 axiomatization where
   121 distinct_Nil:	"distinct []     = True" and
   122 distinct_Cons:	"distinct (x # xs) = (x ~: set xs & distinct xs)"
   123 
   124 axiomatization where
   125 remdups_Nil:	"remdups [] = []" and
   126 remdups_Cons:	"remdups (x#xs) = (if x : set xs then remdups xs else x # remdups xs)" 
   127 
   128 (** Lexicographic orderings on lists ...!!!**)
   129 
   130 ML{* (*the former ListC.ML*)
   131 (** rule set for evaluating listexpr in scripts **)
   132 val list_rls = 
   133   Rls{id = "list_rls", preconds = [], rew_ord = ("dummy_ord", dummy_ord), 
   134     erls = Erls, srls = Erls, calc = [], errpatts = [],
   135     rules = [Thm ("refl", num_str @{thm refl}),  (*'a<>b -> FALSE' by fun eval_equal*)
   136        Thm ("o_apply", num_str @{thm o_apply}),
   137 
   138        Thm ("NTH_CONS",num_str @{thm NTH_CONS}),(*erls for cond. in Atools.ML*)
   139        Thm ("NTH_NIL",num_str @{thm NTH_NIL}),
   140        Thm ("append_Cons",num_str @{thm append_Cons}),
   141        Thm ("append_Nil",num_str @{thm append_Nil}),
   142 (*       Thm ("butlast_Cons",num_str @{thm butlast_Cons}),
   143        Thm ("butlast_Nil",num_str @{thm butlast_Nil}),*)
   144        Thm ("concat_Cons",num_str @{thm concat_Cons}),
   145        Thm ("concat_Nil",num_str @{thm concat_Nil}),
   146 (*       Thm ("del_base",num_str @{thm del_base}),
   147        Thm ("del_rec",num_str @{thm del_rec}), *)
   148 
   149        Thm ("distinct_Cons",num_str @{thm distinct_Cons}),
   150        Thm ("distinct_Nil",num_str @{thm distinct_Nil}),
   151        Thm ("dropWhile_Cons",num_str @{thm dropWhile_Cons}),
   152        Thm ("dropWhile_Nil",num_str @{thm dropWhile_Nil}),
   153        Thm ("filter_Cons",num_str @{thm filter_Cons}),
   154        Thm ("filter_Nil",num_str @{thm filter_Nil}),
   155        Thm ("foldr_Cons",num_str @{thm foldr_Cons}),
   156        Thm ("foldr_Nil",num_str @{thm foldr_Nil}),
   157        Thm ("hd_thm",num_str @{thm hd_thm}),
   158        Thm ("LAST",num_str @{thm LAST}),
   159        Thm ("LENGTH_CONS",num_str @{thm LENGTH_CONS}),
   160        Thm ("LENGTH_NIL",num_str @{thm LENGTH_NIL}),
   161 (*       Thm ("list_diff_def",num_str @{thm list_diff_def}),*)
   162        Thm ("map_Cons",num_str @{thm map_Cons}),
   163        Thm ("map_Nil",num_str @{thm map_Cons}),
   164 (*       Thm ("mem_Cons",num_str @{thm mem_Cons}),
   165        Thm ("mem_Nil",num_str @{thm mem_Nil}), *)
   166 (*       Thm ("null_Cons",num_str @{thm null_Cons}),
   167        Thm ("null_Nil",num_str @{thm null_Nil}),*)
   168        Thm ("remdups_Cons",num_str @{thm remdups_Cons}),
   169        Thm ("remdups_Nil",num_str @{thm remdups_Nil}),
   170        Thm ("rev_Cons",num_str @{thm rev_Cons}),
   171        Thm ("rev_Nil",num_str @{thm rev_Nil}),
   172        Thm ("take_Nil",num_str @{thm take_Nil}),
   173        Thm ("take_Cons",num_str @{thm take_Cons}),
   174        Thm ("tl_Cons",num_str @{thm tl_Cons}),
   175        Thm ("tl_Nil",num_str @{thm tl_Nil}),
   176        Thm ("zip_Cons",num_str @{thm zip_Cons}),
   177        Thm ("zip_Nil",num_str @{thm zip_Nil})],
   178     scr = EmptyScr}:rls;
   179 *}
   180 setup {* KEStore_Elems.add_rlss [("list_rls", (Context.theory_name @{theory}, list_rls))] *}
   181 
   182 end