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