src/HOL/Tools/reconstruction.ML
author berghofe
Mon, 24 Jan 2005 18:18:28 +0100
changeset 15464 02cc838b64ca
parent 15449 a27c81bd838d
child 15466 dce7827f8d75
permissions -rw-r--r--
Added variant of eres_inst_tac that operates on indexnames instead of strings.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15151
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
     1
(*  Title:      HOL/Reconstruction.thy
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
     2
    ID: $Id$
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
     3
    Author:     Lawrence C Paulson and Claire Quigley
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
     4
    Copyright   2004  University of Cambridge
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
     5
*)
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
     6
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
     7
(*Attributes for reconstructing external resolution proofs*)
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
     8
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
     9
structure Reconstruction =
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    10
let open Attrib
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    11
in
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    12
struct
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    13
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    14
(**************************************************************)
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    15
(* extra functions necessary for factoring and paramodulation *)
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    16
(**************************************************************)
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    17
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    18
fun mksubstlist [] sublist = sublist
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    19
  | mksubstlist ((a,b)::rest) sublist = 
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    20
      let val vartype = type_of b
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    21
          val avar = Var(a,vartype)
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    22
          val newlist = ((avar,b)::sublist) 
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    23
      in mksubstlist rest newlist end;
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    24
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    25
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    26
fun get_unif_comb t eqterm =
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    27
    if ((type_of t) = (type_of eqterm))
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    28
    then t
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    29
    else
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    30
        let val _ $ rand = t
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    31
        in get_unif_comb rand eqterm end;
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    32
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    33
fun get_unif_lit t eqterm =
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    34
    if (can HOLogic.dest_eq t)
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    35
    then
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    36
	let val (lhs,rhs) = HOLogic.dest_eq(HOLogic.dest_Trueprop eqterm)
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    37
	in lhs end
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    38
    else
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    39
	get_unif_comb t eqterm;
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    40
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    41
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    42
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    43
(**** attributes ****)
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    44
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    45
(** Binary resolution **)
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    46
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    47
fun binary_rule ((cl1, lit1), (cl2 , lit2)) =
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    48
     select_literal (lit1 + 1) cl1
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    49
     RSN ((lit2 + 1), cl2);
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    50
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    51
fun binary_syntax ((i, B), j) (x, A) = (x, binary_rule ((A,i), (B,j)));
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    52
15384
b13eb8a8897d renamed attributes to lower case
paulson
parents: 15365
diff changeset
    53
fun gen_binary thm = syntax
15151
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    54
      ((Scan.lift Args.nat -- thm -- Scan.lift Args.nat) >> binary_syntax);
15384
b13eb8a8897d renamed attributes to lower case
paulson
parents: 15365
diff changeset
    55
val binary_global = gen_binary global_thm;
b13eb8a8897d renamed attributes to lower case
paulson
parents: 15365
diff changeset
    56
val binary_local = gen_binary local_thm;
15151
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    57
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    58
(*I have not done the MRR rule because it seems to be identifical to 
15384
b13eb8a8897d renamed attributes to lower case
paulson
parents: 15365
diff changeset
    59
binary*)
15151
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    60
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    61
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    62
fun inst_single sign t1 t2 cl =
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    63
    let val ct1 = cterm_of sign t1 and ct2 = cterm_of sign t2
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    64
    in  hd (Seq.list_of(distinct_subgoals_tac
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    65
			    (cterm_instantiate [(ct1,ct2)] cl)))  
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    66
    end;
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    67
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    68
fun inst_subst sign substs cl =
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    69
    if (is_Var (fst(hd(substs))))
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    70
    then inst_single sign (fst (hd substs)) (snd (hd substs)) cl
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    71
    else if (is_Var (snd(hd(substs))))
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    72
    then inst_single sign (snd (hd substs)) (fst (hd substs)) cl
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    73
    else raise THM ("inst_subst", 0, [cl]);
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    74
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    75
(*Grabs the environment from the result of Unify.unifiers*)
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    76
fun getnewenv thisseq = fst (hd (Seq.list_of thisseq));
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    77
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    78
(** Factoring **)
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    79
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    80
fun factor_rule (cl, lit1, lit2) =
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    81
    let
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    82
       val prems = prems_of cl
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    83
       val fac1 = List.nth (prems,lit1)
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    84
       val fac2 = List.nth (prems,lit2)
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    85
       val sign = sign_of_thm cl
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    86
       val unif_env = Unify.unifiers (sign, Envir.empty 0, [(fac1, fac2)])
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    87
       val newenv = getnewenv unif_env
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    88
       val envlist = Envir.alist_of newenv
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    89
     in
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    90
       inst_subst sign (mksubstlist envlist []) cl
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    91
    end;
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    92
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    93
fun factor_syntax (i, j) (x, A) = (x, factor_rule (A,i,j));
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    94
15384
b13eb8a8897d renamed attributes to lower case
paulson
parents: 15365
diff changeset
    95
fun factor x = syntax ((Scan.lift (Args.nat -- Args.nat)) >> factor_syntax) x;
15151
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    96
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    97
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    98
(** Paramodulation **)
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
    99
15449
a27c81bd838d fixed the treatment of demodulation and paramodulation
paulson
parents: 15384
diff changeset
   100
(*subst with premises exchanged: that way, side literals of the equality will appear
a27c81bd838d fixed the treatment of demodulation and paramodulation
paulson
parents: 15384
diff changeset
   101
  as the second to last premises of the result.*)
a27c81bd838d fixed the treatment of demodulation and paramodulation
paulson
parents: 15384
diff changeset
   102
val rev_subst = rotate_prems 1 subst;
a27c81bd838d fixed the treatment of demodulation and paramodulation
paulson
parents: 15384
diff changeset
   103
15151
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
   104
(*Get rid of a Not if it is present*)
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
   105
fun maybe_dest_not (Const ("Not", _) $ t) = t
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
   106
  | maybe_dest_not t = t;
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
   107
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
   108
fun paramod_rule ((cl1, lit1), (cl2 , lit2)) =
15449
a27c81bd838d fixed the treatment of demodulation and paramodulation
paulson
parents: 15384
diff changeset
   109
    let  val eq_lit_th = select_literal (lit1+1) cl1
a27c81bd838d fixed the treatment of demodulation and paramodulation
paulson
parents: 15384
diff changeset
   110
         val mod_lit_th = select_literal (lit2+1) cl2
a27c81bd838d fixed the treatment of demodulation and paramodulation
paulson
parents: 15384
diff changeset
   111
         val eqsubst = eq_lit_th RSN (2,rev_subst)
a27c81bd838d fixed the treatment of demodulation and paramodulation
paulson
parents: 15384
diff changeset
   112
         val newth = Seq.hd (biresolution false [(false, mod_lit_th)] 1 eqsubst)
a27c81bd838d fixed the treatment of demodulation and paramodulation
paulson
parents: 15384
diff changeset
   113
    in negated_asm_of_head newth end
15151
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
   114
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
   115
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
   116
fun paramod_syntax ((i, B), j) (x, A) = (x, paramod_rule ((A,i), (B,j)));
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
   117
15384
b13eb8a8897d renamed attributes to lower case
paulson
parents: 15365
diff changeset
   118
fun gen_paramod thm = syntax
15151
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
   119
      ((Scan.lift Args.nat -- thm -- Scan.lift Args.nat) >> paramod_syntax);
15384
b13eb8a8897d renamed attributes to lower case
paulson
parents: 15365
diff changeset
   120
val paramod_global = gen_paramod global_thm;
b13eb8a8897d renamed attributes to lower case
paulson
parents: 15365
diff changeset
   121
val paramod_local = gen_paramod local_thm;
15151
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
   122
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
   123
15449
a27c81bd838d fixed the treatment of demodulation and paramodulation
paulson
parents: 15384
diff changeset
   124
(** Demodulation: rewriting of a single literal (Non-Unit Rewriting, SPASS) **)
15151
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
   125
15449
a27c81bd838d fixed the treatment of demodulation and paramodulation
paulson
parents: 15384
diff changeset
   126
(*currently identical to paramod_rule: the "match" argument of biresolution cannot be used
a27c81bd838d fixed the treatment of demodulation and paramodulation
paulson
parents: 15384
diff changeset
   127
  to prevent instantiation of the rewritten literal, in mod_lit_th: it could only prevent
a27c81bd838d fixed the treatment of demodulation and paramodulation
paulson
parents: 15384
diff changeset
   128
  instantiation of eq_lit_th, which we do not want.*)
a27c81bd838d fixed the treatment of demodulation and paramodulation
paulson
parents: 15384
diff changeset
   129
fun demod_rule ((cl1, lit1), (cl2 , lit2)) = 
15151
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
   130
    let  val eq_lit_th = select_literal (lit1+1) cl1
15449
a27c81bd838d fixed the treatment of demodulation and paramodulation
paulson
parents: 15384
diff changeset
   131
         val mod_lit_th = select_literal (lit2+1) cl2
a27c81bd838d fixed the treatment of demodulation and paramodulation
paulson
parents: 15384
diff changeset
   132
         val eqsubst = eq_lit_th RSN (2,rev_subst)
a27c81bd838d fixed the treatment of demodulation and paramodulation
paulson
parents: 15384
diff changeset
   133
         val newth = Seq.hd (biresolution false [(false, mod_lit_th)] 1 eqsubst)
a27c81bd838d fixed the treatment of demodulation and paramodulation
paulson
parents: 15384
diff changeset
   134
    in negated_asm_of_head newth end
a27c81bd838d fixed the treatment of demodulation and paramodulation
paulson
parents: 15384
diff changeset
   135
    handle _ => raise THM ("select_literal", lit1, [cl1,cl2]);
15151
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
   136
15449
a27c81bd838d fixed the treatment of demodulation and paramodulation
paulson
parents: 15384
diff changeset
   137
fun demod_syntax ((i, B), j) (x, A) = (x, demod_rule ((A,i), (B,j)));
15151
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
   138
15449
a27c81bd838d fixed the treatment of demodulation and paramodulation
paulson
parents: 15384
diff changeset
   139
fun gen_demod thm = syntax
a27c81bd838d fixed the treatment of demodulation and paramodulation
paulson
parents: 15384
diff changeset
   140
      ((Scan.lift Args.nat -- thm -- Scan.lift Args.nat) >> demod_syntax);
15384
b13eb8a8897d renamed attributes to lower case
paulson
parents: 15365
diff changeset
   141
val demod_global = gen_demod global_thm;
b13eb8a8897d renamed attributes to lower case
paulson
parents: 15365
diff changeset
   142
val demod_local = gen_demod local_thm;
15151
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
   143
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
   144
15359
8bad1f42fec0 new CLAUSIFY attribute for proof reconstruction with lemmas
paulson
parents: 15151
diff changeset
   145
(** Conversion of a theorem into clauses **)
8bad1f42fec0 new CLAUSIFY attribute for proof reconstruction with lemmas
paulson
parents: 15151
diff changeset
   146
8bad1f42fec0 new CLAUSIFY attribute for proof reconstruction with lemmas
paulson
parents: 15151
diff changeset
   147
fun clausify_rule (A,i) =
8bad1f42fec0 new CLAUSIFY attribute for proof reconstruction with lemmas
paulson
parents: 15151
diff changeset
   148
  standard
8bad1f42fec0 new CLAUSIFY attribute for proof reconstruction with lemmas
paulson
parents: 15151
diff changeset
   149
    (make_meta_clause
15365
611c32b7f6e5 clauses counted from 0
paulson
parents: 15359
diff changeset
   150
      (List.nth(ResAxioms.cnf_axiom A,i)));
15359
8bad1f42fec0 new CLAUSIFY attribute for proof reconstruction with lemmas
paulson
parents: 15151
diff changeset
   151
8bad1f42fec0 new CLAUSIFY attribute for proof reconstruction with lemmas
paulson
parents: 15151
diff changeset
   152
fun clausify_syntax i (x, A) = (x, clausify_rule (A,i));
8bad1f42fec0 new CLAUSIFY attribute for proof reconstruction with lemmas
paulson
parents: 15151
diff changeset
   153
15384
b13eb8a8897d renamed attributes to lower case
paulson
parents: 15365
diff changeset
   154
fun clausify x = syntax ((Scan.lift Args.nat) >> clausify_syntax) x;
15359
8bad1f42fec0 new CLAUSIFY attribute for proof reconstruction with lemmas
paulson
parents: 15151
diff changeset
   155
8bad1f42fec0 new CLAUSIFY attribute for proof reconstruction with lemmas
paulson
parents: 15151
diff changeset
   156
15151
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
   157
(** theory setup **)
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
   158
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
   159
val setup =
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
   160
  [Attrib.add_attributes
15384
b13eb8a8897d renamed attributes to lower case
paulson
parents: 15365
diff changeset
   161
     [("binary", (binary_global, binary_local), "binary resolution"),
b13eb8a8897d renamed attributes to lower case
paulson
parents: 15365
diff changeset
   162
      ("paramod", (paramod_global, paramod_local), "paramodulation"),
b13eb8a8897d renamed attributes to lower case
paulson
parents: 15365
diff changeset
   163
      ("demod", (demod_global, demod_local), "demodulation"),
b13eb8a8897d renamed attributes to lower case
paulson
parents: 15365
diff changeset
   164
      ("factor", (factor, factor), "factoring"),
b13eb8a8897d renamed attributes to lower case
paulson
parents: 15365
diff changeset
   165
      ("clausify", (clausify, clausify), "conversion to clauses")]];
15151
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
   166
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
   167
end
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
   168
end
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
   169
429666b09783 proof reconstruction for external ATPs
paulson
parents:
diff changeset
   170