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