src/HOL/Fun.ML
author paulson
Fri Apr 04 11:18:19 1997 +0200 (1997-04-04)
changeset 2890 f27002fc531d
parent 2499 0bc87b063447
child 2912 3fac3e8d5d3e
permissions -rw-r--r--
Adds image_eqI instead of imageI, as the former is more general
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@923
     9
goal Fun.thy "(f = g) = (!x. f(x)=g(x))";
clasohm@923
    10
by (rtac iffI 1);
clasohm@1264
    11
by (Asm_simp_tac 1);
clasohm@1264
    12
by (rtac ext 1 THEN Asm_simp_tac 1);
clasohm@923
    13
qed "expand_fun_eq";
clasohm@923
    14
clasohm@923
    15
val prems = goal Fun.thy
clasohm@923
    16
    "[| f(x)=u;  !!x. P(x) ==> g(f(x)) = x;  P(x) |] ==> x=g(u)";
clasohm@923
    17
by (rtac (arg_cong RS box_equals) 1);
clasohm@923
    18
by (REPEAT (resolve_tac (prems@[refl]) 1));
clasohm@923
    19
qed "apply_inverse";
clasohm@923
    20
clasohm@923
    21
paulson@1883
    22
(*** Image of a set under a function ***)
clasohm@923
    23
clasohm@923
    24
(*Frequently b does not have the syntactic form of f(x).*)
clasohm@923
    25
val prems = goalw Fun.thy [image_def] "[| b=f(x);  x:A |] ==> b : f``A";
clasohm@923
    26
by (REPEAT (resolve_tac (prems @ [CollectI,bexI,prem]) 1));
clasohm@923
    27
qed "image_eqI";
clasohm@923
    28
paulson@1883
    29
bind_thm ("imageI", refl RS image_eqI);
clasohm@923
    30
clasohm@923
    31
(*The eta-expansion gives variable-name preservation.*)
clasohm@923
    32
val major::prems = goalw Fun.thy [image_def]
clasohm@923
    33
    "[| b : (%x.f(x))``A;  !!x.[| b=f(x);  x:A |] ==> P |] ==> P"; 
clasohm@923
    34
by (rtac (major RS CollectD RS bexE) 1);
clasohm@923
    35
by (REPEAT (ares_tac prems 1));
clasohm@923
    36
qed "imageE";
clasohm@923
    37
paulson@2890
    38
AddIs  [image_eqI];
paulson@2499
    39
AddSEs [imageE]; 
paulson@2499
    40
clasohm@923
    41
goalw Fun.thy [o_def] "(f o g)``r = f``(g``r)";
paulson@2499
    42
by (Fast_tac 1);
clasohm@923
    43
qed "image_compose";
clasohm@923
    44
clasohm@923
    45
goal Fun.thy "f``(A Un B) = f``A Un f``B";
paulson@2499
    46
by (Fast_tac 1);
clasohm@923
    47
qed "image_Un";
clasohm@923
    48
paulson@1883
    49
(*** Range of a function -- just a translation for image! ***)
paulson@1883
    50
paulson@1883
    51
goal Fun.thy "!!b. b=f(x) ==> b : range(f)";
paulson@1883
    52
by (EVERY1 [etac image_eqI, rtac UNIV_I]);
paulson@1883
    53
bind_thm ("range_eqI", UNIV_I RSN (2,image_eqI));
paulson@1883
    54
paulson@1883
    55
bind_thm ("rangeI", UNIV_I RS imageI);
paulson@1883
    56
paulson@1883
    57
val [major,minor] = goal Fun.thy 
paulson@1883
    58
    "[| b : range(%x.f(x));  !!x. b=f(x) ==> P |] ==> P"; 
paulson@1883
    59
by (rtac (major RS imageE) 1);
paulson@1883
    60
by (etac minor 1);
paulson@1883
    61
qed "rangeE";
paulson@2890
    62
paulson@2890
    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)";
berghofe@1754
    68
by (fast_tac (!claset 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";
paulson@2499
   114
by (fast_tac (!claset addIs prems) 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)";
berghofe@1754
   131
by (fast_tac (!claset 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);
paulson@2499
   147
by (fast_tac (!claset addIs [injI]
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";
berghofe@1754
   152
by (fast_tac (!claset 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);
berghofe@1754
   168
by (fast_tac (!claset addIs [inj_ontoI] 
paulson@2499
   169
                      addEs [Inv_injective,injD]) 1);
clasohm@923
   170
qed "inj_onto_Inv";
clasohm@923
   171
clasohm@923
   172
paulson@2499
   173
AddIs  [rangeI]; 
paulson@2499
   174
AddSEs [rangeE]; 
berghofe@1754
   175
paulson@1837
   176
val set_cs = !claset delrules [equalityI];
clasohm@923
   177
paulson@1883
   178