112 |
112 |
113 locale ab_group_add_on_with = comm_monoid_add_on_with + |
113 locale ab_group_add_on_with = comm_monoid_add_on_with + |
114 fixes mns um |
114 fixes mns um |
115 assumes ab_left_minus: "a \<in> S \<Longrightarrow> pls (um a) a = z" |
115 assumes ab_left_minus: "a \<in> S \<Longrightarrow> pls (um a) a = z" |
116 assumes ab_diff_conv_add_uminus: "a \<in> S \<Longrightarrow> b \<in> S \<Longrightarrow> mns a b = pls a (um b)" |
116 assumes ab_diff_conv_add_uminus: "a \<in> S \<Longrightarrow> b \<in> S \<Longrightarrow> mns a b = pls a (um b)" |
|
117 assumes uminus_mem: "a \<in> S \<Longrightarrow> um a \<in> S" |
117 |
118 |
118 lemma ab_group_add_on_with_Ball_def: |
119 lemma ab_group_add_on_with_Ball_def: |
119 "ab_group_add_on_with S pls z mns um \<longleftrightarrow> comm_monoid_add_on_with S pls z \<and> |
120 "ab_group_add_on_with S pls z mns um \<longleftrightarrow> comm_monoid_add_on_with S pls z \<and> |
120 (\<forall>a\<in>S. pls (um a) a = z) \<and> (\<forall>a\<in>S. \<forall>b\<in>S. mns a b = pls a (um b))" |
121 (\<forall>a\<in>S. pls (um a) a = z) \<and> (\<forall>a\<in>S. \<forall>b\<in>S. mns a b = pls a (um b)) \<and> (\<forall>a\<in>S. um a \<in> S)" |
121 by (auto simp: ab_group_add_on_with_def ab_group_add_on_with_axioms_def) |
122 by (auto simp: ab_group_add_on_with_def ab_group_add_on_with_axioms_def) |
122 |
123 |
123 lemma ab_group_add_transfer[transfer_rule]: |
124 lemma ab_group_add_transfer[transfer_rule]: |
124 includes lifting_syntax |
125 includes lifting_syntax |
125 assumes [transfer_rule]: "right_total A" "bi_unique A" |
126 assumes [transfer_rule]: "right_total A" "bi_unique A" |
126 shows |
127 shows "((A ===> A ===> A) ===> A ===> (A ===> A ===> A) ===> (A ===> A)===> (=)) |
127 "((A ===> A ===> A) ===> A ===> (A ===> A ===> A) ===> (A ===> A)===> (=)) |
|
128 (ab_group_add_on_with (Collect (Domainp A))) class.ab_group_add" |
128 (ab_group_add_on_with (Collect (Domainp A))) class.ab_group_add" |
129 unfolding class.ab_group_add_def class.ab_group_add_axioms_def ab_group_add_on_with_Ball_def |
129 proof (intro rel_funI) |
130 by transfer_prover |
130 fix p p' z z' m m' um um' |
|
131 assume [transfer_rule]: |
|
132 "(A ===> A ===> A) p p'" "A z z'" "(A ===> A ===> A) m m'" |
|
133 and um[transfer_rule]: "(A ===> A) um um'" |
|
134 show "ab_group_add_on_with (Collect (Domainp A)) p z m um = class.ab_group_add p' z' m' um'" |
|
135 unfolding class.ab_group_add_def class.ab_group_add_axioms_def ab_group_add_on_with_Ball_def |
|
136 by transfer (use um in \<open>auto simp: rel_fun_def\<close>) |
|
137 qed |
131 |
138 |
132 lemma ab_group_add_on_with_transfer[transfer_rule]: |
139 lemma ab_group_add_on_with_transfer[transfer_rule]: |
133 includes lifting_syntax |
140 includes lifting_syntax |
134 assumes [transfer_rule]: "right_total A" "bi_unique A" |
141 assumes [transfer_rule]: "right_total A" "bi_unique A" |
135 shows |
142 shows |
146 Finite_Set.fold (pls o f) z S else z)" |
153 Finite_Set.fold (pls o f) z S else z)" |
147 |
154 |
148 lemma sum_with_empty[simp]: "sum_with pls z f {} = z" |
155 lemma sum_with_empty[simp]: "sum_with pls z f {} = z" |
149 by (auto simp: sum_with_def) |
156 by (auto simp: sum_with_def) |
150 |
157 |
151 lemma sum_with: "sum = sum_with (+) 0" |
158 lemma sum_with_cases[case_names comm zero]: |
152 proof (intro ext) |
159 "P (sum_with pls z f S)" |
153 fix f::"'a\<Rightarrow>'b" and X::"'a set" |
160 if "\<And>C. f ` S \<subseteq> C \<Longrightarrow> comm_monoid_add_on_with C pls z \<Longrightarrow> P (Finite_Set.fold (pls o f) z S)" |
154 have ex: "\<exists>C. f ` X \<subseteq> C \<and> comm_monoid_add_on_with C (+) 0" |
161 "(\<And>C. comm_monoid_add_on_with C pls z \<Longrightarrow> (\<exists>s\<in>S. f s \<notin> C)) \<Longrightarrow> P z" |
155 by (auto intro!: exI[where x=UNIV] comm_monoid_add_on_with) |
162 using that |
156 then show "sum f X = sum_with (+) 0 f X" |
163 by (auto simp: sum_with_def) |
157 unfolding sum.eq_fold sum_with_def |
164 |
|
165 lemma sum_with: "sum f S = sum_with (+) 0 f S" |
|
166 proof (induction rule: sum_with_cases) |
|
167 case (comm C) |
|
168 then show ?case |
|
169 unfolding sum.eq_fold |
158 by simp |
170 by simp |
159 qed |
171 next |
160 |
172 case zero |
161 context fixes C pls z assumes comm_monoid_add_on_with: "comm_monoid_add_on_with C pls z" begin |
173 from zero[OF comm_monoid_add_on_with] |
|
174 show ?case by simp |
|
175 qed |
|
176 |
|
177 context comm_monoid_add_on_with begin |
|
178 |
|
179 lemma sum_with_infinite: "infinite A \<Longrightarrow> sum_with pls z g A = z" |
|
180 by (induction rule: sum_with_cases) auto |
162 |
181 |
163 lemmas comm_monoid_add_unfolded = |
182 lemmas comm_monoid_add_unfolded = |
164 comm_monoid_add_on_with[unfolded |
183 comm_monoid_add_on_with_axioms[unfolded |
165 comm_monoid_add_on_with_Ball_def ab_semigroup_add_on_with_Ball_def semigroup_add_on_with_Ball_def] |
184 comm_monoid_add_on_with_Ball_def ab_semigroup_add_on_with_Ball_def semigroup_add_on_with_Ball_def] |
166 |
185 |
167 private abbreviation "pls' \<equiv> \<lambda>x y. pls (if x \<in> C then x else z) (if y \<in> C then y else z)" |
186 context begin |
168 |
187 |
169 lemma fold_pls'_mem: "Finite_Set.fold (pls' \<circ> g) z A \<in> C" |
188 private abbreviation "pls' \<equiv> \<lambda>x y. pls (if x \<in> S then x else z) (if y \<in> S then y else z)" |
170 if "g ` A \<subseteq> C" |
189 |
|
190 lemma fold_pls'_mem: "Finite_Set.fold (pls' \<circ> g) z A \<in> S" |
|
191 if "g ` A \<subseteq> S" |
171 proof cases |
192 proof cases |
172 assume A: "finite A" |
193 assume A: "finite A" |
173 interpret comp_fun_commute "pls' o g" |
194 interpret comp_fun_commute "pls' o g" |
174 using comm_monoid_add_unfolded that |
195 using comm_monoid_add_unfolded that |
175 by unfold_locales auto |
196 by unfold_locales auto |
176 from fold_graph_fold[OF A] have "fold_graph (pls' \<circ> g) z A (Finite_Set.fold (pls' \<circ> g) z A)" . |
197 from fold_graph_fold[OF A] have "fold_graph (pls' \<circ> g) z A (Finite_Set.fold (pls' \<circ> g) z A)" . |
177 from fold_graph_closed_lemma[OF this, of C "pls' \<circ> g"] comm_monoid_add_unfolded |
198 from fold_graph_closed_lemma[OF this, of S "pls' \<circ> g"] comm_monoid_add_unfolded |
178 show ?thesis |
199 show ?thesis |
179 by auto |
200 by auto |
180 qed (use comm_monoid_add_unfolded in simp) |
201 qed (use comm_monoid_add_unfolded in simp) |
181 |
202 |
182 lemma fold_pls'_eq: "Finite_Set.fold (pls' \<circ> g) z A = Finite_Set.fold (pls \<circ> g) z A" |
203 lemma fold_pls'_eq: "Finite_Set.fold (pls' \<circ> g) z A = Finite_Set.fold (pls \<circ> g) z A" |
183 if "g ` A \<subseteq> C" |
204 if "g ` A \<subseteq> S" |
184 using comm_monoid_add_unfolded that |
205 using comm_monoid_add_unfolded that |
185 by (intro fold_closed_eq[where B=C]) auto |
206 by (intro fold_closed_eq[where B=S]) auto |
186 |
207 |
187 lemma sum_with_mem: "sum_with pls z g A \<in> C" if "g ` A \<subseteq> C" |
208 lemma sum_with_mem: "sum_with pls z g A \<in> S" if "g ` A \<subseteq> S" |
188 proof - |
209 proof - |
189 interpret comp_fun_commute "pls' o g" |
210 interpret comp_fun_commute "pls' o g" |
190 using comm_monoid_add_unfolded that |
211 using comm_monoid_add_unfolded that |
191 by unfold_locales auto |
212 by unfold_locales auto |
192 have "\<exists>C. g ` A \<subseteq> C \<and> comm_monoid_add_on_with C pls z" using that comm_monoid_add_on_with by auto |
213 have "\<exists>C. g ` A \<subseteq> C \<and> comm_monoid_add_on_with C pls z" |
|
214 using that comm_monoid_add_on_with_axioms by auto |
193 then show ?thesis |
215 then show ?thesis |
194 using fold_pls'_mem[OF that] |
216 using fold_pls'_mem[OF that] |
195 by (simp add: sum_with_def fold_pls'_eq that) |
217 by (simp add: sum_with_def fold_pls'_eq that) |
196 qed |
218 qed |
197 |
219 |
198 lemma sum_with_insert: |
220 lemma sum_with_insert: |
199 "sum_with pls z g (insert x A) = pls (g x) (sum_with pls z g A)" |
221 "sum_with pls z g (insert x A) = pls (g x) (sum_with pls z g A)" |
200 if g_into: "g x \<in> C" "g ` A \<subseteq> C" |
222 if g_into: "g x \<in> S" "g ` A \<subseteq> S" |
201 and A: "finite A" and x: "x \<notin> A" |
223 and A: "finite A" and x: "x \<notin> A" |
202 proof - |
224 proof - |
203 interpret comp_fun_commute "pls' o g" |
225 interpret comp_fun_commute "pls' o g" |
204 using comm_monoid_add_unfolded g_into |
226 using comm_monoid_add_unfolded g_into |
205 by unfold_locales auto |
227 by unfold_locales auto |
274 obtain C where comm: "comm_monoid_add_on_with C pls zero" |
298 obtain C where comm: "comm_monoid_add_on_with C pls zero" |
275 and C: "f ` S \<subseteq> C" |
299 and C: "f ` S \<subseteq> C" |
276 and "Domainp (rel_set A) C" |
300 and "Domainp (rel_set A) C" |
277 by auto |
301 by auto |
278 then obtain C' where [transfer_rule]: "rel_set A C C'" by auto |
302 then obtain C' where [transfer_rule]: "rel_set A C C'" by auto |
|
303 interpret comm: comm_monoid_add_on_with C pls zero by fact |
279 have C': "g ` T \<subseteq> C'" |
304 have C': "g ` T \<subseteq> C'" |
280 by transfer (rule C) |
305 by transfer (rule C) |
281 have comm': "comm_monoid_add_on_with C' pls' zero'" |
306 have comm': "comm_monoid_add_on_with C' pls' zero'" |
282 by transfer (rule comm) |
307 by transfer (rule comm) |
|
308 then interpret comm': comm_monoid_add_on_with C' pls' zero' . |
283 from C' comm' have ex_comm': "\<exists>C. g ` T \<subseteq> C \<and> comm_monoid_add_on_with C pls' zero'" by auto |
309 from C' comm' have ex_comm': "\<exists>C. g ` T \<subseteq> C \<and> comm_monoid_add_on_with C pls' zero'" by auto |
284 show ?thesis |
310 show ?thesis |
285 using transfer_T C C' |
311 using transfer_T C C' |
286 proof (induction S arbitrary: T rule: infinite_finite_induct) |
312 proof (induction S arbitrary: T rule: infinite_finite_induct) |
287 case (infinite S) |
313 case (infinite S) |
314 by simp |
340 by simp |
315 from insert.prems have "f ` F \<subseteq> C" "g ` T' \<subseteq> C'" |
341 from insert.prems have "f ` F \<subseteq> C" "g ` T' \<subseteq> C'" |
316 by (auto simp: T'_def) |
342 by (auto simp: T'_def) |
317 from insert.IH[OF transfer_T' this] have [transfer_rule]: "A sF sT" by (auto simp: sF_def sT_def o_def) |
343 from insert.IH[OF transfer_T' this] have [transfer_rule]: "A sF sT" by (auto simp: sF_def sT_def o_def) |
318 have rew: "(sum_with pls zero f (insert x F)) = pls (f x) (sum_with pls zero f F)" |
344 have rew: "(sum_with pls zero f (insert x F)) = pls (f x) (sum_with pls zero f F)" |
319 apply (subst sum_with_insert[OF comm]) |
345 apply (subst comm.sum_with_insert) |
320 subgoal using insert.prems by auto |
346 subgoal using insert.prems by auto |
321 subgoal using insert.prems by auto |
347 subgoal using insert.prems by auto |
322 subgoal by fact |
348 subgoal by fact |
323 subgoal by fact |
349 subgoal by fact |
324 subgoal by auto |
350 subgoal by auto |
325 done |
351 done |
326 have rew': "(sum_with pls' zero' g (insert y T')) = pls' (g y) (sum_with pls' zero' g T')" |
352 have rew': "(sum_with pls' zero' g (insert y T')) = pls' (g y) (sum_with pls' zero' g T')" |
327 apply (subst sum_with_insert[OF comm']) |
353 apply (subst comm'.sum_with_insert) |
328 subgoal |
354 subgoal |
329 apply transfer |
355 apply transfer |
330 using insert.prems by auto |
356 using insert.prems by auto |
331 subgoal |
357 subgoal |
332 apply transfer |
358 apply transfer |