1.1 --- a/src/HOL/IsaMakefile Sat Apr 14 15:08:59 2012 +0100
1.2 +++ b/src/HOL/IsaMakefile Sat Apr 14 19:29:31 2012 +0200
1.3 @@ -1027,7 +1027,7 @@
1.4 ex/Quicksort.thy ex/ROOT.ML \
1.5 ex/Records.thy ex/ReflectionEx.thy ex/Refute_Examples.thy \
1.6 ex/SAT_Examples.thy ex/Serbian.thy ex/Set_Theory.thy \
1.7 - ex/Set_Algebras.thy ex/Simproc_Tests.thy ex/SVC_Oracle.thy \
1.8 + ex/Simproc_Tests.thy ex/SVC_Oracle.thy \
1.9 ex/sledgehammer_tactics.ML ex/Seq.thy ex/Sqrt.thy ex/Sqrt_Script.thy \
1.10 ex/Sudoku.thy ex/Tarski.thy ex/Termination.thy ex/Transfer_Ex.thy \
1.11 ex/Tree23.thy ex/Unification.thy ex/While_Combinator_Example.thy \
2.1 --- a/src/HOL/ex/ROOT.ML Sat Apr 14 15:08:59 2012 +0100
2.2 +++ b/src/HOL/ex/ROOT.ML Sat Apr 14 19:29:31 2012 +0200
2.3 @@ -67,7 +67,6 @@
2.4 "Quicksort",
2.5 "Birthday_Paradox",
2.6 "List_to_Set_Comprehension_Examples",
2.7 - "Set_Algebras",
2.8 "Seq",
2.9 "Simproc_Tests",
2.10 "Executable_Relation"
3.1 --- a/src/HOL/ex/Set_Algebras.thy Sat Apr 14 15:08:59 2012 +0100
3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
3.3 @@ -1,371 +0,0 @@
3.4 -(* Title: HOL/ex/Set_Algebras.thy
3.5 - Author: Jeremy Avigad and Kevin Donnelly; Florian Haftmann, TUM
3.6 -*)
3.7 -
3.8 -header {* Algebraic operations on sets *}
3.9 -
3.10 -theory Set_Algebras
3.11 -imports Main Interpretation_with_Defs
3.12 -begin
3.13 -
3.14 -text {*
3.15 - This library lifts operations like addition and muliplication to
3.16 - sets. It was designed to support asymptotic calculations. See the
3.17 - comments at the top of theory @{text BigO}.
3.18 -*}
3.19 -
3.20 -definition set_plus :: "'a::plus set \<Rightarrow> 'a set \<Rightarrow> 'a set" (infixl "\<oplus>" 65) where
3.21 - "A \<oplus> B = {c. \<exists>a\<in>A. \<exists>b\<in>B. c = a + b}"
3.22 -
3.23 -definition set_times :: "'a::times set \<Rightarrow> 'a set \<Rightarrow> 'a set" (infixl "\<otimes>" 70) where
3.24 - "A \<otimes> B = {c. \<exists>a\<in>A. \<exists>b\<in>B. c = a * b}"
3.25 -
3.26 -definition elt_set_plus :: "'a::plus \<Rightarrow> 'a set \<Rightarrow> 'a set" (infixl "+o" 70) where
3.27 - "a +o B = {c. \<exists>b\<in>B. c = a + b}"
3.28 -
3.29 -definition elt_set_times :: "'a::times \<Rightarrow> 'a set \<Rightarrow> 'a set" (infixl "*o" 80) where
3.30 - "a *o B = {c. \<exists>b\<in>B. c = a * b}"
3.31 -
3.32 -abbreviation (input) elt_set_eq :: "'a \<Rightarrow> 'a set \<Rightarrow> bool" (infix "=o" 50) where
3.33 - "x =o A \<equiv> x \<in> A"
3.34 -
3.35 -interpretation set_add!: semigroup "set_plus :: 'a::semigroup_add set \<Rightarrow> 'a set \<Rightarrow> 'a set"
3.36 - by default (force simp add: set_plus_def add.assoc)
3.37 -
3.38 -interpretation set_add!: abel_semigroup "set_plus :: 'a::ab_semigroup_add set \<Rightarrow> 'a set \<Rightarrow> 'a set"
3.39 - by default (force simp add: set_plus_def add.commute)
3.40 -
3.41 -interpretation set_add!: monoid "set_plus :: 'a::monoid_add set \<Rightarrow> 'a set \<Rightarrow> 'a set" "{0}"
3.42 - by default (simp_all add: set_plus_def)
3.43 -
3.44 -interpretation set_add!: comm_monoid "set_plus :: 'a::comm_monoid_add set \<Rightarrow> 'a set \<Rightarrow> 'a set" "{0}"
3.45 - by default (simp add: set_plus_def)
3.46 -
3.47 -interpretation set_add!: monoid_add "set_plus :: 'a::monoid_add set \<Rightarrow> 'a set \<Rightarrow> 'a set" "{0}"
3.48 - defines listsum_set is set_add.listsum
3.49 - by default (simp_all add: set_add.assoc)
3.50 -
3.51 -interpretation
3.52 - set_add!: comm_monoid_add "set_plus :: 'a::comm_monoid_add set \<Rightarrow> 'a set \<Rightarrow> 'a set" "{0}"
3.53 - defines setsum_set is set_add.setsum
3.54 - where "monoid_add.listsum set_plus {0::'a} = listsum_set"
3.55 -proof -
3.56 - show "class.comm_monoid_add (set_plus :: 'a set \<Rightarrow> 'a set \<Rightarrow> 'a set) {0}"
3.57 - by default (simp_all add: set_add.commute)
3.58 - then interpret set_add!: comm_monoid_add "set_plus :: 'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" "{0}" .
3.59 - show "monoid_add.listsum set_plus {0::'a} = listsum_set"
3.60 - by (simp only: listsum_set_def)
3.61 -qed
3.62 -
3.63 -interpretation set_mult!: semigroup "set_times :: 'a::semigroup_mult set \<Rightarrow> 'a set \<Rightarrow> 'a set"
3.64 - by default (force simp add: set_times_def mult.assoc)
3.65 -
3.66 -interpretation
3.67 - set_mult!: abel_semigroup "set_times :: 'a::ab_semigroup_mult set \<Rightarrow> 'a set \<Rightarrow> 'a set"
3.68 - by default (force simp add: set_times_def mult.commute)
3.69 -
3.70 -interpretation set_mult!: monoid "set_times :: 'a::monoid_mult set \<Rightarrow> 'a set \<Rightarrow> 'a set" "{1}"
3.71 - by default (simp_all add: set_times_def)
3.72 -
3.73 -interpretation
3.74 - set_mult!: comm_monoid "set_times :: 'a::comm_monoid_mult set \<Rightarrow> 'a set \<Rightarrow> 'a set" "{1}"
3.75 - by default (simp add: set_times_def)
3.76 -
3.77 -interpretation set_mult!: monoid_mult "{1}" "set_times :: 'a::monoid_mult set \<Rightarrow> 'a set \<Rightarrow> 'a set"
3.78 - defines power_set is set_mult.power
3.79 - by default (simp_all add: set_mult.assoc)
3.80 -
3.81 -interpretation
3.82 - set_mult!: comm_monoid_mult "set_times :: 'a::comm_monoid_mult set \<Rightarrow> 'a set \<Rightarrow> 'a set" "{1}"
3.83 - defines setprod_set is set_mult.setprod
3.84 - where "power.power {1} set_times = power_set"
3.85 -proof -
3.86 - show "class.comm_monoid_mult (set_times :: 'a set \<Rightarrow> 'a set \<Rightarrow> 'a set) {1}"
3.87 - by default (simp_all add: set_mult.commute)
3.88 - then interpret set_mult!: comm_monoid_mult "set_times :: 'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" "{1}" .
3.89 - show "power.power {1} set_times = power_set"
3.90 - by (simp add: power_set_def)
3.91 -qed
3.92 -
3.93 -lemma set_plus_intro [intro]: "a : C ==> b : D ==> a + b : C \<oplus> D"
3.94 - by (auto simp add: set_plus_def)
3.95 -
3.96 -lemma set_plus_intro2 [intro]: "b : C ==> a + b : a +o C"
3.97 - by (auto simp add: elt_set_plus_def)
3.98 -
3.99 -lemma set_plus_rearrange: "((a::'a::comm_monoid_add) +o C) \<oplus> (b +o D) = (a + b) +o (C \<oplus> D)"
3.100 - apply (auto simp add: elt_set_plus_def set_plus_def add_ac)
3.101 - apply (rule_tac x = "ba + bb" in exI)
3.102 - apply (auto simp add: add_ac)
3.103 - apply (rule_tac x = "aa + a" in exI)
3.104 - apply (auto simp add: add_ac)
3.105 - done
3.106 -
3.107 -lemma set_plus_rearrange2: "(a::'a::semigroup_add) +o (b +o C) = (a + b) +o C"
3.108 - by (auto simp add: elt_set_plus_def add_assoc)
3.109 -
3.110 -lemma set_plus_rearrange3: "((a::'a::semigroup_add) +o B) \<oplus> C = a +o (B \<oplus> C)"
3.111 - apply (auto simp add: elt_set_plus_def set_plus_def)
3.112 - apply (blast intro: add_ac)
3.113 - apply (rule_tac x = "a + aa" in exI)
3.114 - apply (rule conjI)
3.115 - apply (rule_tac x = "aa" in bexI)
3.116 - apply auto
3.117 - apply (rule_tac x = "ba" in bexI)
3.118 - apply (auto simp add: add_ac)
3.119 - done
3.120 -
3.121 -theorem set_plus_rearrange4: "C \<oplus> ((a::'a::comm_monoid_add) +o D) = a +o (C \<oplus> D)"
3.122 - apply (auto intro!: simp add: elt_set_plus_def set_plus_def add_ac)
3.123 - apply (rule_tac x = "aa + ba" in exI)
3.124 - apply (auto simp add: add_ac)
3.125 - done
3.126 -
3.127 -theorems set_plus_rearranges = set_plus_rearrange set_plus_rearrange2
3.128 - set_plus_rearrange3 set_plus_rearrange4
3.129 -
3.130 -lemma set_plus_mono [intro!]: "C <= D ==> a +o C <= a +o D"
3.131 - by (auto simp add: elt_set_plus_def)
3.132 -
3.133 -lemma set_plus_mono2 [intro]: "(C::('a::plus) set) <= D ==> E <= F ==>
3.134 - C \<oplus> E <= D \<oplus> F"
3.135 - by (auto simp add: set_plus_def)
3.136 -
3.137 -lemma set_plus_mono3 [intro]: "a : C ==> a +o D <= C \<oplus> D"
3.138 - by (auto simp add: elt_set_plus_def set_plus_def)
3.139 -
3.140 -lemma set_plus_mono4 [intro]: "(a::'a::comm_monoid_add) : C ==>
3.141 - a +o D <= D \<oplus> C"
3.142 - by (auto simp add: elt_set_plus_def set_plus_def add_ac)
3.143 -
3.144 -lemma set_plus_mono5: "a:C ==> B <= D ==> a +o B <= C \<oplus> D"
3.145 - apply (subgoal_tac "a +o B <= a +o D")
3.146 - apply (erule order_trans)
3.147 - apply (erule set_plus_mono3)
3.148 - apply (erule set_plus_mono)
3.149 - done
3.150 -
3.151 -lemma set_plus_mono_b: "C <= D ==> x : a +o C
3.152 - ==> x : a +o D"
3.153 - apply (frule set_plus_mono)
3.154 - apply auto
3.155 - done
3.156 -
3.157 -lemma set_plus_mono2_b: "C <= D ==> E <= F ==> x : C \<oplus> E ==>
3.158 - x : D \<oplus> F"
3.159 - apply (frule set_plus_mono2)
3.160 - prefer 2
3.161 - apply force
3.162 - apply assumption
3.163 - done
3.164 -
3.165 -lemma set_plus_mono3_b: "a : C ==> x : a +o D ==> x : C \<oplus> D"
3.166 - apply (frule set_plus_mono3)
3.167 - apply auto
3.168 - done
3.169 -
3.170 -lemma set_plus_mono4_b: "(a::'a::comm_monoid_add) : C ==>
3.171 - x : a +o D ==> x : D \<oplus> C"
3.172 - apply (frule set_plus_mono4)
3.173 - apply auto
3.174 - done
3.175 -
3.176 -lemma set_zero_plus [simp]: "(0::'a::comm_monoid_add) +o C = C"
3.177 - by (auto simp add: elt_set_plus_def)
3.178 -
3.179 -lemma set_zero_plus2: "(0::'a::comm_monoid_add) : A ==> B <= A \<oplus> B"
3.180 - apply (auto intro!: simp add: set_plus_def)
3.181 - apply (rule_tac x = 0 in bexI)
3.182 - apply (rule_tac x = x in bexI)
3.183 - apply (auto simp add: add_ac)
3.184 - done
3.185 -
3.186 -lemma set_plus_imp_minus: "(a::'a::ab_group_add) : b +o C ==> (a - b) : C"
3.187 - by (auto simp add: elt_set_plus_def add_ac diff_minus)
3.188 -
3.189 -lemma set_minus_imp_plus: "(a::'a::ab_group_add) - b : C ==> a : b +o C"
3.190 - apply (auto simp add: elt_set_plus_def add_ac diff_minus)
3.191 - apply (subgoal_tac "a = (a + - b) + b")
3.192 - apply (rule bexI, assumption, assumption)
3.193 - apply (auto simp add: add_ac)
3.194 - done
3.195 -
3.196 -lemma set_minus_plus: "((a::'a::ab_group_add) - b : C) = (a : b +o C)"
3.197 - by (rule iffI, rule set_minus_imp_plus, assumption, rule set_plus_imp_minus,
3.198 - assumption)
3.199 -
3.200 -lemma set_times_intro [intro]: "a : C ==> b : D ==> a * b : C \<otimes> D"
3.201 - by (auto simp add: set_times_def)
3.202 -
3.203 -lemma set_times_intro2 [intro!]: "b : C ==> a * b : a *o C"
3.204 - by (auto simp add: elt_set_times_def)
3.205 -
3.206 -lemma set_times_rearrange: "((a::'a::comm_monoid_mult) *o C) \<otimes>
3.207 - (b *o D) = (a * b) *o (C \<otimes> D)"
3.208 - apply (auto simp add: elt_set_times_def set_times_def)
3.209 - apply (rule_tac x = "ba * bb" in exI)
3.210 - apply (auto simp add: mult_ac)
3.211 - apply (rule_tac x = "aa * a" in exI)
3.212 - apply (auto simp add: mult_ac)
3.213 - done
3.214 -
3.215 -lemma set_times_rearrange2: "(a::'a::semigroup_mult) *o (b *o C) =
3.216 - (a * b) *o C"
3.217 - by (auto simp add: elt_set_times_def mult_assoc)
3.218 -
3.219 -lemma set_times_rearrange3: "((a::'a::semigroup_mult) *o B) \<otimes> C =
3.220 - a *o (B \<otimes> C)"
3.221 - apply (auto simp add: elt_set_times_def set_times_def)
3.222 - apply (blast intro: mult_ac)
3.223 - apply (rule_tac x = "a * aa" in exI)
3.224 - apply (rule conjI)
3.225 - apply (rule_tac x = "aa" in bexI)
3.226 - apply auto
3.227 - apply (rule_tac x = "ba" in bexI)
3.228 - apply (auto simp add: mult_ac)
3.229 - done
3.230 -
3.231 -theorem set_times_rearrange4: "C \<otimes> ((a::'a::comm_monoid_mult) *o D) =
3.232 - a *o (C \<otimes> D)"
3.233 - apply (auto intro!: simp add: elt_set_times_def set_times_def
3.234 - mult_ac)
3.235 - apply (rule_tac x = "aa * ba" in exI)
3.236 - apply (auto simp add: mult_ac)
3.237 - done
3.238 -
3.239 -theorems set_times_rearranges = set_times_rearrange set_times_rearrange2
3.240 - set_times_rearrange3 set_times_rearrange4
3.241 -
3.242 -lemma set_times_mono [intro]: "C <= D ==> a *o C <= a *o D"
3.243 - by (auto simp add: elt_set_times_def)
3.244 -
3.245 -lemma set_times_mono2 [intro]: "(C::('a::times) set) <= D ==> E <= F ==>
3.246 - C \<otimes> E <= D \<otimes> F"
3.247 - by (auto simp add: set_times_def)
3.248 -
3.249 -lemma set_times_mono3 [intro]: "a : C ==> a *o D <= C \<otimes> D"
3.250 - by (auto simp add: elt_set_times_def set_times_def)
3.251 -
3.252 -lemma set_times_mono4 [intro]: "(a::'a::comm_monoid_mult) : C ==>
3.253 - a *o D <= D \<otimes> C"
3.254 - by (auto simp add: elt_set_times_def set_times_def mult_ac)
3.255 -
3.256 -lemma set_times_mono5: "a:C ==> B <= D ==> a *o B <= C \<otimes> D"
3.257 - apply (subgoal_tac "a *o B <= a *o D")
3.258 - apply (erule order_trans)
3.259 - apply (erule set_times_mono3)
3.260 - apply (erule set_times_mono)
3.261 - done
3.262 -
3.263 -lemma set_times_mono_b: "C <= D ==> x : a *o C
3.264 - ==> x : a *o D"
3.265 - apply (frule set_times_mono)
3.266 - apply auto
3.267 - done
3.268 -
3.269 -lemma set_times_mono2_b: "C <= D ==> E <= F ==> x : C \<otimes> E ==>
3.270 - x : D \<otimes> F"
3.271 - apply (frule set_times_mono2)
3.272 - prefer 2
3.273 - apply force
3.274 - apply assumption
3.275 - done
3.276 -
3.277 -lemma set_times_mono3_b: "a : C ==> x : a *o D ==> x : C \<otimes> D"
3.278 - apply (frule set_times_mono3)
3.279 - apply auto
3.280 - done
3.281 -
3.282 -lemma set_times_mono4_b: "(a::'a::comm_monoid_mult) : C ==>
3.283 - x : a *o D ==> x : D \<otimes> C"
3.284 - apply (frule set_times_mono4)
3.285 - apply auto
3.286 - done
3.287 -
3.288 -lemma set_one_times [simp]: "(1::'a::comm_monoid_mult) *o C = C"
3.289 - by (auto simp add: elt_set_times_def)
3.290 -
3.291 -lemma set_times_plus_distrib: "(a::'a::semiring) *o (b +o C)=
3.292 - (a * b) +o (a *o C)"
3.293 - by (auto simp add: elt_set_plus_def elt_set_times_def ring_distribs)
3.294 -
3.295 -lemma set_times_plus_distrib2: "(a::'a::semiring) *o (B \<oplus> C) =
3.296 - (a *o B) \<oplus> (a *o C)"
3.297 - apply (auto simp add: set_plus_def elt_set_times_def ring_distribs)
3.298 - apply blast
3.299 - apply (rule_tac x = "b + bb" in exI)
3.300 - apply (auto simp add: ring_distribs)
3.301 - done
3.302 -
3.303 -lemma set_times_plus_distrib3: "((a::'a::semiring) +o C) \<otimes> D <=
3.304 - a *o D \<oplus> C \<otimes> D"
3.305 - apply (auto simp add:
3.306 - elt_set_plus_def elt_set_times_def set_times_def
3.307 - set_plus_def ring_distribs)
3.308 - apply auto
3.309 - done
3.310 -
3.311 -theorems set_times_plus_distribs =
3.312 - set_times_plus_distrib
3.313 - set_times_plus_distrib2
3.314 -
3.315 -lemma set_neg_intro: "(a::'a::ring_1) : (- 1) *o C ==>
3.316 - - a : C"
3.317 - by (auto simp add: elt_set_times_def)
3.318 -
3.319 -lemma set_neg_intro2: "(a::'a::ring_1) : C ==>
3.320 - - a : (- 1) *o C"
3.321 - by (auto simp add: elt_set_times_def)
3.322 -
3.323 -lemma set_plus_image:
3.324 - fixes S T :: "'n::semigroup_add set" shows "S \<oplus> T = (\<lambda>(x, y). x + y) ` (S \<times> T)"
3.325 - unfolding set_plus_def by (fastforce simp: image_iff)
3.326 -
3.327 -lemma set_setsum_alt:
3.328 - assumes fin: "finite I"
3.329 - shows "setsum_set S I = {setsum s I |s. \<forall>i\<in>I. s i \<in> S i}"
3.330 - (is "_ = ?setsum I")
3.331 -using fin
3.332 -proof induct
3.333 - case (insert x F)
3.334 - have "setsum_set S (insert x F) = S x \<oplus> ?setsum F"
3.335 - using insert.hyps by auto
3.336 - also have "...= {s x + setsum s F |s. \<forall> i\<in>insert x F. s i \<in> S i}"
3.337 - proof -
3.338 - {
3.339 - fix y s assume "y \<in> S x" "\<forall>i\<in>F. s i \<in> S i"
3.340 - then have "\<exists>s'. y + setsum s F = s' x + setsum s' F \<and> (\<forall>i\<in>insert x F. s' i \<in> S i)"
3.341 - using insert.hyps
3.342 - by (intro exI[of _ "\<lambda>i. if i \<in> F then s i else y"]) (auto simp add: set_plus_def)
3.343 - }
3.344 - then show ?thesis
3.345 - unfolding set_plus_def by auto
3.346 - qed
3.347 - finally show ?case
3.348 - using insert.hyps by auto
3.349 -qed auto
3.350 -
3.351 -lemma setsum_set_cond_linear:
3.352 - fixes f :: "('a::comm_monoid_add) set \<Rightarrow> ('b::comm_monoid_add) set"
3.353 - assumes [intro!]: "\<And>A B. P A \<Longrightarrow> P B \<Longrightarrow> P (A \<oplus> B)" "P {0}"
3.354 - and f: "\<And>A B. P A \<Longrightarrow> P B \<Longrightarrow> f (A \<oplus> B) = f A \<oplus> f B" "f {0} = {0}"
3.355 - assumes all: "\<And>i. i \<in> I \<Longrightarrow> P (S i)"
3.356 - shows "f (setsum_set S I) = setsum_set (f \<circ> S) I"
3.357 -proof cases
3.358 - assume "finite I" from this all show ?thesis
3.359 - proof induct
3.360 - case (insert x F)
3.361 - from `finite F` `\<And>i. i \<in> insert x F \<Longrightarrow> P (S i)` have "P (setsum_set S F)"
3.362 - by induct auto
3.363 - with insert show ?case
3.364 - by (simp, subst f) auto
3.365 - qed (auto intro!: f)
3.366 -qed (auto intro!: f)
3.367 -
3.368 -lemma setsum_set_linear:
3.369 - fixes f :: "('a::comm_monoid_add) set => ('b::comm_monoid_add) set"
3.370 - assumes "\<And>A B. f(A) \<oplus> f(B) = f(A \<oplus> B)" "f {0} = {0}"
3.371 - shows "f (setsum_set S I) = setsum_set (f \<circ> S) I"
3.372 - using setsum_set_cond_linear[of "\<lambda>x. True" f I S] assms by auto
3.373 -
3.374 -end