TFL/examples/Subst/Setplus.ML
author paulson
Fri, 21 Feb 1997 15:30:41 +0100
changeset 2671 510d94c71dda
parent 2113 21266526ac42
permissions -rw-r--r--
Introduction of rotate_rule
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2113
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
     1
(*  Title:      Substitutions/setplus.ML
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
     2
    Author:     Martin Coen, Cambridge University Computer Laboratory
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
     3
    Copyright   1993  University of Cambridge
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
     4
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
     5
For setplus.thy.
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
     6
Properties of subsets and empty sets.
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
     7
*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
     8
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
     9
open Setplus;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    10
val eq_cs = claset_of "equalities";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    11
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    12
(*********)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    13
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    14
(*** Rules for subsets ***)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    15
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    16
goal Set.thy "A <= B =  (! t.t:A --> t:B)";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    17
by (fast_tac set_cs 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    18
qed "subset_iff";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    19
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    20
goalw Setplus.thy [ssubset_def] "A < B = ((A <= B) & ~(A=B))";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    21
by (rtac refl 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    22
qed "ssubset_iff";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    23
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    24
goal Setplus.thy "((A::'a set) <= B) = ((A < B) | (A=B))";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    25
by (simp_tac (simpset_of "Fun" addsimps [ssubset_iff]) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    26
by (fast_tac set_cs 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    27
qed "subseteq_iff_subset_eq";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    28
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    29
(*Rule in Modus Ponens style*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    30
goal Setplus.thy "A < B --> c:A --> c:B";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    31
by (simp_tac (simpset_of "Fun" addsimps [ssubset_iff]) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    32
by (fast_tac set_cs 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    33
qed "ssubsetD";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    34
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    35
(*********)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    36
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    37
goalw Setplus.thy [empty_def] "~ a : {}";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    38
by (fast_tac set_cs 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    39
qed "not_in_empty";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    40
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    41
goalw Setplus.thy [empty_def] "(A = {}) = (ALL a.~ a:A)";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    42
by (fast_tac (set_cs addIs [set_ext]) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    43
qed "empty_iff";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    44
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    45
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    46
(*********)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    47
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    48
goal Set.thy "(~A=B)  = ((? x.x:A & ~x:B) | (? x.~x:A & x:B))";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    49
by (fast_tac (set_cs addIs [set_ext]) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    50
qed "not_equal_iff";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    51
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    52
(*********)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    53
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    54
val setplus_rews = [ssubset_iff,not_in_empty,empty_iff];
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    55
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    56
(*********)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    57
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    58
(*Case analysis for rewriting; P also gets rewritten*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    59
val [prem1,prem2] = goal HOL.thy "[| P-->Q;  ~P-->Q |] ==> Q";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    60
by (rtac (excluded_middle RS disjE) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    61
by (etac (prem2 RS mp) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    62
by (etac (prem1 RS mp) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    63
qed "imp_excluded_middle";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    64
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    65
fun imp_excluded_middle_tac s = res_inst_tac [("P",s)] imp_excluded_middle;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    66
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    67
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    68
goal Set.thy "(insert a A ~= insert a B) --> A ~= B";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    69
by (fast_tac set_cs 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    70
val insert_lim = result() RS mp;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    71
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    72
goal Set.thy "x~:A --> (A-{x} = A)";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    73
by (fast_tac eq_cs 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    74
val lem = result() RS mp;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    75
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    76
goal Nat.thy "B<=A --> B = Suc A --> P";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    77
by (strip_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    78
by (hyp_subst_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    79
by (Asm_full_simp_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    80
val leq_lem = standard(result() RS mp RS mp);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    81
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    82
goal Nat.thy "A<=B --> (A ~= Suc B)";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    83
by (strip_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    84
by (rtac notI 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    85
by (rtac leq_lem 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    86
by (REPEAT (atac 1));
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    87
val leq_lem1 = standard(result() RS mp);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    88
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    89
(* The following is an adaptation of the proof for the "<=" version 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    90
 * in Finite. *) 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    91
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    92
goalw Setplus.thy [ssubset_def]
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    93
"!!B. finite B ==> !A. A < B --> card(A) < card(B)";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    94
by (etac finite_induct 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    95
by (Simp_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    96
by (fast_tac set_cs 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    97
by (strip_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    98
by (etac conjE 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
    99
by (case_tac "x:A" 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   100
(*1*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   101
by (dtac mk_disjoint_insert 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   102
by (etac exE 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   103
by (etac conjE 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   104
by (hyp_subst_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   105
by (rotate_tac ~1 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   106
by (asm_full_simp_tac (!simpset addsimps 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   107
                        [subset_insert_iff,finite_subset,lem]) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   108
by (dtac insert_lim 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   109
by (Asm_full_simp_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   110
(*2*)
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   111
by (rotate_tac ~1 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   112
by (asm_full_simp_tac (!simpset addsimps 
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   113
                       [subset_insert_iff,finite_subset,lem]) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   114
by (case_tac "A=F" 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   115
by (Asm_simp_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   116
by (Asm_simp_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   117
by (rtac leq_lem1 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   118
by (Asm_simp_tac 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   119
val ssubset_card = result() ;
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   120
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   121
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   122
goal Set.thy "(A = B) = ((A <= (B::'a set)) & (B<=A))";
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   123
by (rtac iffI 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   124
by (simp_tac (HOL_ss addsimps [subset_iff]) 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   125
by (fast_tac set_cs 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   126
by (rtac subset_antisym 1);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   127
by (ALLGOALS Asm_simp_tac);
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   128
val set_eq_subset = result();
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   129
21266526ac42 Subst as modified by Konrad Slind
paulson
parents:
diff changeset
   130