src/HOL/Tools/ATP/recon_order_clauses.ML
author paulson
Tue, 16 Aug 2005 15:36:28 +0200
changeset 17084 fb0a80aef0be
parent 16515 7896ea4f3a87
child 17312 159783c74f75
permissions -rw-r--r--
classical rules must have names for ATP integration
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15789
4cb16144c81b added hearder lines and deleted some redundant material
paulson
parents: 15774
diff changeset
     1
(*  ID:         $Id$
4cb16144c81b added hearder lines and deleted some redundant material
paulson
parents: 15774
diff changeset
     2
    Author:     Claire Quigley
4cb16144c81b added hearder lines and deleted some redundant material
paulson
parents: 15774
diff changeset
     3
    Copyright   2004  University of Cambridge
4cb16144c81b added hearder lines and deleted some redundant material
paulson
parents: 15774
diff changeset
     4
*)
4cb16144c81b added hearder lines and deleted some redundant material
paulson
parents: 15774
diff changeset
     5
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
     6
structure ReconOrderClauses =
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
     7
struct
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
     8
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
     9
(*----------------------------------------------*)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    10
(* Reorder clauses for use in binary resolution *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    11
(*----------------------------------------------*)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    12
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    13
fun remove_nth n [] = []
15697
681bcb7f0389 removal of Main and other tidying up
paulson
parents: 15684
diff changeset
    14
|   remove_nth n xs = (List.take (xs, n-1)) @ (List.drop (xs, n))
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    15
15774
9df37a0e935d more tidying of libraries in Reconstruction
paulson
parents: 15739
diff changeset
    16
(*Differs from List.nth: it counts from 1 rather than from 0*)
9df37a0e935d more tidying of libraries in Reconstruction
paulson
parents: 15739
diff changeset
    17
fun get_nth n (x::xs) = hd (Library.drop (n-1, x::xs))
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    18
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    19
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    20
exception Not_in_list;  
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    21
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    22
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    23
fun numlist 0 = []
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    24
|   numlist n = (numlist (n - 1))@[n]
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    25
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    26
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    27
fun last(x::xs) = if xs=[] then x else last xs
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    28
fun butlast []= []
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    29
|   butlast(x::xs) = if xs=[] then [] else (x::(butlast xs))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    30
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    31
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    32
fun minus a b = b - a;
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    33
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    34
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    35
(* code to rearrange clauses so that they're the same as the parsed in SPASS version *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    36
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    37
 fun takeUntil ch [] res  = (res, [])
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    38
 |   takeUntil ch (x::xs) res = if   x = ch 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    39
                                then
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    40
                                     (res, xs)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    41
                                else
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    42
                                     takeUntil ch xs (res@[x]);
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    43
16157
1764cc98bafd minor tidying and sml/nj compatibility
paulson
parents: 16061
diff changeset
    44
fun contains_eq str = "=" mem str 
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    45
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    46
fun eq_not_neq str = let val uptoeq = fst(takeUntil "=" str [])
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    47
                     in (last uptoeq) <> "~" end
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    48
                   
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    49
fun get_eq_strs str =  if eq_not_neq  str   (*not an inequality *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    50
                       then 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    51
                           let val (left, right) = takeUntil "=" str []
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    52
                           in
15774
9df37a0e935d more tidying of libraries in Reconstruction
paulson
parents: 15739
diff changeset
    53
                               (butlast left, tl right)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    54
                           end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    55
                       else                  (* is an inequality *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    56
                           let val (left, right) = takeUntil "~" str []
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    57
                           in 
15774
9df37a0e935d more tidying of libraries in Reconstruction
paulson
parents: 15739
diff changeset
    58
                              (butlast left, tl (tl right))
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    59
                           end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    60
                
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    61
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    62
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    63
fun switch_equal a x = let val (a_lhs, a_rhs) = get_eq_strs a
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    64
                           val (x_lhs, x_rhs) = get_eq_strs x
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    65
                       in
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    66
                           (a_lhs = x_rhs) andalso (a_rhs = x_lhs)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    67
                       end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    68
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    69
fun is_var_pair (a,b) vars = (a mem vars) andalso (b mem vars)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    70
16515
7896ea4f3a87 VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents: 16157
diff changeset
    71
fun var_equiv vars (a,b)  = a=b orelse (is_var_pair (a,b) vars)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    72
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    73
fun all_true [] = false
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    74
|   all_true xs = let val falselist = List.filter (equal false ) xs 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    75
                  in
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    76
                      falselist = []
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    77
                  end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    78
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    79
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    80
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    81
fun var_pos_eq vars x y = 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    82
    String.size x = String.size y andalso
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    83
    let val xs = explode x
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    84
	val ys = explode y
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    85
	val xsys = ListPair.zip (xs,ys)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    86
	val are_var_pairs = map (var_equiv vars) xsys
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    87
    in
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    88
	all_true are_var_pairs 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    89
    end;
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    90
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    91
fun pos_in_list a [] allvars (pos_num, symlist, nsymlist) =  raise Not_in_list
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    92
  | pos_in_list a (x::[]) allvars (pos_num , symlist, nsymlist) = 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    93
      let val y = explode x 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    94
	  val b = explode a
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    95
      in
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    96
	 if  b = y
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    97
	 then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    98
	      (pos_num, symlist, nsymlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    99
	 else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   100
	      if (var_pos_eq allvars  a x) 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   101
	      then  (* Equal apart from meta-vars having different names *)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   102
		  (pos_num, symlist, nsymlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   103
	      else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   104
		  if (contains_eq b) andalso (contains_eq y)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   105
		  then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   106
		      if (eq_not_neq b) andalso (eq_not_neq y)  andalso (switch_equal b y )          
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   107
		      then (* both are equalities and equal under sym*) 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   108
			  (pos_num, (pos_num::symlist), nsymlist)  (* add pos to symlist *)                                                                    
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   109
			  else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   110
			  if not(eq_not_neq b) andalso not(eq_not_neq y) andalso  (switch_equal b y)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   111
			   then (* if they're equal under not_sym *)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   112
			       (pos_num, (symlist), (pos_num::nsymlist))(* add pos to nsymlist *)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   113
			   else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   114
				raise Not_in_list
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   115
		  else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   116
		       raise Not_in_list
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   117
      end   
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   118
  | pos_in_list a (x::xs) allvars (pos_num, symlist, nsymlist) = 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   119
      let val y = explode x 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   120
	  val b = explode a
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   121
      in
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   122
	 if  b = y
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   123
	 then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   124
	      (pos_num, symlist, nsymlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   125
	 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   126
	 else
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   127
	       if (var_pos_eq allvars  a x) (* Equal apart from meta-vars having different names *)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   128
	       then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   129
		  (pos_num, symlist, nsymlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   130
	       else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   131
		   if (contains_eq b) andalso (contains_eq y)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   132
		   then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   133
		       if (eq_not_neq b) andalso (eq_not_neq y)  andalso (switch_equal b y )   (* both are equalities and equal under sym*)        
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   134
		       then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   135
			   (pos_num, (pos_num::symlist), nsymlist)  (* add pos to symlist *)                                                                    else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   136
			   if not(eq_not_neq b) andalso not(eq_not_neq y) andalso  (switch_equal b y )  (* if they're equal under not_sym *)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   137
			   then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   138
				(pos_num, (symlist), (pos_num::nsymlist))(* add pos to nsymlist *)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   139
			   else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   140
				pos_in_list a xs allvars((pos_num + 1), symlist, nsymlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   141
		   else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   142
			 pos_in_list a xs allvars((pos_num + 1), symlist, nsymlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   143
		   
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   144
      end;
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   145
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   146
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   147
    (* in
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   148
	if  b = y
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   149
	then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   150
	     (pos_num, symlist, nsymlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   151
	else if (contains_eq b) andalso (contains_eq y)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   152
	     then if (eq_not_neq b) andalso (eq_not_neq y) (* both are equalities*)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   153
		  then if (switch_equal b y )              (* if they're equal under sym *)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   154
		       then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   155
			   (pos_num, (pos_num::symlist), nsymlist)  (* add pos to symlist *)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   156
		       else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   157
			     pos_in_list a xs ((pos_num + 1), symlist, nsymlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   158
		  else if not(eq_not_neq b) andalso not(eq_not_neq y)  (* both are inequalities *)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   159
		       then if (switch_equal b y )  (* if they're equal under not_sym *)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   160
			    then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   161
				(pos_num, (symlist), (pos_num::nsymlist))(* add pos to nsymlist *)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   162
			    else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   163
				     pos_in_list a xs ((pos_num + 1), symlist, nsymlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   164
		       else
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   165
			      pos_in_list a xs ((pos_num + 1), symlist, nsymlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   166
		   else  
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   167
			   pos_in_list a xs ((pos_num + 1), symlist, nsymlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   168
	      else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   169
		      pos_in_list a xs ((pos_num + 1), symlist, nsymlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   170
     end   
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   171
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   172
    *)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   173
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   174
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   175
(* checkorder Spass Isabelle [] *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   176
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   177
fun checkorder [] strlist allvars (numlist, symlist, not_symlist) =
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   178
      (numlist,symlist, not_symlist)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   179
|   checkorder (x::xs) strlist allvars (numlist, symlist, not_symlist) =  
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   180
         let val (posnum, symlist', not_symlist') = 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   181
               pos_in_list x strlist allvars (0, symlist, not_symlist) 
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   182
         in
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   183
             checkorder xs  strlist allvars ((numlist@[posnum]), symlist', not_symlist') 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   184
         end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   185
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   186
fun is_digit ch =
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   187
    ( ch >=  "0" andalso ch <=  "9")
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   188
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   189
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   190
fun is_alpha ch =
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   191
    (ch >=  "A" andalso  ch <=  "Z") orelse
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   192
    (ch >=  "a" andalso ch <=  "z")
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   193
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   194
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   195
fun is_alpha_space_or_neg_or_eq ch =
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   196
    (ch = "~") orelse (is_alpha ch) orelse ( ch = " ")orelse ( ch = "=")
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   197
15739
bb2acfed8212 yet more tidying up: removal of some references to Main
paulson
parents: 15702
diff changeset
   198
fun lit_string sg t = 
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   199
    let val termstr = Sign.string_of_term sg t
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   200
	val exp_term = explode termstr
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   201
    in
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   202
	implode(List.filter is_alpha_space_or_neg_or_eq exp_term)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   203
    end
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   204
15739
bb2acfed8212 yet more tidying up: removal of some references to Main
paulson
parents: 15702
diff changeset
   205
fun get_meta_lits thm = map (lit_string (sign_of_thm thm)) (prems_of thm)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   206
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   207
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   208
fun is_alpha_space_or_neg_or_eq_or_bracket ch =
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   209
   is_alpha_space_or_neg_or_eq ch orelse (ch= "(") orelse (ch = ")")
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   210
15739
bb2acfed8212 yet more tidying up: removal of some references to Main
paulson
parents: 15702
diff changeset
   211
fun lit_string_bracket sg t = 
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   212
    let val termstr = Sign.string_of_term sg t
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   213
	val exp_term = explode termstr
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   214
    in
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   215
	implode(List.filter  is_alpha_space_or_neg_or_eq_or_bracket exp_term)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   216
    end;
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   217
15739
bb2acfed8212 yet more tidying up: removal of some references to Main
paulson
parents: 15702
diff changeset
   218
fun get_meta_lits_bracket thm = 
bb2acfed8212 yet more tidying up: removal of some references to Main
paulson
parents: 15702
diff changeset
   219
    map (lit_string_bracket (sign_of_thm thm)) (prems_of thm)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   220
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   221
      
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   222
fun apply_rule rule [] thm = thm
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   223
|   apply_rule rule  (x::xs) thm = let val thm' = rule RSN ((x+1),thm)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   224
                                  in
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   225
                                      apply_rule rule xs thm'
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   226
                                  end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   227
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   228
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   229
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   230
(* resulting thm, clause-strs in spass order, vars *)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   231
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   232
fun rearrange_clause thm res_strlist allvars = 
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   233
    let val isa_strlist = get_meta_lits thm 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   234
        (* change this to use Jia's code to get same looking thing as isastrlist? *)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   235
	val (posns, symlist, not_symlist) = checkorder res_strlist isa_strlist allvars([],[],[])
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   236
	val symmed = apply_rule sym symlist thm
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   237
	val not_symmed = apply_rule not_sym not_symlist symmed
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   238
    in
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   239
       ((rearrange_prems posns not_symmed), posns, symlist,not_symlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   240
    end
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   241
    
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   242
end;
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   243