experimental variant of interpretation with simultaneous definitions, plus example
1.1 --- a/src/HOL/IsaMakefile Sat Jan 15 18:49:42 2011 +0100
1.2 +++ b/src/HOL/IsaMakefile Sat Jan 15 20:05:29 2011 +0100
1.3 @@ -1034,19 +1034,20 @@
1.4 ex/HarmonicSeries.thy ex/Hebrew.thy ex/Hex_Bin_Examples.thy \
1.5 ex/Higher_Order_Logic.thy ex/Iff_Oracle.thy ex/Induction_Schema.thy \
1.6 ex/InductiveInvariant.thy ex/InductiveInvariant_examples.thy \
1.7 - ex/Intuitionistic.thy ex/Lagrange.thy \
1.8 - ex/List_to_Set_Comprehension_Examples.thy ex/LocaleTest2.thy ex/MT.thy \
1.9 - ex/MergeSort.thy ex/Meson_Test.thy ex/MonoidGroup.thy \
1.10 + ex/Interpretation_with_Defs.thy ex/Intuitionistic.thy ex/Lagrange.thy \
1.11 + ex/List_to_Set_Comprehension_Examples.thy ex/LocaleTest2.thy \
1.12 + ex/MT.thy ex/MergeSort.thy ex/Meson_Test.thy ex/MonoidGroup.thy \
1.13 ex/Multiquote.thy ex/NatSum.thy ex/Normalization_by_Evaluation.thy \
1.14 ex/Numeral.thy ex/PER.thy ex/PresburgerEx.thy ex/Primrec.thy \
1.15 ex/Quickcheck_Examples.thy ex/Quickcheck_Lattice_Examples.thy \
1.16 ex/Quicksort.thy ex/ROOT.ML ex/Recdefs.thy ex/Records.thy \
1.17 ex/ReflectionEx.thy ex/Refute_Examples.thy ex/SAT_Examples.thy \
1.18 - ex/SVC_Oracle.thy ex/Serbian.thy ex/Sqrt.thy ex/Sqrt_Script.thy \
1.19 - ex/Sudoku.thy ex/Tarski.thy ex/Termination.thy ex/Transfer_Ex.thy \
1.20 - ex/Tree23.thy ex/Unification.thy ex/While_Combinator_Example.thy \
1.21 - ex/document/root.bib ex/document/root.tex ex/set.thy ex/svc_funcs.ML \
1.22 - ex/svc_test.thy
1.23 + ex/SVC_Oracle.thy ex/Serbian.thy ex/Set_Algebras.thy ex/Sqrt.thy \
1.24 + ex/Sqrt_Script.thy ex/Sudoku.thy ex/Tarski.thy ex/Termination.thy \
1.25 + ex/Transfer_Ex.thy ex/Tree23.thy ex/Unification.thy \
1.26 + ex/While_Combinator_Example.thy ex/document/root.bib \
1.27 + ex/document/root.tex ex/set.thy ex/svc_funcs.ML ex/svc_test.thy \
1.28 + ../Tools/interpretation_with_defs.ML
1.29 @$(ISABELLE_TOOL) usedir $(OUT)/HOL ex
1.30
1.31
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/src/HOL/ex/Interpretation_with_Defs.thy Sat Jan 15 20:05:29 2011 +0100
2.3 @@ -0,0 +1,12 @@
2.4 +(* Title: HOL/ex/Interpretation_with_Defs.thy
2.5 + Author: Florian Haftmann, TU Muenchen
2.6 +*)
2.7 +
2.8 +header {* Interpretation accompanied with mixin definitions. EXPERIMENTAL. *}
2.9 +
2.10 +theory Interpretation_with_Defs
2.11 +imports Pure
2.12 +uses "~~/src/Tools/interpretation_with_defs.ML"
2.13 +begin
2.14 +
2.15 +end
3.1 --- a/src/HOL/ex/ROOT.ML Sat Jan 15 18:49:42 2011 +0100
3.2 +++ b/src/HOL/ex/ROOT.ML Sat Jan 15 20:05:29 2011 +0100
3.3 @@ -72,7 +72,8 @@
3.4 "Dedekind_Real",
3.5 "Quicksort",
3.6 "Birthday_Paradoxon",
3.7 - "List_to_Set_Comprehension_Examples"
3.8 + "List_to_Set_Comprehension_Examples",
3.9 + "Set_Algebras"
3.10 ];
3.11
3.12 use_thy "SVC_Oracle";
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/src/HOL/ex/Set_Algebras.thy Sat Jan 15 20:05:29 2011 +0100
4.3 @@ -0,0 +1,369 @@
4.4 +(* Title: HOL/ex/Set_Algebras.thy
4.5 + Author: Jeremy Avigad and Kevin Donnelly; Florian Haftmann, TUM
4.6 +*)
4.7 +
4.8 +header {* Algebraic operations on sets *}
4.9 +
4.10 +theory Set_Algebras
4.11 +imports Main Interpretation_with_Defs
4.12 +begin
4.13 +
4.14 +text {*
4.15 + This library lifts operations like addition and muliplication to
4.16 + sets. It was designed to support asymptotic calculations. See the
4.17 + comments at the top of theory @{text BigO}.
4.18 +*}
4.19 +
4.20 +definition set_plus :: "'a::plus set \<Rightarrow> 'a set \<Rightarrow> 'a set" (infixl "\<oplus>" 65) where
4.21 + "A \<oplus> B = {c. \<exists>a\<in>A. \<exists>b\<in>B. c = a + b}"
4.22 +
4.23 +definition set_times :: "'a::times set \<Rightarrow> 'a set \<Rightarrow> 'a set" (infixl "\<otimes>" 70) where
4.24 + "A \<otimes> B = {c. \<exists>a\<in>A. \<exists>b\<in>B. c = a * b}"
4.25 +
4.26 +definition elt_set_plus :: "'a::plus \<Rightarrow> 'a set \<Rightarrow> 'a set" (infixl "+o" 70) where
4.27 + "a +o B = {c. \<exists>b\<in>B. c = a + b}"
4.28 +
4.29 +definition elt_set_times :: "'a::times \<Rightarrow> 'a set \<Rightarrow> 'a set" (infixl "*o" 80) where
4.30 + "a *o B = {c. \<exists>b\<in>B. c = a * b}"
4.31 +
4.32 +abbreviation (input) elt_set_eq :: "'a \<Rightarrow> 'a set \<Rightarrow> bool" (infix "=o" 50) where
4.33 + "x =o A \<equiv> x \<in> A"
4.34 +
4.35 +interpretation set_add!: semigroup "set_plus :: 'a::semigroup_add set \<Rightarrow> 'a set \<Rightarrow> 'a set" proof
4.36 +qed (force simp add: set_plus_def add.assoc)
4.37 +
4.38 +interpretation set_add!: abel_semigroup "set_plus :: 'a::ab_semigroup_add set \<Rightarrow> 'a set \<Rightarrow> 'a set" proof
4.39 +qed (force simp add: set_plus_def add.commute)
4.40 +
4.41 +interpretation set_add!: monoid "set_plus :: 'a::monoid_add set \<Rightarrow> 'a set \<Rightarrow> 'a set" "{0}" proof
4.42 +qed (simp_all add: set_plus_def)
4.43 +
4.44 +interpretation set_add!: comm_monoid "set_plus :: 'a::comm_monoid_add set \<Rightarrow> 'a set \<Rightarrow> 'a set" "{0}" proof
4.45 +qed (simp add: set_plus_def)
4.46 +
4.47 +interpretation set_add!: monoid_add "set_plus :: 'a::monoid_add set \<Rightarrow> 'a set \<Rightarrow> 'a set" "{0}"
4.48 + defines listsum_set is set_add.listsum
4.49 +proof
4.50 +qed (simp_all add: set_add.assoc)
4.51 +
4.52 +interpretation set_add!: comm_monoid_add "set_plus :: 'a::comm_monoid_add set \<Rightarrow> 'a set \<Rightarrow> 'a set" "{0}"
4.53 + defines setsum_set is set_add.setsum
4.54 + where "monoid_add.listsum set_plus {0::'a} = listsum_set"
4.55 +proof -
4.56 + show "class.comm_monoid_add (set_plus :: 'a set \<Rightarrow> 'a set \<Rightarrow> 'a set) {0}" proof
4.57 + qed (simp_all add: set_add.commute)
4.58 + then interpret set_add!: comm_monoid_add "set_plus :: 'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" "{0}" .
4.59 + show "monoid_add.listsum set_plus {0::'a} = listsum_set"
4.60 + by (simp only: listsum_set_def)
4.61 +qed
4.62 +
4.63 +interpretation set_mult!: semigroup "set_times :: 'a::semigroup_mult set \<Rightarrow> 'a set \<Rightarrow> 'a set" proof
4.64 +qed (force simp add: set_times_def mult.assoc)
4.65 +
4.66 +interpretation set_mult!: abel_semigroup "set_times :: 'a::ab_semigroup_mult set \<Rightarrow> 'a set \<Rightarrow> 'a set" proof
4.67 +qed (force simp add: set_times_def mult.commute)
4.68 +
4.69 +interpretation set_mult!: monoid "set_times :: 'a::monoid_mult set \<Rightarrow> 'a set \<Rightarrow> 'a set" "{1}" proof
4.70 +qed (simp_all add: set_times_def)
4.71 +
4.72 +interpretation set_mult!: comm_monoid "set_times :: 'a::comm_monoid_mult set \<Rightarrow> 'a set \<Rightarrow> 'a set" "{1}" proof
4.73 +qed (simp add: set_times_def)
4.74 +
4.75 +interpretation set_mult!: monoid_mult "{1}" "set_times :: 'a::monoid_mult set \<Rightarrow> 'a set \<Rightarrow> 'a set"
4.76 + defines power_set is set_mult.power
4.77 +proof
4.78 +qed (simp_all add: set_mult.assoc)
4.79 +
4.80 +interpretation set_mult!: comm_monoid_mult "set_times :: 'a::comm_monoid_mult set \<Rightarrow> 'a set \<Rightarrow> 'a set" "{1}"
4.81 + defines setprod_set is set_mult.setprod
4.82 + where "power.power {1} set_times = power_set"
4.83 +proof -
4.84 + show "class.comm_monoid_mult (set_times :: 'a set \<Rightarrow> 'a set \<Rightarrow> 'a set) {1}" proof
4.85 + qed (simp_all add: set_mult.commute)
4.86 + then interpret set_mult!: comm_monoid_mult "set_times :: 'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" "{1}" .
4.87 + show "power.power {1} set_times = power_set"
4.88 + by (simp add: power_set_def)
4.89 +qed
4.90 +
4.91 +lemma set_plus_intro [intro]: "a : C ==> b : D ==> a + b : C \<oplus> D"
4.92 + by (auto simp add: set_plus_def)
4.93 +
4.94 +lemma set_plus_intro2 [intro]: "b : C ==> a + b : a +o C"
4.95 + by (auto simp add: elt_set_plus_def)
4.96 +
4.97 +lemma set_plus_rearrange: "((a::'a::comm_monoid_add) +o C) \<oplus>
4.98 + (b +o D) = (a + b) +o (C \<oplus> D)"
4.99 + apply (auto simp add: elt_set_plus_def set_plus_def add_ac)
4.100 + apply (rule_tac x = "ba + bb" in exI)
4.101 + apply (auto simp add: add_ac)
4.102 + apply (rule_tac x = "aa + a" in exI)
4.103 + apply (auto simp add: add_ac)
4.104 + done
4.105 +
4.106 +lemma set_plus_rearrange2: "(a::'a::semigroup_add) +o (b +o C) =
4.107 + (a + b) +o C"
4.108 + by (auto simp add: elt_set_plus_def add_assoc)
4.109 +
4.110 +lemma set_plus_rearrange3: "((a::'a::semigroup_add) +o B) \<oplus> C =
4.111 + a +o (B \<oplus> C)"
4.112 + apply (auto simp add: elt_set_plus_def set_plus_def)
4.113 + apply (blast intro: add_ac)
4.114 + apply (rule_tac x = "a + aa" in exI)
4.115 + apply (rule conjI)
4.116 + apply (rule_tac x = "aa" in bexI)
4.117 + apply auto
4.118 + apply (rule_tac x = "ba" in bexI)
4.119 + apply (auto simp add: add_ac)
4.120 + done
4.121 +
4.122 +theorem set_plus_rearrange4: "C \<oplus> ((a::'a::comm_monoid_add) +o D) =
4.123 + a +o (C \<oplus> D)"
4.124 + apply (auto intro!: subsetI simp add: elt_set_plus_def set_plus_def add_ac)
4.125 + apply (rule_tac x = "aa + ba" in exI)
4.126 + apply (auto simp add: add_ac)
4.127 + done
4.128 +
4.129 +theorems set_plus_rearranges = set_plus_rearrange set_plus_rearrange2
4.130 + set_plus_rearrange3 set_plus_rearrange4
4.131 +
4.132 +lemma set_plus_mono [intro!]: "C <= D ==> a +o C <= a +o D"
4.133 + by (auto simp add: elt_set_plus_def)
4.134 +
4.135 +lemma set_plus_mono2 [intro]: "(C::('a::plus) set) <= D ==> E <= F ==>
4.136 + C \<oplus> E <= D \<oplus> F"
4.137 + by (auto simp add: set_plus_def)
4.138 +
4.139 +lemma set_plus_mono3 [intro]: "a : C ==> a +o D <= C \<oplus> D"
4.140 + by (auto simp add: elt_set_plus_def set_plus_def)
4.141 +
4.142 +lemma set_plus_mono4 [intro]: "(a::'a::comm_monoid_add) : C ==>
4.143 + a +o D <= D \<oplus> C"
4.144 + by (auto simp add: elt_set_plus_def set_plus_def add_ac)
4.145 +
4.146 +lemma set_plus_mono5: "a:C ==> B <= D ==> a +o B <= C \<oplus> D"
4.147 + apply (subgoal_tac "a +o B <= a +o D")
4.148 + apply (erule order_trans)
4.149 + apply (erule set_plus_mono3)
4.150 + apply (erule set_plus_mono)
4.151 + done
4.152 +
4.153 +lemma set_plus_mono_b: "C <= D ==> x : a +o C
4.154 + ==> x : a +o D"
4.155 + apply (frule set_plus_mono)
4.156 + apply auto
4.157 + done
4.158 +
4.159 +lemma set_plus_mono2_b: "C <= D ==> E <= F ==> x : C \<oplus> E ==>
4.160 + x : D \<oplus> F"
4.161 + apply (frule set_plus_mono2)
4.162 + prefer 2
4.163 + apply force
4.164 + apply assumption
4.165 + done
4.166 +
4.167 +lemma set_plus_mono3_b: "a : C ==> x : a +o D ==> x : C \<oplus> D"
4.168 + apply (frule set_plus_mono3)
4.169 + apply auto
4.170 + done
4.171 +
4.172 +lemma set_plus_mono4_b: "(a::'a::comm_monoid_add) : C ==>
4.173 + x : a +o D ==> x : D \<oplus> C"
4.174 + apply (frule set_plus_mono4)
4.175 + apply auto
4.176 + done
4.177 +
4.178 +lemma set_zero_plus [simp]: "(0::'a::comm_monoid_add) +o C = C"
4.179 + by (auto simp add: elt_set_plus_def)
4.180 +
4.181 +lemma set_zero_plus2: "(0::'a::comm_monoid_add) : A ==> B <= A \<oplus> B"
4.182 + apply (auto intro!: subsetI simp add: set_plus_def)
4.183 + apply (rule_tac x = 0 in bexI)
4.184 + apply (rule_tac x = x in bexI)
4.185 + apply (auto simp add: add_ac)
4.186 + done
4.187 +
4.188 +lemma set_plus_imp_minus: "(a::'a::ab_group_add) : b +o C ==> (a - b) : C"
4.189 + by (auto simp add: elt_set_plus_def add_ac diff_minus)
4.190 +
4.191 +lemma set_minus_imp_plus: "(a::'a::ab_group_add) - b : C ==> a : b +o C"
4.192 + apply (auto simp add: elt_set_plus_def add_ac diff_minus)
4.193 + apply (subgoal_tac "a = (a + - b) + b")
4.194 + apply (rule bexI, assumption, assumption)
4.195 + apply (auto simp add: add_ac)
4.196 + done
4.197 +
4.198 +lemma set_minus_plus: "((a::'a::ab_group_add) - b : C) = (a : b +o C)"
4.199 + by (rule iffI, rule set_minus_imp_plus, assumption, rule set_plus_imp_minus,
4.200 + assumption)
4.201 +
4.202 +lemma set_times_intro [intro]: "a : C ==> b : D ==> a * b : C \<otimes> D"
4.203 + by (auto simp add: set_times_def)
4.204 +
4.205 +lemma set_times_intro2 [intro!]: "b : C ==> a * b : a *o C"
4.206 + by (auto simp add: elt_set_times_def)
4.207 +
4.208 +lemma set_times_rearrange: "((a::'a::comm_monoid_mult) *o C) \<otimes>
4.209 + (b *o D) = (a * b) *o (C \<otimes> D)"
4.210 + apply (auto simp add: elt_set_times_def set_times_def)
4.211 + apply (rule_tac x = "ba * bb" in exI)
4.212 + apply (auto simp add: mult_ac)
4.213 + apply (rule_tac x = "aa * a" in exI)
4.214 + apply (auto simp add: mult_ac)
4.215 + done
4.216 +
4.217 +lemma set_times_rearrange2: "(a::'a::semigroup_mult) *o (b *o C) =
4.218 + (a * b) *o C"
4.219 + by (auto simp add: elt_set_times_def mult_assoc)
4.220 +
4.221 +lemma set_times_rearrange3: "((a::'a::semigroup_mult) *o B) \<otimes> C =
4.222 + a *o (B \<otimes> C)"
4.223 + apply (auto simp add: elt_set_times_def set_times_def)
4.224 + apply (blast intro: mult_ac)
4.225 + apply (rule_tac x = "a * aa" in exI)
4.226 + apply (rule conjI)
4.227 + apply (rule_tac x = "aa" in bexI)
4.228 + apply auto
4.229 + apply (rule_tac x = "ba" in bexI)
4.230 + apply (auto simp add: mult_ac)
4.231 + done
4.232 +
4.233 +theorem set_times_rearrange4: "C \<otimes> ((a::'a::comm_monoid_mult) *o D) =
4.234 + a *o (C \<otimes> D)"
4.235 + apply (auto intro!: subsetI simp add: elt_set_times_def set_times_def
4.236 + mult_ac)
4.237 + apply (rule_tac x = "aa * ba" in exI)
4.238 + apply (auto simp add: mult_ac)
4.239 + done
4.240 +
4.241 +theorems set_times_rearranges = set_times_rearrange set_times_rearrange2
4.242 + set_times_rearrange3 set_times_rearrange4
4.243 +
4.244 +lemma set_times_mono [intro]: "C <= D ==> a *o C <= a *o D"
4.245 + by (auto simp add: elt_set_times_def)
4.246 +
4.247 +lemma set_times_mono2 [intro]: "(C::('a::times) set) <= D ==> E <= F ==>
4.248 + C \<otimes> E <= D \<otimes> F"
4.249 + by (auto simp add: set_times_def)
4.250 +
4.251 +lemma set_times_mono3 [intro]: "a : C ==> a *o D <= C \<otimes> D"
4.252 + by (auto simp add: elt_set_times_def set_times_def)
4.253 +
4.254 +lemma set_times_mono4 [intro]: "(a::'a::comm_monoid_mult) : C ==>
4.255 + a *o D <= D \<otimes> C"
4.256 + by (auto simp add: elt_set_times_def set_times_def mult_ac)
4.257 +
4.258 +lemma set_times_mono5: "a:C ==> B <= D ==> a *o B <= C \<otimes> D"
4.259 + apply (subgoal_tac "a *o B <= a *o D")
4.260 + apply (erule order_trans)
4.261 + apply (erule set_times_mono3)
4.262 + apply (erule set_times_mono)
4.263 + done
4.264 +
4.265 +lemma set_times_mono_b: "C <= D ==> x : a *o C
4.266 + ==> x : a *o D"
4.267 + apply (frule set_times_mono)
4.268 + apply auto
4.269 + done
4.270 +
4.271 +lemma set_times_mono2_b: "C <= D ==> E <= F ==> x : C \<otimes> E ==>
4.272 + x : D \<otimes> F"
4.273 + apply (frule set_times_mono2)
4.274 + prefer 2
4.275 + apply force
4.276 + apply assumption
4.277 + done
4.278 +
4.279 +lemma set_times_mono3_b: "a : C ==> x : a *o D ==> x : C \<otimes> D"
4.280 + apply (frule set_times_mono3)
4.281 + apply auto
4.282 + done
4.283 +
4.284 +lemma set_times_mono4_b: "(a::'a::comm_monoid_mult) : C ==>
4.285 + x : a *o D ==> x : D \<otimes> C"
4.286 + apply (frule set_times_mono4)
4.287 + apply auto
4.288 + done
4.289 +
4.290 +lemma set_one_times [simp]: "(1::'a::comm_monoid_mult) *o C = C"
4.291 + by (auto simp add: elt_set_times_def)
4.292 +
4.293 +lemma set_times_plus_distrib: "(a::'a::semiring) *o (b +o C)=
4.294 + (a * b) +o (a *o C)"
4.295 + by (auto simp add: elt_set_plus_def elt_set_times_def ring_distribs)
4.296 +
4.297 +lemma set_times_plus_distrib2: "(a::'a::semiring) *o (B \<oplus> C) =
4.298 + (a *o B) \<oplus> (a *o C)"
4.299 + apply (auto simp add: set_plus_def elt_set_times_def ring_distribs)
4.300 + apply blast
4.301 + apply (rule_tac x = "b + bb" in exI)
4.302 + apply (auto simp add: ring_distribs)
4.303 + done
4.304 +
4.305 +lemma set_times_plus_distrib3: "((a::'a::semiring) +o C) \<otimes> D <=
4.306 + a *o D \<oplus> C \<otimes> D"
4.307 + apply (auto intro!: subsetI simp add:
4.308 + elt_set_plus_def elt_set_times_def set_times_def
4.309 + set_plus_def ring_distribs)
4.310 + apply auto
4.311 + done
4.312 +
4.313 +theorems set_times_plus_distribs =
4.314 + set_times_plus_distrib
4.315 + set_times_plus_distrib2
4.316 +
4.317 +lemma set_neg_intro: "(a::'a::ring_1) : (- 1) *o C ==>
4.318 + - a : C"
4.319 + by (auto simp add: elt_set_times_def)
4.320 +
4.321 +lemma set_neg_intro2: "(a::'a::ring_1) : C ==>
4.322 + - a : (- 1) *o C"
4.323 + by (auto simp add: elt_set_times_def)
4.324 +
4.325 +lemma set_plus_image:
4.326 + fixes S T :: "'n::semigroup_add set" shows "S \<oplus> T = (\<lambda>(x, y). x + y) ` (S \<times> T)"
4.327 + unfolding set_plus_def by (fastsimp simp: image_iff)
4.328 +
4.329 +lemma set_setsum_alt:
4.330 + assumes fin: "finite I"
4.331 + shows "setsum_set S I = {setsum s I |s. \<forall>i\<in>I. s i \<in> S i}"
4.332 + (is "_ = ?setsum I")
4.333 +using fin proof induct
4.334 + case (insert x F)
4.335 + have "setsum_set S (insert x F) = S x \<oplus> ?setsum F"
4.336 + using insert.hyps by auto
4.337 + also have "...= {s x + setsum s F |s. \<forall> i\<in>insert x F. s i \<in> S i}"
4.338 + unfolding set_plus_def
4.339 + proof safe
4.340 + fix y s assume "y \<in> S x" "\<forall>i\<in>F. s i \<in> S i"
4.341 + then show "\<exists>s'. y + setsum s F = s' x + setsum s' F \<and> (\<forall>i\<in>insert x F. s' i \<in> S i)"
4.342 + using insert.hyps
4.343 + by (intro exI[of _ "\<lambda>i. if i \<in> F then s i else y"]) (auto simp add: set_plus_def)
4.344 + qed auto
4.345 + finally show ?case
4.346 + using insert.hyps by auto
4.347 +qed auto
4.348 +
4.349 +lemma setsum_set_cond_linear:
4.350 + fixes f :: "('a::comm_monoid_add) set \<Rightarrow> ('b::comm_monoid_add) set"
4.351 + assumes [intro!]: "\<And>A B. P A \<Longrightarrow> P B \<Longrightarrow> P (A \<oplus> B)" "P {0}"
4.352 + and f: "\<And>A B. P A \<Longrightarrow> P B \<Longrightarrow> f (A \<oplus> B) = f A \<oplus> f B" "f {0} = {0}"
4.353 + assumes all: "\<And>i. i \<in> I \<Longrightarrow> P (S i)"
4.354 + shows "f (setsum_set S I) = setsum_set (f \<circ> S) I"
4.355 +proof cases
4.356 + assume "finite I" from this all show ?thesis
4.357 + proof induct
4.358 + case (insert x F)
4.359 + from `finite F` `\<And>i. i \<in> insert x F \<Longrightarrow> P (S i)` have "P (setsum_set S F)"
4.360 + by induct auto
4.361 + with insert show ?case
4.362 + by (simp, subst f) auto
4.363 + qed (auto intro!: f)
4.364 +qed (auto intro!: f)
4.365 +
4.366 +lemma setsum_set_linear:
4.367 + fixes f :: "('a::comm_monoid_add) set => ('b::comm_monoid_add) set"
4.368 + assumes "\<And>A B. f(A) \<oplus> f(B) = f(A \<oplus> B)" "f {0} = {0}"
4.369 + shows "f (setsum_set S I) = setsum_set (f \<circ> S) I"
4.370 + using setsum_set_cond_linear[of "\<lambda>x. True" f I S] assms by auto
4.371 +
4.372 +end
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/src/Tools/interpretation_with_defs.ML Sat Jan 15 20:05:29 2011 +0100
5.3 @@ -0,0 +1,96 @@
5.4 +(* Title: Tools/interpretation_with_defs.ML
5.5 + Author: Florian Haftmann, TU Muenchen
5.6 +
5.7 +Interpretation accompanied with mixin definitions. EXPERIMENTAL.
5.8 +*)
5.9 +
5.10 +signature INTERPRETATION_WITH_DEFS =
5.11 +sig
5.12 + val interpretation: Expression.expression_i ->
5.13 + (Attrib.binding * ((binding * mixfix) * term)) list -> (Attrib.binding * term) list ->
5.14 + theory -> Proof.state
5.15 + val interpretation_cmd: Expression.expression ->
5.16 + (Attrib.binding * ((binding * mixfix) * string)) list -> (Attrib.binding * string) list ->
5.17 + theory -> Proof.state
5.18 +end;
5.19 +
5.20 +structure Interpretation_With_Defs : INTERPRETATION_WITH_DEFS =
5.21 +struct
5.22 +
5.23 +fun note_eqns_register deps witss def_eqns attrss eqns export export' context =
5.24 + let
5.25 + fun meta_rewrite context =
5.26 + map (Local_Defs.meta_rewrite_rule (Context.proof_of context) #> Drule.abs_def) o
5.27 + maps snd;
5.28 + in
5.29 + context
5.30 + |> Element.generic_note_thmss Thm.lemmaK
5.31 + (attrss ~~ map (fn eqn => [([Morphism.thm (export' $> export) eqn], [])]) eqns)
5.32 + |-> (fn facts => `(fn context => meta_rewrite context facts))
5.33 + |-> (fn eqns => fold (fn ((dep, morph), wits) =>
5.34 + fn context =>
5.35 + Locale.add_registration (dep, morph $> Element.satisfy_morphism
5.36 + (map (Element.morph_witness export') wits))
5.37 + (Element.eq_morphism (Context.theory_of context) (def_eqns @ eqns) |>
5.38 + Option.map (rpair true))
5.39 + export context) (deps ~~ witss))
5.40 + end;
5.41 +
5.42 +local
5.43 +
5.44 +fun gen_interpretation prep_expr prep_decl parse_term parse_prop prep_attr
5.45 + expression raw_defs raw_eqns theory =
5.46 + let
5.47 + val (_, (_, defs_ctxt)) =
5.48 + prep_decl expression I [] (ProofContext.init_global theory);
5.49 +
5.50 + val rhss = map (parse_term defs_ctxt o snd o snd) raw_defs
5.51 + |> Syntax.check_terms defs_ctxt;
5.52 + val defs = map2 (fn (binding_thm, (binding_syn, _)) => fn rhs =>
5.53 + (binding_syn, (binding_thm, rhs))) raw_defs rhss;
5.54 +
5.55 + val (def_eqns, theory') = theory
5.56 + |> Named_Target.theory_init
5.57 + |> fold_map (Local_Theory.define) defs
5.58 + |>> map (Thm.symmetric o snd o snd)
5.59 + |> Local_Theory.exit_result_global (map o Morphism.thm);
5.60 +
5.61 + val ((propss, deps, export), expr_ctxt) = theory'
5.62 + |> ProofContext.init_global
5.63 + |> prep_expr expression;
5.64 +
5.65 + val eqns = map (parse_prop expr_ctxt o snd) raw_eqns
5.66 + |> Syntax.check_terms expr_ctxt;
5.67 + val attrss = map ((apsnd o map) (prep_attr theory) o fst) raw_eqns;
5.68 + val goal_ctxt = fold Variable.auto_fixes eqns expr_ctxt;
5.69 + val export' = Variable.export_morphism goal_ctxt expr_ctxt;
5.70 +
5.71 + fun after_qed witss eqns =
5.72 + (ProofContext.background_theory o Context.theory_map)
5.73 + (note_eqns_register deps witss def_eqns attrss eqns export export');
5.74 +
5.75 + in Element.witness_proof_eqs after_qed propss eqns goal_ctxt end;
5.76 +
5.77 +in
5.78 +
5.79 +fun interpretation x = gen_interpretation Expression.cert_goal_expression
5.80 + Expression.cert_declaration (K I) (K I) (K I) x;
5.81 +fun interpretation_cmd x = gen_interpretation Expression.read_goal_expression
5.82 + Expression.read_declaration Syntax.parse_term Syntax.parse_prop Attrib.intern_src x;
5.83 +
5.84 +end;
5.85 +
5.86 +val definesK = "defines";
5.87 +val _ = Keyword.keyword definesK;
5.88 +
5.89 +val _ =
5.90 + Outer_Syntax.command "interpretation"
5.91 + "prove interpretation of locale expression in theory" Keyword.thy_goal
5.92 + (Parse.!!! (Parse_Spec.locale_expression true) --
5.93 + Scan.optional (Parse.$$$ definesK |-- Parse.and_list1 (Parse_Spec.opt_thm_name ":"
5.94 + -- ((Parse.binding -- Parse.opt_mixfix') --| Parse.$$$ "is" -- Parse.term))) [] --
5.95 + Scan.optional (Parse.where_ |-- Parse.and_list1 (Parse_Spec.opt_thm_name ":" -- Parse.prop)) []
5.96 + >> (fn ((expr, defs), equations) => Toplevel.print o
5.97 + Toplevel.theory_to_proof (interpretation_cmd expr defs equations)));
5.98 +
5.99 +end;