src/HOL/Finite_Set.thy
changeset 42272 a46a13b4be5f
parent 42207 2bda5eddadf3
child 42715 fe8ee8099b47
equal deleted inserted replaced
42271:7d08265f181d 42272:a46a13b4be5f
   559 @{term "if finite A then THE y. fold_graph f z A y else e"}.
   559 @{term "if finite A then THE y. fold_graph f z A y else e"}.
   560 It allows the removal of finiteness assumptions from the theorems
   560 It allows the removal of finiteness assumptions from the theorems
   561 @{text fold_comm}, @{text fold_reindex} and @{text fold_distrib}.
   561 @{text fold_comm}, @{text fold_reindex} and @{text fold_distrib}.
   562 The proofs become ugly. It is not worth the effort. (???) *}
   562 The proofs become ugly. It is not worth the effort. (???) *}
   563 
   563 
   564 
       
   565 lemma Diff1_fold_graph:
       
   566   "fold_graph f z (A - {x}) y \<Longrightarrow> x \<in> A \<Longrightarrow> fold_graph f z A (f x y)"
       
   567 by (erule insert_Diff [THEN subst], rule fold_graph.intros, auto)
       
   568 
       
   569 lemma fold_graph_imp_finite: "fold_graph f z A x \<Longrightarrow> finite A"
       
   570 by (induct set: fold_graph) auto
       
   571 
       
   572 lemma finite_imp_fold_graph: "finite A \<Longrightarrow> \<exists>x. fold_graph f z A x"
   564 lemma finite_imp_fold_graph: "finite A \<Longrightarrow> \<exists>x. fold_graph f z A x"
   573 by (induct rule: finite_induct) auto
   565 by (induct rule: finite_induct) auto
   574 
   566 
   575 
   567 
   576 subsubsection{*From @{const fold_graph} to @{term fold}*}
   568 subsubsection{*From @{const fold_graph} to @{term fold}*}
   615 
   607 
   616 lemma fold_equality:
   608 lemma fold_equality:
   617   "fold_graph f z A y \<Longrightarrow> fold f z A = y"
   609   "fold_graph f z A y \<Longrightarrow> fold f z A = y"
   618 by (unfold fold_def) (blast intro: fold_graph_determ)
   610 by (unfold fold_def) (blast intro: fold_graph_determ)
   619 
   611 
   620 lemma fold_graph_fold: "finite A \<Longrightarrow> fold_graph f z A (fold f z A)"
   612 lemma fold_graph_fold:
   621 unfolding fold_def
   613   assumes "finite A"
   622 apply (rule theI')
   614   shows "fold_graph f z A (fold f z A)"
   623 apply (rule ex_ex1I)
   615 proof -
   624 apply (erule finite_imp_fold_graph)
   616   from assms have "\<exists>x. fold_graph f z A x" by (rule finite_imp_fold_graph)
   625 apply (erule (1) fold_graph_determ)
   617   moreover note fold_graph_determ
   626 done
   618   ultimately have "\<exists>!x. fold_graph f z A x" by (rule ex_ex1I)
       
   619   then have "fold_graph f z A (The (fold_graph f z A))" by (rule theI')
       
   620   then show ?thesis by (unfold fold_def)
       
   621 qed
   627 
   622 
   628 text{* The base case for @{text fold}: *}
   623 text{* The base case for @{text fold}: *}
   629 
   624 
   630 lemma (in -) fold_empty [simp]: "fold f z {} = z"
   625 lemma (in -) fold_empty [simp]: "fold f z {} = z"
   631 by (unfold fold_def) blast
   626 by (unfold fold_def) blast