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")
9 ("termC.sml")("calculate.sml")
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*)
18 text {* 'nat' in List.thy replaced by 'real' *}
20 primrec LENGTH :: "'a list => real"
22 LENGTH_NIL: "LENGTH [] = 0" (*length: 'a list => nat*)
23 | LENGTH_CONS: "LENGTH (x#xs) = 1 + LENGTH xs"
25 primrec del :: "['a list, 'a] => 'a list"
27 del_base: "del [] x = []"
28 | del_rec: "del (y#ys) x = (if x = y then ys else y#(del ys x))"
31 list_diff :: "['a list, 'a list] => 'a list" (* as -- bs *)
32 ("(_ --/ _)" [66, 66] 65)
33 where "a -- b == foldl del a b"
35 consts NTH :: "[real, 'a list] => 'a"
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" *)
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
46 (*primrec from Isabelle/src/HOL/List.thy -- def.twice not allowed*)
48 hd_thm: "hd(x#xs) = x" and
50 tl_Nil: "tl([]) = []" and
51 tl_Cons: "tl(x#xs) = xs" and
53 null_Nil: "null([]) = True" and
54 null_Cons: "null(x#xs) = False" and
56 LAST: "last(x#xs) = (if xs=[] then x else last xs)" and
58 butlast_Nil: "butlast [] = []" and
59 butlast_Cons: "butlast(x#xs) = (if xs=[] then [] else x#butlast xs)" and
61 mem_Nil: "x mem [] = False"
62 mem_Cons: "x mem (y#ys) = (if y=x then True else x mem ys)"
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---
68 "set (x#xs) = insert x (set xs)"
70 list_all_Nil "list_all P [] = True"
71 list_all_Cons "list_all P (x#xs) = (P(x) & list_all P xs)"
74 map_Nil: "map f [] = []" and
75 map_Cons: "map f (x#xs) = f(x)#map f xs" and
77 append_Nil: "[] @ys = ys" and
78 append_Cons: "(x#xs)@ys = x#(xs@ys)" and
80 rev_Nil: "rev([]) = []" and
81 rev_Cons: "rev(x#xs) = rev(xs) @ [x]" and
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"
90 foldr_Nil: "foldr f [] a = a" and
91 foldr_Cons: "foldr f (x#xs) a = f x (foldr f xs a)" and
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
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
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
111 "(x#xs)[i:=v] = (case i of 0 => v # xs
112 | Suc j => x # xs[j:=v])"
115 takeWhile_Nil: "takeWhile P [] = []" and
117 "takeWhile P (x#xs) = (if P x then x#takeWhile P xs else [])" and
119 dropWhile_Nil: "dropWhile P [] = []" and
121 "dropWhile P (x#xs) = (if P x then dropWhile P xs else x#xs)" and
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 *)
129 upt_Suc "[i..(Suc j)(] = (if i <= j then [i..j(] @ [j] else [])"
132 distinct_Nil: "distinct [] = True" and
133 distinct_Cons: "distinct (x#xs) = (x ~: set xs & distinct xs)" and
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"
143 (** Lexicographic orderings on lists ...!!!**)
145 ML{* (*the former ListC.ML*)
146 (** rule set for evaluating listexpr in scripts **)
148 Rls{id="list_rls",preconds = [], rew_ord = ("dummy_ord",dummy_ord),
149 erls = e_rls, srls = Erls, calc = [], (*asm_thm=[],*)
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}),
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}),
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;
198 ruleset' := overwritelthy @{theory} (!ruleset',
199 [("list_rls",list_rls)