| author | wenzelm | 
| Thu, 05 Jul 2007 00:15:44 +0200 | |
| changeset 23587 | 46d01f5e1e5b | 
| parent 23566 | b65692d4adcd | 
| child 23878 | bd651ecd4b8a | 
| permissions | -rw-r--r-- | 
| 923 | 1  | 
(* Title: HOL/HOL.thy  | 
2  | 
ID: $Id$  | 
|
| 11750 | 3  | 
Author: Tobias Nipkow, Markus Wenzel, and Larry Paulson  | 
4  | 
*)  | 
|
| 923 | 5  | 
|
| 11750 | 6  | 
header {* The basis of Higher-Order Logic *}
 | 
| 923 | 7  | 
|
| 15131 | 8  | 
theory HOL  | 
| 15140 | 9  | 
imports CPure  | 
| 23163 | 10  | 
uses  | 
| 23247 | 11  | 
"~~/src/Tools/integer.ML"  | 
| 23553 | 12  | 
  ("hologic.ML")
 | 
| 23171 | 13  | 
"~~/src/Tools/IsaPlanner/zipper.ML"  | 
14  | 
"~~/src/Tools/IsaPlanner/isand.ML"  | 
|
15  | 
"~~/src/Tools/IsaPlanner/rw_tools.ML"  | 
|
16  | 
"~~/src/Tools/IsaPlanner/rw_inst.ML"  | 
|
| 23263 | 17  | 
"~~/src/Provers/project_rule.ML"  | 
| 23163 | 18  | 
"~~/src/Provers/induct_method.ML"  | 
| 23263 | 19  | 
"~~/src/Provers/hypsubst.ML"  | 
20  | 
"~~/src/Provers/splitter.ML"  | 
|
| 23163 | 21  | 
"~~/src/Provers/classical.ML"  | 
22  | 
"~~/src/Provers/blast.ML"  | 
|
23  | 
"~~/src/Provers/clasimp.ML"  | 
|
| 23263 | 24  | 
"~~/src/Provers/eqsubst.ML"  | 
| 23163 | 25  | 
"~~/src/Provers/quantifier1.ML"  | 
26  | 
  ("simpdata.ML")
 | 
|
| 23263 | 27  | 
"Tools/res_atpset.ML"  | 
| 23247 | 28  | 
  ("~~/src/HOL/Tools/recfun_codegen.ML")
 | 
| 15131 | 29  | 
begin  | 
| 2260 | 30  | 
|
| 11750 | 31  | 
subsection {* Primitive logic *}
 | 
32  | 
||
33  | 
subsubsection {* Core syntax *}
 | 
|
| 2260 | 34  | 
|
| 14854 | 35  | 
classes type  | 
| 
12338
 
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
 
wenzelm 
parents: 
12281 
diff
changeset
 | 
36  | 
defaultsort type  | 
| 3947 | 37  | 
|
| 
12338
 
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
 
wenzelm 
parents: 
12281 
diff
changeset
 | 
38  | 
global  | 
| 923 | 39  | 
|
| 7357 | 40  | 
typedecl bool  | 
| 923 | 41  | 
|
42  | 
arities  | 
|
| 
12338
 
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
 
wenzelm 
parents: 
12281 
diff
changeset
 | 
43  | 
bool :: type  | 
| 
20590
 
bf92900995f8
introduced syntactic classes; moved some setup to Pure/codegen, Pure/nbe or OperationalEquality.thy
 
haftmann 
parents: 
20453 
diff
changeset
 | 
44  | 
"fun" :: (type, type) type  | 
| 923 | 45  | 
|
| 11750 | 46  | 
judgment  | 
47  | 
  Trueprop      :: "bool => prop"                   ("(_)" 5)
 | 
|
| 923 | 48  | 
|
| 11750 | 49  | 
consts  | 
| 7357 | 50  | 
  Not           :: "bool => bool"                   ("~ _" [40] 40)
 | 
51  | 
True :: bool  | 
|
52  | 
False :: bool  | 
|
| 3947 | 53  | 
arbitrary :: 'a  | 
| 923 | 54  | 
|
| 
11432
 
8a203ae6efe3
added "The" (definite description operator) (by Larry);
 
wenzelm 
parents: 
10489 
diff
changeset
 | 
55  | 
  The           :: "('a => bool) => 'a"
 | 
| 7357 | 56  | 
  All           :: "('a => bool) => bool"           (binder "ALL " 10)
 | 
57  | 
  Ex            :: "('a => bool) => bool"           (binder "EX " 10)
 | 
|
58  | 
  Ex1           :: "('a => bool) => bool"           (binder "EX! " 10)
 | 
|
59  | 
Let :: "['a, 'a => 'b] => 'b"  | 
|
| 923 | 60  | 
|
| 22839 | 61  | 
"op =" :: "['a, 'a] => bool" (infixl "=" 50)  | 
62  | 
"op &" :: "[bool, bool] => bool" (infixr "&" 35)  | 
|
63  | 
"op |" :: "[bool, bool] => bool" (infixr "|" 30)  | 
|
64  | 
"op -->" :: "[bool, bool] => bool" (infixr "-->" 25)  | 
|
| 923 | 65  | 
|
| 
10432
 
3dfbc913d184
added axclass inverse and consts inverse, divide (infix "/");
 
wenzelm 
parents: 
10383 
diff
changeset
 | 
66  | 
local  | 
| 
 
3dfbc913d184
added axclass inverse and consts inverse, divide (infix "/");
 
wenzelm 
parents: 
10383 
diff
changeset
 | 
67  | 
|
| 16587 | 68  | 
consts  | 
69  | 
  If            :: "[bool, 'a, 'a] => 'a"           ("(if (_)/ then (_)/ else (_))" 10)
 | 
|
| 2260 | 70  | 
|
| 
19656
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
71  | 
|
| 11750 | 72  | 
subsubsection {* Additional concrete syntax *}
 | 
| 2260 | 73  | 
|
| 21210 | 74  | 
notation (output)  | 
| 
19656
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
75  | 
"op =" (infix "=" 50)  | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
76  | 
|
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
77  | 
abbreviation  | 
| 
21404
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21250 
diff
changeset
 | 
78  | 
not_equal :: "['a, 'a] => bool" (infixl "~=" 50) where  | 
| 
19656
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
79  | 
"x ~= y == ~ (x = y)"  | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
80  | 
|
| 21210 | 81  | 
notation (output)  | 
| 
19656
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
82  | 
not_equal (infix "~=" 50)  | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
83  | 
|
| 21210 | 84  | 
notation (xsymbols)  | 
| 
21404
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21250 
diff
changeset
 | 
85  | 
  Not  ("\<not> _" [40] 40) and
 | 
| 
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21250 
diff
changeset
 | 
86  | 
"op &" (infixr "\<and>" 35) and  | 
| 
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21250 
diff
changeset
 | 
87  | 
"op |" (infixr "\<or>" 30) and  | 
| 
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21250 
diff
changeset
 | 
88  | 
"op -->" (infixr "\<longrightarrow>" 25) and  | 
| 
19656
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
89  | 
not_equal (infix "\<noteq>" 50)  | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
90  | 
|
| 21210 | 91  | 
notation (HTML output)  | 
| 
21404
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21250 
diff
changeset
 | 
92  | 
  Not  ("\<not> _" [40] 40) and
 | 
| 
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21250 
diff
changeset
 | 
93  | 
"op &" (infixr "\<and>" 35) and  | 
| 
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21250 
diff
changeset
 | 
94  | 
"op |" (infixr "\<or>" 30) and  | 
| 
19656
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
95  | 
not_equal (infix "\<noteq>" 50)  | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
96  | 
|
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
97  | 
abbreviation (iff)  | 
| 
21404
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21250 
diff
changeset
 | 
98  | 
iff :: "[bool, bool] => bool" (infixr "<->" 25) where  | 
| 
19656
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
99  | 
"A <-> B == A = B"  | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
100  | 
|
| 21210 | 101  | 
notation (xsymbols)  | 
| 
19656
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
102  | 
iff (infixr "\<longleftrightarrow>" 25)  | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
103  | 
|
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
104  | 
|
| 4868 | 105  | 
nonterminals  | 
| 923 | 106  | 
letbinds letbind  | 
107  | 
case_syn cases_syn  | 
|
108  | 
||
109  | 
syntax  | 
|
| 
11432
 
8a203ae6efe3
added "The" (definite description operator) (by Larry);
 
wenzelm 
parents: 
10489 
diff
changeset
 | 
110  | 
  "_The"        :: "[pttrn, bool] => 'a"                 ("(3THE _./ _)" [0, 10] 10)
 | 
| 923 | 111  | 
|
| 7357 | 112  | 
  "_bind"       :: "[pttrn, 'a] => letbind"              ("(2_ =/ _)" 10)
 | 
113  | 
  ""            :: "letbind => letbinds"                 ("_")
 | 
|
114  | 
  "_binds"      :: "[letbind, letbinds] => letbinds"     ("_;/ _")
 | 
|
115  | 
  "_Let"        :: "[letbinds, 'a] => 'a"                ("(let (_)/ in (_))" 10)
 | 
|
| 923 | 116  | 
|
| 
9060
 
b0dd884b1848
rename @case to _case_syntax (improves on low-level errors);
 
wenzelm 
parents: 
8959 
diff
changeset
 | 
117  | 
  "_case_syntax":: "['a, cases_syn] => 'b"               ("(case _ of/ _)" 10)
 | 
| 
 
b0dd884b1848
rename @case to _case_syntax (improves on low-level errors);
 
wenzelm 
parents: 
8959 
diff
changeset
 | 
118  | 
  "_case1"      :: "['a, 'b] => case_syn"                ("(2_ =>/ _)" 10)
 | 
| 7357 | 119  | 
  ""            :: "case_syn => cases_syn"               ("_")
 | 
| 
9060
 
b0dd884b1848
rename @case to _case_syntax (improves on low-level errors);
 
wenzelm 
parents: 
8959 
diff
changeset
 | 
120  | 
  "_case2"      :: "[case_syn, cases_syn] => cases_syn"  ("_/ | _")
 | 
| 923 | 121  | 
|
122  | 
translations  | 
|
| 13764 | 123  | 
"THE x. P" == "The (%x. P)"  | 
| 923 | 124  | 
"_Let (_binds b bs) e" == "_Let b (_Let bs e)"  | 
| 1114 | 125  | 
"let x = a in e" == "Let a (%x. e)"  | 
| 923 | 126  | 
|
| 
13763
 
f94b569cd610
added print translations tha avoid eta contraction for important binders.
 
nipkow 
parents: 
13723 
diff
changeset
 | 
127  | 
print_translation {*
 | 
| 
 
f94b569cd610
added print translations tha avoid eta contraction for important binders.
 
nipkow 
parents: 
13723 
diff
changeset
 | 
128  | 
(* To avoid eta-contraction of body: *)  | 
| 
 
f94b569cd610
added print translations tha avoid eta contraction for important binders.
 
nipkow 
parents: 
13723 
diff
changeset
 | 
129  | 
[("The", fn [Abs abs] =>
 | 
| 
 
f94b569cd610
added print translations tha avoid eta contraction for important binders.
 
nipkow 
parents: 
13723 
diff
changeset
 | 
130  | 
let val (x,t) = atomic_abs_tr' abs  | 
| 
 
f94b569cd610
added print translations tha avoid eta contraction for important binders.
 
nipkow 
parents: 
13723 
diff
changeset
 | 
131  | 
in Syntax.const "_The" $ x $ t end)]  | 
| 
 
f94b569cd610
added print translations tha avoid eta contraction for important binders.
 
nipkow 
parents: 
13723 
diff
changeset
 | 
132  | 
*}  | 
| 
 
f94b569cd610
added print translations tha avoid eta contraction for important binders.
 
nipkow 
parents: 
13723 
diff
changeset
 | 
133  | 
|
| 
12114
 
a8e860c86252
eliminated old "symbols" syntax, use "xsymbols" instead;
 
wenzelm 
parents: 
12023 
diff
changeset
 | 
134  | 
syntax (xsymbols)  | 
| 11687 | 135  | 
  "_case1"      :: "['a, 'b] => case_syn"                ("(2_ \<Rightarrow>/ _)" 10)
 | 
| 21524 | 136  | 
|
137  | 
notation (xsymbols)  | 
|
138  | 
All (binder "\<forall>" 10) and  | 
|
139  | 
Ex (binder "\<exists>" 10) and  | 
|
140  | 
Ex1 (binder "\<exists>!" 10)  | 
|
| 2372 | 141  | 
|
| 21524 | 142  | 
notation (HTML output)  | 
143  | 
All (binder "\<forall>" 10) and  | 
|
144  | 
Ex (binder "\<exists>" 10) and  | 
|
145  | 
Ex1 (binder "\<exists>!" 10)  | 
|
| 6340 | 146  | 
|
| 21524 | 147  | 
notation (HOL)  | 
148  | 
All (binder "! " 10) and  | 
|
149  | 
Ex (binder "? " 10) and  | 
|
150  | 
Ex1 (binder "?! " 10)  | 
|
| 
7238
 
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
 
wenzelm 
parents: 
7220 
diff
changeset
 | 
151  | 
|
| 
 
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
 
wenzelm 
parents: 
7220 
diff
changeset
 | 
152  | 
|
| 11750 | 153  | 
subsubsection {* Axioms and basic definitions *}
 | 
| 2260 | 154  | 
|
| 7357 | 155  | 
axioms  | 
| 15380 | 156  | 
eq_reflection: "(x=y) ==> (x==y)"  | 
| 923 | 157  | 
|
| 15380 | 158  | 
refl: "t = (t::'a)"  | 
| 6289 | 159  | 
|
| 15380 | 160  | 
ext: "(!!x::'a. (f x ::'b) = g x) ==> (%x. f x) = (%x. g x)"  | 
161  | 
    -- {*Extensionality is built into the meta-logic, and this rule expresses
 | 
|
162  | 
a related property. It is an eta-expanded version of the traditional  | 
|
163  | 
rule, and similar to the ABS rule of HOL*}  | 
|
| 6289 | 164  | 
|
| 
11432
 
8a203ae6efe3
added "The" (definite description operator) (by Larry);
 
wenzelm 
parents: 
10489 
diff
changeset
 | 
165  | 
the_eq_trivial: "(THE x. x = a) = (a::'a)"  | 
| 923 | 166  | 
|
| 15380 | 167  | 
impI: "(P ==> Q) ==> P-->Q"  | 
168  | 
mp: "[| P-->Q; P |] ==> Q"  | 
|
169  | 
||
170  | 
||
| 923 | 171  | 
defs  | 
| 7357 | 172  | 
True_def: "True == ((%x::bool. x) = (%x. x))"  | 
173  | 
All_def: "All(P) == (P = (%x. True))"  | 
|
| 
11451
 
8abfb4f7bd02
partial restructuring to reduce dependence on Axiom of Choice
 
paulson 
parents: 
11438 
diff
changeset
 | 
174  | 
Ex_def: "Ex(P) == !Q. (!x. P x --> Q) --> Q"  | 
| 7357 | 175  | 
False_def: "False == (!P. P)"  | 
176  | 
not_def: "~ P == P-->False"  | 
|
177  | 
and_def: "P & Q == !R. (P-->Q-->R) --> R"  | 
|
178  | 
or_def: "P | Q == !R. (P-->R) --> (Q-->R) --> R"  | 
|
179  | 
Ex1_def: "Ex1(P) == ? x. P(x) & (! y. P(y) --> y=x)"  | 
|
| 923 | 180  | 
|
| 7357 | 181  | 
axioms  | 
182  | 
iff: "(P-->Q) --> (Q-->P) --> (P=Q)"  | 
|
183  | 
True_or_False: "(P=True) | (P=False)"  | 
|
| 923 | 184  | 
|
185  | 
defs  | 
|
| 
22744
 
5cbe966d67a2
Isar definitions are now added explicitly to code theorem table
 
haftmann 
parents: 
22481 
diff
changeset
 | 
186  | 
Let_def [code func]: "Let s f == f(s)"  | 
| 
11451
 
8abfb4f7bd02
partial restructuring to reduce dependence on Axiom of Choice
 
paulson 
parents: 
11438 
diff
changeset
 | 
187  | 
if_def: "If P x y == THE z::'a. (P=True --> z=x) & (P=False --> z=y)"  | 
| 5069 | 188  | 
|
| 
14223
 
0ee05eef881b
Added support for making constants final, that is, ensuring that no
 
skalberg 
parents: 
14208 
diff
changeset
 | 
189  | 
finalconsts  | 
| 
 
0ee05eef881b
Added support for making constants final, that is, ensuring that no
 
skalberg 
parents: 
14208 
diff
changeset
 | 
190  | 
"op ="  | 
| 
 
0ee05eef881b
Added support for making constants final, that is, ensuring that no
 
skalberg 
parents: 
14208 
diff
changeset
 | 
191  | 
"op -->"  | 
| 
 
0ee05eef881b
Added support for making constants final, that is, ensuring that no
 
skalberg 
parents: 
14208 
diff
changeset
 | 
192  | 
The  | 
| 
 
0ee05eef881b
Added support for making constants final, that is, ensuring that no
 
skalberg 
parents: 
14208 
diff
changeset
 | 
193  | 
arbitrary  | 
| 
22481
 
79c2724c36b5
added class "default" and expansion axioms for undefined
 
haftmann 
parents: 
22473 
diff
changeset
 | 
194  | 
|
| 
 
79c2724c36b5
added class "default" and expansion axioms for undefined
 
haftmann 
parents: 
22473 
diff
changeset
 | 
195  | 
axiomatization  | 
| 
 
79c2724c36b5
added class "default" and expansion axioms for undefined
 
haftmann 
parents: 
22473 
diff
changeset
 | 
196  | 
undefined :: 'a  | 
| 
 
79c2724c36b5
added class "default" and expansion axioms for undefined
 
haftmann 
parents: 
22473 
diff
changeset
 | 
197  | 
|
| 
22744
 
5cbe966d67a2
Isar definitions are now added explicitly to code theorem table
 
haftmann 
parents: 
22481 
diff
changeset
 | 
198  | 
axiomatization where  | 
| 
22481
 
79c2724c36b5
added class "default" and expansion axioms for undefined
 
haftmann 
parents: 
22473 
diff
changeset
 | 
199  | 
undefined_fun: "undefined x = undefined"  | 
| 3320 | 200  | 
|
| 
19656
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
201  | 
|
| 
22481
 
79c2724c36b5
added class "default" and expansion axioms for undefined
 
haftmann 
parents: 
22473 
diff
changeset
 | 
202  | 
subsubsection {* Generic classes and algebraic operations *}
 | 
| 
 
79c2724c36b5
added class "default" and expansion axioms for undefined
 
haftmann 
parents: 
22473 
diff
changeset
 | 
203  | 
|
| 
 
79c2724c36b5
added class "default" and expansion axioms for undefined
 
haftmann 
parents: 
22473 
diff
changeset
 | 
204  | 
class default = type +  | 
| 
 
79c2724c36b5
added class "default" and expansion axioms for undefined
 
haftmann 
parents: 
22473 
diff
changeset
 | 
205  | 
fixes default :: "'a"  | 
| 4868 | 206  | 
|
| 22473 | 207  | 
class zero = type +  | 
| 21524 | 208  | 
  fixes zero :: "'a"  ("\<^loc>0")
 | 
| 
20713
 
823967ef47f1
renamed 0 and 1 to HOL.zero and HOL.one respectivly; introduced corresponding syntactic classes
 
haftmann 
parents: 
20698 
diff
changeset
 | 
209  | 
|
| 22473 | 210  | 
class one = type +  | 
| 21524 | 211  | 
  fixes one  :: "'a"  ("\<^loc>1")
 | 
| 
20713
 
823967ef47f1
renamed 0 and 1 to HOL.zero and HOL.one respectivly; introduced corresponding syntactic classes
 
haftmann 
parents: 
20698 
diff
changeset
 | 
212  | 
|
| 
 
823967ef47f1
renamed 0 and 1 to HOL.zero and HOL.one respectivly; introduced corresponding syntactic classes
 
haftmann 
parents: 
20698 
diff
changeset
 | 
213  | 
hide (open) const zero one  | 
| 
20590
 
bf92900995f8
introduced syntactic classes; moved some setup to Pure/codegen, Pure/nbe or OperationalEquality.thy
 
haftmann 
parents: 
20453 
diff
changeset
 | 
214  | 
|
| 22473 | 215  | 
class plus = type +  | 
| 21524 | 216  | 
fixes plus :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<^loc>+" 65)  | 
| 11750 | 217  | 
|
| 22473 | 218  | 
class minus = type +  | 
| 
20590
 
bf92900995f8
introduced syntactic classes; moved some setup to Pure/codegen, Pure/nbe or OperationalEquality.thy
 
haftmann 
parents: 
20453 
diff
changeset
 | 
219  | 
fixes uminus :: "'a \<Rightarrow> 'a"  | 
| 21524 | 220  | 
and minus :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<^loc>-" 65)  | 
221  | 
and abs :: "'a \<Rightarrow> 'a"  | 
|
| 
20590
 
bf92900995f8
introduced syntactic classes; moved some setup to Pure/codegen, Pure/nbe or OperationalEquality.thy
 
haftmann 
parents: 
20453 
diff
changeset
 | 
222  | 
|
| 22473 | 223  | 
class times = type +  | 
| 
20713
 
823967ef47f1
renamed 0 and 1 to HOL.zero and HOL.one respectivly; introduced corresponding syntactic classes
 
haftmann 
parents: 
20698 
diff
changeset
 | 
224  | 
fixes times :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<^loc>*" 70)  | 
| 
20590
 
bf92900995f8
introduced syntactic classes; moved some setup to Pure/codegen, Pure/nbe or OperationalEquality.thy
 
haftmann 
parents: 
20453 
diff
changeset
 | 
225  | 
|
| 22473 | 226  | 
class inverse = type +  | 
| 
20590
 
bf92900995f8
introduced syntactic classes; moved some setup to Pure/codegen, Pure/nbe or OperationalEquality.thy
 
haftmann 
parents: 
20453 
diff
changeset
 | 
227  | 
fixes inverse :: "'a \<Rightarrow> 'a"  | 
| 21524 | 228  | 
and divide :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<^loc>'/" 70)  | 
229  | 
||
230  | 
notation  | 
|
231  | 
  uminus  ("- _" [81] 80)
 | 
|
232  | 
||
233  | 
notation (xsymbols)  | 
|
234  | 
  abs  ("\<bar>_\<bar>")
 | 
|
235  | 
notation (HTML output)  | 
|
236  | 
  abs  ("\<bar>_\<bar>")
 | 
|
| 11750 | 237  | 
|
| 
13456
 
42601eb7553f
special syntax for index "1" (plain numeral hidden by "1" symbol in HOL);
 
wenzelm 
parents: 
13438 
diff
changeset
 | 
238  | 
syntax  | 
| 
 
42601eb7553f
special syntax for index "1" (plain numeral hidden by "1" symbol in HOL);
 
wenzelm 
parents: 
13438 
diff
changeset
 | 
239  | 
  "_index1"  :: index    ("\<^sub>1")
 | 
| 
 
42601eb7553f
special syntax for index "1" (plain numeral hidden by "1" symbol in HOL);
 
wenzelm 
parents: 
13438 
diff
changeset
 | 
240  | 
translations  | 
| 14690 | 241  | 
(index) "\<^sub>1" => (index) "\<^bsub>\<struct>\<^esub>"  | 
| 
13456
 
42601eb7553f
special syntax for index "1" (plain numeral hidden by "1" symbol in HOL);
 
wenzelm 
parents: 
13438 
diff
changeset
 | 
242  | 
|
| 11750 | 243  | 
typed_print_translation {*
 | 
| 
20713
 
823967ef47f1
renamed 0 and 1 to HOL.zero and HOL.one respectivly; introduced corresponding syntactic classes
 
haftmann 
parents: 
20698 
diff
changeset
 | 
244  | 
let  | 
| 
 
823967ef47f1
renamed 0 and 1 to HOL.zero and HOL.one respectivly; introduced corresponding syntactic classes
 
haftmann 
parents: 
20698 
diff
changeset
 | 
245  | 
fun tr' c = (c, fn show_sorts => fn T => fn ts =>  | 
| 
 
823967ef47f1
renamed 0 and 1 to HOL.zero and HOL.one respectivly; introduced corresponding syntactic classes
 
haftmann 
parents: 
20698 
diff
changeset
 | 
246  | 
if T = dummyT orelse not (! show_types) andalso can Term.dest_Type T then raise Match  | 
| 
 
823967ef47f1
renamed 0 and 1 to HOL.zero and HOL.one respectivly; introduced corresponding syntactic classes
 
haftmann 
parents: 
20698 
diff
changeset
 | 
247  | 
else Syntax.const Syntax.constrainC $ Syntax.const c $ Syntax.term_of_typ show_sorts T);  | 
| 22993 | 248  | 
in map tr' [@{const_syntax HOL.one}, @{const_syntax HOL.zero}] end;
 | 
| 11750 | 249  | 
*} -- {* show types that are presumably too general *}
 | 
250  | 
||
251  | 
||
| 20944 | 252  | 
subsection {* Fundamental rules *}
 | 
253  | 
||
| 20973 | 254  | 
subsubsection {* Equality *}
 | 
| 20944 | 255  | 
|
256  | 
text {* Thanks to Stephan Merz *}
 | 
|
257  | 
lemma subst:  | 
|
258  | 
assumes eq: "s = t" and p: "P s"  | 
|
259  | 
shows "P t"  | 
|
260  | 
proof -  | 
|
261  | 
from eq have meta: "s \<equiv> t"  | 
|
262  | 
by (rule eq_reflection)  | 
|
263  | 
from p show ?thesis  | 
|
264  | 
by (unfold meta)  | 
|
265  | 
qed  | 
|
| 15411 | 266  | 
|
| 18457 | 267  | 
lemma sym: "s = t ==> t = s"  | 
268  | 
by (erule subst) (rule refl)  | 
|
| 15411 | 269  | 
|
| 18457 | 270  | 
lemma ssubst: "t = s ==> P s ==> P t"  | 
271  | 
by (drule sym) (erule subst)  | 
|
| 15411 | 272  | 
|
273  | 
lemma trans: "[| r=s; s=t |] ==> r=t"  | 
|
| 18457 | 274  | 
by (erule subst)  | 
| 15411 | 275  | 
|
| 20944 | 276  | 
lemma meta_eq_to_obj_eq:  | 
277  | 
assumes meq: "A == B"  | 
|
278  | 
shows "A = B"  | 
|
279  | 
by (unfold meq) (rule refl)  | 
|
| 15411 | 280  | 
|
| 21502 | 281  | 
text {* Useful with @{text erule} for proving equalities from known equalities. *}
 | 
| 20944 | 282  | 
(* a = b  | 
| 15411 | 283  | 
| |  | 
284  | 
c = d *)  | 
|
285  | 
lemma box_equals: "[| a=b; a=c; b=d |] ==> c=d"  | 
|
286  | 
apply (rule trans)  | 
|
287  | 
apply (rule trans)  | 
|
288  | 
apply (rule sym)  | 
|
289  | 
apply assumption+  | 
|
290  | 
done  | 
|
291  | 
||
| 
15524
 
2ef571f80a55
Moved oderings from HOL into the new Orderings.thy
 
nipkow 
parents: 
15481 
diff
changeset
 | 
292  | 
text {* For calculational reasoning: *}
 | 
| 
 
2ef571f80a55
Moved oderings from HOL into the new Orderings.thy
 
nipkow 
parents: 
15481 
diff
changeset
 | 
293  | 
|
| 
 
2ef571f80a55
Moved oderings from HOL into the new Orderings.thy
 
nipkow 
parents: 
15481 
diff
changeset
 | 
294  | 
lemma forw_subst: "a = b ==> P b ==> P a"  | 
| 
 
2ef571f80a55
Moved oderings from HOL into the new Orderings.thy
 
nipkow 
parents: 
15481 
diff
changeset
 | 
295  | 
by (rule ssubst)  | 
| 
 
2ef571f80a55
Moved oderings from HOL into the new Orderings.thy
 
nipkow 
parents: 
15481 
diff
changeset
 | 
296  | 
|
| 
 
2ef571f80a55
Moved oderings from HOL into the new Orderings.thy
 
nipkow 
parents: 
15481 
diff
changeset
 | 
297  | 
lemma back_subst: "P a ==> a = b ==> P b"  | 
| 
 
2ef571f80a55
Moved oderings from HOL into the new Orderings.thy
 
nipkow 
parents: 
15481 
diff
changeset
 | 
298  | 
by (rule subst)  | 
| 
 
2ef571f80a55
Moved oderings from HOL into the new Orderings.thy
 
nipkow 
parents: 
15481 
diff
changeset
 | 
299  | 
|
| 15411 | 300  | 
|
| 20944 | 301  | 
subsubsection {*Congruence rules for application*}
 | 
| 15411 | 302  | 
|
303  | 
(*similar to AP_THM in Gordon's HOL*)  | 
|
304  | 
lemma fun_cong: "(f::'a=>'b) = g ==> f(x)=g(x)"  | 
|
305  | 
apply (erule subst)  | 
|
306  | 
apply (rule refl)  | 
|
307  | 
done  | 
|
308  | 
||
309  | 
(*similar to AP_TERM in Gordon's HOL and FOL's subst_context*)  | 
|
310  | 
lemma arg_cong: "x=y ==> f(x)=f(y)"  | 
|
311  | 
apply (erule subst)  | 
|
312  | 
apply (rule refl)  | 
|
313  | 
done  | 
|
314  | 
||
| 15655 | 315  | 
lemma arg_cong2: "\<lbrakk> a = b; c = d \<rbrakk> \<Longrightarrow> f a c = f b d"  | 
316  | 
apply (erule ssubst)+  | 
|
317  | 
apply (rule refl)  | 
|
318  | 
done  | 
|
319  | 
||
| 15411 | 320  | 
lemma cong: "[| f = g; (x::'a) = y |] ==> f(x) = g(y)"  | 
321  | 
apply (erule subst)+  | 
|
322  | 
apply (rule refl)  | 
|
323  | 
done  | 
|
324  | 
||
325  | 
||
| 20944 | 326  | 
subsubsection {*Equality of booleans -- iff*}
 | 
| 15411 | 327  | 
|
| 21504 | 328  | 
lemma iffI: assumes "P ==> Q" and "Q ==> P" shows "P=Q"  | 
329  | 
by (iprover intro: iff [THEN mp, THEN mp] impI assms)  | 
|
| 15411 | 330  | 
|
331  | 
lemma iffD2: "[| P=Q; Q |] ==> P"  | 
|
| 18457 | 332  | 
by (erule ssubst)  | 
| 15411 | 333  | 
|
334  | 
lemma rev_iffD2: "[| Q; P=Q |] ==> P"  | 
|
| 18457 | 335  | 
by (erule iffD2)  | 
| 15411 | 336  | 
|
| 21504 | 337  | 
lemma iffD1: "Q = P \<Longrightarrow> Q \<Longrightarrow> P"  | 
338  | 
by (drule sym) (rule iffD2)  | 
|
339  | 
||
340  | 
lemma rev_iffD1: "Q \<Longrightarrow> Q = P \<Longrightarrow> P"  | 
|
341  | 
by (drule sym) (rule rev_iffD2)  | 
|
| 15411 | 342  | 
|
343  | 
lemma iffE:  | 
|
344  | 
assumes major: "P=Q"  | 
|
| 21504 | 345  | 
and minor: "[| P --> Q; Q --> P |] ==> R"  | 
| 18457 | 346  | 
shows R  | 
347  | 
by (iprover intro: minor impI major [THEN iffD2] major [THEN iffD1])  | 
|
| 15411 | 348  | 
|
349  | 
||
| 20944 | 350  | 
subsubsection {*True*}
 | 
| 15411 | 351  | 
|
352  | 
lemma TrueI: "True"  | 
|
| 21504 | 353  | 
unfolding True_def by (rule refl)  | 
| 15411 | 354  | 
|
| 21504 | 355  | 
lemma eqTrueI: "P ==> P = True"  | 
| 18457 | 356  | 
by (iprover intro: iffI TrueI)  | 
| 15411 | 357  | 
|
| 21504 | 358  | 
lemma eqTrueE: "P = True ==> P"  | 
359  | 
by (erule iffD2) (rule TrueI)  | 
|
| 15411 | 360  | 
|
361  | 
||
| 20944 | 362  | 
subsubsection {*Universal quantifier*}
 | 
| 15411 | 363  | 
|
| 21504 | 364  | 
lemma allI: assumes "!!x::'a. P(x)" shows "ALL x. P(x)"  | 
365  | 
unfolding All_def by (iprover intro: ext eqTrueI assms)  | 
|
| 15411 | 366  | 
|
367  | 
lemma spec: "ALL x::'a. P(x) ==> P(x)"  | 
|
368  | 
apply (unfold All_def)  | 
|
369  | 
apply (rule eqTrueE)  | 
|
370  | 
apply (erule fun_cong)  | 
|
371  | 
done  | 
|
372  | 
||
373  | 
lemma allE:  | 
|
374  | 
assumes major: "ALL x. P(x)"  | 
|
| 21504 | 375  | 
and minor: "P(x) ==> R"  | 
376  | 
shows R  | 
|
377  | 
by (iprover intro: minor major [THEN spec])  | 
|
| 15411 | 378  | 
|
379  | 
lemma all_dupE:  | 
|
380  | 
assumes major: "ALL x. P(x)"  | 
|
| 21504 | 381  | 
and minor: "[| P(x); ALL x. P(x) |] ==> R"  | 
382  | 
shows R  | 
|
383  | 
by (iprover intro: minor major major [THEN spec])  | 
|
| 15411 | 384  | 
|
385  | 
||
| 21504 | 386  | 
subsubsection {* False *}
 | 
387  | 
||
388  | 
text {*
 | 
|
389  | 
  Depends upon @{text spec}; it is impossible to do propositional
 | 
|
390  | 
logic before quantifiers!  | 
|
391  | 
*}  | 
|
| 15411 | 392  | 
|
393  | 
lemma FalseE: "False ==> P"  | 
|
| 21504 | 394  | 
apply (unfold False_def)  | 
395  | 
apply (erule spec)  | 
|
396  | 
done  | 
|
| 15411 | 397  | 
|
| 21504 | 398  | 
lemma False_neq_True: "False = True ==> P"  | 
399  | 
by (erule eqTrueE [THEN FalseE])  | 
|
| 15411 | 400  | 
|
401  | 
||
| 21504 | 402  | 
subsubsection {* Negation *}
 | 
| 15411 | 403  | 
|
404  | 
lemma notI:  | 
|
| 21504 | 405  | 
assumes "P ==> False"  | 
| 15411 | 406  | 
shows "~P"  | 
| 21504 | 407  | 
apply (unfold not_def)  | 
408  | 
apply (iprover intro: impI assms)  | 
|
409  | 
done  | 
|
| 15411 | 410  | 
|
411  | 
lemma False_not_True: "False ~= True"  | 
|
| 21504 | 412  | 
apply (rule notI)  | 
413  | 
apply (erule False_neq_True)  | 
|
414  | 
done  | 
|
| 15411 | 415  | 
|
416  | 
lemma True_not_False: "True ~= False"  | 
|
| 21504 | 417  | 
apply (rule notI)  | 
418  | 
apply (drule sym)  | 
|
419  | 
apply (erule False_neq_True)  | 
|
420  | 
done  | 
|
| 15411 | 421  | 
|
422  | 
lemma notE: "[| ~P; P |] ==> R"  | 
|
| 21504 | 423  | 
apply (unfold not_def)  | 
424  | 
apply (erule mp [THEN FalseE])  | 
|
425  | 
apply assumption  | 
|
426  | 
done  | 
|
| 15411 | 427  | 
|
| 21504 | 428  | 
lemma notI2: "(P \<Longrightarrow> \<not> Pa) \<Longrightarrow> (P \<Longrightarrow> Pa) \<Longrightarrow> \<not> P"  | 
429  | 
by (erule notE [THEN notI]) (erule meta_mp)  | 
|
| 15411 | 430  | 
|
431  | 
||
| 20944 | 432  | 
subsubsection {*Implication*}
 | 
| 15411 | 433  | 
|
434  | 
lemma impE:  | 
|
435  | 
assumes "P-->Q" "P" "Q ==> R"  | 
|
436  | 
shows "R"  | 
|
| 23553 | 437  | 
by (iprover intro: assms mp)  | 
| 15411 | 438  | 
|
439  | 
(* Reduces Q to P-->Q, allowing substitution in P. *)  | 
|
440  | 
lemma rev_mp: "[| P; P --> Q |] ==> Q"  | 
|
| 17589 | 441  | 
by (iprover intro: mp)  | 
| 15411 | 442  | 
|
443  | 
lemma contrapos_nn:  | 
|
444  | 
assumes major: "~Q"  | 
|
445  | 
and minor: "P==>Q"  | 
|
446  | 
shows "~P"  | 
|
| 17589 | 447  | 
by (iprover intro: notI minor major [THEN notE])  | 
| 15411 | 448  | 
|
449  | 
(*not used at all, but we already have the other 3 combinations *)  | 
|
450  | 
lemma contrapos_pn:  | 
|
451  | 
assumes major: "Q"  | 
|
452  | 
and minor: "P ==> ~Q"  | 
|
453  | 
shows "~P"  | 
|
| 17589 | 454  | 
by (iprover intro: notI minor major notE)  | 
| 15411 | 455  | 
|
456  | 
lemma not_sym: "t ~= s ==> s ~= t"  | 
|
| 21250 | 457  | 
by (erule contrapos_nn) (erule sym)  | 
458  | 
||
459  | 
lemma eq_neq_eq_imp_neq: "[| x = a ; a ~= b; b = y |] ==> x ~= y"  | 
|
460  | 
by (erule subst, erule ssubst, assumption)  | 
|
| 15411 | 461  | 
|
462  | 
(*still used in HOLCF*)  | 
|
463  | 
lemma rev_contrapos:  | 
|
464  | 
assumes pq: "P ==> Q"  | 
|
465  | 
and nq: "~Q"  | 
|
466  | 
shows "~P"  | 
|
467  | 
apply (rule nq [THEN contrapos_nn])  | 
|
468  | 
apply (erule pq)  | 
|
469  | 
done  | 
|
470  | 
||
| 20944 | 471  | 
subsubsection {*Existential quantifier*}
 | 
| 15411 | 472  | 
|
473  | 
lemma exI: "P x ==> EX x::'a. P x"  | 
|
474  | 
apply (unfold Ex_def)  | 
|
| 17589 | 475  | 
apply (iprover intro: allI allE impI mp)  | 
| 15411 | 476  | 
done  | 
477  | 
||
478  | 
lemma exE:  | 
|
479  | 
assumes major: "EX x::'a. P(x)"  | 
|
480  | 
and minor: "!!x. P(x) ==> Q"  | 
|
481  | 
shows "Q"  | 
|
482  | 
apply (rule major [unfolded Ex_def, THEN spec, THEN mp])  | 
|
| 17589 | 483  | 
apply (iprover intro: impI [THEN allI] minor)  | 
| 15411 | 484  | 
done  | 
485  | 
||
486  | 
||
| 20944 | 487  | 
subsubsection {*Conjunction*}
 | 
| 15411 | 488  | 
|
489  | 
lemma conjI: "[| P; Q |] ==> P&Q"  | 
|
490  | 
apply (unfold and_def)  | 
|
| 17589 | 491  | 
apply (iprover intro: impI [THEN allI] mp)  | 
| 15411 | 492  | 
done  | 
493  | 
||
494  | 
lemma conjunct1: "[| P & Q |] ==> P"  | 
|
495  | 
apply (unfold and_def)  | 
|
| 17589 | 496  | 
apply (iprover intro: impI dest: spec mp)  | 
| 15411 | 497  | 
done  | 
498  | 
||
499  | 
lemma conjunct2: "[| P & Q |] ==> Q"  | 
|
500  | 
apply (unfold and_def)  | 
|
| 17589 | 501  | 
apply (iprover intro: impI dest: spec mp)  | 
| 15411 | 502  | 
done  | 
503  | 
||
504  | 
lemma conjE:  | 
|
505  | 
assumes major: "P&Q"  | 
|
506  | 
and minor: "[| P; Q |] ==> R"  | 
|
507  | 
shows "R"  | 
|
508  | 
apply (rule minor)  | 
|
509  | 
apply (rule major [THEN conjunct1])  | 
|
510  | 
apply (rule major [THEN conjunct2])  | 
|
511  | 
done  | 
|
512  | 
||
513  | 
lemma context_conjI:  | 
|
| 23553 | 514  | 
assumes "P" "P ==> Q" shows "P & Q"  | 
515  | 
by (iprover intro: conjI assms)  | 
|
| 15411 | 516  | 
|
517  | 
||
| 20944 | 518  | 
subsubsection {*Disjunction*}
 | 
| 15411 | 519  | 
|
520  | 
lemma disjI1: "P ==> P|Q"  | 
|
521  | 
apply (unfold or_def)  | 
|
| 17589 | 522  | 
apply (iprover intro: allI impI mp)  | 
| 15411 | 523  | 
done  | 
524  | 
||
525  | 
lemma disjI2: "Q ==> P|Q"  | 
|
526  | 
apply (unfold or_def)  | 
|
| 17589 | 527  | 
apply (iprover intro: allI impI mp)  | 
| 15411 | 528  | 
done  | 
529  | 
||
530  | 
lemma disjE:  | 
|
531  | 
assumes major: "P|Q"  | 
|
532  | 
and minorP: "P ==> R"  | 
|
533  | 
and minorQ: "Q ==> R"  | 
|
534  | 
shows "R"  | 
|
| 17589 | 535  | 
by (iprover intro: minorP minorQ impI  | 
| 15411 | 536  | 
major [unfolded or_def, THEN spec, THEN mp, THEN mp])  | 
537  | 
||
538  | 
||
| 20944 | 539  | 
subsubsection {*Classical logic*}
 | 
| 15411 | 540  | 
|
541  | 
lemma classical:  | 
|
542  | 
assumes prem: "~P ==> P"  | 
|
543  | 
shows "P"  | 
|
544  | 
apply (rule True_or_False [THEN disjE, THEN eqTrueE])  | 
|
545  | 
apply assumption  | 
|
546  | 
apply (rule notI [THEN prem, THEN eqTrueI])  | 
|
547  | 
apply (erule subst)  | 
|
548  | 
apply assumption  | 
|
549  | 
done  | 
|
550  | 
||
551  | 
lemmas ccontr = FalseE [THEN classical, standard]  | 
|
552  | 
||
553  | 
(*notE with premises exchanged; it discharges ~R so that it can be used to  | 
|
554  | 
make elimination rules*)  | 
|
555  | 
lemma rev_notE:  | 
|
556  | 
assumes premp: "P"  | 
|
557  | 
and premnot: "~R ==> ~P"  | 
|
558  | 
shows "R"  | 
|
559  | 
apply (rule ccontr)  | 
|
560  | 
apply (erule notE [OF premnot premp])  | 
|
561  | 
done  | 
|
562  | 
||
563  | 
(*Double negation law*)  | 
|
564  | 
lemma notnotD: "~~P ==> P"  | 
|
565  | 
apply (rule classical)  | 
|
566  | 
apply (erule notE)  | 
|
567  | 
apply assumption  | 
|
568  | 
done  | 
|
569  | 
||
570  | 
lemma contrapos_pp:  | 
|
571  | 
assumes p1: "Q"  | 
|
572  | 
and p2: "~P ==> ~Q"  | 
|
573  | 
shows "P"  | 
|
| 17589 | 574  | 
by (iprover intro: classical p1 p2 notE)  | 
| 15411 | 575  | 
|
576  | 
||
| 20944 | 577  | 
subsubsection {*Unique existence*}
 | 
| 15411 | 578  | 
|
579  | 
lemma ex1I:  | 
|
| 23553 | 580  | 
assumes "P a" "!!x. P(x) ==> x=a"  | 
| 15411 | 581  | 
shows "EX! x. P(x)"  | 
| 23553 | 582  | 
by (unfold Ex1_def, iprover intro: assms exI conjI allI impI)  | 
| 15411 | 583  | 
|
584  | 
text{*Sometimes easier to use: the premises have no shared variables.  Safe!*}
 | 
|
585  | 
lemma ex_ex1I:  | 
|
586  | 
assumes ex_prem: "EX x. P(x)"  | 
|
587  | 
and eq: "!!x y. [| P(x); P(y) |] ==> x=y"  | 
|
588  | 
shows "EX! x. P(x)"  | 
|
| 17589 | 589  | 
by (iprover intro: ex_prem [THEN exE] ex1I eq)  | 
| 15411 | 590  | 
|
591  | 
lemma ex1E:  | 
|
592  | 
assumes major: "EX! x. P(x)"  | 
|
593  | 
and minor: "!!x. [| P(x); ALL y. P(y) --> y=x |] ==> R"  | 
|
594  | 
shows "R"  | 
|
595  | 
apply (rule major [unfolded Ex1_def, THEN exE])  | 
|
596  | 
apply (erule conjE)  | 
|
| 17589 | 597  | 
apply (iprover intro: minor)  | 
| 15411 | 598  | 
done  | 
599  | 
||
600  | 
lemma ex1_implies_ex: "EX! x. P x ==> EX x. P x"  | 
|
601  | 
apply (erule ex1E)  | 
|
602  | 
apply (rule exI)  | 
|
603  | 
apply assumption  | 
|
604  | 
done  | 
|
605  | 
||
606  | 
||
| 20944 | 607  | 
subsubsection {*THE: definite description operator*}
 | 
| 15411 | 608  | 
|
609  | 
lemma the_equality:  | 
|
610  | 
assumes prema: "P a"  | 
|
611  | 
and premx: "!!x. P x ==> x=a"  | 
|
612  | 
shows "(THE x. P x) = a"  | 
|
613  | 
apply (rule trans [OF _ the_eq_trivial])  | 
|
614  | 
apply (rule_tac f = "The" in arg_cong)  | 
|
615  | 
apply (rule ext)  | 
|
616  | 
apply (rule iffI)  | 
|
617  | 
apply (erule premx)  | 
|
618  | 
apply (erule ssubst, rule prema)  | 
|
619  | 
done  | 
|
620  | 
||
621  | 
lemma theI:  | 
|
622  | 
assumes "P a" and "!!x. P x ==> x=a"  | 
|
623  | 
shows "P (THE x. P x)"  | 
|
| 23553 | 624  | 
by (iprover intro: assms the_equality [THEN ssubst])  | 
| 15411 | 625  | 
|
626  | 
lemma theI': "EX! x. P x ==> P (THE x. P x)"  | 
|
627  | 
apply (erule ex1E)  | 
|
628  | 
apply (erule theI)  | 
|
629  | 
apply (erule allE)  | 
|
630  | 
apply (erule mp)  | 
|
631  | 
apply assumption  | 
|
632  | 
done  | 
|
633  | 
||
634  | 
(*Easier to apply than theI: only one occurrence of P*)  | 
|
635  | 
lemma theI2:  | 
|
636  | 
assumes "P a" "!!x. P x ==> x=a" "!!x. P x ==> Q x"  | 
|
637  | 
shows "Q (THE x. P x)"  | 
|
| 23553 | 638  | 
by (iprover intro: assms theI)  | 
| 15411 | 639  | 
|
| 18697 | 640  | 
lemma the1_equality [elim?]: "[| EX!x. P x; P a |] ==> (THE x. P x) = a"  | 
| 15411 | 641  | 
apply (rule the_equality)  | 
642  | 
apply assumption  | 
|
643  | 
apply (erule ex1E)  | 
|
644  | 
apply (erule all_dupE)  | 
|
645  | 
apply (drule mp)  | 
|
646  | 
apply assumption  | 
|
647  | 
apply (erule ssubst)  | 
|
648  | 
apply (erule allE)  | 
|
649  | 
apply (erule mp)  | 
|
650  | 
apply assumption  | 
|
651  | 
done  | 
|
652  | 
||
653  | 
lemma the_sym_eq_trivial: "(THE y. x=y) = x"  | 
|
654  | 
apply (rule the_equality)  | 
|
655  | 
apply (rule refl)  | 
|
656  | 
apply (erule sym)  | 
|
657  | 
done  | 
|
658  | 
||
659  | 
||
| 20944 | 660  | 
subsubsection {*Classical intro rules for disjunction and existential quantifiers*}
 | 
| 15411 | 661  | 
|
662  | 
lemma disjCI:  | 
|
663  | 
assumes "~Q ==> P" shows "P|Q"  | 
|
664  | 
apply (rule classical)  | 
|
| 23553 | 665  | 
apply (iprover intro: assms disjI1 disjI2 notI elim: notE)  | 
| 15411 | 666  | 
done  | 
667  | 
||
668  | 
lemma excluded_middle: "~P | P"  | 
|
| 17589 | 669  | 
by (iprover intro: disjCI)  | 
| 15411 | 670  | 
|
| 20944 | 671  | 
text {*
 | 
672  | 
case distinction as a natural deduction rule.  | 
|
673  | 
  Note that @{term "~P"} is the second case, not the first
 | 
|
674  | 
*}  | 
|
| 15411 | 675  | 
lemma case_split_thm:  | 
676  | 
assumes prem1: "P ==> Q"  | 
|
677  | 
and prem2: "~P ==> Q"  | 
|
678  | 
shows "Q"  | 
|
679  | 
apply (rule excluded_middle [THEN disjE])  | 
|
680  | 
apply (erule prem2)  | 
|
681  | 
apply (erule prem1)  | 
|
682  | 
done  | 
|
| 20944 | 683  | 
lemmas case_split = case_split_thm [case_names True False]  | 
| 15411 | 684  | 
|
685  | 
(*Classical implies (-->) elimination. *)  | 
|
686  | 
lemma impCE:  | 
|
687  | 
assumes major: "P-->Q"  | 
|
688  | 
and minor: "~P ==> R" "Q ==> R"  | 
|
689  | 
shows "R"  | 
|
690  | 
apply (rule excluded_middle [of P, THEN disjE])  | 
|
| 17589 | 691  | 
apply (iprover intro: minor major [THEN mp])+  | 
| 15411 | 692  | 
done  | 
693  | 
||
694  | 
(*This version of --> elimination works on Q before P. It works best for  | 
|
695  | 
those cases in which P holds "almost everywhere". Can't install as  | 
|
696  | 
default: would break old proofs.*)  | 
|
697  | 
lemma impCE':  | 
|
698  | 
assumes major: "P-->Q"  | 
|
699  | 
and minor: "Q ==> R" "~P ==> R"  | 
|
700  | 
shows "R"  | 
|
701  | 
apply (rule excluded_middle [of P, THEN disjE])  | 
|
| 17589 | 702  | 
apply (iprover intro: minor major [THEN mp])+  | 
| 15411 | 703  | 
done  | 
704  | 
||
705  | 
(*Classical <-> elimination. *)  | 
|
706  | 
lemma iffCE:  | 
|
707  | 
assumes major: "P=Q"  | 
|
708  | 
and minor: "[| P; Q |] ==> R" "[| ~P; ~Q |] ==> R"  | 
|
709  | 
shows "R"  | 
|
710  | 
apply (rule major [THEN iffE])  | 
|
| 17589 | 711  | 
apply (iprover intro: minor elim: impCE notE)  | 
| 15411 | 712  | 
done  | 
713  | 
||
714  | 
lemma exCI:  | 
|
715  | 
assumes "ALL x. ~P(x) ==> P(a)"  | 
|
716  | 
shows "EX x. P(x)"  | 
|
717  | 
apply (rule ccontr)  | 
|
| 23553 | 718  | 
apply (iprover intro: assms exI allI notI notE [of "\<exists>x. P x"])  | 
| 15411 | 719  | 
done  | 
720  | 
||
721  | 
||
| 12386 | 722  | 
subsubsection {* Intuitionistic Reasoning *}
 | 
723  | 
||
724  | 
lemma impE':  | 
|
| 
12937
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
725  | 
assumes 1: "P --> Q"  | 
| 
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
726  | 
and 2: "Q ==> R"  | 
| 
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
727  | 
and 3: "P --> Q ==> P"  | 
| 
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
728  | 
shows R  | 
| 12386 | 729  | 
proof -  | 
730  | 
from 3 and 1 have P .  | 
|
731  | 
with 1 have Q by (rule impE)  | 
|
732  | 
with 2 show R .  | 
|
733  | 
qed  | 
|
734  | 
||
735  | 
lemma allE':  | 
|
| 
12937
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
736  | 
assumes 1: "ALL x. P x"  | 
| 
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
737  | 
and 2: "P x ==> ALL x. P x ==> Q"  | 
| 
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
738  | 
shows Q  | 
| 12386 | 739  | 
proof -  | 
740  | 
from 1 have "P x" by (rule spec)  | 
|
741  | 
from this and 1 show Q by (rule 2)  | 
|
742  | 
qed  | 
|
743  | 
||
| 
12937
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
744  | 
lemma notE':  | 
| 
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
745  | 
assumes 1: "~ P"  | 
| 
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
746  | 
and 2: "~ P ==> P"  | 
| 
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
747  | 
shows R  | 
| 12386 | 748  | 
proof -  | 
749  | 
from 2 and 1 have P .  | 
|
750  | 
with 1 show R by (rule notE)  | 
|
751  | 
qed  | 
|
752  | 
||
| 
22444
 
fb80fedd192d
added safe intro rules for removing "True" subgoals as well as "~ False" ones.
 
dixon 
parents: 
22377 
diff
changeset
 | 
753  | 
lemma TrueE: "True ==> P ==> P" .  | 
| 
 
fb80fedd192d
added safe intro rules for removing "True" subgoals as well as "~ False" ones.
 
dixon 
parents: 
22377 
diff
changeset
 | 
754  | 
lemma notFalseE: "~ False ==> P ==> P" .  | 
| 
 
fb80fedd192d
added safe intro rules for removing "True" subgoals as well as "~ False" ones.
 
dixon 
parents: 
22377 
diff
changeset
 | 
755  | 
|
| 
22467
 
c9357ef01168
TrueElim and notTrueElim tested and added as safe elim rules.
 
dixon 
parents: 
22445 
diff
changeset
 | 
756  | 
lemmas [Pure.elim!] = disjE iffE FalseE conjE exE TrueE notFalseE  | 
| 15801 | 757  | 
and [Pure.intro!] = iffI conjI impI TrueI notI allI refl  | 
758  | 
and [Pure.elim 2] = allE notE' impE'  | 
|
759  | 
and [Pure.intro] = exI disjI2 disjI1  | 
|
| 12386 | 760  | 
|
761  | 
lemmas [trans] = trans  | 
|
762  | 
and [sym] = sym not_sym  | 
|
| 15801 | 763  | 
and [Pure.elim?] = iffD1 iffD2 impE  | 
| 11750 | 764  | 
|
| 23553 | 765  | 
use "hologic.ML"  | 
766  | 
||
| 
11438
 
3d9222b80989
declare trans [trans]  (*overridden in theory Calculation*);
 
wenzelm 
parents: 
11432 
diff
changeset
 | 
767  | 
|
| 11750 | 768  | 
subsubsection {* Atomizing meta-level connectives *}
 | 
769  | 
||
770  | 
lemma atomize_all [atomize]: "(!!x. P x) == Trueprop (ALL x. P x)"  | 
|
| 12003 | 771  | 
proof  | 
| 9488 | 772  | 
assume "!!x. P x"  | 
| 23389 | 773  | 
then show "ALL x. P x" ..  | 
| 9488 | 774  | 
next  | 
775  | 
assume "ALL x. P x"  | 
|
| 23553 | 776  | 
then show "!!x. P x" by (rule allE)  | 
| 9488 | 777  | 
qed  | 
778  | 
||
| 11750 | 779  | 
lemma atomize_imp [atomize]: "(A ==> B) == Trueprop (A --> B)"  | 
| 12003 | 780  | 
proof  | 
| 9488 | 781  | 
assume r: "A ==> B"  | 
| 10383 | 782  | 
show "A --> B" by (rule impI) (rule r)  | 
| 9488 | 783  | 
next  | 
784  | 
assume "A --> B" and A  | 
|
| 23553 | 785  | 
then show B by (rule mp)  | 
| 9488 | 786  | 
qed  | 
787  | 
||
| 14749 | 788  | 
lemma atomize_not: "(A ==> False) == Trueprop (~A)"  | 
789  | 
proof  | 
|
790  | 
assume r: "A ==> False"  | 
|
791  | 
show "~A" by (rule notI) (rule r)  | 
|
792  | 
next  | 
|
793  | 
assume "~A" and A  | 
|
| 23553 | 794  | 
then show False by (rule notE)  | 
| 14749 | 795  | 
qed  | 
796  | 
||
| 11750 | 797  | 
lemma atomize_eq [atomize]: "(x == y) == Trueprop (x = y)"  | 
| 12003 | 798  | 
proof  | 
| 
10432
 
3dfbc913d184
added axclass inverse and consts inverse, divide (infix "/");
 
wenzelm 
parents: 
10383 
diff
changeset
 | 
799  | 
assume "x == y"  | 
| 23553 | 800  | 
show "x = y" by (unfold `x == y`) (rule refl)  | 
| 
10432
 
3dfbc913d184
added axclass inverse and consts inverse, divide (infix "/");
 
wenzelm 
parents: 
10383 
diff
changeset
 | 
801  | 
next  | 
| 
 
3dfbc913d184
added axclass inverse and consts inverse, divide (infix "/");
 
wenzelm 
parents: 
10383 
diff
changeset
 | 
802  | 
assume "x = y"  | 
| 23553 | 803  | 
then show "x == y" by (rule eq_reflection)  | 
| 
10432
 
3dfbc913d184
added axclass inverse and consts inverse, divide (infix "/");
 
wenzelm 
parents: 
10383 
diff
changeset
 | 
804  | 
qed  | 
| 
 
3dfbc913d184
added axclass inverse and consts inverse, divide (infix "/");
 
wenzelm 
parents: 
10383 
diff
changeset
 | 
805  | 
|
| 12023 | 806  | 
lemma atomize_conj [atomize]:  | 
| 19121 | 807  | 
includes meta_conjunction_syntax  | 
808  | 
shows "(A && B) == Trueprop (A & B)"  | 
|
| 12003 | 809  | 
proof  | 
| 19121 | 810  | 
assume conj: "A && B"  | 
811  | 
show "A & B"  | 
|
812  | 
proof (rule conjI)  | 
|
813  | 
from conj show A by (rule conjunctionD1)  | 
|
814  | 
from conj show B by (rule conjunctionD2)  | 
|
815  | 
qed  | 
|
| 11953 | 816  | 
next  | 
| 19121 | 817  | 
assume conj: "A & B"  | 
818  | 
show "A && B"  | 
|
819  | 
proof -  | 
|
820  | 
from conj show A ..  | 
|
821  | 
from conj show B ..  | 
|
| 11953 | 822  | 
qed  | 
823  | 
qed  | 
|
824  | 
||
| 12386 | 825  | 
lemmas [symmetric, rulify] = atomize_all atomize_imp  | 
| 18832 | 826  | 
and [symmetric, defn] = atomize_all atomize_imp atomize_eq  | 
| 12386 | 827  | 
|
| 11750 | 828  | 
|
| 20944 | 829  | 
subsection {* Package setup *}
 | 
830  | 
||
| 11750 | 831  | 
subsubsection {* Classical Reasoner setup *}
 | 
| 9529 | 832  | 
|
| 20944 | 833  | 
lemma thin_refl:  | 
834  | 
"\<And>X. \<lbrakk> x=x; PROP W \<rbrakk> \<Longrightarrow> PROP W" .  | 
|
835  | 
||
| 21151 | 836  | 
ML {*
 | 
837  | 
structure Hypsubst = HypsubstFun(  | 
|
838  | 
struct  | 
|
839  | 
structure Simplifier = Simplifier  | 
|
| 21218 | 840  | 
val dest_eq = HOLogic.dest_eq  | 
| 21151 | 841  | 
val dest_Trueprop = HOLogic.dest_Trueprop  | 
842  | 
val dest_imp = HOLogic.dest_imp  | 
|
| 22129 | 843  | 
  val eq_reflection = @{thm HOL.eq_reflection}
 | 
| 22218 | 844  | 
  val rev_eq_reflection = @{thm HOL.meta_eq_to_obj_eq}
 | 
| 22129 | 845  | 
  val imp_intr = @{thm HOL.impI}
 | 
846  | 
  val rev_mp = @{thm HOL.rev_mp}
 | 
|
847  | 
  val subst = @{thm HOL.subst}
 | 
|
848  | 
  val sym = @{thm HOL.sym}
 | 
|
849  | 
  val thin_refl = @{thm thin_refl};
 | 
|
| 21151 | 850  | 
end);  | 
| 21671 | 851  | 
open Hypsubst;  | 
| 21151 | 852  | 
|
853  | 
structure Classical = ClassicalFun(  | 
|
854  | 
struct  | 
|
| 22129 | 855  | 
  val mp = @{thm HOL.mp}
 | 
856  | 
  val not_elim = @{thm HOL.notE}
 | 
|
857  | 
  val classical = @{thm HOL.classical}
 | 
|
| 21151 | 858  | 
val sizef = Drule.size_of_thm  | 
859  | 
val hyp_subst_tacs = [Hypsubst.hyp_subst_tac]  | 
|
860  | 
end);  | 
|
861  | 
||
862  | 
structure BasicClassical: BASIC_CLASSICAL = Classical;  | 
|
| 21671 | 863  | 
open BasicClassical;  | 
| 22129 | 864  | 
|
865  | 
ML_Context.value_antiq "claset"  | 
|
866  | 
  (Scan.succeed ("claset", "Classical.local_claset_of (ML_Context.the_local_context ())"));
 | 
|
| 21151 | 867  | 
*}  | 
868  | 
||
| 21009 | 869  | 
setup {*
 | 
870  | 
let  | 
|
871  | 
(*prevent substitution on bool*)  | 
|
872  | 
fun hyp_subst_tac' i thm = if i <= Thm.nprems_of thm andalso  | 
|
873  | 
    Term.exists_Const (fn ("op =", Type (_, [T, _])) => T <> Type ("bool", []) | _ => false)
 | 
|
874  | 
(nth (Thm.prems_of thm) (i - 1)) then Hypsubst.hyp_subst_tac i thm else no_tac thm;  | 
|
875  | 
in  | 
|
| 21151 | 876  | 
Hypsubst.hypsubst_setup  | 
877  | 
#> ContextRules.addSWrapper (fn tac => hyp_subst_tac' ORELSE' tac)  | 
|
878  | 
#> Classical.setup  | 
|
879  | 
#> ResAtpset.setup  | 
|
| 21009 | 880  | 
end  | 
881  | 
*}  | 
|
882  | 
||
883  | 
declare iffI [intro!]  | 
|
884  | 
and notI [intro!]  | 
|
885  | 
and impI [intro!]  | 
|
886  | 
and disjCI [intro!]  | 
|
887  | 
and conjI [intro!]  | 
|
888  | 
and TrueI [intro!]  | 
|
889  | 
and refl [intro!]  | 
|
890  | 
||
891  | 
declare iffCE [elim!]  | 
|
892  | 
and FalseE [elim!]  | 
|
893  | 
and impCE [elim!]  | 
|
894  | 
and disjE [elim!]  | 
|
895  | 
and conjE [elim!]  | 
|
896  | 
and conjE [elim!]  | 
|
897  | 
||
898  | 
declare ex_ex1I [intro!]  | 
|
899  | 
and allI [intro!]  | 
|
900  | 
and the_equality [intro]  | 
|
901  | 
and exI [intro]  | 
|
902  | 
||
903  | 
declare exE [elim!]  | 
|
904  | 
allE [elim]  | 
|
905  | 
||
| 22377 | 906  | 
ML {* val HOL_cs = @{claset} *}
 | 
| 19162 | 907  | 
|
| 20223 | 908  | 
lemma contrapos_np: "~ Q ==> (~ P ==> Q) ==> P"  | 
909  | 
apply (erule swap)  | 
|
910  | 
apply (erule (1) meta_mp)  | 
|
911  | 
done  | 
|
| 10383 | 912  | 
|
| 
18689
 
a50587cd8414
prefer ex1I over ex_ex1I in single-step reasoning;
 
wenzelm 
parents: 
18595 
diff
changeset
 | 
913  | 
declare ex_ex1I [rule del, intro! 2]  | 
| 
 
a50587cd8414
prefer ex1I over ex_ex1I in single-step reasoning;
 
wenzelm 
parents: 
18595 
diff
changeset
 | 
914  | 
and ex1I [intro]  | 
| 
 
a50587cd8414
prefer ex1I over ex_ex1I in single-step reasoning;
 
wenzelm 
parents: 
18595 
diff
changeset
 | 
915  | 
|
| 12386 | 916  | 
lemmas [intro?] = ext  | 
917  | 
and [elim?] = ex1_implies_ex  | 
|
| 11977 | 918  | 
|
| 20944 | 919  | 
(*Better then ex1E for classical reasoner: needs no quantifier duplication!*)  | 
| 20973 | 920  | 
lemma alt_ex1E [elim!]:  | 
| 20944 | 921  | 
assumes major: "\<exists>!x. P x"  | 
922  | 
and prem: "\<And>x. \<lbrakk> P x; \<forall>y y'. P y \<and> P y' \<longrightarrow> y = y' \<rbrakk> \<Longrightarrow> R"  | 
|
923  | 
shows R  | 
|
924  | 
apply (rule ex1E [OF major])  | 
|
925  | 
apply (rule prem)  | 
|
| 22129 | 926  | 
apply (tactic {* ares_tac @{thms allI} 1 *})+
 | 
927  | 
apply (tactic {* etac (Classical.dup_elim @{thm allE}) 1 *})
 | 
|
928  | 
apply iprover  | 
|
929  | 
done  | 
|
| 20944 | 930  | 
|
| 21151 | 931  | 
ML {*
 | 
932  | 
structure Blast = BlastFun(  | 
|
933  | 
struct  | 
|
934  | 
type claset = Classical.claset  | 
|
| 
22744
 
5cbe966d67a2
Isar definitions are now added explicitly to code theorem table
 
haftmann 
parents: 
22481 
diff
changeset
 | 
935  | 
  val equality_name = @{const_name "op ="}
 | 
| 22993 | 936  | 
  val not_name = @{const_name Not}
 | 
| 22129 | 937  | 
  val notE = @{thm HOL.notE}
 | 
938  | 
  val ccontr = @{thm HOL.ccontr}
 | 
|
| 21151 | 939  | 
val contr_tac = Classical.contr_tac  | 
940  | 
val dup_intr = Classical.dup_intr  | 
|
941  | 
val hyp_subst_tac = Hypsubst.blast_hyp_subst_tac  | 
|
| 21671 | 942  | 
val claset = Classical.claset  | 
| 21151 | 943  | 
val rep_cs = Classical.rep_cs  | 
944  | 
val cla_modifiers = Classical.cla_modifiers  | 
|
945  | 
val cla_meth' = Classical.cla_meth'  | 
|
946  | 
end);  | 
|
| 21671 | 947  | 
val Blast_tac = Blast.Blast_tac;  | 
948  | 
val blast_tac = Blast.blast_tac;  | 
|
| 20944 | 949  | 
*}  | 
950  | 
||
| 21151 | 951  | 
setup Blast.setup  | 
952  | 
||
| 20944 | 953  | 
|
954  | 
subsubsection {* Simplifier *}
 | 
|
| 12281 | 955  | 
|
956  | 
lemma eta_contract_eq: "(%s. f s) = f" ..  | 
|
957  | 
||
958  | 
lemma simp_thms:  | 
|
| 
12937
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
959  | 
shows not_not: "(~ ~ P) = P"  | 
| 15354 | 960  | 
and Not_eq_iff: "((~P) = (~Q)) = (P = Q)"  | 
| 
12937
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
961  | 
and  | 
| 
12436
 
a2df07fefed7
Replaced several occurrences of "blast" by "rules".
 
berghofe 
parents: 
12386 
diff
changeset
 | 
962  | 
"(P ~= Q) = (P = (~Q))"  | 
| 
 
a2df07fefed7
Replaced several occurrences of "blast" by "rules".
 
berghofe 
parents: 
12386 
diff
changeset
 | 
963  | 
"(P | ~P) = True" "(~P | P) = True"  | 
| 12281 | 964  | 
"(x = x) = True"  | 
| 20944 | 965  | 
and not_True_eq_False: "(\<not> True) = False"  | 
966  | 
and not_False_eq_True: "(\<not> False) = True"  | 
|
967  | 
and  | 
|
| 
12436
 
a2df07fefed7
Replaced several occurrences of "blast" by "rules".
 
berghofe 
parents: 
12386 
diff
changeset
 | 
968  | 
"(~P) ~= P" "P ~= (~P)"  | 
| 20944 | 969  | 
"(True=P) = P"  | 
970  | 
and eq_True: "(P = True) = P"  | 
|
971  | 
and "(False=P) = (~P)"  | 
|
972  | 
and eq_False: "(P = False) = (\<not> P)"  | 
|
973  | 
and  | 
|
| 12281 | 974  | 
"(True --> P) = P" "(False --> P) = True"  | 
975  | 
"(P --> True) = True" "(P --> P) = True"  | 
|
976  | 
"(P --> False) = (~P)" "(P --> ~P) = (~P)"  | 
|
977  | 
"(P & True) = P" "(True & P) = P"  | 
|
978  | 
"(P & False) = False" "(False & P) = False"  | 
|
979  | 
"(P & P) = P" "(P & (P & Q)) = (P & Q)"  | 
|
980  | 
"(P & ~P) = False" "(~P & P) = False"  | 
|
981  | 
"(P | True) = True" "(True | P) = True"  | 
|
982  | 
"(P | False) = P" "(False | P) = P"  | 
|
| 
12436
 
a2df07fefed7
Replaced several occurrences of "blast" by "rules".
 
berghofe 
parents: 
12386 
diff
changeset
 | 
983  | 
"(P | P) = P" "(P | (P | Q)) = (P | Q)" and  | 
| 12281 | 984  | 
"(ALL x. P) = P" "(EX x. P) = P" "EX x. x=t" "EX x. t=x"  | 
985  | 
    -- {* needed for the one-point-rule quantifier simplification procs *}
 | 
|
986  | 
    -- {* essential for termination!! *} and
 | 
|
987  | 
"!!P. (EX x. x=t & P(x)) = P(t)"  | 
|
988  | 
"!!P. (EX x. t=x & P(x)) = P(t)"  | 
|
989  | 
"!!P. (ALL x. x=t --> P(x)) = P(t)"  | 
|
| 
12937
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
990  | 
"!!P. (ALL x. t=x --> P(x)) = P(t)"  | 
| 17589 | 991  | 
by (blast, blast, blast, blast, blast, iprover+)  | 
| 13421 | 992  | 
|
| 14201 | 993  | 
lemma disj_absorb: "(A | A) = A"  | 
994  | 
by blast  | 
|
995  | 
||
996  | 
lemma disj_left_absorb: "(A | (A | B)) = (A | B)"  | 
|
997  | 
by blast  | 
|
998  | 
||
999  | 
lemma conj_absorb: "(A & A) = A"  | 
|
1000  | 
by blast  | 
|
1001  | 
||
1002  | 
lemma conj_left_absorb: "(A & (A & B)) = (A & B)"  | 
|
1003  | 
by blast  | 
|
1004  | 
||
| 12281 | 1005  | 
lemma eq_ac:  | 
| 
12937
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
1006  | 
shows eq_commute: "(a=b) = (b=a)"  | 
| 
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
1007  | 
and eq_left_commute: "(P=(Q=R)) = (Q=(P=R))"  | 
| 17589 | 1008  | 
and eq_assoc: "((P=Q)=R) = (P=(Q=R))" by (iprover, blast+)  | 
1009  | 
lemma neq_commute: "(a~=b) = (b~=a)" by iprover  | 
|
| 12281 | 1010  | 
|
1011  | 
lemma conj_comms:  | 
|
| 
12937
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
1012  | 
shows conj_commute: "(P&Q) = (Q&P)"  | 
| 17589 | 1013  | 
and conj_left_commute: "(P&(Q&R)) = (Q&(P&R))" by iprover+  | 
1014  | 
lemma conj_assoc: "((P&Q)&R) = (P&(Q&R))" by iprover  | 
|
| 12281 | 1015  | 
|
| 19174 | 1016  | 
lemmas conj_ac = conj_commute conj_left_commute conj_assoc  | 
1017  | 
||
| 12281 | 1018  | 
lemma disj_comms:  | 
| 
12937
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
1019  | 
shows disj_commute: "(P|Q) = (Q|P)"  | 
| 17589 | 1020  | 
and disj_left_commute: "(P|(Q|R)) = (Q|(P|R))" by iprover+  | 
1021  | 
lemma disj_assoc: "((P|Q)|R) = (P|(Q|R))" by iprover  | 
|
| 12281 | 1022  | 
|
| 19174 | 1023  | 
lemmas disj_ac = disj_commute disj_left_commute disj_assoc  | 
1024  | 
||
| 17589 | 1025  | 
lemma conj_disj_distribL: "(P&(Q|R)) = (P&Q | P&R)" by iprover  | 
1026  | 
lemma conj_disj_distribR: "((P|Q)&R) = (P&R | Q&R)" by iprover  | 
|
| 12281 | 1027  | 
|
| 17589 | 1028  | 
lemma disj_conj_distribL: "(P|(Q&R)) = ((P|Q) & (P|R))" by iprover  | 
1029  | 
lemma disj_conj_distribR: "((P&Q)|R) = ((P|R) & (Q|R))" by iprover  | 
|
| 12281 | 1030  | 
|
| 17589 | 1031  | 
lemma imp_conjR: "(P --> (Q&R)) = ((P-->Q) & (P-->R))" by iprover  | 
1032  | 
lemma imp_conjL: "((P&Q) -->R) = (P --> (Q --> R))" by iprover  | 
|
1033  | 
lemma imp_disjL: "((P|Q) --> R) = ((P-->R)&(Q-->R))" by iprover  | 
|
| 12281 | 1034  | 
|
1035  | 
text {* These two are specialized, but @{text imp_disj_not1} is useful in @{text "Auth/Yahalom"}. *}
 | 
|
1036  | 
lemma imp_disj_not1: "(P --> Q | R) = (~Q --> P --> R)" by blast  | 
|
1037  | 
lemma imp_disj_not2: "(P --> Q | R) = (~R --> P --> Q)" by blast  | 
|
1038  | 
||
1039  | 
lemma imp_disj1: "((P-->Q)|R) = (P--> Q|R)" by blast  | 
|
1040  | 
lemma imp_disj2: "(Q|(P-->R)) = (P--> Q|R)" by blast  | 
|
1041  | 
||
| 21151 | 1042  | 
lemma imp_cong: "(P = P') ==> (P' ==> (Q = Q')) ==> ((P --> Q) = (P' --> Q'))"  | 
1043  | 
by iprover  | 
|
1044  | 
||
| 17589 | 1045  | 
lemma de_Morgan_disj: "(~(P | Q)) = (~P & ~Q)" by iprover  | 
| 12281 | 1046  | 
lemma de_Morgan_conj: "(~(P & Q)) = (~P | ~Q)" by blast  | 
1047  | 
lemma not_imp: "(~(P --> Q)) = (P & ~Q)" by blast  | 
|
1048  | 
lemma not_iff: "(P~=Q) = (P = (~Q))" by blast  | 
|
1049  | 
lemma disj_not1: "(~P | Q) = (P --> Q)" by blast  | 
|
1050  | 
lemma disj_not2: "(P | ~Q) = (Q --> P)"  -- {* changes orientation :-( *}
 | 
|
1051  | 
by blast  | 
|
1052  | 
lemma imp_conv_disj: "(P --> Q) = ((~P) | Q)" by blast  | 
|
1053  | 
||
| 17589 | 1054  | 
lemma iff_conv_conj_imp: "(P = Q) = ((P --> Q) & (Q --> P))" by iprover  | 
| 12281 | 1055  | 
|
1056  | 
||
1057  | 
lemma cases_simp: "((P --> Q) & (~P --> Q)) = Q"  | 
|
1058  | 
  -- {* Avoids duplication of subgoals after @{text split_if}, when the true and false *}
 | 
|
1059  | 
  -- {* cases boil down to the same thing. *}
 | 
|
1060  | 
by blast  | 
|
1061  | 
||
1062  | 
lemma not_all: "(~ (! x. P(x))) = (? x.~P(x))" by blast  | 
|
1063  | 
lemma imp_all: "((! x. P x) --> Q) = (? x. P x --> Q)" by blast  | 
|
| 17589 | 1064  | 
lemma not_ex: "(~ (? x. P(x))) = (! x.~P(x))" by iprover  | 
1065  | 
lemma imp_ex: "((? x. P x) --> Q) = (! x. P x --> Q)" by iprover  | 
|
| 23403 | 1066  | 
lemma all_not_ex: "(ALL x. P x) = (~ (EX x. ~ P x ))" by blast  | 
| 12281 | 1067  | 
|
| 17589 | 1068  | 
lemma ex_disj_distrib: "(? x. P(x) | Q(x)) = ((? x. P(x)) | (? x. Q(x)))" by iprover  | 
1069  | 
lemma all_conj_distrib: "(!x. P(x) & Q(x)) = ((! x. P(x)) & (! x. Q(x)))" by iprover  | 
|
| 12281 | 1070  | 
|
1071  | 
text {*
 | 
|
1072  | 
  \medskip The @{text "&"} congruence rule: not included by default!
 | 
|
1073  | 
May slow rewrite proofs down by as much as 50\% *}  | 
|
1074  | 
||
1075  | 
lemma conj_cong:  | 
|
1076  | 
"(P = P') ==> (P' ==> (Q = Q')) ==> ((P & Q) = (P' & Q'))"  | 
|
| 17589 | 1077  | 
by iprover  | 
| 12281 | 1078  | 
|
1079  | 
lemma rev_conj_cong:  | 
|
1080  | 
"(Q = Q') ==> (Q' ==> (P = P')) ==> ((P & Q) = (P' & Q'))"  | 
|
| 17589 | 1081  | 
by iprover  | 
| 12281 | 1082  | 
|
1083  | 
text {* The @{text "|"} congruence rule: not included by default! *}
 | 
|
1084  | 
||
1085  | 
lemma disj_cong:  | 
|
1086  | 
"(P = P') ==> (~P' ==> (Q = Q')) ==> ((P | Q) = (P' | Q'))"  | 
|
1087  | 
by blast  | 
|
1088  | 
||
1089  | 
||
1090  | 
text {* \medskip if-then-else rules *}
 | 
|
1091  | 
||
1092  | 
lemma if_True: "(if True then x else y) = x"  | 
|
1093  | 
by (unfold if_def) blast  | 
|
1094  | 
||
1095  | 
lemma if_False: "(if False then x else y) = y"  | 
|
1096  | 
by (unfold if_def) blast  | 
|
1097  | 
||
1098  | 
lemma if_P: "P ==> (if P then x else y) = x"  | 
|
1099  | 
by (unfold if_def) blast  | 
|
1100  | 
||
1101  | 
lemma if_not_P: "~P ==> (if P then x else y) = y"  | 
|
1102  | 
by (unfold if_def) blast  | 
|
1103  | 
||
1104  | 
lemma split_if: "P (if Q then x else y) = ((Q --> P(x)) & (~Q --> P(y)))"  | 
|
1105  | 
apply (rule case_split [of Q])  | 
|
| 15481 | 1106  | 
apply (simplesubst if_P)  | 
1107  | 
prefer 3 apply (simplesubst if_not_P, blast+)  | 
|
| 12281 | 1108  | 
done  | 
1109  | 
||
1110  | 
lemma split_if_asm: "P (if Q then x else y) = (~((Q & ~P x) | (~Q & ~P y)))"  | 
|
| 15481 | 1111  | 
by (simplesubst split_if, blast)  | 
| 12281 | 1112  | 
|
1113  | 
lemmas if_splits = split_if split_if_asm  | 
|
1114  | 
||
1115  | 
lemma if_cancel: "(if c then x else x) = x"  | 
|
| 15481 | 1116  | 
by (simplesubst split_if, blast)  | 
| 12281 | 1117  | 
|
1118  | 
lemma if_eq_cancel: "(if x = y then y else x) = x"  | 
|
| 15481 | 1119  | 
by (simplesubst split_if, blast)  | 
| 12281 | 1120  | 
|
1121  | 
lemma if_bool_eq_conj: "(if P then Q else R) = ((P-->Q) & (~P-->R))"  | 
|
| 19796 | 1122  | 
  -- {* This form is useful for expanding @{text "if"}s on the RIGHT of the @{text "==>"} symbol. *}
 | 
| 12281 | 1123  | 
by (rule split_if)  | 
1124  | 
||
1125  | 
lemma if_bool_eq_disj: "(if P then Q else R) = ((P&Q) | (~P&R))"  | 
|
| 19796 | 1126  | 
  -- {* And this form is useful for expanding @{text "if"}s on the LEFT. *}
 | 
| 15481 | 1127  | 
apply (simplesubst split_if, blast)  | 
| 12281 | 1128  | 
done  | 
1129  | 
||
| 17589 | 1130  | 
lemma Eq_TrueI: "P ==> P == True" by (unfold atomize_eq) iprover  | 
1131  | 
lemma Eq_FalseI: "~P ==> P == False" by (unfold atomize_eq) iprover  | 
|
| 12281 | 1132  | 
|
| 15423 | 1133  | 
text {* \medskip let rules for simproc *}
 | 
1134  | 
||
1135  | 
lemma Let_folded: "f x \<equiv> g x \<Longrightarrow> Let x f \<equiv> Let x g"  | 
|
1136  | 
by (unfold Let_def)  | 
|
1137  | 
||
1138  | 
lemma Let_unfold: "f x \<equiv> g \<Longrightarrow> Let x f \<equiv> g"  | 
|
1139  | 
by (unfold Let_def)  | 
|
1140  | 
||
| 
16633
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1141  | 
text {*
 | 
| 16999 | 1142  | 
The following copy of the implication operator is useful for  | 
1143  | 
fine-tuning congruence rules. It instructs the simplifier to simplify  | 
|
1144  | 
its premise.  | 
|
| 
16633
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1145  | 
*}  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1146  | 
|
| 17197 | 1147  | 
constdefs  | 
1148  | 
simp_implies :: "[prop, prop] => prop" (infixr "=simp=>" 1)  | 
|
1149  | 
"simp_implies \<equiv> op ==>"  | 
|
| 
16633
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1150  | 
|
| 18457 | 1151  | 
lemma simp_impliesI:  | 
| 
16633
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1152  | 
assumes PQ: "(PROP P \<Longrightarrow> PROP Q)"  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1153  | 
shows "PROP P =simp=> PROP Q"  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1154  | 
apply (unfold simp_implies_def)  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1155  | 
apply (rule PQ)  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1156  | 
apply assumption  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1157  | 
done  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1158  | 
|
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1159  | 
lemma simp_impliesE:  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1160  | 
assumes PQ:"PROP P =simp=> PROP Q"  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1161  | 
and P: "PROP P"  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1162  | 
and QR: "PROP Q \<Longrightarrow> PROP R"  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1163  | 
shows "PROP R"  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1164  | 
apply (rule QR)  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1165  | 
apply (rule PQ [unfolded simp_implies_def])  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1166  | 
apply (rule P)  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1167  | 
done  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1168  | 
|
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1169  | 
lemma simp_implies_cong:  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1170  | 
assumes PP' :"PROP P == PROP P'"  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1171  | 
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
 | 
1172  | 
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
 | 
1173  | 
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
 | 
1174  | 
assume PQ: "PROP P \<Longrightarrow> PROP Q"  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1175  | 
and P': "PROP P'"  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1176  | 
from PP' [symmetric] and P' have "PROP P"  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1177  | 
by (rule equal_elim_rule1)  | 
| 23553 | 1178  | 
then have "PROP Q" by (rule PQ)  | 
| 
16633
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1179  | 
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
 | 
1180  | 
next  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1181  | 
assume P'Q': "PROP P' \<Longrightarrow> PROP Q'"  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1182  | 
and P: "PROP P"  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1183  | 
from PP' and P have P': "PROP P'" by (rule equal_elim_rule1)  | 
| 23553 | 1184  | 
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
 | 
1185  | 
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
 | 
1186  | 
by (rule equal_elim_rule1)  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1187  | 
qed  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1188  | 
|
| 20944 | 1189  | 
lemma uncurry:  | 
1190  | 
assumes "P \<longrightarrow> Q \<longrightarrow> R"  | 
|
1191  | 
shows "P \<and> Q \<longrightarrow> R"  | 
|
| 23553 | 1192  | 
using assms by blast  | 
| 20944 | 1193  | 
|
1194  | 
lemma iff_allI:  | 
|
1195  | 
assumes "\<And>x. P x = Q x"  | 
|
1196  | 
shows "(\<forall>x. P x) = (\<forall>x. Q x)"  | 
|
| 23553 | 1197  | 
using assms by blast  | 
| 20944 | 1198  | 
|
1199  | 
lemma iff_exI:  | 
|
1200  | 
assumes "\<And>x. P x = Q x"  | 
|
1201  | 
shows "(\<exists>x. P x) = (\<exists>x. Q x)"  | 
|
| 23553 | 1202  | 
using assms by blast  | 
| 20944 | 1203  | 
|
1204  | 
lemma all_comm:  | 
|
1205  | 
"(\<forall>x y. P x y) = (\<forall>y x. P x y)"  | 
|
1206  | 
by blast  | 
|
1207  | 
||
1208  | 
lemma ex_comm:  | 
|
1209  | 
"(\<exists>x y. P x y) = (\<exists>y x. P x y)"  | 
|
1210  | 
by blast  | 
|
1211  | 
||
| 9869 | 1212  | 
use "simpdata.ML"  | 
| 21671 | 1213  | 
ML {* open Simpdata *}
 | 
1214  | 
||
| 21151 | 1215  | 
setup {*
 | 
1216  | 
Simplifier.method_setup Splitter.split_modifiers  | 
|
| 
21547
 
9c9fdf4c2949
moved order arities for fun and bool to Fun/Orderings
 
haftmann 
parents: 
21524 
diff
changeset
 | 
1217  | 
#> (fn thy => (change_simpset_of thy (fn _ => Simpdata.simpset_simprocs); thy))  | 
| 21151 | 1218  | 
#> Splitter.setup  | 
1219  | 
#> Clasimp.setup  | 
|
1220  | 
#> EqSubst.setup  | 
|
1221  | 
*}  | 
|
1222  | 
||
1223  | 
lemma True_implies_equals: "(True \<Longrightarrow> PROP P) \<equiv> PROP P"  | 
|
1224  | 
proof  | 
|
| 23389 | 1225  | 
assume "True \<Longrightarrow> PROP P"  | 
1226  | 
from this [OF TrueI] show "PROP P" .  | 
|
| 21151 | 1227  | 
next  | 
1228  | 
assume "PROP P"  | 
|
| 23389 | 1229  | 
then show "PROP P" .  | 
| 21151 | 1230  | 
qed  | 
1231  | 
||
1232  | 
lemma ex_simps:  | 
|
1233  | 
"!!P Q. (EX x. P x & Q) = ((EX x. P x) & Q)"  | 
|
1234  | 
"!!P Q. (EX x. P & Q x) = (P & (EX x. Q x))"  | 
|
1235  | 
"!!P Q. (EX x. P x | Q) = ((EX x. P x) | Q)"  | 
|
1236  | 
"!!P Q. (EX x. P | Q x) = (P | (EX x. Q x))"  | 
|
1237  | 
"!!P Q. (EX x. P x --> Q) = ((ALL x. P x) --> Q)"  | 
|
1238  | 
"!!P Q. (EX x. P --> Q x) = (P --> (EX x. Q x))"  | 
|
1239  | 
  -- {* Miniscoping: pushing in existential quantifiers. *}
 | 
|
1240  | 
by (iprover | blast)+  | 
|
1241  | 
||
1242  | 
lemma all_simps:  | 
|
1243  | 
"!!P Q. (ALL x. P x & Q) = ((ALL x. P x) & Q)"  | 
|
1244  | 
"!!P Q. (ALL x. P & Q x) = (P & (ALL x. Q x))"  | 
|
1245  | 
"!!P Q. (ALL x. P x | Q) = ((ALL x. P x) | Q)"  | 
|
1246  | 
"!!P Q. (ALL x. P | Q x) = (P | (ALL x. Q x))"  | 
|
1247  | 
"!!P Q. (ALL x. P x --> Q) = ((EX x. P x) --> Q)"  | 
|
1248  | 
"!!P Q. (ALL x. P --> Q x) = (P --> (ALL x. Q x))"  | 
|
1249  | 
  -- {* Miniscoping: pushing in universal quantifiers. *}
 | 
|
1250  | 
by (iprover | blast)+  | 
|
| 15481 | 1251  | 
|
| 21671 | 1252  | 
lemmas [simp] =  | 
1253  | 
triv_forall_equality (*prunes params*)  | 
|
1254  | 
True_implies_equals (*prune asms `True'*)  | 
|
1255  | 
if_True  | 
|
1256  | 
if_False  | 
|
1257  | 
if_cancel  | 
|
1258  | 
if_eq_cancel  | 
|
1259  | 
imp_disjL  | 
|
| 20973 | 1260  | 
(*In general it seems wrong to add distributive laws by default: they  | 
1261  | 
might cause exponential blow-up. But imp_disjL has been in for a while  | 
|
1262  | 
and cannot be removed without affecting existing proofs. Moreover,  | 
|
1263  | 
rewriting by "(P|Q --> R) = ((P-->R)&(Q-->R))" might be justified on the  | 
|
1264  | 
grounds that it allows simplification of R in the two cases.*)  | 
|
| 21671 | 1265  | 
conj_assoc  | 
1266  | 
disj_assoc  | 
|
1267  | 
de_Morgan_conj  | 
|
1268  | 
de_Morgan_disj  | 
|
1269  | 
imp_disj1  | 
|
1270  | 
imp_disj2  | 
|
1271  | 
not_imp  | 
|
1272  | 
disj_not1  | 
|
1273  | 
not_all  | 
|
1274  | 
not_ex  | 
|
1275  | 
cases_simp  | 
|
1276  | 
the_eq_trivial  | 
|
1277  | 
the_sym_eq_trivial  | 
|
1278  | 
ex_simps  | 
|
1279  | 
all_simps  | 
|
1280  | 
simp_thms  | 
|
1281  | 
||
1282  | 
lemmas [cong] = imp_cong simp_implies_cong  | 
|
1283  | 
lemmas [split] = split_if  | 
|
| 20973 | 1284  | 
|
| 22377 | 1285  | 
ML {* val HOL_ss = @{simpset} *}
 | 
| 20973 | 1286  | 
|
| 20944 | 1287  | 
text {* Simplifies x assuming c and y assuming ~c *}
 | 
1288  | 
lemma if_cong:  | 
|
1289  | 
assumes "b = c"  | 
|
1290  | 
and "c \<Longrightarrow> x = u"  | 
|
1291  | 
and "\<not> c \<Longrightarrow> y = v"  | 
|
1292  | 
shows "(if b then x else y) = (if c then u else v)"  | 
|
| 23553 | 1293  | 
unfolding if_def using assms by simp  | 
| 20944 | 1294  | 
|
1295  | 
text {* Prevents simplification of x and y:
 | 
|
1296  | 
faster and allows the execution of functional programs. *}  | 
|
1297  | 
lemma if_weak_cong [cong]:  | 
|
1298  | 
assumes "b = c"  | 
|
1299  | 
shows "(if b then x else y) = (if c then x else y)"  | 
|
| 23553 | 1300  | 
using assms by (rule arg_cong)  | 
| 20944 | 1301  | 
|
1302  | 
text {* Prevents simplification of t: much faster *}
 | 
|
1303  | 
lemma let_weak_cong:  | 
|
1304  | 
assumes "a = b"  | 
|
1305  | 
shows "(let x = a in t x) = (let x = b in t x)"  | 
|
| 23553 | 1306  | 
using assms by (rule arg_cong)  | 
| 20944 | 1307  | 
|
1308  | 
text {* To tidy up the result of a simproc.  Only the RHS will be simplified. *}
 | 
|
1309  | 
lemma eq_cong2:  | 
|
1310  | 
assumes "u = u'"  | 
|
1311  | 
shows "(t \<equiv> u) \<equiv> (t \<equiv> u')"  | 
|
| 23553 | 1312  | 
using assms by simp  | 
| 20944 | 1313  | 
|
1314  | 
lemma if_distrib:  | 
|
1315  | 
"f (if c then x else y) = (if c then f x else f y)"  | 
|
1316  | 
by simp  | 
|
1317  | 
||
1318  | 
text {* This lemma restricts the effect of the rewrite rule u=v to the left-hand
 | 
|
| 21502 | 1319  | 
  side of an equality.  Used in @{text "{Integ,Real}/simproc.ML"} *}
 | 
| 20944 | 1320  | 
lemma restrict_to_left:  | 
1321  | 
assumes "x = y"  | 
|
1322  | 
shows "(x = z) = (y = z)"  | 
|
| 23553 | 1323  | 
using assms by simp  | 
| 20944 | 1324  | 
|
| 17459 | 1325  | 
|
| 20944 | 1326  | 
subsubsection {* Generic cases and induction *}
 | 
| 17459 | 1327  | 
|
| 20944 | 1328  | 
text {* Rule projections: *}
 | 
| 18887 | 1329  | 
|
| 20944 | 1330  | 
ML {*
 | 
1331  | 
structure ProjectRule = ProjectRuleFun  | 
|
1332  | 
(struct  | 
|
| 22129 | 1333  | 
  val conjunct1 = @{thm conjunct1};
 | 
1334  | 
  val conjunct2 = @{thm conjunct2};
 | 
|
1335  | 
  val mp = @{thm mp};
 | 
|
| 20944 | 1336  | 
end)  | 
| 17459 | 1337  | 
*}  | 
1338  | 
||
| 
11824
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1339  | 
constdefs  | 
| 18457 | 1340  | 
induct_forall where "induct_forall P == \<forall>x. P x"  | 
1341  | 
induct_implies where "induct_implies A B == A \<longrightarrow> B"  | 
|
1342  | 
induct_equal where "induct_equal x y == x = y"  | 
|
1343  | 
induct_conj where "induct_conj A B == A \<and> B"  | 
|
| 
11824
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1344  | 
|
| 11989 | 1345  | 
lemma induct_forall_eq: "(!!x. P x) == Trueprop (induct_forall (\<lambda>x. P x))"  | 
| 18457 | 1346  | 
by (unfold atomize_all induct_forall_def)  | 
| 
11824
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1347  | 
|
| 11989 | 1348  | 
lemma induct_implies_eq: "(A ==> B) == Trueprop (induct_implies A B)"  | 
| 18457 | 1349  | 
by (unfold atomize_imp induct_implies_def)  | 
| 
11824
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1350  | 
|
| 11989 | 1351  | 
lemma induct_equal_eq: "(x == y) == Trueprop (induct_equal x y)"  | 
| 18457 | 1352  | 
by (unfold atomize_eq induct_equal_def)  | 
1353  | 
||
1354  | 
lemma induct_conj_eq:  | 
|
1355  | 
includes meta_conjunction_syntax  | 
|
1356  | 
shows "(A && B) == Trueprop (induct_conj A B)"  | 
|
1357  | 
by (unfold atomize_conj induct_conj_def)  | 
|
1358  | 
||
1359  | 
lemmas induct_atomize = induct_forall_eq induct_implies_eq induct_equal_eq induct_conj_eq  | 
|
1360  | 
lemmas induct_rulify [symmetric, standard] = induct_atomize  | 
|
1361  | 
lemmas induct_rulify_fallback =  | 
|
1362  | 
induct_forall_def induct_implies_def induct_equal_def induct_conj_def  | 
|
1363  | 
||
| 
11824
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1364  | 
|
| 11989 | 1365  | 
lemma induct_forall_conj: "induct_forall (\<lambda>x. induct_conj (A x) (B x)) =  | 
1366  | 
induct_conj (induct_forall A) (induct_forall B)"  | 
|
| 17589 | 1367  | 
by (unfold induct_forall_def induct_conj_def) iprover  | 
| 
11824
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1368  | 
|
| 11989 | 1369  | 
lemma induct_implies_conj: "induct_implies C (induct_conj A B) =  | 
1370  | 
induct_conj (induct_implies C A) (induct_implies C B)"  | 
|
| 17589 | 1371  | 
by (unfold induct_implies_def induct_conj_def) iprover  | 
| 11989 | 1372  | 
|
| 
13598
 
8bc77b17f59f
Fixed problem with induct_conj_curry: variable C should have type prop.
 
berghofe 
parents: 
13596 
diff
changeset
 | 
1373  | 
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
 | 
1374  | 
proof  | 
| 
 
8bc77b17f59f
Fixed problem with induct_conj_curry: variable C should have type prop.
 
berghofe 
parents: 
13596 
diff
changeset
 | 
1375  | 
assume r: "induct_conj A B ==> PROP C" and A B  | 
| 18457 | 1376  | 
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
 | 
1377  | 
next  | 
| 
 
8bc77b17f59f
Fixed problem with induct_conj_curry: variable C should have type prop.
 
berghofe 
parents: 
13596 
diff
changeset
 | 
1378  | 
assume r: "A ==> B ==> PROP C" and "induct_conj A B"  | 
| 18457 | 1379  | 
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
 | 
1380  | 
qed  | 
| 
11824
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1381  | 
|
| 11989 | 1382  | 
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
 | 
1383  | 
|
| 11989 | 1384  | 
hide const induct_forall induct_implies induct_equal induct_conj  | 
| 
11824
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1385  | 
|
| 
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1386  | 
text {* Method setup. *}
 | 
| 
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1387  | 
|
| 
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1388  | 
ML {*
 | 
| 
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1389  | 
structure InductMethod = InductMethodFun  | 
| 
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1390  | 
(struct  | 
| 22129 | 1391  | 
    val cases_default = @{thm case_split}
 | 
1392  | 
    val atomize = @{thms induct_atomize}
 | 
|
1393  | 
    val rulify = @{thms induct_rulify}
 | 
|
1394  | 
    val rulify_fallback = @{thms induct_rulify_fallback}
 | 
|
| 
11824
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1395  | 
end);  | 
| 
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1396  | 
*}  | 
| 
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1397  | 
|
| 
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1398  | 
setup InductMethod.setup  | 
| 
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1399  | 
|
| 18457 | 1400  | 
|
| 20944 | 1401  | 
|
1402  | 
subsection {* Other simple lemmas and lemma duplicates *}
 | 
|
1403  | 
||
1404  | 
lemma ex1_eq [iff]: "EX! x. x = t" "EX! x. t = x"  | 
|
1405  | 
by blast+  | 
|
1406  | 
||
1407  | 
lemma choice_eq: "(ALL x. EX! y. P x y) = (EX! f. ALL x. P x (f x))"  | 
|
1408  | 
apply (rule iffI)  | 
|
1409  | 
apply (rule_tac a = "%x. THE y. P x y" in ex1I)  | 
|
1410  | 
apply (fast dest!: theI')  | 
|
1411  | 
apply (fast intro: ext the1_equality [symmetric])  | 
|
1412  | 
apply (erule ex1E)  | 
|
1413  | 
apply (rule allI)  | 
|
1414  | 
apply (rule ex1I)  | 
|
1415  | 
apply (erule spec)  | 
|
1416  | 
apply (erule_tac x = "%z. if z = x then y else f z" in allE)  | 
|
1417  | 
apply (erule impE)  | 
|
1418  | 
apply (rule allI)  | 
|
1419  | 
apply (rule_tac P = "xa = x" in case_split_thm)  | 
|
1420  | 
apply (drule_tac [3] x = x in fun_cong, simp_all)  | 
|
1421  | 
done  | 
|
1422  | 
||
1423  | 
lemma mk_left_commute:  | 
|
| 
21547
 
9c9fdf4c2949
moved order arities for fun and bool to Fun/Orderings
 
haftmann 
parents: 
21524 
diff
changeset
 | 
1424  | 
fixes f (infix "\<otimes>" 60)  | 
| 
 
9c9fdf4c2949
moved order arities for fun and bool to Fun/Orderings
 
haftmann 
parents: 
21524 
diff
changeset
 | 
1425  | 
assumes a: "\<And>x y z. (x \<otimes> y) \<otimes> z = x \<otimes> (y \<otimes> z)" and  | 
| 
 
9c9fdf4c2949
moved order arities for fun and bool to Fun/Orderings
 
haftmann 
parents: 
21524 
diff
changeset
 | 
1426  | 
c: "\<And>x y. x \<otimes> y = y \<otimes> x"  | 
| 
 
9c9fdf4c2949
moved order arities for fun and bool to Fun/Orderings
 
haftmann 
parents: 
21524 
diff
changeset
 | 
1427  | 
shows "x \<otimes> (y \<otimes> z) = y \<otimes> (x \<otimes> z)"  | 
| 20944 | 1428  | 
by (rule trans [OF trans [OF c a] arg_cong [OF c, of "f y"]])  | 
1429  | 
||
| 22218 | 1430  | 
lemmas eq_sym_conv = eq_commute  | 
1431  | 
||
| 
23037
 
6c72943a71b1
added a set of NNF normalization lemmas and nnf_conv
 
chaieb 
parents: 
22993 
diff
changeset
 | 
1432  | 
lemma nnf_simps:  | 
| 
 
6c72943a71b1
added a set of NNF normalization lemmas and nnf_conv
 
chaieb 
parents: 
22993 
diff
changeset
 | 
1433  | 
"(\<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
 | 
1434  | 
"(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
 | 
1435  | 
"(\<not> \<not>(P)) = P"  | 
| 
 
6c72943a71b1
added a set of NNF normalization lemmas and nnf_conv
 
chaieb 
parents: 
22993 
diff
changeset
 | 
1436  | 
by blast+  | 
| 
 
6c72943a71b1
added a set of NNF normalization lemmas and nnf_conv
 
chaieb 
parents: 
22993 
diff
changeset
 | 
1437  | 
|
| 21671 | 1438  | 
|
1439  | 
subsection {* Basic ML bindings *}
 | 
|
1440  | 
||
1441  | 
ML {*
 | 
|
| 22129 | 1442  | 
val FalseE = @{thm FalseE}
 | 
1443  | 
val Let_def = @{thm Let_def}
 | 
|
1444  | 
val TrueI = @{thm TrueI}
 | 
|
1445  | 
val allE = @{thm allE}
 | 
|
1446  | 
val allI = @{thm allI}
 | 
|
1447  | 
val all_dupE = @{thm all_dupE}
 | 
|
1448  | 
val arg_cong = @{thm arg_cong}
 | 
|
1449  | 
val box_equals = @{thm box_equals}
 | 
|
1450  | 
val ccontr = @{thm ccontr}
 | 
|
1451  | 
val classical = @{thm classical}
 | 
|
1452  | 
val conjE = @{thm conjE}
 | 
|
1453  | 
val conjI = @{thm conjI}
 | 
|
1454  | 
val conjunct1 = @{thm conjunct1}
 | 
|
1455  | 
val conjunct2 = @{thm conjunct2}
 | 
|
1456  | 
val disjCI = @{thm disjCI}
 | 
|
1457  | 
val disjE = @{thm disjE}
 | 
|
1458  | 
val disjI1 = @{thm disjI1}
 | 
|
1459  | 
val disjI2 = @{thm disjI2}
 | 
|
1460  | 
val eq_reflection = @{thm eq_reflection}
 | 
|
1461  | 
val ex1E = @{thm ex1E}
 | 
|
1462  | 
val ex1I = @{thm ex1I}
 | 
|
1463  | 
val ex1_implies_ex = @{thm ex1_implies_ex}
 | 
|
1464  | 
val exE = @{thm exE}
 | 
|
1465  | 
val exI = @{thm exI}
 | 
|
1466  | 
val excluded_middle = @{thm excluded_middle}
 | 
|
1467  | 
val ext = @{thm ext}
 | 
|
1468  | 
val fun_cong = @{thm fun_cong}
 | 
|
1469  | 
val iffD1 = @{thm iffD1}
 | 
|
1470  | 
val iffD2 = @{thm iffD2}
 | 
|
1471  | 
val iffI = @{thm iffI}
 | 
|
1472  | 
val impE = @{thm impE}
 | 
|
1473  | 
val impI = @{thm impI}
 | 
|
1474  | 
val meta_eq_to_obj_eq = @{thm meta_eq_to_obj_eq}
 | 
|
1475  | 
val mp = @{thm mp}
 | 
|
1476  | 
val notE = @{thm notE}
 | 
|
1477  | 
val notI = @{thm notI}
 | 
|
1478  | 
val not_all = @{thm not_all}
 | 
|
1479  | 
val not_ex = @{thm not_ex}
 | 
|
1480  | 
val not_iff = @{thm not_iff}
 | 
|
1481  | 
val not_not = @{thm not_not}
 | 
|
1482  | 
val not_sym = @{thm not_sym}
 | 
|
1483  | 
val refl = @{thm refl}
 | 
|
1484  | 
val rev_mp = @{thm rev_mp}
 | 
|
1485  | 
val spec = @{thm spec}
 | 
|
1486  | 
val ssubst = @{thm ssubst}
 | 
|
1487  | 
val subst = @{thm subst}
 | 
|
1488  | 
val sym = @{thm sym}
 | 
|
1489  | 
val trans = @{thm trans}
 | 
|
| 21671 | 1490  | 
*}  | 
1491  | 
||
1492  | 
||
| 23247 | 1493  | 
subsection {* Code generator setup *}
 | 
1494  | 
||
1495  | 
subsubsection {* SML code generator setup *}
 | 
|
1496  | 
||
1497  | 
use "~~/src/HOL/Tools/recfun_codegen.ML"  | 
|
1498  | 
||
1499  | 
types_code  | 
|
1500  | 
  "bool"  ("bool")
 | 
|
1501  | 
attach (term_of) {*
 | 
|
1502  | 
fun term_of_bool b = if b then HOLogic.true_const else HOLogic.false_const;  | 
|
1503  | 
*}  | 
|
1504  | 
attach (test) {*
 | 
|
1505  | 
fun gen_bool i = one_of [false, true];  | 
|
1506  | 
*}  | 
|
1507  | 
  "prop"  ("bool")
 | 
|
1508  | 
attach (term_of) {*
 | 
|
1509  | 
fun term_of_prop b =  | 
|
1510  | 
HOLogic.mk_Trueprop (if b then HOLogic.true_const else HOLogic.false_const);  | 
|
1511  | 
*}  | 
|
1512  | 
||
1513  | 
consts_code  | 
|
1514  | 
  "Trueprop" ("(_)")
 | 
|
1515  | 
  "True"    ("true")
 | 
|
1516  | 
  "False"   ("false")
 | 
|
1517  | 
  "Not"     ("Bool.not")
 | 
|
1518  | 
  "op |"    ("(_ orelse/ _)")
 | 
|
1519  | 
  "op &"    ("(_ andalso/ _)")
 | 
|
1520  | 
  "If"      ("(if _/ then _/ else _)")
 | 
|
1521  | 
||
1522  | 
setup {*
 | 
|
1523  | 
let  | 
|
1524  | 
||
1525  | 
fun eq_codegen thy defs gr dep thyname b t =  | 
|
1526  | 
(case strip_comb t of  | 
|
1527  | 
       (Const ("op =", Type (_, [Type ("fun", _), _])), _) => NONE
 | 
|
1528  | 
     | (Const ("op =", _), [t, u]) =>
 | 
|
1529  | 
let  | 
|
1530  | 
val (gr', pt) = Codegen.invoke_codegen thy defs dep thyname false (gr, t);  | 
|
1531  | 
val (gr'', pu) = Codegen.invoke_codegen thy defs dep thyname false (gr', u);  | 
|
1532  | 
val (gr''', _) = Codegen.invoke_tycodegen thy defs dep thyname false (gr'', HOLogic.boolT)  | 
|
1533  | 
in  | 
|
1534  | 
SOME (gr''', Codegen.parens  | 
|
1535  | 
(Pretty.block [pt, Pretty.str " =", Pretty.brk 1, pu]))  | 
|
1536  | 
end  | 
|
1537  | 
     | (t as Const ("op =", _), ts) => SOME (Codegen.invoke_codegen
 | 
|
1538  | 
thy defs dep thyname b (gr, Codegen.eta_expand t ts 2))  | 
|
1539  | 
| _ => NONE);  | 
|
1540  | 
||
1541  | 
in  | 
|
1542  | 
||
1543  | 
Codegen.add_codegen "eq_codegen" eq_codegen  | 
|
1544  | 
#> RecfunCodegen.setup  | 
|
1545  | 
||
1546  | 
end  | 
|
1547  | 
*}  | 
|
1548  | 
||
1549  | 
text {* Evaluation *}
 | 
|
1550  | 
||
1551  | 
method_setup evaluation = {*
 | 
|
| 23530 | 1552  | 
Method.no_args (Method.SIMPLE_METHOD' (CONVERSION Codegen.evaluation_conv THEN' rtac TrueI))  | 
| 23247 | 1553  | 
*} "solve goal by evaluation"  | 
1554  | 
||
1555  | 
||
1556  | 
subsubsection {* Generic code generator setup *}
 | 
|
1557  | 
||
1558  | 
text {* operational equality for code generation *}
 | 
|
1559  | 
||
1560  | 
class eq (attach "op =") = type  | 
|
1561  | 
||
1562  | 
||
1563  | 
text {* using built-in Haskell equality *}
 | 
|
1564  | 
||
1565  | 
code_class eq  | 
|
1566  | 
(Haskell "Eq" where "op =" \<equiv> "(==)")  | 
|
1567  | 
||
1568  | 
code_const "op ="  | 
|
1569  | 
(Haskell infixl 4 "==")  | 
|
1570  | 
||
1571  | 
||
1572  | 
text {* type bool *}
 | 
|
1573  | 
||
1574  | 
code_datatype True False  | 
|
1575  | 
||
1576  | 
lemma [code func]:  | 
|
1577  | 
shows "(False \<and> x) = False"  | 
|
1578  | 
and "(True \<and> x) = x"  | 
|
1579  | 
and "(x \<and> False) = False"  | 
|
1580  | 
and "(x \<and> True) = x" by simp_all  | 
|
1581  | 
||
1582  | 
lemma [code func]:  | 
|
1583  | 
shows "(False \<or> x) = x"  | 
|
1584  | 
and "(True \<or> x) = True"  | 
|
1585  | 
and "(x \<or> False) = x"  | 
|
1586  | 
and "(x \<or> True) = True" by simp_all  | 
|
1587  | 
||
1588  | 
lemma [code func]:  | 
|
1589  | 
shows "(\<not> True) = False"  | 
|
1590  | 
and "(\<not> False) = True" by (rule HOL.simp_thms)+  | 
|
1591  | 
||
1592  | 
lemmas [code] = imp_conv_disj  | 
|
1593  | 
||
1594  | 
lemmas [code func] = if_True if_False  | 
|
1595  | 
||
1596  | 
instance bool :: eq ..  | 
|
1597  | 
||
1598  | 
lemma [code func]:  | 
|
1599  | 
shows "True = P \<longleftrightarrow> P"  | 
|
1600  | 
and "False = P \<longleftrightarrow> \<not> P"  | 
|
1601  | 
and "P = True \<longleftrightarrow> P"  | 
|
1602  | 
and "P = False \<longleftrightarrow> \<not> P" by simp_all  | 
|
1603  | 
||
1604  | 
code_type bool  | 
|
1605  | 
(SML "bool")  | 
|
1606  | 
(OCaml "bool")  | 
|
1607  | 
(Haskell "Bool")  | 
|
1608  | 
||
1609  | 
code_instance bool :: eq  | 
|
1610  | 
(Haskell -)  | 
|
1611  | 
||
1612  | 
code_const "op = \<Colon> bool \<Rightarrow> bool \<Rightarrow> bool"  | 
|
1613  | 
(Haskell infixl 4 "==")  | 
|
1614  | 
||
1615  | 
code_const True and False and Not and "op &" and "op |" and If  | 
|
1616  | 
(SML "true" and "false" and "not"  | 
|
1617  | 
and infixl 1 "andalso" and infixl 0 "orelse"  | 
|
1618  | 
and "!(if (_)/ then (_)/ else (_))")  | 
|
1619  | 
(OCaml "true" and "false" and "not"  | 
|
1620  | 
and infixl 4 "&&" and infixl 2 "||"  | 
|
1621  | 
and "!(if (_)/ then (_)/ else (_))")  | 
|
1622  | 
(Haskell "True" and "False" and "not"  | 
|
1623  | 
and infixl 3 "&&" and infixl 2 "||"  | 
|
1624  | 
and "!(if (_)/ then (_)/ else (_))")  | 
|
1625  | 
||
1626  | 
code_reserved SML  | 
|
1627  | 
bool true false not  | 
|
1628  | 
||
1629  | 
code_reserved OCaml  | 
|
| 23511 | 1630  | 
bool not  | 
| 23247 | 1631  | 
|
1632  | 
||
1633  | 
text {* type prop *}
 | 
|
1634  | 
||
1635  | 
code_datatype Trueprop "prop"  | 
|
1636  | 
||
1637  | 
||
1638  | 
text {* type itself *}
 | 
|
1639  | 
||
1640  | 
code_datatype "TYPE('a)"
 | 
|
1641  | 
||
1642  | 
||
1643  | 
text {* code generation for undefined as exception *}
 | 
|
1644  | 
||
1645  | 
code_const undefined  | 
|
1646  | 
(SML "raise/ Fail/ \"undefined\"")  | 
|
1647  | 
(OCaml "failwith/ \"undefined\"")  | 
|
1648  | 
(Haskell "error/ \"undefined\"")  | 
|
1649  | 
||
1650  | 
code_reserved SML Fail  | 
|
1651  | 
code_reserved OCaml failwith  | 
|
1652  | 
||
1653  | 
||
1654  | 
subsubsection {* Evaluation oracle *}
 | 
|
1655  | 
||
1656  | 
oracle eval_oracle ("term") = {* fn thy => fn t => 
 | 
|
1657  | 
if CodegenPackage.satisfies thy (HOLogic.dest_Trueprop t) []  | 
|
1658  | 
then t  | 
|
1659  | 
else HOLogic.Trueprop $ HOLogic.true_const (*dummy*)  | 
|
1660  | 
*}  | 
|
1661  | 
||
1662  | 
method_setup eval = {*
 | 
|
1663  | 
let  | 
|
1664  | 
fun eval_tac thy =  | 
|
1665  | 
SUBGOAL (fn (t, i) => rtac (eval_oracle thy t) i)  | 
|
1666  | 
in  | 
|
1667  | 
Method.ctxt_args (fn ctxt =>  | 
|
1668  | 
Method.SIMPLE_METHOD' (eval_tac (ProofContext.theory_of ctxt)))  | 
|
1669  | 
end  | 
|
1670  | 
*} "solve goal by evaluation"  | 
|
1671  | 
||
1672  | 
||
1673  | 
subsubsection {* Normalization by evaluation *}
 | 
|
1674  | 
||
1675  | 
method_setup normalization = {*
 | 
|
| 23530 | 1676  | 
Method.no_args (Method.SIMPLE_METHOD'  | 
| 
23566
 
b65692d4adcd
replaced HOLogic.Trueprop_conv by ObjectLogic.judgment_conv;
 
wenzelm 
parents: 
23553 
diff
changeset
 | 
1677  | 
(CONVERSION (ObjectLogic.judgment_conv NBE.normalization_conv)  | 
| 
 
b65692d4adcd
replaced HOLogic.Trueprop_conv by ObjectLogic.judgment_conv;
 
wenzelm 
parents: 
23553 
diff
changeset
 | 
1678  | 
THEN' resolve_tac [TrueI, refl]))  | 
| 23247 | 1679  | 
*} "solve goal by normalization"  | 
1680  | 
||
1681  | 
||
1682  | 
text {* lazy @{const If} *}
 | 
|
1683  | 
||
1684  | 
definition  | 
|
1685  | 
if_delayed :: "bool \<Rightarrow> (bool \<Rightarrow> 'a) \<Rightarrow> (bool \<Rightarrow> 'a) \<Rightarrow> 'a" where  | 
|
1686  | 
[code func del]: "if_delayed b f g = (if b then f True else g False)"  | 
|
1687  | 
||
1688  | 
lemma [code func]:  | 
|
1689  | 
shows "if_delayed True f g = f True"  | 
|
1690  | 
and "if_delayed False f g = g False"  | 
|
1691  | 
unfolding if_delayed_def by simp_all  | 
|
1692  | 
||
1693  | 
lemma [normal pre, symmetric, normal post]:  | 
|
1694  | 
"(if b then x else y) = if_delayed b (\<lambda>_. x) (\<lambda>_. y)"  | 
|
1695  | 
unfolding if_delayed_def ..  | 
|
1696  | 
||
1697  | 
hide (open) const if_delayed  | 
|
1698  | 
||
1699  | 
||
| 22839 | 1700  | 
subsection {* Legacy tactics and ML bindings *}
 | 
| 21671 | 1701  | 
|
1702  | 
ML {*
 | 
|
1703  | 
fun strip_tac i = REPEAT (resolve_tac [impI, allI] i);  | 
|
1704  | 
||
1705  | 
(* combination of (spec RS spec RS ...(j times) ... spec RS mp) *)  | 
|
1706  | 
local  | 
|
1707  | 
  fun wrong_prem (Const ("All", _) $ (Abs (_, _, t))) = wrong_prem t
 | 
|
1708  | 
| wrong_prem (Bound _) = true  | 
|
1709  | 
| wrong_prem _ = false;  | 
|
1710  | 
val filter_right = filter (not o wrong_prem o HOLogic.dest_Trueprop o hd o Thm.prems_of);  | 
|
1711  | 
in  | 
|
1712  | 
fun smp i = funpow i (fn m => filter_right ([spec] RL m)) ([mp]);  | 
|
1713  | 
fun smp_tac j = EVERY'[dresolve_tac (smp j), atac];  | 
|
1714  | 
end;  | 
|
| 22839 | 1715  | 
|
1716  | 
val all_conj_distrib = thm "all_conj_distrib";  | 
|
1717  | 
val all_simps = thms "all_simps";  | 
|
1718  | 
val atomize_not = thm "atomize_not";  | 
|
1719  | 
val case_split = thm "case_split_thm";  | 
|
1720  | 
val case_split_thm = thm "case_split_thm"  | 
|
1721  | 
val cases_simp = thm "cases_simp";  | 
|
1722  | 
val choice_eq = thm "choice_eq"  | 
|
1723  | 
val cong = thm "cong"  | 
|
1724  | 
val conj_comms = thms "conj_comms";  | 
|
1725  | 
val conj_cong = thm "conj_cong";  | 
|
1726  | 
val de_Morgan_conj = thm "de_Morgan_conj";  | 
|
1727  | 
val de_Morgan_disj = thm "de_Morgan_disj";  | 
|
1728  | 
val disj_assoc = thm "disj_assoc";  | 
|
1729  | 
val disj_comms = thms "disj_comms";  | 
|
1730  | 
val disj_cong = thm "disj_cong";  | 
|
1731  | 
val eq_ac = thms "eq_ac";  | 
|
1732  | 
val eq_cong2 = thm "eq_cong2"  | 
|
1733  | 
val Eq_FalseI = thm "Eq_FalseI";  | 
|
1734  | 
val Eq_TrueI = thm "Eq_TrueI";  | 
|
1735  | 
val Ex1_def = thm "Ex1_def"  | 
|
1736  | 
val ex_disj_distrib = thm "ex_disj_distrib";  | 
|
1737  | 
val ex_simps = thms "ex_simps";  | 
|
1738  | 
val if_cancel = thm "if_cancel";  | 
|
1739  | 
val if_eq_cancel = thm "if_eq_cancel";  | 
|
1740  | 
val if_False = thm "if_False";  | 
|
1741  | 
val iff_conv_conj_imp = thm "iff_conv_conj_imp";  | 
|
1742  | 
val iff = thm "iff"  | 
|
1743  | 
val if_splits = thms "if_splits";  | 
|
1744  | 
val if_True = thm "if_True";  | 
|
1745  | 
val if_weak_cong = thm "if_weak_cong"  | 
|
1746  | 
val imp_all = thm "imp_all";  | 
|
1747  | 
val imp_cong = thm "imp_cong";  | 
|
1748  | 
val imp_conjL = thm "imp_conjL";  | 
|
1749  | 
val imp_conjR = thm "imp_conjR";  | 
|
1750  | 
val imp_conv_disj = thm "imp_conv_disj";  | 
|
1751  | 
val simp_implies_def = thm "simp_implies_def";  | 
|
1752  | 
val simp_thms = thms "simp_thms";  | 
|
1753  | 
val split_if = thm "split_if";  | 
|
1754  | 
val the1_equality = thm "the1_equality"  | 
|
1755  | 
val theI = thm "theI"  | 
|
1756  | 
val theI' = thm "theI'"  | 
|
1757  | 
val True_implies_equals = thm "True_implies_equals";  | 
|
| 
23037
 
6c72943a71b1
added a set of NNF normalization lemmas and nnf_conv
 
chaieb 
parents: 
22993 
diff
changeset
 | 
1758  | 
val nnf_conv = Simplifier.rewrite (HOL_basic_ss addsimps simp_thms @ @{thms "nnf_simps"})
 | 
| 
 
6c72943a71b1
added a set of NNF normalization lemmas and nnf_conv
 
chaieb 
parents: 
22993 
diff
changeset
 | 
1759  | 
|
| 21671 | 1760  | 
*}  | 
1761  | 
||
| 14357 | 1762  | 
end  |