src/HOL/Fun.ML
author nipkow
Mon, 27 Apr 1998 16:45:11 +0200
changeset 4830 bd73675adbed
parent 4656 134d24ddaad3
child 5069 3ea049f7979d
permissions -rw-r--r--
Added a few lemmas. Renamed expand_const -> split_const.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1264
diff changeset
     1
(*  Title:      HOL/Fun
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     2
    ID:         $Id$
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1264
diff changeset
     3
    Author:     Tobias Nipkow, Cambridge University Computer Laboratory
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     4
    Copyright   1993  University of Cambridge
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     5
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     6
Lemmas about functions.
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     7
*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     8
4656
134d24ddaad3 Proved choice and bchoice; changed Fun.thy -> thy
paulson
parents: 4089
diff changeset
     9
134d24ddaad3 Proved choice and bchoice; changed Fun.thy -> thy
paulson
parents: 4089
diff changeset
    10
goal thy "(f = g) = (!x. f(x)=g(x))";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    11
by (rtac iffI 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 923
diff changeset
    12
by (Asm_simp_tac 1);
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 923
diff changeset
    13
by (rtac ext 1 THEN Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    14
qed "expand_fun_eq";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    15
4656
134d24ddaad3 Proved choice and bchoice; changed Fun.thy -> thy
paulson
parents: 4089
diff changeset
    16
val prems = goal thy
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    17
    "[| f(x)=u;  !!x. P(x) ==> g(f(x)) = x;  P(x) |] ==> x=g(u)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    18
by (rtac (arg_cong RS box_equals) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    19
by (REPEAT (resolve_tac (prems@[refl]) 1));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    20
qed "apply_inverse";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    21
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    22
4656
134d24ddaad3 Proved choice and bchoice; changed Fun.thy -> thy
paulson
parents: 4089
diff changeset
    23
(** "Axiom" of Choice, proved using the description operator **)
134d24ddaad3 Proved choice and bchoice; changed Fun.thy -> thy
paulson
parents: 4089
diff changeset
    24
134d24ddaad3 Proved choice and bchoice; changed Fun.thy -> thy
paulson
parents: 4089
diff changeset
    25
goal HOL.thy "!!Q. ALL x. EX y. Q x y ==> EX f. ALL x. Q x (f x)";
134d24ddaad3 Proved choice and bchoice; changed Fun.thy -> thy
paulson
parents: 4089
diff changeset
    26
by (fast_tac (claset() addEs [selectI]) 1);
134d24ddaad3 Proved choice and bchoice; changed Fun.thy -> thy
paulson
parents: 4089
diff changeset
    27
qed "choice";
134d24ddaad3 Proved choice and bchoice; changed Fun.thy -> thy
paulson
parents: 4089
diff changeset
    28
134d24ddaad3 Proved choice and bchoice; changed Fun.thy -> thy
paulson
parents: 4089
diff changeset
    29
goal Set.thy "!!S. ALL x:S. EX y. Q x y ==> EX f. ALL x:S. Q x (f x)";
134d24ddaad3 Proved choice and bchoice; changed Fun.thy -> thy
paulson
parents: 4089
diff changeset
    30
by (fast_tac (claset() addEs [selectI]) 1);
134d24ddaad3 Proved choice and bchoice; changed Fun.thy -> thy
paulson
parents: 4089
diff changeset
    31
qed "bchoice";
134d24ddaad3 Proved choice and bchoice; changed Fun.thy -> thy
paulson
parents: 4089
diff changeset
    32
134d24ddaad3 Proved choice and bchoice; changed Fun.thy -> thy
paulson
parents: 4089
diff changeset
    33
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    34
(*** inj(f): f is a one-to-one function ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    35
4656
134d24ddaad3 Proved choice and bchoice; changed Fun.thy -> thy
paulson
parents: 4089
diff changeset
    36
val prems = goalw thy [inj_def]
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    37
    "[| !! x y. f(x) = f(y) ==> x=y |] ==> inj(f)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
    38
by (blast_tac (claset() addIs prems) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    39
qed "injI";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    40
4656
134d24ddaad3 Proved choice and bchoice; changed Fun.thy -> thy
paulson
parents: 4089
diff changeset
    41
val [major] = goal thy "(!!x. g(f(x)) = x) ==> inj(f)";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    42
by (rtac injI 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    43
by (etac (arg_cong RS box_equals) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    44
by (rtac major 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    45
by (rtac major 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    46
qed "inj_inverseI";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    47
4656
134d24ddaad3 Proved choice and bchoice; changed Fun.thy -> thy
paulson
parents: 4089
diff changeset
    48
val [major,minor] = goalw thy [inj_def]
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    49
    "[| inj(f); f(x) = f(y) |] ==> x=y";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    50
by (rtac (major RS spec RS spec RS mp) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    51
by (rtac minor 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    52
qed "injD";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    53
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    54
(*Useful with the simplifier*)
4656
134d24ddaad3 Proved choice and bchoice; changed Fun.thy -> thy
paulson
parents: 4089
diff changeset
    55
val [major] = goal thy "inj(f) ==> (f(x) = f(y)) = (x=y)";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    56
by (rtac iffI 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    57
by (etac (major RS injD) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    58
by (etac arg_cong 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    59
qed "inj_eq";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    60
4656
134d24ddaad3 Proved choice and bchoice; changed Fun.thy -> thy
paulson
parents: 4089
diff changeset
    61
val [major] = goal thy "inj(f) ==> (@x. f(x)=f(y)) = y";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    62
by (rtac (major RS injD) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    63
by (rtac selectI 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    64
by (rtac refl 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    65
qed "inj_select";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    66
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    67
(*A one-to-one function has an inverse (given using select).*)
4656
134d24ddaad3 Proved choice and bchoice; changed Fun.thy -> thy
paulson
parents: 4089
diff changeset
    68
val [major] = goalw thy [inv_def] "inj(f) ==> inv f (f x) = x";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    69
by (EVERY1 [rtac (major RS inj_select)]);
2912
3fac3e8d5d3e moved inj and surj from Set to Fun and Inv -> inv.
nipkow
parents: 2890
diff changeset
    70
qed "inv_f_f";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    71
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    72
(* Useful??? *)
4656
134d24ddaad3 Proved choice and bchoice; changed Fun.thy -> thy
paulson
parents: 4089
diff changeset
    73
val [oneone,minor] = goal thy
2912
3fac3e8d5d3e moved inj and surj from Set to Fun and Inv -> inv.
nipkow
parents: 2890
diff changeset
    74
    "[| inj(f); !!y. y: range(f) ==> P(inv f y) |] ==> P(x)";
3fac3e8d5d3e moved inj and surj from Set to Fun and Inv -> inv.
nipkow
parents: 2890
diff changeset
    75
by (res_inst_tac [("t", "x")] (oneone RS (inv_f_f RS subst)) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    76
by (rtac (rangeI RS minor) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    77
qed "inj_transfer";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    78
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    79
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
    80
(*** inj_on f A: f is one-to-one over A ***)
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    81
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
    82
val prems = goalw thy [inj_on_def]
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
    83
    "(!! x y. [| f(x) = f(y);  x:A;  y:A |] ==> x=y) ==> inj_on f A";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
    84
by (blast_tac (claset() addIs prems) 1);
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
    85
qed "inj_onI";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    86
4656
134d24ddaad3 Proved choice and bchoice; changed Fun.thy -> thy
paulson
parents: 4089
diff changeset
    87
val [major] = goal thy 
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
    88
    "(!!x. x:A ==> g(f(x)) = x) ==> inj_on f A";
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
    89
by (rtac inj_onI 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    90
by (etac (apply_inverse RS trans) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    91
by (REPEAT (eresolve_tac [asm_rl,major] 1));
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
    92
qed "inj_on_inverseI";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    93
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
    94
val major::prems = goalw thy [inj_on_def]
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
    95
    "[| inj_on f A;  f(x)=f(y);  x:A;  y:A |] ==> x=y";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    96
by (rtac (major RS bspec RS bspec RS mp) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    97
by (REPEAT (resolve_tac prems 1));
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
    98
qed "inj_onD";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    99
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
   100
goal thy "!!x y.[| inj_on f A;  x:A;  y:A |] ==> (f(x)=f(y)) = (x=y)";
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
   101
by (blast_tac (claset() addSDs [inj_onD]) 1);
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
   102
qed "inj_on_iff";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   103
4656
134d24ddaad3 Proved choice and bchoice; changed Fun.thy -> thy
paulson
parents: 4089
diff changeset
   104
val major::prems = goal thy
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
   105
    "[| inj_on f A;  ~x=y;  x:A;  y:A |] ==> ~ f(x)=f(y)";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   106
by (rtac contrapos 1);
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
   107
by (etac (major RS inj_onD) 2);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   108
by (REPEAT (resolve_tac prems 1));
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
   109
qed "inj_on_contraD";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   110
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
   111
goalw thy [inj_on_def]
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
   112
    "!!A B. [| A<=B; inj_on f B |] ==> inj_on f A";
3341
89fe22bf9f54 New theorem subset_inj_onto
paulson
parents: 2935
diff changeset
   113
by (Blast_tac 1);
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
   114
qed "subset_inj_on";
3341
89fe22bf9f54 New theorem subset_inj_onto
paulson
parents: 2935
diff changeset
   115
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   116
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   117
(*** Lemmas about inj ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   118
4656
134d24ddaad3 Proved choice and bchoice; changed Fun.thy -> thy
paulson
parents: 4089
diff changeset
   119
goalw thy [o_def]
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
   120
    "!!f g. [| inj(f);  inj_on g (range f) |] ==> inj(g o f)";
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
   121
by (fast_tac (claset() addIs [injI] addEs [injD, inj_onD]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   122
qed "comp_inj";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   123
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
   124
val [prem] = goal thy "inj(f) ==> inj_on f A";
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
   125
by (blast_tac (claset() addIs [prem RS injD, inj_onI]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   126
qed "inj_imp";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   127
4656
134d24ddaad3 Proved choice and bchoice; changed Fun.thy -> thy
paulson
parents: 4089
diff changeset
   128
val [prem] = goalw thy [inv_def] "y : range(f) ==> f(inv f y) = y";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   129
by (EVERY1 [rtac (prem RS rangeE), rtac selectI, etac sym]);
2912
3fac3e8d5d3e moved inj and surj from Set to Fun and Inv -> inv.
nipkow
parents: 2890
diff changeset
   130
qed "f_inv_f";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   131
4656
134d24ddaad3 Proved choice and bchoice; changed Fun.thy -> thy
paulson
parents: 4089
diff changeset
   132
val prems = goal thy
2912
3fac3e8d5d3e moved inj and surj from Set to Fun and Inv -> inv.
nipkow
parents: 2890
diff changeset
   133
    "[| inv f x=inv f y; x: range(f);  y: range(f) |] ==> x=y";
3fac3e8d5d3e moved inj and surj from Set to Fun and Inv -> inv.
nipkow
parents: 2890
diff changeset
   134
by (rtac (arg_cong RS box_equals) 1);
3fac3e8d5d3e moved inj and surj from Set to Fun and Inv -> inv.
nipkow
parents: 2890
diff changeset
   135
by (REPEAT (resolve_tac (prems @ [f_inv_f]) 1));
3fac3e8d5d3e moved inj and surj from Set to Fun and Inv -> inv.
nipkow
parents: 2890
diff changeset
   136
qed "inv_injective";
3fac3e8d5d3e moved inj and surj from Set to Fun and Inv -> inv.
nipkow
parents: 2890
diff changeset
   137
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
   138
goal thy "!!f. [| inj(f);  A<=range(f) |] ==> inj_on (inv f) A";
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
   139
by (fast_tac (claset() addIs [inj_onI] 
2912
3fac3e8d5d3e moved inj and surj from Set to Fun and Inv -> inv.
nipkow
parents: 2890
diff changeset
   140
                      addEs [inv_injective,injD]) 1);
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
   141
qed "inj_on_inv";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   142
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
   143
goalw thy [inj_on_def]
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
   144
   "!!f. [| inj_on f C;  A<=C;  B<=C |] ==> f``(A Int B) = f``A Int f``B";
4059
59c1422c9da5 New Blast_tac (and minor tidying...)
paulson
parents: 3842
diff changeset
   145
by (Blast_tac 1);
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
   146
qed "inj_on_image_Int";
4059
59c1422c9da5 New Blast_tac (and minor tidying...)
paulson
parents: 3842
diff changeset
   147
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
   148
goalw thy [inj_on_def]
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
   149
   "!!f. [| inj_on f C;  A<=C;  B<=C |] ==> f``(A-B) = f``A - f``B";
4059
59c1422c9da5 New Blast_tac (and minor tidying...)
paulson
parents: 3842
diff changeset
   150
by (Blast_tac 1);
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4656
diff changeset
   151
qed "inj_on_image_set_diff";
4059
59c1422c9da5 New Blast_tac (and minor tidying...)
paulson
parents: 3842
diff changeset
   152
59c1422c9da5 New Blast_tac (and minor tidying...)
paulson
parents: 3842
diff changeset
   153
goalw thy [inj_def] "!!f. inj f ==> f``(A Int B) = f``A Int f``B";
59c1422c9da5 New Blast_tac (and minor tidying...)
paulson
parents: 3842
diff changeset
   154
by (Blast_tac 1);
59c1422c9da5 New Blast_tac (and minor tidying...)
paulson
parents: 3842
diff changeset
   155
qed "image_Int";
59c1422c9da5 New Blast_tac (and minor tidying...)
paulson
parents: 3842
diff changeset
   156
59c1422c9da5 New Blast_tac (and minor tidying...)
paulson
parents: 3842
diff changeset
   157
goalw thy [inj_def] "!!f. inj f ==> f``(A-B) = f``A - f``B";
59c1422c9da5 New Blast_tac (and minor tidying...)
paulson
parents: 3842
diff changeset
   158
by (Blast_tac 1);
59c1422c9da5 New Blast_tac (and minor tidying...)
paulson
parents: 3842
diff changeset
   159
qed "image_set_diff";
59c1422c9da5 New Blast_tac (and minor tidying...)
paulson
parents: 3842
diff changeset
   160
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   161
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   162
val set_cs = claset() delrules [equalityI];