src/HOL/Fun.thy
author wenzelm
Thu, 05 Jan 2023 21:33:49 +0100
changeset 76923 8a66a88cd5dc
parent 76722 b1d57dd345e1
child 77138 c8597292cd41
permissions -rw-r--r--
isabelle update -u path_cartouches;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 923
diff changeset
     1
(*  Title:      HOL/Fun.thy
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 923
diff changeset
     2
    Author:     Tobias Nipkow, Cambridge University Computer Laboratory
55019
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
     3
    Author:     Andrei Popescu, TU Muenchen
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
     4
    Copyright   1994, 2012
18154
0c05abaf6244 add header
huffman
parents: 17956
diff changeset
     5
*)
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     6
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60303
diff changeset
     7
section \<open>Notions about functions\<close>
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     8
15510
9de204d7b699 new foldSet proofs
paulson
parents: 15439
diff changeset
     9
theory Fun
63575
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    10
  imports Set
69913
ca515cf61651 more specific keyword kinds;
wenzelm
parents: 69768
diff changeset
    11
  keywords "functor" :: thy_goal_defn
15131
c69542757a4d New theory header syntax.
nipkow
parents: 15111
diff changeset
    12
begin
2912
3fac3e8d5d3e moved inj and surj from Set to Fun and Inv -> inv.
nipkow
parents: 1475
diff changeset
    13
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
    14
lemma apply_inverse: "f x = u \<Longrightarrow> (\<And>x. P x \<Longrightarrow> g (f x) = x) \<Longrightarrow> P x \<Longrightarrow> x = g u"
26147
ae2bf929e33c moved some set lemmas to Set.thy
haftmann
parents: 26105
diff changeset
    15
  by auto
2912
3fac3e8d5d3e moved inj and surj from Set to Fun and Inv -> inv.
nipkow
parents: 1475
diff changeset
    16
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
    17
text \<open>Uniqueness, so NOT the axiom of choice.\<close>
59504
8c6747dba731 New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
    18
lemma uniq_choice: "\<forall>x. \<exists>!y. Q x y \<Longrightarrow> \<exists>f. \<forall>x. Q x (f x)"
8c6747dba731 New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
    19
  by (force intro: theI')
8c6747dba731 New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
    20
8c6747dba731 New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
    21
lemma b_uniq_choice: "\<forall>x\<in>S. \<exists>!y. Q x y \<Longrightarrow> \<exists>f. \<forall>x\<in>S. Q x (f x)"
8c6747dba731 New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
    22
  by (force intro: theI')
12258
5da24e7e9aba got rid of theory Inverse_Image;
wenzelm
parents: 12114
diff changeset
    23
63400
249fa34faba2 misc tuning and modernization;
wenzelm
parents: 63365
diff changeset
    24
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61699
diff changeset
    25
subsection \<open>The Identity Function \<open>id\<close>\<close>
6171
cd237a10cbf8 inj is now a translation of inj_on
paulson
parents: 5852
diff changeset
    26
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
    27
definition id :: "'a \<Rightarrow> 'a"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
    28
  where "id = (\<lambda>x. x)"
13910
f9a9ef16466f Added thms
nipkow
parents: 13637
diff changeset
    29
26147
ae2bf929e33c moved some set lemmas to Set.thy
haftmann
parents: 26105
diff changeset
    30
lemma id_apply [simp]: "id x = x"
ae2bf929e33c moved some set lemmas to Set.thy
haftmann
parents: 26105
diff changeset
    31
  by (simp add: id_def)
ae2bf929e33c moved some set lemmas to Set.thy
haftmann
parents: 26105
diff changeset
    32
47579
28f6f4ad69bf tuned lemmas (v)image_id;
huffman
parents: 47488
diff changeset
    33
lemma image_id [simp]: "image id = id"
28f6f4ad69bf tuned lemmas (v)image_id;
huffman
parents: 47488
diff changeset
    34
  by (simp add: id_def fun_eq_iff)
26147
ae2bf929e33c moved some set lemmas to Set.thy
haftmann
parents: 26105
diff changeset
    35
47579
28f6f4ad69bf tuned lemmas (v)image_id;
huffman
parents: 47488
diff changeset
    36
lemma vimage_id [simp]: "vimage id = id"
28f6f4ad69bf tuned lemmas (v)image_id;
huffman
parents: 47488
diff changeset
    37
  by (simp add: id_def fun_eq_iff)
26147
ae2bf929e33c moved some set lemmas to Set.thy
haftmann
parents: 26105
diff changeset
    38
62843
313d3b697c9a Mostly renaming (from HOL Light to Isabelle conventions), with a couple of new results
paulson <lp15@cam.ac.uk>
parents: 62618
diff changeset
    39
lemma eq_id_iff: "(\<forall>x. f x = x) \<longleftrightarrow> f = id"
313d3b697c9a Mostly renaming (from HOL Light to Isabelle conventions), with a couple of new results
paulson <lp15@cam.ac.uk>
parents: 62618
diff changeset
    40
  by auto
313d3b697c9a Mostly renaming (from HOL Light to Isabelle conventions), with a couple of new results
paulson <lp15@cam.ac.uk>
parents: 62618
diff changeset
    41
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 51717
diff changeset
    42
code_printing
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 51717
diff changeset
    43
  constant id \<rightharpoonup> (Haskell) "id"
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 51717
diff changeset
    44
26147
ae2bf929e33c moved some set lemmas to Set.thy
haftmann
parents: 26105
diff changeset
    45
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61699
diff changeset
    46
subsection \<open>The Composition Operator \<open>f \<circ> g\<close>\<close>
26147
ae2bf929e33c moved some set lemmas to Set.thy
haftmann
parents: 26105
diff changeset
    47
61955
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61799
diff changeset
    48
definition comp :: "('b \<Rightarrow> 'c) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'c"  (infixl "\<circ>" 55)
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61799
diff changeset
    49
  where "f \<circ> g = (\<lambda>x. f (g x))"
11123
15ffc08f905e removed whitespace
oheimb
parents: 10826
diff changeset
    50
61955
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61799
diff changeset
    51
notation (ASCII)
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61799
diff changeset
    52
  comp  (infixl "o" 55)
19656
09be06943252 tuned concrete syntax -- abbreviation/const_syntax;
wenzelm
parents: 19536
diff changeset
    53
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
    54
lemma comp_apply [simp]: "(f \<circ> g) x = f (g x)"
49739
13aa6d8268ec consolidated names of theorems on composition;
haftmann
parents: 48891
diff changeset
    55
  by (simp add: comp_def)
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
    56
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
    57
lemma comp_assoc: "(f \<circ> g) \<circ> h = f \<circ> (g \<circ> h)"
49739
13aa6d8268ec consolidated names of theorems on composition;
haftmann
parents: 48891
diff changeset
    58
  by (simp add: fun_eq_iff)
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
    59
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
    60
lemma id_comp [simp]: "id \<circ> g = g"
49739
13aa6d8268ec consolidated names of theorems on composition;
haftmann
parents: 48891
diff changeset
    61
  by (simp add: fun_eq_iff)
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
    62
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
    63
lemma comp_id [simp]: "f \<circ> id = f"
49739
13aa6d8268ec consolidated names of theorems on composition;
haftmann
parents: 48891
diff changeset
    64
  by (simp add: fun_eq_iff)
13aa6d8268ec consolidated names of theorems on composition;
haftmann
parents: 48891
diff changeset
    65
63575
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    66
lemma comp_eq_dest: "a \<circ> b = c \<circ> d \<Longrightarrow> a (b v) = c (d v)"
49739
13aa6d8268ec consolidated names of theorems on composition;
haftmann
parents: 48891
diff changeset
    67
  by (simp add: fun_eq_iff)
34150
22acb8b38639 moved lemmas o_eq_dest, o_eq_elim here
haftmann
parents: 34101
diff changeset
    68
63575
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    69
lemma comp_eq_elim: "a \<circ> b = c \<circ> d \<Longrightarrow> ((\<And>v. a (b v) = c (d v)) \<Longrightarrow> R) \<Longrightarrow> R"
61204
3e491e34a62e new lemmas and movement of lemmas into place
paulson
parents: 60929
diff changeset
    70
  by (simp add: fun_eq_iff)
34150
22acb8b38639 moved lemmas o_eq_dest, o_eq_elim here
haftmann
parents: 34101
diff changeset
    71
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
    72
lemma comp_eq_dest_lhs: "a \<circ> b = c \<Longrightarrow> a (b v) = c v"
55066
blanchet
parents: 55019
diff changeset
    73
  by clarsimp
blanchet
parents: 55019
diff changeset
    74
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
    75
lemma comp_eq_id_dest: "a \<circ> b = id \<circ> c \<Longrightarrow> a (b v) = c v"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
    76
  by clarsimp
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
    77
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
    78
lemma image_comp: "f ` (g ` r) = (f \<circ> g) ` r"
33044
fd0a9c794ec1 Some new lemmas concerning sets
paulson
parents: 32998
diff changeset
    79
  by auto
fd0a9c794ec1 Some new lemmas concerning sets
paulson
parents: 32998
diff changeset
    80
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
    81
lemma vimage_comp: "f -` (g -` x) = (g \<circ> f) -` x"
49739
13aa6d8268ec consolidated names of theorems on composition;
haftmann
parents: 48891
diff changeset
    82
  by auto
13aa6d8268ec consolidated names of theorems on composition;
haftmann
parents: 48891
diff changeset
    83
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
    84
lemma image_eq_imp_comp: "f ` A = g ` B \<Longrightarrow> (h \<circ> f) ` A = (h \<circ> g) ` B"
59504
8c6747dba731 New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
    85
  by (auto simp: comp_def elim!: equalityE)
8c6747dba731 New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
    86
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67226
diff changeset
    87
lemma image_bind: "f ` (Set.bind A g) = Set.bind A ((`) f \<circ> g)"
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
    88
  by (auto simp add: Set.bind_def)
59512
9bf568cc71a4 add lemmas about bind and image
Andreas Lochbihler
parents: 59507
diff changeset
    89
9bf568cc71a4 add lemmas about bind and image
Andreas Lochbihler
parents: 59507
diff changeset
    90
lemma bind_image: "Set.bind (f ` A) g = Set.bind A (g \<circ> f)"
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
    91
  by (auto simp add: Set.bind_def)
59512
9bf568cc71a4 add lemmas about bind and image
Andreas Lochbihler
parents: 59507
diff changeset
    92
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
    93
lemma (in group_add) minus_comp_minus [simp]: "uminus \<circ> uminus = id"
60929
bb3610d34e2e more lemmas
haftmann
parents: 60758
diff changeset
    94
  by (simp add: fun_eq_iff)
bb3610d34e2e more lemmas
haftmann
parents: 60758
diff changeset
    95
74123
7c5842b06114 clarified abstract and concrete boolean algebras
haftmann
parents: 74101
diff changeset
    96
lemma (in boolean_algebra) minus_comp_minus [simp]: "uminus \<circ> uminus = id"
60929
bb3610d34e2e more lemmas
haftmann
parents: 60758
diff changeset
    97
  by (simp add: fun_eq_iff)
bb3610d34e2e more lemmas
haftmann
parents: 60758
diff changeset
    98
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 51717
diff changeset
    99
code_printing
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 51717
diff changeset
   100
  constant comp \<rightharpoonup> (SML) infixl 5 "o" and (Haskell) infixr 9 "."
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 51717
diff changeset
   101
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   102
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61699
diff changeset
   103
subsection \<open>The Forward Composition Operator \<open>fcomp\<close>\<close>
26357
19b153ebda0b added forward composition
haftmann
parents: 26342
diff changeset
   104
63575
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   105
definition fcomp :: "('a \<Rightarrow> 'b) \<Rightarrow> ('b \<Rightarrow> 'c) \<Rightarrow> 'a \<Rightarrow> 'c"  (infixl "\<circ>>" 60)
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   106
  where "f \<circ>> g = (\<lambda>x. g (f x))"
26357
19b153ebda0b added forward composition
haftmann
parents: 26342
diff changeset
   107
37751
89e16802b6cc nicer xsymbol syntax for fcomp and scomp
haftmann
parents: 36176
diff changeset
   108
lemma fcomp_apply [simp]:  "(f \<circ>> g) x = g (f x)"
26357
19b153ebda0b added forward composition
haftmann
parents: 26342
diff changeset
   109
  by (simp add: fcomp_def)
19b153ebda0b added forward composition
haftmann
parents: 26342
diff changeset
   110
37751
89e16802b6cc nicer xsymbol syntax for fcomp and scomp
haftmann
parents: 36176
diff changeset
   111
lemma fcomp_assoc: "(f \<circ>> g) \<circ>> h = f \<circ>> (g \<circ>> h)"
26357
19b153ebda0b added forward composition
haftmann
parents: 26342
diff changeset
   112
  by (simp add: fcomp_def)
19b153ebda0b added forward composition
haftmann
parents: 26342
diff changeset
   113
37751
89e16802b6cc nicer xsymbol syntax for fcomp and scomp
haftmann
parents: 36176
diff changeset
   114
lemma id_fcomp [simp]: "id \<circ>> g = g"
26357
19b153ebda0b added forward composition
haftmann
parents: 26342
diff changeset
   115
  by (simp add: fcomp_def)
19b153ebda0b added forward composition
haftmann
parents: 26342
diff changeset
   116
37751
89e16802b6cc nicer xsymbol syntax for fcomp and scomp
haftmann
parents: 36176
diff changeset
   117
lemma fcomp_id [simp]: "f \<circ>> id = f"
26357
19b153ebda0b added forward composition
haftmann
parents: 26342
diff changeset
   118
  by (simp add: fcomp_def)
19b153ebda0b added forward composition
haftmann
parents: 26342
diff changeset
   119
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   120
lemma fcomp_comp: "fcomp f g = comp g f"
61699
a81dc5c4d6a9 New theorems mostly from Peter Gammie
paulson <lp15@cam.ac.uk>
parents: 61630
diff changeset
   121
  by (simp add: ext)
a81dc5c4d6a9 New theorems mostly from Peter Gammie
paulson <lp15@cam.ac.uk>
parents: 61630
diff changeset
   122
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 51717
diff changeset
   123
code_printing
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 51717
diff changeset
   124
  constant fcomp \<rightharpoonup> (Eval) infixl 1 "#>"
31202
52d332f8f909 pretty printing of functional combinators for evaluation code
haftmann
parents: 31080
diff changeset
   125
37751
89e16802b6cc nicer xsymbol syntax for fcomp and scomp
haftmann
parents: 36176
diff changeset
   126
no_notation fcomp (infixl "\<circ>>" 60)
26588
d83271bfaba5 removed syntax from monad combinators; renamed mbind to scomp
haftmann
parents: 26357
diff changeset
   127
26357
19b153ebda0b added forward composition
haftmann
parents: 26342
diff changeset
   128
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60303
diff changeset
   129
subsection \<open>Mapping functions\<close>
40602
91e583511113 map_fun combinator in theory Fun
haftmann
parents: 39302
diff changeset
   130
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   131
definition map_fun :: "('c \<Rightarrow> 'a) \<Rightarrow> ('b \<Rightarrow> 'd) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'c \<Rightarrow> 'd"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   132
  where "map_fun f g h = g \<circ> h \<circ> f"
40602
91e583511113 map_fun combinator in theory Fun
haftmann
parents: 39302
diff changeset
   133
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   134
lemma map_fun_apply [simp]: "map_fun f g h x = g (h (f x))"
40602
91e583511113 map_fun combinator in theory Fun
haftmann
parents: 39302
diff changeset
   135
  by (simp add: map_fun_def)
91e583511113 map_fun combinator in theory Fun
haftmann
parents: 39302
diff changeset
   136
91e583511113 map_fun combinator in theory Fun
haftmann
parents: 39302
diff changeset
   137
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60303
diff changeset
   138
subsection \<open>Injectivity and Bijectivity\<close>
39076
b3a9b6734663 Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents: 39075
diff changeset
   139
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   140
definition inj_on :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a set \<Rightarrow> bool"  \<comment> \<open>injective\<close>
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   141
  where "inj_on f A \<longleftrightarrow> (\<forall>x\<in>A. \<forall>y\<in>A. f x = f y \<longrightarrow> x = y)"
26147
ae2bf929e33c moved some set lemmas to Set.thy
haftmann
parents: 26105
diff changeset
   142
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   143
definition bij_betw :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a set \<Rightarrow> 'b set \<Rightarrow> bool"  \<comment> \<open>bijective\<close>
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   144
  where "bij_betw f A B \<longleftrightarrow> inj_on f A \<and> f ` A = B"
26147
ae2bf929e33c moved some set lemmas to Set.thy
haftmann
parents: 26105
diff changeset
   145
63575
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   146
text \<open>
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   147
  A common special case: functions injective, surjective or bijective over
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   148
  the entire domain type.
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   149
\<close>
26147
ae2bf929e33c moved some set lemmas to Set.thy
haftmann
parents: 26105
diff changeset
   150
65170
53675f36820d restored surj as output abbreviation, amending 6af79184bef3
haftmann
parents: 64966
diff changeset
   151
abbreviation inj :: "('a \<Rightarrow> 'b) \<Rightarrow> bool"
53675f36820d restored surj as output abbreviation, amending 6af79184bef3
haftmann
parents: 64966
diff changeset
   152
  where "inj f \<equiv> inj_on f UNIV"
26147
ae2bf929e33c moved some set lemmas to Set.thy
haftmann
parents: 26105
diff changeset
   153
65170
53675f36820d restored surj as output abbreviation, amending 6af79184bef3
haftmann
parents: 64966
diff changeset
   154
abbreviation surj :: "('a \<Rightarrow> 'b) \<Rightarrow> bool"
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   155
  where "surj f \<equiv> range f = UNIV"
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   156
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 65170
diff changeset
   157
translations \<comment> \<open>The negated case:\<close>
65170
53675f36820d restored surj as output abbreviation, amending 6af79184bef3
haftmann
parents: 64966
diff changeset
   158
  "\<not> CONST surj f" \<leftharpoondown> "CONST range f \<noteq> CONST UNIV"
53675f36820d restored surj as output abbreviation, amending 6af79184bef3
haftmann
parents: 64966
diff changeset
   159
53675f36820d restored surj as output abbreviation, amending 6af79184bef3
haftmann
parents: 64966
diff changeset
   160
abbreviation bij :: "('a \<Rightarrow> 'b) \<Rightarrow> bool"
53675f36820d restored surj as output abbreviation, amending 6af79184bef3
haftmann
parents: 64966
diff changeset
   161
  where "bij f \<equiv> bij_betw f UNIV UNIV"
26147
ae2bf929e33c moved some set lemmas to Set.thy
haftmann
parents: 26105
diff changeset
   162
64966
d53d7ca3303e added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents: 64965
diff changeset
   163
lemma inj_def: "inj f \<longleftrightarrow> (\<forall>x y. f x = f y \<longrightarrow> x = y)"
d53d7ca3303e added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents: 64965
diff changeset
   164
  unfolding inj_on_def by blast
d53d7ca3303e added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents: 64965
diff changeset
   165
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   166
lemma injI: "(\<And>x y. f x = f y \<Longrightarrow> x = y) \<Longrightarrow> inj f"
64966
d53d7ca3303e added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents: 64965
diff changeset
   167
  unfolding inj_def by blast
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   168
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   169
theorem range_ex1_eq: "inj f \<Longrightarrow> b \<in> range f \<longleftrightarrow> (\<exists>!x. b = f x)"
64966
d53d7ca3303e added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents: 64965
diff changeset
   170
  unfolding inj_def by blast
40703
d1fc454d6735 Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents: 40702
diff changeset
   171
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   172
lemma injD: "inj f \<Longrightarrow> f x = f y \<Longrightarrow> x = y"
64966
d53d7ca3303e added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents: 64965
diff changeset
   173
  by (simp add: inj_def)
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   174
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   175
lemma inj_on_eq_iff: "inj_on f A \<Longrightarrow> x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> f x = f y \<longleftrightarrow> x = y"
64966
d53d7ca3303e added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents: 64965
diff changeset
   176
  by (auto simp: inj_on_def)
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   177
64965
d55d743c45a2 tuned proofs;
wenzelm
parents: 63591
diff changeset
   178
lemma inj_on_cong: "(\<And>a. a \<in> A \<Longrightarrow> f a = g a) \<Longrightarrow> inj_on f A \<longleftrightarrow> inj_on g A"
64966
d53d7ca3303e added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents: 64965
diff changeset
   179
  by (auto simp: inj_on_def)
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   180
76281
457f1cba78fb renamed lemma inj_on_strict_subset to image_strict_mono for symmetry with image_mono and to distinguish from inj_on_subset
desharna
parents: 76264
diff changeset
   181
lemma image_strict_mono: "inj_on f B \<Longrightarrow> A \<subset> B \<Longrightarrow> f ` A \<subset> f ` B"
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   182
  unfolding inj_on_def by blast
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   183
69700
7a92cbec7030 new material about summations and powers, along with some tweaks
paulson <lp15@cam.ac.uk>
parents: 69661
diff changeset
   184
lemma inj_compose: "inj f \<Longrightarrow> inj g \<Longrightarrow> inj (f \<circ> g)"
64966
d53d7ca3303e added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents: 64965
diff changeset
   185
  by (simp add: inj_def)
38620
b40524b74f77 inj_comp and inj_fun
haftmann
parents: 37767
diff changeset
   186
b40524b74f77 inj_comp and inj_fun
haftmann
parents: 37767
diff changeset
   187
lemma inj_fun: "inj f \<Longrightarrow> inj (\<lambda>x y. f x)"
64966
d53d7ca3303e added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents: 64965
diff changeset
   188
  by (simp add: inj_def fun_eq_iff)
38620
b40524b74f77 inj_comp and inj_fun
haftmann
parents: 37767
diff changeset
   189
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   190
lemma inj_eq: "inj f \<Longrightarrow> f x = f y \<longleftrightarrow> x = y"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   191
  by (simp add: inj_on_eq_iff)
32988
d1d4d7a08a66 Inv -> inv_onto, inv abbr. inv_onto UNIV.
nipkow
parents: 32961
diff changeset
   192
71827
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71616
diff changeset
   193
lemma inj_on_iff_Uniq: "inj_on f A \<longleftrightarrow> (\<forall>x\<in>A. \<exists>\<^sub>\<le>\<^sub>1y. y\<in>A \<and> f x = f y)"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71616
diff changeset
   194
  by (auto simp: Uniq_def inj_on_def)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71616
diff changeset
   195
26147
ae2bf929e33c moved some set lemmas to Set.thy
haftmann
parents: 26105
diff changeset
   196
lemma inj_on_id[simp]: "inj_on id A"
39076
b3a9b6734663 Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents: 39075
diff changeset
   197
  by (simp add: inj_on_def)
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   198
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   199
lemma inj_on_id2[simp]: "inj_on (\<lambda>x. x) A"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   200
  by (simp add: inj_on_def)
26147
ae2bf929e33c moved some set lemmas to Set.thy
haftmann
parents: 26105
diff changeset
   201
46586
abbec6fa25c8 generalizing inj_on_Int
bulwahn
parents: 46420
diff changeset
   202
lemma inj_on_Int: "inj_on f A \<or> inj_on f B \<Longrightarrow> inj_on f (A \<inter> B)"
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   203
  unfolding inj_on_def by blast
40703
d1fc454d6735 Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents: 40702
diff changeset
   204
40702
cf26dd7395e4 Replace surj by abbreviation; remove surj_on.
hoelzl
parents: 40602
diff changeset
   205
lemma surj_id: "surj id"
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   206
  by simp
26147
ae2bf929e33c moved some set lemmas to Set.thy
haftmann
parents: 26105
diff changeset
   207
39101
606432dd1896 Revert bij_betw changes to simp set (Problem in afp/Ordinals_and_Cardinals)
hoelzl
parents: 39076
diff changeset
   208
lemma bij_id[simp]: "bij id"
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   209
  by (simp add: bij_betw_def)
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   210
76252
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   211
lemma bij_uminus: "bij (uminus :: 'a \<Rightarrow> 'a::group_add)"
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   212
  unfolding bij_betw_def inj_on_def
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   213
  by (force intro: minus_minus [symmetric])
63072
eb5d493a9e03 renamings and refinements
paulson <lp15@cam.ac.uk>
parents: 62843
diff changeset
   214
72125
cf8399df4d76 elimination of some needless assumptions
paulson <lp15@cam.ac.uk>
parents: 71857
diff changeset
   215
lemma bij_betwE: "bij_betw f A B \<Longrightarrow> \<forall>a\<in>A. f a \<in> B"
cf8399df4d76 elimination of some needless assumptions
paulson <lp15@cam.ac.uk>
parents: 71857
diff changeset
   216
  unfolding bij_betw_def by auto
cf8399df4d76 elimination of some needless assumptions
paulson <lp15@cam.ac.uk>
parents: 71857
diff changeset
   217
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   218
lemma inj_onI [intro?]: "(\<And>x y. x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> f x = f y \<Longrightarrow> x = y) \<Longrightarrow> inj_on f A"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   219
  by (simp add: inj_on_def)
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   220
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   221
lemma inj_on_inverseI: "(\<And>x. x \<in> A \<Longrightarrow> g (f x) = x) \<Longrightarrow> inj_on f A"
64965
d55d743c45a2 tuned proofs;
wenzelm
parents: 63591
diff changeset
   222
  by (auto dest: arg_cong [of concl: g] simp add: inj_on_def)
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   223
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   224
lemma inj_onD: "inj_on f A \<Longrightarrow> f x = f y \<Longrightarrow> x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> x = y"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   225
  unfolding inj_on_def by blast
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   226
63365
5340fb6633d0 more theorems
haftmann
parents: 63324
diff changeset
   227
lemma inj_on_subset:
5340fb6633d0 more theorems
haftmann
parents: 63324
diff changeset
   228
  assumes "inj_on f A"
63575
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   229
    and "B \<subseteq> A"
63365
5340fb6633d0 more theorems
haftmann
parents: 63324
diff changeset
   230
  shows "inj_on f B"
5340fb6633d0 more theorems
haftmann
parents: 63324
diff changeset
   231
proof (rule inj_onI)
5340fb6633d0 more theorems
haftmann
parents: 63324
diff changeset
   232
  fix a b
5340fb6633d0 more theorems
haftmann
parents: 63324
diff changeset
   233
  assume "a \<in> B" and "b \<in> B"
5340fb6633d0 more theorems
haftmann
parents: 63324
diff changeset
   234
  with assms have "a \<in> A" and "b \<in> A"
5340fb6633d0 more theorems
haftmann
parents: 63324
diff changeset
   235
    by auto
5340fb6633d0 more theorems
haftmann
parents: 63324
diff changeset
   236
  moreover assume "f a = f b"
64965
d55d743c45a2 tuned proofs;
wenzelm
parents: 63591
diff changeset
   237
  ultimately show "a = b"
d55d743c45a2 tuned proofs;
wenzelm
parents: 63591
diff changeset
   238
    using assms by (auto dest: inj_onD)
63365
5340fb6633d0 more theorems
haftmann
parents: 63324
diff changeset
   239
qed
5340fb6633d0 more theorems
haftmann
parents: 63324
diff changeset
   240
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   241
lemma comp_inj_on: "inj_on f A \<Longrightarrow> inj_on g (f ` A) \<Longrightarrow> inj_on (g \<circ> f) A"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   242
  by (simp add: comp_def inj_on_def)
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   243
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   244
lemma inj_on_imageI: "inj_on (g \<circ> f) A \<Longrightarrow> inj_on g (f ` A)"
63072
eb5d493a9e03 renamings and refinements
paulson <lp15@cam.ac.uk>
parents: 62843
diff changeset
   245
  by (auto simp add: inj_on_def)
15303
eedbb8d22ca2 added lemmas
nipkow
parents: 15140
diff changeset
   246
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   247
lemma inj_on_image_iff:
64965
d55d743c45a2 tuned proofs;
wenzelm
parents: 63591
diff changeset
   248
  "\<forall>x\<in>A. \<forall>y\<in>A. g (f x) = g (f y) \<longleftrightarrow> g x = g y \<Longrightarrow> inj_on f A \<Longrightarrow> inj_on g (f ` A) \<longleftrightarrow> inj_on g A"
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   249
  unfolding inj_on_def by blast
15439
71c0f98e31f1 made diff_less a simp rule
nipkow
parents: 15303
diff changeset
   250
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   251
lemma inj_on_contraD: "inj_on f A \<Longrightarrow> x \<noteq> y \<Longrightarrow> x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> f x \<noteq> f y"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   252
  unfolding inj_on_def by blast
12258
5da24e7e9aba got rid of theory Inverse_Image;
wenzelm
parents: 12114
diff changeset
   253
63072
eb5d493a9e03 renamings and refinements
paulson <lp15@cam.ac.uk>
parents: 62843
diff changeset
   254
lemma inj_singleton [simp]: "inj_on (\<lambda>x. {x}) A"
eb5d493a9e03 renamings and refinements
paulson <lp15@cam.ac.uk>
parents: 62843
diff changeset
   255
  by (simp add: inj_on_def)
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   256
15111
c108189645f8 added some inj_on thms
nipkow
parents: 14565
diff changeset
   257
lemma inj_on_empty[iff]: "inj_on f {}"
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   258
  by (simp add: inj_on_def)
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   259
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   260
lemma subset_inj_on: "inj_on f B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> inj_on f A"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   261
  unfolding inj_on_def by blast
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   262
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   263
lemma inj_on_Un: "inj_on f (A \<union> B) \<longleftrightarrow> inj_on f A \<and> inj_on f B \<and> f ` (A - B) \<inter> f ` (B - A) = {}"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   264
  unfolding inj_on_def by (blast intro: sym)
15111
c108189645f8 added some inj_on thms
nipkow
parents: 14565
diff changeset
   265
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   266
lemma inj_on_insert [iff]: "inj_on f (insert a A) \<longleftrightarrow> inj_on f A \<and> f a \<notin> f ` (A - {a})"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   267
  unfolding inj_on_def by (blast intro: sym)
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   268
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   269
lemma inj_on_diff: "inj_on f A \<Longrightarrow> inj_on f (A - B)"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   270
  unfolding inj_on_def by blast
15111
c108189645f8 added some inj_on thms
nipkow
parents: 14565
diff changeset
   271
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   272
lemma comp_inj_on_iff: "inj_on f A \<Longrightarrow> inj_on f' (f ` A) \<longleftrightarrow> inj_on (f' \<circ> f) A"
64965
d55d743c45a2 tuned proofs;
wenzelm
parents: 63591
diff changeset
   273
  by (auto simp: comp_inj_on inj_on_def)
15111
c108189645f8 added some inj_on thms
nipkow
parents: 14565
diff changeset
   274
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   275
lemma inj_on_imageI2: "inj_on (f' \<circ> f) A \<Longrightarrow> inj_on f A"
64965
d55d743c45a2 tuned proofs;
wenzelm
parents: 63591
diff changeset
   276
  by (auto simp: comp_inj_on inj_on_def)
40703
d1fc454d6735 Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents: 40702
diff changeset
   277
51598
5dbe537087aa generalized lemma fold_image thanks to Peter Lammich
haftmann
parents: 49905
diff changeset
   278
lemma inj_img_insertE:
5dbe537087aa generalized lemma fold_image thanks to Peter Lammich
haftmann
parents: 49905
diff changeset
   279
  assumes "inj_on f A"
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   280
  assumes "x \<notin> B"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   281
    and "insert x B = f ` A"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   282
  obtains x' A' where "x' \<notin> A'" and "A = insert x' A'" and "x = f x'" and "B = f ` A'"
51598
5dbe537087aa generalized lemma fold_image thanks to Peter Lammich
haftmann
parents: 49905
diff changeset
   283
proof -
5dbe537087aa generalized lemma fold_image thanks to Peter Lammich
haftmann
parents: 49905
diff changeset
   284
  from assms have "x \<in> f ` A" by auto
5dbe537087aa generalized lemma fold_image thanks to Peter Lammich
haftmann
parents: 49905
diff changeset
   285
  then obtain x' where *: "x' \<in> A" "x = f x'" by auto
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   286
  then have A: "A = insert x' (A - {x'})" by auto
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   287
  with assms * have B: "B = f ` (A - {x'})" by (auto dest: inj_on_contraD)
51598
5dbe537087aa generalized lemma fold_image thanks to Peter Lammich
haftmann
parents: 49905
diff changeset
   288
  have "x' \<notin> A - {x'}" by simp
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   289
  from this A \<open>x = f x'\<close> B show ?thesis ..
51598
5dbe537087aa generalized lemma fold_image thanks to Peter Lammich
haftmann
parents: 49905
diff changeset
   290
qed
5dbe537087aa generalized lemma fold_image thanks to Peter Lammich
haftmann
parents: 49905
diff changeset
   291
71404
f2b783abfbe7 A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents: 69913
diff changeset
   292
lemma linorder_inj_onI:
f2b783abfbe7 A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents: 69913
diff changeset
   293
  fixes A :: "'a::order set"
f2b783abfbe7 A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents: 69913
diff changeset
   294
  assumes ne: "\<And>x y. \<lbrakk>x < y; x\<in>A; y\<in>A\<rbrakk> \<Longrightarrow> f x \<noteq> f y" and lin: "\<And>x y. \<lbrakk>x\<in>A; y\<in>A\<rbrakk> \<Longrightarrow> x\<le>y \<or> y\<le>x"
f2b783abfbe7 A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents: 69913
diff changeset
   295
  shows "inj_on f A"
f2b783abfbe7 A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents: 69913
diff changeset
   296
proof (rule inj_onI)
f2b783abfbe7 A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents: 69913
diff changeset
   297
  fix x y
f2b783abfbe7 A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents: 69913
diff changeset
   298
  assume eq: "f x = f y" and "x\<in>A" "y\<in>A"
f2b783abfbe7 A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents: 69913
diff changeset
   299
  then show "x = y"
f2b783abfbe7 A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents: 69913
diff changeset
   300
    using lin [of x y] ne by (force simp: dual_order.order_iff_strict)
f2b783abfbe7 A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents: 69913
diff changeset
   301
qed
f2b783abfbe7 A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents: 69913
diff changeset
   302
76722
b1d57dd345e1 First round of moving material from the number theory development
paulson <lp15@cam.ac.uk>
parents: 76281
diff changeset
   303
lemma linorder_inj_onI':
b1d57dd345e1 First round of moving material from the number theory development
paulson <lp15@cam.ac.uk>
parents: 76281
diff changeset
   304
  fixes A :: "'a :: linorder set"
b1d57dd345e1 First round of moving material from the number theory development
paulson <lp15@cam.ac.uk>
parents: 76281
diff changeset
   305
  assumes "\<And>i j. i \<in> A \<Longrightarrow> j \<in> A \<Longrightarrow> i < j \<Longrightarrow> f i \<noteq> f j"
b1d57dd345e1 First round of moving material from the number theory development
paulson <lp15@cam.ac.uk>
parents: 76281
diff changeset
   306
  shows   "inj_on f A"
b1d57dd345e1 First round of moving material from the number theory development
paulson <lp15@cam.ac.uk>
parents: 76281
diff changeset
   307
  by (intro linorder_inj_onI) (auto simp add: assms)
b1d57dd345e1 First round of moving material from the number theory development
paulson <lp15@cam.ac.uk>
parents: 76281
diff changeset
   308
54578
9387251b6a46 eliminated dependence of BNF on Infinite_Set by moving 3 theorems from the latter to Main
traytel
parents: 54147
diff changeset
   309
lemma linorder_injI:
64965
d55d743c45a2 tuned proofs;
wenzelm
parents: 63591
diff changeset
   310
  assumes "\<And>x y::'a::linorder. x < y \<Longrightarrow> f x \<noteq> f y"
54578
9387251b6a46 eliminated dependence of BNF on Infinite_Set by moving 3 theorems from the latter to Main
traytel
parents: 54147
diff changeset
   311
  shows "inj f"
71404
f2b783abfbe7 A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents: 69913
diff changeset
   312
    \<comment> \<open>Courtesy of Stephan Merz\<close>
76722
b1d57dd345e1 First round of moving material from the number theory development
paulson <lp15@cam.ac.uk>
parents: 76281
diff changeset
   313
using assms by (simp add: linorder_inj_onI')
69735
8230dca028eb the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents: 69700
diff changeset
   314
8230dca028eb the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents: 69700
diff changeset
   315
lemma inj_on_image_Pow: "inj_on f A \<Longrightarrow>inj_on (image f) (Pow A)"
8230dca028eb the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents: 69700
diff changeset
   316
  unfolding Pow_def inj_on_def by blast
8230dca028eb the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents: 69700
diff changeset
   317
8230dca028eb the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents: 69700
diff changeset
   318
lemma bij_betw_image_Pow: "bij_betw f A B \<Longrightarrow> bij_betw (image f) (Pow A) (Pow B)"
8230dca028eb the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents: 69700
diff changeset
   319
  by (auto simp add: bij_betw_def inj_on_image_Pow image_Pow_surj)
8230dca028eb the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents: 69700
diff changeset
   320
40702
cf26dd7395e4 Replace surj by abbreviation; remove surj_on.
hoelzl
parents: 40602
diff changeset
   321
lemma surj_def: "surj f \<longleftrightarrow> (\<forall>y. \<exists>x. y = f x)"
cf26dd7395e4 Replace surj by abbreviation; remove surj_on.
hoelzl
parents: 40602
diff changeset
   322
  by auto
39076
b3a9b6734663 Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents: 39075
diff changeset
   323
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   324
lemma surjI:
64965
d55d743c45a2 tuned proofs;
wenzelm
parents: 63591
diff changeset
   325
  assumes "\<And>x. g (f x) = x"
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   326
  shows "surj g"
64965
d55d743c45a2 tuned proofs;
wenzelm
parents: 63591
diff changeset
   327
  using assms [symmetric] by auto
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   328
39076
b3a9b6734663 Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents: 39075
diff changeset
   329
lemma surjD: "surj f \<Longrightarrow> \<exists>x. y = f x"
b3a9b6734663 Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents: 39075
diff changeset
   330
  by (simp add: surj_def)
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   331
39076
b3a9b6734663 Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents: 39075
diff changeset
   332
lemma surjE: "surj f \<Longrightarrow> (\<And>x. y = f x \<Longrightarrow> C) \<Longrightarrow> C"
63575
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   333
  by (simp add: surj_def) blast
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   334
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   335
lemma comp_surj: "surj f \<Longrightarrow> surj g \<Longrightarrow> surj (g \<circ> f)"
69768
7e4966eaf781 proper congruence rule for image operator
haftmann
parents: 69735
diff changeset
   336
  using image_comp [of g f UNIV] by simp
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   337
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   338
lemma bij_betw_imageI: "inj_on f A \<Longrightarrow> f ` A = B \<Longrightarrow> bij_betw f A B"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   339
  unfolding bij_betw_def by clarify
57282
7da3e398804c Two basic lemmas on bij_betw.
ballarin
parents: 56608
diff changeset
   340
7da3e398804c Two basic lemmas on bij_betw.
ballarin
parents: 56608
diff changeset
   341
lemma bij_betw_imp_surj_on: "bij_betw f A B \<Longrightarrow> f ` A = B"
7da3e398804c Two basic lemmas on bij_betw.
ballarin
parents: 56608
diff changeset
   342
  unfolding bij_betw_def by clarify
7da3e398804c Two basic lemmas on bij_betw.
ballarin
parents: 56608
diff changeset
   343
39074
211e4f6aad63 bij <--> bij_betw
hoelzl
parents: 38620
diff changeset
   344
lemma bij_betw_imp_surj: "bij_betw f A UNIV \<Longrightarrow> surj f"
40702
cf26dd7395e4 Replace surj by abbreviation; remove surj_on.
hoelzl
parents: 40602
diff changeset
   345
  unfolding bij_betw_def by auto
39074
211e4f6aad63 bij <--> bij_betw
hoelzl
parents: 38620
diff changeset
   346
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   347
lemma bij_betw_empty1: "bij_betw f {} A \<Longrightarrow> A = {}"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   348
  unfolding bij_betw_def by blast
40703
d1fc454d6735 Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents: 40702
diff changeset
   349
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   350
lemma bij_betw_empty2: "bij_betw f A {} \<Longrightarrow> A = {}"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   351
  unfolding bij_betw_def by blast
40703
d1fc454d6735 Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents: 40702
diff changeset
   352
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   353
lemma inj_on_imp_bij_betw: "inj_on f A \<Longrightarrow> bij_betw f A (f ` A)"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   354
  unfolding bij_betw_def by simp
40703
d1fc454d6735 Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents: 40702
diff changeset
   355
71464
4a04b6bd628b a few new lemmas
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   356
lemma bij_betw_apply: "\<lbrakk>bij_betw f A B; a \<in> A\<rbrakk> \<Longrightarrow> f a \<in> B"
4a04b6bd628b a few new lemmas
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   357
  unfolding bij_betw_def by auto
4a04b6bd628b a few new lemmas
paulson <lp15@cam.ac.uk>
parents: 71404
diff changeset
   358
39076
b3a9b6734663 Introduce surj_on and replace surj and bij by abbreviations.
hoelzl
parents: 39075
diff changeset
   359
lemma bij_def: "bij f \<longleftrightarrow> inj f \<and> surj f"
64965
d55d743c45a2 tuned proofs;
wenzelm
parents: 63591
diff changeset
   360
  by (rule bij_betw_def)
39074
211e4f6aad63 bij <--> bij_betw
hoelzl
parents: 38620
diff changeset
   361
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   362
lemma bijI: "inj f \<Longrightarrow> surj f \<Longrightarrow> bij f"
64965
d55d743c45a2 tuned proofs;
wenzelm
parents: 63591
diff changeset
   363
  by (rule bij_betw_imageI)
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   364
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   365
lemma bij_is_inj: "bij f \<Longrightarrow> inj f"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   366
  by (simp add: bij_def)
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   367
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   368
lemma bij_is_surj: "bij f \<Longrightarrow> surj f"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   369
  by (simp add: bij_def)
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   370
26105
ae06618225ec moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents: 25886
diff changeset
   371
lemma bij_betw_imp_inj_on: "bij_betw f A B \<Longrightarrow> inj_on f A"
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   372
  by (simp add: bij_betw_def)
26105
ae06618225ec moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents: 25886
diff changeset
   373
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   374
lemma bij_betw_trans: "bij_betw f A B \<Longrightarrow> bij_betw g B C \<Longrightarrow> bij_betw (g \<circ> f) A C"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   375
  by (auto simp add:bij_betw_def comp_inj_on)
31438
a1c4c1500abe A few finite lemmas
nipkow
parents: 31202
diff changeset
   376
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   377
lemma bij_comp: "bij f \<Longrightarrow> bij g \<Longrightarrow> bij (g \<circ> f)"
40702
cf26dd7395e4 Replace surj by abbreviation; remove surj_on.
hoelzl
parents: 40602
diff changeset
   378
  by (rule bij_betw_trans)
cf26dd7395e4 Replace surj by abbreviation; remove surj_on.
hoelzl
parents: 40602
diff changeset
   379
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   380
lemma bij_betw_comp_iff: "bij_betw f A A' \<Longrightarrow> bij_betw f' A' A'' \<longleftrightarrow> bij_betw (f' \<circ> f) A A''"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   381
  by (auto simp add: bij_betw_def inj_on_def)
40703
d1fc454d6735 Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents: 40702
diff changeset
   382
d1fc454d6735 Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents: 40702
diff changeset
   383
lemma bij_betw_comp_iff2:
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   384
  assumes bij: "bij_betw f' A' A''"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   385
    and img: "f ` A \<le> A'"
75669
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   386
  shows "bij_betw f A A' \<longleftrightarrow> bij_betw (f' \<circ> f) A A''" (is "?L \<longleftrightarrow> ?R")
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   387
proof
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   388
  assume "?L"
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   389
  then show "?R"
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   390
    using assms by (auto simp add: bij_betw_comp_iff)
40703
d1fc454d6735 Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents: 40702
diff changeset
   391
  next
75669
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   392
    assume *: "?R"
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   393
    have "inj_on (f' \<circ> f) A \<Longrightarrow> inj_on f A"
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   394
      using inj_on_imageI2 by blast
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   395
    moreover have "A' \<subseteq> f ` A"
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   396
    proof
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   397
      fix a'
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   398
      assume **: "a' \<in> A'"
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   399
      with bij have "f' a' \<in> A''"
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   400
        unfolding bij_betw_def by auto
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   401
      with * obtain a where 1: "a \<in> A \<and> f' (f a) = f' a'"
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   402
        unfolding bij_betw_def by force
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   403
      with img have "f a \<in> A'" by auto
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   404
      with bij ** 1 have "f a = a'"
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   405
        unfolding bij_betw_def inj_on_def by auto
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   406
      with 1 show "a' \<in> f ` A" by auto
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   407
    qed
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   408
    ultimately show "?L"
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   409
      using img * by (auto simp add: bij_betw_def)
40703
d1fc454d6735 Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents: 40702
diff changeset
   410
qed
d1fc454d6735 Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents: 40702
diff changeset
   411
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   412
lemma bij_betw_inv:
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   413
  assumes "bij_betw f A B"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   414
  shows "\<exists>g. bij_betw g B A"
26105
ae06618225ec moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents: 25886
diff changeset
   415
proof -
ae06618225ec moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents: 25886
diff changeset
   416
  have i: "inj_on f A" and s: "f ` A = B"
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   417
    using assms by (auto simp: bij_betw_def)
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   418
  let ?P = "\<lambda>b a. a \<in> A \<and> f a = b"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   419
  let ?g = "\<lambda>b. The (?P b)"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   420
  have g: "?g b = a" if P: "?P b a" for a b
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   421
  proof -
63575
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   422
    from that s have ex1: "\<exists>a. ?P b a" by blast
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   423
    then have uex1: "\<exists>!a. ?P b a" by (blast dest:inj_onD[OF i])
63575
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   424
    then show ?thesis
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   425
      using the1_equality[OF uex1, OF P] P by simp
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   426
  qed
26105
ae06618225ec moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents: 25886
diff changeset
   427
  have "inj_on ?g B"
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   428
  proof (rule inj_onI)
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   429
    fix x y
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   430
    assume "x \<in> B" "y \<in> B" "?g x = ?g y"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   431
    from s \<open>x \<in> B\<close> obtain a1 where a1: "?P x a1" by blast
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   432
    from s \<open>y \<in> B\<close> obtain a2 where a2: "?P y a2" by blast
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   433
    from g [OF a1] a1 g [OF a2] a2 \<open>?g x = ?g y\<close> show "x = y" by simp
26105
ae06618225ec moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents: 25886
diff changeset
   434
  qed
ae06618225ec moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents: 25886
diff changeset
   435
  moreover have "?g ` B = A"
75669
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   436
  proof safe
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   437
    fix b
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   438
    assume "b \<in> B"
56077
d397030fb27e tuned proofs
haftmann
parents: 56015
diff changeset
   439
    with s obtain a where P: "?P b a" by blast
63575
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   440
    with g[OF P] show "?g b \<in> A" by auto
26105
ae06618225ec moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents: 25886
diff changeset
   441
  next
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   442
    fix a
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   443
    assume "a \<in> A"
63575
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   444
    with s obtain b where P: "?P b a" by blast
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   445
    with s have "b \<in> B" by blast
75669
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   446
    with g[OF P] have "\<exists>b\<in>B. a = ?g b" by blast
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   447
    then show "a \<in> ?g ` B"
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   448
      by auto
26105
ae06618225ec moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents: 25886
diff changeset
   449
  qed
63575
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   450
  ultimately show ?thesis
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   451
    by (auto simp: bij_betw_def)
26105
ae06618225ec moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents: 25886
diff changeset
   452
qed
ae06618225ec moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
nipkow
parents: 25886
diff changeset
   453
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63575
diff changeset
   454
lemma bij_betw_cong: "(\<And>a. a \<in> A \<Longrightarrow> f a = g a) \<Longrightarrow> bij_betw f A A' = bij_betw g A A'"
63591
8d20875f1290 tuned proof;
wenzelm
parents: 63588
diff changeset
   455
  unfolding bij_betw_def inj_on_def by safe force+  (* somewhat slow *)
40703
d1fc454d6735 Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents: 40702
diff changeset
   456
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   457
lemma bij_betw_id[intro, simp]: "bij_betw id A A"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   458
  unfolding bij_betw_def id_def by auto
40703
d1fc454d6735 Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents: 40702
diff changeset
   459
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   460
lemma bij_betw_id_iff: "bij_betw id A B \<longleftrightarrow> A = B"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   461
  by (auto simp add: bij_betw_def)
40703
d1fc454d6735 Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents: 40702
diff changeset
   462
39075
a18e5946d63c Permutation implies bij function
hoelzl
parents: 39074
diff changeset
   463
lemma bij_betw_combine:
63400
249fa34faba2 misc tuning and modernization;
wenzelm
parents: 63365
diff changeset
   464
  "bij_betw f A B \<Longrightarrow> bij_betw f C D \<Longrightarrow> B \<inter> D = {} \<Longrightarrow> bij_betw f (A \<union> C) (B \<union> D)"
249fa34faba2 misc tuning and modernization;
wenzelm
parents: 63365
diff changeset
   465
  unfolding bij_betw_def inj_on_Un image_Un by auto
39075
a18e5946d63c Permutation implies bij function
hoelzl
parents: 39074
diff changeset
   466
64966
d53d7ca3303e added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents: 64965
diff changeset
   467
lemma bij_betw_subset: "bij_betw f A A' \<Longrightarrow> B \<subseteq> A \<Longrightarrow> f ` B = B' \<Longrightarrow> bij_betw f B B'"
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   468
  by (auto simp add: bij_betw_def inj_on_def)
40703
d1fc454d6735 Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents: 40702
diff changeset
   469
75624
22d1c5f2b9f4 strict bounds for BNFs (by Jan van Brügge)
traytel
parents: 75609
diff changeset
   470
lemma bij_betw_ball: "bij_betw f A B \<Longrightarrow> (\<forall>b \<in> B. phi b) = (\<forall>a \<in> A. phi (f a))"
22d1c5f2b9f4 strict bounds for BNFs (by Jan van Brügge)
traytel
parents: 75609
diff changeset
   471
  unfolding bij_betw_def inj_on_def by blast
22d1c5f2b9f4 strict bounds for BNFs (by Jan van Brügge)
traytel
parents: 75609
diff changeset
   472
58195
1fee63e0377d added various facts
haftmann
parents: 58111
diff changeset
   473
lemma bij_pointE:
1fee63e0377d added various facts
haftmann
parents: 58111
diff changeset
   474
  assumes "bij f"
1fee63e0377d added various facts
haftmann
parents: 58111
diff changeset
   475
  obtains x where "y = f x" and "\<And>x'. y = f x' \<Longrightarrow> x' = x"
1fee63e0377d added various facts
haftmann
parents: 58111
diff changeset
   476
proof -
1fee63e0377d added various facts
haftmann
parents: 58111
diff changeset
   477
  from assms have "inj f" by (rule bij_is_inj)
1fee63e0377d added various facts
haftmann
parents: 58111
diff changeset
   478
  moreover from assms have "surj f" by (rule bij_is_surj)
1fee63e0377d added various facts
haftmann
parents: 58111
diff changeset
   479
  then have "y \<in> range f" by simp
1fee63e0377d added various facts
haftmann
parents: 58111
diff changeset
   480
  ultimately have "\<exists>!x. y = f x" by (simp add: range_ex1_eq)
1fee63e0377d added various facts
haftmann
parents: 58111
diff changeset
   481
  with that show thesis by blast
1fee63e0377d added various facts
haftmann
parents: 58111
diff changeset
   482
qed
1fee63e0377d added various facts
haftmann
parents: 58111
diff changeset
   483
73326
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   484
lemma bij_iff: \<^marker>\<open>contributor \<open>Amine Chaieb\<close>\<close>
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   485
  \<open>bij f \<longleftrightarrow> (\<forall>x. \<exists>!y. f y = x)\<close>  (is \<open>?P \<longleftrightarrow> ?Q\<close>)
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   486
proof
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   487
  assume ?P
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   488
  then have \<open>inj f\<close> \<open>surj f\<close>
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   489
    by (simp_all add: bij_def)
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   490
  show ?Q
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   491
  proof
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   492
    fix y
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   493
    from \<open>surj f\<close> obtain x where \<open>y = f x\<close>
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   494
      by (auto simp add: surj_def)
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   495
    with \<open>inj f\<close> show \<open>\<exists>!x. f x = y\<close>
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   496
      by (auto simp add: inj_def)
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   497
  qed
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   498
next
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   499
  assume ?Q
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   500
  then have \<open>inj f\<close>
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   501
    by (auto simp add: inj_def)
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   502
  moreover have \<open>\<exists>x. y = f x\<close> for y
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   503
  proof -
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   504
    from \<open>?Q\<close> obtain x where \<open>f x = y\<close>
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   505
      by blast
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   506
    then have \<open>y = f x\<close>
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   507
      by simp
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   508
    then show ?thesis ..
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   509
  qed
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   510
  then have \<open>surj f\<close>
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   511
    by (auto simp add: surj_def)
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   512
  ultimately show ?P
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   513
    by (rule bijI)
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   514
qed
7a88313895d5 dissolve theory with duplicated name from afp
haftmann
parents: 72125
diff changeset
   515
73466
ee1c4962671c more lemmas
haftmann
parents: 73328
diff changeset
   516
lemma bij_betw_partition:
ee1c4962671c more lemmas
haftmann
parents: 73328
diff changeset
   517
  \<open>bij_betw f A B\<close>
ee1c4962671c more lemmas
haftmann
parents: 73328
diff changeset
   518
  if \<open>bij_betw f (A \<union> C) (B \<union> D)\<close> \<open>bij_betw f C D\<close> \<open>A \<inter> C = {}\<close> \<open>B \<inter> D = {}\<close>
ee1c4962671c more lemmas
haftmann
parents: 73328
diff changeset
   519
proof -
ee1c4962671c more lemmas
haftmann
parents: 73328
diff changeset
   520
  from that have \<open>inj_on f (A \<union> C)\<close> \<open>inj_on f C\<close> \<open>f ` (A \<union> C) = B \<union> D\<close> \<open>f ` C = D\<close>
ee1c4962671c more lemmas
haftmann
parents: 73328
diff changeset
   521
    by (simp_all add: bij_betw_def)
ee1c4962671c more lemmas
haftmann
parents: 73328
diff changeset
   522
  then have \<open>inj_on f A\<close> and \<open>f ` (A - C) \<inter> f ` (C - A) = {}\<close>
ee1c4962671c more lemmas
haftmann
parents: 73328
diff changeset
   523
    by (simp_all add: inj_on_Un)
ee1c4962671c more lemmas
haftmann
parents: 73328
diff changeset
   524
  with \<open>A \<inter> C = {}\<close> have \<open>f ` A \<inter> f ` C = {}\<close>
ee1c4962671c more lemmas
haftmann
parents: 73328
diff changeset
   525
    by auto
ee1c4962671c more lemmas
haftmann
parents: 73328
diff changeset
   526
  with \<open>f ` (A \<union> C) = B \<union> D\<close> \<open>f ` C = D\<close>  \<open>B \<inter> D = {}\<close>
ee1c4962671c more lemmas
haftmann
parents: 73328
diff changeset
   527
  have \<open>f ` A = B\<close>
ee1c4962671c more lemmas
haftmann
parents: 73328
diff changeset
   528
    by blast
ee1c4962671c more lemmas
haftmann
parents: 73328
diff changeset
   529
  with \<open>inj_on f A\<close> show ?thesis
ee1c4962671c more lemmas
haftmann
parents: 73328
diff changeset
   530
    by (simp add: bij_betw_def)
ee1c4962671c more lemmas
haftmann
parents: 73328
diff changeset
   531
qed
ee1c4962671c more lemmas
haftmann
parents: 73328
diff changeset
   532
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   533
lemma surj_image_vimage_eq: "surj f \<Longrightarrow> f ` (f -` A) = A"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   534
  by simp
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   535
42903
ec9eb1fbfcb8 add surj_vimage_empty
hoelzl
parents: 42238
diff changeset
   536
lemma surj_vimage_empty:
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   537
  assumes "surj f"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   538
  shows "f -` A = {} \<longleftrightarrow> A = {}"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   539
  using surj_image_vimage_eq [OF \<open>surj f\<close>, of A]
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44860
diff changeset
   540
  by (intro iffI) fastforce+
42903
ec9eb1fbfcb8 add surj_vimage_empty
hoelzl
parents: 42238
diff changeset
   541
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   542
lemma inj_vimage_image_eq: "inj f \<Longrightarrow> f -` (f ` A) = A"
64966
d53d7ca3303e added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents: 64965
diff changeset
   543
  unfolding inj_def by blast
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   544
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   545
lemma vimage_subsetD: "surj f \<Longrightarrow> f -` B \<subseteq> A \<Longrightarrow> B \<subseteq> f ` A"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   546
  by (blast intro: sym)
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   547
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   548
lemma vimage_subsetI: "inj f \<Longrightarrow> B \<subseteq> f ` A \<Longrightarrow> f -` B \<subseteq> A"
64966
d53d7ca3303e added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents: 64965
diff changeset
   549
  unfolding inj_def by blast
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   550
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   551
lemma vimage_subset_eq: "bij f \<Longrightarrow> f -` B \<subseteq> A \<longleftrightarrow> B \<subseteq> f ` A"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   552
  unfolding bij_def by (blast del: subsetI intro: vimage_subsetI vimage_subsetD)
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   553
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   554
lemma inj_on_image_eq_iff: "inj_on f C \<Longrightarrow> A \<subseteq> C \<Longrightarrow> B \<subseteq> C \<Longrightarrow> f ` A = f ` B \<longleftrightarrow> A = B"
64965
d55d743c45a2 tuned proofs;
wenzelm
parents: 63591
diff changeset
   555
  by (fastforce simp: inj_on_def)
53927
abe2b313f0e5 add lemmas
Andreas Lochbihler
parents: 52435
diff changeset
   556
31438
a1c4c1500abe A few finite lemmas
nipkow
parents: 31202
diff changeset
   557
lemma inj_on_Un_image_eq_iff: "inj_on f (A \<union> B) \<Longrightarrow> f ` A = f ` B \<longleftrightarrow> A = B"
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   558
  by (erule inj_on_image_eq_iff) simp_all
31438
a1c4c1500abe A few finite lemmas
nipkow
parents: 31202
diff changeset
   559
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   560
lemma inj_on_image_Int: "inj_on f C \<Longrightarrow> A \<subseteq> C \<Longrightarrow> B \<subseteq> C \<Longrightarrow> f ` (A \<inter> B) = f ` A \<inter> f ` B"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   561
  unfolding inj_on_def by blast
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   562
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   563
lemma inj_on_image_set_diff: "inj_on f C \<Longrightarrow> A - B \<subseteq> C \<Longrightarrow> B \<subseteq> C \<Longrightarrow> f ` (A - B) = f ` A - f ` B"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   564
  unfolding inj_on_def by blast
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   565
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   566
lemma image_Int: "inj f \<Longrightarrow> f ` (A \<inter> B) = f ` A \<inter> f ` B"
64966
d53d7ca3303e added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents: 64965
diff changeset
   567
  unfolding inj_def by blast
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   568
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   569
lemma image_set_diff: "inj f \<Longrightarrow> f ` (A - B) = f ` A - f ` B"
64966
d53d7ca3303e added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents: 64965
diff changeset
   570
  unfolding inj_def by blast
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   571
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   572
lemma inj_on_image_mem_iff: "inj_on f B \<Longrightarrow> a \<in> B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> f a \<in> f ` A \<longleftrightarrow> a \<in> A"
59504
8c6747dba731 New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   573
  by (auto simp: inj_on_def)
8c6747dba731 New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   574
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   575
lemma inj_image_mem_iff: "inj f \<Longrightarrow> f a \<in> f ` A \<longleftrightarrow> a \<in> A"
59504
8c6747dba731 New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   576
  by (blast dest: injD)
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   577
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   578
lemma inj_image_subset_iff: "inj f \<Longrightarrow> f ` A \<subseteq> f ` B \<longleftrightarrow> A \<subseteq> B"
59504
8c6747dba731 New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   579
  by (blast dest: injD)
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   580
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   581
lemma inj_image_eq_iff: "inj f \<Longrightarrow> f ` A = f ` B \<longleftrightarrow> A = B"
59504
8c6747dba731 New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   582
  by (blast dest: injD)
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   583
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   584
lemma surj_Compl_image_subset: "surj f \<Longrightarrow> - (f ` A) \<subseteq> f ` (- A)"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   585
  by auto
5852
4d7320490be4 the function space operator
paulson
parents: 5608
diff changeset
   586
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   587
lemma inj_image_Compl_subset: "inj f \<Longrightarrow> f ` (- A) \<subseteq> - (f ` A)"
64966
d53d7ca3303e added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents: 64965
diff changeset
   588
  by (auto simp: inj_def)
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   589
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   590
lemma bij_image_Compl_eq: "bij f \<Longrightarrow> f ` (- A) = - (f ` A)"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   591
  by (simp add: bij_def inj_image_Compl_subset surj_Compl_image_subset equalityI)
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   592
41657
89451110ba8e moved theorem
haftmann
parents: 41505
diff changeset
   593
lemma inj_vimage_singleton: "inj f \<Longrightarrow> f -` {a} \<subseteq> {THE x. f x = a}"
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   594
  \<comment> \<open>The inverse image of a singleton under an injective function is included in a singleton.\<close>
64966
d53d7ca3303e added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents: 64965
diff changeset
   595
  by (simp add: inj_def) (blast intro: the_equality [symmetric])
41657
89451110ba8e moved theorem
haftmann
parents: 41505
diff changeset
   596
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   597
lemma inj_on_vimage_singleton: "inj_on f A \<Longrightarrow> f -` {a} \<inter> A \<subseteq> {THE x. x \<in> A \<and> f x = a}"
43991
f4a7697011c5 finite vimage on arbitrary domains
hoelzl
parents: 43874
diff changeset
   598
  by (auto simp add: inj_on_def intro: the_equality [symmetric])
f4a7697011c5 finite vimage on arbitrary domains
hoelzl
parents: 43874
diff changeset
   599
55019
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
   600
lemma bij_betw_byWitness:
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   601
  assumes left: "\<forall>a \<in> A. f' (f a) = a"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   602
    and right: "\<forall>a' \<in> A'. f (f' a') = a'"
63575
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   603
    and "f ` A \<subseteq> A'"
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   604
    and img2: "f' ` A' \<subseteq> A"
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   605
  shows "bij_betw f A A'"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   606
  using assms
63400
249fa34faba2 misc tuning and modernization;
wenzelm
parents: 63365
diff changeset
   607
  unfolding bij_betw_def inj_on_def
249fa34faba2 misc tuning and modernization;
wenzelm
parents: 63365
diff changeset
   608
proof safe
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   609
  fix a b
63575
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   610
  assume "a \<in> A" "b \<in> A"
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   611
  with left have "a = f' (f a) \<and> b = f' (f b)" by simp
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   612
  moreover assume "f a = f b"
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   613
  ultimately show "a = b" by simp
55019
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
   614
next
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
   615
  fix a' assume *: "a' \<in> A'"
63575
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   616
  with img2 have "f' a' \<in> A" by blast
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   617
  moreover from * right have "a' = f (f' a')" by simp
55019
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
   618
  ultimately show "a' \<in> f ` A" by blast
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
   619
qed
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
   620
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
   621
corollary notIn_Un_bij_betw:
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   622
  assumes "b \<notin> A"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   623
    and "f b \<notin> A'"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   624
    and "bij_betw f A A'"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   625
  shows "bij_betw f (A \<union> {b}) (A' \<union> {f b})"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   626
proof -
55019
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
   627
  have "bij_betw f {b} {f b}"
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   628
    unfolding bij_betw_def inj_on_def by simp
55019
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
   629
  with assms show ?thesis
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   630
    using bij_betw_combine[of f A A' "{b}" "{f b}"] by blast
55019
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
   631
qed
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
   632
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
   633
lemma notIn_Un_bij_betw3:
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   634
  assumes "b \<notin> A"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   635
    and "f b \<notin> A'"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   636
  shows "bij_betw f A A' = bij_betw f (A \<union> {b}) (A' \<union> {f b})"
55019
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
   637
proof
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
   638
  assume "bij_betw f A A'"
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   639
  then show "bij_betw f (A \<union> {b}) (A' \<union> {f b})"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   640
    using assms notIn_Un_bij_betw [of b A f A'] by blast
55019
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
   641
next
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
   642
  assume *: "bij_betw f (A \<union> {b}) (A' \<union> {f b})"
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
   643
  have "f ` A = A'"
75669
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   644
  proof safe
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   645
    fix a
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   646
    assume **: "a \<in> A"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   647
    then have "f a \<in> A' \<union> {f b}"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   648
      using * unfolding bij_betw_def by blast
55019
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
   649
    moreover
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   650
    have False if "f a = f b"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   651
    proof -
63575
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   652
      have "a = b"
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   653
        using * ** that unfolding bij_betw_def inj_on_def by blast
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   654
      with \<open>b \<notin> A\<close> ** show ?thesis by blast
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   655
    qed
55019
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
   656
    ultimately show "f a \<in> A'" by blast
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
   657
  next
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   658
    fix a'
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   659
    assume **: "a' \<in> A'"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   660
    then have "a' \<in> f ` (A \<union> {b})"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   661
      using * by (auto simp add: bij_betw_def)
55019
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
   662
    then obtain a where 1: "a \<in> A \<union> {b} \<and> f a = a'" by blast
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
   663
    moreover
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   664
    have False if "a = b" using 1 ** \<open>f b \<notin> A'\<close> that by blast
55019
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
   665
    ultimately have "a \<in> A" by blast
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
   666
    with 1 show "a' \<in> f ` A" by blast
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
   667
  qed
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   668
  then show "bij_betw f A A'"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   669
    using * bij_betw_subset[of f "A \<union> {b}" _ A] by blast
55019
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
   670
qed
0d5e831175de moved lemmas from 'Fun_More_FP' to where they belong
blanchet
parents: 54578
diff changeset
   671
71857
d73955442df5 a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   672
lemma inj_on_disjoint_Un:
d73955442df5 a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   673
  assumes "inj_on f A" and "inj_on g B" 
d73955442df5 a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   674
  and "f ` A \<inter> g ` B = {}"
d73955442df5 a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   675
  shows "inj_on (\<lambda>x. if x \<in> A then f x else g x) (A \<union> B)"
d73955442df5 a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   676
  using assms by (simp add: inj_on_def disjoint_iff) (blast)
d73955442df5 a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   677
d73955442df5 a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   678
lemma bij_betw_disjoint_Un:
d73955442df5 a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   679
  assumes "bij_betw f A C" and "bij_betw g B D" 
d73955442df5 a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   680
  and "A \<inter> B = {}"
d73955442df5 a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   681
  and "C \<inter> D = {}"
d73955442df5 a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   682
  shows "bij_betw (\<lambda>x. if x \<in> A then f x else g x) (A \<union> B) (C \<union> D)"
d73955442df5 a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   683
  using assms by (auto simp: inj_on_disjoint_Un bij_betw_def)
d73955442df5 a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   684
73594
5c4a09c4bc9c collecting more lemmas concerning multisets
haftmann
parents: 73466
diff changeset
   685
lemma involuntory_imp_bij:
5c4a09c4bc9c collecting more lemmas concerning multisets
haftmann
parents: 73466
diff changeset
   686
  \<open>bij f\<close> if \<open>\<And>x. f (f x) = x\<close>
5c4a09c4bc9c collecting more lemmas concerning multisets
haftmann
parents: 73466
diff changeset
   687
proof (rule bijI)
5c4a09c4bc9c collecting more lemmas concerning multisets
haftmann
parents: 73466
diff changeset
   688
  from that show \<open>surj f\<close>
5c4a09c4bc9c collecting more lemmas concerning multisets
haftmann
parents: 73466
diff changeset
   689
    by (rule surjI)
5c4a09c4bc9c collecting more lemmas concerning multisets
haftmann
parents: 73466
diff changeset
   690
  show \<open>inj f\<close>
5c4a09c4bc9c collecting more lemmas concerning multisets
haftmann
parents: 73466
diff changeset
   691
  proof (rule injI)
5c4a09c4bc9c collecting more lemmas concerning multisets
haftmann
parents: 73466
diff changeset
   692
    fix x y
5c4a09c4bc9c collecting more lemmas concerning multisets
haftmann
parents: 73466
diff changeset
   693
    assume \<open>f x = f y\<close>
5c4a09c4bc9c collecting more lemmas concerning multisets
haftmann
parents: 73466
diff changeset
   694
    then have \<open>f (f x) = f (f y)\<close>
5c4a09c4bc9c collecting more lemmas concerning multisets
haftmann
parents: 73466
diff changeset
   695
      by simp
5c4a09c4bc9c collecting more lemmas concerning multisets
haftmann
parents: 73466
diff changeset
   696
    then show \<open>x = y\<close>
5c4a09c4bc9c collecting more lemmas concerning multisets
haftmann
parents: 73466
diff changeset
   697
      by (simp add: that)
5c4a09c4bc9c collecting more lemmas concerning multisets
haftmann
parents: 73466
diff changeset
   698
  qed
5c4a09c4bc9c collecting more lemmas concerning multisets
haftmann
parents: 73466
diff changeset
   699
qed
5c4a09c4bc9c collecting more lemmas concerning multisets
haftmann
parents: 73466
diff changeset
   700
5c4a09c4bc9c collecting more lemmas concerning multisets
haftmann
parents: 73466
diff changeset
   701
76261
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   702
subsubsection \<open>Inj/surj/bij of Algebraic Operations\<close>
69502
0cf906072e20 more rules
haftmann
parents: 67399
diff changeset
   703
0cf906072e20 more rules
haftmann
parents: 67399
diff changeset
   704
context cancel_semigroup_add
0cf906072e20 more rules
haftmann
parents: 67399
diff changeset
   705
begin
0cf906072e20 more rules
haftmann
parents: 67399
diff changeset
   706
69661
a03a63b81f44 tuned proofs
haftmann
parents: 69605
diff changeset
   707
lemma inj_on_add [simp]:
a03a63b81f44 tuned proofs
haftmann
parents: 69605
diff changeset
   708
  "inj_on ((+) a) A"
a03a63b81f44 tuned proofs
haftmann
parents: 69605
diff changeset
   709
  by (rule inj_onI) simp
a03a63b81f44 tuned proofs
haftmann
parents: 69605
diff changeset
   710
a03a63b81f44 tuned proofs
haftmann
parents: 69605
diff changeset
   711
lemma inj_on_add' [simp]:
a03a63b81f44 tuned proofs
haftmann
parents: 69605
diff changeset
   712
  "inj_on (\<lambda>b. b + a) A"
a03a63b81f44 tuned proofs
haftmann
parents: 69605
diff changeset
   713
  by (rule inj_onI) simp
a03a63b81f44 tuned proofs
haftmann
parents: 69605
diff changeset
   714
a03a63b81f44 tuned proofs
haftmann
parents: 69605
diff changeset
   715
lemma bij_betw_add [simp]:
a03a63b81f44 tuned proofs
haftmann
parents: 69605
diff changeset
   716
  "bij_betw ((+) a) A B \<longleftrightarrow> (+) a ` A = B"
a03a63b81f44 tuned proofs
haftmann
parents: 69605
diff changeset
   717
  by (simp add: bij_betw_def)
69502
0cf906072e20 more rules
haftmann
parents: 67399
diff changeset
   718
0cf906072e20 more rules
haftmann
parents: 67399
diff changeset
   719
end
0cf906072e20 more rules
haftmann
parents: 67399
diff changeset
   720
76252
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   721
context group_add
69502
0cf906072e20 more rules
haftmann
parents: 67399
diff changeset
   722
begin
0cf906072e20 more rules
haftmann
parents: 67399
diff changeset
   723
76261
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   724
lemma diff_left_imp_eq: "a - b = a - c \<Longrightarrow> b = c"
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   725
unfolding add_uminus_conv_diff[symmetric]
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   726
by(drule local.add_left_imp_eq) simp
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   727
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   728
lemma inj_uminus[simp, intro]: "inj_on uminus A"
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   729
  by (auto intro!: inj_onI)
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   730
76264
60511708a650 one more lemma
nipkow
parents: 76261
diff changeset
   731
lemma surj_uminus[simp]: "surj uminus"
60511708a650 one more lemma
nipkow
parents: 76261
diff changeset
   732
using surjI minus_minus by blast
60511708a650 one more lemma
nipkow
parents: 76261
diff changeset
   733
69661
a03a63b81f44 tuned proofs
haftmann
parents: 69605
diff changeset
   734
lemma surj_plus [simp]:
a03a63b81f44 tuned proofs
haftmann
parents: 69605
diff changeset
   735
  "surj ((+) a)"
76252
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   736
proof (standard, simp, standard, simp)
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   737
  fix x
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   738
  have "x = a + (-a + x)" by (simp add: add.assoc)
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   739
  thus "x \<in> range ((+) a)" by blast
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   740
qed
69661
a03a63b81f44 tuned proofs
haftmann
parents: 69605
diff changeset
   741
76261
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   742
lemma surj_plus_right [simp]:
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   743
  "surj (\<lambda>b. b+a)"
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   744
proof (standard, simp, standard, simp)
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   745
  fix b show "b \<in> range (\<lambda>b. b+a)"
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   746
    using diff_add_cancel[of b a, symmetric] by blast
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   747
qed
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   748
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   749
lemma inj_on_diff_left [simp]:
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   750
  \<open>inj_on ((-) a) A\<close>
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   751
by (auto intro: inj_onI dest!: diff_left_imp_eq)
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   752
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   753
lemma inj_on_diff_right [simp]:
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   754
  \<open>inj_on (\<lambda>b. b - a) A\<close>
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   755
by (auto intro: inj_onI simp add: algebra_simps)
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   756
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   757
lemma surj_diff [simp]:
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   758
  "surj ((-) a)"
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   759
proof (standard, simp, standard, simp)
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   760
  fix x
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   761
  have "x = a - (- x + a)" by (simp add: algebra_simps)
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   762
  thus "x \<in> range ((-) a)" by blast
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   763
qed
69502
0cf906072e20 more rules
haftmann
parents: 67399
diff changeset
   764
69661
a03a63b81f44 tuned proofs
haftmann
parents: 69605
diff changeset
   765
lemma surj_diff_right [simp]:
a03a63b81f44 tuned proofs
haftmann
parents: 69605
diff changeset
   766
  "surj (\<lambda>x. x - a)"
76252
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   767
proof (standard, simp, standard, simp)
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   768
  fix x
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   769
  have "x = x + a - a" by simp
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   770
  thus "x \<in> range (\<lambda>x. x - a)" by fast
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   771
qed
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   772
76261
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   773
lemma shows bij_plus: "bij ((+) a)" and bij_plus_right: "bij (\<lambda>x. x + a)"
76264
60511708a650 one more lemma
nipkow
parents: 76261
diff changeset
   774
  and bij_uminus: "bij uminus"
76261
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   775
  and bij_diff: "bij ((-) a)" and bij_diff_right: "bij (\<lambda>x. x - a)"
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   776
by(simp_all add: bij_def)
26524d0b4395 added and reorganized lemmas (some suggested by Jeremy Sylvestre)
nipkow
parents: 76260
diff changeset
   777
76252
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   778
lemma translation_subtract_Compl:
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   779
  "(\<lambda>x. x - a) ` (- t) = - ((\<lambda>x. x - a) ` t)"
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   780
by(rule bij_image_Compl_eq)
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   781
  (auto simp add: bij_def surj_def inj_def diff_eq_eq intro!: add_diff_cancel[symmetric])
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   782
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   783
lemma translation_diff:
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   784
  "(+) a ` (s - t) = ((+) a ` s) - ((+) a ` t)"
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   785
  by auto
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   786
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   787
lemma translation_subtract_diff:
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   788
  "(\<lambda>x. x - a) ` (s - t) = ((\<lambda>x. x - a) ` s) - ((\<lambda>x. x - a) ` t)"
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   789
by(rule image_set_diff)(simp add: inj_on_def diff_eq_eq)
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   790
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   791
lemma translation_Int:
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   792
  "(+) a ` (s \<inter> t) = ((+) a ` s) \<inter> ((+) a ` t)"
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   793
  by auto
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   794
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   795
lemma translation_subtract_Int:
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   796
  "(\<lambda>x. x - a) ` (s \<inter> t) = ((\<lambda>x. x - a) ` s) \<inter> ((\<lambda>x. x - a) ` t)"
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   797
by(rule image_Int)(simp add: inj_on_def diff_eq_eq)
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   798
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   799
end
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   800
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   801
(* TODO: prove in group_add *)
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   802
context ab_group_add
d123d9f67514 generalized type classes as suggested by Jeremy Sylvestre
nipkow
parents: 76056
diff changeset
   803
begin
69661
a03a63b81f44 tuned proofs
haftmann
parents: 69605
diff changeset
   804
a03a63b81f44 tuned proofs
haftmann
parents: 69605
diff changeset
   805
lemma translation_Compl:
a03a63b81f44 tuned proofs
haftmann
parents: 69605
diff changeset
   806
  "(+) a ` (- t) = - ((+) a ` t)"
a03a63b81f44 tuned proofs
haftmann
parents: 69605
diff changeset
   807
proof (rule set_eqI)
a03a63b81f44 tuned proofs
haftmann
parents: 69605
diff changeset
   808
  fix b
a03a63b81f44 tuned proofs
haftmann
parents: 69605
diff changeset
   809
  show "b \<in> (+) a ` (- t) \<longleftrightarrow> b \<in> - (+) a ` t"
a03a63b81f44 tuned proofs
haftmann
parents: 69605
diff changeset
   810
    by (auto simp: image_iff algebra_simps intro!: bexI [of _ "b - a"])
a03a63b81f44 tuned proofs
haftmann
parents: 69605
diff changeset
   811
qed
a03a63b81f44 tuned proofs
haftmann
parents: 69605
diff changeset
   812
69502
0cf906072e20 more rules
haftmann
parents: 67399
diff changeset
   813
end
0cf906072e20 more rules
haftmann
parents: 67399
diff changeset
   814
41657
89451110ba8e moved theorem
haftmann
parents: 41505
diff changeset
   815
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   816
subsection \<open>Function Updating\<close>
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   817
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   818
definition fun_upd :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> ('a \<Rightarrow> 'b)"
63324
1e98146f3581 prefer HOL definitions;
wenzelm
parents: 63323
diff changeset
   819
  where "fun_upd f a b = (\<lambda>x. if x = a then b else f x)"
26147
ae2bf929e33c moved some set lemmas to Set.thy
haftmann
parents: 26105
diff changeset
   820
41229
d797baa3d57c replaced command 'nonterminals' by slightly modernized version 'nonterminal';
wenzelm
parents: 40969
diff changeset
   821
nonterminal updbinds and updbind
d797baa3d57c replaced command 'nonterminals' by slightly modernized version 'nonterminal';
wenzelm
parents: 40969
diff changeset
   822
26147
ae2bf929e33c moved some set lemmas to Set.thy
haftmann
parents: 26105
diff changeset
   823
syntax
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   824
  "_updbind" :: "'a \<Rightarrow> 'a \<Rightarrow> updbind"             ("(2_ :=/ _)")
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   825
  ""         :: "updbind \<Rightarrow> updbinds"             ("_")
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   826
  "_updbinds":: "updbind \<Rightarrow> updbinds \<Rightarrow> updbinds" ("_,/ _")
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   827
  "_Update"  :: "'a \<Rightarrow> updbinds \<Rightarrow> 'a"            ("_/'((_)')" [1000, 0] 900)
26147
ae2bf929e33c moved some set lemmas to Set.thy
haftmann
parents: 26105
diff changeset
   828
ae2bf929e33c moved some set lemmas to Set.thy
haftmann
parents: 26105
diff changeset
   829
translations
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   830
  "_Update f (_updbinds b bs)" \<rightleftharpoons> "_Update (_Update f b) bs"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   831
  "f(x:=y)" \<rightleftharpoons> "CONST fun_upd f x y"
26147
ae2bf929e33c moved some set lemmas to Set.thy
haftmann
parents: 26105
diff changeset
   832
55414
eab03e9cee8a renamed '{prod,sum,bool,unit}_case' to 'case_...'
blanchet
parents: 55066
diff changeset
   833
(* Hint: to define the sum of two functions (or maps), use case_sum.
58111
82db9ad610b9 tuned structure inclusion
blanchet
parents: 57282
diff changeset
   834
         A nice infix syntax could be defined by
35115
446c5063e4fd modernized translations;
wenzelm
parents: 34209
diff changeset
   835
notation
55414
eab03e9cee8a renamed '{prod,sum,bool,unit}_case' to 'case_...'
blanchet
parents: 55066
diff changeset
   836
  case_sum  (infixr "'(+')"80)
26147
ae2bf929e33c moved some set lemmas to Set.thy
haftmann
parents: 26105
diff changeset
   837
*)
ae2bf929e33c moved some set lemmas to Set.thy
haftmann
parents: 26105
diff changeset
   838
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   839
lemma fun_upd_idem_iff: "f(x:=y) = f \<longleftrightarrow> f x = y"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   840
  unfolding fun_upd_def
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   841
  apply safe
63575
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   842
   apply (erule subst)
b9bd9e61fd63 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   843
   apply auto
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   844
  done
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   845
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   846
lemma fun_upd_idem: "f x = y \<Longrightarrow> f(x := y) = f"
45603
d2d9ef16ccaf explicit is better than implicit;
wenzelm
parents: 45174
diff changeset
   847
  by (simp only: fun_upd_idem_iff)
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   848
45603
d2d9ef16ccaf explicit is better than implicit;
wenzelm
parents: 45174
diff changeset
   849
lemma fun_upd_triv [iff]: "f(x := f x) = f"
d2d9ef16ccaf explicit is better than implicit;
wenzelm
parents: 45174
diff changeset
   850
  by (simp only: fun_upd_idem)
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   851
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   852
lemma fun_upd_apply [simp]: "(f(x := y)) z = (if z = x then y else f z)"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   853
  by (simp add: fun_upd_def)
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   854
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   855
(* fun_upd_apply supersedes these two, but they are useful
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   856
   if fun_upd_apply is intentionally removed from the simpset *)
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   857
lemma fun_upd_same: "(f(x := y)) x = y"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   858
  by simp
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   859
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   860
lemma fun_upd_other: "z \<noteq> x \<Longrightarrow> (f(x := y)) z = f z"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   861
  by simp
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   862
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   863
lemma fun_upd_upd [simp]: "f(x := y, x := z) = f(x := z)"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   864
  by (simp add: fun_eq_iff)
13585
db4005b40cc6 Converted Fun to Isar style.
paulson
parents: 12460
diff changeset
   865
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   866
lemma fun_upd_twist: "a \<noteq> c \<Longrightarrow> (m(a := b))(c := d) = (m(c := d))(a := b)"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 71472
diff changeset
   867
  by auto
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   868
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   869
lemma inj_on_fun_updI: "inj_on f A \<Longrightarrow> y \<notin> f ` A \<Longrightarrow> inj_on (f(x := y)) A"
64966
d53d7ca3303e added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents: 64965
diff changeset
   870
  by (auto simp: inj_on_def)
15303
eedbb8d22ca2 added lemmas
nipkow
parents: 15140
diff changeset
   871
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   872
lemma fun_upd_image: "f(x := y) ` A = (if x \<in> A then insert y (f ` (A - {x})) else f ` A)"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   873
  by auto
15510
9de204d7b699 new foldSet proofs
paulson
parents: 15439
diff changeset
   874
31080
21ffc770ebc0 lemmas by Andreas Lochbihler
nipkow
parents: 30301
diff changeset
   875
lemma fun_upd_comp: "f \<circ> (g(x := y)) = (f \<circ> g)(x := f y)"
44921
58eef4843641 tuned proofs
huffman
parents: 44890
diff changeset
   876
  by auto
31080
21ffc770ebc0 lemmas by Andreas Lochbihler
nipkow
parents: 30301
diff changeset
   877
61630
608520e0e8e2 add various lemmas
Andreas Lochbihler
parents: 61520
diff changeset
   878
lemma fun_upd_eqD: "f(x := y) = g(x := z) \<Longrightarrow> y = z"
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   879
  by (simp add: fun_eq_iff split: if_split_asm)
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   880
26147
ae2bf929e33c moved some set lemmas to Set.thy
haftmann
parents: 26105
diff changeset
   881
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61699
diff changeset
   882
subsection \<open>\<open>override_on\<close>\<close>
26147
ae2bf929e33c moved some set lemmas to Set.thy
haftmann
parents: 26105
diff changeset
   883
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   884
definition override_on :: "('a \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a set \<Rightarrow> 'a \<Rightarrow> 'b"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   885
  where "override_on f g A = (\<lambda>a. if a \<in> A then g a else f a)"
13910
f9a9ef16466f Added thms
nipkow
parents: 13637
diff changeset
   886
15691
900cf45ff0a6 _(_|_) is now override_on
nipkow
parents: 15531
diff changeset
   887
lemma override_on_emptyset[simp]: "override_on f g {} = f"
64965
d55d743c45a2 tuned proofs;
wenzelm
parents: 63591
diff changeset
   888
  by (simp add: override_on_def)
13910
f9a9ef16466f Added thms
nipkow
parents: 13637
diff changeset
   889
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   890
lemma override_on_apply_notin[simp]: "a \<notin> A \<Longrightarrow> (override_on f g A) a = f a"
64965
d55d743c45a2 tuned proofs;
wenzelm
parents: 63591
diff changeset
   891
  by (simp add: override_on_def)
13910
f9a9ef16466f Added thms
nipkow
parents: 13637
diff changeset
   892
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   893
lemma override_on_apply_in[simp]: "a \<in> A \<Longrightarrow> (override_on f g A) a = g a"
64965
d55d743c45a2 tuned proofs;
wenzelm
parents: 63591
diff changeset
   894
  by (simp add: override_on_def)
13910
f9a9ef16466f Added thms
nipkow
parents: 13637
diff changeset
   895
63561
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63416
diff changeset
   896
lemma override_on_insert: "override_on f g (insert x X) = (override_on f g X)(x:=g x)"
64965
d55d743c45a2 tuned proofs;
wenzelm
parents: 63591
diff changeset
   897
  by (simp add: override_on_def fun_eq_iff)
63561
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63416
diff changeset
   898
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63416
diff changeset
   899
lemma override_on_insert': "override_on f g (insert x X) = (override_on (f(x:=g x)) g X)"
64965
d55d743c45a2 tuned proofs;
wenzelm
parents: 63591
diff changeset
   900
  by (simp add: override_on_def fun_eq_iff)
63561
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63416
diff changeset
   901
26147
ae2bf929e33c moved some set lemmas to Set.thy
haftmann
parents: 26105
diff changeset
   902
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60303
diff changeset
   903
subsection \<open>Inversion of injective functions\<close>
31949
3f933687fae9 moved Inductive.myinv to Fun.inv; tuned
haftmann
parents: 31775
diff changeset
   904
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   905
definition the_inv_into :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> ('b \<Rightarrow> 'a)"
63324
1e98146f3581 prefer HOL definitions;
wenzelm
parents: 63323
diff changeset
   906
  where "the_inv_into A f = (\<lambda>x. THE y. y \<in> A \<and> f y = x)"
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   907
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   908
lemma the_inv_into_f_f: "inj_on f A \<Longrightarrow> x \<in> A \<Longrightarrow> the_inv_into A f (f x) = x"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   909
  unfolding the_inv_into_def inj_on_def by blast
32961
61431a41ddd5 added the_inv_onto
nipkow
parents: 32740
diff changeset
   910
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   911
lemma f_the_inv_into_f: "inj_on f A \<Longrightarrow> y \<in> f ` A  \<Longrightarrow> f (the_inv_into A f y) = y"
71857
d73955442df5 a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   912
  unfolding the_inv_into_def
d73955442df5 a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   913
  by (rule the1I2; blast dest: inj_onD)
32961
61431a41ddd5 added the_inv_onto
nipkow
parents: 32740
diff changeset
   914
72125
cf8399df4d76 elimination of some needless assumptions
paulson <lp15@cam.ac.uk>
parents: 71857
diff changeset
   915
lemma f_the_inv_into_f_bij_betw:
cf8399df4d76 elimination of some needless assumptions
paulson <lp15@cam.ac.uk>
parents: 71857
diff changeset
   916
  "bij_betw f A B \<Longrightarrow> (bij_betw f A B \<Longrightarrow> x \<in> B) \<Longrightarrow> f (the_inv_into A f x) = x"
cf8399df4d76 elimination of some needless assumptions
paulson <lp15@cam.ac.uk>
parents: 71857
diff changeset
   917
  unfolding bij_betw_def by (blast intro: f_the_inv_into_f)
cf8399df4d76 elimination of some needless assumptions
paulson <lp15@cam.ac.uk>
parents: 71857
diff changeset
   918
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   919
lemma the_inv_into_into: "inj_on f A \<Longrightarrow> x \<in> f ` A \<Longrightarrow> A \<subseteq> B \<Longrightarrow> the_inv_into A f x \<in> B"
71857
d73955442df5 a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   920
  unfolding the_inv_into_def
d73955442df5 a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   921
  by (rule the1I2; blast dest: inj_onD)
32961
61431a41ddd5 added the_inv_onto
nipkow
parents: 32740
diff changeset
   922
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   923
lemma the_inv_into_onto [simp]: "inj_on f A \<Longrightarrow> the_inv_into A f ` (f ` A) = A"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   924
  by (fast intro: the_inv_into_into the_inv_into_f_f [symmetric])
32961
61431a41ddd5 added the_inv_onto
nipkow
parents: 32740
diff changeset
   925
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   926
lemma the_inv_into_f_eq: "inj_on f A \<Longrightarrow> f x = y \<Longrightarrow> x \<in> A \<Longrightarrow> the_inv_into A f y = x"
71857
d73955442df5 a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   927
  by (force simp add: the_inv_into_f_f)
32961
61431a41ddd5 added the_inv_onto
nipkow
parents: 32740
diff changeset
   928
33057
764547b68538 inv_onto -> inv_into
nipkow
parents: 33044
diff changeset
   929
lemma the_inv_into_comp:
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   930
  "inj_on f (g ` A) \<Longrightarrow> inj_on g A \<Longrightarrow> x \<in> f ` g ` A \<Longrightarrow>
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   931
    the_inv_into A (f \<circ> g) x = (the_inv_into A g \<circ> the_inv_into (g ` A) f) x"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   932
  apply (rule the_inv_into_f_eq)
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   933
    apply (fast intro: comp_inj_on)
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   934
   apply (simp add: f_the_inv_into_f the_inv_into_into)
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   935
  apply (simp add: the_inv_into_into)
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   936
  done
32961
61431a41ddd5 added the_inv_onto
nipkow
parents: 32740
diff changeset
   937
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   938
lemma inj_on_the_inv_into: "inj_on f A \<Longrightarrow> inj_on (the_inv_into A f) (f ` A)"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   939
  by (auto intro: inj_onI simp: the_inv_into_f_f)
32961
61431a41ddd5 added the_inv_onto
nipkow
parents: 32740
diff changeset
   940
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   941
lemma bij_betw_the_inv_into: "bij_betw f A B \<Longrightarrow> bij_betw (the_inv_into A f) B A"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   942
  by (auto simp add: bij_betw_def inj_on_the_inv_into the_inv_into_into)
32961
61431a41ddd5 added the_inv_onto
nipkow
parents: 32740
diff changeset
   943
71857
d73955442df5 a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   944
lemma bij_betw_iff_bijections:
d73955442df5 a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   945
  "bij_betw f A B \<longleftrightarrow> (\<exists>g. (\<forall>x \<in> A. f x \<in> B \<and> g(f x) = x) \<and> (\<forall>y \<in> B. g y \<in> A \<and> f(g y) = y))"
d73955442df5 a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   946
  (is "?lhs = ?rhs")
d73955442df5 a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   947
proof
75669
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   948
  show "?lhs \<Longrightarrow> ?rhs"
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   949
    by (auto simp: bij_betw_def f_the_inv_into_f the_inv_into_f_f the_inv_into_into
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   950
        exI[where ?x="the_inv_into A f"])
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   951
next
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   952
  show "?rhs \<Longrightarrow> ?lhs"
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   953
    by (force intro: bij_betw_byWitness)
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
   954
qed
71857
d73955442df5 a few new lemmas about functions
paulson <lp15@cam.ac.uk>
parents: 71827
diff changeset
   955
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   956
abbreviation the_inv :: "('a \<Rightarrow> 'b) \<Rightarrow> ('b \<Rightarrow> 'a)"
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
   957
  where "the_inv f \<equiv> the_inv_into UNIV f"
32998
31b19fa0de0b Renamed inv to the_inv and turned it into an abbreviation (based on the_inv_onto).
berghofe
parents: 32988
diff changeset
   958
64965
d55d743c45a2 tuned proofs;
wenzelm
parents: 63591
diff changeset
   959
lemma the_inv_f_f: "the_inv f (f x) = x" if "inj f"
d55d743c45a2 tuned proofs;
wenzelm
parents: 63591
diff changeset
   960
  using that UNIV_I by (rule the_inv_into_f_f)
32998
31b19fa0de0b Renamed inv to the_inv and turned it into an abbreviation (based on the_inv_onto).
berghofe
parents: 32988
diff changeset
   961
44277
bcb696533579 moved fundamental lemma fun_eq_iff to theory HOL; tuned whitespace
haftmann
parents: 43991
diff changeset
   962
76054
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
   963
subsection \<open>Monotonicity\<close>
71472
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
   964
75582
6fb4a0829cc4 added predicate monotone_on and redefined monotone to be an abbreviation.
desharna
parents: 74123
diff changeset
   965
definition monotone_on :: "'a set \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> bool"
6fb4a0829cc4 added predicate monotone_on and redefined monotone to be an abbreviation.
desharna
parents: 74123
diff changeset
   966
  where "monotone_on A orda ordb f \<longleftrightarrow> (\<forall>x\<in>A. \<forall>y\<in>A. orda x y \<longrightarrow> ordb (f x) (f y))"
6fb4a0829cc4 added predicate monotone_on and redefined monotone to be an abbreviation.
desharna
parents: 74123
diff changeset
   967
6fb4a0829cc4 added predicate monotone_on and redefined monotone to be an abbreviation.
desharna
parents: 74123
diff changeset
   968
abbreviation monotone :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> bool"
6fb4a0829cc4 added predicate monotone_on and redefined monotone to be an abbreviation.
desharna
parents: 74123
diff changeset
   969
  where "monotone \<equiv> monotone_on UNIV"
6fb4a0829cc4 added predicate monotone_on and redefined monotone to be an abbreviation.
desharna
parents: 74123
diff changeset
   970
6fb4a0829cc4 added predicate monotone_on and redefined monotone to be an abbreviation.
desharna
parents: 74123
diff changeset
   971
lemma monotone_def[no_atp]: "monotone orda ordb f \<longleftrightarrow> (\<forall>x y. orda x y \<longrightarrow> ordb (f x) (f y))"
6fb4a0829cc4 added predicate monotone_on and redefined monotone to be an abbreviation.
desharna
parents: 74123
diff changeset
   972
  by (simp add: monotone_on_def)
6fb4a0829cc4 added predicate monotone_on and redefined monotone to be an abbreviation.
desharna
parents: 74123
diff changeset
   973
6fb4a0829cc4 added predicate monotone_on and redefined monotone to be an abbreviation.
desharna
parents: 74123
diff changeset
   974
text \<open>Lemma @{thm [source] monotone_def} is provided for backward compatibility.\<close>
6fb4a0829cc4 added predicate monotone_on and redefined monotone to be an abbreviation.
desharna
parents: 74123
diff changeset
   975
6fb4a0829cc4 added predicate monotone_on and redefined monotone to be an abbreviation.
desharna
parents: 74123
diff changeset
   976
lemma monotone_onI:
6fb4a0829cc4 added predicate monotone_on and redefined monotone to be an abbreviation.
desharna
parents: 74123
diff changeset
   977
  "(\<And>x y. x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> orda x y \<Longrightarrow> ordb (f x) (f y)) \<Longrightarrow> monotone_on A orda ordb f"
6fb4a0829cc4 added predicate monotone_on and redefined monotone to be an abbreviation.
desharna
parents: 74123
diff changeset
   978
  by (simp add: monotone_on_def)
6fb4a0829cc4 added predicate monotone_on and redefined monotone to be an abbreviation.
desharna
parents: 74123
diff changeset
   979
6fb4a0829cc4 added predicate monotone_on and redefined monotone to be an abbreviation.
desharna
parents: 74123
diff changeset
   980
lemma monotoneI[intro?]: "(\<And>x y. orda x y \<Longrightarrow> ordb (f x) (f y)) \<Longrightarrow> monotone orda ordb f"
6fb4a0829cc4 added predicate monotone_on and redefined monotone to be an abbreviation.
desharna
parents: 74123
diff changeset
   981
  by (rule monotone_onI)
6fb4a0829cc4 added predicate monotone_on and redefined monotone to be an abbreviation.
desharna
parents: 74123
diff changeset
   982
6fb4a0829cc4 added predicate monotone_on and redefined monotone to be an abbreviation.
desharna
parents: 74123
diff changeset
   983
lemma monotone_onD:
6fb4a0829cc4 added predicate monotone_on and redefined monotone to be an abbreviation.
desharna
parents: 74123
diff changeset
   984
  "monotone_on A orda ordb f \<Longrightarrow> x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> orda x y \<Longrightarrow> ordb (f x) (f y)"
6fb4a0829cc4 added predicate monotone_on and redefined monotone to be an abbreviation.
desharna
parents: 74123
diff changeset
   985
  by (simp add: monotone_on_def)
6fb4a0829cc4 added predicate monotone_on and redefined monotone to be an abbreviation.
desharna
parents: 74123
diff changeset
   986
6fb4a0829cc4 added predicate monotone_on and redefined monotone to be an abbreviation.
desharna
parents: 74123
diff changeset
   987
lemma monotoneD[dest?]: "monotone orda ordb f \<Longrightarrow> orda x y \<Longrightarrow> ordb (f x) (f y)"
75607
3c544d64c218 changed argument order of mono_on and strict_mono_on to uniformize with monotone_on and other predicates
desharna
parents: 75583
diff changeset
   988
  by (rule monotone_onD[of UNIV, simplified])
75582
6fb4a0829cc4 added predicate monotone_on and redefined monotone to be an abbreviation.
desharna
parents: 74123
diff changeset
   989
75583
451e17e0ba9d added lemmas monotone_on_empty[simp] and monotone_on_subset
desharna
parents: 75582
diff changeset
   990
lemma monotone_on_subset: "monotone_on A orda ordb f \<Longrightarrow> B \<subseteq> A \<Longrightarrow> monotone_on B orda ordb f"
451e17e0ba9d added lemmas monotone_on_empty[simp] and monotone_on_subset
desharna
parents: 75582
diff changeset
   991
  by (auto intro: monotone_onI dest: monotone_onD)
451e17e0ba9d added lemmas monotone_on_empty[simp] and monotone_on_subset
desharna
parents: 75582
diff changeset
   992
451e17e0ba9d added lemmas monotone_on_empty[simp] and monotone_on_subset
desharna
parents: 75582
diff changeset
   993
lemma monotone_on_empty[simp]: "monotone_on {} orda ordb f"
451e17e0ba9d added lemmas monotone_on_empty[simp] and monotone_on_subset
desharna
parents: 75582
diff changeset
   994
  by (auto intro: monotone_onI dest: monotone_onD)
451e17e0ba9d added lemmas monotone_on_empty[simp] and monotone_on_subset
desharna
parents: 75582
diff changeset
   995
75609
19ec8f844e08 added lemma monotone_on_o
desharna
parents: 75608
diff changeset
   996
lemma monotone_on_o:
19ec8f844e08 added lemma monotone_on_o
desharna
parents: 75608
diff changeset
   997
  assumes
19ec8f844e08 added lemma monotone_on_o
desharna
parents: 75608
diff changeset
   998
    mono_f: "monotone_on A orda ordb f" and
19ec8f844e08 added lemma monotone_on_o
desharna
parents: 75608
diff changeset
   999
    mono_g: "monotone_on B ordc orda g" and
19ec8f844e08 added lemma monotone_on_o
desharna
parents: 75608
diff changeset
  1000
    "g ` B \<subseteq> A"
19ec8f844e08 added lemma monotone_on_o
desharna
parents: 75608
diff changeset
  1001
  shows "monotone_on B ordc ordb (f \<circ> g)"
19ec8f844e08 added lemma monotone_on_o
desharna
parents: 75608
diff changeset
  1002
proof (rule monotone_onI)
19ec8f844e08 added lemma monotone_on_o
desharna
parents: 75608
diff changeset
  1003
  fix x y assume "x \<in> B" and "y \<in> B" and "ordc x y"
19ec8f844e08 added lemma monotone_on_o
desharna
parents: 75608
diff changeset
  1004
  hence "orda (g x) (g y)"
19ec8f844e08 added lemma monotone_on_o
desharna
parents: 75608
diff changeset
  1005
    by (rule mono_g[THEN monotone_onD])
19ec8f844e08 added lemma monotone_on_o
desharna
parents: 75608
diff changeset
  1006
  moreover from \<open>g ` B \<subseteq> A\<close> \<open>x \<in> B\<close> \<open>y \<in> B\<close> have "g x \<in> A" and "g y \<in> A"
19ec8f844e08 added lemma monotone_on_o
desharna
parents: 75608
diff changeset
  1007
    unfolding image_subset_iff by simp_all
19ec8f844e08 added lemma monotone_on_o
desharna
parents: 75608
diff changeset
  1008
  ultimately show "ordb ((f \<circ> g) x) ((f \<circ> g) y)"
19ec8f844e08 added lemma monotone_on_o
desharna
parents: 75608
diff changeset
  1009
    using mono_f[THEN monotone_onD] by simp
19ec8f844e08 added lemma monotone_on_o
desharna
parents: 75608
diff changeset
  1010
qed
19ec8f844e08 added lemma monotone_on_o
desharna
parents: 75608
diff changeset
  1011
76054
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1012
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1013
subsubsection \<open>Specializations For @{class ord} Type Class And More\<close>
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1014
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1015
context ord begin
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1016
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1017
abbreviation mono_on :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b :: ord) \<Rightarrow> bool"
75608
6c542e152b8a redefined mono_on and strict_mono_on as an abbreviation of monotone_on
desharna
parents: 75607
diff changeset
  1018
  where "mono_on A \<equiv> monotone_on A (\<le>) (\<le>)"
6c542e152b8a redefined mono_on and strict_mono_on as an abbreviation of monotone_on
desharna
parents: 75607
diff changeset
  1019
76054
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1020
abbreviation strict_mono_on :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b :: ord) \<Rightarrow> bool"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1021
  where "strict_mono_on A \<equiv> monotone_on A (<) (<)"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1022
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1023
lemma mono_on_def[no_atp]: "mono_on A f \<longleftrightarrow> (\<forall>r s. r \<in> A \<and> s \<in> A \<and> r \<le> s \<longrightarrow> f r \<le> f s)"
75608
6c542e152b8a redefined mono_on and strict_mono_on as an abbreviation of monotone_on
desharna
parents: 75607
diff changeset
  1024
  by (auto simp add: monotone_on_def)
71472
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1025
76054
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1026
lemma strict_mono_on_def[no_atp]:
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1027
  "strict_mono_on A f \<longleftrightarrow> (\<forall>r s. r \<in> A \<and> s \<in> A \<and> r < s \<longrightarrow> f r < f s)"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1028
  by (auto simp add: monotone_on_def)
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1029
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1030
text \<open>Lemmas @{thm [source] mono_on_def} and @{thm [source] strict_mono_on_def} are provided for
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1031
backward compatibility.\<close>
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1032
71472
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1033
lemma mono_onI:
75607
3c544d64c218 changed argument order of mono_on and strict_mono_on to uniformize with monotone_on and other predicates
desharna
parents: 75583
diff changeset
  1034
  "(\<And>r s. r \<in> A \<Longrightarrow> s \<in> A \<Longrightarrow> r \<le> s \<Longrightarrow> f r \<le> f s) \<Longrightarrow> mono_on A f"
75608
6c542e152b8a redefined mono_on and strict_mono_on as an abbreviation of monotone_on
desharna
parents: 75607
diff changeset
  1035
  by (rule monotone_onI)
71472
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1036
76054
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1037
lemma strict_mono_onI:
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1038
  "(\<And>r s. r \<in> A \<Longrightarrow> s \<in> A \<Longrightarrow> r < s \<Longrightarrow> f r < f s) \<Longrightarrow> strict_mono_on A f"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1039
  by (rule monotone_onI)
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1040
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1041
lemma mono_onD: "\<lbrakk>mono_on A f; r \<in> A; s \<in> A; r \<le> s\<rbrakk> \<Longrightarrow> f r \<le> f s"
75608
6c542e152b8a redefined mono_on and strict_mono_on as an abbreviation of monotone_on
desharna
parents: 75607
diff changeset
  1042
  by (rule monotone_onD)
71472
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1043
76054
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1044
lemma strict_mono_onD: "\<lbrakk>strict_mono_on A f; r \<in> A; s \<in> A; r < s\<rbrakk> \<Longrightarrow> f r < f s"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1045
  by (rule monotone_onD)
71472
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1046
75607
3c544d64c218 changed argument order of mono_on and strict_mono_on to uniformize with monotone_on and other predicates
desharna
parents: 75583
diff changeset
  1047
lemma mono_on_subset: "mono_on A f \<Longrightarrow> B \<subseteq> A \<Longrightarrow> mono_on B f"
75608
6c542e152b8a redefined mono_on and strict_mono_on as an abbreviation of monotone_on
desharna
parents: 75607
diff changeset
  1048
  by (rule monotone_on_subset)
71472
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1049
76054
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1050
end
71472
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1051
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1052
lemma mono_on_greaterD:
75607
3c544d64c218 changed argument order of mono_on and strict_mono_on to uniformize with monotone_on and other predicates
desharna
parents: 75583
diff changeset
  1053
  assumes "mono_on A g" "x \<in> A" "y \<in> A" "g x > (g (y::_::linorder) :: _ :: linorder)"
71472
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1054
  shows "x > y"
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1055
proof (rule ccontr)
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1056
  assume "\<not>x > y"
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1057
  hence "x \<le> y" by (simp add: not_less)
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1058
  from assms(1-3) and this have "g x \<le> g y" by (rule mono_onD)
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1059
  with assms(4) show False by simp
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1060
qed
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1061
76054
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1062
context order begin
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1063
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1064
abbreviation mono :: "('a \<Rightarrow> 'b::order) \<Rightarrow> bool"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1065
  where "mono \<equiv> mono_on UNIV"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1066
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1067
abbreviation strict_mono :: "('a \<Rightarrow> 'b::order) \<Rightarrow> bool"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1068
  where "strict_mono \<equiv> strict_mono_on UNIV"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1069
76055
8d56461f85ec moved antimono to Fun and redefined it as an abbreviation
desharna
parents: 76054
diff changeset
  1070
abbreviation antimono :: "('a \<Rightarrow> 'b::order) \<Rightarrow> bool"
8d56461f85ec moved antimono to Fun and redefined it as an abbreviation
desharna
parents: 76054
diff changeset
  1071
  where "antimono \<equiv> monotone (\<le>) (\<lambda>x y. y \<le> x)"
8d56461f85ec moved antimono to Fun and redefined it as an abbreviation
desharna
parents: 76054
diff changeset
  1072
76054
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1073
lemma mono_def[no_atp]: "mono f \<longleftrightarrow> (\<forall>x y. x \<le> y \<longrightarrow> f x \<le> f y)"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1074
  by (simp add: monotone_on_def)
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1075
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1076
lemma strict_mono_def[no_atp]: "strict_mono f \<longleftrightarrow> (\<forall>x y. x < y \<longrightarrow> f x < f y)"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1077
  by (simp add: monotone_on_def)
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1078
76055
8d56461f85ec moved antimono to Fun and redefined it as an abbreviation
desharna
parents: 76054
diff changeset
  1079
lemma antimono_def[no_atp]: "antimono f \<longleftrightarrow> (\<forall>x y. x \<le> y \<longrightarrow> f x \<ge> f y)"
8d56461f85ec moved antimono to Fun and redefined it as an abbreviation
desharna
parents: 76054
diff changeset
  1080
  by (simp add: monotone_on_def)
8d56461f85ec moved antimono to Fun and redefined it as an abbreviation
desharna
parents: 76054
diff changeset
  1081
8d56461f85ec moved antimono to Fun and redefined it as an abbreviation
desharna
parents: 76054
diff changeset
  1082
text \<open>Lemmas @{thm [source] mono_def}, @{thm [source] strict_mono_def}, and
8d56461f85ec moved antimono to Fun and redefined it as an abbreviation
desharna
parents: 76054
diff changeset
  1083
@{thm [source] antimono_def} are provided for backward compatibility.\<close>
76054
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1084
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1085
lemma monoI [intro?]: "(\<And>x y. x \<le> y \<Longrightarrow> f x \<le> f y) \<Longrightarrow> mono f"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1086
  by (rule monotoneI)
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1087
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1088
lemma strict_monoI [intro?]: "(\<And>x y. x < y \<Longrightarrow> f x < f y) \<Longrightarrow> strict_mono f"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1089
  by (rule monotoneI)
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1090
76055
8d56461f85ec moved antimono to Fun and redefined it as an abbreviation
desharna
parents: 76054
diff changeset
  1091
lemma antimonoI [intro?]: "(\<And>x y. x \<le> y \<Longrightarrow> f x \<ge> f y) \<Longrightarrow> antimono f"
8d56461f85ec moved antimono to Fun and redefined it as an abbreviation
desharna
parents: 76054
diff changeset
  1092
  by (rule monotoneI)
8d56461f85ec moved antimono to Fun and redefined it as an abbreviation
desharna
parents: 76054
diff changeset
  1093
76054
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1094
lemma monoD [dest?]: "mono f \<Longrightarrow> x \<le> y \<Longrightarrow> f x \<le> f y"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1095
  by (rule monotoneD)
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1096
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1097
lemma strict_monoD [dest?]: "strict_mono f \<Longrightarrow> x < y \<Longrightarrow> f x < f y"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1098
  by (rule monotoneD)
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1099
76055
8d56461f85ec moved antimono to Fun and redefined it as an abbreviation
desharna
parents: 76054
diff changeset
  1100
lemma antimonoD [dest?]: "antimono f \<Longrightarrow> x \<le> y \<Longrightarrow> f x \<ge> f y"
8d56461f85ec moved antimono to Fun and redefined it as an abbreviation
desharna
parents: 76054
diff changeset
  1101
  by (rule monotoneD)
8d56461f85ec moved antimono to Fun and redefined it as an abbreviation
desharna
parents: 76054
diff changeset
  1102
76054
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1103
lemma monoE:
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1104
  assumes "mono f"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1105
  assumes "x \<le> y"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1106
  obtains "f x \<le> f y"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1107
proof
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1108
  from assms show "f x \<le> f y" by (simp add: mono_def)
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1109
qed
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1110
76055
8d56461f85ec moved antimono to Fun and redefined it as an abbreviation
desharna
parents: 76054
diff changeset
  1111
lemma antimonoE:
8d56461f85ec moved antimono to Fun and redefined it as an abbreviation
desharna
parents: 76054
diff changeset
  1112
  fixes f :: "'a \<Rightarrow> 'b::order"
8d56461f85ec moved antimono to Fun and redefined it as an abbreviation
desharna
parents: 76054
diff changeset
  1113
  assumes "antimono f"
8d56461f85ec moved antimono to Fun and redefined it as an abbreviation
desharna
parents: 76054
diff changeset
  1114
  assumes "x \<le> y"
8d56461f85ec moved antimono to Fun and redefined it as an abbreviation
desharna
parents: 76054
diff changeset
  1115
  obtains "f x \<ge> f y"
8d56461f85ec moved antimono to Fun and redefined it as an abbreviation
desharna
parents: 76054
diff changeset
  1116
proof
8d56461f85ec moved antimono to Fun and redefined it as an abbreviation
desharna
parents: 76054
diff changeset
  1117
  from assms show "f x \<ge> f y" by (simp add: antimono_def)
8d56461f85ec moved antimono to Fun and redefined it as an abbreviation
desharna
parents: 76054
diff changeset
  1118
qed
8d56461f85ec moved antimono to Fun and redefined it as an abbreviation
desharna
parents: 76054
diff changeset
  1119
76054
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1120
lemma mono_imp_mono_on: "mono f \<Longrightarrow> mono_on A f"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1121
  by (rule monotone_on_subset[OF _ subset_UNIV])
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1122
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1123
lemma strict_mono_mono [dest?]:
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1124
  assumes "strict_mono f"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1125
  shows "mono f"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1126
proof (rule monoI)
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1127
  fix x y
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1128
  assume "x \<le> y"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1129
  show "f x \<le> f y"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1130
  proof (cases "x = y")
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1131
    case True then show ?thesis by simp
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1132
  next
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1133
    case False with \<open>x \<le> y\<close> have "x < y" by simp
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1134
    with assms strict_monoD have "f x < f y" by auto
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1135
    then show ?thesis by simp
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1136
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1137
  qed
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1138
qed
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1139
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1140
end
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1141
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1142
context linorder begin
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1143
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1144
lemma mono_invE:
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1145
  fixes f :: "'a \<Rightarrow> 'b::order"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1146
  assumes "mono f"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1147
  assumes "f x < f y"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1148
  obtains "x \<le> y"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1149
proof
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1150
  show "x \<le> y"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1151
  proof (rule ccontr)
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1152
    assume "\<not> x \<le> y"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1153
    then have "y \<le> x" by simp
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1154
    with \<open>mono f\<close> obtain "f y \<le> f x" by (rule monoE)
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1155
    with \<open>f x < f y\<close> show False by simp
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1156
  qed
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1157
qed
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1158
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1159
lemma mono_strict_invE:
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1160
  fixes f :: "'a \<Rightarrow> 'b::order"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1161
  assumes "mono f"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1162
  assumes "f x < f y"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1163
  obtains "x < y"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1164
proof
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1165
  show "x < y"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1166
  proof (rule ccontr)
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1167
    assume "\<not> x < y"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1168
    then have "y \<le> x" by simp
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1169
    with \<open>mono f\<close> obtain "f y \<le> f x" by (rule monoE)
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1170
    with \<open>f x < f y\<close> show False by simp
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1171
  qed
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1172
qed
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1173
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1174
lemma strict_mono_eq:
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1175
  assumes "strict_mono f"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1176
  shows "f x = f y \<longleftrightarrow> x = y"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1177
proof
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1178
  assume "f x = f y"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1179
  show "x = y" proof (cases x y rule: linorder_cases)
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1180
    case less with assms strict_monoD have "f x < f y" by auto
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1181
    with \<open>f x = f y\<close> show ?thesis by simp
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1182
  next
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1183
    case equal then show ?thesis .
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1184
  next
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1185
    case greater with assms strict_monoD have "f y < f x" by auto
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1186
    with \<open>f x = f y\<close> show ?thesis by simp
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1187
  qed
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1188
qed simp
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1189
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1190
lemma strict_mono_less_eq:
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1191
  assumes "strict_mono f"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1192
  shows "f x \<le> f y \<longleftrightarrow> x \<le> y"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1193
proof
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1194
  assume "x \<le> y"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1195
  with assms strict_mono_mono monoD show "f x \<le> f y" by auto
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1196
next
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1197
  assume "f x \<le> f y"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1198
  show "x \<le> y" proof (rule ccontr)
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1199
    assume "\<not> x \<le> y" then have "y < x" by simp
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1200
    with assms strict_monoD have "f y < f x" by auto
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1201
    with \<open>f x \<le> f y\<close> show False by simp
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1202
  qed
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1203
qed
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1204
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1205
lemma strict_mono_less:
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1206
  assumes "strict_mono f"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1207
  shows "f x < f y \<longleftrightarrow> x < y"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1208
  using assms
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1209
    by (auto simp add: less_le Orderings.less_le strict_mono_eq strict_mono_less_eq)
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1210
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1211
end
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1212
71472
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1213
lemma strict_mono_inv:
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1214
  fixes f :: "('a::linorder) \<Rightarrow> ('b::linorder)"
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1215
  assumes "strict_mono f" and "surj f" and inv: "\<And>x. g (f x) = x"
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1216
  shows "strict_mono g"
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1217
proof
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1218
  fix x y :: 'b assume "x < y"
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1219
  from \<open>surj f\<close> obtain x' y' where [simp]: "x = f x'" "y = f y'" by blast
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1220
  with \<open>x < y\<close> and \<open>strict_mono f\<close> have "x' < y'" by (simp add: strict_mono_less)
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1221
  with inv show "g x < g y" by simp
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1222
qed
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1223
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1224
lemma strict_mono_on_imp_inj_on:
75607
3c544d64c218 changed argument order of mono_on and strict_mono_on to uniformize with monotone_on and other predicates
desharna
parents: 75583
diff changeset
  1225
  assumes "strict_mono_on A (f :: (_ :: linorder) \<Rightarrow> (_ :: preorder))"
71472
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1226
  shows "inj_on f A"
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1227
proof (rule inj_onI)
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1228
  fix x y assume "x \<in> A" "y \<in> A" "f x = f y"
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1229
  thus "x = y"
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1230
    by (cases x y rule: linorder_cases)
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1231
       (auto dest: strict_mono_onD[OF assms, of x y] strict_mono_onD[OF assms, of y x])
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1232
qed
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1233
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1234
lemma strict_mono_on_leD:
75607
3c544d64c218 changed argument order of mono_on and strict_mono_on to uniformize with monotone_on and other predicates
desharna
parents: 75583
diff changeset
  1235
  assumes "strict_mono_on A (f :: (_ :: linorder) \<Rightarrow> _ :: preorder)" "x \<in> A" "y \<in> A" "x \<le> y"
71472
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1236
  shows "f x \<le> f y"
75669
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
  1237
proof (cases "x = y")
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
  1238
  case True
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
  1239
  then show ?thesis by simp
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
  1240
next
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
  1241
  case False
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
  1242
  with assms have "f x < f y"
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
  1243
    using strict_mono_onD[OF assms(1)] by simp
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
  1244
  then show ?thesis by (rule less_imp_le)
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
  1245
qed
71472
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1246
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1247
lemma strict_mono_on_eqD:
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1248
  fixes f :: "(_ :: linorder) \<Rightarrow> (_ :: preorder)"
75607
3c544d64c218 changed argument order of mono_on and strict_mono_on to uniformize with monotone_on and other predicates
desharna
parents: 75583
diff changeset
  1249
  assumes "strict_mono_on A f" "f x = f y" "x \<in> A" "y \<in> A"
71472
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1250
  shows "y = x"
75669
43f5dfb7fa35 tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents: 75624
diff changeset
  1251
  using assms by (cases rule: linorder_cases) (auto dest: strict_mono_onD)
71472
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1252
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1253
lemma strict_mono_on_imp_mono_on:
75607
3c544d64c218 changed argument order of mono_on and strict_mono_on to uniformize with monotone_on and other predicates
desharna
parents: 75583
diff changeset
  1254
  "strict_mono_on A (f :: (_ :: linorder) \<Rightarrow> _ :: preorder) \<Longrightarrow> mono_on A f"
71472
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1255
  by (rule mono_onI, rule strict_mono_on_leD)
c213d067e60f Moved a number of general-purpose lemmas into HOL
paulson <lp15@cam.ac.uk>
parents: 71464
diff changeset
  1256
76054
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1257
lemma mono_compose: "mono Q \<Longrightarrow> mono (\<lambda>i x. Q i (f x))"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1258
  unfolding mono_def le_fun_def by auto
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1259
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1260
lemma mono_add:
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1261
  fixes a :: "'a::ordered_ab_semigroup_add" 
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1262
  shows "mono ((+) a)"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1263
  by (simp add: add_left_mono monoI)
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1264
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1265
lemma (in semilattice_inf) mono_inf: "mono f \<Longrightarrow> f (A \<sqinter> B) \<le> f A \<sqinter> f B"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1266
  for f :: "'a \<Rightarrow> 'b::semilattice_inf"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1267
  by (auto simp add: mono_def intro: Lattices.inf_greatest)
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1268
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1269
lemma (in semilattice_sup) mono_sup: "mono f \<Longrightarrow> f A \<squnion> f B \<le> f (A \<squnion> B)"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1270
  for f :: "'a \<Rightarrow> 'b::semilattice_sup"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1271
  by (auto simp add: mono_def intro: Lattices.sup_least)
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1272
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1273
lemma (in linorder) min_of_mono: "mono f \<Longrightarrow> min (f m) (f n) = f (min m n)"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1274
  by (auto simp: mono_def Orderings.min_def min_def intro: Orderings.antisym)
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1275
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1276
lemma (in linorder) max_of_mono: "mono f \<Longrightarrow> max (f m) (f n) = f (max m n)"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1277
  by (auto simp: mono_def Orderings.max_def max_def intro: Orderings.antisym)
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1278
76055
8d56461f85ec moved antimono to Fun and redefined it as an abbreviation
desharna
parents: 76054
diff changeset
  1279
lemma (in linorder)
8d56461f85ec moved antimono to Fun and redefined it as an abbreviation
desharna
parents: 76054
diff changeset
  1280
  max_of_antimono: "antimono f \<Longrightarrow> max (f x) (f y) = f (min x y)" and
8d56461f85ec moved antimono to Fun and redefined it as an abbreviation
desharna
parents: 76054
diff changeset
  1281
  min_of_antimono: "antimono f \<Longrightarrow> min (f x) (f y) = f (max x y)"
8d56461f85ec moved antimono to Fun and redefined it as an abbreviation
desharna
parents: 76054
diff changeset
  1282
  by (auto simp: antimono_def Orderings.max_def max_def Orderings.min_def min_def intro!: antisym)
8d56461f85ec moved antimono to Fun and redefined it as an abbreviation
desharna
parents: 76054
diff changeset
  1283
76054
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1284
lemma (in linorder) strict_mono_imp_inj_on: "strict_mono f \<Longrightarrow> inj_on f A"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1285
  by (auto intro!: inj_onI dest: strict_mono_eq)
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1286
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1287
lemma mono_Int: "mono f \<Longrightarrow> f (A \<inter> B) \<subseteq> f A \<inter> f B"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1288
  by (fact mono_inf)
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1289
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1290
lemma mono_Un: "mono f \<Longrightarrow> f A \<union> f B \<subseteq> f (A \<union> B)"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1291
  by (fact mono_sup)
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1292
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1293
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1294
subsubsection \<open>Least value operator\<close>
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1295
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1296
lemma Least_mono: "mono f \<Longrightarrow> \<exists>x\<in>S. \<forall>y\<in>S. x \<le> y \<Longrightarrow> (LEAST y. y \<in> f ` S) = f (LEAST x. x \<in> S)"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1297
  for f :: "'a::order \<Rightarrow> 'b::order"
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1298
  \<comment> \<open>Courtesy of Stephan Merz\<close>
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1299
  apply clarify
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1300
  apply (erule_tac P = "\<lambda>x. x \<in> S" in LeastI2_order)
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1301
   apply fast
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1302
  apply (rule LeastI2_order)
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1303
    apply (auto elim: monoD intro!: order_antisym)
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1304
  done
a4b47c684445 moved mono and strict_mono to Fun and redefined them as abbreviations
desharna
parents: 75624
diff changeset
  1305
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
  1306
61204
3e491e34a62e new lemmas and movement of lemmas into place
paulson
parents: 60929
diff changeset
  1307
subsection \<open>Setup\<close>
40969
fb2d3ccda5a7 moved bootstrap of type_lifting to Fun
haftmann
parents: 40968
diff changeset
  1308
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60303
diff changeset
  1309
subsubsection \<open>Proof tools\<close>
22845
5f9138bcb3d7 changed code generator invocation syntax
haftmann
parents: 22744
diff changeset
  1310
63400
249fa34faba2 misc tuning and modernization;
wenzelm
parents: 63365
diff changeset
  1311
text \<open>Simplify terms of the form \<open>f(\<dots>,x:=y,\<dots>,x:=z,\<dots>)\<close> to \<open>f(\<dots>,x:=z,\<dots>)\<close>\<close>
22845
5f9138bcb3d7 changed code generator invocation syntax
haftmann
parents: 22744
diff changeset
  1312
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60303
diff changeset
  1313
simproc_setup fun_upd2 ("f(v := w, x := y)") = \<open>fn _ =>
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
  1314
  let
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
  1315
    fun gen_fun_upd NONE T _ _ = NONE
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69502
diff changeset
  1316
      | gen_fun_upd (SOME f) T x y = SOME (Const (\<^const_name>\<open>fun_upd\<close>, T) $ f $ x $ y)
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
  1317
    fun dest_fun_T1 (Type (_, T :: Ts)) = T
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69502
diff changeset
  1318
    fun find_double (t as Const (\<^const_name>\<open>fun_upd\<close>,T) $ f $ x $ y) =
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
  1319
      let
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69502
diff changeset
  1320
        fun find (Const (\<^const_name>\<open>fun_upd\<close>,T) $ g $ v $ w) =
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
  1321
              if v aconv x then SOME g else gen_fun_upd (find g) T v w
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
  1322
          | find t = NONE
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
  1323
      in (dest_fun_T1 T, gen_fun_upd (find f) T x y) end
24017
363287741ebe simproc_setup fun_upd2;
wenzelm
parents: 23878
diff changeset
  1324
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69502
diff changeset
  1325
    val ss = simpset_of \<^context>
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51598
diff changeset
  1326
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
  1327
    fun proc ctxt ct =
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
  1328
      let
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
  1329
        val t = Thm.term_of ct
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
  1330
      in
63400
249fa34faba2 misc tuning and modernization;
wenzelm
parents: 63365
diff changeset
  1331
        (case find_double t of
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
  1332
          (T, NONE) => NONE
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
  1333
        | (T, SOME rhs) =>
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
  1334
            SOME (Goal.prove ctxt [] [] (Logic.mk_equals (t, rhs))
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
  1335
              (fn _ =>
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
  1336
                resolve_tac ctxt [eq_reflection] 1 THEN
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
  1337
                resolve_tac ctxt @{thms ext} 1 THEN
63400
249fa34faba2 misc tuning and modernization;
wenzelm
parents: 63365
diff changeset
  1338
                simp_tac (put_simpset ss ctxt) 1)))
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
  1339
      end
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
  1340
  in proc end
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60303
diff changeset
  1341
\<close>
22845
5f9138bcb3d7 changed code generator invocation syntax
haftmann
parents: 22744
diff changeset
  1342
5f9138bcb3d7 changed code generator invocation syntax
haftmann
parents: 22744
diff changeset
  1343
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60303
diff changeset
  1344
subsubsection \<open>Functorial structure of types\<close>
40969
fb2d3ccda5a7 moved bootstrap of type_lifting to Fun
haftmann
parents: 40968
diff changeset
  1345
69605
a96320074298 isabelle update -u path_cartouches;
wenzelm
parents: 69593
diff changeset
  1346
ML_file \<open>Tools/functor.ML\<close>
40969
fb2d3ccda5a7 moved bootstrap of type_lifting to Fun
haftmann
parents: 40968
diff changeset
  1347
55467
a5c9002bc54d renamed 'enriched_type' to more informative 'functor' (following the renaming of enriched type constructors to bounded natural functors)
blanchet
parents: 55414
diff changeset
  1348
functor map_fun: map_fun
47488
be6dd389639d centralized enriched_type declaration, thanks to in-situ available Isar commands
haftmann
parents: 46950
diff changeset
  1349
  by (simp_all add: fun_eq_iff)
be6dd389639d centralized enriched_type declaration, thanks to in-situ available Isar commands
haftmann
parents: 46950
diff changeset
  1350
55467
a5c9002bc54d renamed 'enriched_type' to more informative 'functor' (following the renaming of enriched type constructors to bounded natural functors)
blanchet
parents: 55414
diff changeset
  1351
functor vimage
49739
13aa6d8268ec consolidated names of theorems on composition;
haftmann
parents: 48891
diff changeset
  1352
  by (simp_all add: fun_eq_iff vimage_comp)
13aa6d8268ec consolidated names of theorems on composition;
haftmann
parents: 48891
diff changeset
  1353
63322
bc1f17d45e91 misc tuning and modernization;
wenzelm
parents: 63072
diff changeset
  1354
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60303
diff changeset
  1355
text \<open>Legacy theorem names\<close>
49739
13aa6d8268ec consolidated names of theorems on composition;
haftmann
parents: 48891
diff changeset
  1356
13aa6d8268ec consolidated names of theorems on composition;
haftmann
parents: 48891
diff changeset
  1357
lemmas o_def = comp_def
13aa6d8268ec consolidated names of theorems on composition;
haftmann
parents: 48891
diff changeset
  1358
lemmas o_apply = comp_apply
13aa6d8268ec consolidated names of theorems on composition;
haftmann
parents: 48891
diff changeset
  1359
lemmas o_assoc = comp_assoc [symmetric]
13aa6d8268ec consolidated names of theorems on composition;
haftmann
parents: 48891
diff changeset
  1360
lemmas id_o = id_comp
13aa6d8268ec consolidated names of theorems on composition;
haftmann
parents: 48891
diff changeset
  1361
lemmas o_id = comp_id
13aa6d8268ec consolidated names of theorems on composition;
haftmann
parents: 48891
diff changeset
  1362
lemmas o_eq_dest = comp_eq_dest
13aa6d8268ec consolidated names of theorems on composition;
haftmann
parents: 48891
diff changeset
  1363
lemmas o_eq_elim = comp_eq_elim
55066
blanchet
parents: 55019
diff changeset
  1364
lemmas o_eq_dest_lhs = comp_eq_dest_lhs
blanchet
parents: 55019
diff changeset
  1365
lemmas o_eq_id_dest = comp_eq_id_dest
47488
be6dd389639d centralized enriched_type declaration, thanks to in-situ available Isar commands
haftmann
parents: 46950
diff changeset
  1366
2912
3fac3e8d5d3e moved inj and surj from Set to Fun and Inv -> inv.
nipkow
parents: 1475
diff changeset
  1367
end