equal
deleted
inserted
replaced
10 imports Divides Equiv_Relations IntDef |
10 imports Divides Equiv_Relations IntDef |
11 begin |
11 begin |
12 |
12 |
13 subsection {* Definition and basic properties *} |
13 subsection {* Definition and basic properties *} |
14 |
14 |
15 inductive2 finite :: "'a set => bool" |
15 inductive finite :: "'a set => bool" |
16 where |
16 where |
17 emptyI [simp, intro!]: "finite {}" |
17 emptyI [simp, intro!]: "finite {}" |
18 | insertI [simp, intro!]: "finite A ==> finite (insert a A)" |
18 | insertI [simp, intro!]: "finite A ==> finite (insert a A)" |
19 |
19 |
20 lemma ex_new_if_finite: -- "does not depend on def of finite at all" |
20 lemma ex_new_if_finite: -- "does not depend on def of finite at all" |
425 @{text "fold f g z {x\<^isub>1, ..., x\<^isub>n} = f (g x\<^isub>1) (\<dots> (f (g x\<^isub>n) z)\<dots>)"} |
425 @{text "fold f g z {x\<^isub>1, ..., x\<^isub>n} = f (g x\<^isub>1) (\<dots> (f (g x\<^isub>n) z)\<dots>)"} |
426 if @{text f} is associative-commutative. For an application of @{text fold} |
426 if @{text f} is associative-commutative. For an application of @{text fold} |
427 se the definitions of sums and products over finite sets. |
427 se the definitions of sums and products over finite sets. |
428 *} |
428 *} |
429 |
429 |
430 inductive2 |
430 inductive |
431 foldSet :: "('a => 'a => 'a) => ('b => 'a) => 'a => 'b set => 'a => bool" |
431 foldSet :: "('a => 'a => 'a) => ('b => 'a) => 'a => 'b set => 'a => bool" |
432 for f :: "'a => 'a => 'a" |
432 for f :: "'a => 'a => 'a" |
433 and g :: "'b => 'a" |
433 and g :: "'b => 'a" |
434 and z :: 'a |
434 and z :: 'a |
435 where |
435 where |
436 emptyI [intro]: "foldSet f g z {} z" |
436 emptyI [intro]: "foldSet f g z {} z" |
437 | insertI [intro]: |
437 | insertI [intro]: |
438 "\<lbrakk> x \<notin> A; foldSet f g z A y \<rbrakk> |
438 "\<lbrakk> x \<notin> A; foldSet f g z A y \<rbrakk> |
439 \<Longrightarrow> foldSet f g z (insert x A) (f (g x) y)" |
439 \<Longrightarrow> foldSet f g z (insert x A) (f (g x) y)" |
440 |
440 |
441 inductive_cases2 empty_foldSetE [elim!]: "foldSet f g z {} x" |
441 inductive_cases empty_foldSetE [elim!]: "foldSet f g z {} x" |
442 |
442 |
443 constdefs |
443 constdefs |
444 fold :: "('a => 'a => 'a) => ('b => 'a) => 'a => 'b set => 'a" |
444 fold :: "('a => 'a => 'a) => ('b => 'a) => 'a => 'b set => 'a" |
445 "fold f g z A == THE x. foldSet f g z A x" |
445 "fold f g z A == THE x. foldSet f g z A x" |
446 |
446 |
1792 |
1792 |
1793 subsection{* A fold functional for non-empty sets *} |
1793 subsection{* A fold functional for non-empty sets *} |
1794 |
1794 |
1795 text{* Does not require start value. *} |
1795 text{* Does not require start value. *} |
1796 |
1796 |
1797 inductive2 |
1797 inductive |
1798 fold1Set :: "('a => 'a => 'a) => 'a set => 'a => bool" |
1798 fold1Set :: "('a => 'a => 'a) => 'a set => 'a => bool" |
1799 for f :: "'a => 'a => 'a" |
1799 for f :: "'a => 'a => 'a" |
1800 where |
1800 where |
1801 fold1Set_insertI [intro]: |
1801 fold1Set_insertI [intro]: |
1802 "\<lbrakk> foldSet f id a A x; a \<notin> A \<rbrakk> \<Longrightarrow> fold1Set f (insert a A) x" |
1802 "\<lbrakk> foldSet f id a A x; a \<notin> A \<rbrakk> \<Longrightarrow> fold1Set f (insert a A) x" |
1807 |
1807 |
1808 lemma fold1Set_nonempty: |
1808 lemma fold1Set_nonempty: |
1809 "fold1Set f A x \<Longrightarrow> A \<noteq> {}" |
1809 "fold1Set f A x \<Longrightarrow> A \<noteq> {}" |
1810 by(erule fold1Set.cases, simp_all) |
1810 by(erule fold1Set.cases, simp_all) |
1811 |
1811 |
1812 inductive_cases2 empty_fold1SetE [elim!]: "fold1Set f {} x" |
1812 inductive_cases empty_fold1SetE [elim!]: "fold1Set f {} x" |
1813 |
1813 |
1814 inductive_cases2 insert_fold1SetE [elim!]: "fold1Set f (insert a X) x" |
1814 inductive_cases insert_fold1SetE [elim!]: "fold1Set f (insert a X) x" |
1815 |
1815 |
1816 |
1816 |
1817 lemma fold1Set_sing [iff]: "(fold1Set f {a} b) = (a = b)" |
1817 lemma fold1Set_sing [iff]: "(fold1Set f {a} b) = (a = b)" |
1818 by (blast intro: foldSet.intros elim: foldSet.cases) |
1818 by (blast intro: foldSet.intros elim: foldSet.cases) |
1819 |
1819 |