src/HOL/Tools/ATP/recon_transfer_proof.ML
author paulson
Tue, 19 Apr 2005 18:08:44 +0200
changeset 15774 9df37a0e935d
parent 15739 bb2acfed8212
child 15782 a1863ea9052b
permissions -rw-r--r--
more tidying of libraries in Reconstruction
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
     1
(******************)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
     2
(* complete later *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
     3
(******************)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
     4
15684
5ec4d21889d6 Reconstruction code, now packaged to avoid name clashes
paulson
parents: 15658
diff changeset
     5
structure Recon_Transfer =
5ec4d21889d6 Reconstruction code, now packaged to avoid name clashes
paulson
parents: 15658
diff changeset
     6
struct
5ec4d21889d6 Reconstruction code, now packaged to avoid name clashes
paulson
parents: 15658
diff changeset
     7
5ec4d21889d6 Reconstruction code, now packaged to avoid name clashes
paulson
parents: 15658
diff changeset
     8
open Recon_Parse
5ec4d21889d6 Reconstruction code, now packaged to avoid name clashes
paulson
parents: 15658
diff changeset
     9
infixr 8 ++; infixr 7 >>; infixr 6 ||;
5ec4d21889d6 Reconstruction code, now packaged to avoid name clashes
paulson
parents: 15658
diff changeset
    10
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    11
fun not_newline ch = not (ch = "\n");
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    12
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    13
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    14
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    15
(* Versions that include type information *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    16
 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    17
fun string_of_thm thm = let val _ = set show_sorts
15697
681bcb7f0389 removal of Main and other tidying up
paulson
parents: 15684
diff changeset
    18
                                val str = string_of_thm thm
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    19
                                val no_returns =List.filter not_newline (explode str)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    20
                                val _ = reset show_sorts
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    21
                            in 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    22
                                implode no_returns
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    23
                            end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    24
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    25
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    26
fun thm_of_string str = let val _ = set show_sorts
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    27
                                val term = read str
15684
5ec4d21889d6 Reconstruction code, now packaged to avoid name clashes
paulson
parents: 15658
diff changeset
    28
                                val propterm = HOLogic.mk_Trueprop term
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    29
                                val cterm = cterm_of Mainsign propterm
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    30
                                val _ = reset show_sorts
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    31
                            in
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    32
                                assume cterm
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    33
                            end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    34
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    35
(* check separate args in the watcher program for separating strings with a * or ; or something *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    36
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    37
fun clause_strs_to_string [] str = str
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    38
|   clause_strs_to_string (x::xs) str = clause_strs_to_string xs (str^x^"%")
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    39
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    40
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    41
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    42
fun thmvars_to_string [] str = str
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    43
|   thmvars_to_string (x::xs) str = thmvars_to_string xs (str^x^"%")
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    44
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    45
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    46
fun proofstep_to_string Axiom = "Axiom()"
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    47
|   proofstep_to_string  (Binary ((a,b), (c,d)))= "Binary"^"("^"("^(string_of_int a)^","^(string_of_int b)^")"^","^"("^(string_of_int c)^","^(string_of_int d)^")"^")"
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    48
|   proofstep_to_string (Factor (a,b,c)) = "Factor"^"("^(string_of_int a)^","^(string_of_int b)^","^(string_of_int c)^")"
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    49
|   proofstep_to_string  (Para ((a,b), (c,d)))= "Para"^"("^"("^(string_of_int a)^","^(string_of_int b)^")"^","^"("^(string_of_int c)^","^(string_of_int d)^")"^")"
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    50
|   proofstep_to_string  (MRR ((a,b), (c,d)))= "MRR"^"("^"("^(string_of_int a)^","^(string_of_int b)^")"^","^"("^(string_of_int c)^","^(string_of_int d)^")"^")"
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    51
|   proofstep_to_string (Rewrite((a,b),(c,d))) = "Rewrite"^"("^"("^(string_of_int a)^","^(string_of_int b)^")"^","^"("^(string_of_int c)^","^(string_of_int d)^")"^")"
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    52
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    53
fun list_to_string [] liststr = liststr
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    54
|   list_to_string (x::[]) liststr = liststr^(string_of_int x)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    55
|   list_to_string (x::xs) liststr = list_to_string xs (liststr^(string_of_int x)^",")
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    56
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    57
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    58
fun proof_to_string (num,(step,clause_strs, thmvars)) = (string_of_int num)^(proofstep_to_string step)^"["^(clause_strs_to_string clause_strs "")^"]"^"["^(thmvars_to_string thmvars "")^"]"
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    59
 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    60
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    61
fun proofs_to_string [] str = str
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    62
|   proofs_to_string (x::xs) str = let val newstr = proof_to_string x 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    63
                                   in
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    64
                                       proofs_to_string xs (str^newstr)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    65
                                   end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    66
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    67
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    68
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    69
fun init_proofstep_to_string (num, step, clause_strs) = (string_of_int num)^" "^(proofstep_to_string step)^" "^(clause_strs_to_string clause_strs "")^" "
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    70
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    71
fun init_proofsteps_to_string [] str = str
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    72
|   init_proofsteps_to_string (x::xs) str = let val newstr = init_proofstep_to_string x 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    73
                                   in
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    74
                                       init_proofsteps_to_string xs (str^newstr)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    75
                                   end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    76
  
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    77
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    78
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    79
(*** get a string representing the Isabelle ordered axioms ***)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    80
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    81
fun origAx_to_string (num,(meta,thmvars)) =let val clause_strs = get_meta_lits_bracket meta
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    82
                                         in
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    83
                                            (string_of_int num)^"OrigAxiom()"^"["^(clause_strs_to_string clause_strs "")^"]"^"["^(thmvars_to_string thmvars "")^"]"
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    84
                                         end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    85
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    86
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    87
fun  origAxs_to_string [] str = str
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    88
|   origAxs_to_string (x::xs) str = let val newstr = origAx_to_string x 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    89
                                   in
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    90
                                       origAxs_to_string xs (str^newstr)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    91
                                   end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    92
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    93
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    94
(*** get a string representing the Isabelle ordered axioms not used in the spass proof***)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    95
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    96
fun extraAx_to_string (num, (meta,thmvars)) = let val clause_strs = get_meta_lits_bracket meta
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    97
                                           in
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    98
                                              (string_of_int num)^"ExtraAxiom()"^"["^(clause_strs_to_string clause_strs "")^"]"^"["^(thmvars_to_string thmvars "")^"]"
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    99
                                           end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   100
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   101
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   102
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   103
fun  extraAxs_to_string [] str = str
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   104
|   extraAxs_to_string (x::xs) str = let val newstr = extraAx_to_string x 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   105
                                   in
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   106
                                       extraAxs_to_string xs (str^newstr)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   107
                                   end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   108
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   109
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   110
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   111
fun is_axiom ( num:int,Axiom, str) = true
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   112
|   is_axiom (num, _,_) = false
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   113
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   114
fun get_init_axioms xs = List.filter (is_axiom) ( xs)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   115
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   116
fun get_step_nums [] nums = nums
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   117
|   get_step_nums (( num:int,Axiom, str)::xs) nums = get_step_nums xs (nums@[num])
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   118
15774
9df37a0e935d more tidying of libraries in Reconstruction
paulson
parents: 15739
diff changeset
   119
exception Noassoc;
9df37a0e935d more tidying of libraries in Reconstruction
paulson
parents: 15739
diff changeset
   120
9df37a0e935d more tidying of libraries in Reconstruction
paulson
parents: 15739
diff changeset
   121
fun assoc_snd a [] = raise Noassoc
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   122
  | assoc_snd a ((x, y)::t) = if a = y then x else assoc_snd a t;
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   123
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   124
(* change to be something using check_order  instead of a = y --> returns true if ASSERTION not raised in checkorder, false otherwise *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   125
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   126
(*fun get_assoc_snds [] xs assocs= assocs
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   127
|   get_assoc_snds (x::xs) ys assocs = get_assoc_snds xs ys (assocs@[((assoc_snd x ys))])
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   128
*)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   129
(*FIX - should this have vars in it? *)
15774
9df37a0e935d more tidying of libraries in Reconstruction
paulson
parents: 15739
diff changeset
   130
fun there_out_of_order xs ys = (checkorder xs ys [] ([],[],[]); true) 
9df37a0e935d more tidying of libraries in Reconstruction
paulson
parents: 15739
diff changeset
   131
                               handle _ => false
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   132
15774
9df37a0e935d more tidying of libraries in Reconstruction
paulson
parents: 15739
diff changeset
   133
fun assoc_out_of_order a [] = raise Noassoc
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   134
|   assoc_out_of_order a ((b,c)::t) = if there_out_of_order a c then b else assoc_out_of_order a t;
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   135
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   136
fun get_assoc_snds [] xs assocs= assocs
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   137
|   get_assoc_snds (x::xs) ys assocs = get_assoc_snds xs ys (assocs@[((assoc_out_of_order x ys))])
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   138
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   139
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   140
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   141
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   142
fun add_if_not_inlist [] xs newlist = newlist
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   143
|   add_if_not_inlist (y::ys) xs newlist = if (not (inlist y xs)) then 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   144
                                      add_if_not_inlist ys xs (y::newlist)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   145
                                        else add_if_not_inlist ys xs (newlist)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   146
15700
970e0293dfb3 tweaks mainly to achieve sml/nj compatibility
paulson
parents: 15697
diff changeset
   147
(*Flattens a list of list of strings to one string*)
970e0293dfb3 tweaks mainly to achieve sml/nj compatibility
paulson
parents: 15697
diff changeset
   148
fun onestr ls = String.concat (map String.concat ls);
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   149
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   150
fun thmstrings [] str = str
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   151
|   thmstrings (x::xs) str = thmstrings xs (str^(string_of_thm x))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   152
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   153
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   154
 fun get_axioms_used proof_steps thmstring = let 
15658
2edb384bf61f watcher.ML and watcher.sig changed. Debug files now write to tmp.
quigley
parents: 15642
diff changeset
   155
                                             val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_ax_thmstr")))                                                                      
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   156
                                             val _ = TextIO.output (outfile, thmstring)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   157
                                             
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   158
                                             val _ =  TextIO.closeOut outfile
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   159
                                            (* not sure why this is necessary again, but seems to be *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   160
                                            val _=  (print_mode := (Library.gen_rems (op =) (! print_mode, ["xsymbols", "symbols"])))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   161
                                            val axioms = get_init_axioms proof_steps
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   162
                                            val step_nums = get_step_nums axioms []
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   163
                                            val thm = thm_of_string thmstring
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   164
                                            val clauses = make_clauses [thm]
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   165
                                            
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   166
                                            val vars = map thm_vars clauses
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   167
                                           
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   168
                                            val distvars = distinct (fold append vars [])
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   169
                                            val clause_terms = map prop_of clauses  
15739
bb2acfed8212 yet more tidying up: removal of some references to Main
paulson
parents: 15700
diff changeset
   170
                                            val clause_frees = List.concat (map term_frees clause_terms)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   171
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   172
                                            val frees = map lit_string_with_nums clause_frees;
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   173
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   174
                                            val distfrees = distinct frees
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   175
15697
681bcb7f0389 removal of Main and other tidying up
paulson
parents: 15684
diff changeset
   176
                                            val metas = map Meson.make_meta_clause clauses
15684
5ec4d21889d6 Reconstruction code, now packaged to avoid name clashes
paulson
parents: 15658
diff changeset
   177
                                            val ax_strs = map #3 axioms
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   178
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   179
                                            (* literals of -all- axioms, not just those used by spass *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   180
                                            val meta_strs = map get_meta_lits metas
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   181
                                           
15774
9df37a0e935d more tidying of libraries in Reconstruction
paulson
parents: 15739
diff changeset
   182
                                            val metas_and_strs = ListPair.zip (metas,meta_strs)
15658
2edb384bf61f watcher.ML and watcher.sig changed. Debug files now write to tmp.
quigley
parents: 15642
diff changeset
   183
                                             val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_clauses")));                                                                       
15700
970e0293dfb3 tweaks mainly to achieve sml/nj compatibility
paulson
parents: 15697
diff changeset
   184
                                             val _ = TextIO.output (outfile, onestr ax_strs)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   185
                                             
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   186
                                             val _ =  TextIO.closeOut outfile
15658
2edb384bf61f watcher.ML and watcher.sig changed. Debug files now write to tmp.
quigley
parents: 15642
diff changeset
   187
                                             val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_metastrs")));                                                                       
15700
970e0293dfb3 tweaks mainly to achieve sml/nj compatibility
paulson
parents: 15697
diff changeset
   188
                                             val _ = TextIO.output (outfile, onestr meta_strs)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   189
                                             val _ =  TextIO.closeOut outfile
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   190
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   191
                                            (* get list of axioms as thms with their variables *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   192
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   193
                                            val ax_metas = get_assoc_snds ax_strs metas_and_strs []
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   194
                                            val ax_vars = map thm_vars ax_metas
15774
9df37a0e935d more tidying of libraries in Reconstruction
paulson
parents: 15739
diff changeset
   195
                                            val ax_with_vars = ListPair.zip (ax_metas,ax_vars)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   196
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   197
                                            (* get list of extra axioms as thms with their variables *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   198
                                            val extra_metas = add_if_not_inlist metas ax_metas []
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   199
                                            val extra_vars = map thm_vars extra_metas
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   200
                                            val extra_with_vars = if (not (extra_metas = []) ) 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   201
                                                                  then
15774
9df37a0e935d more tidying of libraries in Reconstruction
paulson
parents: 15739
diff changeset
   202
 									 ListPair.zip (extra_metas,extra_vars)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   203
                                                                  else
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   204
                                                                         []
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   205
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   206
                                           (* val _=  (print_mode := (Library.gen_rems (op =) (! print_mode, ["xsymbols", "symbols"])))
15658
2edb384bf61f watcher.ML and watcher.sig changed. Debug files now write to tmp.
quigley
parents: 15642
diff changeset
   207
                                           val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_metas")))
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   208
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   209
                                           val _ = TextIO.output (outfile, ((thmstrings ax_metas "")))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   210
                                           val _ =  TextIO.closeOut outfile
15658
2edb384bf61f watcher.ML and watcher.sig changed. Debug files now write to tmp.
quigley
parents: 15642
diff changeset
   211
                                          val foo_metas =  File.sysify_path(File.tmp_path (Path.basic "foo_metas"))
2edb384bf61f watcher.ML and watcher.sig changed. Debug files now write to tmp.
quigley
parents: 15642
diff changeset
   212
                                          val foo_metas2 =   File.sysify_path(File.tmp_path (Path.basic "foo_metas2"))
2edb384bf61f watcher.ML and watcher.sig changed. Debug files now write to tmp.
quigley
parents: 15642
diff changeset
   213
                                            val execperl = Unix.execute("/usr/bin/perl", ["remchars.pl", "  <", foo_metas, "  >", foo_metas2])
2edb384bf61f watcher.ML and watcher.sig changed. Debug files now write to tmp.
quigley
parents: 15642
diff changeset
   214
                                         val infile = TextIO.openIn(File.sysify_path(File.tmp_path (Path.basic "foo_metas2")))
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   215
                                        val ax_metas_str = TextIO.inputLine (infile)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   216
                                        val _ = TextIO.closeIn infile
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   217
                                           val _= (print_mode := (["xsymbols", "symbols"] @ ! print_mode))*)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   218
                                           
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   219
                                         in
15774
9df37a0e935d more tidying of libraries in Reconstruction
paulson
parents: 15739
diff changeset
   220
                                            (distfrees,distvars, extra_with_vars,ax_with_vars, (ListPair.zip (step_nums,ax_metas)))
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   221
                                         end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   222
                                        
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   223
fun thmstrings [] str = str
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   224
|   thmstrings (x::xs) str = thmstrings xs (str^(string_of_thm x))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   225
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   226
fun numclstr (vars, []) str = str
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   227
|   numclstr ( vars, ((num, thm)::rest)) str = let val newstr = str^(string_of_int num)^" "^(string_of_thm thm)^" "
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   228
                               in
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   229
                                   numclstr  (vars,rest) newstr
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   230
                               end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   231
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   232
(*
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   233
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   234
val proofstr = "Did parsing on Here is a proof with depth 4, length 9 :\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   235
\1[0:Inp] || v_P(tconst_fun(typ__da_a,tconst_bool),v_x)*+ -> v_P(tconst_fun(typ__da_a,tconst_bool),U)*.\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   236
\3[0:Inp] || v_P(tconst_fun(typ__da_a,tconst_bool),U)*+ -> v_P(tconst_fun(typ__da_a,tconst_bool),v_x)*.\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   237
\5[0:Inp] ||  -> v_P(tconst_fun(typ__da_a,tconst_bool),U)* v_P(tconst_fun(typ__da_a,tconst_bool),v_xa)*.\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   238
\7[0:Inp] || v_P(tconst_fun(typ__da_a,tconst_bool),U)*+ v_P(tconst_fun(typ__da_a,tconst_bool),v_xb)* -> .\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   239
\9[0:Fac:5.0,5.1] ||  -> v_P(tconst_fun(typ__da_a,tconst_bool),v_xa)*.\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   240
\10[0:Res:9.0,3.0] ||  -> v_P(tconst_fun(typ__da_a,tconst_bool),v_x)*.\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   241
\11[0:Res:10.0,1.0] ||  -> v_P(tconst_fun(typ__da_a,tconst_bool),U)*.\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   242
\12[0:Fac:7.0,7.1] || v_P(tconst_fun(typ__da_a,tconst_bool),v_xb)* -> .\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   243
\14[0:Res:11.0,12.0] ||  -> .\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   244
\Formulae used in the proof :"
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   245
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   246
*)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   247
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   248
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   249
fun addvars  c (a,b)  = (a,b,c)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   250
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   251
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   252
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   253
(*********************************************************************)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   254
(* Pass in spass string of proof and string version of isabelle goal *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   255
(* Get out reconstruction steps as a string to be sent to Isabelle   *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   256
(*********************************************************************)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   257
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   258
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   259
(*
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   260
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   261
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   262
val proofstr = "Here is a proof with depth 2, length 5 :\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   263
\1[0:Inp] ||  -> v_P(tconst_fun(typ__asc39_a,tconst_bool),U)*.\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   264
\3[0:Inp] || v_Q(tconst_fun(typ__asc39_a,tconst_bool),U)* -> .\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   265
\5[0:Inp] || v_P(tconst_fun(typ__asc39_a,tconst_bool),v_x)* -> v_Q(tconst_fun(typ__asc39_a,tconst_bool),v_xa).\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   266
\7[0:Res:1.0,5.0] ||  -> v_Q(tconst_fun(typ__asc39_a,tconst_bool),v_xa)*.\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   267
\9[0:Res:7.0,3.0] ||  -> .\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   268
\Formulae used in the proof :"
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   269
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   270
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   271
val proofstr = "Here is a proof with depth 4, length 9 :\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   272
\1[0:Inp] || v_P(tconst_fun(typ__asc39_a,tconst_bool),v_x)*+ -> v_P(tconst_fun(typ__asc39_a,tconst_bool),U)*.\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   273
\3[0:Inp] || v_P(tconst_fun(typ__asc39_a,tconst_bool),U)*+ -> v_P(tconst_fun(typ__asc39_a,tconst_bool),v_x)*.\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   274
\5[0:Inp] ||  -> v_P(tconst_fun(typ__asc39_a,tconst_bool),U)* v_P(tconst_fun(typ__asc39_a,tconst_bool),v_xa)*.\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   275
\7[0:Inp] || v_P(tconst_fun(typ__asc39_a,tconst_bool),U)*+ v_P(tconst_fun(typ__asc39_a,tconst_bool),v_xb)* -> .\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   276
\9[0:Fac:5.0,5.1] ||  -> v_P(tconst_fun(typ__asc39_a,tconst_bool),v_xa)*.\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   277
\10[0:Res:9.0,3.0] ||  -> v_P(tconst_fun(typ__asc39_a,tconst_bool),v_x)*.\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   278
\11[0:Res:10.0,1.0] ||  -> v_P(tconst_fun(typ__asc39_a,tconst_bool),U)*.\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   279
\12[0:Fac:7.0,7.1] || v_P(tconst_fun(typ__asc39_a,tconst_bool),v_xb)* -> .\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   280
\14[0:Res:11.0,12.0] ||  -> .\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   281
\Formulae used in the proof :";
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   282
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   283
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   284
val thmstring = " (~ (P::'a::type => bool) (x::'a::type) | P (U::'a::type)) & (~ (P::'a::type => bool) (U::'a::type) | P (x::'a::type)) & ((P::'a::type => bool) (xa::'a::type) | P (U::'a::type)) & (~ (P::'a::type => bool) (U::'a::type) | ~ P (xb::'a::type))";
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   285
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   286
val thmstring = "(ALL xb::'a::type.   (~ (P::'a::type => bool) ((x::'a::type => 'a::type) xb) |    (Q::'a::type => bool) ((xa::'a::type => 'a::type) xb)) &   P xb & ~ Q xb)"
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   287
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   288
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   289
val thmstring ="(ALL xb::'a::type.   (~ (P::'a::type => bool) ((x::'a::type => 'a::type) xb) |    (Q::'a::type => bool) ((xa::'a::type => 'a::type) xb)) &   P xb & ~ Q xb)"
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   290
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   291
val proofstr = "Did parsing on Here is a proof with depth 2, length 5 :\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   292
\1[0:Inp] ||  -> v_P(tconst_fun(typ__asc39_a,tconst_bool),U)*.\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   293
\3[0:Inp] || v_Q(tconst_fun(typ__asc39_a,tconst_bool),U)* -> .\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   294
\5[0:Inp] || v_P(tconst_fun(typ__asc39_a,tconst_bool),v_x(tconst_fun(typ__asc39_a,typ__asc39_a),U))* -> v_Q(tconst_fun(typ__asc39_a,tconst_bool),v_xa(tconst_fun(typ__asc39_a,typ__asc39_a),U)).\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   295
\7[0:Res:1.0,5.0] ||  -> v_Q(tconst_fun(typ__asc39_a,tconst_bool),v_xa(tconst_fun(typ__asc39_a,typ__asc39_a),U))*.\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   296
\9[0:Res:7.0,3.0] ||  -> .\
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   297
\Formulae used in the proof :";
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   298
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   299
*)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   300
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   301
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   302
fun spassString_to_reconString proofstr thmstring = 
15658
2edb384bf61f watcher.ML and watcher.sig changed. Debug files now write to tmp.
quigley
parents: 15642
diff changeset
   303
                                              let val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "thmstringfile")));                                                                                      val _= warning("proofstr is: "^proofstr);
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   304
                                                  val _ = warning ("thmstring is: "^thmstring);
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   305
                                                  val _ = TextIO.output (outfile, (thmstring))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   306
                                                  val _ =  TextIO.closeOut outfile
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   307
                                                  val proofextract = extract_proof proofstr
15739
bb2acfed8212 yet more tidying up: removal of some references to Main
paulson
parents: 15700
diff changeset
   308
                                                  val tokens = #1(lex proofextract)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   309
                                                     
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   310
                                              (***********************************)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   311
                                              (* parse spass proof into datatype *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   312
                                              (***********************************)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   313
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   314
                                                  val proof_steps1 = parse tokens
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   315
                                                  val proof_steps = just_change_space proof_steps1
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   316
15658
2edb384bf61f watcher.ML and watcher.sig changed. Debug files now write to tmp.
quigley
parents: 15642
diff changeset
   317
                                                  val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_parse")));                                                                                          val _ = TextIO.output (outfile, ("Did parsing on "^proofstr))
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   318
                                                  val _ =  TextIO.closeOut outfile
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   319
                                                
15658
2edb384bf61f watcher.ML and watcher.sig changed. Debug files now write to tmp.
quigley
parents: 15642
diff changeset
   320
                                                  val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_thmstring_at_parse")));                                                                             val _ = TextIO.output (outfile, ("Parsing for thmstring: "^thmstring))
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   321
                                                  val _ =  TextIO.closeOut outfile
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   322
                                              (************************************)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   323
                                              (* recreate original subgoal as thm *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   324
                                              (************************************)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   325
                                                
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   326
                                                  (* get axioms as correctly numbered clauses w.r.t. the Spass proof *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   327
                                                  val (frees,vars,extra_with_vars ,ax_with_vars,numcls) = get_axioms_used proof_steps thmstring
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   328
                                                  
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   329
                                                  (*val numcls_string = numclstr ( vars, numcls) ""*)
15658
2edb384bf61f watcher.ML and watcher.sig changed. Debug files now write to tmp.
quigley
parents: 15642
diff changeset
   330
                                                  val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_axiom")));                                                                            val _ = TextIO.output (outfile,"got axioms")
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   331
                                                  val _ =  TextIO.closeOut outfile
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   332
                                                    
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   333
                                              (************************************)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   334
                                              (* translate proof                  *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   335
                                              (************************************)
15658
2edb384bf61f watcher.ML and watcher.sig changed. Debug files now write to tmp.
quigley
parents: 15642
diff changeset
   336
                                                  val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_steps")));                                                          val _ = TextIO.output (outfile, ("about to translate proof, steps: "^(init_proofsteps_to_string proof_steps "")))
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   337
                                                  val _ =  TextIO.closeOut outfile
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   338
                                                  val (newthm,proof) = translate_proof numcls  proof_steps vars
15658
2edb384bf61f watcher.ML and watcher.sig changed. Debug files now write to tmp.
quigley
parents: 15642
diff changeset
   339
                                                  val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_steps2")));                                                                         val _ = TextIO.output (outfile, ("translated proof, steps: "^(init_proofsteps_to_string proof_steps "")))
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   340
                                                  val _ =  TextIO.closeOut outfile
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   341
                                              (***************************************************)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   342
                                              (* transfer necessary steps as strings to Isabelle *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   343
                                              (***************************************************)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   344
                                                  (* turn the proof into a string *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   345
                                                  val reconProofStr = proofs_to_string proof ""
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   346
                                                  (* do the bit for the Isabelle ordered axioms at the top *)
15739
bb2acfed8212 yet more tidying up: removal of some references to Main
paulson
parents: 15700
diff changeset
   347
                                                  val ax_nums = map #1 numcls
bb2acfed8212 yet more tidying up: removal of some references to Main
paulson
parents: 15700
diff changeset
   348
                                                  val ax_strs = map get_meta_lits_bracket (map #2 numcls)
15774
9df37a0e935d more tidying of libraries in Reconstruction
paulson
parents: 15739
diff changeset
   349
                                                  val numcls_strs = ListPair.zip (ax_nums,ax_strs)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   350
                                                  val num_cls_vars =  map (addvars vars) numcls_strs;
15774
9df37a0e935d more tidying of libraries in Reconstruction
paulson
parents: 15739
diff changeset
   351
                                                  val reconIsaAxStr = origAxs_to_string (ListPair.zip (ax_nums,ax_with_vars)) ""
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   352
                                                  
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   353
                                                  val extra_nums = if (not (extra_with_vars = [])) then (1 upto (length extra_with_vars)) else []
15774
9df37a0e935d more tidying of libraries in Reconstruction
paulson
parents: 15739
diff changeset
   354
                                                  val reconExtraAxStr = extraAxs_to_string ( ListPair.zip (extra_nums,extra_with_vars)) ""
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   355
                                                  val frees_str = "["^(thmvars_to_string frees "")^"]"
15658
2edb384bf61f watcher.ML and watcher.sig changed. Debug files now write to tmp.
quigley
parents: 15642
diff changeset
   356
                                                  val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "reconstringfile")));
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   357
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   358
                                                  val _ = TextIO.output (outfile, (frees_str^reconExtraAxStr^reconIsaAxStr^reconProofStr))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   359
                                                  val _ =  TextIO.closeOut outfile
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   360
                                              in 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   361
                                                   (frees_str^reconExtraAxStr^reconIsaAxStr^reconProofStr)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   362
                                              end
15658
2edb384bf61f watcher.ML and watcher.sig changed. Debug files now write to tmp.
quigley
parents: 15642
diff changeset
   363
                                              handle _ => (let val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_handler")));
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   364
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   365
                                                  val _ = TextIO.output (outfile, ("In exception handler"));
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   366
                                                  val _ =  TextIO.closeOut outfile
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   367
                                              in 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   368
                                                 "Proof found but translation failed!"
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   369
                                              end)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   370
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   371
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   372
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   373
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   374
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   375
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   376
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   377
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   378
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   379
(**********************************************************************************)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   380
(* At other end, want to turn back into datatype so can apply reconstruct_proof.  *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   381
(* This will be done by the signal handler                                        *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   382
(**********************************************************************************)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   383
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   384
(* Parse in the string version of the proof steps for reconstruction *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   385
(* Isar format: cl1 [BINARY 0 cl2 0];cl1 [PARAMOD 0 cl2 0]; cl1 [DEMOD 0 cl2];cl1 [FACTOR 1 2];*)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   386
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   387
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   388
 val term_numstep =
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   389
        (number ++ (a (Other ",")) ++ number) >> (fn (a, (_, c)) => (a, c))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   390
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   391
val extraaxiomstep = (a (Word "ExtraAxiom"))++ (a (Other "(")) ++(a (Other ")"))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   392
            >> (fn (_) => ExtraAxiom)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   393
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   394
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   395
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   396
val origaxiomstep = (a (Word "OrigAxiom"))++ (a (Other "(")) ++(a (Other ")"))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   397
            >> (fn (_) => OrigAxiom)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   398
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   399
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   400
 val axiomstep = (a (Word "Axiom"))++ (a (Other "(")) ++(a (Other ")"))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   401
            >> (fn (_) => Axiom)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   402
     
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   403
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   404
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   405
      
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   406
 val binarystep = (a (Word "Binary")) ++ (a (Other "(")) ++ (a (Other "(")) 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   407
                   ++ term_numstep  ++ (a (Other ")")) ++ (a (Other ","))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   408
                   ++ (a (Other "(")) ++ term_numstep ++ (a (Other ")")) ++ (a (Other ")"))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   409
            >> (fn (_, (_, (_, (c, (_,(_,(_, (e,(_,_))))))))) => Binary (c,e))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   410
      
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   411
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   412
 val parastep = (a (Word "Para")) ++ (a (Other "(")) ++ (a (Other "(")) 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   413
                   ++ term_numstep  ++ (a (Other ")")) ++ (a (Other ","))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   414
                   ++ (a (Other "(")) ++ term_numstep ++ (a (Other ")")) ++ (a (Other ")"))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   415
            >> (fn (_, (_, (_, (c, (_,(_,(_, (e,(_,_))))))))) => Para(c, e))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   416
      
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   417
 val mrrstep = (a (Word "MRR")) ++ (a (Other "(")) ++ (a (Other "(")) 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   418
                   ++ term_numstep  ++ (a (Other ")")) ++ (a (Other ","))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   419
                   ++ (a (Other "(")) ++ term_numstep ++ (a (Other ")")) ++ (a (Other ")"))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   420
            >> (fn (_, (_, (_, (c, (_,(_,(_, (e,(_,_))))))))) => MRR(c, e))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   421
      
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   422
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   423
 val factorstep = (a (Word "Factor")) ++ (a (Other "("))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   424
                    ++ number ++ (a (Other ","))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   425
                       ++ number ++ (a (Other ","))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   426
                       ++ number ++  (a (Other ")"))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   427
                   
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   428
            >> (fn (_, (_, (c, (_, (e,(_,(f,_))))))) =>  Factor (c,e,f))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   429
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   430
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   431
val rewritestep = (a (Word "Rewrite"))  ++ (a (Other "(")) ++ (a (Other "(")) 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   432
                   ++ term_numstep  ++ (a (Other ")")) ++ (a (Other ","))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   433
                   ++ (a (Other "(")) ++ term_numstep ++ (a (Other ")")) ++ (a (Other ")"))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   434
            >> (fn (_, (_, (_, (c, (_,(_,(_, (e,(_,_))))))))) => Rewrite (c,e))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   435
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   436
val obviousstep = (a (Word "Obvious")) ++ (a (Other "(")) 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   437
                   ++ term_numstep  ++ (a (Other ")")) 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   438
            >> (fn (_, (_, (c,_))) => Obvious (c))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   439
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   440
 val methodstep = extraaxiomstep || origaxiomstep || axiomstep ||binarystep || factorstep|| parastep || mrrstep || rewritestep || obviousstep
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   441
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   442
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   443
 val number_list_step =
15739
bb2acfed8212 yet more tidying up: removal of some references to Main
paulson
parents: 15700
diff changeset
   444
        ( number ++ many ((a (Other ",") ++ number)>> #2))
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   445
        >> (fn (a,b) => (a::b))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   446
        
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   447
 val numberlist_step = a (Other "[")  ++ a (Other "]")
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   448
                        >>(fn (_,_) => ([]:int list))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   449
                       || a (Other "[") ++ number_list_step ++ a (Other "]")
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   450
                        >>(fn (_,(a,_)) => a)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   451
                    
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   452
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   453
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   454
(** change this to allow P (x U) *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   455
 fun arglist_step input = ( word ++ many  word >> (fn (a, b) => (a^" "^(implode_with_space b)))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   456
                           ||word >> (fn (a) => (a)))input
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   457
                
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   458
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   459
fun literal_step input = (word ++ a (Other "(") ++ arglist_step ++  a (Other ")")
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   460
                                          >>(fn (a, (b, (c,d))) => (a^" ("^(c)^")"))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   461
                        || arglist_step >> (fn (a) => (a)))input
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   462
                           
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   463
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   464
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   465
(* fun term_step input = (a (Other "~") ++ arglist_step ++ a (Other "%")>> (fn (a,(b,c)) => ("~ "^b))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   466
                     ||  arglist_step ++ a (Other "%")>> (fn (a,b) => a ))input
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   467
*)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   468
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   469
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   470
 fun term_step input = (a (Other "~") ++ literal_step ++ a (Other "%")>> (fn (a,(b,c)) => ("~ "^b))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   471
                     ||  literal_step ++ a (Other "%")>> (fn (a,b) => a ))input
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   472
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   473
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   474
         
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   475
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   476
 val term_list_step =
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   477
        (  term_step ++ many ( term_step))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   478
        >> (fn (a,b) => (a::b))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   479
        
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   480
 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   481
val term_lists_step = a (Other "[")  ++ a (Other "]")
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   482
                        >>(fn (_,_) => ([]:string list))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   483
                       || a (Other "[") ++ term_list_step ++ a (Other "]")
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   484
                        >>(fn (_,(a,_)) => a)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   485
                     
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   486
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   487
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   488
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   489
fun anytoken_step input  = (word>> (fn (a) => a)  ) input
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   490
                       handle NOPARSE_WORD => (number>> (fn (a) => string_of_int a)  ) input
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   491
                      handle NOPARSE_NUMBER => (other_char >> (fn(a) => a)) input
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   492
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   493
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   494
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   495
fun goalstring_step input= (anytoken_step ++ many (anytoken_step )
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   496
                  >> (fn (a,b) =>  (a^" "^(implode b)))) input
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   497
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   498
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   499
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   500
 val linestep = number ++ methodstep ++ term_lists_step ++ term_lists_step
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   501
                >> (fn (a, (b, (c,d))) => (a,(b,c,d)))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   502
    
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   503
 val lines_step = many linestep
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   504
15739
bb2acfed8212 yet more tidying up: removal of some references to Main
paulson
parents: 15700
diff changeset
   505
 val alllines_step = (term_lists_step ++ lines_step ) ++ finished >> #1
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   506
    
15739
bb2acfed8212 yet more tidying up: removal of some references to Main
paulson
parents: 15700
diff changeset
   507
 val parse_step = #1 o alllines_step
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   508
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   509
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   510
 (*
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   511
val reconstr ="[P%x%xa%xb%]1OrigAxiom()[P x%~ P U%][U%]3OrigAxiom()[P U%~ P x%][U%]5OrigAxiom()[~ P xa%~ P U%][U%]7OrigAxiom()[P U%P xb%][U%]1Axiom()[P x%~ P U%][U%]3Axiom()[P U%~ P x%][U%]5Axiom()[~ P U%~ P xa%][U%]7Axiom()[P U%P xb%][U%]9Factor(5,0,1)[~ P xa%][]10Binary((9,0),(3,0))[~ P x%][]11Binary((10,0),(1,0))[~ P U%][U%]12Factor(7,0,1)[P xb%][]14Binary((11,0),(12,0))[][]%(EX x::'a::type. ALL y::'a::type. (P::'a::type => bool) x = P y) -->(EX x::'a::type. P x) = (ALL y::'a::type. P y)"
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   512
*)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   513
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   514
(************************************************************)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   515
(* Construct an Isar style proof from a list of proof steps *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   516
(************************************************************)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   517
(* want to assume all axioms, then do haves for the other clauses*)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   518
(* then show for the last step *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   519
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   520
(* replace ~ by not here *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   521
fun change_nots [] = []
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   522
|   change_nots (x::xs) = if x = "~" 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   523
                          then 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   524
                             ["\\", "<", "n", "o", "t", ">"]@(change_nots xs)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   525
                          else (x::(change_nots xs))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   526
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   527
(*
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   528
fun clstrs_to_string [] str = str
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   529
|   clstrs_to_string (x::[]) str = str^x
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   530
|   clstrs_to_string (x::xs) str = clstrs_to_string xs (str^(x^"; "))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   531
*)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   532
fun clstrs_to_string [] str = implode (change_nots (explode str))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   533
|   clstrs_to_string (x::[]) str = implode (change_nots (explode (str^x)))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   534
|   clstrs_to_string (x::xs) str = implode (change_nots (explode (clstrs_to_string xs (str^(x^"; ")))))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   535
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   536
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   537
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   538
fun thmvars_to_quantstring [] str = str
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   539
|   thmvars_to_quantstring (x::[]) str =str^x^". "
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   540
|   thmvars_to_quantstring (x::xs) str = thmvars_to_quantstring xs (str^(x^" "))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   541
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   542
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   543
fun clause_strs_to_isar clstrs [] =  "\"\\<lbrakk>"^(clstrs_to_string clstrs "")^"\\<rbrakk> "^" \\<Longrightarrow> False\""
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   544
|   clause_strs_to_isar clstrs thmvars = "\"\\<And>"^(thmvars_to_quantstring thmvars "")^"\\<lbrakk>"^(clstrs_to_string clstrs "")^"\\<rbrakk> "^"\\<Longrightarrow> False\""
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   545
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   546
fun frees_to_string [] str = implode (change_nots (explode str))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   547
|   frees_to_string (x::[]) str = implode (change_nots (explode (str^x)))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   548
|   frees_to_string  (x::xs) str = implode (change_nots (explode (frees_to_string xs (str^(x^" ")))))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   549
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   550
fun frees_to_isar_str [] =  ""
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   551
|   frees_to_isar_str  clstrs = (frees_to_string clstrs "")
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   552
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   553
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   554
(***********************************************************************)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   555
(* functions for producing assumptions for the Isabelle ordered axioms *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   556
(***********************************************************************)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   557
(*val str = "[P%x%xa%xb%]1OrigAxiom()[P x%~ P U%][U%]3OrigAxiom()[P U%~ P x%][U%]5OrigAxiom()[~ P xa%~ P U%][U%]7OrigAxiom()[P U%P xb%][U%]1Axiom()[P x%~ P U%][U%]3Axiom()[P U%~ P x%][U%]5Axiom()[~ P U%~ P xa%][U%]7Axiom()[P U%P xb%][U%]9Factor(5,0,1)[~ P xa%][]10Binary((9,0),(3,0))[~ P x%][]11Binary((10,0),(1,0))[~ P U%][U%]12Factor(7,0,1)[P xb%][]14Binary((11,0),(12,0))[][]";       
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   558
num, rule, clausestrs, vars*)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   559
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   560
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   561
(* assume the extra clauses - not used in Spass proof *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   562
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   563
fun is_extraaxiom_step ( num:int,(ExtraAxiom, str, tstr)) = true
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   564
|   is_extraaxiom_step (num, _) = false
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   565
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   566
fun get_extraaxioms xs = List.filter (is_extraaxiom_step) ( xs)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   567
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   568
fun assume_isar_extraaxiom [] str  = str
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   569
|   assume_isar_extraaxiom ((numb,(step, clstr, thmvars))::xs) str  = assume_isar_extraaxiom xs (str^"and cl"^(string_of_int numb)^"': "^(clause_strs_to_isar clstr thmvars)^"\n " )
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   570
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   571
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   572
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   573
fun assume_isar_extraaxioms  [] = ""
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   574
|assume_isar_extraaxioms ((numb,(step, clstrs, thmstrs))::xs) = let val str = "assume cl"^(string_of_int numb)^"': "^(clause_strs_to_isar clstrs thmstrs)^"\n" 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   575
                                         in
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   576
                                             assume_isar_extraaxiom xs str
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   577
                                         end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   578
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   579
(* assume the Isabelle ordered clauses *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   580
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   581
fun is_origaxiom_step ( num:int,(OrigAxiom, str, tstr)) = true
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   582
|   is_origaxiom_step (num, _) = false
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   583
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   584
fun get_origaxioms xs = List.filter (is_origaxiom_step) ( xs)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   585
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   586
fun assume_isar_origaxiom [] str  = str
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   587
|   assume_isar_origaxiom ((numb,(step, clstr, thmvars))::xs) str  = assume_isar_origaxiom xs (str^"and cl"^(string_of_int numb)^"': "^(clause_strs_to_isar clstr thmvars)^"\n " )
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   588
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   589
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   590
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   591
fun assume_isar_origaxioms ((numb,(step, clstrs, thmstrs))::xs) = let val str = "assume cl"^(string_of_int numb)^"': "^(clause_strs_to_isar clstrs thmstrs)^"\n" 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   592
                                         in
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   593
                                             assume_isar_origaxiom xs str
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   594
                                         end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   595
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   596
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   597
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   598
fun is_axiom_step ( num:int,(Axiom, str, tstr)) = true
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   599
|   is_axiom_step (num, _) = false
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   600
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   601
fun get_axioms xs = List.filter  (is_axiom_step) ( xs)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   602
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   603
fun have_isar_axiomline (numb,(step, clstrs, thmstrs))="have cl"^(string_of_int numb)^": "^(clause_strs_to_isar clstrs thmstrs)^"\n"
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   604
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   605
fun  by_isar_axiomline (numb,(step, clstrs, thmstrs))="by (rule cl"^ (string_of_int numb)^"') \n"
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   606
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   607
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   608
fun isar_axiomline (numb, (step, clstrs, thmstrs))  = (have_isar_axiomline (numb,(step,clstrs, thmstrs )))^( by_isar_axiomline(numb,(step,clstrs, thmstrs )) )
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   609
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   610
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   611
fun isar_axiomlines [] str = str
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   612
|   isar_axiomlines (x::xs) str = isar_axiomlines xs (str^(isar_axiomline x))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   613
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   614
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   615
fun have_isar_line (numb,(step, clstrs, thmstrs))="have cl"^(string_of_int numb)^": "^(clause_strs_to_isar clstrs thmstrs)^"\n"
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   616
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   617
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   618
fun  by_isar_line ((Binary ((a,b), (c,d))))="by(rule cl"^
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   619
                                                  (string_of_int a)^" [BINARY "^(string_of_int b)^" "^"cl"^
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   620
                                                  (string_of_int c)^" "^(string_of_int d)^"])"^"\n"
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   621
|   by_isar_line ( (Para ((a,b), (c,d)))) ="by (rule cl"^
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   622
                                                  (string_of_int a)^" [PARAMOD "^(string_of_int b)^" "^"cl"^
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   623
                                                  (string_of_int c)^" "^(string_of_int d)^"])"^"\n"
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   624
|   by_isar_line ((Factor ((a,b,c)))) =    "by (rule cl"^(string_of_int a)^" [FACTOR "^(string_of_int b)^" "^
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   625
                                                  (string_of_int c)^" "^"])"^"\n"
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   626
|   by_isar_line ( (Rewrite ((a,b),(c,d)))) =  "by (rule cl"^(string_of_int a)^" [DEMOD "^(string_of_int b)^" "^
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   627
                                                  (string_of_int c)^" "^(string_of_int d)^" "^"])"^"\n"
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   628
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   629
|   by_isar_line ( (Obvious ((a,b)))) =  "by (rule cl"^(string_of_int a)^" [OBVIOUS "^(string_of_int b)^" ])"^"\n"
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   630
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   631
fun isar_line (numb, (step, clstrs, thmstrs))  = (have_isar_line (numb,(step,clstrs, thmstrs )))^( by_isar_line step)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   632
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   633
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   634
fun isar_lines [] str = str
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   635
|   isar_lines (x::xs) str = isar_lines xs (str^(isar_line x))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   636
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   637
fun last_isar_line (numb,( step, clstrs,thmstrs)) = "show \"False\"\n"^(by_isar_line step)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   638
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   639
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   640
fun to_isar_proof (frees, xs, goalstring) = let val extraaxioms = get_extraaxioms xs
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   641
                           val extraax_num = length extraaxioms
15774
9df37a0e935d more tidying of libraries in Reconstruction
paulson
parents: 15739
diff changeset
   642
                           val origaxioms_and_steps = Library.drop (extraax_num, xs)  
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   643
                          
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   644
  
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   645
                           val origaxioms = get_origaxioms origaxioms_and_steps
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   646
                           val origax_num = length origaxioms
15774
9df37a0e935d more tidying of libraries in Reconstruction
paulson
parents: 15739
diff changeset
   647
                           val axioms_and_steps = Library.drop (origax_num + extraax_num, xs)  
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   648
                           val axioms = get_axioms axioms_and_steps
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   649
                           
15774
9df37a0e935d more tidying of libraries in Reconstruction
paulson
parents: 15739
diff changeset
   650
                           val steps = Library.drop (origax_num, axioms_and_steps)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   651
                           val firststeps = butlast steps
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   652
                           val laststep = last steps
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   653
                           val goalstring = implode(butlast(explode goalstring))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   654
                        
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   655
                           val isar_proof = 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   656
                           ("show \""^goalstring^"\"\n")^
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   657
                           ("proof (rule ccontr,skolemize, make_clauses) \n")^
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   658
                           ("fix "^(frees_to_isar_str frees)^"\n")^
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   659
                           (assume_isar_extraaxioms extraaxioms)^
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   660
                           (assume_isar_origaxioms origaxioms)^
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   661
                           (isar_axiomlines axioms "")^
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   662
                           (isar_lines firststeps "")^
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   663
                           (last_isar_line laststep)^
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   664
                           ("qed")
15658
2edb384bf61f watcher.ML and watcher.sig changed. Debug files now write to tmp.
quigley
parents: 15642
diff changeset
   665
                          val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "isar_proof_file")));
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   666
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   667
                                                  val _ = TextIO.output (outfile, isar_proof)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   668
                                                  val _ =  TextIO.closeOut outfile
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   669
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   670
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   671
                       in
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   672
                           isar_proof
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   673
                       end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   674
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   675
(* get fix vars from axioms - all Frees *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   676
(* check each clause for meta-vars and /\ over them at each step*)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   677
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   678
(*******************************************************)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   679
(* This assumes the thm list  "numcls" is still there  *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   680
(* In reality, should probably label it with an        *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   681
(* ID number identifying the subgoal.  This could      *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   682
(* be passed over to the watcher, e.g.  numcls25       *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   683
(*******************************************************)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   684
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   685
(* val str = "[S%x%P%R%Q%]1ExtraAxiom()[~ Q U%~ R U%][U%]2ExtraAxiom()[~ Q U%~ P U%][U%]3ExtraAxiom()[Q U%R U%][U%]1OrigAxiom()[S x%][]2OrigAxiom()[P U%R U%][U%]6OrigAxiom()[~ S U%~ P U%][U%]7OrigAxiom()[~ S U%~ R U%][U%]1Axiom()[S x%][]2Axiom()[R U%P U%][U%]6Axiom()[~ P U%~ S U%][U%]7Axiom()[~ R U%~ S U%][U%]8Binary((6,1),(1,0))[~ P x%][]9Binary((7,1),(1,0))[~ R x%][]19Binary((9,0),(2,0))[P x%][]25Binary((8,0),(19,0))[][]";
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   686
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   687
val str = "[P%x%xa%xb%]1OrigAxiom()[P x%~ P U%][U%]3OrigAxiom()[P U%~ P x%][U%]5OrigAxiom()[~ P xa%~ P U%][U%]7OrigAxiom()[P U%P xb%][U%]1Axiom()[P x%~ P U%][U%]3Axiom()[P U%~ P x%][U%]5Axiom()[~ P U%~ P xa%][U%]7Axiom()[P U%P xb%][U%]9Factor(5,0,1)[~ P xa%][]10Binary((9,0),(3,0))[~ P x%][]11Binary((10,0),(1,0))[~ P U%][U%]12Factor(7,0,1)[P xb%][]14Binary((11,0),(12,0))[][]";
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   688
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   689
val reconstr = "[P%Q%x%xa%]1OrigAxiom()[~ P U%][U%]3OrigAxiom()[Q U%][U%]5OrigAxiom()[P (x U)%~ Q (xa U)%][U%]9Binary((7,0),(3,0))[][]7Binary((1,0),(5,0))[~ Q (xa U)%][U%]5Axiom()[P (x U)%~ Q (xa U)%][U%]3Axiom()[Q U%][U%]1Axiom()[~ P U%][U%](ALL xb::'a::type.   (~ (P::'a::type => bool) ((x::'a::type => 'a::type) xb) |    (Q::'a::type => bool) ((xa::'a::type => 'a::type) xb)) &   P xb & ~ Q xb)";
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   690
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   691
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   692
val reconstr = "[P%x%xa%xb%]1OrigAxiom()[P x%~ P U%][U%]3OrigAxiom()[P U%~ P x%][U%]5OrigAxiom()[~ P xa%~ P U%][U%]7OrigAxiom()[P U%P xb%][U%]1Axiom()[P x%~ P U%][U%]3Axiom()[P U%~ P x%][U%]5Axiom()[~ P U%~ P xa%][U%]7Axiom()[P U%P xb%][U%]9Factor(5,0,1)[~ P xa%][]10Binary((9,0),(3,0))[~ P x%][]11Binary((10,0),(1,0))[~ P U%][U%]12Factor(7,0,1)[P xb%][]14Binary((11,0),(12,0))[][]";
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   693
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   694
val thmstring = " (ALL xa::'a::type.   (~ (P::'a::type => bool) (x::'a::type) | P xa) & (~ P xa | P x)) & (((P::'a::type => bool) (xa::'a::type) | (ALL x::'a::type. P x)) &((ALL x::'a::type. ~ P x) | ~ P (xb::'a::type)))";
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   695
*)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   696
15739
bb2acfed8212 yet more tidying up: removal of some references to Main
paulson
parents: 15700
diff changeset
   697
fun apply_res_thm str goalstring  = let val tokens = #1 (lex str);
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   698
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   699
                                   val (frees,recon_steps) = parse_step tokens 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   700
                                   val isar_str = to_isar_proof (frees, recon_steps, goalstring)
15658
2edb384bf61f watcher.ML and watcher.sig changed. Debug files now write to tmp.
quigley
parents: 15642
diff changeset
   701
                                   val foo =   TextIO.openOut (File.sysify_path(File.tmp_path (Path.basic "foobar")));
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   702
                               in 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   703
                                  TextIO.output(foo,(isar_str));TextIO.closeOut foo;Pretty.writeln(Pretty.str  isar_str); () 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   704
                               end 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   705
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   706
15684
5ec4d21889d6 Reconstruction code, now packaged to avoid name clashes
paulson
parents: 15658
diff changeset
   707
end;