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