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