src/ZF/Induct/FoldSet.thy
author wenzelm
Wed, 13 Jul 2005 16:07:35 +0200
changeset 16813 67140ae50e77
parent 16417 9bc16273c2d4
child 24893 b8ef7afe3a6b
permissions -rw-r--r--
removed ad-hoc atp_hook, cal_atp; removed depth_of; tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12610
8b9845807f77 tuned document sources;
wenzelm
parents: 12089
diff changeset
     1
(*  Title:      ZF/Induct/FoldSet.thy
12089
34e7693271a9 Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
diff changeset
     2
    ID:         $Id$
34e7693271a9 Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
diff changeset
     3
    Author:     Sidi O Ehmety, Cambridge University Computer Laboratory
34e7693271a9 Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
diff changeset
     4
34e7693271a9 Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
diff changeset
     5
34e7693271a9 Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
diff changeset
     6
A "fold" functional for finite sets.  For n non-negative we have
34e7693271a9 Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
diff changeset
     7
fold f e {x1,...,xn} = f x1 (... (f xn e)) where f is at
34e7693271a9 Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
diff changeset
     8
least left-commutative.  
34e7693271a9 Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
diff changeset
     9
*)
34e7693271a9 Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
diff changeset
    10
16417
9bc16273c2d4 migrated theory headers to new format
haftmann
parents: 14071
diff changeset
    11
theory FoldSet imports Main begin
12089
34e7693271a9 Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
diff changeset
    12
34e7693271a9 Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
diff changeset
    13
consts fold_set :: "[i, i, [i,i]=>i, i] => i"
34e7693271a9 Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
diff changeset
    14
34e7693271a9 Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
diff changeset
    15
inductive
34e7693271a9 Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
diff changeset
    16
  domains "fold_set(A, B, f,e)" <= "Fin(A)*B"
14071
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    17
  intros
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    18
    emptyI: "e\<in>B ==> <0, e>\<in>fold_set(A, B, f,e)"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    19
    consI:  "[| x\<in>A; x \<notin>C;  <C,y> : fold_set(A, B,f,e); f(x,y):B |]
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    20
		==>  <cons(x,C), f(x,y)>\<in>fold_set(A, B, f, e)"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    21
  type_intros Fin.intros
12089
34e7693271a9 Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
diff changeset
    22
  
34e7693271a9 Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
diff changeset
    23
constdefs
34e7693271a9 Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
diff changeset
    24
  
34e7693271a9 Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
diff changeset
    25
  fold :: "[i, [i,i]=>i, i, i] => i"  ("fold[_]'(_,_,_')")
14071
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    26
   "fold[B](f,e, A) == THE x. <A, x>\<in>fold_set(A, B, f,e)"
12089
34e7693271a9 Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
diff changeset
    27
34e7693271a9 Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
diff changeset
    28
   setsum :: "[i=>i, i] => i"
14071
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    29
   "setsum(g, C) == if Finite(C) then
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    30
                     fold[int](%x y. g(x) $+ y, #0, C) else #0"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    31
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    32
(** foldSet **)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    33
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    34
inductive_cases empty_fold_setE: "<0, x> : fold_set(A, B, f,e)"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    35
inductive_cases cons_fold_setE: "<cons(x,C), y> : fold_set(A, B, f,e)"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    36
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    37
(* add-hoc lemmas *)                                                
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    38
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    39
lemma cons_lemma1: "[| x\<notin>C; x\<notin>B |] ==> cons(x,B)=cons(x,C) <-> B = C"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    40
by (auto elim: equalityE)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    41
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    42
lemma cons_lemma2: "[| cons(x, B)=cons(y, C); x\<noteq>y; x\<notin>B; y\<notin>C |]  
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    43
    ==>  B - {y} = C-{x} & x\<in>C & y\<in>B"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    44
apply (auto elim: equalityE)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    45
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    46
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    47
(* fold_set monotonicity *)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    48
lemma fold_set_mono_lemma:
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    49
     "<C, x> : fold_set(A, B, f, e)  
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    50
      ==> ALL D. A<=D --> <C, x> : fold_set(D, B, f, e)"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    51
apply (erule fold_set.induct)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    52
apply (auto intro: fold_set.intros)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    53
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    54
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    55
lemma fold_set_mono: " C<=A ==> fold_set(C, B, f, e) <= fold_set(A, B, f, e)"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    56
apply clarify
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    57
apply (frule fold_set.dom_subset [THEN subsetD], clarify)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    58
apply (auto dest: fold_set_mono_lemma)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    59
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    60
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    61
lemma fold_set_lemma:
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    62
     "<C, x>\<in>fold_set(A, B, f, e) ==> <C, x>\<in>fold_set(C, B, f, e) & C<=A"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    63
apply (erule fold_set.induct)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    64
apply (auto intro!: fold_set.intros intro: fold_set_mono [THEN subsetD])
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    65
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    66
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    67
(* Proving that fold_set is deterministic *)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    68
lemma Diff1_fold_set:
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    69
     "[| <C-{x},y> : fold_set(A, B, f,e);  x\<in>C; x\<in>A; f(x, y):B |]  
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    70
      ==> <C, f(x, y)> : fold_set(A, B, f, e)"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    71
apply (frule fold_set.dom_subset [THEN subsetD])
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    72
apply (erule cons_Diff [THEN subst], rule fold_set.intros, auto)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    73
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    74
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    75
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    76
locale fold_typing =
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    77
 fixes A and B and e and f
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    78
 assumes ftype [intro,simp]:  "[|x \<in> A; y \<in> B|] ==> f(x,y) \<in> B"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    79
     and etype [intro,simp]:  "e \<in> B"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    80
     and fcomm:  "[|x \<in> A; y \<in> A; z \<in> B|] ==> f(x, f(y, z))=f(y, f(x, z))"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    81
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    82
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    83
lemma (in fold_typing) Fin_imp_fold_set:
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    84
     "C\<in>Fin(A) ==> (EX x. <C, x> : fold_set(A, B, f,e))"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    85
apply (erule Fin_induct)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    86
apply (auto dest: fold_set.dom_subset [THEN subsetD] 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    87
            intro: fold_set.intros etype ftype)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    88
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    89
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    90
lemma Diff_sing_imp:
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    91
     "[|C - {b} = D - {a}; a \<noteq> b; b \<in> C|] ==> C = cons(b,D) - {a}"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    92
by (blast elim: equalityE)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    93
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    94
lemma (in fold_typing) fold_set_determ_lemma [rule_format]: 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    95
"n\<in>nat
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    96
 ==> ALL C. |C|<n -->  
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    97
   (ALL x. <C, x> : fold_set(A, B, f,e)--> 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    98
           (ALL y. <C, y> : fold_set(A, B, f,e) --> y=x))"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
    99
apply (erule nat_induct)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   100
 apply (auto simp add: le_iff)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   101
apply (erule fold_set.cases)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   102
 apply (force elim!: empty_fold_setE)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   103
apply (erule fold_set.cases)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   104
 apply (force elim!: empty_fold_setE, clarify)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   105
(*force simplification of "|C| < |cons(...)|"*)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   106
apply (frule_tac a = Ca in fold_set.dom_subset [THEN subsetD, THEN SigmaD1])
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   107
apply (frule_tac a = Cb in fold_set.dom_subset [THEN subsetD, THEN SigmaD1])
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   108
apply (simp add: Fin_into_Finite [THEN Finite_imp_cardinal_cons])
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   109
apply (case_tac "x=xb", auto) 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   110
apply (simp add: cons_lemma1, blast)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   111
txt{*case @{term "x\<noteq>xb"}*}
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   112
apply (drule cons_lemma2, safe)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   113
apply (frule Diff_sing_imp, assumption+) 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   114
txt{** LEVEL 17*}
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   115
apply (subgoal_tac "|Ca| le |Cb|")
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   116
 prefer 2
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   117
 apply (rule succ_le_imp_le)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   118
 apply (simp add: Fin_into_Finite Finite_imp_succ_cardinal_Diff 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   119
                  Fin_into_Finite [THEN Finite_imp_cardinal_cons])
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   120
apply (rule_tac C1 = "Ca-{xb}" in Fin_imp_fold_set [THEN exE])
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   121
 apply (blast intro: Diff_subset [THEN Fin_subset])
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   122
txt{** LEVEL 24 **}
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   123
apply (frule Diff1_fold_set, blast, blast)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   124
apply (blast dest!: ftype fold_set.dom_subset [THEN subsetD])
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   125
apply (subgoal_tac "ya = f(xb,xa) ")
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   126
 prefer 2 apply (blast del: equalityCE)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   127
apply (subgoal_tac "<Cb-{x}, xa> : fold_set(A,B,f,e)")
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   128
 prefer 2 apply simp
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   129
apply (subgoal_tac "yb = f (x, xa) ")
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   130
 apply (drule_tac [2] C = Cb in Diff1_fold_set, simp_all)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   131
  apply (blast intro: fcomm dest!: fold_set.dom_subset [THEN subsetD])
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   132
 apply (blast intro: ftype dest!: fold_set.dom_subset [THEN subsetD], blast) 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   133
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   134
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   135
lemma (in fold_typing) fold_set_determ: 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   136
     "[| <C, x>\<in>fold_set(A, B, f, e);  
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   137
         <C, y>\<in>fold_set(A, B, f, e)|] ==> y=x"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   138
apply (frule fold_set.dom_subset [THEN subsetD], clarify)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   139
apply (drule Fin_into_Finite)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   140
apply (unfold Finite_def, clarify)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   141
apply (rule_tac n = "succ (n)" in fold_set_determ_lemma) 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   142
apply (auto intro: eqpoll_imp_lepoll [THEN lepoll_cardinal_le])
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   143
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   144
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   145
(** The fold function **)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   146
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   147
lemma (in fold_typing) fold_equality: 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   148
     "<C,y> : fold_set(A,B,f,e) ==> fold[B](f,e,C) = y"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   149
apply (unfold fold_def)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   150
apply (frule fold_set.dom_subset [THEN subsetD], clarify)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   151
apply (rule the_equality)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   152
 apply (rule_tac [2] A=C in fold_typing.fold_set_determ)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   153
apply (force dest: fold_set_lemma)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   154
apply (auto dest: fold_set_lemma)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   155
apply (simp add: fold_typing_def, auto) 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   156
apply (auto dest: fold_set_lemma intro: ftype etype fcomm)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   157
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   158
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   159
lemma fold_0 [simp]: "e : B ==> fold[B](f,e,0) = e"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   160
apply (unfold fold_def)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   161
apply (blast elim!: empty_fold_setE intro: fold_set.intros)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   162
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   163
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   164
text{*This result is the right-to-left direction of the subsequent result*}
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   165
lemma (in fold_typing) fold_set_imp_cons: 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   166
     "[| <C, y> : fold_set(C, B, f, e); C : Fin(A); c : A; c\<notin>C |]
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   167
      ==> <cons(c, C), f(c,y)> : fold_set(cons(c, C), B, f, e)"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   168
apply (frule FinD [THEN fold_set_mono, THEN subsetD])
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   169
 apply assumption
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   170
apply (frule fold_set.dom_subset [of A, THEN subsetD])
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   171
apply (blast intro!: fold_set.consI intro: fold_set_mono [THEN subsetD])
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   172
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   173
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   174
lemma (in fold_typing) fold_cons_lemma [rule_format]: 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   175
"[| C : Fin(A); c : A; c\<notin>C |]   
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   176
     ==> <cons(c, C), v> : fold_set(cons(c, C), B, f, e) <->   
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   177
         (EX y. <C, y> : fold_set(C, B, f, e) & v = f(c, y))"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   178
apply auto
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   179
 prefer 2 apply (blast intro: fold_set_imp_cons) 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   180
 apply (frule_tac Fin.consI [of c, THEN FinD, THEN fold_set_mono, THEN subsetD], assumption+)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   181
apply (frule_tac fold_set.dom_subset [of A, THEN subsetD])
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   182
apply (drule FinD) 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   183
apply (rule_tac A1 = "cons(c,C)" and f1=f and B1=B and C1=C and e1=e in fold_typing.Fin_imp_fold_set [THEN exE])
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   184
apply (blast intro: fold_typing.intro ftype etype fcomm) 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   185
apply (blast intro: Fin_subset [of _ "cons(c,C)"] Finite_into_Fin 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   186
             dest: Fin_into_Finite)  
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   187
apply (rule_tac x = x in exI)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   188
apply (auto intro: fold_set.intros)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   189
apply (drule_tac fold_set_lemma [of C], blast)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   190
apply (blast intro!: fold_set.consI
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   191
             intro: fold_set_determ fold_set_mono [THEN subsetD] 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   192
             dest: fold_set.dom_subset [THEN subsetD]) 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   193
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   194
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   195
lemma (in fold_typing) fold_cons: 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   196
     "[| C\<in>Fin(A); c\<in>A; c\<notin>C|] 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   197
      ==> fold[B](f, e, cons(c, C)) = f(c, fold[B](f, e, C))"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   198
apply (unfold fold_def)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   199
apply (simp add: fold_cons_lemma)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   200
apply (rule the_equality, auto) 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   201
 apply (subgoal_tac [2] "\<langle>C, y\<rangle> \<in> fold_set(A, B, f, e)")
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   202
  apply (drule Fin_imp_fold_set)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   203
apply (auto dest: fold_set_lemma  simp add: fold_def [symmetric] fold_equality) 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   204
apply (blast intro: fold_set_mono [THEN subsetD] dest!: FinD) 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   205
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   206
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   207
lemma (in fold_typing) fold_type [simp,TC]: 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   208
     "C\<in>Fin(A) ==> fold[B](f,e,C):B"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   209
apply (erule Fin_induct)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   210
apply (simp_all add: fold_cons ftype etype)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   211
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   212
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   213
lemma (in fold_typing) fold_commute [rule_format]: 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   214
     "[| C\<in>Fin(A); c\<in>A |]  
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   215
      ==> (\<forall>y\<in>B. f(c, fold[B](f, y, C)) = fold[B](f, f(c, y), C))"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   216
apply (erule Fin_induct)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   217
apply (simp_all add: fold_typing.fold_cons [of A B _ f] 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   218
                     fold_typing.fold_type [of A B _ f] 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   219
                     fold_typing_def fcomm)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   220
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   221
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   222
lemma (in fold_typing) fold_nest_Un_Int: 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   223
     "[| C\<in>Fin(A); D\<in>Fin(A) |]
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   224
      ==> fold[B](f, fold[B](f, e, D), C) =
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   225
          fold[B](f, fold[B](f, e, (C Int D)), C Un D)"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   226
apply (erule Fin_induct, auto)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   227
apply (simp add: Un_cons Int_cons_left fold_type fold_commute
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   228
                 fold_typing.fold_cons [of A _ _ f] 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   229
                 fold_typing_def fcomm cons_absorb)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   230
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   231
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   232
lemma (in fold_typing) fold_nest_Un_disjoint:
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   233
     "[| C\<in>Fin(A); D\<in>Fin(A); C Int D = 0 |]  
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   234
      ==> fold[B](f,e,C Un D) =  fold[B](f, fold[B](f,e,D), C)"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   235
by (simp add: fold_nest_Un_Int)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   236
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   237
lemma Finite_cons_lemma: "Finite(C) ==> C\<in>Fin(cons(c, C))"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   238
apply (drule Finite_into_Fin)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   239
apply (blast intro: Fin_mono [THEN subsetD])
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   240
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   241
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   242
subsection{*The Operator @{term setsum}*}
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   243
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   244
lemma setsum_0 [simp]: "setsum(g, 0) = #0"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   245
by (simp add: setsum_def)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   246
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   247
lemma setsum_cons [simp]: 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   248
     "Finite(C) ==> 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   249
      setsum(g, cons(c,C)) = 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   250
        (if c : C then setsum(g,C) else g(c) $+ setsum(g,C))"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   251
apply (auto simp add: setsum_def Finite_cons cons_absorb)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   252
apply (rule_tac A = "cons (c, C)" in fold_typing.fold_cons)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   253
apply (auto intro: fold_typing.intro Finite_cons_lemma)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   254
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   255
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   256
lemma setsum_K0: "setsum((%i. #0), C) = #0"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   257
apply (case_tac "Finite (C) ")
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   258
 prefer 2 apply (simp add: setsum_def)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   259
apply (erule Finite_induct, auto)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   260
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   261
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   262
(*The reversed orientation looks more natural, but LOOPS as a simprule!*)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   263
lemma setsum_Un_Int:
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   264
     "[| Finite(C); Finite(D) |]  
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   265
      ==> setsum(g, C Un D) $+ setsum(g, C Int D)  
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   266
        = setsum(g, C) $+ setsum(g, D)"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   267
apply (erule Finite_induct)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   268
apply (simp_all add: Int_cons_right cons_absorb Un_cons Int_commute Finite_Un
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   269
                     Int_lower1 [THEN subset_Finite]) 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   270
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   271
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   272
lemma setsum_type [simp,TC]: "setsum(g, C):int"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   273
apply (case_tac "Finite (C) ")
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   274
 prefer 2 apply (simp add: setsum_def)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   275
apply (erule Finite_induct, auto)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   276
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   277
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   278
lemma setsum_Un_disjoint:
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   279
     "[| Finite(C); Finite(D); C Int D = 0 |]  
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   280
      ==> setsum(g, C Un D) = setsum(g, C) $+ setsum(g,D)"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   281
apply (subst setsum_Un_Int [symmetric])
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   282
apply (subgoal_tac [3] "Finite (C Un D) ")
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   283
apply (auto intro: Finite_Un)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   284
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   285
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   286
lemma Finite_RepFun [rule_format (no_asm)]:
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   287
     "Finite(I) ==> (\<forall>i\<in>I. Finite(C(i))) --> Finite(RepFun(I, C))"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   288
apply (erule Finite_induct, auto)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   289
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   290
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   291
lemma setsum_UN_disjoint [rule_format (no_asm)]:
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   292
     "Finite(I)  
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   293
      ==> (\<forall>i\<in>I. Finite(C(i))) -->  
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   294
          (\<forall>i\<in>I. \<forall>j\<in>I. i\<noteq>j --> C(i) Int C(j) = 0) -->  
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   295
          setsum(f, \<Union>i\<in>I. C(i)) = setsum (%i. setsum(f, C(i)), I)"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   296
apply (erule Finite_induct, auto)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   297
apply (subgoal_tac "\<forall>i\<in>B. x \<noteq> i")
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   298
 prefer 2 apply blast
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   299
apply (subgoal_tac "C (x) Int (\<Union>i\<in>B. C (i)) = 0")
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   300
 prefer 2 apply blast
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   301
apply (subgoal_tac "Finite (\<Union>i\<in>B. C (i)) & Finite (C (x)) & Finite (B) ")
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   302
apply (simp (no_asm_simp) add: setsum_Un_disjoint)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   303
apply (auto intro: Finite_Union Finite_RepFun)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   304
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   305
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   306
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   307
lemma setsum_addf: "setsum(%x. f(x) $+ g(x),C) = setsum(f, C) $+ setsum(g, C)"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   308
apply (case_tac "Finite (C) ")
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   309
 prefer 2 apply (simp add: setsum_def)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   310
apply (erule Finite_induct, auto)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   311
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   312
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   313
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   314
lemma fold_set_cong:
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   315
     "[| A=A'; B=B'; e=e'; (\<forall>x\<in>A'. \<forall>y\<in>B'. f(x,y) = f'(x,y)) |] 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   316
      ==> fold_set(A,B,f,e) = fold_set(A',B',f',e')"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   317
apply (simp add: fold_set_def)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   318
apply (intro refl iff_refl lfp_cong Collect_cong disj_cong ex_cong, auto)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   319
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   320
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   321
lemma fold_cong:
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   322
"[| B=B'; A=A'; e=e';   
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   323
    !!x y. [|x\<in>A'; y\<in>B'|] ==> f(x,y) = f'(x,y) |] ==>  
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   324
   fold[B](f,e,A) = fold[B'](f', e', A')"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   325
apply (simp add: fold_def)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   326
apply (subst fold_set_cong)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   327
apply (rule_tac [5] refl, simp_all)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   328
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   329
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   330
lemma setsum_cong:
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   331
 "[| A=B; !!x. x\<in>B ==> f(x) = g(x) |] ==>  
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   332
     setsum(f, A) = setsum(g, B)"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   333
by (simp add: setsum_def cong add: fold_cong)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   334
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   335
lemma setsum_Un:
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   336
     "[| Finite(A); Finite(B) |]  
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   337
      ==> setsum(f, A Un B) =  
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   338
          setsum(f, A) $+ setsum(f, B) $- setsum(f, A Int B)"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   339
apply (subst setsum_Un_Int [symmetric], auto)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   340
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   341
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   342
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   343
lemma setsum_zneg_or_0 [rule_format (no_asm)]:
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   344
     "Finite(A) ==> (\<forall>x\<in>A. g(x) $<= #0) --> setsum(g, A) $<= #0"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   345
apply (erule Finite_induct)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   346
apply (auto intro: zneg_or_0_add_zneg_or_0_imp_zneg_or_0)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   347
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   348
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   349
lemma setsum_succD_lemma [rule_format]:
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   350
     "Finite(A)  
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   351
      ==> \<forall>n\<in>nat. setsum(f,A) = $# succ(n) --> (\<exists>a\<in>A. #0 $< f(a))"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   352
apply (erule Finite_induct)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   353
apply (auto simp del: int_of_0 int_of_succ simp add: not_zless_iff_zle int_of_0 [symmetric])
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   354
apply (subgoal_tac "setsum (f, B) $<= #0")
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   355
apply simp_all
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   356
prefer 2 apply (blast intro: setsum_zneg_or_0)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   357
apply (subgoal_tac "$# 1 $<= f (x) $+ setsum (f, B) ")
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   358
apply (drule zdiff_zle_iff [THEN iffD2])
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   359
apply (subgoal_tac "$# 1 $<= $# 1 $- setsum (f,B) ")
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   360
apply (drule_tac x = "$# 1" in zle_trans)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   361
apply (rule_tac [2] j = "#1" in zless_zle_trans, auto)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   362
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   363
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   364
lemma setsum_succD:
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   365
     "[| setsum(f, A) = $# succ(n); n\<in>nat |]==> \<exists>a\<in>A. #0 $< f(a)"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   366
apply (case_tac "Finite (A) ")
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   367
apply (blast intro: setsum_succD_lemma)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   368
apply (unfold setsum_def)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   369
apply (auto simp del: int_of_0 int_of_succ simp add: int_succ_int_1 [symmetric] int_of_0 [symmetric])
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   370
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   371
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   372
lemma g_zpos_imp_setsum_zpos [rule_format]:
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   373
     "Finite(A) ==> (\<forall>x\<in>A. #0 $<= g(x)) --> #0 $<= setsum(g, A)"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   374
apply (erule Finite_induct)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   375
apply (simp (no_asm))
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   376
apply (auto intro: zpos_add_zpos_imp_zpos)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   377
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   378
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   379
lemma g_zpos_imp_setsum_zpos2 [rule_format]:
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   380
     "[| Finite(A); \<forall>x. #0 $<= g(x) |] ==> #0 $<= setsum(g, A)"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   381
apply (erule Finite_induct)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   382
apply (auto intro: zpos_add_zpos_imp_zpos)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   383
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   384
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   385
lemma g_zspos_imp_setsum_zspos [rule_format]:
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   386
     "Finite(A)  
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   387
      ==> (\<forall>x\<in>A. #0 $< g(x)) --> A \<noteq> 0 --> (#0 $< setsum(g, A))"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   388
apply (erule Finite_induct)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   389
apply (auto intro: zspos_add_zspos_imp_zspos)
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   390
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   391
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   392
lemma setsum_Diff [rule_format]:
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   393
     "Finite(A) ==> \<forall>a. M(a) = #0 --> setsum(M, A) = setsum(M, A-{a})"
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   394
apply (erule Finite_induct) 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   395
apply (simp_all add: Diff_cons_eq Finite_Diff) 
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   396
done
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   397
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   398
ML
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   399
{*
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   400
val fold_set_mono = thm "fold_set_mono";
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   401
val Diff1_fold_set = thm "Diff1_fold_set";
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   402
val Diff_sing_imp = thm "Diff_sing_imp";
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   403
val fold_0 = thm "fold_0";
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   404
val setsum_0 = thm "setsum_0";
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   405
val setsum_cons = thm "setsum_cons";
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   406
val setsum_K0 = thm "setsum_K0";
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   407
val setsum_Un_Int = thm "setsum_Un_Int";
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   408
val setsum_type = thm "setsum_type";
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   409
val setsum_Un_disjoint = thm "setsum_Un_disjoint";
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   410
val Finite_RepFun = thm "Finite_RepFun";
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   411
val setsum_UN_disjoint = thm "setsum_UN_disjoint";
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   412
val setsum_addf = thm "setsum_addf";
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   413
val fold_set_cong = thm "fold_set_cong";
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   414
val fold_cong = thm "fold_cong";
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   415
val setsum_cong = thm "setsum_cong";
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   416
val setsum_Un = thm "setsum_Un";
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   417
val setsum_zneg_or_0 = thm "setsum_zneg_or_0";
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   418
val setsum_succD = thm "setsum_succD";
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   419
val g_zpos_imp_setsum_zpos = thm "g_zpos_imp_setsum_zpos";
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   420
val g_zpos_imp_setsum_zpos2 = thm "g_zpos_imp_setsum_zpos2";
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   421
val g_zspos_imp_setsum_zspos = thm "g_zspos_imp_setsum_zspos";
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   422
val setsum_Diff = thm "setsum_Diff";
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   423
*}
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   424
373806545656 Converting ZF/UNITY to Isar
paulson
parents: 14046
diff changeset
   425
12089
34e7693271a9 Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
diff changeset
   426
end