| author | haftmann | 
| Mon, 16 Nov 2009 10:16:40 +0100 | |
| changeset 33708 | b45d3b8cc74e | 
| parent 33552 | 506f80a9afe8 | 
| child 33756 | 47b7c9e0bf6e | 
| permissions | -rw-r--r-- | 
| 923 | 1 | (* Title: HOL/HOL.thy | 
| 11750 | 2 | Author: Tobias Nipkow, Markus Wenzel, and Larry Paulson | 
| 3 | *) | |
| 923 | 4 | |
| 11750 | 5 | header {* The basis of Higher-Order Logic *}
 | 
| 923 | 6 | |
| 15131 | 7 | theory HOL | 
| 30929 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 8 | imports Pure "~~/src/Tools/Code_Generator" | 
| 23163 | 9 | uses | 
| 28952 
15a4b2cf8c34
made repository layout more coherent with logical distribution structure; stripped some $Id$s
 haftmann parents: 
28856diff
changeset | 10 |   ("Tools/hologic.ML")
 | 
| 30980 | 11 | "~~/src/Tools/auto_solve.ML" | 
| 23171 | 12 | "~~/src/Tools/IsaPlanner/zipper.ML" | 
| 13 | "~~/src/Tools/IsaPlanner/isand.ML" | |
| 14 | "~~/src/Tools/IsaPlanner/rw_tools.ML" | |
| 15 | "~~/src/Tools/IsaPlanner/rw_inst.ML" | |
| 30165 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: 
30160diff
changeset | 16 | "~~/src/Tools/intuitionistic.ML" | 
| 30160 
5f7b17941730
moved some generic tools to src/Tools/ -- src/Provers is essentially obsolete;
 wenzelm parents: 
30063diff
changeset | 17 | "~~/src/Tools/project_rule.ML" | 
| 32733 
71618deaf777
moved generic cong_tac from HOL/Tools/datatype_aux.ML to Tools/cong_tac.ML, proper subgoal selection (failure, not exception);
 wenzelm parents: 
32668diff
changeset | 18 | "~~/src/Tools/cong_tac.ML" | 
| 23263 | 19 | "~~/src/Provers/hypsubst.ML" | 
| 20 | "~~/src/Provers/splitter.ML" | |
| 23163 | 21 | "~~/src/Provers/classical.ML" | 
| 22 | "~~/src/Provers/blast.ML" | |
| 23 | "~~/src/Provers/clasimp.ML" | |
| 30160 
5f7b17941730
moved some generic tools to src/Tools/ -- src/Provers is essentially obsolete;
 wenzelm parents: 
30063diff
changeset | 24 | "~~/src/Tools/coherent.ML" | 
| 
5f7b17941730
moved some generic tools to src/Tools/ -- src/Provers is essentially obsolete;
 wenzelm parents: 
30063diff
changeset | 25 | "~~/src/Tools/eqsubst.ML" | 
| 23163 | 26 | "~~/src/Provers/quantifier1.ML" | 
| 33308 
cf62d1690d04
separate ResBlacklist, based on scalable persistent data -- avoids inefficient hashing later on;
 wenzelm parents: 
33185diff
changeset | 27 | "Tools/res_blacklist.ML" | 
| 28952 
15a4b2cf8c34
made repository layout more coherent with logical distribution structure; stripped some $Id$s
 haftmann parents: 
28856diff
changeset | 28 |   ("Tools/simpdata.ML")
 | 
| 25741 | 29 | "~~/src/Tools/random_word.ML" | 
| 26580 
c3e597a476fd
Generic conversion and tactic "atomize_elim" to convert elimination rules
 krauss parents: 
26555diff
changeset | 30 | "~~/src/Tools/atomize_elim.ML" | 
| 24901 
d3cbf79769b9
added first version of user-space type system for class target
 haftmann parents: 
24844diff
changeset | 31 | "~~/src/Tools/induct.ML" | 
| 27326 
d3beec370964
moved src/HOL/Tools/induct_tacs.ML to src/Tools/induct_tacs.ML;
 wenzelm parents: 
27212diff
changeset | 32 |   ("~~/src/Tools/induct_tacs.ML")
 | 
| 29505 | 33 |   ("Tools/recfun_codegen.ML")
 | 
| 32402 | 34 | "~~/src/Tools/more_conv.ML" | 
| 15131 | 35 | begin | 
| 2260 | 36 | |
| 31299 | 37 | setup {* Intuitionistic.method_setup @{binding iprover} *}
 | 
| 33316 | 38 | |
| 39 | setup Res_Blacklist.setup | |
| 30165 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: 
30160diff
changeset | 40 | |
| 
6ee87f67d9cd
moved generic intuitionistic prover to src/Tools/intuitionistic.ML;
 wenzelm parents: 
30160diff
changeset | 41 | |
| 11750 | 42 | subsection {* Primitive logic *}
 | 
| 43 | ||
| 44 | subsubsection {* Core syntax *}
 | |
| 2260 | 45 | |
| 14854 | 46 | classes type | 
| 12338 
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
 wenzelm parents: 
12281diff
changeset | 47 | defaultsort type | 
| 25494 
b2484a7912ac
replaced typedecl interpretation by ObjectLogic.typedecl (based on base_sort);
 wenzelm parents: 
25460diff
changeset | 48 | setup {* ObjectLogic.add_base_sort @{sort type} *}
 | 
| 25460 
b80087af2274
interpretation of typedecls: instantiation to class type
 haftmann parents: 
25388diff
changeset | 49 | |
| 
b80087af2274
interpretation of typedecls: instantiation to class type
 haftmann parents: 
25388diff
changeset | 50 | arities | 
| 
b80087af2274
interpretation of typedecls: instantiation to class type
 haftmann parents: 
25388diff
changeset | 51 | "fun" :: (type, type) type | 
| 
b80087af2274
interpretation of typedecls: instantiation to class type
 haftmann parents: 
25388diff
changeset | 52 | itself :: (type) type | 
| 
b80087af2274
interpretation of typedecls: instantiation to class type
 haftmann parents: 
25388diff
changeset | 53 | |
| 12338 
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
 wenzelm parents: 
12281diff
changeset | 54 | global | 
| 923 | 55 | |
| 7357 | 56 | typedecl bool | 
| 923 | 57 | |
| 11750 | 58 | judgment | 
| 59 |   Trueprop      :: "bool => prop"                   ("(_)" 5)
 | |
| 923 | 60 | |
| 11750 | 61 | consts | 
| 7357 | 62 |   Not           :: "bool => bool"                   ("~ _" [40] 40)
 | 
| 63 | True :: bool | |
| 64 | False :: bool | |
| 923 | 65 | |
| 11432 
8a203ae6efe3
added "The" (definite description operator) (by Larry);
 wenzelm parents: 
10489diff
changeset | 66 |   The           :: "('a => bool) => 'a"
 | 
| 7357 | 67 |   All           :: "('a => bool) => bool"           (binder "ALL " 10)
 | 
| 68 |   Ex            :: "('a => bool) => bool"           (binder "EX " 10)
 | |
| 69 |   Ex1           :: "('a => bool) => bool"           (binder "EX! " 10)
 | |
| 70 | Let :: "['a, 'a => 'b] => 'b" | |
| 923 | 71 | |
| 22839 | 72 | "op =" :: "['a, 'a] => bool" (infixl "=" 50) | 
| 73 | "op &" :: "[bool, bool] => bool" (infixr "&" 35) | |
| 74 | "op |" :: "[bool, bool] => bool" (infixr "|" 30) | |
| 75 | "op -->" :: "[bool, bool] => bool" (infixr "-->" 25) | |
| 923 | 76 | |
| 10432 
3dfbc913d184
added axclass inverse and consts inverse, divide (infix "/");
 wenzelm parents: 
10383diff
changeset | 77 | local | 
| 
3dfbc913d184
added axclass inverse and consts inverse, divide (infix "/");
 wenzelm parents: 
10383diff
changeset | 78 | |
| 16587 | 79 | consts | 
| 80 |   If            :: "[bool, 'a, 'a] => 'a"           ("(if (_)/ then (_)/ else (_))" 10)
 | |
| 2260 | 81 | |
| 19656 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 wenzelm parents: 
19607diff
changeset | 82 | |
| 11750 | 83 | subsubsection {* Additional concrete syntax *}
 | 
| 2260 | 84 | |
| 21210 | 85 | notation (output) | 
| 19656 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 wenzelm parents: 
19607diff
changeset | 86 | "op =" (infix "=" 50) | 
| 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 wenzelm parents: 
19607diff
changeset | 87 | |
| 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 wenzelm parents: 
19607diff
changeset | 88 | abbreviation | 
| 21404 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 wenzelm parents: 
21250diff
changeset | 89 | not_equal :: "['a, 'a] => bool" (infixl "~=" 50) where | 
| 19656 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 wenzelm parents: 
19607diff
changeset | 90 | "x ~= y == ~ (x = y)" | 
| 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 wenzelm parents: 
19607diff
changeset | 91 | |
| 21210 | 92 | notation (output) | 
| 19656 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 wenzelm parents: 
19607diff
changeset | 93 | not_equal (infix "~=" 50) | 
| 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 wenzelm parents: 
19607diff
changeset | 94 | |
| 21210 | 95 | notation (xsymbols) | 
| 21404 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 wenzelm parents: 
21250diff
changeset | 96 |   Not  ("\<not> _" [40] 40) and
 | 
| 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 wenzelm parents: 
21250diff
changeset | 97 | "op &" (infixr "\<and>" 35) and | 
| 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 wenzelm parents: 
21250diff
changeset | 98 | "op |" (infixr "\<or>" 30) and | 
| 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 wenzelm parents: 
21250diff
changeset | 99 | "op -->" (infixr "\<longrightarrow>" 25) and | 
| 19656 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 wenzelm parents: 
19607diff
changeset | 100 | not_equal (infix "\<noteq>" 50) | 
| 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 wenzelm parents: 
19607diff
changeset | 101 | |
| 21210 | 102 | notation (HTML output) | 
| 21404 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 wenzelm parents: 
21250diff
changeset | 103 |   Not  ("\<not> _" [40] 40) and
 | 
| 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 wenzelm parents: 
21250diff
changeset | 104 | "op &" (infixr "\<and>" 35) and | 
| 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 wenzelm parents: 
21250diff
changeset | 105 | "op |" (infixr "\<or>" 30) and | 
| 19656 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 wenzelm parents: 
19607diff
changeset | 106 | not_equal (infix "\<noteq>" 50) | 
| 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 wenzelm parents: 
19607diff
changeset | 107 | |
| 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 wenzelm parents: 
19607diff
changeset | 108 | abbreviation (iff) | 
| 21404 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 wenzelm parents: 
21250diff
changeset | 109 | iff :: "[bool, bool] => bool" (infixr "<->" 25) where | 
| 19656 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 wenzelm parents: 
19607diff
changeset | 110 | "A <-> B == A = B" | 
| 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 wenzelm parents: 
19607diff
changeset | 111 | |
| 21210 | 112 | notation (xsymbols) | 
| 19656 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 wenzelm parents: 
19607diff
changeset | 113 | iff (infixr "\<longleftrightarrow>" 25) | 
| 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 wenzelm parents: 
19607diff
changeset | 114 | |
| 4868 | 115 | nonterminals | 
| 923 | 116 | letbinds letbind | 
| 117 | case_syn cases_syn | |
| 118 | ||
| 119 | syntax | |
| 11432 
8a203ae6efe3
added "The" (definite description operator) (by Larry);
 wenzelm parents: 
10489diff
changeset | 120 |   "_The"        :: "[pttrn, bool] => 'a"                 ("(3THE _./ _)" [0, 10] 10)
 | 
| 923 | 121 | |
| 7357 | 122 |   "_bind"       :: "[pttrn, 'a] => letbind"              ("(2_ =/ _)" 10)
 | 
| 123 |   ""            :: "letbind => letbinds"                 ("_")
 | |
| 124 |   "_binds"      :: "[letbind, letbinds] => letbinds"     ("_;/ _")
 | |
| 125 |   "_Let"        :: "[letbinds, 'a] => 'a"                ("(let (_)/ in (_))" 10)
 | |
| 923 | 126 | |
| 9060 
b0dd884b1848
rename @case to _case_syntax (improves on low-level errors);
 wenzelm parents: 
8959diff
changeset | 127 |   "_case_syntax":: "['a, cases_syn] => 'b"               ("(case _ of/ _)" 10)
 | 
| 
b0dd884b1848
rename @case to _case_syntax (improves on low-level errors);
 wenzelm parents: 
8959diff
changeset | 128 |   "_case1"      :: "['a, 'b] => case_syn"                ("(2_ =>/ _)" 10)
 | 
| 7357 | 129 |   ""            :: "case_syn => cases_syn"               ("_")
 | 
| 9060 
b0dd884b1848
rename @case to _case_syntax (improves on low-level errors);
 wenzelm parents: 
8959diff
changeset | 130 |   "_case2"      :: "[case_syn, cases_syn] => cases_syn"  ("_/ | _")
 | 
| 923 | 131 | |
| 132 | translations | |
| 13764 | 133 | "THE x. P" == "The (%x. P)" | 
| 923 | 134 | "_Let (_binds b bs) e" == "_Let b (_Let bs e)" | 
| 1114 | 135 | "let x = a in e" == "Let a (%x. e)" | 
| 923 | 136 | |
| 13763 
f94b569cd610
added print translations tha avoid eta contraction for important binders.
 nipkow parents: 
13723diff
changeset | 137 | print_translation {*
 | 
| 
f94b569cd610
added print translations tha avoid eta contraction for important binders.
 nipkow parents: 
13723diff
changeset | 138 | (* To avoid eta-contraction of body: *) | 
| 
f94b569cd610
added print translations tha avoid eta contraction for important binders.
 nipkow parents: 
13723diff
changeset | 139 | [("The", fn [Abs abs] =>
 | 
| 
f94b569cd610
added print translations tha avoid eta contraction for important binders.
 nipkow parents: 
13723diff
changeset | 140 | let val (x,t) = atomic_abs_tr' abs | 
| 
f94b569cd610
added print translations tha avoid eta contraction for important binders.
 nipkow parents: 
13723diff
changeset | 141 | in Syntax.const "_The" $ x $ t end)] | 
| 
f94b569cd610
added print translations tha avoid eta contraction for important binders.
 nipkow parents: 
13723diff
changeset | 142 | *} | 
| 
f94b569cd610
added print translations tha avoid eta contraction for important binders.
 nipkow parents: 
13723diff
changeset | 143 | |
| 12114 
a8e860c86252
eliminated old "symbols" syntax, use "xsymbols" instead;
 wenzelm parents: 
12023diff
changeset | 144 | syntax (xsymbols) | 
| 11687 | 145 |   "_case1"      :: "['a, 'b] => case_syn"                ("(2_ \<Rightarrow>/ _)" 10)
 | 
| 21524 | 146 | |
| 147 | notation (xsymbols) | |
| 148 | All (binder "\<forall>" 10) and | |
| 149 | Ex (binder "\<exists>" 10) and | |
| 150 | Ex1 (binder "\<exists>!" 10) | |
| 2372 | 151 | |
| 21524 | 152 | notation (HTML output) | 
| 153 | All (binder "\<forall>" 10) and | |
| 154 | Ex (binder "\<exists>" 10) and | |
| 155 | Ex1 (binder "\<exists>!" 10) | |
| 6340 | 156 | |
| 21524 | 157 | notation (HOL) | 
| 158 | All (binder "! " 10) and | |
| 159 | Ex (binder "? " 10) and | |
| 160 | Ex1 (binder "?! " 10) | |
| 7238 
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
 wenzelm parents: 
7220diff
changeset | 161 | |
| 
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
 wenzelm parents: 
7220diff
changeset | 162 | |
| 11750 | 163 | subsubsection {* Axioms and basic definitions *}
 | 
| 2260 | 164 | |
| 7357 | 165 | axioms | 
| 15380 | 166 | refl: "t = (t::'a)" | 
| 28513 | 167 | subst: "s = t \<Longrightarrow> P s \<Longrightarrow> P t" | 
| 15380 | 168 | ext: "(!!x::'a. (f x ::'b) = g x) ==> (%x. f x) = (%x. g x)" | 
| 169 |     -- {*Extensionality is built into the meta-logic, and this rule expresses
 | |
| 170 | a related property. It is an eta-expanded version of the traditional | |
| 171 | rule, and similar to the ABS rule of HOL*} | |
| 6289 | 172 | |
| 11432 
8a203ae6efe3
added "The" (definite description operator) (by Larry);
 wenzelm parents: 
10489diff
changeset | 173 | the_eq_trivial: "(THE x. x = a) = (a::'a)" | 
| 923 | 174 | |
| 15380 | 175 | impI: "(P ==> Q) ==> P-->Q" | 
| 176 | mp: "[| P-->Q; P |] ==> Q" | |
| 177 | ||
| 178 | ||
| 923 | 179 | defs | 
| 7357 | 180 | True_def: "True == ((%x::bool. x) = (%x. x))" | 
| 181 | All_def: "All(P) == (P = (%x. True))" | |
| 11451 
8abfb4f7bd02
partial restructuring to reduce dependence on Axiom of Choice
 paulson parents: 
11438diff
changeset | 182 | Ex_def: "Ex(P) == !Q. (!x. P x --> Q) --> Q" | 
| 7357 | 183 | False_def: "False == (!P. P)" | 
| 184 | not_def: "~ P == P-->False" | |
| 185 | and_def: "P & Q == !R. (P-->Q-->R) --> R" | |
| 186 | or_def: "P | Q == !R. (P-->R) --> (Q-->R) --> R" | |
| 187 | Ex1_def: "Ex1(P) == ? x. P(x) & (! y. P(y) --> y=x)" | |
| 923 | 188 | |
| 7357 | 189 | axioms | 
| 190 | iff: "(P-->Q) --> (Q-->P) --> (P=Q)" | |
| 191 | True_or_False: "(P=True) | (P=False)" | |
| 923 | 192 | |
| 193 | defs | |
| 32068 | 194 | Let_def [code]: "Let s f == f(s)" | 
| 195 | if_def: "If P x y == THE z::'a. (P=True --> z=x) & (P=False --> z=y)" | |
| 5069 | 196 | |
| 14223 
0ee05eef881b
Added support for making constants final, that is, ensuring that no
 skalberg parents: 
14208diff
changeset | 197 | finalconsts | 
| 
0ee05eef881b
Added support for making constants final, that is, ensuring that no
 skalberg parents: 
14208diff
changeset | 198 | "op =" | 
| 
0ee05eef881b
Added support for making constants final, that is, ensuring that no
 skalberg parents: 
14208diff
changeset | 199 | "op -->" | 
| 
0ee05eef881b
Added support for making constants final, that is, ensuring that no
 skalberg parents: 
14208diff
changeset | 200 | The | 
| 22481 
79c2724c36b5
added class "default" and expansion axioms for undefined
 haftmann parents: 
22473diff
changeset | 201 | |
| 
79c2724c36b5
added class "default" and expansion axioms for undefined
 haftmann parents: 
22473diff
changeset | 202 | axiomatization | 
| 
79c2724c36b5
added class "default" and expansion axioms for undefined
 haftmann parents: 
22473diff
changeset | 203 | undefined :: 'a | 
| 
79c2724c36b5
added class "default" and expansion axioms for undefined
 haftmann parents: 
22473diff
changeset | 204 | |
| 29608 | 205 | class default = | 
| 24901 
d3cbf79769b9
added first version of user-space type system for class target
 haftmann parents: 
24844diff
changeset | 206 | fixes default :: 'a | 
| 4868 | 207 | |
| 11750 | 208 | |
| 20944 | 209 | subsection {* Fundamental rules *}
 | 
| 210 | ||
| 20973 | 211 | subsubsection {* Equality *}
 | 
| 20944 | 212 | |
| 18457 | 213 | lemma sym: "s = t ==> t = s" | 
| 214 | by (erule subst) (rule refl) | |
| 15411 | 215 | |
| 18457 | 216 | lemma ssubst: "t = s ==> P s ==> P t" | 
| 217 | by (drule sym) (erule subst) | |
| 15411 | 218 | |
| 219 | lemma trans: "[| r=s; s=t |] ==> r=t" | |
| 18457 | 220 | by (erule subst) | 
| 15411 | 221 | |
| 20944 | 222 | lemma meta_eq_to_obj_eq: | 
| 223 | assumes meq: "A == B" | |
| 224 | shows "A = B" | |
| 225 | by (unfold meq) (rule refl) | |
| 15411 | 226 | |
| 21502 | 227 | text {* Useful with @{text erule} for proving equalities from known equalities. *}
 | 
| 20944 | 228 | (* a = b | 
| 15411 | 229 | | | | 
| 230 | c = d *) | |
| 231 | lemma box_equals: "[| a=b; a=c; b=d |] ==> c=d" | |
| 232 | apply (rule trans) | |
| 233 | apply (rule trans) | |
| 234 | apply (rule sym) | |
| 235 | apply assumption+ | |
| 236 | done | |
| 237 | ||
| 15524 
2ef571f80a55
Moved oderings from HOL into the new Orderings.thy
 nipkow parents: 
15481diff
changeset | 238 | text {* For calculational reasoning: *}
 | 
| 
2ef571f80a55
Moved oderings from HOL into the new Orderings.thy
 nipkow parents: 
15481diff
changeset | 239 | |
| 
2ef571f80a55
Moved oderings from HOL into the new Orderings.thy
 nipkow parents: 
15481diff
changeset | 240 | lemma forw_subst: "a = b ==> P b ==> P a" | 
| 
2ef571f80a55
Moved oderings from HOL into the new Orderings.thy
 nipkow parents: 
15481diff
changeset | 241 | by (rule ssubst) | 
| 
2ef571f80a55
Moved oderings from HOL into the new Orderings.thy
 nipkow parents: 
15481diff
changeset | 242 | |
| 
2ef571f80a55
Moved oderings from HOL into the new Orderings.thy
 nipkow parents: 
15481diff
changeset | 243 | lemma back_subst: "P a ==> a = b ==> P b" | 
| 
2ef571f80a55
Moved oderings from HOL into the new Orderings.thy
 nipkow parents: 
15481diff
changeset | 244 | by (rule subst) | 
| 
2ef571f80a55
Moved oderings from HOL into the new Orderings.thy
 nipkow parents: 
15481diff
changeset | 245 | |
| 15411 | 246 | |
| 32733 
71618deaf777
moved generic cong_tac from HOL/Tools/datatype_aux.ML to Tools/cong_tac.ML, proper subgoal selection (failure, not exception);
 wenzelm parents: 
32668diff
changeset | 247 | subsubsection {* Congruence rules for application *}
 | 
| 15411 | 248 | |
| 32733 
71618deaf777
moved generic cong_tac from HOL/Tools/datatype_aux.ML to Tools/cong_tac.ML, proper subgoal selection (failure, not exception);
 wenzelm parents: 
32668diff
changeset | 249 | text {* Similar to @{text AP_THM} in Gordon's HOL. *}
 | 
| 15411 | 250 | lemma fun_cong: "(f::'a=>'b) = g ==> f(x)=g(x)" | 
| 251 | apply (erule subst) | |
| 252 | apply (rule refl) | |
| 253 | done | |
| 254 | ||
| 32733 
71618deaf777
moved generic cong_tac from HOL/Tools/datatype_aux.ML to Tools/cong_tac.ML, proper subgoal selection (failure, not exception);
 wenzelm parents: 
32668diff
changeset | 255 | text {* Similar to @{text AP_TERM} in Gordon's HOL and FOL's @{text subst_context}. *}
 | 
| 15411 | 256 | lemma arg_cong: "x=y ==> f(x)=f(y)" | 
| 257 | apply (erule subst) | |
| 258 | apply (rule refl) | |
| 259 | done | |
| 260 | ||
| 15655 | 261 | lemma arg_cong2: "\<lbrakk> a = b; c = d \<rbrakk> \<Longrightarrow> f a c = f b d" | 
| 262 | apply (erule ssubst)+ | |
| 263 | apply (rule refl) | |
| 264 | done | |
| 265 | ||
| 32733 
71618deaf777
moved generic cong_tac from HOL/Tools/datatype_aux.ML to Tools/cong_tac.ML, proper subgoal selection (failure, not exception);
 wenzelm parents: 
32668diff
changeset | 266 | lemma cong: "[| f = g; (x::'a) = y |] ==> f x = g y" | 
| 15411 | 267 | apply (erule subst)+ | 
| 268 | apply (rule refl) | |
| 269 | done | |
| 270 | ||
| 32733 
71618deaf777
moved generic cong_tac from HOL/Tools/datatype_aux.ML to Tools/cong_tac.ML, proper subgoal selection (failure, not exception);
 wenzelm parents: 
32668diff
changeset | 271 | ML {* val cong_tac = Cong_Tac.cong_tac @{thm cong} *}
 | 
| 15411 | 272 | |
| 32733 
71618deaf777
moved generic cong_tac from HOL/Tools/datatype_aux.ML to Tools/cong_tac.ML, proper subgoal selection (failure, not exception);
 wenzelm parents: 
32668diff
changeset | 273 | |
| 
71618deaf777
moved generic cong_tac from HOL/Tools/datatype_aux.ML to Tools/cong_tac.ML, proper subgoal selection (failure, not exception);
 wenzelm parents: 
32668diff
changeset | 274 | subsubsection {* Equality of booleans -- iff *}
 | 
| 15411 | 275 | |
| 21504 | 276 | lemma iffI: assumes "P ==> Q" and "Q ==> P" shows "P=Q" | 
| 277 | by (iprover intro: iff [THEN mp, THEN mp] impI assms) | |
| 15411 | 278 | |
| 279 | lemma iffD2: "[| P=Q; Q |] ==> P" | |
| 18457 | 280 | by (erule ssubst) | 
| 15411 | 281 | |
| 282 | lemma rev_iffD2: "[| Q; P=Q |] ==> P" | |
| 18457 | 283 | by (erule iffD2) | 
| 15411 | 284 | |
| 21504 | 285 | lemma iffD1: "Q = P \<Longrightarrow> Q \<Longrightarrow> P" | 
| 286 | by (drule sym) (rule iffD2) | |
| 287 | ||
| 288 | lemma rev_iffD1: "Q \<Longrightarrow> Q = P \<Longrightarrow> P" | |
| 289 | by (drule sym) (rule rev_iffD2) | |
| 15411 | 290 | |
| 291 | lemma iffE: | |
| 292 | assumes major: "P=Q" | |
| 21504 | 293 | and minor: "[| P --> Q; Q --> P |] ==> R" | 
| 18457 | 294 | shows R | 
| 295 | by (iprover intro: minor impI major [THEN iffD2] major [THEN iffD1]) | |
| 15411 | 296 | |
| 297 | ||
| 20944 | 298 | subsubsection {*True*}
 | 
| 15411 | 299 | |
| 300 | lemma TrueI: "True" | |
| 21504 | 301 | unfolding True_def by (rule refl) | 
| 15411 | 302 | |
| 21504 | 303 | lemma eqTrueI: "P ==> P = True" | 
| 18457 | 304 | by (iprover intro: iffI TrueI) | 
| 15411 | 305 | |
| 21504 | 306 | lemma eqTrueE: "P = True ==> P" | 
| 307 | by (erule iffD2) (rule TrueI) | |
| 15411 | 308 | |
| 309 | ||
| 20944 | 310 | subsubsection {*Universal quantifier*}
 | 
| 15411 | 311 | |
| 21504 | 312 | lemma allI: assumes "!!x::'a. P(x)" shows "ALL x. P(x)" | 
| 313 | unfolding All_def by (iprover intro: ext eqTrueI assms) | |
| 15411 | 314 | |
| 315 | lemma spec: "ALL x::'a. P(x) ==> P(x)" | |
| 316 | apply (unfold All_def) | |
| 317 | apply (rule eqTrueE) | |
| 318 | apply (erule fun_cong) | |
| 319 | done | |
| 320 | ||
| 321 | lemma allE: | |
| 322 | assumes major: "ALL x. P(x)" | |
| 21504 | 323 | and minor: "P(x) ==> R" | 
| 324 | shows R | |
| 325 | by (iprover intro: minor major [THEN spec]) | |
| 15411 | 326 | |
| 327 | lemma all_dupE: | |
| 328 | assumes major: "ALL x. P(x)" | |
| 21504 | 329 | and minor: "[| P(x); ALL x. P(x) |] ==> R" | 
| 330 | shows R | |
| 331 | by (iprover intro: minor major major [THEN spec]) | |
| 15411 | 332 | |
| 333 | ||
| 21504 | 334 | subsubsection {* False *}
 | 
| 335 | ||
| 336 | text {*
 | |
| 337 |   Depends upon @{text spec}; it is impossible to do propositional
 | |
| 338 | logic before quantifiers! | |
| 339 | *} | |
| 15411 | 340 | |
| 341 | lemma FalseE: "False ==> P" | |
| 21504 | 342 | apply (unfold False_def) | 
| 343 | apply (erule spec) | |
| 344 | done | |
| 15411 | 345 | |
| 21504 | 346 | lemma False_neq_True: "False = True ==> P" | 
| 347 | by (erule eqTrueE [THEN FalseE]) | |
| 15411 | 348 | |
| 349 | ||
| 21504 | 350 | subsubsection {* Negation *}
 | 
| 15411 | 351 | |
| 352 | lemma notI: | |
| 21504 | 353 | assumes "P ==> False" | 
| 15411 | 354 | shows "~P" | 
| 21504 | 355 | apply (unfold not_def) | 
| 356 | apply (iprover intro: impI assms) | |
| 357 | done | |
| 15411 | 358 | |
| 359 | lemma False_not_True: "False ~= True" | |
| 21504 | 360 | apply (rule notI) | 
| 361 | apply (erule False_neq_True) | |
| 362 | done | |
| 15411 | 363 | |
| 364 | lemma True_not_False: "True ~= False" | |
| 21504 | 365 | apply (rule notI) | 
| 366 | apply (drule sym) | |
| 367 | apply (erule False_neq_True) | |
| 368 | done | |
| 15411 | 369 | |
| 370 | lemma notE: "[| ~P; P |] ==> R" | |
| 21504 | 371 | apply (unfold not_def) | 
| 372 | apply (erule mp [THEN FalseE]) | |
| 373 | apply assumption | |
| 374 | done | |
| 15411 | 375 | |
| 21504 | 376 | lemma notI2: "(P \<Longrightarrow> \<not> Pa) \<Longrightarrow> (P \<Longrightarrow> Pa) \<Longrightarrow> \<not> P" | 
| 377 | by (erule notE [THEN notI]) (erule meta_mp) | |
| 15411 | 378 | |
| 379 | ||
| 20944 | 380 | subsubsection {*Implication*}
 | 
| 15411 | 381 | |
| 382 | lemma impE: | |
| 383 | assumes "P-->Q" "P" "Q ==> R" | |
| 384 | shows "R" | |
| 23553 | 385 | by (iprover intro: assms mp) | 
| 15411 | 386 | |
| 387 | (* Reduces Q to P-->Q, allowing substitution in P. *) | |
| 388 | lemma rev_mp: "[| P; P --> Q |] ==> Q" | |
| 17589 | 389 | by (iprover intro: mp) | 
| 15411 | 390 | |
| 391 | lemma contrapos_nn: | |
| 392 | assumes major: "~Q" | |
| 393 | and minor: "P==>Q" | |
| 394 | shows "~P" | |
| 17589 | 395 | by (iprover intro: notI minor major [THEN notE]) | 
| 15411 | 396 | |
| 397 | (*not used at all, but we already have the other 3 combinations *) | |
| 398 | lemma contrapos_pn: | |
| 399 | assumes major: "Q" | |
| 400 | and minor: "P ==> ~Q" | |
| 401 | shows "~P" | |
| 17589 | 402 | by (iprover intro: notI minor major notE) | 
| 15411 | 403 | |
| 404 | lemma not_sym: "t ~= s ==> s ~= t" | |
| 21250 | 405 | by (erule contrapos_nn) (erule sym) | 
| 406 | ||
| 407 | lemma eq_neq_eq_imp_neq: "[| x = a ; a ~= b; b = y |] ==> x ~= y" | |
| 408 | by (erule subst, erule ssubst, assumption) | |
| 15411 | 409 | |
| 410 | (*still used in HOLCF*) | |
| 411 | lemma rev_contrapos: | |
| 412 | assumes pq: "P ==> Q" | |
| 413 | and nq: "~Q" | |
| 414 | shows "~P" | |
| 415 | apply (rule nq [THEN contrapos_nn]) | |
| 416 | apply (erule pq) | |
| 417 | done | |
| 418 | ||
| 20944 | 419 | subsubsection {*Existential quantifier*}
 | 
| 15411 | 420 | |
| 421 | lemma exI: "P x ==> EX x::'a. P x" | |
| 422 | apply (unfold Ex_def) | |
| 17589 | 423 | apply (iprover intro: allI allE impI mp) | 
| 15411 | 424 | done | 
| 425 | ||
| 426 | lemma exE: | |
| 427 | assumes major: "EX x::'a. P(x)" | |
| 428 | and minor: "!!x. P(x) ==> Q" | |
| 429 | shows "Q" | |
| 430 | apply (rule major [unfolded Ex_def, THEN spec, THEN mp]) | |
| 17589 | 431 | apply (iprover intro: impI [THEN allI] minor) | 
| 15411 | 432 | done | 
| 433 | ||
| 434 | ||
| 20944 | 435 | subsubsection {*Conjunction*}
 | 
| 15411 | 436 | |
| 437 | lemma conjI: "[| P; Q |] ==> P&Q" | |
| 438 | apply (unfold and_def) | |
| 17589 | 439 | apply (iprover intro: impI [THEN allI] mp) | 
| 15411 | 440 | done | 
| 441 | ||
| 442 | lemma conjunct1: "[| P & Q |] ==> P" | |
| 443 | apply (unfold and_def) | |
| 17589 | 444 | apply (iprover intro: impI dest: spec mp) | 
| 15411 | 445 | done | 
| 446 | ||
| 447 | lemma conjunct2: "[| P & Q |] ==> Q" | |
| 448 | apply (unfold and_def) | |
| 17589 | 449 | apply (iprover intro: impI dest: spec mp) | 
| 15411 | 450 | done | 
| 451 | ||
| 452 | lemma conjE: | |
| 453 | assumes major: "P&Q" | |
| 454 | and minor: "[| P; Q |] ==> R" | |
| 455 | shows "R" | |
| 456 | apply (rule minor) | |
| 457 | apply (rule major [THEN conjunct1]) | |
| 458 | apply (rule major [THEN conjunct2]) | |
| 459 | done | |
| 460 | ||
| 461 | lemma context_conjI: | |
| 23553 | 462 | assumes "P" "P ==> Q" shows "P & Q" | 
| 463 | by (iprover intro: conjI assms) | |
| 15411 | 464 | |
| 465 | ||
| 20944 | 466 | subsubsection {*Disjunction*}
 | 
| 15411 | 467 | |
| 468 | lemma disjI1: "P ==> P|Q" | |
| 469 | apply (unfold or_def) | |
| 17589 | 470 | apply (iprover intro: allI impI mp) | 
| 15411 | 471 | done | 
| 472 | ||
| 473 | lemma disjI2: "Q ==> P|Q" | |
| 474 | apply (unfold or_def) | |
| 17589 | 475 | apply (iprover intro: allI impI mp) | 
| 15411 | 476 | done | 
| 477 | ||
| 478 | lemma disjE: | |
| 479 | assumes major: "P|Q" | |
| 480 | and minorP: "P ==> R" | |
| 481 | and minorQ: "Q ==> R" | |
| 482 | shows "R" | |
| 17589 | 483 | by (iprover intro: minorP minorQ impI | 
| 15411 | 484 | major [unfolded or_def, THEN spec, THEN mp, THEN mp]) | 
| 485 | ||
| 486 | ||
| 20944 | 487 | subsubsection {*Classical logic*}
 | 
| 15411 | 488 | |
| 489 | lemma classical: | |
| 490 | assumes prem: "~P ==> P" | |
| 491 | shows "P" | |
| 492 | apply (rule True_or_False [THEN disjE, THEN eqTrueE]) | |
| 493 | apply assumption | |
| 494 | apply (rule notI [THEN prem, THEN eqTrueI]) | |
| 495 | apply (erule subst) | |
| 496 | apply assumption | |
| 497 | done | |
| 498 | ||
| 499 | lemmas ccontr = FalseE [THEN classical, standard] | |
| 500 | ||
| 501 | (*notE with premises exchanged; it discharges ~R so that it can be used to | |
| 502 | make elimination rules*) | |
| 503 | lemma rev_notE: | |
| 504 | assumes premp: "P" | |
| 505 | and premnot: "~R ==> ~P" | |
| 506 | shows "R" | |
| 507 | apply (rule ccontr) | |
| 508 | apply (erule notE [OF premnot premp]) | |
| 509 | done | |
| 510 | ||
| 511 | (*Double negation law*) | |
| 512 | lemma notnotD: "~~P ==> P" | |
| 513 | apply (rule classical) | |
| 514 | apply (erule notE) | |
| 515 | apply assumption | |
| 516 | done | |
| 517 | ||
| 518 | lemma contrapos_pp: | |
| 519 | assumes p1: "Q" | |
| 520 | and p2: "~P ==> ~Q" | |
| 521 | shows "P" | |
| 17589 | 522 | by (iprover intro: classical p1 p2 notE) | 
| 15411 | 523 | |
| 524 | ||
| 20944 | 525 | subsubsection {*Unique existence*}
 | 
| 15411 | 526 | |
| 527 | lemma ex1I: | |
| 23553 | 528 | assumes "P a" "!!x. P(x) ==> x=a" | 
| 15411 | 529 | shows "EX! x. P(x)" | 
| 23553 | 530 | by (unfold Ex1_def, iprover intro: assms exI conjI allI impI) | 
| 15411 | 531 | |
| 532 | text{*Sometimes easier to use: the premises have no shared variables.  Safe!*}
 | |
| 533 | lemma ex_ex1I: | |
| 534 | assumes ex_prem: "EX x. P(x)" | |
| 535 | and eq: "!!x y. [| P(x); P(y) |] ==> x=y" | |
| 536 | shows "EX! x. P(x)" | |
| 17589 | 537 | by (iprover intro: ex_prem [THEN exE] ex1I eq) | 
| 15411 | 538 | |
| 539 | lemma ex1E: | |
| 540 | assumes major: "EX! x. P(x)" | |
| 541 | and minor: "!!x. [| P(x); ALL y. P(y) --> y=x |] ==> R" | |
| 542 | shows "R" | |
| 543 | apply (rule major [unfolded Ex1_def, THEN exE]) | |
| 544 | apply (erule conjE) | |
| 17589 | 545 | apply (iprover intro: minor) | 
| 15411 | 546 | done | 
| 547 | ||
| 548 | lemma ex1_implies_ex: "EX! x. P x ==> EX x. P x" | |
| 549 | apply (erule ex1E) | |
| 550 | apply (rule exI) | |
| 551 | apply assumption | |
| 552 | done | |
| 553 | ||
| 554 | ||
| 20944 | 555 | subsubsection {*THE: definite description operator*}
 | 
| 15411 | 556 | |
| 557 | lemma the_equality: | |
| 558 | assumes prema: "P a" | |
| 559 | and premx: "!!x. P x ==> x=a" | |
| 560 | shows "(THE x. P x) = a" | |
| 561 | apply (rule trans [OF _ the_eq_trivial]) | |
| 562 | apply (rule_tac f = "The" in arg_cong) | |
| 563 | apply (rule ext) | |
| 564 | apply (rule iffI) | |
| 565 | apply (erule premx) | |
| 566 | apply (erule ssubst, rule prema) | |
| 567 | done | |
| 568 | ||
| 569 | lemma theI: | |
| 570 | assumes "P a" and "!!x. P x ==> x=a" | |
| 571 | shows "P (THE x. P x)" | |
| 23553 | 572 | by (iprover intro: assms the_equality [THEN ssubst]) | 
| 15411 | 573 | |
| 574 | lemma theI': "EX! x. P x ==> P (THE x. P x)" | |
| 575 | apply (erule ex1E) | |
| 576 | apply (erule theI) | |
| 577 | apply (erule allE) | |
| 578 | apply (erule mp) | |
| 579 | apply assumption | |
| 580 | done | |
| 581 | ||
| 582 | (*Easier to apply than theI: only one occurrence of P*) | |
| 583 | lemma theI2: | |
| 584 | assumes "P a" "!!x. P x ==> x=a" "!!x. P x ==> Q x" | |
| 585 | shows "Q (THE x. P x)" | |
| 23553 | 586 | by (iprover intro: assms theI) | 
| 15411 | 587 | |
| 24553 | 588 | lemma the1I2: assumes "EX! x. P x" "\<And>x. P x \<Longrightarrow> Q x" shows "Q (THE x. P x)" | 
| 589 | by(iprover intro:assms(2) theI2[where P=P and Q=Q] ex1E[OF assms(1)] | |
| 590 | elim:allE impE) | |
| 591 | ||
| 18697 | 592 | lemma the1_equality [elim?]: "[| EX!x. P x; P a |] ==> (THE x. P x) = a" | 
| 15411 | 593 | apply (rule the_equality) | 
| 594 | apply assumption | |
| 595 | apply (erule ex1E) | |
| 596 | apply (erule all_dupE) | |
| 597 | apply (drule mp) | |
| 598 | apply assumption | |
| 599 | apply (erule ssubst) | |
| 600 | apply (erule allE) | |
| 601 | apply (erule mp) | |
| 602 | apply assumption | |
| 603 | done | |
| 604 | ||
| 605 | lemma the_sym_eq_trivial: "(THE y. x=y) = x" | |
| 606 | apply (rule the_equality) | |
| 607 | apply (rule refl) | |
| 608 | apply (erule sym) | |
| 609 | done | |
| 610 | ||
| 611 | ||
| 20944 | 612 | subsubsection {*Classical intro rules for disjunction and existential quantifiers*}
 | 
| 15411 | 613 | |
| 614 | lemma disjCI: | |
| 615 | assumes "~Q ==> P" shows "P|Q" | |
| 616 | apply (rule classical) | |
| 23553 | 617 | apply (iprover intro: assms disjI1 disjI2 notI elim: notE) | 
| 15411 | 618 | done | 
| 619 | ||
| 620 | lemma excluded_middle: "~P | P" | |
| 17589 | 621 | by (iprover intro: disjCI) | 
| 15411 | 622 | |
| 20944 | 623 | text {*
 | 
| 624 | case distinction as a natural deduction rule. | |
| 625 |   Note that @{term "~P"} is the second case, not the first
 | |
| 626 | *} | |
| 27126 
3ede9103de8e
eliminated obsolete case_split_thm -- use case_split;
 wenzelm parents: 
27107diff
changeset | 627 | lemma case_split [case_names True False]: | 
| 15411 | 628 | assumes prem1: "P ==> Q" | 
| 629 | and prem2: "~P ==> Q" | |
| 630 | shows "Q" | |
| 631 | apply (rule excluded_middle [THEN disjE]) | |
| 632 | apply (erule prem2) | |
| 633 | apply (erule prem1) | |
| 634 | done | |
| 27126 
3ede9103de8e
eliminated obsolete case_split_thm -- use case_split;
 wenzelm parents: 
27107diff
changeset | 635 | |
| 15411 | 636 | (*Classical implies (-->) elimination. *) | 
| 637 | lemma impCE: | |
| 638 | assumes major: "P-->Q" | |
| 639 | and minor: "~P ==> R" "Q ==> R" | |
| 640 | shows "R" | |
| 641 | apply (rule excluded_middle [of P, THEN disjE]) | |
| 17589 | 642 | apply (iprover intro: minor major [THEN mp])+ | 
| 15411 | 643 | done | 
| 644 | ||
| 645 | (*This version of --> elimination works on Q before P. It works best for | |
| 646 | those cases in which P holds "almost everywhere". Can't install as | |
| 647 | default: would break old proofs.*) | |
| 648 | lemma impCE': | |
| 649 | assumes major: "P-->Q" | |
| 650 | and minor: "Q ==> R" "~P ==> R" | |
| 651 | shows "R" | |
| 652 | apply (rule excluded_middle [of P, THEN disjE]) | |
| 17589 | 653 | apply (iprover intro: minor major [THEN mp])+ | 
| 15411 | 654 | done | 
| 655 | ||
| 656 | (*Classical <-> elimination. *) | |
| 657 | lemma iffCE: | |
| 658 | assumes major: "P=Q" | |
| 659 | and minor: "[| P; Q |] ==> R" "[| ~P; ~Q |] ==> R" | |
| 660 | shows "R" | |
| 661 | apply (rule major [THEN iffE]) | |
| 17589 | 662 | apply (iprover intro: minor elim: impCE notE) | 
| 15411 | 663 | done | 
| 664 | ||
| 665 | lemma exCI: | |
| 666 | assumes "ALL x. ~P(x) ==> P(a)" | |
| 667 | shows "EX x. P(x)" | |
| 668 | apply (rule ccontr) | |
| 23553 | 669 | apply (iprover intro: assms exI allI notI notE [of "\<exists>x. P x"]) | 
| 15411 | 670 | done | 
| 671 | ||
| 672 | ||
| 12386 | 673 | subsubsection {* Intuitionistic Reasoning *}
 | 
| 674 | ||
| 675 | lemma impE': | |
| 12937 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 wenzelm parents: 
12892diff
changeset | 676 | assumes 1: "P --> Q" | 
| 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 wenzelm parents: 
12892diff
changeset | 677 | and 2: "Q ==> R" | 
| 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 wenzelm parents: 
12892diff
changeset | 678 | and 3: "P --> Q ==> P" | 
| 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 wenzelm parents: 
12892diff
changeset | 679 | shows R | 
| 12386 | 680 | proof - | 
| 681 | from 3 and 1 have P . | |
| 682 | with 1 have Q by (rule impE) | |
| 683 | with 2 show R . | |
| 684 | qed | |
| 685 | ||
| 686 | lemma allE': | |
| 12937 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 wenzelm parents: 
12892diff
changeset | 687 | assumes 1: "ALL x. P x" | 
| 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 wenzelm parents: 
12892diff
changeset | 688 | and 2: "P x ==> ALL x. P x ==> Q" | 
| 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 wenzelm parents: 
12892diff
changeset | 689 | shows Q | 
| 12386 | 690 | proof - | 
| 691 | from 1 have "P x" by (rule spec) | |
| 692 | from this and 1 show Q by (rule 2) | |
| 693 | qed | |
| 694 | ||
| 12937 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 wenzelm parents: 
12892diff
changeset | 695 | lemma notE': | 
| 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 wenzelm parents: 
12892diff
changeset | 696 | assumes 1: "~ P" | 
| 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 wenzelm parents: 
12892diff
changeset | 697 | and 2: "~ P ==> P" | 
| 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 wenzelm parents: 
12892diff
changeset | 698 | shows R | 
| 12386 | 699 | proof - | 
| 700 | from 2 and 1 have P . | |
| 701 | with 1 show R by (rule notE) | |
| 702 | qed | |
| 703 | ||
| 22444 
fb80fedd192d
added safe intro rules for removing "True" subgoals as well as "~ False" ones.
 dixon parents: 
22377diff
changeset | 704 | lemma TrueE: "True ==> P ==> P" . | 
| 
fb80fedd192d
added safe intro rules for removing "True" subgoals as well as "~ False" ones.
 dixon parents: 
22377diff
changeset | 705 | lemma notFalseE: "~ False ==> P ==> P" . | 
| 
fb80fedd192d
added safe intro rules for removing "True" subgoals as well as "~ False" ones.
 dixon parents: 
22377diff
changeset | 706 | |
| 22467 
c9357ef01168
TrueElim and notTrueElim tested and added as safe elim rules.
 dixon parents: 
22445diff
changeset | 707 | lemmas [Pure.elim!] = disjE iffE FalseE conjE exE TrueE notFalseE | 
| 15801 | 708 | and [Pure.intro!] = iffI conjI impI TrueI notI allI refl | 
| 709 | and [Pure.elim 2] = allE notE' impE' | |
| 710 | and [Pure.intro] = exI disjI2 disjI1 | |
| 12386 | 711 | |
| 712 | lemmas [trans] = trans | |
| 713 | and [sym] = sym not_sym | |
| 15801 | 714 | and [Pure.elim?] = iffD1 iffD2 impE | 
| 11750 | 715 | |
| 28952 
15a4b2cf8c34
made repository layout more coherent with logical distribution structure; stripped some $Id$s
 haftmann parents: 
28856diff
changeset | 716 | use "Tools/hologic.ML" | 
| 23553 | 717 | |
| 11438 
3d9222b80989
declare trans [trans]  (*overridden in theory Calculation*);
 wenzelm parents: 
11432diff
changeset | 718 | |
| 11750 | 719 | subsubsection {* Atomizing meta-level connectives *}
 | 
| 720 | ||
| 28513 | 721 | axiomatization where | 
| 722 | eq_reflection: "x = y \<Longrightarrow> x \<equiv> y" (*admissible axiom*) | |
| 723 | ||
| 11750 | 724 | lemma atomize_all [atomize]: "(!!x. P x) == Trueprop (ALL x. P x)" | 
| 12003 | 725 | proof | 
| 9488 | 726 | assume "!!x. P x" | 
| 23389 | 727 | then show "ALL x. P x" .. | 
| 9488 | 728 | next | 
| 729 | assume "ALL x. P x" | |
| 23553 | 730 | then show "!!x. P x" by (rule allE) | 
| 9488 | 731 | qed | 
| 732 | ||
| 11750 | 733 | lemma atomize_imp [atomize]: "(A ==> B) == Trueprop (A --> B)" | 
| 12003 | 734 | proof | 
| 9488 | 735 | assume r: "A ==> B" | 
| 10383 | 736 | show "A --> B" by (rule impI) (rule r) | 
| 9488 | 737 | next | 
| 738 | assume "A --> B" and A | |
| 23553 | 739 | then show B by (rule mp) | 
| 9488 | 740 | qed | 
| 741 | ||
| 14749 | 742 | lemma atomize_not: "(A ==> False) == Trueprop (~A)" | 
| 743 | proof | |
| 744 | assume r: "A ==> False" | |
| 745 | show "~A" by (rule notI) (rule r) | |
| 746 | next | |
| 747 | assume "~A" and A | |
| 23553 | 748 | then show False by (rule notE) | 
| 14749 | 749 | qed | 
| 750 | ||
| 11750 | 751 | lemma atomize_eq [atomize]: "(x == y) == Trueprop (x = y)" | 
| 12003 | 752 | proof | 
| 10432 
3dfbc913d184
added axclass inverse and consts inverse, divide (infix "/");
 wenzelm parents: 
10383diff
changeset | 753 | assume "x == y" | 
| 23553 | 754 | show "x = y" by (unfold `x == y`) (rule refl) | 
| 10432 
3dfbc913d184
added axclass inverse and consts inverse, divide (infix "/");
 wenzelm parents: 
10383diff
changeset | 755 | next | 
| 
3dfbc913d184
added axclass inverse and consts inverse, divide (infix "/");
 wenzelm parents: 
10383diff
changeset | 756 | assume "x = y" | 
| 23553 | 757 | then show "x == y" by (rule eq_reflection) | 
| 10432 
3dfbc913d184
added axclass inverse and consts inverse, divide (infix "/");
 wenzelm parents: 
10383diff
changeset | 758 | qed | 
| 
3dfbc913d184
added axclass inverse and consts inverse, divide (infix "/");
 wenzelm parents: 
10383diff
changeset | 759 | |
| 28856 
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
 wenzelm parents: 
28741diff
changeset | 760 | lemma atomize_conj [atomize]: "(A &&& B) == Trueprop (A & B)" | 
| 12003 | 761 | proof | 
| 28856 
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
 wenzelm parents: 
28741diff
changeset | 762 | assume conj: "A &&& B" | 
| 19121 | 763 | show "A & B" | 
| 764 | proof (rule conjI) | |
| 765 | from conj show A by (rule conjunctionD1) | |
| 766 | from conj show B by (rule conjunctionD2) | |
| 767 | qed | |
| 11953 | 768 | next | 
| 19121 | 769 | assume conj: "A & B" | 
| 28856 
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
 wenzelm parents: 
28741diff
changeset | 770 | show "A &&& B" | 
| 19121 | 771 | proof - | 
| 772 | from conj show A .. | |
| 773 | from conj show B .. | |
| 11953 | 774 | qed | 
| 775 | qed | |
| 776 | ||
| 12386 | 777 | lemmas [symmetric, rulify] = atomize_all atomize_imp | 
| 18832 | 778 | and [symmetric, defn] = atomize_all atomize_imp atomize_eq | 
| 12386 | 779 | |
| 11750 | 780 | |
| 26580 
c3e597a476fd
Generic conversion and tactic "atomize_elim" to convert elimination rules
 krauss parents: 
26555diff
changeset | 781 | subsubsection {* Atomizing elimination rules *}
 | 
| 
c3e597a476fd
Generic conversion and tactic "atomize_elim" to convert elimination rules
 krauss parents: 
26555diff
changeset | 782 | |
| 
c3e597a476fd
Generic conversion and tactic "atomize_elim" to convert elimination rules
 krauss parents: 
26555diff
changeset | 783 | setup AtomizeElim.setup | 
| 
c3e597a476fd
Generic conversion and tactic "atomize_elim" to convert elimination rules
 krauss parents: 
26555diff
changeset | 784 | |
| 
c3e597a476fd
Generic conversion and tactic "atomize_elim" to convert elimination rules
 krauss parents: 
26555diff
changeset | 785 | lemma atomize_exL[atomize_elim]: "(!!x. P x ==> Q) == ((EX x. P x) ==> Q)" | 
| 
c3e597a476fd
Generic conversion and tactic "atomize_elim" to convert elimination rules
 krauss parents: 
26555diff
changeset | 786 | by rule iprover+ | 
| 
c3e597a476fd
Generic conversion and tactic "atomize_elim" to convert elimination rules
 krauss parents: 
26555diff
changeset | 787 | |
| 
c3e597a476fd
Generic conversion and tactic "atomize_elim" to convert elimination rules
 krauss parents: 
26555diff
changeset | 788 | lemma atomize_conjL[atomize_elim]: "(A ==> B ==> C) == (A & B ==> C)" | 
| 
c3e597a476fd
Generic conversion and tactic "atomize_elim" to convert elimination rules
 krauss parents: 
26555diff
changeset | 789 | by rule iprover+ | 
| 
c3e597a476fd
Generic conversion and tactic "atomize_elim" to convert elimination rules
 krauss parents: 
26555diff
changeset | 790 | |
| 
c3e597a476fd
Generic conversion and tactic "atomize_elim" to convert elimination rules
 krauss parents: 
26555diff
changeset | 791 | lemma atomize_disjL[atomize_elim]: "((A ==> C) ==> (B ==> C) ==> C) == ((A | B ==> C) ==> C)" | 
| 
c3e597a476fd
Generic conversion and tactic "atomize_elim" to convert elimination rules
 krauss parents: 
26555diff
changeset | 792 | by rule iprover+ | 
| 
c3e597a476fd
Generic conversion and tactic "atomize_elim" to convert elimination rules
 krauss parents: 
26555diff
changeset | 793 | |
| 
c3e597a476fd
Generic conversion and tactic "atomize_elim" to convert elimination rules
 krauss parents: 
26555diff
changeset | 794 | lemma atomize_elimL[atomize_elim]: "(!!B. (A ==> B) ==> B) == Trueprop A" .. | 
| 
c3e597a476fd
Generic conversion and tactic "atomize_elim" to convert elimination rules
 krauss parents: 
26555diff
changeset | 795 | |
| 
c3e597a476fd
Generic conversion and tactic "atomize_elim" to convert elimination rules
 krauss parents: 
26555diff
changeset | 796 | |
| 20944 | 797 | subsection {* Package setup *}
 | 
| 798 | ||
| 11750 | 799 | subsubsection {* Classical Reasoner setup *}
 | 
| 9529 | 800 | |
| 26411 | 801 | lemma imp_elim: "P --> Q ==> (~ R ==> P) ==> (Q ==> R) ==> R" | 
| 802 | by (rule classical) iprover | |
| 803 | ||
| 804 | lemma swap: "~ P ==> (~ R ==> P) ==> R" | |
| 805 | by (rule classical) iprover | |
| 806 | ||
| 20944 | 807 | lemma thin_refl: | 
| 808 | "\<And>X. \<lbrakk> x=x; PROP W \<rbrakk> \<Longrightarrow> PROP W" . | |
| 809 | ||
| 21151 | 810 | ML {*
 | 
| 811 | structure Hypsubst = HypsubstFun( | |
| 812 | struct | |
| 813 | structure Simplifier = Simplifier | |
| 21218 | 814 | val dest_eq = HOLogic.dest_eq | 
| 21151 | 815 | val dest_Trueprop = HOLogic.dest_Trueprop | 
| 816 | val dest_imp = HOLogic.dest_imp | |
| 26411 | 817 |   val eq_reflection = @{thm eq_reflection}
 | 
| 818 |   val rev_eq_reflection = @{thm meta_eq_to_obj_eq}
 | |
| 819 |   val imp_intr = @{thm impI}
 | |
| 820 |   val rev_mp = @{thm rev_mp}
 | |
| 821 |   val subst = @{thm subst}
 | |
| 822 |   val sym = @{thm sym}
 | |
| 22129 | 823 |   val thin_refl = @{thm thin_refl};
 | 
| 27572 
67cd6ed76446
single_hyp(_meta)_subst_tac: Controlled substitution of a single hyp
 krauss parents: 
27338diff
changeset | 824 |   val prop_subst = @{lemma "PROP P t ==> PROP prop (x = t ==> PROP P x)"
 | 
| 
67cd6ed76446
single_hyp(_meta)_subst_tac: Controlled substitution of a single hyp
 krauss parents: 
27338diff
changeset | 825 | by (unfold prop_def) (drule eq_reflection, unfold)} | 
| 21151 | 826 | end); | 
| 21671 | 827 | open Hypsubst; | 
| 21151 | 828 | |
| 829 | structure Classical = ClassicalFun( | |
| 830 | struct | |
| 26411 | 831 |   val imp_elim = @{thm imp_elim}
 | 
| 832 |   val not_elim = @{thm notE}
 | |
| 833 |   val swap = @{thm swap}
 | |
| 834 |   val classical = @{thm classical}
 | |
| 21151 | 835 | val sizef = Drule.size_of_thm | 
| 836 | val hyp_subst_tacs = [Hypsubst.hyp_subst_tac] | |
| 837 | end); | |
| 838 | ||
| 33308 
cf62d1690d04
separate ResBlacklist, based on scalable persistent data -- avoids inefficient hashing later on;
 wenzelm parents: 
33185diff
changeset | 839 | structure Basic_Classical: BASIC_CLASSICAL = Classical; | 
| 
cf62d1690d04
separate ResBlacklist, based on scalable persistent data -- avoids inefficient hashing later on;
 wenzelm parents: 
33185diff
changeset | 840 | open Basic_Classical; | 
| 22129 | 841 | |
| 27338 | 842 | ML_Antiquote.value "claset" | 
| 32149 
ef59550a55d3
renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
 wenzelm parents: 
32119diff
changeset | 843 | (Scan.succeed "Classical.claset_of (ML_Context.the_local_context ())"); | 
| 21151 | 844 | *} | 
| 845 | ||
| 33308 
cf62d1690d04
separate ResBlacklist, based on scalable persistent data -- avoids inefficient hashing later on;
 wenzelm parents: 
33185diff
changeset | 846 | setup Classical.setup | 
| 24286 
7619080e49f0
ATP blacklisting is now in theory data, attribute noatp
 paulson parents: 
24280diff
changeset | 847 | |
| 21009 | 848 | setup {*
 | 
| 849 | let | |
| 850 | (*prevent substitution on bool*) | |
| 851 | fun hyp_subst_tac' i thm = if i <= Thm.nprems_of thm andalso | |
| 852 |     Term.exists_Const (fn ("op =", Type (_, [T, _])) => T <> Type ("bool", []) | _ => false)
 | |
| 853 | (nth (Thm.prems_of thm) (i - 1)) then Hypsubst.hyp_subst_tac i thm else no_tac thm; | |
| 854 | in | |
| 21151 | 855 | Hypsubst.hypsubst_setup | 
| 33369 | 856 | #> Context_Rules.addSWrapper (fn tac => hyp_subst_tac' ORELSE' tac) | 
| 21009 | 857 | end | 
| 858 | *} | |
| 859 | ||
| 860 | declare iffI [intro!] | |
| 861 | and notI [intro!] | |
| 862 | and impI [intro!] | |
| 863 | and disjCI [intro!] | |
| 864 | and conjI [intro!] | |
| 865 | and TrueI [intro!] | |
| 866 | and refl [intro!] | |
| 867 | ||
| 868 | declare iffCE [elim!] | |
| 869 | and FalseE [elim!] | |
| 870 | and impCE [elim!] | |
| 871 | and disjE [elim!] | |
| 872 | and conjE [elim!] | |
| 873 | and conjE [elim!] | |
| 874 | ||
| 875 | declare ex_ex1I [intro!] | |
| 876 | and allI [intro!] | |
| 877 | and the_equality [intro] | |
| 878 | and exI [intro] | |
| 879 | ||
| 880 | declare exE [elim!] | |
| 881 | allE [elim] | |
| 882 | ||
| 22377 | 883 | ML {* val HOL_cs = @{claset} *}
 | 
| 19162 | 884 | |
| 20223 | 885 | lemma contrapos_np: "~ Q ==> (~ P ==> Q) ==> P" | 
| 886 | apply (erule swap) | |
| 887 | apply (erule (1) meta_mp) | |
| 888 | done | |
| 10383 | 889 | |
| 18689 
a50587cd8414
prefer ex1I over ex_ex1I in single-step reasoning;
 wenzelm parents: 
18595diff
changeset | 890 | declare ex_ex1I [rule del, intro! 2] | 
| 
a50587cd8414
prefer ex1I over ex_ex1I in single-step reasoning;
 wenzelm parents: 
18595diff
changeset | 891 | and ex1I [intro] | 
| 
a50587cd8414
prefer ex1I over ex_ex1I in single-step reasoning;
 wenzelm parents: 
18595diff
changeset | 892 | |
| 12386 | 893 | lemmas [intro?] = ext | 
| 894 | and [elim?] = ex1_implies_ex | |
| 11977 | 895 | |
| 20944 | 896 | (*Better then ex1E for classical reasoner: needs no quantifier duplication!*) | 
| 20973 | 897 | lemma alt_ex1E [elim!]: | 
| 20944 | 898 | assumes major: "\<exists>!x. P x" | 
| 899 | and prem: "\<And>x. \<lbrakk> P x; \<forall>y y'. P y \<and> P y' \<longrightarrow> y = y' \<rbrakk> \<Longrightarrow> R" | |
| 900 | shows R | |
| 901 | apply (rule ex1E [OF major]) | |
| 902 | apply (rule prem) | |
| 22129 | 903 | apply (tactic {* ares_tac @{thms allI} 1 *})+
 | 
| 904 | apply (tactic {* etac (Classical.dup_elim @{thm allE}) 1 *})
 | |
| 905 | apply iprover | |
| 906 | done | |
| 20944 | 907 | |
| 21151 | 908 | ML {*
 | 
| 32176 
893614e2c35c
renamed functor BlastFun to Blast, require explicit theory;
 wenzelm parents: 
32172diff
changeset | 909 | structure Blast = Blast | 
| 25388 | 910 | ( | 
| 32176 
893614e2c35c
renamed functor BlastFun to Blast, require explicit theory;
 wenzelm parents: 
32172diff
changeset | 911 |   val thy = @{theory}
 | 
| 21151 | 912 | type claset = Classical.claset | 
| 22744 
5cbe966d67a2
Isar definitions are now added explicitly to code theorem table
 haftmann parents: 
22481diff
changeset | 913 |   val equality_name = @{const_name "op ="}
 | 
| 22993 | 914 |   val not_name = @{const_name Not}
 | 
| 26411 | 915 |   val notE = @{thm notE}
 | 
| 916 |   val ccontr = @{thm ccontr}
 | |
| 21151 | 917 | val contr_tac = Classical.contr_tac | 
| 918 | val dup_intr = Classical.dup_intr | |
| 919 | val hyp_subst_tac = Hypsubst.blast_hyp_subst_tac | |
| 920 | val rep_cs = Classical.rep_cs | |
| 921 | val cla_modifiers = Classical.cla_modifiers | |
| 922 | val cla_meth' = Classical.cla_meth' | |
| 25388 | 923 | ); | 
| 21671 | 924 | val blast_tac = Blast.blast_tac; | 
| 20944 | 925 | *} | 
| 926 | ||
| 21151 | 927 | setup Blast.setup | 
| 928 | ||
| 20944 | 929 | |
| 930 | subsubsection {* Simplifier *}
 | |
| 12281 | 931 | |
| 932 | lemma eta_contract_eq: "(%s. f s) = f" .. | |
| 933 | ||
| 934 | lemma simp_thms: | |
| 12937 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 wenzelm parents: 
12892diff
changeset | 935 | shows not_not: "(~ ~ P) = P" | 
| 15354 | 936 | and Not_eq_iff: "((~P) = (~Q)) = (P = Q)" | 
| 12937 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 wenzelm parents: 
12892diff
changeset | 937 | and | 
| 12436 
a2df07fefed7
Replaced several occurrences of "blast" by "rules".
 berghofe parents: 
12386diff
changeset | 938 | "(P ~= Q) = (P = (~Q))" | 
| 
a2df07fefed7
Replaced several occurrences of "blast" by "rules".
 berghofe parents: 
12386diff
changeset | 939 | "(P | ~P) = True" "(~P | P) = True" | 
| 12281 | 940 | "(x = x) = True" | 
| 32068 | 941 | and not_True_eq_False [code]: "(\<not> True) = False" | 
| 942 | and not_False_eq_True [code]: "(\<not> False) = True" | |
| 20944 | 943 | and | 
| 12436 
a2df07fefed7
Replaced several occurrences of "blast" by "rules".
 berghofe parents: 
12386diff
changeset | 944 | "(~P) ~= P" "P ~= (~P)" | 
| 20944 | 945 | "(True=P) = P" | 
| 946 | and eq_True: "(P = True) = P" | |
| 947 | and "(False=P) = (~P)" | |
| 948 | and eq_False: "(P = False) = (\<not> P)" | |
| 949 | and | |
| 12281 | 950 | "(True --> P) = P" "(False --> P) = True" | 
| 951 | "(P --> True) = True" "(P --> P) = True" | |
| 952 | "(P --> False) = (~P)" "(P --> ~P) = (~P)" | |
| 953 | "(P & True) = P" "(True & P) = P" | |
| 954 | "(P & False) = False" "(False & P) = False" | |
| 955 | "(P & P) = P" "(P & (P & Q)) = (P & Q)" | |
| 956 | "(P & ~P) = False" "(~P & P) = False" | |
| 957 | "(P | True) = True" "(True | P) = True" | |
| 958 | "(P | False) = P" "(False | P) = P" | |
| 12436 
a2df07fefed7
Replaced several occurrences of "blast" by "rules".
 berghofe parents: 
12386diff
changeset | 959 | "(P | P) = P" "(P | (P | Q)) = (P | Q)" and | 
| 12281 | 960 | "(ALL x. P) = P" "(EX x. P) = P" "EX x. x=t" "EX x. t=x" | 
| 31166 
a90fe83f58ea
"{x. P x & x=t & Q x}" is now rewritten to "if P t & Q t then {t} else {}"
 nipkow parents: 
31156diff
changeset | 961 | and | 
| 12281 | 962 | "!!P. (EX x. x=t & P(x)) = P(t)" | 
| 963 | "!!P. (EX x. t=x & P(x)) = P(t)" | |
| 964 | "!!P. (ALL x. x=t --> P(x)) = P(t)" | |
| 12937 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 wenzelm parents: 
12892diff
changeset | 965 | "!!P. (ALL x. t=x --> P(x)) = P(t)" | 
| 17589 | 966 | by (blast, blast, blast, blast, blast, iprover+) | 
| 13421 | 967 | |
| 14201 | 968 | lemma disj_absorb: "(A | A) = A" | 
| 969 | by blast | |
| 970 | ||
| 971 | lemma disj_left_absorb: "(A | (A | B)) = (A | B)" | |
| 972 | by blast | |
| 973 | ||
| 974 | lemma conj_absorb: "(A & A) = A" | |
| 975 | by blast | |
| 976 | ||
| 977 | lemma conj_left_absorb: "(A & (A & B)) = (A & B)" | |
| 978 | by blast | |
| 979 | ||
| 12281 | 980 | lemma eq_ac: | 
| 12937 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 wenzelm parents: 
12892diff
changeset | 981 | shows eq_commute: "(a=b) = (b=a)" | 
| 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 wenzelm parents: 
12892diff
changeset | 982 | and eq_left_commute: "(P=(Q=R)) = (Q=(P=R))" | 
| 17589 | 983 | and eq_assoc: "((P=Q)=R) = (P=(Q=R))" by (iprover, blast+) | 
| 984 | lemma neq_commute: "(a~=b) = (b~=a)" by iprover | |
| 12281 | 985 | |
| 986 | lemma conj_comms: | |
| 12937 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 wenzelm parents: 
12892diff
changeset | 987 | shows conj_commute: "(P&Q) = (Q&P)" | 
| 17589 | 988 | and conj_left_commute: "(P&(Q&R)) = (Q&(P&R))" by iprover+ | 
| 989 | lemma conj_assoc: "((P&Q)&R) = (P&(Q&R))" by iprover | |
| 12281 | 990 | |
| 19174 | 991 | lemmas conj_ac = conj_commute conj_left_commute conj_assoc | 
| 992 | ||
| 12281 | 993 | lemma disj_comms: | 
| 12937 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 wenzelm parents: 
12892diff
changeset | 994 | shows disj_commute: "(P|Q) = (Q|P)" | 
| 17589 | 995 | and disj_left_commute: "(P|(Q|R)) = (Q|(P|R))" by iprover+ | 
| 996 | lemma disj_assoc: "((P|Q)|R) = (P|(Q|R))" by iprover | |
| 12281 | 997 | |
| 19174 | 998 | lemmas disj_ac = disj_commute disj_left_commute disj_assoc | 
| 999 | ||
| 17589 | 1000 | lemma conj_disj_distribL: "(P&(Q|R)) = (P&Q | P&R)" by iprover | 
| 1001 | lemma conj_disj_distribR: "((P|Q)&R) = (P&R | Q&R)" by iprover | |
| 12281 | 1002 | |
| 17589 | 1003 | lemma disj_conj_distribL: "(P|(Q&R)) = ((P|Q) & (P|R))" by iprover | 
| 1004 | lemma disj_conj_distribR: "((P&Q)|R) = ((P|R) & (Q|R))" by iprover | |
| 12281 | 1005 | |
| 17589 | 1006 | lemma imp_conjR: "(P --> (Q&R)) = ((P-->Q) & (P-->R))" by iprover | 
| 1007 | lemma imp_conjL: "((P&Q) -->R) = (P --> (Q --> R))" by iprover | |
| 1008 | lemma imp_disjL: "((P|Q) --> R) = ((P-->R)&(Q-->R))" by iprover | |
| 12281 | 1009 | |
| 1010 | text {* These two are specialized, but @{text imp_disj_not1} is useful in @{text "Auth/Yahalom"}. *}
 | |
| 1011 | lemma imp_disj_not1: "(P --> Q | R) = (~Q --> P --> R)" by blast | |
| 1012 | lemma imp_disj_not2: "(P --> Q | R) = (~R --> P --> Q)" by blast | |
| 1013 | ||
| 1014 | lemma imp_disj1: "((P-->Q)|R) = (P--> Q|R)" by blast | |
| 1015 | lemma imp_disj2: "(Q|(P-->R)) = (P--> Q|R)" by blast | |
| 1016 | ||
| 21151 | 1017 | lemma imp_cong: "(P = P') ==> (P' ==> (Q = Q')) ==> ((P --> Q) = (P' --> Q'))" | 
| 1018 | by iprover | |
| 1019 | ||
| 17589 | 1020 | lemma de_Morgan_disj: "(~(P | Q)) = (~P & ~Q)" by iprover | 
| 12281 | 1021 | lemma de_Morgan_conj: "(~(P & Q)) = (~P | ~Q)" by blast | 
| 1022 | lemma not_imp: "(~(P --> Q)) = (P & ~Q)" by blast | |
| 1023 | lemma not_iff: "(P~=Q) = (P = (~Q))" by blast | |
| 1024 | lemma disj_not1: "(~P | Q) = (P --> Q)" by blast | |
| 1025 | lemma disj_not2: "(P | ~Q) = (Q --> P)"  -- {* changes orientation :-( *}
 | |
| 1026 | by blast | |
| 1027 | lemma imp_conv_disj: "(P --> Q) = ((~P) | Q)" by blast | |
| 1028 | ||
| 17589 | 1029 | lemma iff_conv_conj_imp: "(P = Q) = ((P --> Q) & (Q --> P))" by iprover | 
| 12281 | 1030 | |
| 1031 | ||
| 1032 | lemma cases_simp: "((P --> Q) & (~P --> Q)) = Q" | |
| 1033 |   -- {* Avoids duplication of subgoals after @{text split_if}, when the true and false *}
 | |
| 1034 |   -- {* cases boil down to the same thing. *}
 | |
| 1035 | by blast | |
| 1036 | ||
| 1037 | lemma not_all: "(~ (! x. P(x))) = (? x.~P(x))" by blast | |
| 1038 | lemma imp_all: "((! x. P x) --> Q) = (? x. P x --> Q)" by blast | |
| 17589 | 1039 | lemma not_ex: "(~ (? x. P(x))) = (! x.~P(x))" by iprover | 
| 1040 | lemma imp_ex: "((? x. P x) --> Q) = (! x. P x --> Q)" by iprover | |
| 23403 | 1041 | lemma all_not_ex: "(ALL x. P x) = (~ (EX x. ~ P x ))" by blast | 
| 12281 | 1042 | |
| 24286 
7619080e49f0
ATP blacklisting is now in theory data, attribute noatp
 paulson parents: 
24280diff
changeset | 1043 | declare All_def [noatp] | 
| 
7619080e49f0
ATP blacklisting is now in theory data, attribute noatp
 paulson parents: 
24280diff
changeset | 1044 | |
| 17589 | 1045 | lemma ex_disj_distrib: "(? x. P(x) | Q(x)) = ((? x. P(x)) | (? x. Q(x)))" by iprover | 
| 1046 | lemma all_conj_distrib: "(!x. P(x) & Q(x)) = ((! x. P(x)) & (! x. Q(x)))" by iprover | |
| 12281 | 1047 | |
| 1048 | text {*
 | |
| 1049 |   \medskip The @{text "&"} congruence rule: not included by default!
 | |
| 1050 | May slow rewrite proofs down by as much as 50\% *} | |
| 1051 | ||
| 1052 | lemma conj_cong: | |
| 1053 | "(P = P') ==> (P' ==> (Q = Q')) ==> ((P & Q) = (P' & Q'))" | |
| 17589 | 1054 | by iprover | 
| 12281 | 1055 | |
| 1056 | lemma rev_conj_cong: | |
| 1057 | "(Q = Q') ==> (Q' ==> (P = P')) ==> ((P & Q) = (P' & Q'))" | |
| 17589 | 1058 | by iprover | 
| 12281 | 1059 | |
| 1060 | text {* The @{text "|"} congruence rule: not included by default! *}
 | |
| 1061 | ||
| 1062 | lemma disj_cong: | |
| 1063 | "(P = P') ==> (~P' ==> (Q = Q')) ==> ((P | Q) = (P' | Q'))" | |
| 1064 | by blast | |
| 1065 | ||
| 1066 | ||
| 1067 | text {* \medskip if-then-else rules *}
 | |
| 1068 | ||
| 32068 | 1069 | lemma if_True [code]: "(if True then x else y) = x" | 
| 12281 | 1070 | by (unfold if_def) blast | 
| 1071 | ||
| 32068 | 1072 | lemma if_False [code]: "(if False then x else y) = y" | 
| 12281 | 1073 | by (unfold if_def) blast | 
| 1074 | ||
| 1075 | lemma if_P: "P ==> (if P then x else y) = x" | |
| 1076 | by (unfold if_def) blast | |
| 1077 | ||
| 1078 | lemma if_not_P: "~P ==> (if P then x else y) = y" | |
| 1079 | by (unfold if_def) blast | |
| 1080 | ||
| 1081 | lemma split_if: "P (if Q then x else y) = ((Q --> P(x)) & (~Q --> P(y)))" | |
| 1082 | apply (rule case_split [of Q]) | |
| 15481 | 1083 | apply (simplesubst if_P) | 
| 1084 | prefer 3 apply (simplesubst if_not_P, blast+) | |
| 12281 | 1085 | done | 
| 1086 | ||
| 1087 | lemma split_if_asm: "P (if Q then x else y) = (~((Q & ~P x) | (~Q & ~P y)))" | |
| 15481 | 1088 | by (simplesubst split_if, blast) | 
| 12281 | 1089 | |
| 24286 
7619080e49f0
ATP blacklisting is now in theory data, attribute noatp
 paulson parents: 
24280diff
changeset | 1090 | lemmas if_splits [noatp] = split_if split_if_asm | 
| 12281 | 1091 | |
| 1092 | lemma if_cancel: "(if c then x else x) = x" | |
| 15481 | 1093 | by (simplesubst split_if, blast) | 
| 12281 | 1094 | |
| 1095 | lemma if_eq_cancel: "(if x = y then y else x) = x" | |
| 15481 | 1096 | by (simplesubst split_if, blast) | 
| 12281 | 1097 | |
| 1098 | lemma if_bool_eq_conj: "(if P then Q else R) = ((P-->Q) & (~P-->R))" | |
| 19796 | 1099 |   -- {* This form is useful for expanding @{text "if"}s on the RIGHT of the @{text "==>"} symbol. *}
 | 
| 12281 | 1100 | by (rule split_if) | 
| 1101 | ||
| 1102 | lemma if_bool_eq_disj: "(if P then Q else R) = ((P&Q) | (~P&R))" | |
| 19796 | 1103 |   -- {* And this form is useful for expanding @{text "if"}s on the LEFT. *}
 | 
| 15481 | 1104 | apply (simplesubst split_if, blast) | 
| 12281 | 1105 | done | 
| 1106 | ||
| 17589 | 1107 | lemma Eq_TrueI: "P ==> P == True" by (unfold atomize_eq) iprover | 
| 1108 | lemma Eq_FalseI: "~P ==> P == False" by (unfold atomize_eq) iprover | |
| 12281 | 1109 | |
| 15423 | 1110 | text {* \medskip let rules for simproc *}
 | 
| 1111 | ||
| 1112 | lemma Let_folded: "f x \<equiv> g x \<Longrightarrow> Let x f \<equiv> Let x g" | |
| 1113 | by (unfold Let_def) | |
| 1114 | ||
| 1115 | lemma Let_unfold: "f x \<equiv> g \<Longrightarrow> Let x f \<equiv> g" | |
| 1116 | by (unfold Let_def) | |
| 1117 | ||
| 16633 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1118 | text {*
 | 
| 16999 | 1119 | The following copy of the implication operator is useful for | 
| 1120 | fine-tuning congruence rules. It instructs the simplifier to simplify | |
| 1121 | its premise. | |
| 16633 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1122 | *} | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1123 | |
| 17197 | 1124 | constdefs | 
| 1125 | simp_implies :: "[prop, prop] => prop" (infixr "=simp=>" 1) | |
| 28562 | 1126 | [code del]: "simp_implies \<equiv> op ==>" | 
| 16633 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1127 | |
| 18457 | 1128 | lemma simp_impliesI: | 
| 16633 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1129 | assumes PQ: "(PROP P \<Longrightarrow> PROP Q)" | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1130 | shows "PROP P =simp=> PROP Q" | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1131 | apply (unfold simp_implies_def) | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1132 | apply (rule PQ) | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1133 | apply assumption | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1134 | done | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1135 | |
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1136 | lemma simp_impliesE: | 
| 25388 | 1137 | assumes PQ: "PROP P =simp=> PROP Q" | 
| 16633 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1138 | and P: "PROP P" | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1139 | and QR: "PROP Q \<Longrightarrow> PROP R" | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1140 | shows "PROP R" | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1141 | apply (rule QR) | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1142 | apply (rule PQ [unfolded simp_implies_def]) | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1143 | apply (rule P) | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1144 | done | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1145 | |
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1146 | lemma simp_implies_cong: | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1147 | assumes PP' :"PROP P == PROP P'" | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1148 | and P'QQ': "PROP P' ==> (PROP Q == PROP Q')" | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1149 | shows "(PROP P =simp=> PROP Q) == (PROP P' =simp=> PROP Q')" | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1150 | proof (unfold simp_implies_def, rule equal_intr_rule) | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1151 | assume PQ: "PROP P \<Longrightarrow> PROP Q" | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1152 | and P': "PROP P'" | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1153 | from PP' [symmetric] and P' have "PROP P" | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1154 | by (rule equal_elim_rule1) | 
| 23553 | 1155 | then have "PROP Q" by (rule PQ) | 
| 16633 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1156 | with P'QQ' [OF P'] show "PROP Q'" by (rule equal_elim_rule1) | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1157 | next | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1158 | assume P'Q': "PROP P' \<Longrightarrow> PROP Q'" | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1159 | and P: "PROP P" | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1160 | from PP' and P have P': "PROP P'" by (rule equal_elim_rule1) | 
| 23553 | 1161 | then have "PROP Q'" by (rule P'Q') | 
| 16633 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1162 | with P'QQ' [OF P', symmetric] show "PROP Q" | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1163 | by (rule equal_elim_rule1) | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1164 | qed | 
| 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 berghofe parents: 
16587diff
changeset | 1165 | |
| 20944 | 1166 | lemma uncurry: | 
| 1167 | assumes "P \<longrightarrow> Q \<longrightarrow> R" | |
| 1168 | shows "P \<and> Q \<longrightarrow> R" | |
| 23553 | 1169 | using assms by blast | 
| 20944 | 1170 | |
| 1171 | lemma iff_allI: | |
| 1172 | assumes "\<And>x. P x = Q x" | |
| 1173 | shows "(\<forall>x. P x) = (\<forall>x. Q x)" | |
| 23553 | 1174 | using assms by blast | 
| 20944 | 1175 | |
| 1176 | lemma iff_exI: | |
| 1177 | assumes "\<And>x. P x = Q x" | |
| 1178 | shows "(\<exists>x. P x) = (\<exists>x. Q x)" | |
| 23553 | 1179 | using assms by blast | 
| 20944 | 1180 | |
| 1181 | lemma all_comm: | |
| 1182 | "(\<forall>x y. P x y) = (\<forall>y x. P x y)" | |
| 1183 | by blast | |
| 1184 | ||
| 1185 | lemma ex_comm: | |
| 1186 | "(\<exists>x y. P x y) = (\<exists>y x. P x y)" | |
| 1187 | by blast | |
| 1188 | ||
| 28952 
15a4b2cf8c34
made repository layout more coherent with logical distribution structure; stripped some $Id$s
 haftmann parents: 
28856diff
changeset | 1189 | use "Tools/simpdata.ML" | 
| 21671 | 1190 | ML {* open Simpdata *}
 | 
| 1191 | ||
| 21151 | 1192 | setup {*
 | 
| 1193 | Simplifier.method_setup Splitter.split_modifiers | |
| 26496 
49ae9456eba9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26411diff
changeset | 1194 | #> Simplifier.map_simpset (K Simpdata.simpset_simprocs) | 
| 21151 | 1195 | #> Splitter.setup | 
| 26496 
49ae9456eba9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26411diff
changeset | 1196 | #> clasimp_setup | 
| 21151 | 1197 | #> EqSubst.setup | 
| 1198 | *} | |
| 1199 | ||
| 24035 | 1200 | text {* Simproc for proving @{text "(y = x) == False"} from premise @{text "~(x = y)"}: *}
 | 
| 1201 | ||
| 1202 | simproc_setup neq ("x = y") = {* fn _ =>
 | |
| 1203 | let | |
| 1204 |   val neq_to_EQ_False = @{thm not_sym} RS @{thm Eq_FalseI};
 | |
| 1205 | fun is_neq eq lhs rhs thm = | |
| 1206 | (case Thm.prop_of thm of | |
| 1207 | _ $ (Not $ (eq' $ l' $ r')) => | |
| 1208 | Not = HOLogic.Not andalso eq' = eq andalso | |
| 1209 | r' aconv lhs andalso l' aconv rhs | |
| 1210 | | _ => false); | |
| 1211 | fun proc ss ct = | |
| 1212 | (case Thm.term_of ct of | |
| 1213 | eq $ lhs $ rhs => | |
| 1214 | (case find_first (is_neq eq lhs rhs) (Simplifier.prems_of_ss ss) of | |
| 1215 | SOME thm => SOME (thm RS neq_to_EQ_False) | |
| 1216 | | NONE => NONE) | |
| 1217 | | _ => NONE); | |
| 1218 | in proc end; | |
| 1219 | *} | |
| 1220 | ||
| 1221 | simproc_setup let_simp ("Let x f") = {*
 | |
| 1222 | let | |
| 1223 | val (f_Let_unfold, x_Let_unfold) = | |
| 28741 | 1224 |     let val [(_ $ (f $ x) $ _)] = prems_of @{thm Let_unfold}
 | 
| 24035 | 1225 |     in (cterm_of @{theory} f, cterm_of @{theory} x) end
 | 
| 1226 | val (f_Let_folded, x_Let_folded) = | |
| 28741 | 1227 |     let val [(_ $ (f $ x) $ _)] = prems_of @{thm Let_folded}
 | 
| 24035 | 1228 |     in (cterm_of @{theory} f, cterm_of @{theory} x) end;
 | 
| 1229 | val g_Let_folded = | |
| 28741 | 1230 |     let val [(_ $ _ $ (g $ _))] = prems_of @{thm Let_folded}
 | 
| 1231 |     in cterm_of @{theory} g end;
 | |
| 1232 | fun count_loose (Bound i) k = if i >= k then 1 else 0 | |
| 1233 | | count_loose (s $ t) k = count_loose s k + count_loose t k | |
| 1234 | | count_loose (Abs (_, _, t)) k = count_loose t (k + 1) | |
| 1235 | | count_loose _ _ = 0; | |
| 1236 |   fun is_trivial_let (Const (@{const_name Let}, _) $ x $ t) =
 | |
| 1237 | case t | |
| 1238 | of Abs (_, _, t') => count_loose t' 0 <= 1 | |
| 1239 | | _ => true; | |
| 1240 | in fn _ => fn ss => fn ct => if is_trivial_let (Thm.term_of ct) | |
| 31151 | 1241 |   then SOME @{thm Let_def} (*no or one ocurrence of bound variable*)
 | 
| 28741 | 1242 | else let (*Norbert Schirmer's case*) | 
| 1243 | val ctxt = Simplifier.the_context ss; | |
| 1244 | val thy = ProofContext.theory_of ctxt; | |
| 1245 | val t = Thm.term_of ct; | |
| 1246 | val ([t'], ctxt') = Variable.import_terms false [t] ctxt; | |
| 1247 | in Option.map (hd o Variable.export ctxt' ctxt o single) | |
| 1248 |     (case t' of Const (@{const_name Let},_) $ x $ f => (* x and f are already in normal form *)
 | |
| 1249 | if is_Free x orelse is_Bound x orelse is_Const x | |
| 1250 |       then SOME @{thm Let_def}
 | |
| 1251 | else | |
| 1252 | let | |
| 1253 | val n = case f of (Abs (x, _, _)) => x | _ => "x"; | |
| 1254 | val cx = cterm_of thy x; | |
| 1255 |           val {T = xT, ...} = rep_cterm cx;
 | |
| 1256 | val cf = cterm_of thy f; | |
| 1257 | val fx_g = Simplifier.rewrite ss (Thm.capply cf cx); | |
| 1258 | val (_ $ _ $ g) = prop_of fx_g; | |
| 1259 | val g' = abstract_over (x,g); | |
| 1260 | in (if (g aconv g') | |
| 1261 | then | |
| 1262 | let | |
| 1263 | val rl = | |
| 1264 |                     cterm_instantiate [(f_Let_unfold, cf), (x_Let_unfold, cx)] @{thm Let_unfold};
 | |
| 1265 | in SOME (rl OF [fx_g]) end | |
| 1266 | else if Term.betapply (f, x) aconv g then NONE (*avoid identity conversion*) | |
| 1267 | else let | |
| 1268 | val abs_g'= Abs (n,xT,g'); | |
| 1269 | val g'x = abs_g'$x; | |
| 1270 | val g_g'x = symmetric (beta_conversion false (cterm_of thy g'x)); | |
| 1271 | val rl = cterm_instantiate | |
| 1272 | [(f_Let_folded, cterm_of thy f), (x_Let_folded, cx), | |
| 1273 | (g_Let_folded, cterm_of thy abs_g')] | |
| 1274 |                              @{thm Let_folded};
 | |
| 1275 | in SOME (rl OF [transitive fx_g g_g'x]) | |
| 1276 | end) | |
| 1277 | end | |
| 1278 | | _ => NONE) | |
| 1279 | end | |
| 1280 | end *} | |
| 24035 | 1281 | |
| 21151 | 1282 | lemma True_implies_equals: "(True \<Longrightarrow> PROP P) \<equiv> PROP P" | 
| 1283 | proof | |
| 23389 | 1284 | assume "True \<Longrightarrow> PROP P" | 
| 1285 | from this [OF TrueI] show "PROP P" . | |
| 21151 | 1286 | next | 
| 1287 | assume "PROP P" | |
| 23389 | 1288 | then show "PROP P" . | 
| 21151 | 1289 | qed | 
| 1290 | ||
| 1291 | lemma ex_simps: | |
| 1292 | "!!P Q. (EX x. P x & Q) = ((EX x. P x) & Q)" | |
| 1293 | "!!P Q. (EX x. P & Q x) = (P & (EX x. Q x))" | |
| 1294 | "!!P Q. (EX x. P x | Q) = ((EX x. P x) | Q)" | |
| 1295 | "!!P Q. (EX x. P | Q x) = (P | (EX x. Q x))" | |
| 1296 | "!!P Q. (EX x. P x --> Q) = ((ALL x. P x) --> Q)" | |
| 1297 | "!!P Q. (EX x. P --> Q x) = (P --> (EX x. Q x))" | |
| 1298 |   -- {* Miniscoping: pushing in existential quantifiers. *}
 | |
| 1299 | by (iprover | blast)+ | |
| 1300 | ||
| 1301 | lemma all_simps: | |
| 1302 | "!!P Q. (ALL x. P x & Q) = ((ALL x. P x) & Q)" | |
| 1303 | "!!P Q. (ALL x. P & Q x) = (P & (ALL x. Q x))" | |
| 1304 | "!!P Q. (ALL x. P x | Q) = ((ALL x. P x) | Q)" | |
| 1305 | "!!P Q. (ALL x. P | Q x) = (P | (ALL x. Q x))" | |
| 1306 | "!!P Q. (ALL x. P x --> Q) = ((EX x. P x) --> Q)" | |
| 1307 | "!!P Q. (ALL x. P --> Q x) = (P --> (ALL x. Q x))" | |
| 1308 |   -- {* Miniscoping: pushing in universal quantifiers. *}
 | |
| 1309 | by (iprover | blast)+ | |
| 15481 | 1310 | |
| 21671 | 1311 | lemmas [simp] = | 
| 1312 | triv_forall_equality (*prunes params*) | |
| 1313 | True_implies_equals (*prune asms `True'*) | |
| 1314 | if_True | |
| 1315 | if_False | |
| 1316 | if_cancel | |
| 1317 | if_eq_cancel | |
| 1318 | imp_disjL | |
| 20973 | 1319 | (*In general it seems wrong to add distributive laws by default: they | 
| 1320 | might cause exponential blow-up. But imp_disjL has been in for a while | |
| 1321 | and cannot be removed without affecting existing proofs. Moreover, | |
| 1322 | rewriting by "(P|Q --> R) = ((P-->R)&(Q-->R))" might be justified on the | |
| 1323 | grounds that it allows simplification of R in the two cases.*) | |
| 21671 | 1324 | conj_assoc | 
| 1325 | disj_assoc | |
| 1326 | de_Morgan_conj | |
| 1327 | de_Morgan_disj | |
| 1328 | imp_disj1 | |
| 1329 | imp_disj2 | |
| 1330 | not_imp | |
| 1331 | disj_not1 | |
| 1332 | not_all | |
| 1333 | not_ex | |
| 1334 | cases_simp | |
| 1335 | the_eq_trivial | |
| 1336 | the_sym_eq_trivial | |
| 1337 | ex_simps | |
| 1338 | all_simps | |
| 1339 | simp_thms | |
| 1340 | ||
| 1341 | lemmas [cong] = imp_cong simp_implies_cong | |
| 1342 | lemmas [split] = split_if | |
| 20973 | 1343 | |
| 22377 | 1344 | ML {* val HOL_ss = @{simpset} *}
 | 
| 20973 | 1345 | |
| 20944 | 1346 | text {* Simplifies x assuming c and y assuming ~c *}
 | 
| 1347 | lemma if_cong: | |
| 1348 | assumes "b = c" | |
| 1349 | and "c \<Longrightarrow> x = u" | |
| 1350 | and "\<not> c \<Longrightarrow> y = v" | |
| 1351 | shows "(if b then x else y) = (if c then u else v)" | |
| 23553 | 1352 | unfolding if_def using assms by simp | 
| 20944 | 1353 | |
| 1354 | text {* Prevents simplification of x and y:
 | |
| 1355 | faster and allows the execution of functional programs. *} | |
| 1356 | lemma if_weak_cong [cong]: | |
| 1357 | assumes "b = c" | |
| 1358 | shows "(if b then x else y) = (if c then x else y)" | |
| 23553 | 1359 | using assms by (rule arg_cong) | 
| 20944 | 1360 | |
| 1361 | text {* Prevents simplification of t: much faster *}
 | |
| 1362 | lemma let_weak_cong: | |
| 1363 | assumes "a = b" | |
| 1364 | shows "(let x = a in t x) = (let x = b in t x)" | |
| 23553 | 1365 | using assms by (rule arg_cong) | 
| 20944 | 1366 | |
| 1367 | text {* To tidy up the result of a simproc.  Only the RHS will be simplified. *}
 | |
| 1368 | lemma eq_cong2: | |
| 1369 | assumes "u = u'" | |
| 1370 | shows "(t \<equiv> u) \<equiv> (t \<equiv> u')" | |
| 23553 | 1371 | using assms by simp | 
| 20944 | 1372 | |
| 1373 | lemma if_distrib: | |
| 1374 | "f (if c then x else y) = (if c then f x else f y)" | |
| 1375 | by simp | |
| 1376 | ||
| 1377 | text {* This lemma restricts the effect of the rewrite rule u=v to the left-hand
 | |
| 21502 | 1378 |   side of an equality.  Used in @{text "{Integ,Real}/simproc.ML"} *}
 | 
| 20944 | 1379 | lemma restrict_to_left: | 
| 1380 | assumes "x = y" | |
| 1381 | shows "(x = z) = (y = z)" | |
| 23553 | 1382 | using assms by simp | 
| 20944 | 1383 | |
| 17459 | 1384 | |
| 20944 | 1385 | subsubsection {* Generic cases and induction *}
 | 
| 17459 | 1386 | |
| 20944 | 1387 | text {* Rule projections: *}
 | 
| 18887 | 1388 | |
| 20944 | 1389 | ML {*
 | 
| 32172 | 1390 | structure Project_Rule = Project_Rule | 
| 25388 | 1391 | ( | 
| 27126 
3ede9103de8e
eliminated obsolete case_split_thm -- use case_split;
 wenzelm parents: 
27107diff
changeset | 1392 |   val conjunct1 = @{thm conjunct1}
 | 
| 
3ede9103de8e
eliminated obsolete case_split_thm -- use case_split;
 wenzelm parents: 
27107diff
changeset | 1393 |   val conjunct2 = @{thm conjunct2}
 | 
| 
3ede9103de8e
eliminated obsolete case_split_thm -- use case_split;
 wenzelm parents: 
27107diff
changeset | 1394 |   val mp = @{thm mp}
 | 
| 25388 | 1395 | ) | 
| 17459 | 1396 | *} | 
| 1397 | ||
| 11824 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 wenzelm parents: 
11770diff
changeset | 1398 | constdefs | 
| 18457 | 1399 | induct_forall where "induct_forall P == \<forall>x. P x" | 
| 1400 | induct_implies where "induct_implies A B == A \<longrightarrow> B" | |
| 1401 | induct_equal where "induct_equal x y == x = y" | |
| 1402 | induct_conj where "induct_conj A B == A \<and> B" | |
| 11824 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 wenzelm parents: 
11770diff
changeset | 1403 | |
| 11989 | 1404 | lemma induct_forall_eq: "(!!x. P x) == Trueprop (induct_forall (\<lambda>x. P x))" | 
| 18457 | 1405 | by (unfold atomize_all induct_forall_def) | 
| 11824 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 wenzelm parents: 
11770diff
changeset | 1406 | |
| 11989 | 1407 | lemma induct_implies_eq: "(A ==> B) == Trueprop (induct_implies A B)" | 
| 18457 | 1408 | by (unfold atomize_imp induct_implies_def) | 
| 11824 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 wenzelm parents: 
11770diff
changeset | 1409 | |
| 11989 | 1410 | lemma induct_equal_eq: "(x == y) == Trueprop (induct_equal x y)" | 
| 18457 | 1411 | by (unfold atomize_eq induct_equal_def) | 
| 1412 | ||
| 28856 
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
 wenzelm parents: 
28741diff
changeset | 1413 | lemma induct_conj_eq: "(A &&& B) == Trueprop (induct_conj A B)" | 
| 18457 | 1414 | by (unfold atomize_conj induct_conj_def) | 
| 1415 | ||
| 1416 | lemmas induct_atomize = induct_forall_eq induct_implies_eq induct_equal_eq induct_conj_eq | |
| 1417 | lemmas induct_rulify [symmetric, standard] = induct_atomize | |
| 1418 | lemmas induct_rulify_fallback = | |
| 1419 | induct_forall_def induct_implies_def induct_equal_def induct_conj_def | |
| 1420 | ||
| 11824 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 wenzelm parents: 
11770diff
changeset | 1421 | |
| 11989 | 1422 | lemma induct_forall_conj: "induct_forall (\<lambda>x. induct_conj (A x) (B x)) = | 
| 1423 | induct_conj (induct_forall A) (induct_forall B)" | |
| 17589 | 1424 | by (unfold induct_forall_def induct_conj_def) iprover | 
| 11824 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 wenzelm parents: 
11770diff
changeset | 1425 | |
| 11989 | 1426 | lemma induct_implies_conj: "induct_implies C (induct_conj A B) = | 
| 1427 | induct_conj (induct_implies C A) (induct_implies C B)" | |
| 17589 | 1428 | by (unfold induct_implies_def induct_conj_def) iprover | 
| 11989 | 1429 | |
| 13598 
8bc77b17f59f
Fixed problem with induct_conj_curry: variable C should have type prop.
 berghofe parents: 
13596diff
changeset | 1430 | lemma induct_conj_curry: "(induct_conj A B ==> PROP C) == (A ==> B ==> PROP C)" | 
| 
8bc77b17f59f
Fixed problem with induct_conj_curry: variable C should have type prop.
 berghofe parents: 
13596diff
changeset | 1431 | proof | 
| 
8bc77b17f59f
Fixed problem with induct_conj_curry: variable C should have type prop.
 berghofe parents: 
13596diff
changeset | 1432 | assume r: "induct_conj A B ==> PROP C" and A B | 
| 18457 | 1433 | show "PROP C" by (rule r) (simp add: induct_conj_def `A` `B`) | 
| 13598 
8bc77b17f59f
Fixed problem with induct_conj_curry: variable C should have type prop.
 berghofe parents: 
13596diff
changeset | 1434 | next | 
| 
8bc77b17f59f
Fixed problem with induct_conj_curry: variable C should have type prop.
 berghofe parents: 
13596diff
changeset | 1435 | assume r: "A ==> B ==> PROP C" and "induct_conj A B" | 
| 18457 | 1436 | show "PROP C" by (rule r) (simp_all add: `induct_conj A B` [unfolded induct_conj_def]) | 
| 13598 
8bc77b17f59f
Fixed problem with induct_conj_curry: variable C should have type prop.
 berghofe parents: 
13596diff
changeset | 1437 | qed | 
| 11824 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 wenzelm parents: 
11770diff
changeset | 1438 | |
| 11989 | 1439 | lemmas induct_conj = induct_forall_conj induct_implies_conj induct_conj_curry | 
| 11824 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 wenzelm parents: 
11770diff
changeset | 1440 | |
| 11989 | 1441 | hide const induct_forall induct_implies induct_equal induct_conj | 
| 11824 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 wenzelm parents: 
11770diff
changeset | 1442 | |
| 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 wenzelm parents: 
11770diff
changeset | 1443 | text {* Method setup. *}
 | 
| 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 wenzelm parents: 
11770diff
changeset | 1444 | |
| 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 wenzelm parents: 
11770diff
changeset | 1445 | ML {*
 | 
| 32171 | 1446 | structure Induct = Induct | 
| 27126 
3ede9103de8e
eliminated obsolete case_split_thm -- use case_split;
 wenzelm parents: 
27107diff
changeset | 1447 | ( | 
| 
3ede9103de8e
eliminated obsolete case_split_thm -- use case_split;
 wenzelm parents: 
27107diff
changeset | 1448 |   val cases_default = @{thm case_split}
 | 
| 
3ede9103de8e
eliminated obsolete case_split_thm -- use case_split;
 wenzelm parents: 
27107diff
changeset | 1449 |   val atomize = @{thms induct_atomize}
 | 
| 
3ede9103de8e
eliminated obsolete case_split_thm -- use case_split;
 wenzelm parents: 
27107diff
changeset | 1450 |   val rulify = @{thms induct_rulify}
 | 
| 
3ede9103de8e
eliminated obsolete case_split_thm -- use case_split;
 wenzelm parents: 
27107diff
changeset | 1451 |   val rulify_fallback = @{thms induct_rulify_fallback}
 | 
| 
3ede9103de8e
eliminated obsolete case_split_thm -- use case_split;
 wenzelm parents: 
27107diff
changeset | 1452 | ) | 
| 11824 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 wenzelm parents: 
11770diff
changeset | 1453 | *} | 
| 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 wenzelm parents: 
11770diff
changeset | 1454 | |
| 24830 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
 wenzelm parents: 
24748diff
changeset | 1455 | setup Induct.setup | 
| 18457 | 1456 | |
| 27326 
d3beec370964
moved src/HOL/Tools/induct_tacs.ML to src/Tools/induct_tacs.ML;
 wenzelm parents: 
27212diff
changeset | 1457 | use "~~/src/Tools/induct_tacs.ML" | 
| 27126 
3ede9103de8e
eliminated obsolete case_split_thm -- use case_split;
 wenzelm parents: 
27107diff
changeset | 1458 | setup InductTacs.setup | 
| 
3ede9103de8e
eliminated obsolete case_split_thm -- use case_split;
 wenzelm parents: 
27107diff
changeset | 1459 | |
| 20944 | 1460 | |
| 28325 | 1461 | subsubsection {* Coherent logic *}
 | 
| 1462 | ||
| 1463 | ML {*
 | |
| 32734 | 1464 | structure Coherent = Coherent | 
| 28325 | 1465 | ( | 
| 1466 |   val atomize_elimL = @{thm atomize_elimL}
 | |
| 1467 |   val atomize_exL = @{thm atomize_exL}
 | |
| 1468 |   val atomize_conjL = @{thm atomize_conjL}
 | |
| 1469 |   val atomize_disjL = @{thm atomize_disjL}
 | |
| 1470 | val operator_names = | |
| 1471 |     [@{const_name "op |"}, @{const_name "op &"}, @{const_name "Ex"}]
 | |
| 1472 | ); | |
| 1473 | *} | |
| 1474 | ||
| 1475 | setup Coherent.setup | |
| 1476 | ||
| 1477 | ||
| 31024 
0fdf666e08bf
reimplement reorientation simproc using theory data
 huffman parents: 
30980diff
changeset | 1478 | subsubsection {* Reorienting equalities *}
 | 
| 
0fdf666e08bf
reimplement reorientation simproc using theory data
 huffman parents: 
30980diff
changeset | 1479 | |
| 
0fdf666e08bf
reimplement reorientation simproc using theory data
 huffman parents: 
30980diff
changeset | 1480 | ML {*
 | 
| 
0fdf666e08bf
reimplement reorientation simproc using theory data
 huffman parents: 
30980diff
changeset | 1481 | signature REORIENT_PROC = | 
| 
0fdf666e08bf
reimplement reorientation simproc using theory data
 huffman parents: 
30980diff
changeset | 1482 | sig | 
| 
0fdf666e08bf
reimplement reorientation simproc using theory data
 huffman parents: 
30980diff
changeset | 1483 | val add : (term -> bool) -> theory -> theory | 
| 
0fdf666e08bf
reimplement reorientation simproc using theory data
 huffman parents: 
30980diff
changeset | 1484 | val proc : morphism -> simpset -> cterm -> thm option | 
| 
0fdf666e08bf
reimplement reorientation simproc using theory data
 huffman parents: 
30980diff
changeset | 1485 | end; | 
| 
0fdf666e08bf
reimplement reorientation simproc using theory data
 huffman parents: 
30980diff
changeset | 1486 | |
| 33523 | 1487 | structure Reorient_Proc : REORIENT_PROC = | 
| 31024 
0fdf666e08bf
reimplement reorientation simproc using theory data
 huffman parents: 
30980diff
changeset | 1488 | struct | 
| 33523 | 1489 | structure Data = Theory_Data | 
| 31024 
0fdf666e08bf
reimplement reorientation simproc using theory data
 huffman parents: 
30980diff
changeset | 1490 | ( | 
| 33523 | 1491 | type T = ((term -> bool) * stamp) list; | 
| 1492 | val empty = []; | |
| 31024 
0fdf666e08bf
reimplement reorientation simproc using theory data
 huffman parents: 
30980diff
changeset | 1493 | val extend = I; | 
| 33523 | 1494 | fun merge data : T = Library.merge (eq_snd op =) data; | 
| 1495 | ); | |
| 1496 | fun add m = Data.map (cons (m, stamp ())); | |
| 1497 | fun matches thy t = exists (fn (m, _) => m t) (Data.get thy); | |
| 31024 
0fdf666e08bf
reimplement reorientation simproc using theory data
 huffman parents: 
30980diff
changeset | 1498 | |
| 
0fdf666e08bf
reimplement reorientation simproc using theory data
 huffman parents: 
30980diff
changeset | 1499 |   val meta_reorient = @{thm eq_commute [THEN eq_reflection]};
 | 
| 
0fdf666e08bf
reimplement reorientation simproc using theory data
 huffman parents: 
30980diff
changeset | 1500 | fun proc phi ss ct = | 
| 
0fdf666e08bf
reimplement reorientation simproc using theory data
 huffman parents: 
30980diff
changeset | 1501 | let | 
| 
0fdf666e08bf
reimplement reorientation simproc using theory data
 huffman parents: 
30980diff
changeset | 1502 | val ctxt = Simplifier.the_context ss; | 
| 
0fdf666e08bf
reimplement reorientation simproc using theory data
 huffman parents: 
30980diff
changeset | 1503 | val thy = ProofContext.theory_of ctxt; | 
| 
0fdf666e08bf
reimplement reorientation simproc using theory data
 huffman parents: 
30980diff
changeset | 1504 | in | 
| 
0fdf666e08bf
reimplement reorientation simproc using theory data
 huffman parents: 
30980diff
changeset | 1505 | case Thm.term_of ct of | 
| 33523 | 1506 | (_ $ t $ u) => if matches thy u then NONE else SOME meta_reorient | 
| 31024 
0fdf666e08bf
reimplement reorientation simproc using theory data
 huffman parents: 
30980diff
changeset | 1507 | | _ => NONE | 
| 
0fdf666e08bf
reimplement reorientation simproc using theory data
 huffman parents: 
30980diff
changeset | 1508 | end; | 
| 
0fdf666e08bf
reimplement reorientation simproc using theory data
 huffman parents: 
30980diff
changeset | 1509 | end; | 
| 
0fdf666e08bf
reimplement reorientation simproc using theory data
 huffman parents: 
30980diff
changeset | 1510 | *} | 
| 
0fdf666e08bf
reimplement reorientation simproc using theory data
 huffman parents: 
30980diff
changeset | 1511 | |
| 
0fdf666e08bf
reimplement reorientation simproc using theory data
 huffman parents: 
30980diff
changeset | 1512 | |
| 20944 | 1513 | subsection {* Other simple lemmas and lemma duplicates *}
 | 
| 1514 | ||
| 1515 | lemma ex1_eq [iff]: "EX! x. x = t" "EX! x. t = x" | |
| 1516 | by blast+ | |
| 1517 | ||
| 1518 | lemma choice_eq: "(ALL x. EX! y. P x y) = (EX! f. ALL x. P x (f x))" | |
| 1519 | apply (rule iffI) | |
| 1520 | apply (rule_tac a = "%x. THE y. P x y" in ex1I) | |
| 1521 | apply (fast dest!: theI') | |
| 1522 | apply (fast intro: ext the1_equality [symmetric]) | |
| 1523 | apply (erule ex1E) | |
| 1524 | apply (rule allI) | |
| 1525 | apply (rule ex1I) | |
| 1526 | apply (erule spec) | |
| 1527 | apply (erule_tac x = "%z. if z = x then y else f z" in allE) | |
| 1528 | apply (erule impE) | |
| 1529 | apply (rule allI) | |
| 27126 
3ede9103de8e
eliminated obsolete case_split_thm -- use case_split;
 wenzelm parents: 
27107diff
changeset | 1530 | apply (case_tac "xa = x") | 
| 20944 | 1531 | apply (drule_tac [3] x = x in fun_cong, simp_all) | 
| 1532 | done | |
| 1533 | ||
| 22218 | 1534 | lemmas eq_sym_conv = eq_commute | 
| 1535 | ||
| 23037 
6c72943a71b1
added a set of NNF normalization lemmas and nnf_conv
 chaieb parents: 
22993diff
changeset | 1536 | lemma nnf_simps: | 
| 
6c72943a71b1
added a set of NNF normalization lemmas and nnf_conv
 chaieb parents: 
22993diff
changeset | 1537 | "(\<not>(P \<and> Q)) = (\<not> P \<or> \<not> Q)" "(\<not> (P \<or> Q)) = (\<not> P \<and> \<not>Q)" "(P \<longrightarrow> Q) = (\<not>P \<or> Q)" | 
| 
6c72943a71b1
added a set of NNF normalization lemmas and nnf_conv
 chaieb parents: 
22993diff
changeset | 1538 | "(P = Q) = ((P \<and> Q) \<or> (\<not>P \<and> \<not> Q))" "(\<not>(P = Q)) = ((P \<and> \<not> Q) \<or> (\<not>P \<and> Q))" | 
| 
6c72943a71b1
added a set of NNF normalization lemmas and nnf_conv
 chaieb parents: 
22993diff
changeset | 1539 | "(\<not> \<not>(P)) = P" | 
| 
6c72943a71b1
added a set of NNF normalization lemmas and nnf_conv
 chaieb parents: 
22993diff
changeset | 1540 | by blast+ | 
| 
6c72943a71b1
added a set of NNF normalization lemmas and nnf_conv
 chaieb parents: 
22993diff
changeset | 1541 | |
| 21671 | 1542 | |
| 32119 | 1543 | subsection {* Generic classes and algebraic operations *}
 | 
| 1544 | ||
| 1545 | class zero = | |
| 1546 |   fixes zero :: 'a  ("0")
 | |
| 1547 | ||
| 1548 | class one = | |
| 1549 |   fixes one  :: 'a  ("1")
 | |
| 1550 | ||
| 1551 | lemma Let_0 [simp]: "Let 0 f = f 0" | |
| 1552 | unfolding Let_def .. | |
| 1553 | ||
| 1554 | lemma Let_1 [simp]: "Let 1 f = f 1" | |
| 1555 | unfolding Let_def .. | |
| 1556 | ||
| 1557 | setup {*
 | |
| 33523 | 1558 | Reorient_Proc.add | 
| 32119 | 1559 |     (fn Const(@{const_name HOL.zero}, _) => true
 | 
| 1560 |       | Const(@{const_name HOL.one}, _) => true
 | |
| 1561 | | _ => false) | |
| 1562 | *} | |
| 1563 | ||
| 33523 | 1564 | simproc_setup reorient_zero ("0 = x") = Reorient_Proc.proc
 | 
| 1565 | simproc_setup reorient_one ("1 = x") = Reorient_Proc.proc
 | |
| 32119 | 1566 | |
| 1567 | typed_print_translation {*
 | |
| 1568 | let | |
| 1569 | fun tr' c = (c, fn show_sorts => fn T => fn ts => | |
| 1570 | if (not o null) ts orelse T = dummyT | |
| 1571 | orelse not (! show_types) andalso can Term.dest_Type T | |
| 1572 | then raise Match | |
| 1573 | else Syntax.const Syntax.constrainC $ Syntax.const c $ Syntax.term_of_typ show_sorts T); | |
| 1574 | in map tr' [@{const_syntax HOL.one}, @{const_syntax HOL.zero}] end;
 | |
| 1575 | *} -- {* show types that are presumably too general *}
 | |
| 1576 | ||
| 1577 | hide (open) const zero one | |
| 1578 | ||
| 1579 | class plus = | |
| 1580 | fixes plus :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "+" 65) | |
| 1581 | ||
| 1582 | class minus = | |
| 1583 | fixes minus :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "-" 65) | |
| 1584 | ||
| 1585 | class uminus = | |
| 1586 |   fixes uminus :: "'a \<Rightarrow> 'a"  ("- _" [81] 80)
 | |
| 1587 | ||
| 1588 | class times = | |
| 1589 | fixes times :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "*" 70) | |
| 1590 | ||
| 1591 | class inverse = | |
| 1592 | fixes inverse :: "'a \<Rightarrow> 'a" | |
| 1593 | and divide :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "'/" 70) | |
| 1594 | ||
| 1595 | class abs = | |
| 1596 | fixes abs :: "'a \<Rightarrow> 'a" | |
| 1597 | begin | |
| 1598 | ||
| 1599 | notation (xsymbols) | |
| 1600 |   abs  ("\<bar>_\<bar>")
 | |
| 1601 | ||
| 1602 | notation (HTML output) | |
| 1603 |   abs  ("\<bar>_\<bar>")
 | |
| 1604 | ||
| 1605 | end | |
| 1606 | ||
| 1607 | class sgn = | |
| 1608 | fixes sgn :: "'a \<Rightarrow> 'a" | |
| 1609 | ||
| 1610 | class ord = | |
| 1611 | fixes less_eq :: "'a \<Rightarrow> 'a \<Rightarrow> bool" | |
| 1612 | and less :: "'a \<Rightarrow> 'a \<Rightarrow> bool" | |
| 1613 | begin | |
| 1614 | ||
| 1615 | notation | |
| 1616 |   less_eq  ("op <=") and
 | |
| 1617 |   less_eq  ("(_/ <= _)" [51, 51] 50) and
 | |
| 1618 |   less  ("op <") and
 | |
| 1619 |   less  ("(_/ < _)"  [51, 51] 50)
 | |
| 1620 | ||
| 1621 | notation (xsymbols) | |
| 1622 |   less_eq  ("op \<le>") and
 | |
| 1623 |   less_eq  ("(_/ \<le> _)"  [51, 51] 50)
 | |
| 1624 | ||
| 1625 | notation (HTML output) | |
| 1626 |   less_eq  ("op \<le>") and
 | |
| 1627 |   less_eq  ("(_/ \<le> _)"  [51, 51] 50)
 | |
| 1628 | ||
| 1629 | abbreviation (input) | |
| 1630 | greater_eq (infix ">=" 50) where | |
| 1631 | "x >= y \<equiv> y <= x" | |
| 1632 | ||
| 1633 | notation (input) | |
| 1634 | greater_eq (infix "\<ge>" 50) | |
| 1635 | ||
| 1636 | abbreviation (input) | |
| 1637 | greater (infix ">" 50) where | |
| 1638 | "x > y \<equiv> y < x" | |
| 1639 | ||
| 1640 | end | |
| 1641 | ||
| 1642 | syntax | |
| 1643 |   "_index1"  :: index    ("\<^sub>1")
 | |
| 1644 | translations | |
| 1645 | (index) "\<^sub>1" => (index) "\<^bsub>\<struct>\<^esub>" | |
| 1646 | ||
| 1647 | lemma mk_left_commute: | |
| 1648 | fixes f (infix "\<otimes>" 60) | |
| 1649 | assumes a: "\<And>x y z. (x \<otimes> y) \<otimes> z = x \<otimes> (y \<otimes> z)" and | |
| 1650 | c: "\<And>x y. x \<otimes> y = y \<otimes> x" | |
| 1651 | shows "x \<otimes> (y \<otimes> z) = y \<otimes> (x \<otimes> z)" | |
| 1652 | by (rule trans [OF trans [OF c a] arg_cong [OF c, of "f y"]]) | |
| 1653 | ||
| 1654 | ||
| 21671 | 1655 | subsection {* Basic ML bindings *}
 | 
| 1656 | ||
| 1657 | ML {*
 | |
| 22129 | 1658 | val FalseE = @{thm FalseE}
 | 
| 1659 | val Let_def = @{thm Let_def}
 | |
| 1660 | val TrueI = @{thm TrueI}
 | |
| 1661 | val allE = @{thm allE}
 | |
| 1662 | val allI = @{thm allI}
 | |
| 1663 | val all_dupE = @{thm all_dupE}
 | |
| 1664 | val arg_cong = @{thm arg_cong}
 | |
| 1665 | val box_equals = @{thm box_equals}
 | |
| 1666 | val ccontr = @{thm ccontr}
 | |
| 1667 | val classical = @{thm classical}
 | |
| 1668 | val conjE = @{thm conjE}
 | |
| 1669 | val conjI = @{thm conjI}
 | |
| 1670 | val conjunct1 = @{thm conjunct1}
 | |
| 1671 | val conjunct2 = @{thm conjunct2}
 | |
| 1672 | val disjCI = @{thm disjCI}
 | |
| 1673 | val disjE = @{thm disjE}
 | |
| 1674 | val disjI1 = @{thm disjI1}
 | |
| 1675 | val disjI2 = @{thm disjI2}
 | |
| 1676 | val eq_reflection = @{thm eq_reflection}
 | |
| 1677 | val ex1E = @{thm ex1E}
 | |
| 1678 | val ex1I = @{thm ex1I}
 | |
| 1679 | val ex1_implies_ex = @{thm ex1_implies_ex}
 | |
| 1680 | val exE = @{thm exE}
 | |
| 1681 | val exI = @{thm exI}
 | |
| 1682 | val excluded_middle = @{thm excluded_middle}
 | |
| 1683 | val ext = @{thm ext}
 | |
| 1684 | val fun_cong = @{thm fun_cong}
 | |
| 1685 | val iffD1 = @{thm iffD1}
 | |
| 1686 | val iffD2 = @{thm iffD2}
 | |
| 1687 | val iffI = @{thm iffI}
 | |
| 1688 | val impE = @{thm impE}
 | |
| 1689 | val impI = @{thm impI}
 | |
| 1690 | val meta_eq_to_obj_eq = @{thm meta_eq_to_obj_eq}
 | |
| 1691 | val mp = @{thm mp}
 | |
| 1692 | val notE = @{thm notE}
 | |
| 1693 | val notI = @{thm notI}
 | |
| 1694 | val not_all = @{thm not_all}
 | |
| 1695 | val not_ex = @{thm not_ex}
 | |
| 1696 | val not_iff = @{thm not_iff}
 | |
| 1697 | val not_not = @{thm not_not}
 | |
| 1698 | val not_sym = @{thm not_sym}
 | |
| 1699 | val refl = @{thm refl}
 | |
| 1700 | val rev_mp = @{thm rev_mp}
 | |
| 1701 | val spec = @{thm spec}
 | |
| 1702 | val ssubst = @{thm ssubst}
 | |
| 1703 | val subst = @{thm subst}
 | |
| 1704 | val sym = @{thm sym}
 | |
| 1705 | val trans = @{thm trans}
 | |
| 21671 | 1706 | *} | 
| 1707 | ||
| 1708 | ||
| 30929 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1709 | subsection {* Code generator setup *}
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1710 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1711 | subsubsection {* SML code generator setup *}
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1712 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1713 | use "Tools/recfun_codegen.ML" | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1714 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1715 | setup {*
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1716 | Codegen.setup | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1717 | #> RecfunCodegen.setup | 
| 32068 | 1718 | #> Codegen.map_unfold (K HOL_basic_ss) | 
| 30929 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1719 | *} | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1720 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1721 | types_code | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1722 |   "bool"  ("bool")
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1723 | attach (term_of) {*
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1724 | fun term_of_bool b = if b then HOLogic.true_const else HOLogic.false_const; | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1725 | *} | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1726 | attach (test) {*
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1727 | fun gen_bool i = | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1728 | let val b = one_of [false, true] | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1729 | in (b, fn () => term_of_bool b) end; | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1730 | *} | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1731 |   "prop"  ("bool")
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1732 | attach (term_of) {*
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1733 | fun term_of_prop b = | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1734 | HOLogic.mk_Trueprop (if b then HOLogic.true_const else HOLogic.false_const); | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1735 | *} | 
| 28400 | 1736 | |
| 30929 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1737 | consts_code | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1738 |   "Trueprop" ("(_)")
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1739 |   "True"    ("true")
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1740 |   "False"   ("false")
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1741 |   "Not"     ("Bool.not")
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1742 |   "op |"    ("(_ orelse/ _)")
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1743 |   "op &"    ("(_ andalso/ _)")
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1744 |   "If"      ("(if _/ then _/ else _)")
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1745 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1746 | setup {*
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1747 | let | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1748 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1749 | fun eq_codegen thy defs dep thyname b t gr = | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1750 | (case strip_comb t of | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1751 |        (Const ("op =", Type (_, [Type ("fun", _), _])), _) => NONE
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1752 |      | (Const ("op =", _), [t, u]) =>
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1753 | let | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1754 | val (pt, gr') = Codegen.invoke_codegen thy defs dep thyname false t gr; | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1755 | val (pu, gr'') = Codegen.invoke_codegen thy defs dep thyname false u gr'; | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1756 | val (_, gr''') = Codegen.invoke_tycodegen thy defs dep thyname false HOLogic.boolT gr''; | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1757 | in | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1758 | SOME (Codegen.parens | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1759 | (Pretty.block [pt, Codegen.str " =", Pretty.brk 1, pu]), gr''') | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1760 | end | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1761 |      | (t as Const ("op =", _), ts) => SOME (Codegen.invoke_codegen
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1762 | thy defs dep thyname b (Codegen.eta_expand t ts 2) gr) | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1763 | | _ => NONE); | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1764 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1765 | in | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1766 | Codegen.add_codegen "eq_codegen" eq_codegen | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1767 | end | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1768 | *} | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1769 | |
| 31151 | 1770 | subsubsection {* Generic code generator preprocessor setup *}
 | 
| 1771 | ||
| 1772 | setup {*
 | |
| 1773 | Code_Preproc.map_pre (K HOL_basic_ss) | |
| 1774 | #> Code_Preproc.map_post (K HOL_basic_ss) | |
| 1775 | *} | |
| 1776 | ||
| 30929 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1777 | subsubsection {* Equality *}
 | 
| 24844 
98c006a30218
certificates for code generator case expressions
 haftmann parents: 
24842diff
changeset | 1778 | |
| 29608 | 1779 | class eq = | 
| 26513 | 1780 | fixes eq :: "'a \<Rightarrow> 'a \<Rightarrow> bool" | 
| 28400 | 1781 | assumes eq_equals: "eq x y \<longleftrightarrow> x = y" | 
| 26513 | 1782 | begin | 
| 1783 | ||
| 31998 
2c7a24f74db9
code attributes use common underscore convention
 haftmann parents: 
31956diff
changeset | 1784 | lemma eq [code_unfold, code_inline del]: "eq = (op =)" | 
| 28346 
b8390cd56b8f
discontinued special treatment of op = vs. eq_class.eq
 haftmann parents: 
28325diff
changeset | 1785 | by (rule ext eq_equals)+ | 
| 
b8390cd56b8f
discontinued special treatment of op = vs. eq_class.eq
 haftmann parents: 
28325diff
changeset | 1786 | |
| 
b8390cd56b8f
discontinued special treatment of op = vs. eq_class.eq
 haftmann parents: 
28325diff
changeset | 1787 | lemma eq_refl: "eq x x \<longleftrightarrow> True" | 
| 
b8390cd56b8f
discontinued special treatment of op = vs. eq_class.eq
 haftmann parents: 
28325diff
changeset | 1788 | unfolding eq by rule+ | 
| 
b8390cd56b8f
discontinued special treatment of op = vs. eq_class.eq
 haftmann parents: 
28325diff
changeset | 1789 | |
| 31151 | 1790 | lemma equals_eq: "(op =) \<equiv> eq" | 
| 30929 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1791 | by (rule eq_reflection) (rule ext, rule ext, rule sym, rule eq_equals) | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1792 | |
| 31998 
2c7a24f74db9
code attributes use common underscore convention
 haftmann parents: 
31956diff
changeset | 1793 | declare equals_eq [symmetric, code_post] | 
| 30929 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1794 | |
| 26513 | 1795 | end | 
| 1796 | ||
| 30966 | 1797 | declare equals_eq [code] | 
| 1798 | ||
| 31151 | 1799 | setup {*
 | 
| 1800 | Code_Preproc.map_pre (fn simpset => | |
| 1801 |     simpset addsimprocs [Simplifier.simproc_i @{theory} "eq" [@{term "op ="}]
 | |
| 1802 | (fn thy => fn _ => fn t as Const (_, T) => case strip_type T | |
| 1803 |         of ((T as Type _) :: _, _) => SOME @{thm equals_eq}
 | |
| 1804 | | _ => NONE)]) | |
| 1805 | *} | |
| 1806 | ||
| 30966 | 1807 | |
| 30929 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1808 | subsubsection {* Generic code generator foundation *}
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1809 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1810 | text {* Datatypes *}
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1811 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1812 | code_datatype True False | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1813 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1814 | code_datatype "TYPE('a\<Colon>{})"
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1815 | |
| 33364 | 1816 | code_datatype "prop" Trueprop | 
| 30929 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1817 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1818 | text {* Code equations *}
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1819 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1820 | lemma [code]: | 
| 33185 
247f6c6969d9
tuned code setup for primitive boolean connectors
 haftmann parents: 
33084diff
changeset | 1821 | shows "(False \<Longrightarrow> P) \<equiv> Trueprop True" | 
| 
247f6c6969d9
tuned code setup for primitive boolean connectors
 haftmann parents: 
33084diff
changeset | 1822 | and "(True \<Longrightarrow> PROP Q) \<equiv> PROP Q" | 
| 
247f6c6969d9
tuned code setup for primitive boolean connectors
 haftmann parents: 
33084diff
changeset | 1823 | and "(P \<Longrightarrow> False) \<equiv> Trueprop (\<not> P)" | 
| 
247f6c6969d9
tuned code setup for primitive boolean connectors
 haftmann parents: 
33084diff
changeset | 1824 | and "(PROP Q \<Longrightarrow> True) \<equiv> Trueprop True" by (auto intro!: equal_intr_rule) | 
| 30929 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1825 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1826 | lemma [code]: | 
| 33185 
247f6c6969d9
tuned code setup for primitive boolean connectors
 haftmann parents: 
33084diff
changeset | 1827 | shows "False \<and> P \<longleftrightarrow> False" | 
| 
247f6c6969d9
tuned code setup for primitive boolean connectors
 haftmann parents: 
33084diff
changeset | 1828 | and "True \<and> P \<longleftrightarrow> P" | 
| 
247f6c6969d9
tuned code setup for primitive boolean connectors
 haftmann parents: 
33084diff
changeset | 1829 | and "P \<and> False \<longleftrightarrow> False" | 
| 
247f6c6969d9
tuned code setup for primitive boolean connectors
 haftmann parents: 
33084diff
changeset | 1830 | and "P \<and> True \<longleftrightarrow> P" by simp_all | 
| 30929 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1831 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1832 | lemma [code]: | 
| 33185 
247f6c6969d9
tuned code setup for primitive boolean connectors
 haftmann parents: 
33084diff
changeset | 1833 | shows "False \<or> P \<longleftrightarrow> P" | 
| 
247f6c6969d9
tuned code setup for primitive boolean connectors
 haftmann parents: 
33084diff
changeset | 1834 | and "True \<or> P \<longleftrightarrow> True" | 
| 
247f6c6969d9
tuned code setup for primitive boolean connectors
 haftmann parents: 
33084diff
changeset | 1835 | and "P \<or> False \<longleftrightarrow> P" | 
| 
247f6c6969d9
tuned code setup for primitive boolean connectors
 haftmann parents: 
33084diff
changeset | 1836 | and "P \<or> True \<longleftrightarrow> True" by simp_all | 
| 30929 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1837 | |
| 33185 
247f6c6969d9
tuned code setup for primitive boolean connectors
 haftmann parents: 
33084diff
changeset | 1838 | lemma [code]: | 
| 
247f6c6969d9
tuned code setup for primitive boolean connectors
 haftmann parents: 
33084diff
changeset | 1839 | shows "(False \<longrightarrow> P) \<longleftrightarrow> True" | 
| 
247f6c6969d9
tuned code setup for primitive boolean connectors
 haftmann parents: 
33084diff
changeset | 1840 | and "(True \<longrightarrow> P) \<longleftrightarrow> P" | 
| 
247f6c6969d9
tuned code setup for primitive boolean connectors
 haftmann parents: 
33084diff
changeset | 1841 | and "(P \<longrightarrow> False) \<longleftrightarrow> \<not> P" | 
| 
247f6c6969d9
tuned code setup for primitive boolean connectors
 haftmann parents: 
33084diff
changeset | 1842 | and "(P \<longrightarrow> True) \<longleftrightarrow> True" by simp_all | 
| 30929 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1843 | |
| 31132 | 1844 | instantiation itself :: (type) eq | 
| 1845 | begin | |
| 1846 | ||
| 1847 | definition eq_itself :: "'a itself \<Rightarrow> 'a itself \<Rightarrow> bool" where | |
| 1848 | "eq_itself x y \<longleftrightarrow> x = y" | |
| 1849 | ||
| 1850 | instance proof | |
| 1851 | qed (fact eq_itself_def) | |
| 1852 | ||
| 1853 | end | |
| 1854 | ||
| 1855 | lemma eq_itself_code [code]: | |
| 1856 |   "eq_class.eq TYPE('a) TYPE('a) \<longleftrightarrow> True"
 | |
| 1857 | by (simp add: eq) | |
| 1858 | ||
| 30929 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1859 | text {* Equality *}
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1860 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1861 | declare simp_thms(6) [code nbe] | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1862 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1863 | setup {*
 | 
| 31956 
c3844c4d0c2c
more accurate certificates for constant aliasses
 haftmann parents: 
31902diff
changeset | 1864 |   Sign.add_const_constraint (@{const_name eq}, SOME @{typ "'a\<Colon>type \<Rightarrow> 'a \<Rightarrow> bool"})
 | 
| 
c3844c4d0c2c
more accurate certificates for constant aliasses
 haftmann parents: 
31902diff
changeset | 1865 | *} | 
| 
c3844c4d0c2c
more accurate certificates for constant aliasses
 haftmann parents: 
31902diff
changeset | 1866 | |
| 
c3844c4d0c2c
more accurate certificates for constant aliasses
 haftmann parents: 
31902diff
changeset | 1867 | lemma equals_alias_cert: "OFCLASS('a, eq_class) \<equiv> ((op = :: 'a \<Rightarrow> 'a \<Rightarrow> bool) \<equiv> eq)" (is "?ofclass \<equiv> ?eq")
 | 
| 
c3844c4d0c2c
more accurate certificates for constant aliasses
 haftmann parents: 
31902diff
changeset | 1868 | proof | 
| 
c3844c4d0c2c
more accurate certificates for constant aliasses
 haftmann parents: 
31902diff
changeset | 1869 | assume "PROP ?ofclass" | 
| 
c3844c4d0c2c
more accurate certificates for constant aliasses
 haftmann parents: 
31902diff
changeset | 1870 | show "PROP ?eq" | 
| 
c3844c4d0c2c
more accurate certificates for constant aliasses
 haftmann parents: 
31902diff
changeset | 1871 |     by (tactic {* ALLGOALS (rtac (Drule.unconstrainTs @{thm equals_eq})) *}) 
 | 
| 
c3844c4d0c2c
more accurate certificates for constant aliasses
 haftmann parents: 
31902diff
changeset | 1872 | (fact `PROP ?ofclass`) | 
| 
c3844c4d0c2c
more accurate certificates for constant aliasses
 haftmann parents: 
31902diff
changeset | 1873 | next | 
| 
c3844c4d0c2c
more accurate certificates for constant aliasses
 haftmann parents: 
31902diff
changeset | 1874 | assume "PROP ?eq" | 
| 
c3844c4d0c2c
more accurate certificates for constant aliasses
 haftmann parents: 
31902diff
changeset | 1875 | show "PROP ?ofclass" proof | 
| 
c3844c4d0c2c
more accurate certificates for constant aliasses
 haftmann parents: 
31902diff
changeset | 1876 | qed (simp add: `PROP ?eq`) | 
| 
c3844c4d0c2c
more accurate certificates for constant aliasses
 haftmann parents: 
31902diff
changeset | 1877 | qed | 
| 
c3844c4d0c2c
more accurate certificates for constant aliasses
 haftmann parents: 
31902diff
changeset | 1878 | |
| 
c3844c4d0c2c
more accurate certificates for constant aliasses
 haftmann parents: 
31902diff
changeset | 1879 | setup {*
 | 
| 
c3844c4d0c2c
more accurate certificates for constant aliasses
 haftmann parents: 
31902diff
changeset | 1880 |   Sign.add_const_constraint (@{const_name eq}, SOME @{typ "'a\<Colon>eq \<Rightarrow> 'a \<Rightarrow> bool"})
 | 
| 
c3844c4d0c2c
more accurate certificates for constant aliasses
 haftmann parents: 
31902diff
changeset | 1881 | *} | 
| 
c3844c4d0c2c
more accurate certificates for constant aliasses
 haftmann parents: 
31902diff
changeset | 1882 | |
| 
c3844c4d0c2c
more accurate certificates for constant aliasses
 haftmann parents: 
31902diff
changeset | 1883 | setup {*
 | 
| 32544 | 1884 |   Nbe.add_const_alias @{thm equals_alias_cert}
 | 
| 30929 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1885 | *} | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1886 | |
| 31151 | 1887 | hide (open) const eq | 
| 1888 | hide const eq | |
| 1889 | ||
| 30929 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1890 | text {* Cases *}
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1891 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1892 | lemma Let_case_cert: | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1893 | assumes "CASE \<equiv> (\<lambda>x. Let x f)" | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1894 | shows "CASE x \<equiv> f x" | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1895 | using assms by simp_all | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1896 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1897 | lemma If_case_cert: | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1898 | assumes "CASE \<equiv> (\<lambda>b. If b f g)" | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1899 | shows "(CASE True \<equiv> f) &&& (CASE False \<equiv> g)" | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1900 | using assms by simp_all | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1901 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1902 | setup {*
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1903 |   Code.add_case @{thm Let_case_cert}
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1904 |   #> Code.add_case @{thm If_case_cert}
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1905 |   #> Code.add_undefined @{const_name undefined}
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1906 | *} | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1907 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1908 | code_abort undefined | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1909 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1910 | subsubsection {* Generic code generator target languages *}
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1911 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1912 | text {* type bool *}
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1913 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1914 | code_type bool | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1915 | (SML "bool") | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1916 | (OCaml "bool") | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1917 | (Haskell "Bool") | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1918 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1919 | code_const True and False and Not and "op &" and "op |" and If | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1920 | (SML "true" and "false" and "not" | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1921 | and infixl 1 "andalso" and infixl 0 "orelse" | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1922 | and "!(if (_)/ then (_)/ else (_))") | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1923 | (OCaml "true" and "false" and "not" | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1924 | and infixl 4 "&&" and infixl 2 "||" | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1925 | and "!(if (_)/ then (_)/ else (_))") | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1926 | (Haskell "True" and "False" and "not" | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1927 | and infixl 3 "&&" and infixl 2 "||" | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1928 | and "!(if (_)/ then (_)/ else (_))") | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1929 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1930 | code_reserved SML | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1931 | bool true false not | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1932 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1933 | code_reserved OCaml | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1934 | bool not | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1935 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1936 | text {* using built-in Haskell equality *}
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1937 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1938 | code_class eq | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1939 | (Haskell "Eq") | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1940 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1941 | code_const "eq_class.eq" | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1942 | (Haskell infixl 4 "==") | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1943 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1944 | code_const "op =" | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1945 | (Haskell infixl 4 "==") | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1946 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1947 | text {* undefined *}
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1948 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1949 | code_const undefined | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1950 | (SML "!(raise/ Fail/ \"undefined\")") | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1951 | (OCaml "failwith/ \"undefined\"") | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1952 | (Haskell "error/ \"undefined\"") | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1953 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1954 | subsubsection {* Evaluation and normalization by evaluation *}
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1955 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1956 | setup {*
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1957 |   Value.add_evaluator ("SML", Codegen.eval_term o ProofContext.theory_of)
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1958 | *} | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1959 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1960 | ML {*
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1961 | structure Eval_Method = | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1962 | struct | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1963 | |
| 32740 | 1964 | val eval_ref : (unit -> bool) option Unsynchronized.ref = Unsynchronized.ref NONE; | 
| 30929 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1965 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1966 | end; | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1967 | *} | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1968 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1969 | oracle eval_oracle = {* fn ct =>
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1970 | let | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1971 | val thy = Thm.theory_of_cterm ct; | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1972 | val t = Thm.term_of ct; | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1973 |     val dummy = @{cprop True};
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1974 | in case try HOLogic.dest_Trueprop t | 
| 30947 | 1975 | of SOME t' => if Code_ML.eval NONE | 
| 30970 
3fe2e418a071
generic postprocessing scheme for term evaluations
 haftmann parents: 
30966diff
changeset | 1976 |          ("Eval_Method.eval_ref", Eval_Method.eval_ref) (K I) thy t' [] 
 | 
| 30929 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1977 |        then Thm.capply (Thm.capply @{cterm "op \<equiv> \<Colon> prop \<Rightarrow> prop \<Rightarrow> prop"} ct) dummy
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1978 | else dummy | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1979 | | NONE => dummy | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1980 | end | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1981 | *} | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1982 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1983 | ML {*
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1984 | fun gen_eval_method conv ctxt = SIMPLE_METHOD' | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1985 | (CONVERSION (Conv.params_conv (~1) (K (Conv.concl_conv (~1) conv)) ctxt) | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1986 | THEN' rtac TrueI) | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1987 | *} | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1988 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1989 | method_setup eval = {* Scan.succeed (gen_eval_method eval_oracle) *}
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1990 | "solve goal by evaluation" | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1991 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1992 | method_setup evaluation = {* Scan.succeed (gen_eval_method Codegen.evaluation_conv) *}
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1993 | "solve goal by evaluation" | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1994 | |
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1995 | method_setup normalization = {*
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1996 | Scan.succeed (K (SIMPLE_METHOD' (CONVERSION Nbe.norm_conv THEN' (fn k => TRY (rtac TrueI k))))) | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1997 | *} "solve goal by normalization" | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 1998 | |
| 31902 | 1999 | |
| 33084 | 2000 | subsection {* Counterexample Search Units *}
 | 
| 2001 | ||
| 30929 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 2002 | subsubsection {* Quickcheck *}
 | 
| 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 2003 | |
| 33084 | 2004 | quickcheck_params [size = 5, iterations = 50] | 
| 2005 | ||
| 30929 
d9343c0aac11
code generator bootstrap theory src/Tools/Code_Generator.thy
 haftmann parents: 
30927diff
changeset | 2006 | |
| 33084 | 2007 | subsubsection {* Nitpick setup *}
 | 
| 30309 
188f0658af9f
Added a "nitpick_maybe" symbol, which is used by Nitpick. This will go away once Nitpick is part of HOL.
 blanchet parents: 
30254diff
changeset | 2008 | |
| 
188f0658af9f
Added a "nitpick_maybe" symbol, which is used by Nitpick. This will go away once Nitpick is part of HOL.
 blanchet parents: 
30254diff
changeset | 2009 | text {* This will be relocated once Nitpick is moved to HOL. *}
 | 
| 
188f0658af9f
Added a "nitpick_maybe" symbol, which is used by Nitpick. This will go away once Nitpick is part of HOL.
 blanchet parents: 
30254diff
changeset | 2010 | |
| 29863 
dadad1831e9d
Added "nitpick_const_simps" and "nitpick_ind_intros" attributes for theorems;
 blanchet parents: 
29608diff
changeset | 2011 | ML {*
 | 
| 33056 
791a4655cae3
renamed "nitpick_const_xxx" attributes to "nitpick_xxx" and "nitpick_ind_intros" to "nitpick_intros"
 blanchet parents: 
33022diff
changeset | 2012 | structure Nitpick_Defs = Named_Thms | 
| 30254 
7b8afdfa2f83
Second try at adding "nitpick_const_def" attribute.
 blanchet parents: 
30242diff
changeset | 2013 | ( | 
| 33056 
791a4655cae3
renamed "nitpick_const_xxx" attributes to "nitpick_xxx" and "nitpick_ind_intros" to "nitpick_intros"
 blanchet parents: 
33022diff
changeset | 2014 | val name = "nitpick_def" | 
| 30254 
7b8afdfa2f83
Second try at adding "nitpick_const_def" attribute.
 blanchet parents: 
30242diff
changeset | 2015 | val description = "alternative definitions of constants as needed by Nitpick" | 
| 
7b8afdfa2f83
Second try at adding "nitpick_const_def" attribute.
 blanchet parents: 
30242diff
changeset | 2016 | ) | 
| 33056 
791a4655cae3
renamed "nitpick_const_xxx" attributes to "nitpick_xxx" and "nitpick_ind_intros" to "nitpick_intros"
 blanchet parents: 
33022diff
changeset | 2017 | structure Nitpick_Simps = Named_Thms | 
| 29863 
dadad1831e9d
Added "nitpick_const_simps" and "nitpick_ind_intros" attributes for theorems;
 blanchet parents: 
29608diff
changeset | 2018 | ( | 
| 33056 
791a4655cae3
renamed "nitpick_const_xxx" attributes to "nitpick_xxx" and "nitpick_ind_intros" to "nitpick_intros"
 blanchet parents: 
33022diff
changeset | 2019 | val name = "nitpick_simp" | 
| 29869 
a7a8b90cd882
Renamed descriptions of Nitpick (and ATP) attributes, so that they fit well with the rest of the sentence in ProofGeneral.
 blanchet parents: 
29868diff
changeset | 2020 | val description = "equational specification of constants as needed by Nitpick" | 
| 29863 
dadad1831e9d
Added "nitpick_const_simps" and "nitpick_ind_intros" attributes for theorems;
 blanchet parents: 
29608diff
changeset | 2021 | ) | 
| 33056 
791a4655cae3
renamed "nitpick_const_xxx" attributes to "nitpick_xxx" and "nitpick_ind_intros" to "nitpick_intros"
 blanchet parents: 
33022diff
changeset | 2022 | structure Nitpick_Psimps = Named_Thms | 
| 29863 
dadad1831e9d
Added "nitpick_const_simps" and "nitpick_ind_intros" attributes for theorems;
 blanchet parents: 
29608diff
changeset | 2023 | ( | 
| 33056 
791a4655cae3
renamed "nitpick_const_xxx" attributes to "nitpick_xxx" and "nitpick_ind_intros" to "nitpick_intros"
 blanchet parents: 
33022diff
changeset | 2024 | val name = "nitpick_psimp" | 
| 29869 
a7a8b90cd882
Renamed descriptions of Nitpick (and ATP) attributes, so that they fit well with the rest of the sentence in ProofGeneral.
 blanchet parents: 
29868diff
changeset | 2025 | val description = "partial equational specification of constants as needed by Nitpick" | 
| 29863 
dadad1831e9d
Added "nitpick_const_simps" and "nitpick_ind_intros" attributes for theorems;
 blanchet parents: 
29608diff
changeset | 2026 | ) | 
| 33056 
791a4655cae3
renamed "nitpick_const_xxx" attributes to "nitpick_xxx" and "nitpick_ind_intros" to "nitpick_intros"
 blanchet parents: 
33022diff
changeset | 2027 | structure Nitpick_Intros = Named_Thms | 
| 29868 | 2028 | ( | 
| 33056 
791a4655cae3
renamed "nitpick_const_xxx" attributes to "nitpick_xxx" and "nitpick_ind_intros" to "nitpick_intros"
 blanchet parents: 
33022diff
changeset | 2029 | val name = "nitpick_intro" | 
| 29869 
a7a8b90cd882
Renamed descriptions of Nitpick (and ATP) attributes, so that they fit well with the rest of the sentence in ProofGeneral.
 blanchet parents: 
29868diff
changeset | 2030 | val description = "introduction rules for (co)inductive predicates as needed by Nitpick" | 
| 29868 | 2031 | ) | 
| 29863 
dadad1831e9d
Added "nitpick_const_simps" and "nitpick_ind_intros" attributes for theorems;
 blanchet parents: 
29608diff
changeset | 2032 | *} | 
| 30980 | 2033 | |
| 2034 | setup {*
 | |
| 33056 
791a4655cae3
renamed "nitpick_const_xxx" attributes to "nitpick_xxx" and "nitpick_ind_intros" to "nitpick_intros"
 blanchet parents: 
33022diff
changeset | 2035 | Nitpick_Defs.setup | 
| 
791a4655cae3
renamed "nitpick_const_xxx" attributes to "nitpick_xxx" and "nitpick_ind_intros" to "nitpick_intros"
 blanchet parents: 
33022diff
changeset | 2036 | #> Nitpick_Simps.setup | 
| 
791a4655cae3
renamed "nitpick_const_xxx" attributes to "nitpick_xxx" and "nitpick_ind_intros" to "nitpick_intros"
 blanchet parents: 
33022diff
changeset | 2037 | #> Nitpick_Psimps.setup | 
| 
791a4655cae3
renamed "nitpick_const_xxx" attributes to "nitpick_xxx" and "nitpick_ind_intros" to "nitpick_intros"
 blanchet parents: 
33022diff
changeset | 2038 | #> Nitpick_Intros.setup | 
| 30980 | 2039 | *} | 
| 2040 | ||
| 29863 
dadad1831e9d
Added "nitpick_const_simps" and "nitpick_ind_intros" attributes for theorems;
 blanchet parents: 
29608diff
changeset | 2041 | |
| 33084 | 2042 | subsection {* Preprocessing for the predicate compiler *}
 | 
| 2043 | ||
| 2044 | ML {*
 | |
| 2045 | structure Predicate_Compile_Alternative_Defs = Named_Thms | |
| 2046 | ( | |
| 2047 | val name = "code_pred_def" | |
| 2048 | val description = "alternative definitions of constants for the Predicate Compiler" | |
| 2049 | ) | |
| 2050 | *} | |
| 2051 | ||
| 2052 | ML {*
 | |
| 2053 | structure Predicate_Compile_Inline_Defs = Named_Thms | |
| 2054 | ( | |
| 2055 | val name = "code_pred_inline" | |
| 2056 | val description = "inlining definitions for the Predicate Compiler" | |
| 2057 | ) | |
| 2058 | *} | |
| 2059 | ||
| 2060 | setup {*
 | |
| 2061 | Predicate_Compile_Alternative_Defs.setup | |
| 2062 | #> Predicate_Compile_Inline_Defs.setup | |
| 2063 | #> Predicate_Compile_Preproc_Const_Defs.setup | |
| 2064 | *} | |
| 2065 | ||
| 2066 | ||
| 22839 | 2067 | subsection {* Legacy tactics and ML bindings *}
 | 
| 21671 | 2068 | |
| 2069 | ML {*
 | |
| 2070 | fun strip_tac i = REPEAT (resolve_tac [impI, allI] i); | |
| 2071 | ||
| 2072 | (* combination of (spec RS spec RS ...(j times) ... spec RS mp) *) | |
| 2073 | local | |
| 2074 |   fun wrong_prem (Const ("All", _) $ (Abs (_, _, t))) = wrong_prem t
 | |
| 2075 | | wrong_prem (Bound _) = true | |
| 2076 | | wrong_prem _ = false; | |
| 2077 | val filter_right = filter (not o wrong_prem o HOLogic.dest_Trueprop o hd o Thm.prems_of); | |
| 2078 | in | |
| 2079 | fun smp i = funpow i (fn m => filter_right ([spec] RL m)) ([mp]); | |
| 2080 | fun smp_tac j = EVERY'[dresolve_tac (smp j), atac]; | |
| 2081 | end; | |
| 22839 | 2082 | |
| 2083 | val all_conj_distrib = thm "all_conj_distrib"; | |
| 2084 | val all_simps = thms "all_simps"; | |
| 2085 | val atomize_not = thm "atomize_not"; | |
| 24830 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
 wenzelm parents: 
24748diff
changeset | 2086 | val case_split = thm "case_split"; | 
| 22839 | 2087 | val cases_simp = thm "cases_simp"; | 
| 2088 | val choice_eq = thm "choice_eq" | |
| 2089 | val cong = thm "cong" | |
| 2090 | val conj_comms = thms "conj_comms"; | |
| 2091 | val conj_cong = thm "conj_cong"; | |
| 2092 | val de_Morgan_conj = thm "de_Morgan_conj"; | |
| 2093 | val de_Morgan_disj = thm "de_Morgan_disj"; | |
| 2094 | val disj_assoc = thm "disj_assoc"; | |
| 2095 | val disj_comms = thms "disj_comms"; | |
| 2096 | val disj_cong = thm "disj_cong"; | |
| 2097 | val eq_ac = thms "eq_ac"; | |
| 2098 | val eq_cong2 = thm "eq_cong2" | |
| 2099 | val Eq_FalseI = thm "Eq_FalseI"; | |
| 2100 | val Eq_TrueI = thm "Eq_TrueI"; | |
| 2101 | val Ex1_def = thm "Ex1_def" | |
| 2102 | val ex_disj_distrib = thm "ex_disj_distrib"; | |
| 2103 | val ex_simps = thms "ex_simps"; | |
| 2104 | val if_cancel = thm "if_cancel"; | |
| 2105 | val if_eq_cancel = thm "if_eq_cancel"; | |
| 2106 | val if_False = thm "if_False"; | |
| 2107 | val iff_conv_conj_imp = thm "iff_conv_conj_imp"; | |
| 2108 | val iff = thm "iff" | |
| 2109 | val if_splits = thms "if_splits"; | |
| 2110 | val if_True = thm "if_True"; | |
| 2111 | val if_weak_cong = thm "if_weak_cong" | |
| 2112 | val imp_all = thm "imp_all"; | |
| 2113 | val imp_cong = thm "imp_cong"; | |
| 2114 | val imp_conjL = thm "imp_conjL"; | |
| 2115 | val imp_conjR = thm "imp_conjR"; | |
| 2116 | val imp_conv_disj = thm "imp_conv_disj"; | |
| 2117 | val simp_implies_def = thm "simp_implies_def"; | |
| 2118 | val simp_thms = thms "simp_thms"; | |
| 2119 | val split_if = thm "split_if"; | |
| 2120 | val the1_equality = thm "the1_equality" | |
| 2121 | val theI = thm "theI" | |
| 2122 | val theI' = thm "theI'" | |
| 2123 | val True_implies_equals = thm "True_implies_equals"; | |
| 23037 
6c72943a71b1
added a set of NNF normalization lemmas and nnf_conv
 chaieb parents: 
22993diff
changeset | 2124 | val nnf_conv = Simplifier.rewrite (HOL_basic_ss addsimps simp_thms @ @{thms "nnf_simps"})
 | 
| 
6c72943a71b1
added a set of NNF normalization lemmas and nnf_conv
 chaieb parents: 
22993diff
changeset | 2125 | |
| 21671 | 2126 | *} | 
| 2127 | ||
| 14357 | 2128 | end |