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