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