--- a/src/HOL/Finite_Set.thy Fri May 08 16:19:51 2009 -0700
+++ b/src/HOL/Finite_Set.thy Sat May 09 07:25:45 2009 +0200
@@ -365,6 +365,29 @@
lemma finite_Plus: "[| finite A; finite B |] ==> finite (A <+> B)"
by (simp add: Plus_def)
+lemma finite_PlusD:
+ fixes A :: "'a set" and B :: "'b set"
+ assumes fin: "finite (A <+> B)"
+ shows "finite A" "finite B"
+proof -
+ have "Inl ` A \<subseteq> A <+> B" by auto
+ hence "finite (Inl ` A :: ('a + 'b) set)" using fin by(rule finite_subset)
+ thus "finite A" by(rule finite_imageD)(auto intro: inj_onI)
+next
+ have "Inr ` B \<subseteq> A <+> B" by auto
+ hence "finite (Inr ` B :: ('a + 'b) set)" using fin by(rule finite_subset)
+ thus "finite B" by(rule finite_imageD)(auto intro: inj_onI)
+qed
+
+lemma finite_Plus_iff[simp]: "finite (A <+> B) \<longleftrightarrow> finite A \<and> finite B"
+by(auto intro: finite_PlusD finite_Plus)
+
+lemma finite_Plus_UNIV_iff[simp]:
+ "finite (UNIV :: ('a + 'b) set) =
+ (finite (UNIV :: 'a set) & finite (UNIV :: 'b set))"
+by(subst UNIV_Plus_UNIV[symmetric])(rule finite_Plus_iff)
+
+
text {* Sigma of finite sets *}
lemma finite_SigmaI [simp]:
@@ -1563,6 +1586,20 @@
qed
+lemma setsum_Plus:
+ fixes A :: "'a set" and B :: "'b set"
+ assumes fin: "finite A" "finite B"
+ shows "setsum f (A <+> B) = setsum (f \<circ> Inl) A + setsum (f \<circ> Inr) B"
+proof -
+ have "A <+> B = Inl ` A \<union> Inr ` B" by auto
+ moreover from fin have "finite (Inl ` A :: ('a + 'b) set)" "finite (Inr ` B :: ('a + 'b) set)"
+ by(auto intro: finite_imageI)
+ moreover have "Inl ` A \<inter> Inr ` B = ({} :: ('a + 'b) set)" by auto
+ moreover have "inj_on (Inl :: 'a \<Rightarrow> 'a + 'b) A" "inj_on (Inr :: 'b \<Rightarrow> 'a + 'b) B" by(auto intro: inj_onI)
+ ultimately show ?thesis using fin by(simp add: setsum_Un_disjoint setsum_reindex)
+qed
+
+
text {* Commuting outer and inner summation *}
lemma swap_inj_on:
@@ -2091,6 +2128,10 @@
qed
+lemma card_UNIV_unit: "card (UNIV :: unit set) = 1"
+ unfolding UNIV_unit by simp
+
+
subsubsection {* Cardinality of unions *}
lemma card_UN_disjoint:
@@ -2201,6 +2242,10 @@
by (simp add: card_Un_disjoint card_image)
qed
+lemma card_Plus_conv_if:
+ "card (A <+> B) = (if finite A \<and> finite B then card(A) + card(B) else 0)"
+by(auto simp: card_def setsum_Plus simp del: setsum_constant)
+
subsubsection {* Cardinality of the Powerset *}
--- a/src/HOL/Fun.thy Fri May 08 16:19:51 2009 -0700
+++ b/src/HOL/Fun.thy Sat May 09 07:25:45 2009 +0200
@@ -412,6 +412,9 @@
"f(x:=y) ` A = (if x \<in> A then insert y (f ` (A-{x})) else f ` A)"
by auto
+lemma fun_upd_comp: "f \<circ> (g(x := y)) = (f \<circ> g)(x := f y)"
+by(auto intro: ext)
+
subsection {* @{text override_on} *}
--- a/src/HOL/Library/Nat_Infinity.thy Fri May 08 16:19:51 2009 -0700
+++ b/src/HOL/Library/Nat_Infinity.thy Sat May 09 07:25:45 2009 +0200
@@ -24,6 +24,10 @@
Infty ("\<infinity>")
+lemma not_Infty_eq[simp]: "(x ~= Infty) = (EX i. x = Fin i)"
+by (cases x) auto
+
+
subsection {* Constructors and numbers *}
instantiation inat :: "{zero, one, number}"
@@ -261,6 +265,9 @@
end
+instance inat :: linorder
+by intro_classes (auto simp add: less_eq_inat_def split: inat.splits)
+
instance inat :: pordered_comm_semiring
proof
fix a b c :: inat
@@ -413,4 +420,8 @@
lemmas inat_splits = inat.splits
+
+instance inat :: linorder
+by intro_classes (auto simp add: inat_defs split: inat.splits)
+
end
--- a/src/HOL/Library/Numeral_Type.thy Fri May 08 16:19:51 2009 -0700
+++ b/src/HOL/Library/Numeral_Type.thy Sat May 09 07:25:45 2009 +0200
@@ -55,7 +55,7 @@
unfolding UNIV_Plus_UNIV [symmetric] by (simp only: finite card_Plus)
lemma card_option [simp]: "CARD('a option) = Suc CARD('a::finite)"
- unfolding insert_None_conv_UNIV [symmetric]
+ unfolding UNIV_option_conv
apply (subgoal_tac "(None::'a option) \<notin> range Some")
apply (simp add: card_image)
apply fast
--- a/src/HOL/List.thy Fri May 08 16:19:51 2009 -0700
+++ b/src/HOL/List.thy Sat May 09 07:25:45 2009 +0200
@@ -1324,6 +1324,9 @@
apply simp_all
done
+lemma list_update_nonempty[simp]: "xs[k:=x] = [] \<longleftrightarrow> xs=[]"
+by(metis length_0_conv length_list_update)
+
lemma list_update_same_conv:
"i < length xs ==> (xs[i := x] = xs) = (xs!i = x)"
by (induct xs arbitrary: i) (auto split: nat.split)
@@ -1344,8 +1347,7 @@
by (induct xs, auto)
lemma update_zip:
- "length xs = length ys ==>
- (zip xs ys)[i:=xy] = zip (xs[i:=fst xy]) (ys[i:=snd xy])"
+ "(zip xs ys)[i:=xy] = zip (xs[i:=fst xy]) (ys[i:=snd xy])"
by (induct ys arbitrary: i xy xs) (auto, case_tac xs, auto split: nat.split)
lemma set_update_subset_insert: "set(xs[i:=x]) <= insert x (set xs)"
@@ -1357,12 +1359,10 @@
lemma set_update_memI: "n < length xs \<Longrightarrow> x \<in> set (xs[n := x])"
by (induct xs arbitrary: n) (auto split:nat.splits)
-lemma list_update_overwrite:
+lemma list_update_overwrite[simp]:
"xs [i := x, i := y] = xs [i := y]"
-apply (induct xs arbitrary: i)
-apply simp
-apply (case_tac i)
-apply simp_all
+apply (induct xs arbitrary: i) apply simp
+apply (case_tac i, simp_all)
done
lemma list_update_swap:
@@ -1444,6 +1444,18 @@
lemma butlast_conv_take: "butlast xs = take (length xs - 1) xs"
by (induct xs, simp, case_tac xs, simp_all)
+lemma last_list_update:
+ "xs \<noteq> [] \<Longrightarrow> last(xs[k:=x]) = (if k = size xs - 1 then x else last xs)"
+by (auto simp: last_conv_nth)
+
+lemma butlast_list_update:
+ "butlast(xs[k:=x]) =
+ (if k = size xs - 1 then butlast xs else (butlast xs)[k:=x])"
+apply(cases xs rule:rev_cases)
+apply simp
+apply(simp add:list_update_append split:nat.splits)
+done
+
subsubsection {* @{text take} and @{text drop} *}
@@ -1723,6 +1735,13 @@
"(dropWhile P xs = y#ys) = (xs = takeWhile P xs @ y # ys & \<not> P y)"
by(induct xs, auto)
+lemma distinct_takeWhile[simp]: "distinct xs ==> distinct (takeWhile P xs)"
+by (induct xs) (auto dest: set_takeWhileD)
+
+lemma distinct_dropWhile[simp]: "distinct xs ==> distinct (dropWhile P xs)"
+by (induct xs) auto
+
+
text{* The following two lemmmas could be generalized to an arbitrary
property. *}
@@ -1809,6 +1828,10 @@
apply simp_all
done
+text{* Courtesy of Andreas Lochbihler: *}
+lemma zip_same_conv_map: "zip xs xs = map (\<lambda>x. (x, x)) xs"
+by(induct xs) auto
+
lemma nth_zip [simp]:
"[| i < length xs; i < length ys|] ==> (zip xs ys)!i = (xs!i, ys!i)"
apply (induct ys arbitrary: i xs, simp)
@@ -1818,11 +1841,11 @@
lemma set_zip:
"set (zip xs ys) = {(xs!i, ys!i) | i. i < min (length xs) (length ys)}"
-by (simp add: set_conv_nth cong: rev_conj_cong)
+by(simp add: set_conv_nth cong: rev_conj_cong)
lemma zip_update:
-"length xs = length ys ==> zip (xs[i:=x]) (ys[i:=y]) = (zip xs ys)[i:=(x,y)]"
-by (rule sym, simp add: update_zip)
+ "zip (xs[i:=x]) (ys[i:=y]) = (zip xs ys)[i:=(x,y)]"
+by(rule sym, simp add: update_zip)
lemma zip_replicate [simp]:
"zip (replicate i x) (replicate j y) = replicate (min i j) (x,y)"
@@ -2140,6 +2163,10 @@
lemma listsum[code unfold]: "listsum xs = foldl (op +) 0 xs"
by(simp add:listsum_foldr foldl_foldr1)
+lemma distinct_listsum_conv_Setsum:
+ "distinct xs \<Longrightarrow> listsum xs = Setsum(set xs)"
+by (induct xs) simp_all
+
text{* Some syntactic sugar for summing a function over a list: *}
@@ -2553,6 +2580,11 @@
apply (simp add: add_commute)
done
+text{* Courtesy of Andreas Lochbihler: *}
+lemma filter_replicate:
+ "filter P (replicate n x) = (if P x then replicate n x else [])"
+by(induct n) auto
+
lemma hd_replicate [simp]: "n \<noteq> 0 ==> hd (replicate n x) = x"
by (induct n) auto
--- a/src/HOL/Map.thy Fri May 08 16:19:51 2009 -0700
+++ b/src/HOL/Map.thy Sat May 09 07:25:45 2009 +0200
@@ -452,6 +452,9 @@
subsection {* @{term [source] dom} *}
+lemma dom_eq_empty_conv [simp]: "dom f = {} \<longleftrightarrow> f = empty"
+by(auto intro!:ext simp: dom_def)
+
lemma domI: "m a = Some b ==> a : dom m"
by(simp add:dom_def)
(* declare domI [intro]? *)
@@ -593,4 +596,19 @@
lemma map_add_le_mapI: "\<lbrakk> f \<subseteq>\<^sub>m h; g \<subseteq>\<^sub>m h; f \<subseteq>\<^sub>m f++g \<rbrakk> \<Longrightarrow> f++g \<subseteq>\<^sub>m h"
by (clarsimp simp add: map_le_def map_add_def dom_def split: option.splits)
+
+lemma dom_eq_singleton_conv: "dom f = {x} \<longleftrightarrow> (\<exists>v. f = [x \<mapsto> v])"
+proof(rule iffI)
+ assume "\<exists>v. f = [x \<mapsto> v]"
+ thus "dom f = {x}" by(auto split: split_if_asm)
+next
+ assume "dom f = {x}"
+ then obtain v where "f x = Some v" by auto
+ hence "[x \<mapsto> v] \<subseteq>\<^sub>m f" by(auto simp add: map_le_def)
+ moreover have "f \<subseteq>\<^sub>m [x \<mapsto> v]" using `dom f = {x}` `f x = Some v`
+ by(auto simp add: map_le_def)
+ ultimately have "f = [x \<mapsto> v]" by-(rule map_le_antisym)
+ thus "\<exists>v. f = [x \<mapsto> v]" by blast
+qed
+
end
--- a/src/HOL/Nat_Numeral.thy Fri May 08 16:19:51 2009 -0700
+++ b/src/HOL/Nat_Numeral.thy Sat May 09 07:25:45 2009 +0200
@@ -982,6 +982,9 @@
subsubsection{*Various Other Lemmas*}
+lemma card_UNIV_bool[simp]: "card (UNIV :: bool set) = 2"
+by(simp add: UNIV_bool)
+
text {*Evens and Odds, for Mutilated Chess Board*}
text{*Lemmas for specialist use, NOT as default simprules*}
--- a/src/HOL/Option.thy Fri May 08 16:19:51 2009 -0700
+++ b/src/HOL/Option.thy Sat May 09 07:25:45 2009 +0200
@@ -20,6 +20,9 @@
only when applied to assumptions, in practice it seems better to give
them the uniform iff attribute. *}
+lemma inj_Some [simp]: "inj_on Some A"
+by (rule inj_onI) simp
+
lemma option_caseE:
assumes c: "(case x of None => P | Some y => Q y)"
obtains
@@ -27,14 +30,15 @@
| (Some) y where "x = Some y" and "Q y"
using c by (cases x) simp_all
-lemma insert_None_conv_UNIV: "insert None (range Some) = UNIV"
- by (rule set_ext, case_tac x) auto
+lemma UNIV_option_conv: "UNIV = insert None (range Some)"
+by(auto intro: classical)
+
+lemma finite_option_UNIV[simp]:
+ "finite (UNIV :: 'a option set) = finite (UNIV :: 'a set)"
+by(auto simp add: UNIV_option_conv elim: finite_imageD intro: inj_Some)
instance option :: (finite) finite proof
-qed (simp add: insert_None_conv_UNIV [symmetric])
-
-lemma inj_Some [simp]: "inj_on Some A"
- by (rule inj_onI) simp
+qed (simp add: UNIV_option_conv)
subsubsection {* Operations *}
--- a/src/HOL/Sum_Type.thy Fri May 08 16:19:51 2009 -0700
+++ b/src/HOL/Sum_Type.thy Sat May 09 07:25:45 2009 +0200
@@ -157,6 +157,8 @@
apply auto
done
+lemma Plus_eq_empty_conv[simp]: "A <+> B = {} \<longleftrightarrow> A = {} \<and> B = {}"
+by(auto)
subsection{*The @{term Part} Primitive*}