HOL.ML
author clasohm
Tue, 04 Oct 1994 13:00:20 +0100
changeset 149 7cfa79d92a83
parent 128 89669c58e506
child 153 c0ff8f1ebc16
permissions -rw-r--r--
changed precedences to eliminate some ambiguities
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
     1
(*  Title: 	HOL/hol.ML
7949f97df77a Initial revision
clasohm
parents:
diff changeset
     2
    ID:         $Id$
7949f97df77a Initial revision
clasohm
parents:
diff changeset
     3
    Author: 	Tobias Nipkow
7949f97df77a Initial revision
clasohm
parents:
diff changeset
     4
    Copyright   1991  University of Cambridge
7949f97df77a Initial revision
clasohm
parents:
diff changeset
     5
7949f97df77a Initial revision
clasohm
parents:
diff changeset
     6
For hol.thy
7949f97df77a Initial revision
clasohm
parents:
diff changeset
     7
Derived rules from Appendix of Mike Gordons HOL Report, Cambridge TR 68 
7949f97df77a Initial revision
clasohm
parents:
diff changeset
     8
*)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
     9
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    10
open HOL;
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    11
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    12
signature HOL_LEMMAS =
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    13
  sig
128
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    14
  val allE	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    15
  val all_dupE	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    16
  val allI	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    17
  val arg_cong	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    18
  val fun_cong	: thm
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    19
  val box_equals: thm
128
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    20
  val case_tac	: string -> int -> tactic
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    21
  val ccontr	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    22
  val classical	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    23
  val cong	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    24
  val conjunct1	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    25
  val conjunct2	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    26
  val conjE	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    27
  val conjI	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    28
  val contrapos	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    29
  val disjCI	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    30
  val disjE	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    31
  val disjI1	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    32
  val disjI2	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    33
  val eqTrueI	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    34
  val eqTrueE	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    35
  val ex1E	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    36
  val ex1I	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    37
  val exCI	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    38
  val exI	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    39
  val exE	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    40
  val excluded_middle		: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    41
  val excluded_middle_tac	: string -> int -> tactic
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    42
  val False_neq_True	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    43
  val FalseE	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    44
  val iffCE 	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    45
  val iffD1	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    46
  val iffD2	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    47
  val iffE	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    48
  val iffI	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    49
  val impCE	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    50
  val impE	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    51
  val not_sym	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    52
  val notE	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    53
  val notI	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    54
  val notnotD 	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    55
  val rev_mp	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    56
  val select_equality	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    57
  val spec	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    58
  val sstac	: thm list -> int -> tactic
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    59
  val ssubst	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    60
  val stac	: thm -> int -> tactic
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    61
  val strip_tac	: int -> tactic
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    62
  val swap	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    63
  val sym	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    64
  val trans	: thm
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
    65
  val TrueI	: thm
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    66
  end;
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    67
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    68
structure HOL_Lemmas : HOL_LEMMAS =
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    69
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    70
struct
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    71
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    72
(** Equality **)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    73
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    74
val sym = prove_goal HOL.thy "s=t ==> t=s"
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    75
 (fn prems => [cut_facts_tac prems 1, etac subst 1, rtac refl 1]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    76
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    77
(*calling "standard" reduces maxidx to 0*)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    78
val ssubst = standard (sym RS subst);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    79
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    80
val trans = prove_goal HOL.thy "[| r=s; s=t |] ==> r=t"
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    81
 (fn prems =>
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    82
	[rtac subst 1, resolve_tac prems 1, resolve_tac prems 1]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    83
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    84
(*Useful with eresolve_tac for proving equalties from known equalities.
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    85
	a = b
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    86
	|   |
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    87
	c = d	*)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    88
val box_equals = prove_goal HOL.thy
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    89
    "[| a=b;  a=c;  b=d |] ==> c=d"  
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    90
 (fn prems=>
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    91
  [ (rtac trans 1),
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    92
    (rtac trans 1),
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    93
    (rtac sym 1),
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    94
    (REPEAT (resolve_tac prems 1)) ]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    95
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    96
(** Congruence rules for meta-application **)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    97
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    98
(*similar to AP_THM in Gordon's HOL*)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
    99
val fun_cong = prove_goal HOL.thy "(f::'a=>'b) = g ==> f(x)=g(x)"
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   100
  (fn [prem] => [rtac (prem RS subst) 1, rtac refl 1]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   101
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   102
(*similar to AP_TERM in Gordon's HOL and FOL's subst_context*)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   103
val arg_cong = prove_goal HOL.thy "x=y ==> f(x)=f(y)"
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   104
 (fn [prem] => [rtac (prem RS subst) 1, rtac refl 1]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   105
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   106
val cong = prove_goal HOL.thy
90
5c7a69cef18b added parentheses made necessary by change of constrain's precedence
clasohm
parents: 84
diff changeset
   107
   "[| f = g; (x::'a) = y |] ==> f(x) = g(y)"
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   108
 (fn [prem1,prem2] =>
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   109
   [rtac (prem1 RS subst) 1, rtac (prem2 RS subst) 1, rtac refl 1]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   110
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   111
(** Equality of booleans -- iff **)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   112
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   113
val iffI = prove_goal HOL.thy
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   114
   "[| P ==> Q;  Q ==> P |] ==> P=Q"
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   115
 (fn prems=> [ (REPEAT (ares_tac (prems@[impI, iff RS mp RS mp]) 1)) ]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   116
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   117
val iffD2 = prove_goal HOL.thy "[| P=Q; Q |] ==> P"
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   118
 (fn prems =>
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   119
	[rtac ssubst 1, resolve_tac prems 1, resolve_tac prems 1]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   120
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   121
val iffD1 = sym RS iffD2;
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   122
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   123
val iffE = prove_goal HOL.thy
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   124
    "[| P=Q; [| P --> Q; Q --> P |] ==> R |] ==> R"
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   125
 (fn [p1,p2] => [REPEAT(ares_tac([p1 RS iffD2, p1 RS iffD1, p2, impI])1)]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   126
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   127
(** True **)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   128
66
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   129
val TrueI = prove_goalw HOL.thy [True_def] "True"
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   130
  (fn _ => [rtac refl 1]);
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   131
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   132
val eqTrueI  = prove_goal HOL.thy "P ==> P=True" 
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   133
 (fn prems => [REPEAT(resolve_tac ([iffI,TrueI]@prems) 1)]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   134
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   135
val eqTrueE = prove_goal HOL.thy "P=True ==> P" 
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   136
 (fn prems => [REPEAT(resolve_tac (prems@[TrueI,iffD2]) 1)]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   137
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   138
(** Universal quantifier **)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   139
66
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   140
val allI = prove_goalw HOL.thy [All_def] "(!!x::'a. P(x)) ==> !x. P(x)"
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   141
 (fn prems => [resolve_tac (prems RL [eqTrueI RS ext]) 1]);
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   142
66
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   143
val spec = prove_goalw HOL.thy [All_def] "! x::'a.P(x) ==> P(x)"
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   144
 (fn prems => [rtac eqTrueE 1, resolve_tac (prems RL [fun_cong]) 1]);
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   145
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   146
val allE = prove_goal HOL.thy "[| !x.P(x);  P(x) ==> R |] ==> R"
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   147
 (fn major::prems=>
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   148
  [ (REPEAT (resolve_tac (prems @ [major RS spec]) 1)) ]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   149
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   150
val all_dupE = prove_goal HOL.thy 
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   151
    "[| ! x.P(x);  [| P(x); ! x.P(x) |] ==> R |] ==> R"
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   152
 (fn prems =>
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   153
  [ (REPEAT (resolve_tac (prems @ (prems RL [spec])) 1)) ]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   154
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   155
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   156
(** False ** Depends upon spec; it is impossible to do propositional logic
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   157
             before quantifiers! **)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   158
84
3410f4d85086 HOL/HOL.ML/notE: tidied the proof
lcp
parents: 75
diff changeset
   159
val FalseE = prove_goalw HOL.thy [False_def] "False ==> P"
3410f4d85086 HOL/HOL.ML/notE: tidied the proof
lcp
parents: 75
diff changeset
   160
 (fn [major] => [rtac (major RS spec) 1]);
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   161
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   162
val False_neq_True = prove_goal HOL.thy "False=True ==> P"
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   163
 (fn [prem] => [rtac (prem RS eqTrueE RS FalseE) 1]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   164
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   165
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   166
(** Negation **)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   167
66
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   168
val notI = prove_goalw HOL.thy [not_def] "(P ==> False) ==> ~P"
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   169
 (fn prems=> [rtac impI 1, eresolve_tac prems 1]);
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   170
66
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   171
val notE = prove_goalw HOL.thy [not_def] "[| ~P;  P |] ==> R"
75
74bc51d20112 HOL/HOL.ML/notE: tidied
lcp
parents: 66
diff changeset
   172
 (fn prems => [rtac (prems MRS mp RS FalseE) 1]);
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   173
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   174
(** Implication **)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   175
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   176
val impE = prove_goal HOL.thy "[| P-->Q;  P;  Q ==> R |] ==> R"
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   177
 (fn prems=> [ (REPEAT (resolve_tac (prems@[mp]) 1)) ]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   178
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   179
(* Reduces Q to P-->Q, allowing substitution in P. *)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   180
val rev_mp = prove_goal HOL.thy "[| P;  P --> Q |] ==> Q"
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   181
 (fn prems=>  [ (REPEAT (resolve_tac (prems@[mp]) 1)) ]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   182
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   183
val contrapos = prove_goal HOL.thy "[| ~Q;  P==>Q |] ==> ~P"
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   184
 (fn [major,minor]=> 
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   185
  [ (rtac (major RS notE RS notI) 1), 
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   186
    (etac minor 1) ]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   187
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   188
(* ~(?t = ?s) ==> ~(?s = ?t) *)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   189
val [not_sym] = compose(sym,2,contrapos);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   190
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   191
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   192
(** Existential quantifier **)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   193
66
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   194
val exI = prove_goalw HOL.thy [Ex_def] "P(x) ==> ? x::'a.P(x)"
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   195
 (fn prems => [rtac selectI 1, resolve_tac prems 1]);
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   196
66
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   197
val exE = prove_goalw HOL.thy [Ex_def]
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   198
  "[| ? x::'a.P(x); !!x. P(x) ==> Q |] ==> Q"
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   199
  (fn prems => [REPEAT(resolve_tac prems 1)]);
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   200
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   201
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   202
(** Conjunction **)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   203
66
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   204
val conjI = prove_goalw HOL.thy [and_def] "[| P; Q |] ==> P&Q"
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   205
 (fn prems =>
66
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   206
  [REPEAT (resolve_tac (prems@[allI,impI]) 1 ORELSE etac (mp RS mp) 1)]);
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   207
66
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   208
val conjunct1 = prove_goalw HOL.thy [and_def] "[| P & Q |] ==> P"
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   209
 (fn prems =>
66
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   210
   [resolve_tac (prems RL [spec] RL [mp]) 1, REPEAT(ares_tac [impI] 1)]);
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   211
66
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   212
val conjunct2 = prove_goalw HOL.thy [and_def] "[| P & Q |] ==> Q"
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   213
 (fn prems =>
66
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   214
   [resolve_tac (prems RL [spec] RL [mp]) 1, REPEAT(ares_tac [impI] 1)]);
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   215
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   216
val conjE = prove_goal HOL.thy "[| P&Q;  [| P; Q |] ==> R |] ==> R"
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   217
 (fn prems =>
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   218
	 [cut_facts_tac prems 1, resolve_tac prems 1,
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   219
	  etac conjunct1 1, etac conjunct2 1]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   220
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   221
(** Disjunction *)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   222
66
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   223
val disjI1 = prove_goalw HOL.thy [or_def] "P ==> P|Q"
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   224
 (fn [prem] => [REPEAT(ares_tac [allI,impI, prem RSN (2,mp)] 1)]);
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   225
66
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   226
val disjI2 = prove_goalw HOL.thy [or_def] "Q ==> P|Q"
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   227
 (fn [prem] => [REPEAT(ares_tac [allI,impI, prem RSN (2,mp)] 1)]);
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   228
66
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   229
val disjE = prove_goalw HOL.thy [or_def] "[| P | Q; P ==> R; Q ==> R |] ==> R"
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   230
 (fn [a1,a2,a3] =>
66
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   231
	[rtac (mp RS mp) 1, rtac spec 1, rtac a1 1,
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   232
	 rtac (a2 RS impI) 1, atac 1, rtac (a3 RS impI) 1, atac 1]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   233
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   234
(** CCONTR -- classical logic **)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   235
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   236
val ccontr = prove_goal HOL.thy "(~P ==> False) ==> P"
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   237
 (fn prems =>
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   238
   [rtac (True_or_False RS (disjE RS eqTrueE)) 1, atac 1,
66
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   239
    rtac spec 1, fold_tac [False_def], resolve_tac prems 1,
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   240
    rtac ssubst 1, atac 1, rewtac not_def,
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   241
    REPEAT (ares_tac [impI] 1) ]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   242
66
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   243
val ccontr = prove_goalw HOL.thy [not_def] "(~P ==> False) ==> P"
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   244
 (fn prems =>
66
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   245
   [rtac (True_or_False RS (disjE RS eqTrueE)) 1, atac 1,
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   246
    rtac spec 1, fold_tac [False_def], resolve_tac prems 1,
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   247
    rtac ssubst 1, atac 1, REPEAT (ares_tac [impI] 1) ]);
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   248
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   249
val classical = prove_goal HOL.thy "(~P ==> P) ==> P"
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   250
 (fn prems => [rtac ccontr 1, REPEAT (ares_tac (prems@[notE]) 1)]);
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   251
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   252
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   253
(*Double negation law*)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   254
val notnotD = prove_goal HOL.thy "~~P ==> P"
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   255
 (fn [major]=>
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   256
  [ (rtac classical 1), (eresolve_tac [major RS notE] 1) ]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   257
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   258
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   259
(** Unique existence **)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   260
66
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   261
val ex1I = prove_goalw HOL.thy [Ex1_def]
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   262
    "[| P(a);  !!x. P(x) ==> x=a |] ==> ?! x. P(x)"
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   263
 (fn prems =>
66
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   264
  [REPEAT (ares_tac (prems@[exI,conjI,allI,impI]) 1)]);
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   265
66
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   266
val ex1E = prove_goalw HOL.thy [Ex1_def]
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   267
    "[| ?! x.P(x);  !!x. [| P(x);  ! y. P(y) --> y=x |] ==> R |] ==> R"
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   268
 (fn major::prems =>
66
14b9286ed036 changed defns in hol.thy from = to ==
nipkow
parents: 48
diff changeset
   269
  [rtac (major RS exE) 1, REPEAT (etac conjE 1 ORELSE ares_tac prems 1)]);
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   270
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   271
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   272
(** Select: Hilbert's Epsilon-operator **)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   273
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   274
val select_equality = prove_goal HOL.thy
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   275
    "[| P(a);  !!x. P(x) ==> x=a |] ==> (@x.P(x)) = a"
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   276
 (fn prems => [ resolve_tac prems 1, 
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   277
	        rtac selectI 1, 
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   278
		resolve_tac prems 1 ]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   279
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   280
(** Classical intro rules for disjunction and existential quantifiers *)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   281
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   282
val disjCI = prove_goal HOL.thy "(~Q ==> P) ==> P|Q"
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   283
 (fn prems=>
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   284
  [ (rtac classical 1),
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   285
    (REPEAT (ares_tac (prems@[disjI1,notI]) 1)),
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   286
    (REPEAT (ares_tac (prems@[disjI2,notE]) 1)) ]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   287
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   288
val excluded_middle = prove_goal HOL.thy "~P | P"
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   289
 (fn _ => [ (REPEAT (ares_tac [disjCI] 1)) ]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   290
128
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
   291
(*For disjunctive case analysis*)
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
   292
fun excluded_middle_tac sP =
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
   293
    res_inst_tac [("Q",sP)] (excluded_middle RS disjE);
89669c58e506 INSTALLATION OF INDUCTIVE DEFINITIONS
lcp
parents: 90
diff changeset
   294
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   295
(*Classical implies (-->) elimination. *)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   296
val impCE = prove_goal HOL.thy "[| P-->Q; ~P ==> R; Q ==> R |] ==> R" 
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   297
 (fn major::prems=>
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   298
  [ rtac (excluded_middle RS disjE) 1,
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   299
    REPEAT (DEPTH_SOLVE_1 (ares_tac (prems @ [major RS mp]) 1))]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   300
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   301
(*Classical <-> elimination. *)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   302
val iffCE = prove_goal HOL.thy
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   303
    "[| P=Q;  [| P; Q |] ==> R;  [| ~P; ~Q |] ==> R |] ==> R"
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   304
 (fn major::prems =>
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   305
  [ (rtac (major RS iffE) 1),
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   306
    (REPEAT (DEPTH_SOLVE_1 
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   307
	(eresolve_tac ([asm_rl,impCE,notE]@prems) 1))) ]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   308
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   309
val exCI = prove_goal HOL.thy "(! x. ~P(x) ==> P(a)) ==> ? x.P(x)"
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   310
 (fn prems=>
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   311
  [ (rtac ccontr 1),
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   312
    (REPEAT (ares_tac (prems@[exI,allI,notI,notE]) 1))  ]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   313
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   314
(*Required by the "classical" module*)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   315
val swap = prove_goal HOL.thy "~P ==> (~Q ==> P) ==> Q"
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   316
 (fn major::prems=>
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   317
  [ rtac ccontr 1, rtac (major RS notE) 1, REPEAT (ares_tac prems 1)]);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   318
40
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 0
diff changeset
   319
(* case distinction *)
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 0
diff changeset
   320
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 0
diff changeset
   321
val case_split_thm = prove_goal HOL.thy "[| P ==> Q; ~P ==> Q |] ==> Q"
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 0
diff changeset
   322
  (fn [p1,p2] => [cut_facts_tac [excluded_middle] 1, etac disjE 1,
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 0
diff changeset
   323
                  etac p2 1, etac p1 1]);
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 0
diff changeset
   324
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 0
diff changeset
   325
fun case_tac a = res_inst_tac [("P",a)] case_split_thm;
ac7b7003f177 Introduction of various new lemmas and of case_tac.
nipkow
parents: 0
diff changeset
   326
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   327
(** Standard abbreviations **)
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   328
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   329
fun stac th = rtac(th RS ssubst);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   330
fun sstac ths = EVERY' (map stac ths);
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   331
fun strip_tac i = REPEAT(resolve_tac [impI,allI] i); 
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   332
48
21291189b51e changed "." to "$" and Cons to infix "#" to eliminate ambiguity
clasohm
parents: 40
diff changeset
   333
0
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   334
end;
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   335
7949f97df77a Initial revision
clasohm
parents:
diff changeset
   336
open HOL_Lemmas;