src/HOL/Fun.ML
author paulson
Mon Mar 11 14:04:37 1996 +0100 (1996-03-11)
changeset 1561 9ba6d69f7763
parent 1465 5d7a7e439cec
child 1666 5183de4c496d
permissions -rw-r--r--
set_cs now includes singleton_inject
clasohm@1465
     1
(*  Title:      HOL/Fun
clasohm@923
     2
    ID:         $Id$
clasohm@1465
     3
    Author:     Tobias Nipkow, Cambridge University Computer Laboratory
clasohm@923
     4
    Copyright   1993  University of Cambridge
clasohm@923
     5
clasohm@923
     6
Lemmas about functions.
clasohm@923
     7
*)
clasohm@923
     8
clasohm@1264
     9
simpset := HOL_ss;
clasohm@1264
    10
clasohm@923
    11
goal Fun.thy "(f = g) = (!x. f(x)=g(x))";
clasohm@923
    12
by (rtac iffI 1);
clasohm@1264
    13
by (Asm_simp_tac 1);
clasohm@1264
    14
by (rtac ext 1 THEN Asm_simp_tac 1);
clasohm@923
    15
qed "expand_fun_eq";
clasohm@923
    16
clasohm@923
    17
val prems = goal Fun.thy
clasohm@923
    18
    "[| f(x)=u;  !!x. P(x) ==> g(f(x)) = x;  P(x) |] ==> x=g(u)";
clasohm@923
    19
by (rtac (arg_cong RS box_equals) 1);
clasohm@923
    20
by (REPEAT (resolve_tac (prems@[refl]) 1));
clasohm@923
    21
qed "apply_inverse";
clasohm@923
    22
clasohm@923
    23
clasohm@923
    24
(*** Range of a function ***)
clasohm@923
    25
clasohm@923
    26
(*Frequently b does not have the syntactic form of f(x).*)
clasohm@923
    27
val [prem] = goalw Fun.thy [range_def] "b=f(x) ==> b : range(f)";
clasohm@923
    28
by (EVERY1 [rtac CollectI, rtac exI, rtac prem]);
clasohm@923
    29
qed "range_eqI";
clasohm@923
    30
clasohm@923
    31
val rangeI = refl RS range_eqI;
clasohm@923
    32
clasohm@923
    33
val [major,minor] = goalw Fun.thy [range_def]
clasohm@923
    34
    "[| b : range(%x.f(x));  !!x. b=f(x) ==> P |] ==> P"; 
clasohm@923
    35
by (rtac (major RS CollectD RS exE) 1);
clasohm@923
    36
by (etac minor 1);
clasohm@923
    37
qed "rangeE";
clasohm@923
    38
clasohm@923
    39
(*** Image of a set under a function ***)
clasohm@923
    40
clasohm@923
    41
val prems = goalw Fun.thy [image_def] "[| b=f(x);  x:A |] ==> b : f``A";
clasohm@923
    42
by (REPEAT (resolve_tac (prems @ [CollectI,bexI,prem]) 1));
clasohm@923
    43
qed "image_eqI";
clasohm@923
    44
clasohm@923
    45
val imageI = refl RS image_eqI;
clasohm@923
    46
clasohm@923
    47
(*The eta-expansion gives variable-name preservation.*)
clasohm@923
    48
val major::prems = goalw Fun.thy [image_def]
clasohm@923
    49
    "[| b : (%x.f(x))``A;  !!x.[| b=f(x);  x:A |] ==> P |] ==> P"; 
clasohm@923
    50
by (rtac (major RS CollectD RS bexE) 1);
clasohm@923
    51
by (REPEAT (ares_tac prems 1));
clasohm@923
    52
qed "imageE";
clasohm@923
    53
clasohm@923
    54
goalw Fun.thy [o_def] "(f o g)``r = f``(g``r)";
clasohm@923
    55
by (rtac set_ext 1);
clasohm@923
    56
by (fast_tac (HOL_cs addIs [imageI] addSEs [imageE]) 1);
clasohm@923
    57
qed "image_compose";
clasohm@923
    58
clasohm@923
    59
goal Fun.thy "f``(A Un B) = f``A Un f``B";
clasohm@923
    60
by (rtac set_ext 1);
clasohm@923
    61
by (fast_tac (HOL_cs addIs [imageI,UnCI] addSEs [imageE,UnE]) 1);
clasohm@923
    62
qed "image_Un";
clasohm@923
    63
clasohm@923
    64
(*** inj(f): f is a one-to-one function ***)
clasohm@923
    65
clasohm@923
    66
val prems = goalw Fun.thy [inj_def]
clasohm@923
    67
    "[| !! x y. f(x) = f(y) ==> x=y |] ==> inj(f)";
clasohm@923
    68
by (fast_tac (HOL_cs addIs prems) 1);
clasohm@923
    69
qed "injI";
clasohm@923
    70
clasohm@923
    71
val [major] = goal Fun.thy "(!!x. g(f(x)) = x) ==> inj(f)";
clasohm@923
    72
by (rtac injI 1);
clasohm@923
    73
by (etac (arg_cong RS box_equals) 1);
clasohm@923
    74
by (rtac major 1);
clasohm@923
    75
by (rtac major 1);
clasohm@923
    76
qed "inj_inverseI";
clasohm@923
    77
clasohm@923
    78
val [major,minor] = goalw Fun.thy [inj_def]
clasohm@923
    79
    "[| inj(f); f(x) = f(y) |] ==> x=y";
clasohm@923
    80
by (rtac (major RS spec RS spec RS mp) 1);
clasohm@923
    81
by (rtac minor 1);
clasohm@923
    82
qed "injD";
clasohm@923
    83
clasohm@923
    84
(*Useful with the simplifier*)
clasohm@923
    85
val [major] = goal Fun.thy "inj(f) ==> (f(x) = f(y)) = (x=y)";
clasohm@923
    86
by (rtac iffI 1);
clasohm@923
    87
by (etac (major RS injD) 1);
clasohm@923
    88
by (etac arg_cong 1);
clasohm@923
    89
qed "inj_eq";
clasohm@923
    90
clasohm@923
    91
val [major] = goal Fun.thy "inj(f) ==> (@x.f(x)=f(y)) = y";
clasohm@923
    92
by (rtac (major RS injD) 1);
clasohm@923
    93
by (rtac selectI 1);
clasohm@923
    94
by (rtac refl 1);
clasohm@923
    95
qed "inj_select";
clasohm@923
    96
clasohm@923
    97
(*A one-to-one function has an inverse (given using select).*)
clasohm@923
    98
val [major] = goalw Fun.thy [Inv_def] "inj(f) ==> Inv f (f x) = x";
clasohm@923
    99
by (EVERY1 [rtac (major RS inj_select)]);
clasohm@923
   100
qed "Inv_f_f";
clasohm@923
   101
clasohm@923
   102
(* Useful??? *)
clasohm@923
   103
val [oneone,minor] = goal Fun.thy
clasohm@923
   104
    "[| inj(f); !!y. y: range(f) ==> P(Inv f y) |] ==> P(x)";
clasohm@923
   105
by (res_inst_tac [("t", "x")] (oneone RS (Inv_f_f RS subst)) 1);
clasohm@923
   106
by (rtac (rangeI RS minor) 1);
clasohm@923
   107
qed "inj_transfer";
clasohm@923
   108
clasohm@923
   109
clasohm@923
   110
(*** inj_onto f A: f is one-to-one over A ***)
clasohm@923
   111
clasohm@923
   112
val prems = goalw Fun.thy [inj_onto_def]
clasohm@923
   113
    "(!! x y. [| f(x) = f(y);  x:A;  y:A |] ==> x=y) ==> inj_onto f A";
clasohm@923
   114
by (fast_tac (HOL_cs addIs prems addSIs [ballI]) 1);
clasohm@923
   115
qed "inj_ontoI";
clasohm@923
   116
clasohm@923
   117
val [major] = goal Fun.thy 
clasohm@923
   118
    "(!!x. x:A ==> g(f(x)) = x) ==> inj_onto f A";
clasohm@923
   119
by (rtac inj_ontoI 1);
clasohm@923
   120
by (etac (apply_inverse RS trans) 1);
clasohm@923
   121
by (REPEAT (eresolve_tac [asm_rl,major] 1));
clasohm@923
   122
qed "inj_onto_inverseI";
clasohm@923
   123
clasohm@923
   124
val major::prems = goalw Fun.thy [inj_onto_def]
clasohm@923
   125
    "[| inj_onto f A;  f(x)=f(y);  x:A;  y:A |] ==> x=y";
clasohm@923
   126
by (rtac (major RS bspec RS bspec RS mp) 1);
clasohm@923
   127
by (REPEAT (resolve_tac prems 1));
clasohm@923
   128
qed "inj_ontoD";
clasohm@923
   129
clasohm@923
   130
goal Fun.thy "!!x y.[| inj_onto f A;  x:A;  y:A |] ==> (f(x)=f(y)) = (x=y)";
clasohm@923
   131
by (fast_tac (HOL_cs addSEs [inj_ontoD]) 1);
clasohm@923
   132
qed "inj_onto_iff";
clasohm@923
   133
clasohm@923
   134
val major::prems = goal Fun.thy
clasohm@923
   135
    "[| inj_onto f A;  ~x=y;  x:A;  y:A |] ==> ~ f(x)=f(y)";
clasohm@923
   136
by (rtac contrapos 1);
clasohm@923
   137
by (etac (major RS inj_ontoD) 2);
clasohm@923
   138
by (REPEAT (resolve_tac prems 1));
clasohm@923
   139
qed "inj_onto_contraD";
clasohm@923
   140
clasohm@923
   141
clasohm@923
   142
(*** Lemmas about inj ***)
clasohm@923
   143
clasohm@923
   144
val prems = goalw Fun.thy [o_def]
clasohm@923
   145
    "[| inj(f);  inj_onto g (range f) |] ==> inj(g o f)";
clasohm@923
   146
by (cut_facts_tac prems 1);
clasohm@923
   147
by (fast_tac (HOL_cs addIs [injI,rangeI]
clasohm@923
   148
                     addEs [injD,inj_ontoD]) 1);
clasohm@923
   149
qed "comp_inj";
clasohm@923
   150
clasohm@923
   151
val [prem] = goal Fun.thy "inj(f) ==> inj_onto f A";
clasohm@923
   152
by (fast_tac (HOL_cs addIs [prem RS injD, inj_ontoI]) 1);
clasohm@923
   153
qed "inj_imp";
clasohm@923
   154
clasohm@923
   155
val [prem] = goalw Fun.thy [Inv_def] "y : range(f) ==> f(Inv f y) = y";
clasohm@923
   156
by (EVERY1 [rtac (prem RS rangeE), rtac selectI, etac sym]);
clasohm@923
   157
qed "f_Inv_f";
clasohm@923
   158
clasohm@923
   159
val prems = goal Fun.thy
clasohm@923
   160
    "[| Inv f x=Inv f y; x: range(f);  y: range(f) |] ==> x=y";
clasohm@923
   161
by (rtac (arg_cong RS box_equals) 1);
clasohm@923
   162
by (REPEAT (resolve_tac (prems @ [f_Inv_f]) 1));
clasohm@923
   163
qed "Inv_injective";
clasohm@923
   164
clasohm@923
   165
val prems = goal Fun.thy
clasohm@923
   166
    "[| inj(f);  A<=range(f) |] ==> inj_onto (Inv f) A";
clasohm@923
   167
by (cut_facts_tac prems 1);
clasohm@923
   168
by (fast_tac (HOL_cs addIs [inj_ontoI] 
clasohm@1465
   169
                     addEs [Inv_injective,injD,subsetD]) 1);
clasohm@923
   170
qed "inj_onto_Inv";
clasohm@923
   171
clasohm@923
   172
clasohm@923
   173
(*** Set reasoning tools ***)
clasohm@923
   174
clasohm@923
   175
val set_cs = HOL_cs 
clasohm@923
   176
    addSIs [ballI, PowI, subsetI, InterI, INT_I, INT1_I, CollectI, 
clasohm@1465
   177
            ComplI, IntI, DiffI, UnCI, insertCI] 
clasohm@923
   178
    addIs  [bexI, UnionI, UN_I, UN1_I, imageI, rangeI] 
clasohm@923
   179
    addSEs [bexE, make_elim PowD, UnionE, UN_E, UN1_E, DiffE,
paulson@1561
   180
	    make_elim singleton_inject,
clasohm@1465
   181
            CollectE, ComplE, IntE, UnE, insertE, imageE, rangeE, emptyE] 
clasohm@923
   182
    addEs  [ballE, InterD, InterE, INT_D, INT_E, make_elim INT1_D,
clasohm@1465
   183
            subsetD, subsetCE];
clasohm@923
   184
clasohm@923
   185
fun cfast_tac prems = cut_facts_tac prems THEN' fast_tac set_cs;
clasohm@923
   186
clasohm@923
   187
clasohm@923
   188
fun prover s = prove_goal Fun.thy s (fn _=>[fast_tac set_cs 1]);
clasohm@923
   189
clasohm@923
   190
val mem_simps = map prover
clasohm@923
   191
 [ "(a : A Un B)   =  (a:A | a:B)",
clasohm@923
   192
   "(a : A Int B)  =  (a:A & a:B)",
clasohm@923
   193
   "(a : Compl(B)) =  (~a:B)",
clasohm@923
   194
   "(a : A-B)      =  (a:A & ~a:B)",
clasohm@923
   195
   "(a : {b})      =  (a=b)",
clasohm@923
   196
   "(a : {x.P(x)}) =  P(a)" ];
clasohm@923
   197
clasohm@923
   198
val mksimps_pairs = ("Ball",[bspec]) :: mksimps_pairs;
clasohm@923
   199
clasohm@1264
   200
simpset := !simpset addsimps mem_simps
clasohm@1264
   201
                    addcongs [ball_cong,bex_cong]
clasohm@1264
   202
                    setmksimps (mksimps mksimps_pairs);