src/HOL/Tools/ATP/recon_order_clauses.ML
author aspinall
Fri, 30 Sep 2005 18:18:34 +0200
changeset 17740 fc385ce6187d
parent 17312 159783c74f75
child 20138 6dc6fc8b261e
permissions -rw-r--r--
Add icon for interface.
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
fun butlast []= []
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    27
|   butlast(x::xs) = if xs=[] then [] else (x::(butlast xs))
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    28
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    29
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    30
fun minus a b = b - a;
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    31
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    32
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    33
(* code to rearrange clauses so that they're the same as the parsed in SPASS version *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    34
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    35
 fun takeUntil ch [] res  = (res, [])
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    36
 |   takeUntil ch (x::xs) res = if   x = ch 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    37
                                then
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    38
                                     (res, xs)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    39
                                else
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    40
                                     takeUntil ch xs (res@[x]);
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    41
16157
1764cc98bafd minor tidying and sml/nj compatibility
paulson
parents: 16061
diff changeset
    42
fun contains_eq str = "=" mem str 
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    43
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    44
fun eq_not_neq str = let val uptoeq = fst(takeUntil "=" str [])
17312
159783c74f75 yet more tidying of Isabelle-ATP link
paulson
parents: 16515
diff changeset
    45
                     in (List.last uptoeq) <> "~" end
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    46
                   
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    47
fun get_eq_strs str =  if eq_not_neq  str   (*not an inequality *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    48
                       then 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    49
                           let val (left, right) = takeUntil "=" str []
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    50
                           in
15774
9df37a0e935d more tidying of libraries in Reconstruction
paulson
parents: 15739
diff changeset
    51
                               (butlast left, tl right)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    52
                           end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    53
                       else                  (* is an inequality *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    54
                           let val (left, right) = takeUntil "~" str []
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    55
                           in 
15774
9df37a0e935d more tidying of libraries in Reconstruction
paulson
parents: 15739
diff changeset
    56
                              (butlast left, tl (tl right))
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    57
                           end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    58
                
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 switch_equal a x = let val (a_lhs, a_rhs) = get_eq_strs a
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    62
                           val (x_lhs, x_rhs) = get_eq_strs x
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    63
                       in
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    64
                           (a_lhs = x_rhs) andalso (a_rhs = x_lhs)
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
fun is_var_pair (a,b) vars = (a mem vars) andalso (b mem vars)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    68
16515
7896ea4f3a87 VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents: 16157
diff changeset
    69
fun var_equiv vars (a,b)  = a=b orelse (is_var_pair (a,b) vars)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    70
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    71
fun all_true [] = false
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    72
|   all_true xs = let val falselist = List.filter (equal false ) xs 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    73
                  in
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    74
                      falselist = []
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
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    79
fun var_pos_eq vars x y = 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    80
    String.size x = String.size y andalso
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    81
    let val xs = explode x
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    82
	val ys = explode y
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    83
	val xsys = ListPair.zip (xs,ys)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    84
	val are_var_pairs = map (var_equiv vars) xsys
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    85
    in
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    86
	all_true are_var_pairs 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    87
    end;
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    88
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    89
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
    90
  | pos_in_list a (x::[]) allvars (pos_num , symlist, nsymlist) = 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    91
      let val y = explode x 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    92
	  val b = explode a
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    93
      in
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    94
	 if  b = y
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    95
	 then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    96
	      (pos_num, symlist, nsymlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    97
	 else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    98
	      if (var_pos_eq allvars  a x) 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    99
	      then  (* Equal apart from meta-vars having different names *)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   100
		  (pos_num, symlist, nsymlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   101
	      else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   102
		  if (contains_eq b) andalso (contains_eq y)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   103
		  then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   104
		      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
   105
		      then (* both are equalities and equal under sym*) 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   106
			  (pos_num, (pos_num::symlist), nsymlist)  (* add pos to symlist *)                                                                    
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   107
			  else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   108
			  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
   109
			   then (* if they're equal under not_sym *)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   110
			       (pos_num, (symlist), (pos_num::nsymlist))(* add pos to nsymlist *)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   111
			   else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   112
				raise Not_in_list
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
      end   
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   116
  | pos_in_list a (x::xs) allvars (pos_num, symlist, nsymlist) = 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   117
      let val y = explode x 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   118
	  val b = explode a
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   119
      in
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   120
	 if  b = y
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   121
	 then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   122
	      (pos_num, symlist, nsymlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   123
	 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   124
	 else
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   125
	       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
   126
	       then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   127
		  (pos_num, symlist, nsymlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   128
	       else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   129
		   if (contains_eq b) andalso (contains_eq y)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   130
		   then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   131
		       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
   132
		       then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   133
			   (pos_num, (pos_num::symlist), nsymlist)  (* add pos to symlist *)                                                                    else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   134
			   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
   135
			   then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   136
				(pos_num, (symlist), (pos_num::nsymlist))(* add pos to nsymlist *)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   137
			   else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   138
				pos_in_list a xs allvars((pos_num + 1), symlist, 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
		   
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   142
      end;
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   143
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   144
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   145
    (* in
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   146
	if  b = y
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   147
	then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   148
	     (pos_num, symlist, nsymlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   149
	else if (contains_eq b) andalso (contains_eq y)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   150
	     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
   151
		  then if (switch_equal b y )              (* if they're equal under sym *)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   152
		       then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   153
			   (pos_num, (pos_num::symlist), nsymlist)  (* add pos to symlist *)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   154
		       else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   155
			     pos_in_list a xs ((pos_num + 1), symlist, nsymlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   156
		  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
   157
		       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
   158
			    then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   159
				(pos_num, (symlist), (pos_num::nsymlist))(* add pos to nsymlist *)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   160
			    else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   161
				     pos_in_list a xs ((pos_num + 1), symlist, 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
     end   
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   169
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   170
    *)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   171
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   172
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   173
(* checkorder Spass Isabelle [] *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   174
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   175
fun checkorder [] strlist allvars (numlist, symlist, not_symlist) =
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   176
      (numlist,symlist, not_symlist)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   177
|   checkorder (x::xs) strlist allvars (numlist, symlist, not_symlist) =  
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   178
         let val (posnum, symlist', not_symlist') = 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   179
               pos_in_list x strlist allvars (0, symlist, not_symlist) 
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   180
         in
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   181
             checkorder xs  strlist allvars ((numlist@[posnum]), symlist', not_symlist') 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   182
         end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   183
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   184
fun is_digit ch =
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   185
    ( ch >=  "0" andalso ch <=  "9")
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   186
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   187
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   188
fun is_alpha ch =
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   189
    (ch >=  "A" andalso  ch <=  "Z") orelse
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   190
    (ch >=  "a" andalso ch <=  "z")
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   191
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   192
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   193
fun is_alpha_space_or_neg_or_eq ch =
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   194
    (ch = "~") orelse (is_alpha ch) orelse ( ch = " ")orelse ( ch = "=")
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   195
15739
bb2acfed8212 yet more tidying up: removal of some references to Main
paulson
parents: 15702
diff changeset
   196
fun lit_string sg t = 
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   197
    let val termstr = Sign.string_of_term sg t
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   198
	val exp_term = explode termstr
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   199
    in
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   200
	implode(List.filter is_alpha_space_or_neg_or_eq exp_term)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   201
    end
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   202
15739
bb2acfed8212 yet more tidying up: removal of some references to Main
paulson
parents: 15702
diff changeset
   203
fun get_meta_lits thm = map (lit_string (sign_of_thm thm)) (prems_of thm)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   204
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   205
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   206
fun is_alpha_space_or_neg_or_eq_or_bracket ch =
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   207
   is_alpha_space_or_neg_or_eq ch orelse (ch= "(") orelse (ch = ")")
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   208
15739
bb2acfed8212 yet more tidying up: removal of some references to Main
paulson
parents: 15702
diff changeset
   209
fun lit_string_bracket sg t = 
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   210
    let val termstr = Sign.string_of_term sg t
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   211
	val exp_term = explode termstr
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   212
    in
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   213
	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
   214
    end;
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   215
15739
bb2acfed8212 yet more tidying up: removal of some references to Main
paulson
parents: 15702
diff changeset
   216
fun get_meta_lits_bracket thm = 
bb2acfed8212 yet more tidying up: removal of some references to Main
paulson
parents: 15702
diff changeset
   217
    map (lit_string_bracket (sign_of_thm thm)) (prems_of thm)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   218
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   219
      
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   220
fun apply_rule rule [] thm = thm
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   221
|   apply_rule rule  (x::xs) thm = let val thm' = rule RSN ((x+1),thm)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   222
                                  in
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   223
                                      apply_rule rule xs thm'
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   224
                                  end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   225
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   226
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   227
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   228
(* resulting thm, clause-strs in spass order, vars *)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   229
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   230
fun rearrange_clause thm res_strlist allvars = 
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   231
    let val isa_strlist = get_meta_lits thm 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   232
        (* 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
   233
	val (posns, symlist, not_symlist) = checkorder res_strlist isa_strlist allvars([],[],[])
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   234
	val symmed = apply_rule sym symlist thm
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   235
	val not_symmed = apply_rule not_sym not_symlist symmed
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   236
    in
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   237
       ((rearrange_prems posns not_symmed), posns, symlist,not_symlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   238
    end
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   239
    
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