src/ZF/ex/proplog.ML
author lcp
Tue Aug 16 18:58:42 1994 +0200 (1994-08-16)
changeset 532 851df239ac8b
parent 16 0b033d50ca1c
permissions -rw-r--r--
ZF/Makefile,ROOT.ML, ZF/ex/Integ.thy: updated for EquivClass
clasohm@0
     1
(*  Title: 	ZF/ex/prop-log.ML
clasohm@0
     2
    ID:         $Id$
clasohm@0
     3
    Author: 	Tobias Nipkow & Lawrence C Paulson
clasohm@0
     4
    Copyright   1992  University of Cambridge
clasohm@0
     5
clasohm@0
     6
For ex/prop-log.thy.  Inductive definition of propositional logic.
clasohm@0
     7
Soundness and completeness w.r.t. truth-tables.
clasohm@0
     8
clasohm@0
     9
Prove: If H|=p then G|=p where G:Fin(H)
clasohm@0
    10
*)
clasohm@0
    11
clasohm@0
    12
open PropLog;
clasohm@0
    13
clasohm@0
    14
(*** prop_rec -- by Vset recursion ***)
clasohm@0
    15
clasohm@0
    16
(** conversion rules **)
clasohm@0
    17
clasohm@0
    18
goal PropLog.thy "prop_rec(Fls,b,c,d) = b";
clasohm@0
    19
by (rtac (prop_rec_def RS def_Vrec RS trans) 1);
clasohm@0
    20
by (rewrite_goals_tac Prop.con_defs);
lcp@7
    21
by (simp_tac rank_ss 1);
clasohm@0
    22
val prop_rec_Fls = result();
clasohm@0
    23
clasohm@0
    24
goal PropLog.thy "prop_rec(#v,b,c,d) = c(v)";
clasohm@0
    25
by (rtac (prop_rec_def RS def_Vrec RS trans) 1);
clasohm@0
    26
by (rewrite_goals_tac Prop.con_defs);
lcp@7
    27
by (simp_tac rank_ss 1);
clasohm@0
    28
val prop_rec_Var = result();
clasohm@0
    29
clasohm@0
    30
goal PropLog.thy "prop_rec(p=>q,b,c,d) = \
clasohm@0
    31
\      d(p, q, prop_rec(p,b,c,d), prop_rec(q,b,c,d))";
clasohm@0
    32
by (rtac (prop_rec_def RS def_Vrec RS trans) 1);
clasohm@0
    33
by (rewrite_goals_tac Prop.con_defs);
lcp@7
    34
by (simp_tac rank_ss 1);
clasohm@0
    35
val prop_rec_Imp = result();
clasohm@0
    36
clasohm@0
    37
val prop_rec_ss = 
lcp@7
    38
    arith_ss addsimps [prop_rec_Fls, prop_rec_Var, prop_rec_Imp];
clasohm@0
    39
clasohm@0
    40
(*** Semantics of propositional logic ***)
clasohm@0
    41
clasohm@0
    42
(** The function is_true **)
clasohm@0
    43
clasohm@0
    44
goalw PropLog.thy [is_true_def] "is_true(Fls,t) <-> False";
lcp@7
    45
by (simp_tac (prop_rec_ss addsimps [one_not_0 RS not_sym]) 1);
clasohm@0
    46
val is_true_Fls = result();
clasohm@0
    47
clasohm@0
    48
goalw PropLog.thy [is_true_def] "is_true(#v,t) <-> v:t";
lcp@7
    49
by (simp_tac (prop_rec_ss addsimps [one_not_0 RS not_sym] 
lcp@7
    50
	      setloop (split_tac [expand_if])) 1);
clasohm@0
    51
val is_true_Var = result();
clasohm@0
    52
clasohm@0
    53
goalw PropLog.thy [is_true_def]
clasohm@0
    54
    "is_true(p=>q,t) <-> (is_true(p,t)-->is_true(q,t))";
lcp@7
    55
by (simp_tac (prop_rec_ss setloop (split_tac [expand_if])) 1);
clasohm@0
    56
val is_true_Imp = result();
clasohm@0
    57
clasohm@0
    58
(** The function hyps **)
clasohm@0
    59
clasohm@0
    60
goalw PropLog.thy [hyps_def] "hyps(Fls,t) = 0";
lcp@7
    61
by (simp_tac prop_rec_ss 1);
clasohm@0
    62
val hyps_Fls = result();
clasohm@0
    63
clasohm@0
    64
goalw PropLog.thy [hyps_def] "hyps(#v,t) = {if(v:t, #v, #v=>Fls)}";
lcp@7
    65
by (simp_tac prop_rec_ss 1);
clasohm@0
    66
val hyps_Var = result();
clasohm@0
    67
clasohm@0
    68
goalw PropLog.thy [hyps_def] "hyps(p=>q,t) = hyps(p,t) Un hyps(q,t)";
lcp@7
    69
by (simp_tac prop_rec_ss 1);
clasohm@0
    70
val hyps_Imp = result();
clasohm@0
    71
clasohm@0
    72
val prop_ss = prop_rec_ss 
lcp@7
    73
    addsimps Prop.intrs
lcp@7
    74
    addsimps [is_true_Fls, is_true_Var, is_true_Imp,
lcp@7
    75
	      hyps_Fls, hyps_Var, hyps_Imp];
clasohm@0
    76
clasohm@0
    77
(*** Proof theory of propositional logic ***)
clasohm@0
    78
clasohm@0
    79
structure PropThms = Inductive_Fun
clasohm@0
    80
 (val thy = PropLog.thy;
clasohm@0
    81
  val rec_doms = [("thms","prop")];
clasohm@0
    82
  val sintrs = 
clasohm@0
    83
      ["[| p:H;  p:prop |] ==> H |- p",
clasohm@0
    84
       "[| p:prop;  q:prop |] ==> H |- p=>q=>p",
clasohm@0
    85
       "[| p:prop;  q:prop;  r:prop |] ==> H |- (p=>q=>r) => (p=>q) => p=>r",
clasohm@0
    86
       "p:prop ==> H |- ((p=>Fls) => Fls) => p",
clasohm@0
    87
       "[| H |- p=>q;  H |- p;  p:prop;  q:prop |] ==> H |- q"];
clasohm@0
    88
  val monos = [];
clasohm@0
    89
  val con_defs = [];
clasohm@0
    90
  val type_intrs = Prop.intrs;
clasohm@0
    91
  val type_elims = []);
clasohm@0
    92
clasohm@0
    93
goalw PropThms.thy PropThms.defs "!!G H. G<=H ==> thms(G) <= thms(H)";
clasohm@0
    94
by (rtac lfp_mono 1);
clasohm@0
    95
by (REPEAT (rtac PropThms.bnd_mono 1));
clasohm@0
    96
by (REPEAT (ares_tac (univ_mono::basic_monos) 1));
clasohm@0
    97
val thms_mono = result();
clasohm@0
    98
clasohm@0
    99
val thms_in_pl = PropThms.dom_subset RS subsetD;
clasohm@0
   100
clasohm@0
   101
val [thms_H, thms_K, thms_S, thms_DN, weak_thms_MP] = PropThms.intrs;
clasohm@0
   102
clasohm@0
   103
(*Modus Ponens rule -- this stronger version avoids typecheck*)
clasohm@0
   104
goal PropThms.thy "!!p q H. [| H |- p=>q;  H |- p |] ==> H |- q";
clasohm@0
   105
by (rtac weak_thms_MP 1);
clasohm@0
   106
by (REPEAT (eresolve_tac [asm_rl, thms_in_pl, thms_in_pl RS ImpE] 1));
clasohm@0
   107
val thms_MP = result();
clasohm@0
   108
clasohm@0
   109
(*Rule is called I for Identity Combinator, not for Introduction*)
clasohm@0
   110
goal PropThms.thy "!!p H. p:prop ==> H |- p=>p";
clasohm@0
   111
by (rtac (thms_S RS thms_MP RS thms_MP) 1);
clasohm@0
   112
by (rtac thms_K 5);
clasohm@0
   113
by (rtac thms_K 4);
clasohm@0
   114
by (REPEAT (ares_tac [ImpI] 1));
clasohm@0
   115
val thms_I = result();
clasohm@0
   116
clasohm@0
   117
(** Weakening, left and right **)
clasohm@0
   118
clasohm@0
   119
(* [| G<=H;  G|-p |] ==> H|-p   Order of premises is convenient with RS*)
clasohm@0
   120
val weaken_left = standard (thms_mono RS subsetD);
clasohm@0
   121
clasohm@0
   122
(* H |- p ==> cons(a,H) |- p *)
clasohm@0
   123
val weaken_left_cons = subset_consI RS weaken_left;
clasohm@0
   124
clasohm@0
   125
val weaken_left_Un1  = Un_upper1 RS weaken_left;
clasohm@0
   126
val weaken_left_Un2  = Un_upper2 RS weaken_left;
clasohm@0
   127
clasohm@0
   128
goal PropThms.thy "!!H p q. [| H |- q;  p:prop |] ==> H |- p=>q";
clasohm@0
   129
by (rtac (thms_K RS thms_MP) 1);
clasohm@0
   130
by (REPEAT (ares_tac [thms_in_pl] 1));
clasohm@0
   131
val weaken_right = result();
clasohm@0
   132
clasohm@0
   133
(*The deduction theorem*)
clasohm@0
   134
goal PropThms.thy "!!p q H. [| cons(p,H) |- q;  p:prop |] ==>  H |- p=>q";
clasohm@0
   135
by (etac PropThms.induct 1);
clasohm@0
   136
by (fast_tac (ZF_cs addIs [thms_I, thms_H RS weaken_right]) 1);
clasohm@0
   137
by (fast_tac (ZF_cs addIs [thms_K RS weaken_right]) 1);
clasohm@0
   138
by (fast_tac (ZF_cs addIs [thms_S RS weaken_right]) 1);
clasohm@0
   139
by (fast_tac (ZF_cs addIs [thms_DN RS weaken_right]) 1);
clasohm@0
   140
by (fast_tac (ZF_cs addIs [thms_S RS thms_MP RS thms_MP]) 1);
clasohm@0
   141
val deduction = result();
clasohm@0
   142
clasohm@0
   143
clasohm@0
   144
(*The cut rule*)
clasohm@0
   145
goal PropThms.thy "!!H p q. [| H|-p;  cons(p,H) |- q |] ==>  H |- q";
clasohm@0
   146
by (rtac (deduction RS thms_MP) 1);
clasohm@0
   147
by (REPEAT (ares_tac [thms_in_pl] 1));
clasohm@0
   148
val cut = result();
clasohm@0
   149
clasohm@0
   150
goal PropThms.thy "!!H p. [| H |- Fls; p:prop |] ==> H |- p";
clasohm@0
   151
by (rtac (thms_DN RS thms_MP) 1);
clasohm@0
   152
by (rtac weaken_right 2);
clasohm@0
   153
by (REPEAT (ares_tac (Prop.intrs@[consI1]) 1));
clasohm@0
   154
val thms_FlsE = result();
clasohm@0
   155
clasohm@0
   156
(* [| H |- p=>Fls;  H |- p;  q: prop |] ==> H |- q *)
clasohm@0
   157
val thms_notE = standard (thms_MP RS thms_FlsE);
clasohm@0
   158
clasohm@0
   159
(*Soundness of the rules wrt truth-table semantics*)
lcp@7
   160
goalw PropThms.thy [sat_def] "!!H. H |- p ==> H |= p";
lcp@7
   161
by (etac PropThms.induct 1);
clasohm@0
   162
by (fast_tac (ZF_cs addSDs [is_true_Imp RS iffD1 RS mp]) 5);
lcp@7
   163
by (ALLGOALS (asm_simp_tac prop_ss));
clasohm@0
   164
val soundness = result();
clasohm@0
   165
clasohm@0
   166
(*** Towards the completeness proof ***)
clasohm@0
   167
clasohm@0
   168
val [premf,premq] = goal PropThms.thy
clasohm@0
   169
    "[| H |- p=>Fls; q: prop |] ==> H |- p=>q";
clasohm@0
   170
by (rtac (premf RS thms_in_pl RS ImpE) 1);
clasohm@0
   171
by (rtac deduction 1);
clasohm@0
   172
by (rtac (premf RS weaken_left_cons RS thms_notE) 1);
clasohm@0
   173
by (REPEAT (ares_tac [premq, consI1, thms_H] 1));
clasohm@0
   174
val Fls_Imp = result();
clasohm@0
   175
clasohm@0
   176
val [premp,premq] = goal PropThms.thy
clasohm@0
   177
    "[| H |- p;  H |- q=>Fls |] ==> H |- (p=>q)=>Fls";
clasohm@0
   178
by (cut_facts_tac ([premp,premq] RL [thms_in_pl]) 1);
clasohm@0
   179
by (etac ImpE 1);
clasohm@0
   180
by (rtac deduction 1);
clasohm@0
   181
by (rtac (premq RS weaken_left_cons RS thms_MP) 1);
clasohm@0
   182
by (rtac (consI1 RS thms_H RS thms_MP) 1);
clasohm@0
   183
by (rtac (premp RS weaken_left_cons) 2);
clasohm@0
   184
by (REPEAT (ares_tac Prop.intrs 1));
clasohm@0
   185
val Imp_Fls = result();
clasohm@0
   186
clasohm@0
   187
(*Typical example of strengthening the induction formula*)
clasohm@0
   188
val [major] = goal PropThms.thy 
clasohm@0
   189
    "p: prop ==> hyps(p,t) |- if(is_true(p,t), p, p=>Fls)";
clasohm@0
   190
by (rtac (expand_if RS iffD2) 1);
clasohm@0
   191
by (rtac (major RS Prop.induct) 1);
lcp@7
   192
by (ALLGOALS (asm_simp_tac (prop_ss addsimps [thms_I, thms_H])));
lcp@16
   193
by (safe_tac (ZF_cs addSEs [Fls_Imp RS weaken_left_Un1, 
lcp@16
   194
			    Fls_Imp RS weaken_left_Un2]));
lcp@16
   195
by (ALLGOALS (fast_tac (ZF_cs addIs [weaken_left_Un1, weaken_left_Un2, 
lcp@16
   196
				     weaken_right, Imp_Fls])));
clasohm@0
   197
val hyps_thms_if = result();
clasohm@0
   198
clasohm@0
   199
(*Key lemma for completeness; yields a set of assumptions satisfying p*)
clasohm@0
   200
val [premp,sat] = goalw PropThms.thy [sat_def]
clasohm@0
   201
    "[| p: prop;  0 |= p |] ==> hyps(p,t) |- p";
clasohm@0
   202
by (rtac (sat RS spec RS mp RS if_P RS subst) 1 THEN
clasohm@0
   203
    rtac (premp RS hyps_thms_if) 2);
clasohm@0
   204
by (fast_tac ZF_cs 1);
clasohm@0
   205
val sat_thms_p = result();
clasohm@0
   206
clasohm@0
   207
(*For proving certain theorems in our new propositional logic*)
clasohm@0
   208
val thms_cs = 
clasohm@0
   209
    ZF_cs addSIs [FlsI, VarI, ImpI, deduction]
clasohm@0
   210
          addIs [thms_in_pl, thms_H, thms_H RS thms_MP];
clasohm@0
   211
clasohm@0
   212
(*The excluded middle in the form of an elimination rule*)
clasohm@0
   213
val prems = goal PropThms.thy
clasohm@0
   214
    "[| p: prop;  q: prop |] ==> H |- (p=>q) => ((p=>Fls)=>q) => q";
clasohm@0
   215
by (rtac (deduction RS deduction) 1);
clasohm@0
   216
by (rtac (thms_DN RS thms_MP) 1);
clasohm@0
   217
by (ALLGOALS (best_tac (thms_cs addSIs prems)));
clasohm@0
   218
val thms_excluded_middle = result();
clasohm@0
   219
clasohm@0
   220
(*Hard to prove directly because it requires cuts*)
clasohm@0
   221
val prems = goal PropThms.thy
clasohm@0
   222
    "[| cons(p,H) |- q;  cons(p=>Fls,H) |- q;  p: prop |] ==> H |- q";
clasohm@0
   223
by (rtac (thms_excluded_middle RS thms_MP RS thms_MP) 1);
clasohm@0
   224
by (REPEAT (resolve_tac (prems@Prop.intrs@[deduction,thms_in_pl]) 1));
clasohm@0
   225
val thms_excluded_middle_rule = result();
clasohm@0
   226
clasohm@0
   227
(*** Completeness -- lemmas for reducing the set of assumptions ***)
clasohm@0
   228
clasohm@0
   229
(*For the case hyps(p,t)-cons(#v,Y) |- p;
clasohm@0
   230
  we also have hyps(p,t)-{#v} <= hyps(p, t-{v}) *)
clasohm@0
   231
val [major] = goal PropThms.thy
clasohm@0
   232
    "p: prop ==> hyps(p, t-{v}) <= cons(#v=>Fls, hyps(p,t)-{#v})";
clasohm@0
   233
by (rtac (major RS Prop.induct) 1);
lcp@7
   234
by (simp_tac prop_ss 1);
lcp@7
   235
by (asm_simp_tac (prop_ss setloop (split_tac [expand_if])) 1);
clasohm@0
   236
by (fast_tac (ZF_cs addSEs Prop.free_SEs) 1);
lcp@7
   237
by (asm_simp_tac prop_ss 1);
clasohm@0
   238
by (fast_tac ZF_cs 1);
clasohm@0
   239
val hyps_Diff = result();
clasohm@0
   240
clasohm@0
   241
(*For the case hyps(p,t)-cons(#v => Fls,Y) |- p;
clasohm@0
   242
  we also have hyps(p,t)-{#v=>Fls} <= hyps(p, cons(v,t)) *)
clasohm@0
   243
val [major] = goal PropThms.thy
clasohm@0
   244
    "p: prop ==> hyps(p, cons(v,t)) <= cons(#v, hyps(p,t)-{#v=>Fls})";
clasohm@0
   245
by (rtac (major RS Prop.induct) 1);
lcp@7
   246
by (simp_tac prop_ss 1);
lcp@7
   247
by (asm_simp_tac (prop_ss setloop (split_tac [expand_if])) 1);
clasohm@0
   248
by (fast_tac (ZF_cs addSEs Prop.free_SEs) 1);
lcp@7
   249
by (asm_simp_tac prop_ss 1);
clasohm@0
   250
by (fast_tac ZF_cs 1);
clasohm@0
   251
val hyps_cons = result();
clasohm@0
   252
clasohm@0
   253
(** Two lemmas for use with weaken_left **)
clasohm@0
   254
clasohm@0
   255
goal ZF.thy "B-C <= cons(a, B-cons(a,C))";
clasohm@0
   256
by (fast_tac ZF_cs 1);
clasohm@0
   257
val cons_Diff_same = result();
clasohm@0
   258
clasohm@0
   259
goal ZF.thy "cons(a, B-{c}) - D <= cons(a, B-cons(c,D))";
clasohm@0
   260
by (fast_tac ZF_cs 1);
clasohm@0
   261
val cons_Diff_subset2 = result();
clasohm@0
   262
clasohm@0
   263
(*The set hyps(p,t) is finite, and elements have the form #v or #v=>Fls;
clasohm@0
   264
 could probably prove the stronger hyps(p,t) : Fin(hyps(p,0) Un hyps(p,nat))*)
clasohm@0
   265
val [major] = goal PropThms.thy
clasohm@0
   266
    "p: prop ==> hyps(p,t) : Fin(UN v:nat. {#v, #v=>Fls})";
clasohm@0
   267
by (rtac (major RS Prop.induct) 1);
lcp@16
   268
by (asm_simp_tac (prop_ss addsimps [Fin_0I, Fin_consI, UN_I, cons_iff]
lcp@7
   269
		  setloop (split_tac [expand_if])) 2);
lcp@7
   270
by (ALLGOALS (asm_simp_tac (prop_ss addsimps [Un_0, Fin_0I, Fin_UnI])));
clasohm@0
   271
val hyps_finite = result();
clasohm@0
   272
clasohm@0
   273
val Diff_weaken_left = subset_refl RSN (2, Diff_mono) RS weaken_left;
clasohm@0
   274
clasohm@0
   275
(*Induction on the finite set of assumptions hyps(p,t0).
clasohm@0
   276
  We may repeatedly subtract assumptions until none are left!*)
clasohm@0
   277
val [premp,sat] = goal PropThms.thy
clasohm@0
   278
    "[| p: prop;  0 |= p |] ==> ALL t. hyps(p,t) - hyps(p,t0) |- p";
clasohm@0
   279
by (rtac (premp RS hyps_finite RS Fin_induct) 1);
lcp@7
   280
by (simp_tac (prop_ss addsimps [premp, sat, sat_thms_p, Diff_0]) 1);
clasohm@0
   281
by (safe_tac ZF_cs);
clasohm@0
   282
(*Case hyps(p,t)-cons(#v,Y) |- p *)
clasohm@0
   283
by (rtac thms_excluded_middle_rule 1);
clasohm@0
   284
by (etac VarI 3);
clasohm@0
   285
by (rtac (cons_Diff_same RS weaken_left) 1);
clasohm@0
   286
by (etac spec 1);
clasohm@0
   287
by (rtac (cons_Diff_subset2 RS weaken_left) 1);
clasohm@0
   288
by (rtac (premp RS hyps_Diff RS Diff_weaken_left) 1);
clasohm@0
   289
by (etac spec 1);
clasohm@0
   290
(*Case hyps(p,t)-cons(#v => Fls,Y) |- p *)
clasohm@0
   291
by (rtac thms_excluded_middle_rule 1);
clasohm@0
   292
by (etac VarI 3);
clasohm@0
   293
by (rtac (cons_Diff_same RS weaken_left) 2);
clasohm@0
   294
by (etac spec 2);
clasohm@0
   295
by (rtac (cons_Diff_subset2 RS weaken_left) 1);
clasohm@0
   296
by (rtac (premp RS hyps_cons RS Diff_weaken_left) 1);
clasohm@0
   297
by (etac spec 1);
clasohm@0
   298
val completeness_0_lemma = result();
clasohm@0
   299
clasohm@0
   300
(*The base case for completeness*)
clasohm@0
   301
val [premp,sat] = goal PropThms.thy "[| p: prop;  0 |= p |] ==> 0 |- p";
clasohm@0
   302
by (rtac (Diff_cancel RS subst) 1);
clasohm@0
   303
by (rtac (sat RS (premp RS completeness_0_lemma RS spec)) 1);
clasohm@0
   304
val completeness_0 = result();
clasohm@0
   305
clasohm@0
   306
(*A semantic analogue of the Deduction Theorem*)
clasohm@0
   307
goalw PropThms.thy [sat_def] "!!H p q. [| cons(p,H) |= q |] ==> H |= p=>q";
lcp@7
   308
by (simp_tac prop_ss 1);
clasohm@0
   309
by (fast_tac ZF_cs 1);
clasohm@0
   310
val sat_Imp = result();
clasohm@0
   311
clasohm@0
   312
goal PropThms.thy "!!H. H: Fin(prop) ==> ALL p:prop. H |= p --> H |- p";
clasohm@0
   313
by (etac Fin_induct 1);
clasohm@0
   314
by (safe_tac (ZF_cs addSIs [completeness_0]));
clasohm@0
   315
by (rtac (weaken_left_cons RS thms_MP) 1);
clasohm@0
   316
by (fast_tac (ZF_cs addSIs [sat_Imp,ImpI]) 1);
clasohm@0
   317
by (fast_tac thms_cs 1);
clasohm@0
   318
val completeness_lemma = result();
clasohm@0
   319
clasohm@0
   320
val completeness = completeness_lemma RS bspec RS mp;
clasohm@0
   321
clasohm@0
   322
val [finite] = goal PropThms.thy "H: Fin(prop) ==> H |- p <-> H |= p & p:prop";
clasohm@0
   323
by (fast_tac (ZF_cs addSEs [soundness, finite RS completeness, 
clasohm@0
   324
			    thms_in_pl]) 1);
clasohm@0
   325
val thms_iff = result();
clasohm@0
   326
clasohm@0
   327
writeln"Reached end of file.";