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