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