src/ZF/ex/misc.ML
changeset 11316 b4e71bd751e4
parent 11233 34c81a796ee3
equal deleted inserted replaced
11315:fbca0f74bcef 11316:b4e71bd751e4
     8 *)
     8 *)
     9 
     9 
    10 (*These two are cited in Benzmueller and Kohlhase's system description of LEO,
    10 (*These two are cited in Benzmueller and Kohlhase's system description of LEO,
    11   CADE-15, 1998 (page 139-143) as theorems LEO could not prove.*)
    11   CADE-15, 1998 (page 139-143) as theorems LEO could not prove.*)
    12 
    12 
    13 Goal "(X = Y Un Z) <-> (Y<=X & Z<=X & (ALL V. Y<=V & Z<=V --> X<=V))";
    13 Goal "(X = Y Un Z) <-> (Y \\<subseteq> X & Z \\<subseteq> X & (\\<forall>V. Y \\<subseteq> V & Z \\<subseteq> V --> X \\<subseteq> V))";
    14 by (blast_tac (claset() addSIs [equalityI]) 1);
    14 by (blast_tac (claset() addSIs [equalityI]) 1);
    15 qed "";
    15 qed "";
    16 
    16 
    17 (*the dual of the previous one*)
    17 (*the dual of the previous one*)
    18 Goal "(X = Y Int Z) <-> (X<=Y & X<=Z & (ALL V. V<=Y & V<=Z --> V<=X))";
    18 Goal "(X = Y Int Z) <-> (X \\<subseteq> Y & X \\<subseteq> Z & (\\<forall>V. V \\<subseteq> Y & V \\<subseteq> Z --> V \\<subseteq> X))";
    19 by (blast_tac (claset() addSIs [equalityI]) 1);
    19 by (blast_tac (claset() addSIs [equalityI]) 1);
    20 qed "";
    20 qed "";
    21 
    21 
    22 (*trivial example of term synthesis: apparently hard for some provers!*)
    22 (*trivial example of term synthesis: apparently hard for some provers!*)
    23 Goal "a ~= b ==> a:?X & b ~: ?X";
    23 Goal "a \\<noteq> b ==> a:?X & b \\<notin> ?X";
    24 by (Blast_tac 1);
    24 by (Blast_tac 1);
    25 qed "";
    25 qed "";
    26 
    26 
    27 (*Nice Blast_tac benchmark.  Proved in 0.3s; old tactics can't manage it!*)
    27 (*Nice Blast_tac benchmark.  Proved in 0.3s; old tactics can't manage it!*)
    28 Goal "ALL x:S. ALL y:S. x<=y ==> EX z. S <= {z}";
    28 Goal "\\<forall>x \\<in> S. \\<forall>y \\<in> S. x \\<subseteq> y ==> \\<exists>z. S \\<subseteq> {z}";
    29 by (Blast_tac 1);
    29 by (Blast_tac 1);
    30 qed "";
    30 qed "";
    31 
    31 
    32 (*variant of the benchmark above*)
    32 (*variant of the benchmark above*)
    33 Goal "ALL x:S. Union(S) <= x ==> EX z. S <= {z}";
    33 Goal "\\<forall>x \\<in> S. Union(S) \\<subseteq> x ==> \\<exists>z. S \\<subseteq> {z}";
    34 by (Blast_tac 1);
    34 by (Blast_tac 1);
    35 qed "";
    35 qed "";
    36 
    36 
    37 context Perm.thy;
    37 context Perm.thy;
    38 
    38 
    39 (*Example 12 (credited to Peter Andrews) from
    39 (*Example 12 (credited to Peter Andrews) from
    40  W. Bledsoe.  A Maximal Method for Set Variables in Automatic Theorem-proving.
    40  W. Bledsoe.  A Maximal Method for Set Variables in Automatic Theorem-proving.
    41  In: J. Hayes and D. Michie and L. Mikulich, eds.  Machine Intelligence 9.
    41  In: J. Hayes and D. Michie and L. Mikulich, eds.  Machine Intelligence 9.
    42  Ellis Horwood, 53-100 (1979). *)
    42  Ellis Horwood, 53-100 (1979). *)
    43 Goal "(ALL F. {x}: F --> {y}:F) --> (ALL A. x:A --> y:A)";
    43 Goal "(\\<forall>F. {x}: F --> {y}:F) --> (\\<forall>A. x \\<in> A --> y \\<in> A)";
    44 by (Best_tac 1);
    44 by (Best_tac 1);
    45 qed "";
    45 qed "";
    46 
    46 
    47 
    47 
    48 (*** Composition of homomorphisms is a homomorphism ***)
    48 (*** Composition of homomorphisms is a homomorphism ***)
    58 
    58 
    59 (*This version uses a super application of simp_tac.  Needs setloop to help
    59 (*This version uses a super application of simp_tac.  Needs setloop to help
    60   proving conditions of rewrites such as comp_fun_apply;
    60   proving conditions of rewrites such as comp_fun_apply;
    61   rewriting does not instantiate Vars*)
    61   rewriting does not instantiate Vars*)
    62 goal Perm.thy
    62 goal Perm.thy
    63     "(ALL A f B g. hom(A,f,B,g) = \
    63     "(\\<forall>A f B g. hom(A,f,B,g) = \
    64 \          {H: A->B. f:A*A->A & g:B*B->B & \
    64 \          {H \\<in> A->B. f \\<in> A*A->A & g \\<in> B*B->B & \
    65 \                    (ALL x:A. ALL y:A. H`(f`<x,y>) = g`<H`x,H`y>)}) --> \
    65 \                    (\\<forall>x \\<in> A. \\<forall>y \\<in> A. H`(f`<x,y>) = g`<H`x,H`y>)}) --> \
    66 \    J : hom(A,f,B,g) & K : hom(B,g,C,h) -->  \
    66 \    J \\<in> hom(A,f,B,g) & K \\<in> hom(B,g,C,h) -->  \
    67 \    (K O J) : hom(A,f,C,h)";
    67 \    (K O J) \\<in> hom(A,f,C,h)";
    68 by (asm_simp_tac (simpset() setloop (K Safe_tac)) 1);
    68 by (asm_simp_tac (simpset() setloop (K Safe_tac)) 1);
    69 qed "";
    69 qed "";
    70 
    70 
    71 (*This version uses meta-level rewriting, safe_tac and asm_simp_tac*)
    71 (*This version uses meta-level rewriting, safe_tac and asm_simp_tac*)
    72 val [hom_def] = goal Perm.thy
    72 val [hom_def] = goal Perm.thy
    73     "(!! A f B g. hom(A,f,B,g) == \
    73     "(!! A f B g. hom(A,f,B,g) == \
    74 \          {H: A->B. f:A*A->A & g:B*B->B & \
    74 \          {H \\<in> A->B. f \\<in> A*A->A & g \\<in> B*B->B & \
    75 \                    (ALL x:A. ALL y:A. H`(f`<x,y>) = g`<H`x,H`y>)}) ==> \
    75 \                    (\\<forall>x \\<in> A. \\<forall>y \\<in> A. H`(f`<x,y>) = g`<H`x,H`y>)}) ==> \
    76 \    J : hom(A,f,B,g) & K : hom(B,g,C,h) -->  \
    76 \    J \\<in> hom(A,f,B,g) & K \\<in> hom(B,g,C,h) -->  \
    77 \    (K O J) : hom(A,f,C,h)";
    77 \    (K O J) \\<in> hom(A,f,C,h)";
    78 by (rewtac hom_def);
    78 by (rewtac hom_def);
    79 by Safe_tac;
    79 by Safe_tac;
    80 by (Asm_simp_tac 1);
    80 by (Asm_simp_tac 1);
    81 by (Asm_simp_tac 1);
    81 by (Asm_simp_tac 1);
    82 qed "comp_homs";
    82 qed "comp_homs";
    83 
    83 
    84 
    84 
    85 (** A characterization of functions, suggested by Tobias Nipkow **)
    85 (** A characterization of functions, suggested by Tobias Nipkow **)
    86 
    86 
    87 Goalw [Pi_def, function_def]
    87 Goalw [Pi_def, function_def]
    88     "r: domain(r)->B  <->  r <= domain(r)*B & (ALL X. r `` (r -`` X) <= X)";
    88     "r \\<in> domain(r)->B  <->  r \\<subseteq> domain(r)*B & (\\<forall>X. r `` (r -`` X) \\<subseteq> X)";
    89 by (Best_tac 1);
    89 by (Best_tac 1);
    90 qed "";
    90 qed "";
    91 
    91 
    92 
    92 
    93 (**** From D Pastre.  Automatic theorem proving in set theory. 
    93 (**** From D Pastre.  Automatic theorem proving in set theory. 
   117 
   117 
   118 val prems = goalw Perm.thy [bij_def]
   118 val prems = goalw Perm.thy [bij_def]
   119     "[| (h O g O f): inj(A,A);          \
   119     "[| (h O g O f): inj(A,A);          \
   120 \       (f O h O g): surj(B,B);         \
   120 \       (f O h O g): surj(B,B);         \
   121 \       (g O f O h): surj(C,C);         \
   121 \       (g O f O h): surj(C,C);         \
   122 \       f: A->B;  g: B->C;  h: C->A |] ==> h: bij(C,A)";
   122 \       f \\<in> A->B;  g \\<in> B->C;  h \\<in> C->A |] ==> h \\<in> bij(C,A)";
   123 by (REPEAT (resolve_tac (IntI :: pastre_facts prems) 1));
   123 by (REPEAT (resolve_tac (IntI :: pastre_facts prems) 1));
   124 qed "pastre1";
   124 qed "pastre1";
   125 
   125 
   126 val prems = goalw Perm.thy [bij_def]
   126 val prems = goalw Perm.thy [bij_def]
   127     "[| (h O g O f): surj(A,A);         \
   127     "[| (h O g O f): surj(A,A);         \
   128 \       (f O h O g): inj(B,B);          \
   128 \       (f O h O g): inj(B,B);          \
   129 \       (g O f O h): surj(C,C);         \
   129 \       (g O f O h): surj(C,C);         \
   130 \       f: A->B;  g: B->C;  h: C->A |] ==> h: bij(C,A)";
   130 \       f \\<in> A->B;  g \\<in> B->C;  h \\<in> C->A |] ==> h \\<in> bij(C,A)";
   131 by (REPEAT (resolve_tac (IntI :: pastre_facts prems) 1));
   131 by (REPEAT (resolve_tac (IntI :: pastre_facts prems) 1));
   132 qed "pastre2";
   132 qed "pastre2";
   133 
   133 
   134 val prems = goalw Perm.thy [bij_def]
   134 val prems = goalw Perm.thy [bij_def]
   135     "[| (h O g O f): surj(A,A);         \
   135     "[| (h O g O f): surj(A,A);         \
   136 \       (f O h O g): surj(B,B);         \
   136 \       (f O h O g): surj(B,B);         \
   137 \       (g O f O h): inj(C,C);          \
   137 \       (g O f O h): inj(C,C);          \
   138 \       f: A->B;  g: B->C;  h: C->A |] ==> h: bij(C,A)";
   138 \       f \\<in> A->B;  g \\<in> B->C;  h \\<in> C->A |] ==> h \\<in> bij(C,A)";
   139 by (REPEAT (resolve_tac (IntI :: pastre_facts prems) 1));
   139 by (REPEAT (resolve_tac (IntI :: pastre_facts prems) 1));
   140 qed "pastre3";
   140 qed "pastre3";
   141 
   141 
   142 val prems = goalw Perm.thy [bij_def]
   142 val prems = goalw Perm.thy [bij_def]
   143     "[| (h O g O f): surj(A,A);         \
   143     "[| (h O g O f): surj(A,A);         \
   144 \       (f O h O g): inj(B,B);          \
   144 \       (f O h O g): inj(B,B);          \
   145 \       (g O f O h): inj(C,C);          \
   145 \       (g O f O h): inj(C,C);          \
   146 \       f: A->B;  g: B->C;  h: C->A |] ==> h: bij(C,A)";
   146 \       f \\<in> A->B;  g \\<in> B->C;  h \\<in> C->A |] ==> h \\<in> bij(C,A)";
   147 by (REPEAT (resolve_tac (IntI :: pastre_facts prems) 1));
   147 by (REPEAT (resolve_tac (IntI :: pastre_facts prems) 1));
   148 qed "pastre4";
   148 qed "pastre4";
   149 
   149 
   150 val prems = goalw Perm.thy [bij_def]
   150 val prems = goalw Perm.thy [bij_def]
   151     "[| (h O g O f): inj(A,A);          \
   151     "[| (h O g O f): inj(A,A);          \
   152 \       (f O h O g): surj(B,B);         \
   152 \       (f O h O g): surj(B,B);         \
   153 \       (g O f O h): inj(C,C);          \
   153 \       (g O f O h): inj(C,C);          \
   154 \       f: A->B;  g: B->C;  h: C->A |] ==> h: bij(C,A)";
   154 \       f \\<in> A->B;  g \\<in> B->C;  h \\<in> C->A |] ==> h \\<in> bij(C,A)";
   155 by (REPEAT (resolve_tac (IntI :: pastre_facts prems) 1));
   155 by (REPEAT (resolve_tac (IntI :: pastre_facts prems) 1));
   156 qed "pastre5";
   156 qed "pastre5";
   157 
   157 
   158 val prems = goalw Perm.thy [bij_def]
   158 val prems = goalw Perm.thy [bij_def]
   159     "[| (h O g O f): inj(A,A);          \
   159     "[| (h O g O f): inj(A,A);          \
   160 \       (f O h O g): inj(B,B);          \
   160 \       (f O h O g): inj(B,B);          \
   161 \       (g O f O h): surj(C,C);         \
   161 \       (g O f O h): surj(C,C);         \
   162 \       f: A->B;  g: B->C;  h: C->A |] ==> h: bij(C,A)";
   162 \       f \\<in> A->B;  g \\<in> B->C;  h \\<in> C->A |] ==> h \\<in> bij(C,A)";
   163 by (REPEAT (resolve_tac (IntI :: pastre_facts prems) 1));
   163 by (REPEAT (resolve_tac (IntI :: pastre_facts prems) 1));
   164 qed "pastre6";
   164 qed "pastre6";
   165 
   165 
   166 (** Yet another example... **)
   166 (** Yet another example... **)
   167 
   167 
   168 goal Perm.thy
   168 goal Perm.thy
   169     "(lam Z:Pow(A+B). <{x:A. Inl(x):Z}, {y:B. Inr(y):Z}>) \
   169     "(\\<lambda>Z \\<in> Pow(A+B). <{x \\<in> A. Inl(x):Z}, {y \\<in> B. Inr(y):Z}>) \
   170 \    : bij(Pow(A+B), Pow(A)*Pow(B))";
   170 \    \\<in> bij(Pow(A+B), Pow(A)*Pow(B))";
   171 by (res_inst_tac [("d", "%<X,Y>.{Inl(x).x:X} Un {Inr(y).y:Y}")] 
   171 by (res_inst_tac [("d", "%<X,Y>.{Inl(x).x \\<in> X} Un {Inr(y).y \\<in> Y}")] 
   172     lam_bijective 1);
   172     lam_bijective 1);
   173 (*Auto_tac no longer proves it*)
   173 (*Auto_tac no longer proves it*)
   174 by Auto_tac;
   174 by Auto_tac;
   175 by (ALLGOALS Blast_tac);  
   175 by (ALLGOALS Blast_tac);  
   176 qed "Pow_sum_bij";
   176 qed "Pow_sum_bij";
   177 
   177 
   178 (*As a special case, we have  bij(Pow(A*B), A -> Pow B)  *)
   178 (*As a special case, we have  bij(Pow(A*B), A -> Pow B)  *)
   179 goal Perm.thy
   179 goal Perm.thy
   180     "(lam r:Pow(Sigma(A,B)). lam x:A. r``{x}) \
   180     "(\\<lambda>r \\<in> Pow(Sigma(A,B)). \\<lambda>x \\<in> A. r``{x}) \
   181 \    : bij(Pow(Sigma(A,B)), PROD x:A. Pow(B(x)))";
   181 \    \\<in> bij(Pow(Sigma(A,B)), \\<Pi>x \\<in> A. Pow(B(x)))";
   182 by (res_inst_tac [("d", "%f. UN x:A. UN y:f`x. {<x,y>}")] lam_bijective 1);
   182 by (res_inst_tac [("d", "%f. \\<Union>x \\<in> A. \\<Union>y \\<in> f`x. {<x,y>}")] lam_bijective 1);
   183 by (blast_tac (claset() addDs [apply_type]) 2);
   183 by (blast_tac (claset() addDs [apply_type]) 2);
   184 by (blast_tac (claset() addIs [lam_type]) 1);
   184 by (blast_tac (claset() addIs [lam_type]) 1);
   185 by (ALLGOALS Asm_simp_tac);
   185 by (ALLGOALS Asm_simp_tac);
   186 by (Fast_tac 1);
   186 by (Fast_tac 1);
   187 by (rtac fun_extension 1);
   187 by (rtac fun_extension 1);