src/ZF/Finite.ML
 author lcp Tue, 16 Aug 1994 19:03:45 +0200 changeset 534 cd8bec47e175 parent 516 1957113f0d7d child 760 f0200e91b272 permissions -rw-r--r--
ZF/Finite: added the finite function space, A-||>B ZF/InfDatatype: added rules for the above
```
(*  Title: 	ZF/Finite.ML
ID:         \$Id\$
Author: 	Lawrence C Paulson, Cambridge University Computer Laboratory

Finite powerset operator; finite function space

prove X:Fin(A) ==> |X| < nat

prove:  b: Fin(A) ==> inj(b,b)<=surj(b,b)
*)

open Finite;

(*** Finite powerset operator ***)

goalw Finite.thy Fin.defs "!!A B. A<=B ==> Fin(A) <= Fin(B)";
by (rtac lfp_mono 1);
by (REPEAT (rtac Fin.bnd_mono 1));
by (REPEAT (ares_tac (Pow_mono::basic_monos) 1));
val Fin_mono = result();

(* A : Fin(B) ==> A <= B *)
val FinD = Fin.dom_subset RS subsetD RS PowD;

(** Induction on finite sets **)

(*Discharging x~:y entails extra work*)
val major::prems = goal Finite.thy
"[| b: Fin(A);  \
\       P(0);        \
\       !!x y. [| x: A;  y: Fin(A);  x~:y;  P(y) |] ==> P(cons(x,y)) \
\    |] ==> P(b)";
by (rtac (major RS Fin.induct) 1);
by (excluded_middle_tac "a:b" 2);
by (etac (cons_absorb RS ssubst) 3 THEN assume_tac 3);	    (*backtracking!*)
by (REPEAT (ares_tac prems 1));
val Fin_induct = result();

(** Simplification for Fin **)
val Fin_ss = arith_ss addsimps Fin.intrs;

(*The union of two finite sets is finite.*)
val major::prems = goal Finite.thy
"[| b: Fin(A);  c: Fin(A) |] ==> b Un c : Fin(A)";
by (rtac (major RS Fin_induct) 1);
by (ALLGOALS (asm_simp_tac (Fin_ss addsimps (prems@[Un_0, Un_cons]))));
val Fin_UnI = result();

(*The union of a set of finite sets is finite.*)
val [major] = goal Finite.thy "C : Fin(Fin(A)) ==> Union(C) : Fin(A)";
by (rtac (major RS Fin_induct) 1);
by (ALLGOALS (asm_simp_tac (Fin_ss addsimps [Union_0, Union_cons, Fin_UnI])));
val Fin_UnionI = result();

(*Every subset of a finite set is finite.*)
goal Finite.thy "!!b A. b: Fin(A) ==> ALL z. z<=b --> z: Fin(A)";
by (etac Fin_induct 1);
by (simp_tac (Fin_ss addsimps [subset_empty_iff]) 1);
by (asm_simp_tac (ZF_ss addsimps subset_cons_iff::distrib_rews) 1);
by (safe_tac ZF_cs);
by (eres_inst_tac [("b","z")] (cons_Diff RS subst) 1);
by (asm_simp_tac Fin_ss 1);
val Fin_subset_lemma = result();

goal Finite.thy "!!c b A. [| c<=b;  b: Fin(A) |] ==> c: Fin(A)";
by (REPEAT (ares_tac [Fin_subset_lemma RS spec RS mp] 1));
val Fin_subset = result();

val major::prems = goal Finite.thy
"[| c: Fin(A);  b: Fin(A);  				\
\       P(b);       						\
\       !!x y. [| x: A;  y: Fin(A);  x:y;  P(y) |] ==> P(y-{x}) \
\    |] ==> c<=b --> P(b-c)";
by (rtac (major RS Fin_induct) 1);
by (rtac (Diff_cons RS ssubst) 2);
by (ALLGOALS (asm_simp_tac (Fin_ss addsimps (prems@[Diff_0, cons_subset_iff,
Diff_subset RS Fin_subset]))));
val Fin_0_induct_lemma = result();

val prems = goal Finite.thy
"[| b: Fin(A);  						\
\       P(b);        						\
\       !!x y. [| x: A;  y: Fin(A);  x:y;  P(y) |] ==> P(y-{x}) \
\    |] ==> P(0)";
by (rtac (Diff_cancel RS subst) 1);
by (rtac (Fin_0_induct_lemma RS mp) 1);
by (REPEAT (ares_tac (subset_refl::prems) 1));
val Fin_0_induct = result();

(*Functions from a finite ordinal*)
val prems = goal Finite.thy "n: nat ==> n->A <= Fin(nat*A)";
by (nat_ind_tac "n" prems 1);
by (simp_tac (ZF_ss addsimps [Pi_empty1, Fin.emptyI, subset_iff, cons_iff]) 1);
by (asm_simp_tac (ZF_ss addsimps [succ_def, mem_not_refl RS cons_fun_eq]) 1);
by (fast_tac (ZF_cs addSIs [Fin.consI]) 1);
val nat_fun_subset_Fin = result();

(*** Finite function space ***)

goalw Finite.thy FiniteFun.defs
"!!A B C D. [| A<=C;  B<=D |] ==> A -||> B  <=  C -||> D";
by (rtac lfp_mono 1);
by (REPEAT (rtac FiniteFun.bnd_mono 1));
by (REPEAT (ares_tac (Fin_mono::Sigma_mono::basic_monos) 1));
val FiniteFun_mono = result();

goal Finite.thy "!!A B. A<=B ==> A -||> A  <=  B -||> B";
by (REPEAT (ares_tac [FiniteFun_mono] 1));
val FiniteFun_mono1 = result();

goal Finite.thy "!!h. h: A -||>B ==> h: domain(h) -> B";
by (etac FiniteFun.induct 1);
by (simp_tac (ZF_ss addsimps [empty_fun, domain_0]) 1);
by (asm_simp_tac (ZF_ss addsimps [fun_extend3, domain_cons]) 1);
val FiniteFun_is_fun = result();

goal Finite.thy "!!h. h: A -||>B ==> domain(h) : Fin(A)";
by (etac FiniteFun.induct 1);
by (simp_tac (Fin_ss addsimps [domain_0]) 1);
by (asm_simp_tac (Fin_ss addsimps [domain_cons]) 1);
val FiniteFun_domain_Fin = result();

val FiniteFun_apply_type = FiniteFun_is_fun RS apply_type |> standard;

(*Every subset of a finite function is a finite function.*)
goal Finite.thy "!!b A. b: A-||>B ==> ALL z. z<=b --> z: A-||>B";
by (etac FiniteFun.induct 1);
by (simp_tac (ZF_ss addsimps subset_empty_iff::FiniteFun.intrs) 1);
by (asm_simp_tac (ZF_ss addsimps subset_cons_iff::distrib_rews) 1);
by (safe_tac ZF_cs);
by (eres_inst_tac [("b","z")] (cons_Diff RS subst) 1);
by (dtac (spec RS mp) 1 THEN assume_tac 1);
by (fast_tac (ZF_cs addSIs FiniteFun.intrs) 1);
val FiniteFun_subset_lemma = result();

goal Finite.thy "!!c b A. [| c<=b;  b: A-||>B |] ==> c: A-||>B";
by (REPEAT (ares_tac [FiniteFun_subset_lemma RS spec RS mp] 1));
val FiniteFun_subset = result();

```