1 (* Title: functions on lists for Scripts
2 Author: Walther Neuper 0108
3 (c) due to copyright terms
6 theory ListC imports Complex_Main
7 uses ("../library.sml")("../calcelems.sml")
8 ("termC.sml")("calculate.sml")
11 use "../library.sml" (*indent,...*)
12 use "../calcelems.sml" (*str_of_type, Thm,...*)
13 use "termC.sml" (*num_str,...*)
14 use "calculate.sml" (*???*)
15 use "rewrite.sml" (*?*** At command "end" (line 205../ListC.thy*)
17 text {* 'nat' in List.thy replaced by 'real' *}
19 primrec LENGTH :: "'a list => real"
21 LENGTH_NIL: "LENGTH [] = 0" (*length: 'a list => nat*)
22 | LENGTH_CONS: "LENGTH (x#xs) = 1 + LENGTH xs"
24 primrec del :: "['a list, 'a] => 'a list"
26 del_base: "del [] x = []"
27 | del_rec: "del (y#ys) x = (if x = y then ys else y#(del ys x))"
30 list_diff :: "['a list, 'a list] => 'a list" (* as -- bs *)
31 ("(_ --/ _)" [66, 66] 65)
32 where "a -- b == foldl del a b"
34 consts NTH :: "[real, 'a list] => 'a"
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" *)
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"
44 (*-.-.-.-.-.-isolate response.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
45 (*primrec from Isabelle/src/HOL/List.thy -- def.twice not allowed*)
47 hd_thm: "hd(x#xs) = x"
50 tl_Cons: "tl(x#xs) = xs"
52 null_Nil: "null([]) = True"
53 null_Cons: "null(x#xs) = False"
55 LAST: "last(x#xs) = (if xs=[] then x else last xs)"
57 butlast_Nil: "butlast [] = []"
58 butlast_Cons: "butlast(x#xs) = (if xs=[] then [] else x#butlast xs)"
60 mem_Nil: "x mem [] = False"
61 mem_Cons: "x mem (y#ys) = (if y=x then True else x mem ys)"
63 mem_Nil: "x : set [] = False"
64 mem_Cons: "x : set (y#ys) = (if y=x then True else x : set ys)"
65 (*primrec-------already named---
67 "set (x#xs) = insert x (set xs)"
69 list_all_Nil "list_all P [] = True"
70 list_all_Cons "list_all P (x#xs) = (P(x) & list_all P xs)"
73 map_Nil: "map f [] = []"
74 map_Cons: "map f (x#xs) = f(x)#map f xs"
76 append_Nil: "[] @ys = ys"
77 append_Cons: "(x#xs)@ys = x#(xs@ys)"
79 rev_Nil: "rev([]) = []"
80 rev_Cons: "rev(x#xs) = rev(xs) @ [x]"
82 filter_Nil: "filter P [] = []"
83 filter_Cons: "filter P (x#xs) =(if P x then x#filter P xs else filter P xs)"
84 (*primrec-------already named---
85 foldl_Nil "foldl f a [] = a"
86 foldl_Cons "foldl f a (x#xs) = foldl f (f a x) xs"
89 foldr_Nil: "foldr f [] a = a"
90 foldr_Cons: "foldr f (x#xs) a = f x (foldr f xs a)"
92 concat_Nil: "concat([]) = []"
93 concat_Cons: "concat(x#xs) = x @ concat(xs)"
94 (*primrec-------already named---
95 drop_Nil "drop n [] = []"
96 drop_Cons "drop n (x#xs) = (case n of 0 => x#xs | Suc(m) => drop m xs)"
97 (* Warning: simpset does not contain this definition but separate theorems
100 take_Nil "take n [] = []"
101 take_Cons "take n (x#xs) = (case n of 0 => [] | Suc(m) => x # take m xs)"
102 (* Warning: simpset does not contain this definition but separate theorems
105 nth_Cons "(x#xs)!n = (case n of 0 => x | (Suc k) => xs!k)"
106 (* Warning: simpset does not contain this definition but separate theorems
110 "(x#xs)[i:=v] = (case i of 0 => v # xs
111 | Suc j => x # xs[j:=v])"
114 takeWhile_Nil: "takeWhile P [] = []"
116 "takeWhile P (x#xs) = (if P x then x#takeWhile P xs else [])"
118 dropWhile_Nil: "dropWhile P [] = []"
120 "dropWhile P (x#xs) = (if P x then dropWhile P xs else x#xs)"
122 zip_Nil: "zip xs [] = []"
123 zip_Cons: "zip xs (y#ys) =(case xs of [] => [] | z#zs =>(z,y)#zip zs ys)"
124 (* Warning: simpset does not contain this definition but separate theorems
125 for xs=[] / xs=z#zs *)
128 upt_Suc "[i..(Suc j)(] = (if i <= j then [i..j(] @ [j] else [])"
131 distinct_Nil: "distinct [] = True"
132 distinct_Cons: "distinct (x#xs) = (x ~: set xs & distinct xs)"
134 remdups_Nil: "remdups [] = []"
135 remdups_Cons: "remdups (x#xs) =
136 (if x : set xs then remdups xs else x # remdups xs)"
137 (*primrec-------already named---
138 replicate_0 "replicate 0 x = []"
139 replicate_Suc "replicate (Suc n) x = x # replicate n x"
142 (** Lexicographic orderings on lists ...!!!**)
144 ML{* (*the former ListC.ML*)
145 (** rule set for evaluating listexpr in scripts **)
147 Rls{id="list_rls",preconds = [], rew_ord = ("dummy_ord",dummy_ord),
148 erls = e_rls, srls = Erls, calc = [], (*asm_thm=[],*)
149 rules = (*8.01: copied from*)
150 [Thm ("refl", num_str @{thm refl}), (*'a<>b -> FALSE' by fun eval_equal*)
151 Thm ("o_apply", num_str @{thm o_apply}),
153 Thm ("NTH_CONS",num_str @{thm NTH_CONS}),(*erls for cond. in Atools.ML*)
154 Thm ("NTH_NIL",num_str @{thm NTH_NIL}),
155 Thm ("append_Cons",num_str @{thm append_Cons}),
156 Thm ("append_Nil",num_str @{thm append_Nil}),
157 Thm ("butlast_Cons",num_str @{thm butlast_Cons}),
158 Thm ("butlast_Nil",num_str @{thm butlast_Nil}),
159 Thm ("concat_Cons",num_str @{thm concat_Cons}),
160 Thm ("concat_Nil",num_str @{thm concat_Nil}),
161 Thm ("del_base",num_str @{thm del_base}),
162 Thm ("del_rec",num_str @{thm del_rec}),
164 Thm ("distinct_Cons",num_str @{thm distinct_Cons}),
165 Thm ("distinct_Nil",num_str @{thm distinct_Nil}),
166 Thm ("dropWhile_Cons",num_str @{thm dropWhile_Cons}),
167 Thm ("dropWhile_Nil",num_str @{thm dropWhile_Nil}),
168 Thm ("filter_Cons",num_str @{thm filter_Cons}),
169 Thm ("filter_Nil",num_str @{thm filter_Nil}),
170 Thm ("foldr_Cons",num_str @{thm foldr_Cons}),
171 Thm ("foldr_Nil",num_str @{thm foldr_Nil}),
172 Thm ("hd_thm",num_str @{thm hd_thm}),
173 Thm ("LAST",num_str @{thm LAST}),
174 Thm ("LENGTH_CONS",num_str @{thm LENGTH_CONS}),
175 Thm ("LENGTH_NIL",num_str @{thm LENGTH_NIL}),
176 Thm ("list_diff_def",num_str @{thm list_diff_def}),
177 Thm ("map_Cons",num_str @{thm map_Cons}),
178 Thm ("map_Nil",num_str @{thm map_Cons}),
179 Thm ("mem_Cons",num_str @{thm mem_Cons}),
180 Thm ("mem_Nil",num_str @{thm mem_Nil}),
181 Thm ("null_Cons",num_str @{thm null_Cons}),
182 Thm ("null_Nil",num_str @{thm null_Nil}),
183 Thm ("remdups_Cons",num_str @{thm remdups_Cons}),
184 Thm ("remdups_Nil",num_str @{thm remdups_Nil}),
185 Thm ("rev_Cons",num_str @{thm rev_Cons}),
186 Thm ("rev_Nil",num_str @{thm rev_Nil}),
187 Thm ("take_Nil",num_str @{thm take_Nil}),
188 Thm ("take_Cons",num_str @{thm take_Cons}),
189 Thm ("tl_Cons",num_str @{thm tl_Cons}),
190 Thm ("tl_Nil",num_str @{thm tl_Nil}),
191 Thm ("zip_Cons",num_str @{thm zip_Cons}),
192 Thm ("zip_Nil",num_str @{thm zip_Nil})
193 ], scr = EmptyScr}:rls;
197 ruleset' := overwritelthy @{theory} (!ruleset',
198 [("list_rls",list_rls)
201 -.-.-.-.-.-.-isolate response.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.*)