| author | wenzelm | 
| Thu, 03 Aug 2006 17:30:39 +0200 | |
| changeset 20331 | ccdd1592f5ff | 
| parent 20223 | 89d2758ecddf | 
| child 20380 | 14f9f2a1caa6 | 
| 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  | 
| 18595 | 10  | 
uses ("cladata.ML") ("blastdata.ML") ("simpdata.ML")
 | 
| 19174 | 11  | 
"Tools/res_atpset.ML"  | 
| 
16775
 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 
avigad 
parents: 
16633 
diff
changeset
 | 
12  | 
|
| 15131 | 13  | 
begin  | 
| 2260 | 14  | 
|
| 11750 | 15  | 
subsection {* Primitive logic *}
 | 
16  | 
||
17  | 
subsubsection {* Core syntax *}
 | 
|
| 2260 | 18  | 
|
| 14854 | 19  | 
classes type  | 
| 
12338
 
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
 
wenzelm 
parents: 
12281 
diff
changeset
 | 
20  | 
defaultsort type  | 
| 3947 | 21  | 
|
| 
12338
 
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
 
wenzelm 
parents: 
12281 
diff
changeset
 | 
22  | 
global  | 
| 923 | 23  | 
|
| 7357 | 24  | 
typedecl bool  | 
| 923 | 25  | 
|
26  | 
arities  | 
|
| 
12338
 
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
 
wenzelm 
parents: 
12281 
diff
changeset
 | 
27  | 
bool :: type  | 
| 
 
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
 
wenzelm 
parents: 
12281 
diff
changeset
 | 
28  | 
fun :: (type, type) type  | 
| 923 | 29  | 
|
| 11750 | 30  | 
judgment  | 
31  | 
  Trueprop      :: "bool => prop"                   ("(_)" 5)
 | 
|
| 923 | 32  | 
|
| 11750 | 33  | 
consts  | 
| 7357 | 34  | 
  Not           :: "bool => bool"                   ("~ _" [40] 40)
 | 
35  | 
True :: bool  | 
|
36  | 
False :: bool  | 
|
| 3947 | 37  | 
arbitrary :: 'a  | 
| 20172 | 38  | 
undefined :: 'a  | 
| 923 | 39  | 
|
| 
11432
 
8a203ae6efe3
added "The" (definite description operator) (by Larry);
 
wenzelm 
parents: 
10489 
diff
changeset
 | 
40  | 
  The           :: "('a => bool) => 'a"
 | 
| 7357 | 41  | 
  All           :: "('a => bool) => bool"           (binder "ALL " 10)
 | 
42  | 
  Ex            :: "('a => bool) => bool"           (binder "EX " 10)
 | 
|
43  | 
  Ex1           :: "('a => bool) => bool"           (binder "EX! " 10)
 | 
|
44  | 
Let :: "['a, 'a => 'b] => 'b"  | 
|
| 923 | 45  | 
|
| 7357 | 46  | 
"=" :: "['a, 'a] => bool" (infixl 50)  | 
47  | 
& :: "[bool, bool] => bool" (infixr 35)  | 
|
48  | 
"|" :: "[bool, bool] => bool" (infixr 30)  | 
|
49  | 
--> :: "[bool, bool] => bool" (infixr 25)  | 
|
| 923 | 50  | 
|
| 
10432
 
3dfbc913d184
added axclass inverse and consts inverse, divide (infix "/");
 
wenzelm 
parents: 
10383 
diff
changeset
 | 
51  | 
local  | 
| 
 
3dfbc913d184
added axclass inverse and consts inverse, divide (infix "/");
 
wenzelm 
parents: 
10383 
diff
changeset
 | 
52  | 
|
| 16587 | 53  | 
consts  | 
54  | 
  If            :: "[bool, 'a, 'a] => 'a"           ("(if (_)/ then (_)/ else (_))" 10)
 | 
|
| 2260 | 55  | 
|
| 
19656
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
56  | 
|
| 11750 | 57  | 
subsubsection {* Additional concrete syntax *}
 | 
| 2260 | 58  | 
|
| 
19656
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
59  | 
const_syntax (output)  | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
60  | 
"op =" (infix "=" 50)  | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
61  | 
|
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
62  | 
abbreviation  | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
63  | 
not_equal :: "['a, 'a] => bool" (infixl "~=" 50)  | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
64  | 
"x ~= y == ~ (x = y)"  | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
65  | 
|
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
66  | 
const_syntax (output)  | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
67  | 
not_equal (infix "~=" 50)  | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
68  | 
|
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
69  | 
const_syntax (xsymbols)  | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
70  | 
  Not  ("\<not> _" [40] 40)
 | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
71  | 
"op &" (infixr "\<and>" 35)  | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
72  | 
"op |" (infixr "\<or>" 30)  | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
73  | 
"op -->" (infixr "\<longrightarrow>" 25)  | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
74  | 
not_equal (infix "\<noteq>" 50)  | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
75  | 
|
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
76  | 
const_syntax (HTML output)  | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
77  | 
  Not  ("\<not> _" [40] 40)
 | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
78  | 
"op &" (infixr "\<and>" 35)  | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
79  | 
"op |" (infixr "\<or>" 30)  | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
80  | 
not_equal (infix "\<noteq>" 50)  | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
81  | 
|
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
82  | 
abbreviation (iff)  | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
83  | 
iff :: "[bool, bool] => bool" (infixr "<->" 25)  | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
84  | 
"A <-> B == A = B"  | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
85  | 
|
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
86  | 
const_syntax (xsymbols)  | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
87  | 
iff (infixr "\<longleftrightarrow>" 25)  | 
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
88  | 
|
| 
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
89  | 
|
| 4868 | 90  | 
nonterminals  | 
| 923 | 91  | 
letbinds letbind  | 
92  | 
case_syn cases_syn  | 
|
93  | 
||
94  | 
syntax  | 
|
| 
11432
 
8a203ae6efe3
added "The" (definite description operator) (by Larry);
 
wenzelm 
parents: 
10489 
diff
changeset
 | 
95  | 
  "_The"        :: "[pttrn, bool] => 'a"                 ("(3THE _./ _)" [0, 10] 10)
 | 
| 923 | 96  | 
|
| 7357 | 97  | 
  "_bind"       :: "[pttrn, 'a] => letbind"              ("(2_ =/ _)" 10)
 | 
98  | 
  ""            :: "letbind => letbinds"                 ("_")
 | 
|
99  | 
  "_binds"      :: "[letbind, letbinds] => letbinds"     ("_;/ _")
 | 
|
100  | 
  "_Let"        :: "[letbinds, 'a] => 'a"                ("(let (_)/ in (_))" 10)
 | 
|
| 923 | 101  | 
|
| 
9060
 
b0dd884b1848
rename @case to _case_syntax (improves on low-level errors);
 
wenzelm 
parents: 
8959 
diff
changeset
 | 
102  | 
  "_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
 | 
103  | 
  "_case1"      :: "['a, 'b] => case_syn"                ("(2_ =>/ _)" 10)
 | 
| 7357 | 104  | 
  ""            :: "case_syn => cases_syn"               ("_")
 | 
| 
9060
 
b0dd884b1848
rename @case to _case_syntax (improves on low-level errors);
 
wenzelm 
parents: 
8959 
diff
changeset
 | 
105  | 
  "_case2"      :: "[case_syn, cases_syn] => cases_syn"  ("_/ | _")
 | 
| 923 | 106  | 
|
107  | 
translations  | 
|
| 13764 | 108  | 
"THE x. P" == "The (%x. P)"  | 
| 923 | 109  | 
"_Let (_binds b bs) e" == "_Let b (_Let bs e)"  | 
| 1114 | 110  | 
"let x = a in e" == "Let a (%x. e)"  | 
| 923 | 111  | 
|
| 
13763
 
f94b569cd610
added print translations tha avoid eta contraction for important binders.
 
nipkow 
parents: 
13723 
diff
changeset
 | 
112  | 
print_translation {*
 | 
| 
 
f94b569cd610
added print translations tha avoid eta contraction for important binders.
 
nipkow 
parents: 
13723 
diff
changeset
 | 
113  | 
(* To avoid eta-contraction of body: *)  | 
| 
 
f94b569cd610
added print translations tha avoid eta contraction for important binders.
 
nipkow 
parents: 
13723 
diff
changeset
 | 
114  | 
[("The", fn [Abs abs] =>
 | 
| 
 
f94b569cd610
added print translations tha avoid eta contraction for important binders.
 
nipkow 
parents: 
13723 
diff
changeset
 | 
115  | 
let val (x,t) = atomic_abs_tr' abs  | 
| 
 
f94b569cd610
added print translations tha avoid eta contraction for important binders.
 
nipkow 
parents: 
13723 
diff
changeset
 | 
116  | 
in Syntax.const "_The" $ x $ t end)]  | 
| 
 
f94b569cd610
added print translations tha avoid eta contraction for important binders.
 
nipkow 
parents: 
13723 
diff
changeset
 | 
117  | 
*}  | 
| 
 
f94b569cd610
added print translations tha avoid eta contraction for important binders.
 
nipkow 
parents: 
13723 
diff
changeset
 | 
118  | 
|
| 
12114
 
a8e860c86252
eliminated old "symbols" syntax, use "xsymbols" instead;
 
wenzelm 
parents: 
12023 
diff
changeset
 | 
119  | 
syntax (xsymbols)  | 
| 11687 | 120  | 
  "ALL "        :: "[idts, bool] => bool"                ("(3\<forall>_./ _)" [0, 10] 10)
 | 
121  | 
  "EX "         :: "[idts, bool] => bool"                ("(3\<exists>_./ _)" [0, 10] 10)
 | 
|
122  | 
  "EX! "        :: "[idts, bool] => bool"                ("(3\<exists>!_./ _)" [0, 10] 10)
 | 
|
123  | 
  "_case1"      :: "['a, 'b] => case_syn"                ("(2_ \<Rightarrow>/ _)" 10)
 | 
|
| 
14361
 
ad2f5da643b4
* Support for raw latex output in control symbols: \<^raw...>
 
schirmer 
parents: 
14357 
diff
changeset
 | 
124  | 
(*"_case2"      :: "[case_syn, cases_syn] => cases_syn"  ("_/ \<orelse> _")*)
 | 
| 2372 | 125  | 
|
| 6340 | 126  | 
syntax (HTML output)  | 
| 14565 | 127  | 
  "ALL "        :: "[idts, bool] => bool"                ("(3\<forall>_./ _)" [0, 10] 10)
 | 
128  | 
  "EX "         :: "[idts, bool] => bool"                ("(3\<exists>_./ _)" [0, 10] 10)
 | 
|
129  | 
  "EX! "        :: "[idts, bool] => bool"                ("(3\<exists>!_./ _)" [0, 10] 10)
 | 
|
| 6340 | 130  | 
|
| 
7238
 
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
 
wenzelm 
parents: 
7220 
diff
changeset
 | 
131  | 
syntax (HOL)  | 
| 7357 | 132  | 
  "ALL "        :: "[idts, bool] => bool"                ("(3! _./ _)" [0, 10] 10)
 | 
133  | 
  "EX "         :: "[idts, bool] => bool"                ("(3? _./ _)" [0, 10] 10)
 | 
|
134  | 
  "EX! "        :: "[idts, bool] => bool"                ("(3?! _./ _)" [0, 10] 10)
 | 
|
| 
7238
 
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
 
wenzelm 
parents: 
7220 
diff
changeset
 | 
135  | 
|
| 
 
36e58620ffc8
replaced HOL_quantifiers flag by "HOL" print mode;
 
wenzelm 
parents: 
7220 
diff
changeset
 | 
136  | 
|
| 11750 | 137  | 
subsubsection {* Axioms and basic definitions *}
 | 
| 2260 | 138  | 
|
| 7357 | 139  | 
axioms  | 
| 15380 | 140  | 
eq_reflection: "(x=y) ==> (x==y)"  | 
| 923 | 141  | 
|
| 15380 | 142  | 
refl: "t = (t::'a)"  | 
| 6289 | 143  | 
|
| 15380 | 144  | 
ext: "(!!x::'a. (f x ::'b) = g x) ==> (%x. f x) = (%x. g x)"  | 
145  | 
    -- {*Extensionality is built into the meta-logic, and this rule expresses
 | 
|
146  | 
a related property. It is an eta-expanded version of the traditional  | 
|
147  | 
rule, and similar to the ABS rule of HOL*}  | 
|
| 6289 | 148  | 
|
| 
11432
 
8a203ae6efe3
added "The" (definite description operator) (by Larry);
 
wenzelm 
parents: 
10489 
diff
changeset
 | 
149  | 
the_eq_trivial: "(THE x. x = a) = (a::'a)"  | 
| 923 | 150  | 
|
| 15380 | 151  | 
impI: "(P ==> Q) ==> P-->Q"  | 
152  | 
mp: "[| P-->Q; P |] ==> Q"  | 
|
153  | 
||
154  | 
||
155  | 
text{*Thanks to Stephan Merz*}
 | 
|
156  | 
theorem subst:  | 
|
157  | 
assumes eq: "s = t" and p: "P(s)"  | 
|
158  | 
shows "P(t::'a)"  | 
|
159  | 
proof -  | 
|
160  | 
from eq have meta: "s \<equiv> t"  | 
|
161  | 
by (rule eq_reflection)  | 
|
162  | 
from p show ?thesis  | 
|
163  | 
by (unfold meta)  | 
|
164  | 
qed  | 
|
| 923 | 165  | 
|
166  | 
defs  | 
|
| 7357 | 167  | 
True_def: "True == ((%x::bool. x) = (%x. x))"  | 
168  | 
All_def: "All(P) == (P = (%x. True))"  | 
|
| 
11451
 
8abfb4f7bd02
partial restructuring to reduce dependence on Axiom of Choice
 
paulson 
parents: 
11438 
diff
changeset
 | 
169  | 
Ex_def: "Ex(P) == !Q. (!x. P x --> Q) --> Q"  | 
| 7357 | 170  | 
False_def: "False == (!P. P)"  | 
171  | 
not_def: "~ P == P-->False"  | 
|
172  | 
and_def: "P & Q == !R. (P-->Q-->R) --> R"  | 
|
173  | 
or_def: "P | Q == !R. (P-->R) --> (Q-->R) --> R"  | 
|
174  | 
Ex1_def: "Ex1(P) == ? x. P(x) & (! y. P(y) --> y=x)"  | 
|
| 923 | 175  | 
|
| 7357 | 176  | 
axioms  | 
177  | 
iff: "(P-->Q) --> (Q-->P) --> (P=Q)"  | 
|
178  | 
True_or_False: "(P=True) | (P=False)"  | 
|
| 923 | 179  | 
|
180  | 
defs  | 
|
| 7357 | 181  | 
Let_def: "Let s f == f(s)"  | 
| 
11451
 
8abfb4f7bd02
partial restructuring to reduce dependence on Axiom of Choice
 
paulson 
parents: 
11438 
diff
changeset
 | 
182  | 
if_def: "If P x y == THE z::'a. (P=True --> z=x) & (P=False --> z=y)"  | 
| 5069 | 183  | 
|
| 
14223
 
0ee05eef881b
Added support for making constants final, that is, ensuring that no
 
skalberg 
parents: 
14208 
diff
changeset
 | 
184  | 
finalconsts  | 
| 
 
0ee05eef881b
Added support for making constants final, that is, ensuring that no
 
skalberg 
parents: 
14208 
diff
changeset
 | 
185  | 
"op ="  | 
| 
 
0ee05eef881b
Added support for making constants final, that is, ensuring that no
 
skalberg 
parents: 
14208 
diff
changeset
 | 
186  | 
"op -->"  | 
| 
 
0ee05eef881b
Added support for making constants final, that is, ensuring that no
 
skalberg 
parents: 
14208 
diff
changeset
 | 
187  | 
The  | 
| 
 
0ee05eef881b
Added support for making constants final, that is, ensuring that no
 
skalberg 
parents: 
14208 
diff
changeset
 | 
188  | 
arbitrary  | 
| 20172 | 189  | 
undefined  | 
| 3320 | 190  | 
|
| 
19656
 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 
wenzelm 
parents: 
19607 
diff
changeset
 | 
191  | 
|
| 11750 | 192  | 
subsubsection {* Generic algebraic operations *}
 | 
| 4868 | 193  | 
|
| 
12338
 
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
 
wenzelm 
parents: 
12281 
diff
changeset
 | 
194  | 
axclass zero < type  | 
| 
 
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
 
wenzelm 
parents: 
12281 
diff
changeset
 | 
195  | 
axclass one < type  | 
| 
 
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
 
wenzelm 
parents: 
12281 
diff
changeset
 | 
196  | 
axclass plus < type  | 
| 
 
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
 
wenzelm 
parents: 
12281 
diff
changeset
 | 
197  | 
axclass minus < type  | 
| 
 
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
 
wenzelm 
parents: 
12281 
diff
changeset
 | 
198  | 
axclass times < type  | 
| 
 
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
 
wenzelm 
parents: 
12281 
diff
changeset
 | 
199  | 
axclass inverse < type  | 
| 11750 | 200  | 
|
| 
19233
 
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
 
haftmann 
parents: 
19174 
diff
changeset
 | 
201  | 
consts  | 
| 
 
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
 
haftmann 
parents: 
19174 
diff
changeset
 | 
202  | 
plus :: "['a::plus, 'a] => 'a" (infixl "+" 65)  | 
| 
 
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
 
haftmann 
parents: 
19174 
diff
changeset
 | 
203  | 
  uminus           :: "'a::minus => 'a"             ("- _" [81] 80)
 | 
| 
 
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
 
haftmann 
parents: 
19174 
diff
changeset
 | 
204  | 
minus :: "['a::minus, 'a] => 'a" (infixl "-" 65)  | 
| 
 
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
 
haftmann 
parents: 
19174 
diff
changeset
 | 
205  | 
abs :: "'a::minus => 'a"  | 
| 
 
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
 
haftmann 
parents: 
19174 
diff
changeset
 | 
206  | 
times :: "['a::times, 'a] => 'a" (infixl "*" 70)  | 
| 
 
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
 
haftmann 
parents: 
19174 
diff
changeset
 | 
207  | 
inverse :: "'a::inverse => 'a"  | 
| 
 
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
 
haftmann 
parents: 
19174 
diff
changeset
 | 
208  | 
divide :: "['a::inverse, 'a] => 'a" (infixl "'/" 70)  | 
| 
 
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
 
haftmann 
parents: 
19174 
diff
changeset
 | 
209  | 
|
| 11750 | 210  | 
global  | 
211  | 
||
212  | 
consts  | 
|
213  | 
  "0"           :: "'a::zero"                       ("0")
 | 
|
214  | 
  "1"           :: "'a::one"                        ("1")
 | 
|
215  | 
||
| 
13456
 
42601eb7553f
special syntax for index "1" (plain numeral hidden by "1" symbol in HOL);
 
wenzelm 
parents: 
13438 
diff
changeset
 | 
216  | 
syntax  | 
| 
 
42601eb7553f
special syntax for index "1" (plain numeral hidden by "1" symbol in HOL);
 
wenzelm 
parents: 
13438 
diff
changeset
 | 
217  | 
  "_index1"  :: index    ("\<^sub>1")
 | 
| 
 
42601eb7553f
special syntax for index "1" (plain numeral hidden by "1" symbol in HOL);
 
wenzelm 
parents: 
13438 
diff
changeset
 | 
218  | 
translations  | 
| 14690 | 219  | 
(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
 | 
220  | 
|
| 11750 | 221  | 
local  | 
222  | 
||
223  | 
typed_print_translation {*
 | 
|
224  | 
let  | 
|
225  | 
fun tr' c = (c, fn show_sorts => fn T => fn ts =>  | 
|
226  | 
if T = dummyT orelse not (! show_types) andalso can Term.dest_Type T then raise Match  | 
|
227  | 
else Syntax.const Syntax.constrainC $ Syntax.const c $ Syntax.term_of_typ show_sorts T);  | 
|
228  | 
in [tr' "0", tr' "1"] end;  | 
|
229  | 
*} -- {* show types that are presumably too general *}
 | 
|
230  | 
||
231  | 
syntax (xsymbols)  | 
|
232  | 
  abs :: "'a::minus => 'a"    ("\<bar>_\<bar>")
 | 
|
233  | 
syntax (HTML output)  | 
|
234  | 
  abs :: "'a::minus => 'a"    ("\<bar>_\<bar>")
 | 
|
235  | 
||
236  | 
||
| 15411 | 237  | 
subsection {*Equality*}
 | 
238  | 
||
| 18457 | 239  | 
lemma sym: "s = t ==> t = s"  | 
240  | 
by (erule subst) (rule refl)  | 
|
| 15411 | 241  | 
|
| 18457 | 242  | 
lemma ssubst: "t = s ==> P s ==> P t"  | 
243  | 
by (drule sym) (erule subst)  | 
|
| 15411 | 244  | 
|
245  | 
lemma trans: "[| r=s; s=t |] ==> r=t"  | 
|
| 18457 | 246  | 
by (erule subst)  | 
| 15411 | 247  | 
|
| 18457 | 248  | 
lemma def_imp_eq: assumes meq: "A == B" shows "A = B"  | 
249  | 
by (unfold meq) (rule refl)  | 
|
250  | 
||
| 15411 | 251  | 
|
252  | 
(*Useful with eresolve_tac for proving equalties from known equalities.  | 
|
253  | 
a = b  | 
|
254  | 
| |  | 
|
255  | 
c = d *)  | 
|
256  | 
lemma box_equals: "[| a=b; a=c; b=d |] ==> c=d"  | 
|
257  | 
apply (rule trans)  | 
|
258  | 
apply (rule trans)  | 
|
259  | 
apply (rule sym)  | 
|
260  | 
apply assumption+  | 
|
261  | 
done  | 
|
262  | 
||
| 
15524
 
2ef571f80a55
Moved oderings from HOL into the new Orderings.thy
 
nipkow 
parents: 
15481 
diff
changeset
 | 
263  | 
text {* For calculational reasoning: *}
 | 
| 
 
2ef571f80a55
Moved oderings from HOL into the new Orderings.thy
 
nipkow 
parents: 
15481 
diff
changeset
 | 
264  | 
|
| 
 
2ef571f80a55
Moved oderings from HOL into the new Orderings.thy
 
nipkow 
parents: 
15481 
diff
changeset
 | 
265  | 
lemma forw_subst: "a = b ==> P b ==> P a"  | 
| 
 
2ef571f80a55
Moved oderings from HOL into the new Orderings.thy
 
nipkow 
parents: 
15481 
diff
changeset
 | 
266  | 
by (rule ssubst)  | 
| 
 
2ef571f80a55
Moved oderings from HOL into the new Orderings.thy
 
nipkow 
parents: 
15481 
diff
changeset
 | 
267  | 
|
| 
 
2ef571f80a55
Moved oderings from HOL into the new Orderings.thy
 
nipkow 
parents: 
15481 
diff
changeset
 | 
268  | 
lemma back_subst: "P a ==> a = b ==> P b"  | 
| 
 
2ef571f80a55
Moved oderings from HOL into the new Orderings.thy
 
nipkow 
parents: 
15481 
diff
changeset
 | 
269  | 
by (rule subst)  | 
| 
 
2ef571f80a55
Moved oderings from HOL into the new Orderings.thy
 
nipkow 
parents: 
15481 
diff
changeset
 | 
270  | 
|
| 15411 | 271  | 
|
272  | 
subsection {*Congruence rules for application*}
 | 
|
273  | 
||
274  | 
(*similar to AP_THM in Gordon's HOL*)  | 
|
275  | 
lemma fun_cong: "(f::'a=>'b) = g ==> f(x)=g(x)"  | 
|
276  | 
apply (erule subst)  | 
|
277  | 
apply (rule refl)  | 
|
278  | 
done  | 
|
279  | 
||
280  | 
(*similar to AP_TERM in Gordon's HOL and FOL's subst_context*)  | 
|
281  | 
lemma arg_cong: "x=y ==> f(x)=f(y)"  | 
|
282  | 
apply (erule subst)  | 
|
283  | 
apply (rule refl)  | 
|
284  | 
done  | 
|
285  | 
||
| 15655 | 286  | 
lemma arg_cong2: "\<lbrakk> a = b; c = d \<rbrakk> \<Longrightarrow> f a c = f b d"  | 
287  | 
apply (erule ssubst)+  | 
|
288  | 
apply (rule refl)  | 
|
289  | 
done  | 
|
290  | 
||
291  | 
||
| 15411 | 292  | 
lemma cong: "[| f = g; (x::'a) = y |] ==> f(x) = g(y)"  | 
293  | 
apply (erule subst)+  | 
|
294  | 
apply (rule refl)  | 
|
295  | 
done  | 
|
296  | 
||
297  | 
||
298  | 
subsection {*Equality of booleans -- iff*}
 | 
|
299  | 
||
300  | 
lemma iffI: assumes prems: "P ==> Q" "Q ==> P" shows "P=Q"  | 
|
| 18457 | 301  | 
by (iprover intro: iff [THEN mp, THEN mp] impI prems)  | 
| 15411 | 302  | 
|
303  | 
lemma iffD2: "[| P=Q; Q |] ==> P"  | 
|
| 18457 | 304  | 
by (erule ssubst)  | 
| 15411 | 305  | 
|
306  | 
lemma rev_iffD2: "[| Q; P=Q |] ==> P"  | 
|
| 18457 | 307  | 
by (erule iffD2)  | 
| 15411 | 308  | 
|
309  | 
lemmas iffD1 = sym [THEN iffD2, standard]  | 
|
310  | 
lemmas rev_iffD1 = sym [THEN [2] rev_iffD2, standard]  | 
|
311  | 
||
312  | 
lemma iffE:  | 
|
313  | 
assumes major: "P=Q"  | 
|
314  | 
and minor: "[| P --> Q; Q --> P |] ==> R"  | 
|
| 18457 | 315  | 
shows R  | 
316  | 
by (iprover intro: minor impI major [THEN iffD2] major [THEN iffD1])  | 
|
| 15411 | 317  | 
|
318  | 
||
319  | 
subsection {*True*}
 | 
|
320  | 
||
321  | 
lemma TrueI: "True"  | 
|
| 18457 | 322  | 
by (unfold True_def) (rule refl)  | 
| 15411 | 323  | 
|
324  | 
lemma eqTrueI: "P ==> P=True"  | 
|
| 18457 | 325  | 
by (iprover intro: iffI TrueI)  | 
| 15411 | 326  | 
|
327  | 
lemma eqTrueE: "P=True ==> P"  | 
|
328  | 
apply (erule iffD2)  | 
|
329  | 
apply (rule TrueI)  | 
|
330  | 
done  | 
|
331  | 
||
332  | 
||
333  | 
subsection {*Universal quantifier*}
 | 
|
334  | 
||
335  | 
lemma allI: assumes p: "!!x::'a. P(x)" shows "ALL x. P(x)"  | 
|
336  | 
apply (unfold All_def)  | 
|
| 17589 | 337  | 
apply (iprover intro: ext eqTrueI p)  | 
| 15411 | 338  | 
done  | 
339  | 
||
340  | 
lemma spec: "ALL x::'a. P(x) ==> P(x)"  | 
|
341  | 
apply (unfold All_def)  | 
|
342  | 
apply (rule eqTrueE)  | 
|
343  | 
apply (erule fun_cong)  | 
|
344  | 
done  | 
|
345  | 
||
346  | 
lemma allE:  | 
|
347  | 
assumes major: "ALL x. P(x)"  | 
|
348  | 
and minor: "P(x) ==> R"  | 
|
349  | 
shows "R"  | 
|
| 17589 | 350  | 
by (iprover intro: minor major [THEN spec])  | 
| 15411 | 351  | 
|
352  | 
lemma all_dupE:  | 
|
353  | 
assumes major: "ALL x. P(x)"  | 
|
354  | 
and minor: "[| P(x); ALL x. P(x) |] ==> R"  | 
|
355  | 
shows "R"  | 
|
| 17589 | 356  | 
by (iprover intro: minor major major [THEN spec])  | 
| 15411 | 357  | 
|
358  | 
||
359  | 
subsection {*False*}
 | 
|
360  | 
(*Depends upon spec; it is impossible to do propositional logic before quantifiers!*)  | 
|
361  | 
||
362  | 
lemma FalseE: "False ==> P"  | 
|
363  | 
apply (unfold False_def)  | 
|
364  | 
apply (erule spec)  | 
|
365  | 
done  | 
|
366  | 
||
367  | 
lemma False_neq_True: "False=True ==> P"  | 
|
368  | 
by (erule eqTrueE [THEN FalseE])  | 
|
369  | 
||
370  | 
||
371  | 
subsection {*Negation*}
 | 
|
372  | 
||
373  | 
lemma notI:  | 
|
374  | 
assumes p: "P ==> False"  | 
|
375  | 
shows "~P"  | 
|
376  | 
apply (unfold not_def)  | 
|
| 17589 | 377  | 
apply (iprover intro: impI p)  | 
| 15411 | 378  | 
done  | 
379  | 
||
380  | 
lemma False_not_True: "False ~= True"  | 
|
381  | 
apply (rule notI)  | 
|
382  | 
apply (erule False_neq_True)  | 
|
383  | 
done  | 
|
384  | 
||
385  | 
lemma True_not_False: "True ~= False"  | 
|
386  | 
apply (rule notI)  | 
|
387  | 
apply (drule sym)  | 
|
388  | 
apply (erule False_neq_True)  | 
|
389  | 
done  | 
|
390  | 
||
391  | 
lemma notE: "[| ~P; P |] ==> R"  | 
|
392  | 
apply (unfold not_def)  | 
|
393  | 
apply (erule mp [THEN FalseE])  | 
|
394  | 
apply assumption  | 
|
395  | 
done  | 
|
396  | 
||
397  | 
(* Alternative ~ introduction rule: [| P ==> ~ Pa; P ==> Pa |] ==> ~ P *)  | 
|
398  | 
lemmas notI2 = notE [THEN notI, standard]  | 
|
399  | 
||
400  | 
||
401  | 
subsection {*Implication*}
 | 
|
402  | 
||
403  | 
lemma impE:  | 
|
404  | 
assumes "P-->Q" "P" "Q ==> R"  | 
|
405  | 
shows "R"  | 
|
| 17589 | 406  | 
by (iprover intro: prems mp)  | 
| 15411 | 407  | 
|
408  | 
(* Reduces Q to P-->Q, allowing substitution in P. *)  | 
|
409  | 
lemma rev_mp: "[| P; P --> Q |] ==> Q"  | 
|
| 17589 | 410  | 
by (iprover intro: mp)  | 
| 15411 | 411  | 
|
412  | 
lemma contrapos_nn:  | 
|
413  | 
assumes major: "~Q"  | 
|
414  | 
and minor: "P==>Q"  | 
|
415  | 
shows "~P"  | 
|
| 17589 | 416  | 
by (iprover intro: notI minor major [THEN notE])  | 
| 15411 | 417  | 
|
418  | 
(*not used at all, but we already have the other 3 combinations *)  | 
|
419  | 
lemma contrapos_pn:  | 
|
420  | 
assumes major: "Q"  | 
|
421  | 
and minor: "P ==> ~Q"  | 
|
422  | 
shows "~P"  | 
|
| 17589 | 423  | 
by (iprover intro: notI minor major notE)  | 
| 15411 | 424  | 
|
425  | 
lemma not_sym: "t ~= s ==> s ~= t"  | 
|
426  | 
apply (erule contrapos_nn)  | 
|
427  | 
apply (erule sym)  | 
|
428  | 
done  | 
|
429  | 
||
430  | 
(*still used in HOLCF*)  | 
|
431  | 
lemma rev_contrapos:  | 
|
432  | 
assumes pq: "P ==> Q"  | 
|
433  | 
and nq: "~Q"  | 
|
434  | 
shows "~P"  | 
|
435  | 
apply (rule nq [THEN contrapos_nn])  | 
|
436  | 
apply (erule pq)  | 
|
437  | 
done  | 
|
438  | 
||
439  | 
subsection {*Existential quantifier*}
 | 
|
440  | 
||
441  | 
lemma exI: "P x ==> EX x::'a. P x"  | 
|
442  | 
apply (unfold Ex_def)  | 
|
| 17589 | 443  | 
apply (iprover intro: allI allE impI mp)  | 
| 15411 | 444  | 
done  | 
445  | 
||
446  | 
lemma exE:  | 
|
447  | 
assumes major: "EX x::'a. P(x)"  | 
|
448  | 
and minor: "!!x. P(x) ==> Q"  | 
|
449  | 
shows "Q"  | 
|
450  | 
apply (rule major [unfolded Ex_def, THEN spec, THEN mp])  | 
|
| 17589 | 451  | 
apply (iprover intro: impI [THEN allI] minor)  | 
| 15411 | 452  | 
done  | 
453  | 
||
454  | 
||
455  | 
subsection {*Conjunction*}
 | 
|
456  | 
||
457  | 
lemma conjI: "[| P; Q |] ==> P&Q"  | 
|
458  | 
apply (unfold and_def)  | 
|
| 17589 | 459  | 
apply (iprover intro: impI [THEN allI] mp)  | 
| 15411 | 460  | 
done  | 
461  | 
||
462  | 
lemma conjunct1: "[| P & Q |] ==> P"  | 
|
463  | 
apply (unfold and_def)  | 
|
| 17589 | 464  | 
apply (iprover intro: impI dest: spec mp)  | 
| 15411 | 465  | 
done  | 
466  | 
||
467  | 
lemma conjunct2: "[| P & Q |] ==> Q"  | 
|
468  | 
apply (unfold and_def)  | 
|
| 17589 | 469  | 
apply (iprover intro: impI dest: spec mp)  | 
| 15411 | 470  | 
done  | 
471  | 
||
472  | 
lemma conjE:  | 
|
473  | 
assumes major: "P&Q"  | 
|
474  | 
and minor: "[| P; Q |] ==> R"  | 
|
475  | 
shows "R"  | 
|
476  | 
apply (rule minor)  | 
|
477  | 
apply (rule major [THEN conjunct1])  | 
|
478  | 
apply (rule major [THEN conjunct2])  | 
|
479  | 
done  | 
|
480  | 
||
481  | 
lemma context_conjI:  | 
|
482  | 
assumes prems: "P" "P ==> Q" shows "P & Q"  | 
|
| 17589 | 483  | 
by (iprover intro: conjI prems)  | 
| 15411 | 484  | 
|
485  | 
||
486  | 
subsection {*Disjunction*}
 | 
|
487  | 
||
488  | 
lemma disjI1: "P ==> P|Q"  | 
|
489  | 
apply (unfold or_def)  | 
|
| 17589 | 490  | 
apply (iprover intro: allI impI mp)  | 
| 15411 | 491  | 
done  | 
492  | 
||
493  | 
lemma disjI2: "Q ==> P|Q"  | 
|
494  | 
apply (unfold or_def)  | 
|
| 17589 | 495  | 
apply (iprover intro: allI impI mp)  | 
| 15411 | 496  | 
done  | 
497  | 
||
498  | 
lemma disjE:  | 
|
499  | 
assumes major: "P|Q"  | 
|
500  | 
and minorP: "P ==> R"  | 
|
501  | 
and minorQ: "Q ==> R"  | 
|
502  | 
shows "R"  | 
|
| 17589 | 503  | 
by (iprover intro: minorP minorQ impI  | 
| 15411 | 504  | 
major [unfolded or_def, THEN spec, THEN mp, THEN mp])  | 
505  | 
||
506  | 
||
507  | 
subsection {*Classical logic*}
 | 
|
508  | 
||
509  | 
||
510  | 
lemma classical:  | 
|
511  | 
assumes prem: "~P ==> P"  | 
|
512  | 
shows "P"  | 
|
513  | 
apply (rule True_or_False [THEN disjE, THEN eqTrueE])  | 
|
514  | 
apply assumption  | 
|
515  | 
apply (rule notI [THEN prem, THEN eqTrueI])  | 
|
516  | 
apply (erule subst)  | 
|
517  | 
apply assumption  | 
|
518  | 
done  | 
|
519  | 
||
520  | 
lemmas ccontr = FalseE [THEN classical, standard]  | 
|
521  | 
||
522  | 
(*notE with premises exchanged; it discharges ~R so that it can be used to  | 
|
523  | 
make elimination rules*)  | 
|
524  | 
lemma rev_notE:  | 
|
525  | 
assumes premp: "P"  | 
|
526  | 
and premnot: "~R ==> ~P"  | 
|
527  | 
shows "R"  | 
|
528  | 
apply (rule ccontr)  | 
|
529  | 
apply (erule notE [OF premnot premp])  | 
|
530  | 
done  | 
|
531  | 
||
532  | 
(*Double negation law*)  | 
|
533  | 
lemma notnotD: "~~P ==> P"  | 
|
534  | 
apply (rule classical)  | 
|
535  | 
apply (erule notE)  | 
|
536  | 
apply assumption  | 
|
537  | 
done  | 
|
538  | 
||
539  | 
lemma contrapos_pp:  | 
|
540  | 
assumes p1: "Q"  | 
|
541  | 
and p2: "~P ==> ~Q"  | 
|
542  | 
shows "P"  | 
|
| 17589 | 543  | 
by (iprover intro: classical p1 p2 notE)  | 
| 15411 | 544  | 
|
545  | 
||
546  | 
subsection {*Unique existence*}
 | 
|
547  | 
||
548  | 
lemma ex1I:  | 
|
549  | 
assumes prems: "P a" "!!x. P(x) ==> x=a"  | 
|
550  | 
shows "EX! x. P(x)"  | 
|
| 17589 | 551  | 
by (unfold Ex1_def, iprover intro: prems exI conjI allI impI)  | 
| 15411 | 552  | 
|
553  | 
text{*Sometimes easier to use: the premises have no shared variables.  Safe!*}
 | 
|
554  | 
lemma ex_ex1I:  | 
|
555  | 
assumes ex_prem: "EX x. P(x)"  | 
|
556  | 
and eq: "!!x y. [| P(x); P(y) |] ==> x=y"  | 
|
557  | 
shows "EX! x. P(x)"  | 
|
| 17589 | 558  | 
by (iprover intro: ex_prem [THEN exE] ex1I eq)  | 
| 15411 | 559  | 
|
560  | 
lemma ex1E:  | 
|
561  | 
assumes major: "EX! x. P(x)"  | 
|
562  | 
and minor: "!!x. [| P(x); ALL y. P(y) --> y=x |] ==> R"  | 
|
563  | 
shows "R"  | 
|
564  | 
apply (rule major [unfolded Ex1_def, THEN exE])  | 
|
565  | 
apply (erule conjE)  | 
|
| 17589 | 566  | 
apply (iprover intro: minor)  | 
| 15411 | 567  | 
done  | 
568  | 
||
569  | 
lemma ex1_implies_ex: "EX! x. P x ==> EX x. P x"  | 
|
570  | 
apply (erule ex1E)  | 
|
571  | 
apply (rule exI)  | 
|
572  | 
apply assumption  | 
|
573  | 
done  | 
|
574  | 
||
575  | 
||
576  | 
subsection {*THE: definite description operator*}
 | 
|
577  | 
||
578  | 
lemma the_equality:  | 
|
579  | 
assumes prema: "P a"  | 
|
580  | 
and premx: "!!x. P x ==> x=a"  | 
|
581  | 
shows "(THE x. P x) = a"  | 
|
582  | 
apply (rule trans [OF _ the_eq_trivial])  | 
|
583  | 
apply (rule_tac f = "The" in arg_cong)  | 
|
584  | 
apply (rule ext)  | 
|
585  | 
apply (rule iffI)  | 
|
586  | 
apply (erule premx)  | 
|
587  | 
apply (erule ssubst, rule prema)  | 
|
588  | 
done  | 
|
589  | 
||
590  | 
lemma theI:  | 
|
591  | 
assumes "P a" and "!!x. P x ==> x=a"  | 
|
592  | 
shows "P (THE x. P x)"  | 
|
| 17589 | 593  | 
by (iprover intro: prems the_equality [THEN ssubst])  | 
| 15411 | 594  | 
|
595  | 
lemma theI': "EX! x. P x ==> P (THE x. P x)"  | 
|
596  | 
apply (erule ex1E)  | 
|
597  | 
apply (erule theI)  | 
|
598  | 
apply (erule allE)  | 
|
599  | 
apply (erule mp)  | 
|
600  | 
apply assumption  | 
|
601  | 
done  | 
|
602  | 
||
603  | 
(*Easier to apply than theI: only one occurrence of P*)  | 
|
604  | 
lemma theI2:  | 
|
605  | 
assumes "P a" "!!x. P x ==> x=a" "!!x. P x ==> Q x"  | 
|
606  | 
shows "Q (THE x. P x)"  | 
|
| 17589 | 607  | 
by (iprover intro: prems theI)  | 
| 15411 | 608  | 
|
| 18697 | 609  | 
lemma the1_equality [elim?]: "[| EX!x. P x; P a |] ==> (THE x. P x) = a"  | 
| 15411 | 610  | 
apply (rule the_equality)  | 
611  | 
apply assumption  | 
|
612  | 
apply (erule ex1E)  | 
|
613  | 
apply (erule all_dupE)  | 
|
614  | 
apply (drule mp)  | 
|
615  | 
apply assumption  | 
|
616  | 
apply (erule ssubst)  | 
|
617  | 
apply (erule allE)  | 
|
618  | 
apply (erule mp)  | 
|
619  | 
apply assumption  | 
|
620  | 
done  | 
|
621  | 
||
622  | 
lemma the_sym_eq_trivial: "(THE y. x=y) = x"  | 
|
623  | 
apply (rule the_equality)  | 
|
624  | 
apply (rule refl)  | 
|
625  | 
apply (erule sym)  | 
|
626  | 
done  | 
|
627  | 
||
628  | 
||
629  | 
subsection {*Classical intro rules for disjunction and existential quantifiers*}
 | 
|
630  | 
||
631  | 
lemma disjCI:  | 
|
632  | 
assumes "~Q ==> P" shows "P|Q"  | 
|
633  | 
apply (rule classical)  | 
|
| 17589 | 634  | 
apply (iprover intro: prems disjI1 disjI2 notI elim: notE)  | 
| 15411 | 635  | 
done  | 
636  | 
||
637  | 
lemma excluded_middle: "~P | P"  | 
|
| 17589 | 638  | 
by (iprover intro: disjCI)  | 
| 15411 | 639  | 
|
640  | 
text{*case distinction as a natural deduction rule. Note that @{term "~P"}
 | 
|
641  | 
is the second case, not the first.*}  | 
|
642  | 
lemma case_split_thm:  | 
|
643  | 
assumes prem1: "P ==> Q"  | 
|
644  | 
and prem2: "~P ==> Q"  | 
|
645  | 
shows "Q"  | 
|
646  | 
apply (rule excluded_middle [THEN disjE])  | 
|
647  | 
apply (erule prem2)  | 
|
648  | 
apply (erule prem1)  | 
|
649  | 
done  | 
|
650  | 
||
651  | 
(*Classical implies (-->) elimination. *)  | 
|
652  | 
lemma impCE:  | 
|
653  | 
assumes major: "P-->Q"  | 
|
654  | 
and minor: "~P ==> R" "Q ==> R"  | 
|
655  | 
shows "R"  | 
|
656  | 
apply (rule excluded_middle [of P, THEN disjE])  | 
|
| 17589 | 657  | 
apply (iprover intro: minor major [THEN mp])+  | 
| 15411 | 658  | 
done  | 
659  | 
||
660  | 
(*This version of --> elimination works on Q before P. It works best for  | 
|
661  | 
those cases in which P holds "almost everywhere". Can't install as  | 
|
662  | 
default: would break old proofs.*)  | 
|
663  | 
lemma impCE':  | 
|
664  | 
assumes major: "P-->Q"  | 
|
665  | 
and minor: "Q ==> R" "~P ==> R"  | 
|
666  | 
shows "R"  | 
|
667  | 
apply (rule excluded_middle [of P, THEN disjE])  | 
|
| 17589 | 668  | 
apply (iprover intro: minor major [THEN mp])+  | 
| 15411 | 669  | 
done  | 
670  | 
||
671  | 
(*Classical <-> elimination. *)  | 
|
672  | 
lemma iffCE:  | 
|
673  | 
assumes major: "P=Q"  | 
|
674  | 
and minor: "[| P; Q |] ==> R" "[| ~P; ~Q |] ==> R"  | 
|
675  | 
shows "R"  | 
|
676  | 
apply (rule major [THEN iffE])  | 
|
| 17589 | 677  | 
apply (iprover intro: minor elim: impCE notE)  | 
| 15411 | 678  | 
done  | 
679  | 
||
680  | 
lemma exCI:  | 
|
681  | 
assumes "ALL x. ~P(x) ==> P(a)"  | 
|
682  | 
shows "EX x. P(x)"  | 
|
683  | 
apply (rule ccontr)  | 
|
| 17589 | 684  | 
apply (iprover intro: prems exI allI notI notE [of "\<exists>x. P x"])  | 
| 15411 | 685  | 
done  | 
686  | 
||
687  | 
||
688  | 
||
| 11750 | 689  | 
subsection {* Theory and package setup *}
 | 
690  | 
||
| 15411 | 691  | 
ML  | 
692  | 
{*
 | 
|
693  | 
val eq_reflection = thm "eq_reflection"  | 
|
694  | 
val refl = thm "refl"  | 
|
695  | 
val subst = thm "subst"  | 
|
696  | 
val ext = thm "ext"  | 
|
697  | 
val impI = thm "impI"  | 
|
698  | 
val mp = thm "mp"  | 
|
699  | 
val True_def = thm "True_def"  | 
|
700  | 
val All_def = thm "All_def"  | 
|
701  | 
val Ex_def = thm "Ex_def"  | 
|
702  | 
val False_def = thm "False_def"  | 
|
703  | 
val not_def = thm "not_def"  | 
|
704  | 
val and_def = thm "and_def"  | 
|
705  | 
val or_def = thm "or_def"  | 
|
706  | 
val Ex1_def = thm "Ex1_def"  | 
|
707  | 
val iff = thm "iff"  | 
|
708  | 
val True_or_False = thm "True_or_False"  | 
|
709  | 
val Let_def = thm "Let_def"  | 
|
710  | 
val if_def = thm "if_def"  | 
|
711  | 
val sym = thm "sym"  | 
|
712  | 
val ssubst = thm "ssubst"  | 
|
713  | 
val trans = thm "trans"  | 
|
714  | 
val def_imp_eq = thm "def_imp_eq"  | 
|
715  | 
val box_equals = thm "box_equals"  | 
|
716  | 
val fun_cong = thm "fun_cong"  | 
|
717  | 
val arg_cong = thm "arg_cong"  | 
|
718  | 
val cong = thm "cong"  | 
|
719  | 
val iffI = thm "iffI"  | 
|
720  | 
val iffD2 = thm "iffD2"  | 
|
721  | 
val rev_iffD2 = thm "rev_iffD2"  | 
|
722  | 
val iffD1 = thm "iffD1"  | 
|
723  | 
val rev_iffD1 = thm "rev_iffD1"  | 
|
724  | 
val iffE = thm "iffE"  | 
|
725  | 
val TrueI = thm "TrueI"  | 
|
726  | 
val eqTrueI = thm "eqTrueI"  | 
|
727  | 
val eqTrueE = thm "eqTrueE"  | 
|
728  | 
val allI = thm "allI"  | 
|
729  | 
val spec = thm "spec"  | 
|
730  | 
val allE = thm "allE"  | 
|
731  | 
val all_dupE = thm "all_dupE"  | 
|
732  | 
val FalseE = thm "FalseE"  | 
|
733  | 
val False_neq_True = thm "False_neq_True"  | 
|
734  | 
val notI = thm "notI"  | 
|
735  | 
val False_not_True = thm "False_not_True"  | 
|
736  | 
val True_not_False = thm "True_not_False"  | 
|
737  | 
val notE = thm "notE"  | 
|
738  | 
val notI2 = thm "notI2"  | 
|
739  | 
val impE = thm "impE"  | 
|
740  | 
val rev_mp = thm "rev_mp"  | 
|
741  | 
val contrapos_nn = thm "contrapos_nn"  | 
|
742  | 
val contrapos_pn = thm "contrapos_pn"  | 
|
743  | 
val not_sym = thm "not_sym"  | 
|
744  | 
val rev_contrapos = thm "rev_contrapos"  | 
|
745  | 
val exI = thm "exI"  | 
|
746  | 
val exE = thm "exE"  | 
|
747  | 
val conjI = thm "conjI"  | 
|
748  | 
val conjunct1 = thm "conjunct1"  | 
|
749  | 
val conjunct2 = thm "conjunct2"  | 
|
750  | 
val conjE = thm "conjE"  | 
|
751  | 
val context_conjI = thm "context_conjI"  | 
|
752  | 
val disjI1 = thm "disjI1"  | 
|
753  | 
val disjI2 = thm "disjI2"  | 
|
754  | 
val disjE = thm "disjE"  | 
|
755  | 
val classical = thm "classical"  | 
|
756  | 
val ccontr = thm "ccontr"  | 
|
757  | 
val rev_notE = thm "rev_notE"  | 
|
758  | 
val notnotD = thm "notnotD"  | 
|
759  | 
val contrapos_pp = thm "contrapos_pp"  | 
|
760  | 
val ex1I = thm "ex1I"  | 
|
761  | 
val ex_ex1I = thm "ex_ex1I"  | 
|
762  | 
val ex1E = thm "ex1E"  | 
|
763  | 
val ex1_implies_ex = thm "ex1_implies_ex"  | 
|
764  | 
val the_equality = thm "the_equality"  | 
|
765  | 
val theI = thm "theI"  | 
|
766  | 
val theI' = thm "theI'"  | 
|
767  | 
val theI2 = thm "theI2"  | 
|
768  | 
val the1_equality = thm "the1_equality"  | 
|
769  | 
val the_sym_eq_trivial = thm "the_sym_eq_trivial"  | 
|
770  | 
val disjCI = thm "disjCI"  | 
|
771  | 
val excluded_middle = thm "excluded_middle"  | 
|
772  | 
val case_split_thm = thm "case_split_thm"  | 
|
773  | 
val impCE = thm "impCE"  | 
|
774  | 
val impCE = thm "impCE"  | 
|
775  | 
val iffCE = thm "iffCE"  | 
|
776  | 
val exCI = thm "exCI"  | 
|
| 4868 | 777  | 
|
| 15411 | 778  | 
(* combination of (spec RS spec RS ...(j times) ... spec RS mp) *)  | 
779  | 
local  | 
|
780  | 
  fun wrong_prem (Const ("All", _) $ (Abs (_, _, t))) = wrong_prem t
 | 
|
781  | 
| wrong_prem (Bound _) = true  | 
|
782  | 
| wrong_prem _ = false  | 
|
| 15570 | 783  | 
val filter_right = List.filter (fn t => not (wrong_prem (HOLogic.dest_Trueprop (hd (Thm.prems_of t)))))  | 
| 15411 | 784  | 
in  | 
785  | 
fun smp i = funpow i (fn m => filter_right ([spec] RL m)) ([mp])  | 
|
786  | 
fun smp_tac j = EVERY'[dresolve_tac (smp j), atac]  | 
|
787  | 
end  | 
|
788  | 
||
789  | 
||
790  | 
fun strip_tac i = REPEAT(resolve_tac [impI,allI] i)  | 
|
791  | 
||
792  | 
(*Obsolete form of disjunctive case analysis*)  | 
|
793  | 
fun excluded_middle_tac sP =  | 
|
794  | 
    res_inst_tac [("Q",sP)] (excluded_middle RS disjE)
 | 
|
795  | 
||
796  | 
fun case_tac a = res_inst_tac [("P",a)] case_split_thm
 | 
|
797  | 
*}  | 
|
798  | 
||
| 11687 | 799  | 
theorems case_split = case_split_thm [case_names True False]  | 
| 9869 | 800  | 
|
| 18457 | 801  | 
ML {*
 | 
802  | 
structure ProjectRule = ProjectRuleFun  | 
|
803  | 
(struct  | 
|
804  | 
val conjunct1 = thm "conjunct1";  | 
|
805  | 
val conjunct2 = thm "conjunct2";  | 
|
806  | 
val mp = thm "mp";  | 
|
807  | 
end)  | 
|
808  | 
*}  | 
|
809  | 
||
| 12386 | 810  | 
|
811  | 
subsubsection {* Intuitionistic Reasoning *}
 | 
|
812  | 
||
813  | 
lemma impE':  | 
|
| 
12937
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
814  | 
assumes 1: "P --> Q"  | 
| 
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
815  | 
and 2: "Q ==> R"  | 
| 
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
816  | 
and 3: "P --> Q ==> P"  | 
| 
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
817  | 
shows R  | 
| 12386 | 818  | 
proof -  | 
819  | 
from 3 and 1 have P .  | 
|
820  | 
with 1 have Q by (rule impE)  | 
|
821  | 
with 2 show R .  | 
|
822  | 
qed  | 
|
823  | 
||
824  | 
lemma allE':  | 
|
| 
12937
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
825  | 
assumes 1: "ALL x. P x"  | 
| 
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
826  | 
and 2: "P x ==> ALL x. P x ==> Q"  | 
| 
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
827  | 
shows Q  | 
| 12386 | 828  | 
proof -  | 
829  | 
from 1 have "P x" by (rule spec)  | 
|
830  | 
from this and 1 show Q by (rule 2)  | 
|
831  | 
qed  | 
|
832  | 
||
| 
12937
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
833  | 
lemma notE':  | 
| 
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
834  | 
assumes 1: "~ P"  | 
| 
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
835  | 
and 2: "~ P ==> P"  | 
| 
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
836  | 
shows R  | 
| 12386 | 837  | 
proof -  | 
838  | 
from 2 and 1 have P .  | 
|
839  | 
with 1 show R by (rule notE)  | 
|
840  | 
qed  | 
|
841  | 
||
| 15801 | 842  | 
lemmas [Pure.elim!] = disjE iffE FalseE conjE exE  | 
843  | 
and [Pure.intro!] = iffI conjI impI TrueI notI allI refl  | 
|
844  | 
and [Pure.elim 2] = allE notE' impE'  | 
|
845  | 
and [Pure.intro] = exI disjI2 disjI1  | 
|
| 12386 | 846  | 
|
847  | 
lemmas [trans] = trans  | 
|
848  | 
and [sym] = sym not_sym  | 
|
| 15801 | 849  | 
and [Pure.elim?] = iffD1 iffD2 impE  | 
| 11750 | 850  | 
|
| 
11438
 
3d9222b80989
declare trans [trans]  (*overridden in theory Calculation*);
 
wenzelm 
parents: 
11432 
diff
changeset
 | 
851  | 
|
| 11750 | 852  | 
subsubsection {* Atomizing meta-level connectives *}
 | 
853  | 
||
854  | 
lemma atomize_all [atomize]: "(!!x. P x) == Trueprop (ALL x. P x)"  | 
|
| 12003 | 855  | 
proof  | 
| 9488 | 856  | 
assume "!!x. P x"  | 
| 10383 | 857  | 
show "ALL x. P x" by (rule allI)  | 
| 9488 | 858  | 
next  | 
859  | 
assume "ALL x. P x"  | 
|
| 10383 | 860  | 
thus "!!x. P x" by (rule allE)  | 
| 9488 | 861  | 
qed  | 
862  | 
||
| 11750 | 863  | 
lemma atomize_imp [atomize]: "(A ==> B) == Trueprop (A --> B)"  | 
| 12003 | 864  | 
proof  | 
| 9488 | 865  | 
assume r: "A ==> B"  | 
| 10383 | 866  | 
show "A --> B" by (rule impI) (rule r)  | 
| 9488 | 867  | 
next  | 
868  | 
assume "A --> B" and A  | 
|
| 10383 | 869  | 
thus B by (rule mp)  | 
| 9488 | 870  | 
qed  | 
871  | 
||
| 14749 | 872  | 
lemma atomize_not: "(A ==> False) == Trueprop (~A)"  | 
873  | 
proof  | 
|
874  | 
assume r: "A ==> False"  | 
|
875  | 
show "~A" by (rule notI) (rule r)  | 
|
876  | 
next  | 
|
877  | 
assume "~A" and A  | 
|
878  | 
thus False by (rule notE)  | 
|
879  | 
qed  | 
|
880  | 
||
| 11750 | 881  | 
lemma atomize_eq [atomize]: "(x == y) == Trueprop (x = y)"  | 
| 12003 | 882  | 
proof  | 
| 
10432
 
3dfbc913d184
added axclass inverse and consts inverse, divide (infix "/");
 
wenzelm 
parents: 
10383 
diff
changeset
 | 
883  | 
assume "x == y"  | 
| 
 
3dfbc913d184
added axclass inverse and consts inverse, divide (infix "/");
 
wenzelm 
parents: 
10383 
diff
changeset
 | 
884  | 
show "x = y" by (unfold prems) (rule refl)  | 
| 
 
3dfbc913d184
added axclass inverse and consts inverse, divide (infix "/");
 
wenzelm 
parents: 
10383 
diff
changeset
 | 
885  | 
next  | 
| 
 
3dfbc913d184
added axclass inverse and consts inverse, divide (infix "/");
 
wenzelm 
parents: 
10383 
diff
changeset
 | 
886  | 
assume "x = y"  | 
| 
 
3dfbc913d184
added axclass inverse and consts inverse, divide (infix "/");
 
wenzelm 
parents: 
10383 
diff
changeset
 | 
887  | 
thus "x == y" by (rule eq_reflection)  | 
| 
 
3dfbc913d184
added axclass inverse and consts inverse, divide (infix "/");
 
wenzelm 
parents: 
10383 
diff
changeset
 | 
888  | 
qed  | 
| 
 
3dfbc913d184
added axclass inverse and consts inverse, divide (infix "/");
 
wenzelm 
parents: 
10383 
diff
changeset
 | 
889  | 
|
| 12023 | 890  | 
lemma atomize_conj [atomize]:  | 
| 19121 | 891  | 
includes meta_conjunction_syntax  | 
892  | 
shows "(A && B) == Trueprop (A & B)"  | 
|
| 12003 | 893  | 
proof  | 
| 19121 | 894  | 
assume conj: "A && B"  | 
895  | 
show "A & B"  | 
|
896  | 
proof (rule conjI)  | 
|
897  | 
from conj show A by (rule conjunctionD1)  | 
|
898  | 
from conj show B by (rule conjunctionD2)  | 
|
899  | 
qed  | 
|
| 11953 | 900  | 
next  | 
| 19121 | 901  | 
assume conj: "A & B"  | 
902  | 
show "A && B"  | 
|
903  | 
proof -  | 
|
904  | 
from conj show A ..  | 
|
905  | 
from conj show B ..  | 
|
| 11953 | 906  | 
qed  | 
907  | 
qed  | 
|
908  | 
||
| 12386 | 909  | 
lemmas [symmetric, rulify] = atomize_all atomize_imp  | 
| 18832 | 910  | 
and [symmetric, defn] = atomize_all atomize_imp atomize_eq  | 
| 12386 | 911  | 
|
| 11750 | 912  | 
|
913  | 
subsubsection {* Classical Reasoner setup *}
 | 
|
| 9529 | 914  | 
|
| 10383 | 915  | 
use "cladata.ML"  | 
916  | 
setup hypsubst_setup  | 
|
| 18708 | 917  | 
setup {* ContextRules.addSWrapper (fn tac => hyp_subst_tac' ORELSE' tac) *}
 | 
| 10383 | 918  | 
setup Classical.setup  | 
| 20223 | 919  | 
setup ResAtpSet.setup  | 
920  | 
setup clasetup  | 
|
| 19162 | 921  | 
|
| 20223 | 922  | 
lemma contrapos_np: "~ Q ==> (~ P ==> Q) ==> P"  | 
923  | 
apply (erule swap)  | 
|
924  | 
apply (erule (1) meta_mp)  | 
|
925  | 
done  | 
|
| 10383 | 926  | 
|
| 
18689
 
a50587cd8414
prefer ex1I over ex_ex1I in single-step reasoning;
 
wenzelm 
parents: 
18595 
diff
changeset
 | 
927  | 
declare ex_ex1I [rule del, intro! 2]  | 
| 
 
a50587cd8414
prefer ex1I over ex_ex1I in single-step reasoning;
 
wenzelm 
parents: 
18595 
diff
changeset
 | 
928  | 
and ex1I [intro]  | 
| 
 
a50587cd8414
prefer ex1I over ex_ex1I in single-step reasoning;
 
wenzelm 
parents: 
18595 
diff
changeset
 | 
929  | 
|
| 12386 | 930  | 
lemmas [intro?] = ext  | 
931  | 
and [elim?] = ex1_implies_ex  | 
|
| 11977 | 932  | 
|
| 9869 | 933  | 
use "blastdata.ML"  | 
934  | 
setup Blast.setup  | 
|
| 4868 | 935  | 
|
| 11750 | 936  | 
|
| 17459 | 937  | 
subsubsection {* Simplifier setup *}
 | 
| 11750 | 938  | 
|
| 12281 | 939  | 
lemma meta_eq_to_obj_eq: "x == y ==> x = y"  | 
940  | 
proof -  | 
|
941  | 
assume r: "x == y"  | 
|
942  | 
show "x = y" by (unfold r) (rule refl)  | 
|
943  | 
qed  | 
|
944  | 
||
945  | 
lemma eta_contract_eq: "(%s. f s) = f" ..  | 
|
946  | 
||
947  | 
lemma simp_thms:  | 
|
| 
12937
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
948  | 
shows not_not: "(~ ~ P) = P"  | 
| 15354 | 949  | 
and Not_eq_iff: "((~P) = (~Q)) = (P = Q)"  | 
| 
12937
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
950  | 
and  | 
| 
12436
 
a2df07fefed7
Replaced several occurrences of "blast" by "rules".
 
berghofe 
parents: 
12386 
diff
changeset
 | 
951  | 
"(P ~= Q) = (P = (~Q))"  | 
| 
 
a2df07fefed7
Replaced several occurrences of "blast" by "rules".
 
berghofe 
parents: 
12386 
diff
changeset
 | 
952  | 
"(P | ~P) = True" "(~P | P) = True"  | 
| 12281 | 953  | 
"(x = x) = True"  | 
954  | 
"(~True) = False" "(~False) = True"  | 
|
| 
12436
 
a2df07fefed7
Replaced several occurrences of "blast" by "rules".
 
berghofe 
parents: 
12386 
diff
changeset
 | 
955  | 
"(~P) ~= P" "P ~= (~P)"  | 
| 12281 | 956  | 
"(True=P) = P" "(P=True) = P" "(False=P) = (~P)" "(P=False) = (~P)"  | 
957  | 
"(True --> P) = P" "(False --> P) = True"  | 
|
958  | 
"(P --> True) = True" "(P --> P) = True"  | 
|
959  | 
"(P --> False) = (~P)" "(P --> ~P) = (~P)"  | 
|
960  | 
"(P & True) = P" "(True & P) = P"  | 
|
961  | 
"(P & False) = False" "(False & P) = False"  | 
|
962  | 
"(P & P) = P" "(P & (P & Q)) = (P & Q)"  | 
|
963  | 
"(P & ~P) = False" "(~P & P) = False"  | 
|
964  | 
"(P | True) = True" "(True | P) = True"  | 
|
965  | 
"(P | False) = P" "(False | P) = P"  | 
|
| 
12436
 
a2df07fefed7
Replaced several occurrences of "blast" by "rules".
 
berghofe 
parents: 
12386 
diff
changeset
 | 
966  | 
"(P | P) = P" "(P | (P | Q)) = (P | Q)" and  | 
| 12281 | 967  | 
"(ALL x. P) = P" "(EX x. P) = P" "EX x. x=t" "EX x. t=x"  | 
968  | 
    -- {* needed for the one-point-rule quantifier simplification procs *}
 | 
|
969  | 
    -- {* essential for termination!! *} and
 | 
|
970  | 
"!!P. (EX x. x=t & P(x)) = P(t)"  | 
|
971  | 
"!!P. (EX x. t=x & P(x)) = P(t)"  | 
|
972  | 
"!!P. (ALL x. x=t --> P(x)) = P(t)"  | 
|
| 
12937
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
973  | 
"!!P. (ALL x. t=x --> P(x)) = P(t)"  | 
| 17589 | 974  | 
by (blast, blast, blast, blast, blast, iprover+)  | 
| 13421 | 975  | 
|
| 12281 | 976  | 
lemma imp_cong: "(P = P') ==> (P' ==> (Q = Q')) ==> ((P --> Q) = (P' --> Q'))"  | 
| 17589 | 977  | 
by iprover  | 
| 12281 | 978  | 
|
979  | 
lemma ex_simps:  | 
|
980  | 
"!!P Q. (EX x. P x & Q) = ((EX x. P x) & Q)"  | 
|
981  | 
"!!P Q. (EX x. P & Q x) = (P & (EX x. Q x))"  | 
|
982  | 
"!!P Q. (EX x. P x | Q) = ((EX x. P x) | Q)"  | 
|
983  | 
"!!P Q. (EX x. P | Q x) = (P | (EX x. Q x))"  | 
|
984  | 
"!!P Q. (EX x. P x --> Q) = ((ALL x. P x) --> Q)"  | 
|
985  | 
"!!P Q. (EX x. P --> Q x) = (P --> (EX x. Q x))"  | 
|
986  | 
  -- {* Miniscoping: pushing in existential quantifiers. *}
 | 
|
| 17589 | 987  | 
by (iprover | blast)+  | 
| 12281 | 988  | 
|
989  | 
lemma all_simps:  | 
|
990  | 
"!!P Q. (ALL x. P x & Q) = ((ALL x. P x) & Q)"  | 
|
991  | 
"!!P Q. (ALL x. P & Q x) = (P & (ALL x. Q x))"  | 
|
992  | 
"!!P Q. (ALL x. P x | Q) = ((ALL x. P x) | Q)"  | 
|
993  | 
"!!P Q. (ALL x. P | Q x) = (P | (ALL x. Q x))"  | 
|
994  | 
"!!P Q. (ALL x. P x --> Q) = ((EX x. P x) --> Q)"  | 
|
995  | 
"!!P Q. (ALL x. P --> Q x) = (P --> (ALL x. Q x))"  | 
|
996  | 
  -- {* Miniscoping: pushing in universal quantifiers. *}
 | 
|
| 17589 | 997  | 
by (iprover | blast)+  | 
| 12281 | 998  | 
|
| 14201 | 999  | 
lemma disj_absorb: "(A | A) = A"  | 
1000  | 
by blast  | 
|
1001  | 
||
1002  | 
lemma disj_left_absorb: "(A | (A | B)) = (A | B)"  | 
|
1003  | 
by blast  | 
|
1004  | 
||
1005  | 
lemma conj_absorb: "(A & A) = A"  | 
|
1006  | 
by blast  | 
|
1007  | 
||
1008  | 
lemma conj_left_absorb: "(A & (A & B)) = (A & B)"  | 
|
1009  | 
by blast  | 
|
1010  | 
||
| 12281 | 1011  | 
lemma eq_ac:  | 
| 
12937
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
1012  | 
shows eq_commute: "(a=b) = (b=a)"  | 
| 
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
1013  | 
and eq_left_commute: "(P=(Q=R)) = (Q=(P=R))"  | 
| 17589 | 1014  | 
and eq_assoc: "((P=Q)=R) = (P=(Q=R))" by (iprover, blast+)  | 
1015  | 
lemma neq_commute: "(a~=b) = (b~=a)" by iprover  | 
|
| 12281 | 1016  | 
|
1017  | 
lemma conj_comms:  | 
|
| 
12937
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
1018  | 
shows conj_commute: "(P&Q) = (Q&P)"  | 
| 17589 | 1019  | 
and conj_left_commute: "(P&(Q&R)) = (Q&(P&R))" by iprover+  | 
1020  | 
lemma conj_assoc: "((P&Q)&R) = (P&(Q&R))" by iprover  | 
|
| 12281 | 1021  | 
|
| 19174 | 1022  | 
lemmas conj_ac = conj_commute conj_left_commute conj_assoc  | 
1023  | 
||
| 12281 | 1024  | 
lemma disj_comms:  | 
| 
12937
 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 
wenzelm 
parents: 
12892 
diff
changeset
 | 
1025  | 
shows disj_commute: "(P|Q) = (Q|P)"  | 
| 17589 | 1026  | 
and disj_left_commute: "(P|(Q|R)) = (Q|(P|R))" by iprover+  | 
1027  | 
lemma disj_assoc: "((P|Q)|R) = (P|(Q|R))" by iprover  | 
|
| 12281 | 1028  | 
|
| 19174 | 1029  | 
lemmas disj_ac = disj_commute disj_left_commute disj_assoc  | 
1030  | 
||
| 17589 | 1031  | 
lemma conj_disj_distribL: "(P&(Q|R)) = (P&Q | P&R)" by iprover  | 
1032  | 
lemma conj_disj_distribR: "((P|Q)&R) = (P&R | Q&R)" by iprover  | 
|
| 12281 | 1033  | 
|
| 17589 | 1034  | 
lemma disj_conj_distribL: "(P|(Q&R)) = ((P|Q) & (P|R))" by iprover  | 
1035  | 
lemma disj_conj_distribR: "((P&Q)|R) = ((P|R) & (Q|R))" by iprover  | 
|
| 12281 | 1036  | 
|
| 17589 | 1037  | 
lemma imp_conjR: "(P --> (Q&R)) = ((P-->Q) & (P-->R))" by iprover  | 
1038  | 
lemma imp_conjL: "((P&Q) -->R) = (P --> (Q --> R))" by iprover  | 
|
1039  | 
lemma imp_disjL: "((P|Q) --> R) = ((P-->R)&(Q-->R))" by iprover  | 
|
| 12281 | 1040  | 
|
1041  | 
text {* These two are specialized, but @{text imp_disj_not1} is useful in @{text "Auth/Yahalom"}. *}
 | 
|
1042  | 
lemma imp_disj_not1: "(P --> Q | R) = (~Q --> P --> R)" by blast  | 
|
1043  | 
lemma imp_disj_not2: "(P --> Q | R) = (~R --> P --> Q)" by blast  | 
|
1044  | 
||
1045  | 
lemma imp_disj1: "((P-->Q)|R) = (P--> Q|R)" by blast  | 
|
1046  | 
lemma imp_disj2: "(Q|(P-->R)) = (P--> Q|R)" by blast  | 
|
1047  | 
||
| 17589 | 1048  | 
lemma de_Morgan_disj: "(~(P | Q)) = (~P & ~Q)" by iprover  | 
| 12281 | 1049  | 
lemma de_Morgan_conj: "(~(P & Q)) = (~P | ~Q)" by blast  | 
1050  | 
lemma not_imp: "(~(P --> Q)) = (P & ~Q)" by blast  | 
|
1051  | 
lemma not_iff: "(P~=Q) = (P = (~Q))" by blast  | 
|
1052  | 
lemma disj_not1: "(~P | Q) = (P --> Q)" by blast  | 
|
1053  | 
lemma disj_not2: "(P | ~Q) = (Q --> P)"  -- {* changes orientation :-( *}
 | 
|
1054  | 
by blast  | 
|
1055  | 
lemma imp_conv_disj: "(P --> Q) = ((~P) | Q)" by blast  | 
|
1056  | 
||
| 17589 | 1057  | 
lemma iff_conv_conj_imp: "(P = Q) = ((P --> Q) & (Q --> P))" by iprover  | 
| 12281 | 1058  | 
|
1059  | 
||
1060  | 
lemma cases_simp: "((P --> Q) & (~P --> Q)) = Q"  | 
|
1061  | 
  -- {* Avoids duplication of subgoals after @{text split_if}, when the true and false *}
 | 
|
1062  | 
  -- {* cases boil down to the same thing. *}
 | 
|
1063  | 
by blast  | 
|
1064  | 
||
1065  | 
lemma not_all: "(~ (! x. P(x))) = (? x.~P(x))" by blast  | 
|
1066  | 
lemma imp_all: "((! x. P x) --> Q) = (? x. P x --> Q)" by blast  | 
|
| 17589 | 1067  | 
lemma not_ex: "(~ (? x. P(x))) = (! x.~P(x))" by iprover  | 
1068  | 
lemma imp_ex: "((? x. P x) --> Q) = (! x. P x --> Q)" by iprover  | 
|
| 12281 | 1069  | 
|
| 17589 | 1070  | 
lemma ex_disj_distrib: "(? x. P(x) | Q(x)) = ((? x. P(x)) | (? x. Q(x)))" by iprover  | 
1071  | 
lemma all_conj_distrib: "(!x. P(x) & Q(x)) = ((! x. P(x)) & (! x. Q(x)))" by iprover  | 
|
| 12281 | 1072  | 
|
1073  | 
text {*
 | 
|
1074  | 
  \medskip The @{text "&"} congruence rule: not included by default!
 | 
|
1075  | 
May slow rewrite proofs down by as much as 50\% *}  | 
|
1076  | 
||
1077  | 
lemma conj_cong:  | 
|
1078  | 
"(P = P') ==> (P' ==> (Q = Q')) ==> ((P & Q) = (P' & Q'))"  | 
|
| 17589 | 1079  | 
by iprover  | 
| 12281 | 1080  | 
|
1081  | 
lemma rev_conj_cong:  | 
|
1082  | 
"(Q = Q') ==> (Q' ==> (P = P')) ==> ((P & Q) = (P' & Q'))"  | 
|
| 17589 | 1083  | 
by iprover  | 
| 12281 | 1084  | 
|
1085  | 
text {* The @{text "|"} congruence rule: not included by default! *}
 | 
|
1086  | 
||
1087  | 
lemma disj_cong:  | 
|
1088  | 
"(P = P') ==> (~P' ==> (Q = Q')) ==> ((P | Q) = (P' | Q'))"  | 
|
1089  | 
by blast  | 
|
1090  | 
||
1091  | 
lemma eq_sym_conv: "(x = y) = (y = x)"  | 
|
| 17589 | 1092  | 
by iprover  | 
| 12281 | 1093  | 
|
1094  | 
||
1095  | 
text {* \medskip if-then-else rules *}
 | 
|
1096  | 
||
1097  | 
lemma if_True: "(if True then x else y) = x"  | 
|
1098  | 
by (unfold if_def) blast  | 
|
1099  | 
||
1100  | 
lemma if_False: "(if False then x else y) = y"  | 
|
1101  | 
by (unfold if_def) blast  | 
|
1102  | 
||
1103  | 
lemma if_P: "P ==> (if P then x else y) = x"  | 
|
1104  | 
by (unfold if_def) blast  | 
|
1105  | 
||
1106  | 
lemma if_not_P: "~P ==> (if P then x else y) = y"  | 
|
1107  | 
by (unfold if_def) blast  | 
|
1108  | 
||
1109  | 
lemma split_if: "P (if Q then x else y) = ((Q --> P(x)) & (~Q --> P(y)))"  | 
|
1110  | 
apply (rule case_split [of Q])  | 
|
| 15481 | 1111  | 
apply (simplesubst if_P)  | 
1112  | 
prefer 3 apply (simplesubst if_not_P, blast+)  | 
|
| 12281 | 1113  | 
done  | 
1114  | 
||
1115  | 
lemma split_if_asm: "P (if Q then x else y) = (~((Q & ~P x) | (~Q & ~P y)))"  | 
|
| 15481 | 1116  | 
by (simplesubst split_if, blast)  | 
| 12281 | 1117  | 
|
1118  | 
lemmas if_splits = split_if split_if_asm  | 
|
1119  | 
||
1120  | 
lemma if_def2: "(if Q then x else y) = ((Q --> x) & (~ Q --> y))"  | 
|
1121  | 
by (rule split_if)  | 
|
1122  | 
||
1123  | 
lemma if_cancel: "(if c then x else x) = x"  | 
|
| 15481 | 1124  | 
by (simplesubst split_if, blast)  | 
| 12281 | 1125  | 
|
1126  | 
lemma if_eq_cancel: "(if x = y then y else x) = x"  | 
|
| 15481 | 1127  | 
by (simplesubst split_if, blast)  | 
| 12281 | 1128  | 
|
1129  | 
lemma if_bool_eq_conj: "(if P then Q else R) = ((P-->Q) & (~P-->R))"  | 
|
| 19796 | 1130  | 
  -- {* This form is useful for expanding @{text "if"}s on the RIGHT of the @{text "==>"} symbol. *}
 | 
| 12281 | 1131  | 
by (rule split_if)  | 
1132  | 
||
1133  | 
lemma if_bool_eq_disj: "(if P then Q else R) = ((P&Q) | (~P&R))"  | 
|
| 19796 | 1134  | 
  -- {* And this form is useful for expanding @{text "if"}s on the LEFT. *}
 | 
| 15481 | 1135  | 
apply (simplesubst split_if, blast)  | 
| 12281 | 1136  | 
done  | 
1137  | 
||
| 17589 | 1138  | 
lemma Eq_TrueI: "P ==> P == True" by (unfold atomize_eq) iprover  | 
1139  | 
lemma Eq_FalseI: "~P ==> P == False" by (unfold atomize_eq) iprover  | 
|
| 12281 | 1140  | 
|
| 15423 | 1141  | 
text {* \medskip let rules for simproc *}
 | 
1142  | 
||
1143  | 
lemma Let_folded: "f x \<equiv> g x \<Longrightarrow> Let x f \<equiv> Let x g"  | 
|
1144  | 
by (unfold Let_def)  | 
|
1145  | 
||
1146  | 
lemma Let_unfold: "f x \<equiv> g \<Longrightarrow> Let x f \<equiv> g"  | 
|
1147  | 
by (unfold Let_def)  | 
|
1148  | 
||
| 
16633
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1149  | 
text {*
 | 
| 16999 | 1150  | 
The following copy of the implication operator is useful for  | 
1151  | 
fine-tuning congruence rules. It instructs the simplifier to simplify  | 
|
1152  | 
its premise.  | 
|
| 
16633
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1153  | 
*}  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1154  | 
|
| 17197 | 1155  | 
constdefs  | 
1156  | 
simp_implies :: "[prop, prop] => prop" (infixr "=simp=>" 1)  | 
|
1157  | 
"simp_implies \<equiv> op ==>"  | 
|
| 
16633
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1158  | 
|
| 18457 | 1159  | 
lemma simp_impliesI:  | 
| 
16633
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1160  | 
assumes PQ: "(PROP P \<Longrightarrow> PROP Q)"  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1161  | 
shows "PROP P =simp=> PROP Q"  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1162  | 
apply (unfold simp_implies_def)  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1163  | 
apply (rule PQ)  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1164  | 
apply assumption  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1165  | 
done  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1166  | 
|
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1167  | 
lemma simp_impliesE:  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1168  | 
assumes PQ:"PROP P =simp=> PROP Q"  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1169  | 
and P: "PROP P"  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1170  | 
and QR: "PROP Q \<Longrightarrow> PROP R"  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1171  | 
shows "PROP R"  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1172  | 
apply (rule QR)  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1173  | 
apply (rule PQ [unfolded simp_implies_def])  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1174  | 
apply (rule P)  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1175  | 
done  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1176  | 
|
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1177  | 
lemma simp_implies_cong:  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1178  | 
assumes PP' :"PROP P == PROP P'"  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1179  | 
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
 | 
1180  | 
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
 | 
1181  | 
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
 | 
1182  | 
assume PQ: "PROP P \<Longrightarrow> PROP Q"  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1183  | 
and P': "PROP P'"  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1184  | 
from PP' [symmetric] and P' have "PROP P"  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1185  | 
by (rule equal_elim_rule1)  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1186  | 
hence "PROP Q" by (rule PQ)  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1187  | 
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
 | 
1188  | 
next  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1189  | 
assume P'Q': "PROP P' \<Longrightarrow> PROP Q'"  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1190  | 
and P: "PROP P"  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1191  | 
from PP' and P have P': "PROP P'" by (rule equal_elim_rule1)  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1192  | 
hence "PROP Q'" by (rule P'Q')  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1193  | 
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
 | 
1194  | 
by (rule equal_elim_rule1)  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1195  | 
qed  | 
| 
 
208ebc9311f2
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification
 
berghofe 
parents: 
16587 
diff
changeset
 | 
1196  | 
|
| 17459 | 1197  | 
|
1198  | 
text {* \medskip Actual Installation of the Simplifier. *}
 | 
|
| 14201 | 1199  | 
|
| 9869 | 1200  | 
use "simpdata.ML"  | 
1201  | 
setup "Simplifier.method_setup Splitter.split_modifiers" setup simpsetup  | 
|
1202  | 
setup Splitter.setup setup Clasimp.setup  | 
|
| 18591 | 1203  | 
setup EqSubst.setup  | 
| 15481 | 1204  | 
|
| 17459 | 1205  | 
|
1206  | 
subsubsection {* Code generator setup *}
 | 
|
1207  | 
||
1208  | 
types_code  | 
|
1209  | 
  "bool"  ("bool")
 | 
|
1210  | 
attach (term_of) {*
 | 
|
1211  | 
fun term_of_bool b = if b then HOLogic.true_const else HOLogic.false_const;  | 
|
1212  | 
*}  | 
|
1213  | 
attach (test) {*
 | 
|
1214  | 
fun gen_bool i = one_of [false, true];  | 
|
1215  | 
*}  | 
|
| 18887 | 1216  | 
  "prop"  ("bool")
 | 
1217  | 
attach (term_of) {*
 | 
|
1218  | 
fun term_of_prop b =  | 
|
1219  | 
HOLogic.mk_Trueprop (if b then HOLogic.true_const else HOLogic.false_const);  | 
|
1220  | 
*}  | 
|
| 17459 | 1221  | 
|
1222  | 
consts_code  | 
|
| 18887 | 1223  | 
  "Trueprop" ("(_)")
 | 
| 17459 | 1224  | 
  "True"    ("true")
 | 
1225  | 
  "False"   ("false")
 | 
|
1226  | 
  "Not"     ("not")
 | 
|
1227  | 
  "op |"    ("(_ orelse/ _)")
 | 
|
1228  | 
  "op &"    ("(_ andalso/ _)")
 | 
|
1229  | 
  "HOL.If"      ("(if _/ then _/ else _)")
 | 
|
1230  | 
||
1231  | 
ML {*
 | 
|
1232  | 
local  | 
|
1233  | 
||
1234  | 
fun eq_codegen thy defs gr dep thyname b t =  | 
|
1235  | 
(case strip_comb t of  | 
|
1236  | 
       (Const ("op =", Type (_, [Type ("fun", _), _])), _) => NONE
 | 
|
1237  | 
     | (Const ("op =", _), [t, u]) =>
 | 
|
1238  | 
let  | 
|
1239  | 
val (gr', pt) = Codegen.invoke_codegen thy defs dep thyname false (gr, t);  | 
|
| 
17639
 
50878db27b94
eq_codegen now ensures that code for bool type is generated.
 
berghofe 
parents: 
17589 
diff
changeset
 | 
1240  | 
val (gr'', pu) = Codegen.invoke_codegen thy defs dep thyname false (gr', u);  | 
| 
 
50878db27b94
eq_codegen now ensures that code for bool type is generated.
 
berghofe 
parents: 
17589 
diff
changeset
 | 
1241  | 
val (gr''', _) = Codegen.invoke_tycodegen thy defs dep thyname false (gr'', HOLogic.boolT)  | 
| 17459 | 1242  | 
in  | 
| 
17639
 
50878db27b94
eq_codegen now ensures that code for bool type is generated.
 
berghofe 
parents: 
17589 
diff
changeset
 | 
1243  | 
SOME (gr''', Codegen.parens  | 
| 17459 | 1244  | 
(Pretty.block [pt, Pretty.str " =", Pretty.brk 1, pu]))  | 
1245  | 
end  | 
|
1246  | 
     | (t as Const ("op =", _), ts) => SOME (Codegen.invoke_codegen
 | 
|
1247  | 
thy defs dep thyname b (gr, Codegen.eta_expand t ts 2))  | 
|
1248  | 
| _ => NONE);  | 
|
1249  | 
||
| 18887 | 1250  | 
exception Evaluation of term;  | 
1251  | 
||
1252  | 
fun evaluation_oracle (thy, Evaluation t) =  | 
|
1253  | 
Logic.mk_equals (t, Codegen.eval_term thy t);  | 
|
1254  | 
||
1255  | 
fun evaluation_conv ct =  | 
|
1256  | 
  let val {sign, t, ...} = rep_cterm ct
 | 
|
1257  | 
in Thm.invoke_oracle_i sign "HOL.Evaluation" (sign, Evaluation t) end;  | 
|
1258  | 
||
1259  | 
fun evaluation_tac i = Tactical.PRIMITIVE (Drule.fconv_rule  | 
|
1260  | 
(Drule.goals_conv (equal i) evaluation_conv));  | 
|
1261  | 
||
1262  | 
val evaluation_meth =  | 
|
1263  | 
Method.no_args (Method.METHOD (fn _ => evaluation_tac 1 THEN rtac TrueI 1));  | 
|
1264  | 
||
| 17459 | 1265  | 
in  | 
1266  | 
||
| 
20036
 
fa655d0e18c2
made evaluation_conv and normalization_conv visible.
 
nipkow 
parents: 
20018 
diff
changeset
 | 
1267  | 
val evaluation_conv = evaluation_conv;  | 
| 
 
fa655d0e18c2
made evaluation_conv and normalization_conv visible.
 
nipkow 
parents: 
20018 
diff
changeset
 | 
1268  | 
|
| 18708 | 1269  | 
val eq_codegen_setup = Codegen.add_codegen "eq_codegen" eq_codegen;  | 
| 17459 | 1270  | 
|
| 18887 | 1271  | 
val evaluation_oracle_setup =  | 
1272  | 
  Theory.add_oracle ("Evaluation", evaluation_oracle) #>
 | 
|
1273  | 
  Method.add_method ("evaluation", evaluation_meth, "solve goal by evaluation");
 | 
|
1274  | 
||
| 17459 | 1275  | 
end;  | 
1276  | 
*}  | 
|
1277  | 
||
1278  | 
setup eq_codegen_setup  | 
|
| 18887 | 1279  | 
setup evaluation_oracle_setup  | 
| 15481 | 1280  | 
|
1281  | 
||
| 19961 | 1282  | 
ML {*
 | 
1283  | 
local  | 
|
1284  | 
||
1285  | 
exception Normalization of term;  | 
|
1286  | 
||
| 20172 | 1287  | 
fun normalization_oracle (thy, Normalization t) =  | 
1288  | 
Logic.mk_equals (t, NBE.norm_term thy t);  | 
|
| 19961 | 1289  | 
|
1290  | 
fun normalization_conv ct =  | 
|
1291  | 
  let val {sign, t, ...} = rep_cterm ct
 | 
|
1292  | 
in Thm.invoke_oracle_i sign "HOL.Normalization" (sign, Normalization t) end;  | 
|
1293  | 
||
| 20172 | 1294  | 
fun Trueprop_conv conv ct = (case term_of ct of  | 
1295  | 
    Const ("Trueprop", _) $ _ =>
 | 
|
1296  | 
let val (ct1, ct2) = Thm.dest_comb ct  | 
|
1297  | 
in Thm.combination (Thm.reflexive ct1) (conv ct2) end  | 
|
1298  | 
  | _ => raise TERM ("Trueprop_conv", []));
 | 
|
1299  | 
||
| 19961 | 1300  | 
fun normalization_tac i = Tactical.PRIMITIVE (Drule.fconv_rule  | 
| 20172 | 1301  | 
(Drule.goals_conv (equal i) (Trueprop_conv normalization_conv)));  | 
| 19961 | 1302  | 
|
1303  | 
val normalization_meth =  | 
|
| 19970 | 1304  | 
Method.no_args (Method.METHOD (fn _ => normalization_tac 1 THEN resolve_tac [TrueI,refl] 1));  | 
| 19961 | 1305  | 
|
1306  | 
in  | 
|
1307  | 
||
| 
20036
 
fa655d0e18c2
made evaluation_conv and normalization_conv visible.
 
nipkow 
parents: 
20018 
diff
changeset
 | 
1308  | 
val normalization_conv = normalization_conv;  | 
| 
 
fa655d0e18c2
made evaluation_conv and normalization_conv visible.
 
nipkow 
parents: 
20018 
diff
changeset
 | 
1309  | 
|
| 19961 | 1310  | 
val normalization_oracle_setup =  | 
1311  | 
  Theory.add_oracle ("Normalization", normalization_oracle) #>
 | 
|
1312  | 
  Method.add_method ("normalization", normalization_meth, "solve goal by normalization");
 | 
|
1313  | 
||
1314  | 
end;  | 
|
1315  | 
*}  | 
|
1316  | 
||
1317  | 
setup normalization_oracle_setup  | 
|
1318  | 
||
1319  | 
||
| 15481 | 1320  | 
subsection {* Other simple lemmas *}
 | 
1321  | 
||
| 15411 | 1322  | 
declare disj_absorb [simp] conj_absorb [simp]  | 
| 14201 | 1323  | 
|
| 13723 | 1324  | 
lemma ex1_eq[iff]: "EX! x. x = t" "EX! x. t = x"  | 
1325  | 
by blast+  | 
|
1326  | 
||
| 15481 | 1327  | 
|
| 13638 | 1328  | 
theorem choice_eq: "(ALL x. EX! y. P x y) = (EX! f. ALL x. P x (f x))"  | 
1329  | 
apply (rule iffI)  | 
|
1330  | 
apply (rule_tac a = "%x. THE y. P x y" in ex1I)  | 
|
1331  | 
apply (fast dest!: theI')  | 
|
1332  | 
apply (fast intro: ext the1_equality [symmetric])  | 
|
1333  | 
apply (erule ex1E)  | 
|
1334  | 
apply (rule allI)  | 
|
1335  | 
apply (rule ex1I)  | 
|
1336  | 
apply (erule spec)  | 
|
1337  | 
apply (erule_tac x = "%z. if z = x then y else f z" in allE)  | 
|
1338  | 
apply (erule impE)  | 
|
1339  | 
apply (rule allI)  | 
|
1340  | 
apply (rule_tac P = "xa = x" in case_split_thm)  | 
|
| 14208 | 1341  | 
apply (drule_tac [3] x = x in fun_cong, simp_all)  | 
| 13638 | 1342  | 
done  | 
1343  | 
||
| 
13438
 
527811f00c56
added mk_left_commute to HOL.thy and used it "everywhere"
 
nipkow 
parents: 
13421 
diff
changeset
 | 
1344  | 
text{*Needs only HOL-lemmas:*}
 | 
| 
 
527811f00c56
added mk_left_commute to HOL.thy and used it "everywhere"
 
nipkow 
parents: 
13421 
diff
changeset
 | 
1345  | 
lemma mk_left_commute:  | 
| 
 
527811f00c56
added mk_left_commute to HOL.thy and used it "everywhere"
 
nipkow 
parents: 
13421 
diff
changeset
 | 
1346  | 
assumes a: "\<And>x y z. f (f x y) z = f x (f y z)" and  | 
| 
 
527811f00c56
added mk_left_commute to HOL.thy and used it "everywhere"
 
nipkow 
parents: 
13421 
diff
changeset
 | 
1347  | 
c: "\<And>x y. f x y = f y x"  | 
| 
 
527811f00c56
added mk_left_commute to HOL.thy and used it "everywhere"
 
nipkow 
parents: 
13421 
diff
changeset
 | 
1348  | 
shows "f x (f y z) = f y (f x z)"  | 
| 
 
527811f00c56
added mk_left_commute to HOL.thy and used it "everywhere"
 
nipkow 
parents: 
13421 
diff
changeset
 | 
1349  | 
by(rule trans[OF trans[OF c a] arg_cong[OF c, of "f y"]])  | 
| 
 
527811f00c56
added mk_left_commute to HOL.thy and used it "everywhere"
 
nipkow 
parents: 
13421 
diff
changeset
 | 
1350  | 
|
| 11750 | 1351  | 
|
| 15481 | 1352  | 
subsection {* Generic cases and induction *}
 | 
| 
11824
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1353  | 
|
| 
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1354  | 
constdefs  | 
| 18457 | 1355  | 
induct_forall where "induct_forall P == \<forall>x. P x"  | 
1356  | 
induct_implies where "induct_implies A B == A \<longrightarrow> B"  | 
|
1357  | 
induct_equal where "induct_equal x y == x = y"  | 
|
1358  | 
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
 | 
1359  | 
|
| 11989 | 1360  | 
lemma induct_forall_eq: "(!!x. P x) == Trueprop (induct_forall (\<lambda>x. P x))"  | 
| 18457 | 1361  | 
by (unfold atomize_all induct_forall_def)  | 
| 
11824
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1362  | 
|
| 11989 | 1363  | 
lemma induct_implies_eq: "(A ==> B) == Trueprop (induct_implies A B)"  | 
| 18457 | 1364  | 
by (unfold atomize_imp induct_implies_def)  | 
| 
11824
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1365  | 
|
| 11989 | 1366  | 
lemma induct_equal_eq: "(x == y) == Trueprop (induct_equal x y)"  | 
| 18457 | 1367  | 
by (unfold atomize_eq induct_equal_def)  | 
1368  | 
||
1369  | 
lemma induct_conj_eq:  | 
|
1370  | 
includes meta_conjunction_syntax  | 
|
1371  | 
shows "(A && B) == Trueprop (induct_conj A B)"  | 
|
1372  | 
by (unfold atomize_conj induct_conj_def)  | 
|
1373  | 
||
1374  | 
lemmas induct_atomize = induct_forall_eq induct_implies_eq induct_equal_eq induct_conj_eq  | 
|
1375  | 
lemmas induct_rulify [symmetric, standard] = induct_atomize  | 
|
1376  | 
lemmas induct_rulify_fallback =  | 
|
1377  | 
induct_forall_def induct_implies_def induct_equal_def induct_conj_def  | 
|
1378  | 
||
| 
11824
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1379  | 
|
| 11989 | 1380  | 
lemma induct_forall_conj: "induct_forall (\<lambda>x. induct_conj (A x) (B x)) =  | 
1381  | 
induct_conj (induct_forall A) (induct_forall B)"  | 
|
| 17589 | 1382  | 
by (unfold induct_forall_def induct_conj_def) iprover  | 
| 
11824
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1383  | 
|
| 11989 | 1384  | 
lemma induct_implies_conj: "induct_implies C (induct_conj A B) =  | 
1385  | 
induct_conj (induct_implies C A) (induct_implies C B)"  | 
|
| 17589 | 1386  | 
by (unfold induct_implies_def induct_conj_def) iprover  | 
| 11989 | 1387  | 
|
| 
13598
 
8bc77b17f59f
Fixed problem with induct_conj_curry: variable C should have type prop.
 
berghofe 
parents: 
13596 
diff
changeset
 | 
1388  | 
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
 | 
1389  | 
proof  | 
| 
 
8bc77b17f59f
Fixed problem with induct_conj_curry: variable C should have type prop.
 
berghofe 
parents: 
13596 
diff
changeset
 | 
1390  | 
assume r: "induct_conj A B ==> PROP C" and A B  | 
| 18457 | 1391  | 
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
 | 
1392  | 
next  | 
| 
 
8bc77b17f59f
Fixed problem with induct_conj_curry: variable C should have type prop.
 
berghofe 
parents: 
13596 
diff
changeset
 | 
1393  | 
assume r: "A ==> B ==> PROP C" and "induct_conj A B"  | 
| 18457 | 1394  | 
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
 | 
1395  | 
qed  | 
| 
11824
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1396  | 
|
| 11989 | 1397  | 
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
 | 
1398  | 
|
| 11989 | 1399  | 
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
 | 
1400  | 
|
| 
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1401  | 
|
| 
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1402  | 
text {* Method setup. *}
 | 
| 
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1403  | 
|
| 
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1404  | 
ML {*
 | 
| 
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1405  | 
structure InductMethod = InductMethodFun  | 
| 
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1406  | 
(struct  | 
| 15411 | 1407  | 
val cases_default = thm "case_split"  | 
1408  | 
val atomize = thms "induct_atomize"  | 
|
| 18457 | 1409  | 
val rulify = thms "induct_rulify"  | 
1410  | 
val rulify_fallback = thms "induct_rulify_fallback"  | 
|
| 
11824
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1411  | 
end);  | 
| 
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1412  | 
*}  | 
| 
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1413  | 
|
| 
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1414  | 
setup InductMethod.setup  | 
| 
 
f4c1882dde2c
setup generic cases and induction (from Inductive.thy);
 
wenzelm 
parents: 
11770 
diff
changeset
 | 
1415  | 
|
| 18457 | 1416  | 
|
| 18702 | 1417  | 
subsection {* Code generator setup *}
 | 
1418  | 
||
| 
19598
 
d68dd20af31f
different object logic setup for CodegenTheorems
 
haftmann 
parents: 
19536 
diff
changeset
 | 
1419  | 
setup {*
 | 
| 
 
d68dd20af31f
different object logic setup for CodegenTheorems
 
haftmann 
parents: 
19536 
diff
changeset
 | 
1420  | 
CodegenTheorems.init_obj ((TrueI, FalseE), (conjI, thm "HOL.atomize_eq" |> Thm.symmetric))  | 
| 19347 | 1421  | 
*}  | 
1422  | 
||
| 18702 | 1423  | 
code_alias  | 
1424  | 
bool "HOL.bool"  | 
|
1425  | 
True "HOL.True"  | 
|
1426  | 
False "HOL.False"  | 
|
1427  | 
"op =" "HOL.op_eq"  | 
|
1428  | 
"op -->" "HOL.op_implies"  | 
|
1429  | 
"op &" "HOL.op_and"  | 
|
1430  | 
"op |" "HOL.op_or"  | 
|
1431  | 
Not "HOL.not"  | 
|
| 18867 | 1432  | 
arbitrary "HOL.arbitrary"  | 
| 18702 | 1433  | 
|
| 19890 | 1434  | 
code_constapp  | 
| 19039 | 1435  | 
"op =" (* an intermediate solution for polymorphic equality *)  | 
| 18702 | 1436  | 
ml (infixl 6 "=")  | 
1437  | 
haskell (infixl 4 "==")  | 
|
1438  | 
||
| 14357 | 1439  | 
end  |