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 (*primrec from Isabelle/src/HOL/List.thy -- def.twice not allowed*)
46 hd_thm: "hd(x#xs) = x"
49 tl_Cons: "tl(x#xs) = xs"
51 null_Nil: "null([]) = True"
52 null_Cons: "null(x#xs) = False"
54 LAST: "last(x#xs) = (if xs=[] then x else last xs)"
56 butlast_Nil: "butlast [] = []"
57 butlast_Cons: "butlast(x#xs) = (if xs=[] then [] else x#butlast xs)"
59 mem_Nil: "x mem [] = False"
60 mem_Cons: "x mem (y#ys) = (if y=x then True else x mem ys)"
62 mem_Nil: "x : set [] = False"
63 mem_Cons: "x : set (y#ys) = (if y=x then True else x : set ys)"
64 (*primrec-------already named---
66 "set (x#xs) = insert x (set xs)"
68 list_all_Nil "list_all P [] = True"
69 list_all_Cons "list_all P (x#xs) = (P(x) & list_all P xs)"
72 map_Nil: "map f [] = []"
73 map_Cons: "map f (x#xs) = f(x)#map f xs"
75 append_Nil: "[] @ys = ys"
76 append_Cons: "(x#xs)@ys = x#(xs@ys)"
78 rev_Nil: "rev([]) = []"
79 rev_Cons: "rev(x#xs) = rev(xs) @ [x]"
81 filter_Nil: "filter P [] = []"
82 filter_Cons: "filter P (x#xs) =(if P x then x#filter P xs else filter P xs)"
83 (*primrec-------already named---
84 foldl_Nil "foldl f a [] = a"
85 foldl_Cons "foldl f a (x#xs) = foldl f (f a x) xs"
88 foldr_Nil: "foldr f [] a = a"
89 foldr_Cons: "foldr f (x#xs) a = f x (foldr f xs a)"
91 concat_Nil: "concat([]) = []"
92 concat_Cons: "concat(x#xs) = x @ concat(xs)"
93 (*primrec-------already named---
94 drop_Nil "drop n [] = []"
95 drop_Cons "drop n (x#xs) = (case n of 0 => x#xs | Suc(m) => drop m xs)"
96 (* Warning: simpset does not contain this definition but separate theorems
99 take_Nil "take n [] = []"
100 take_Cons "take n (x#xs) = (case n of 0 => [] | Suc(m) => x # take m xs)"
101 (* Warning: simpset does not contain this definition but separate theorems
104 nth_Cons "(x#xs)!n = (case n of 0 => x | (Suc k) => xs!k)"
105 (* Warning: simpset does not contain this definition but separate theorems
109 "(x#xs)[i:=v] = (case i of 0 => v # xs
110 | Suc j => x # xs[j:=v])"
113 takeWhile_Nil: "takeWhile P [] = []"
115 "takeWhile P (x#xs) = (if P x then x#takeWhile P xs else [])"
117 dropWhile_Nil: "dropWhile P [] = []"
119 "dropWhile P (x#xs) = (if P x then dropWhile P xs else x#xs)"
121 zip_Nil: "zip xs [] = []"
122 zip_Cons: "zip xs (y#ys) =(case xs of [] => [] | z#zs =>(z,y)#zip zs ys)"
123 (* Warning: simpset does not contain this definition but separate theorems
124 for xs=[] / xs=z#zs *)
127 upt_Suc "[i..(Suc j)(] = (if i <= j then [i..j(] @ [j] else [])"
130 distinct_Nil: "distinct [] = True"
131 distinct_Cons: "distinct (x#xs) = (x ~: set xs & distinct xs)"
133 remdups_Nil: "remdups [] = []"
134 remdups_Cons: "remdups (x#xs) =
135 (if x : set xs then remdups xs else x # remdups xs)"
136 (*primrec-------already named---
137 replicate_0 "replicate 0 x = []"
138 replicate_Suc "replicate (Suc n) x = x # replicate n x"
141 (** Lexicographic orderings on lists ...!!!**)
143 ML{* (*the former ListC.ML*)
144 (** rule set for evaluating listexpr in scripts **)
146 Rls{id="list_rls",preconds = [], rew_ord = ("dummy_ord",dummy_ord),
147 erls = e_rls, srls = Erls, calc = [], (*asm_thm=[],*)
148 rules = (*8.01: copied from*)
149 [Thm ("refl", num_str @{thm refl}), (*'a<>b -> FALSE' by fun eval_equal*)
150 Thm ("o_apply", num_str @{thm o_apply}),
152 Thm ("NTH_CONS",num_str @{thm NTH_CONS}),(*erls for cond. in Atools.ML*)
153 Thm ("NTH_NIL",num_str @{thm NTH_NIL}),
154 Thm ("append_Cons",num_str @{thm append_Cons}),
155 Thm ("append_Nil",num_str @{thm append_Nil}),
156 Thm ("butlast_Cons",num_str @{thm butlast_Cons}),
157 Thm ("butlast_Nil",num_str @{thm butlast_Nil}),
158 Thm ("concat_Cons",num_str @{thm concat_Cons}),
159 Thm ("concat_Nil",num_str @{thm concat_Nil}),
160 Thm ("del_base",num_str @{thm del_base}),
161 Thm ("del_rec",num_str @{thm del_rec}),
163 Thm ("distinct_Cons",num_str @{thm distinct_Cons}),
164 Thm ("distinct_Nil",num_str @{thm distinct_Nil}),
165 Thm ("dropWhile_Cons",num_str @{thm dropWhile_Cons}),
166 Thm ("dropWhile_Nil",num_str @{thm dropWhile_Nil}),
167 Thm ("filter_Cons",num_str @{thm filter_Cons}),
168 Thm ("filter_Nil",num_str @{thm filter_Nil}),
169 Thm ("foldr_Cons",num_str @{thm foldr_Cons}),
170 Thm ("foldr_Nil",num_str @{thm foldr_Nil}),
171 Thm ("hd_thm",num_str @{thm hd_thm}),
172 Thm ("LAST",num_str @{thm LAST}),
173 Thm ("LENGTH_CONS",num_str @{thm LENGTH_CONS}),
174 Thm ("LENGTH_NIL",num_str @{thm LENGTH_NIL}),
175 Thm ("list_diff_def",num_str @{thm list_diff_def}),
176 Thm ("map_Cons",num_str @{thm map_Cons}),
177 Thm ("map_Nil",num_str @{thm map_Cons}),
178 Thm ("mem_Cons",num_str @{thm mem_Cons}),
179 Thm ("mem_Nil",num_str @{thm mem_Nil}),
180 Thm ("null_Cons",num_str @{thm null_Cons}),
181 Thm ("null_Nil",num_str @{thm null_Nil}),
182 Thm ("remdups_Cons",num_str @{thm remdups_Cons}),
183 Thm ("remdups_Nil",num_str @{thm remdups_Nil}),
184 Thm ("rev_Cons",num_str @{thm rev_Cons}),
185 Thm ("rev_Nil",num_str @{thm rev_Nil}),
186 Thm ("take_Nil",num_str @{thm take_Nil}),
187 Thm ("take_Cons",num_str @{thm take_Cons}),
188 Thm ("tl_Cons",num_str @{thm tl_Cons}),
189 Thm ("tl_Nil",num_str @{thm tl_Nil}),
190 Thm ("zip_Cons",num_str @{thm zip_Cons}),
191 Thm ("zip_Nil",num_str @{thm zip_Nil})
192 ], scr = EmptyScr}:rls;
196 ruleset' := overwritelthy @{theory} (!ruleset',
197 [("list_rls",list_rls)