# HG changeset patch # User haftmann # Date 1179767499 -7200 # Node ID 0c0b03d0ec7ee45739bf45a9a272fecadd36a927 # Parent e7cd9719dbc2822224928a60e18404a097719890 improved code for rev diff -r e7cd9719dbc2 -r 0c0b03d0ec7e src/HOL/List.thy --- a/src/HOL/List.thy Mon May 21 19:11:38 2007 +0200 +++ b/src/HOL/List.thy Mon May 21 19:11:39 2007 +0200 @@ -2728,7 +2728,6 @@ list_inter :: "'a list \ 'a list \ 'a list" list_ex :: "('a \ bool) \ 'a list \ bool" list_all :: "('a \ bool) \ ('a list \ bool)" - itrev :: "'a list \ 'a list \ 'a list" filtermap :: "('a \ 'b option) \ 'a list \ 'b list" map_filter :: "('a \ 'b) \ ('a \ bool) \ 'a list \ 'b list" @@ -2764,10 +2763,6 @@ "map_filter f P (x#xs) = (if P x then f x # map_filter f P xs else map_filter f P xs)" -primrec - "itrev [] ys = ys" - "itrev (x#xs) ys = itrev xs (x#ys)" - text {* Only use @{text mem} for generating executable code. Otherwise use @{prop "x : set xs"} instead --- it is much easier to reason about. @@ -2780,11 +2775,27 @@ Efficient emptyness check is implemented by @{const null}. - The functions @{const itrev}, @{const filtermap} and @{const - map_filter} are just there to generate efficient code. Do not use + The functions @{const filtermap} and @{const map_filter} are just + there to generate efficient code. Do not use them for modelling and proving. *} +lemma rev_foldl_cons [code]: + "rev xs = foldl (\xs x. x # xs) [] xs" +proof (induct xs) + case Nil then show ?case by simp +next + case Cons + { + fix x xs ys + have "foldl (\xs x. x # xs) ys xs @ [x] + = foldl (\xs x. x # xs) (ys @ [x]) xs" + by (induct xs arbitrary: ys) auto + } + note aux = this + show ?case by (induct xs) (auto simp add: Cons aux) +qed + lemma mem_iff [normal post]: "x mem xs \ x \ set xs" by (induct xs) auto @@ -2831,10 +2842,6 @@ "list_ex P xs \ (\n < length xs. P (xs ! n))" unfolding list_ex_iff set_conv_nth by auto -lemma itrev [simp]: - "itrev xs ys = rev xs @ ys" - by (induct xs arbitrary: ys) simp_all - lemma filtermap_conv: "filtermap f xs = map (\x. the (f x)) (filter (\x. f x \ None) xs)" by (induct xs) (simp_all split: option.split) @@ -2843,10 +2850,6 @@ "map_filter f P xs = map f (filter P xs)" by (induct xs) auto -lemma rev_code [code func]: - "rev xs = itrev xs []" - by simp - text {* code for bounded quantification over nats *}