src/HOL/Tools/ATP/recon_order_clauses.ML
author wenzelm
Mon, 17 Jul 2006 18:42:38 +0200
changeset 20139 804927db5311
parent 20138 6dc6fc8b261e
permissions -rw-r--r--
replaced butlast by Library.split_last;
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
(* code to rearrange clauses so that they're the same as the parsed in SPASS version *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    24
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    25
 fun takeUntil ch [] res  = (res, [])
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    26
 |   takeUntil ch (x::xs) res = if   x = ch 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    27
                                then
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    28
                                     (res, xs)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    29
                                else
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    30
                                     takeUntil ch xs (res@[x]);
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    31
16157
1764cc98bafd minor tidying and sml/nj compatibility
paulson
parents: 16061
diff changeset
    32
fun contains_eq str = "=" mem str 
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    33
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    34
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
    35
                     in (List.last uptoeq) <> "~" end
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    36
                   
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    37
fun get_eq_strs str =  if eq_not_neq  str   (*not an inequality *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    38
                       then 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    39
                           let val (left, right) = takeUntil "=" str []
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    40
                           in
20138
6dc6fc8b261e replaced butlast by Library.split_last;
wenzelm
parents: 17312
diff changeset
    41
                               (#1 (split_last left), tl right)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    42
                           end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    43
                       else                  (* is an inequality *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    44
                           let val (left, right) = takeUntil "~" str []
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    45
                           in 
20138
6dc6fc8b261e replaced butlast by Library.split_last;
wenzelm
parents: 17312
diff changeset
    46
                              (#1 (split_last left), tl (tl right))
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    47
                           end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    48
                
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    49
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    50
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    51
fun switch_equal a x = let val (a_lhs, a_rhs) = get_eq_strs a
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    52
                           val (x_lhs, x_rhs) = get_eq_strs x
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    53
                       in
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    54
                           (a_lhs = x_rhs) andalso (a_rhs = x_lhs)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    55
                       end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    56
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    57
fun is_var_pair (a,b) vars = (a mem vars) andalso (b mem vars)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    58
16515
7896ea4f3a87 VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents: 16157
diff changeset
    59
fun var_equiv vars (a,b)  = a=b orelse (is_var_pair (a,b) vars)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    60
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    61
fun all_true [] = false
20138
6dc6fc8b261e replaced butlast by Library.split_last;
wenzelm
parents: 17312
diff changeset
    62
|   all_true xs = null (List.filter (equal false ) xs)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    63
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    64
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
    65
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    66
fun var_pos_eq vars x y = 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    67
    String.size x = String.size y andalso
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    68
    let val xs = explode x
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    69
	val ys = explode y
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    70
	val xsys = ListPair.zip (xs,ys)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    71
	val are_var_pairs = map (var_equiv vars) xsys
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    72
    in
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    73
	all_true are_var_pairs 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    74
    end;
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    75
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    76
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
    77
  | pos_in_list a (x::[]) allvars (pos_num , symlist, nsymlist) = 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    78
      let val y = explode x 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    79
	  val b = explode a
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    80
      in
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    81
	 if  b = y
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    82
	 then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    83
	      (pos_num, symlist, nsymlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    84
	 else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    85
	      if (var_pos_eq allvars  a x) 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    86
	      then  (* Equal apart from meta-vars having different names *)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    87
		  (pos_num, symlist, nsymlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    88
	      else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    89
		  if (contains_eq b) andalso (contains_eq y)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    90
		  then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    91
		      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
    92
		      then (* both are equalities and equal under sym*) 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    93
			  (pos_num, (pos_num::symlist), nsymlist)  (* add pos to symlist *)                                                                    
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    94
			  else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    95
			  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
    96
			   then (* if they're equal under not_sym *)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    97
			       (pos_num, (symlist), (pos_num::nsymlist))(* add pos to nsymlist *)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    98
			   else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
    99
				raise Not_in_list
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   100
		  else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   101
		       raise Not_in_list
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   102
      end   
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   103
  | pos_in_list a (x::xs) allvars (pos_num, symlist, nsymlist) = 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   104
      let val y = explode x 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   105
	  val b = explode a
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   106
      in
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   107
	 if  b = y
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   108
	 then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   109
	      (pos_num, symlist, nsymlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   110
	 
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
	       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
   113
	       then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   114
		  (pos_num, symlist, nsymlist)
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
		   if (contains_eq b) andalso (contains_eq y)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   117
		   then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   118
		       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
   119
		       then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   120
			   (pos_num, (pos_num::symlist), nsymlist)  (* add pos to symlist *)                                                                    else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   121
			   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
   122
			   then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   123
				(pos_num, (symlist), (pos_num::nsymlist))(* add pos to nsymlist *)
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
				pos_in_list a xs allvars((pos_num + 1), symlist, nsymlist)
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
			 pos_in_list a xs allvars((pos_num + 1), symlist, nsymlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   128
		   
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   129
      end;
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   130
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   131
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   132
    (* in
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   133
	if  b = y
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, symlist, nsymlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   136
	else if (contains_eq b) andalso (contains_eq y)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   137
	     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
   138
		  then if (switch_equal b y )              (* if they're equal under sym *)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   139
		       then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   140
			   (pos_num, (pos_num::symlist), nsymlist)  (* add pos to symlist *)
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 ((pos_num + 1), symlist, nsymlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   143
		  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
   144
		       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
   145
			    then 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   146
				(pos_num, (symlist), (pos_num::nsymlist))(* add pos to nsymlist *)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   147
			    else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   148
				     pos_in_list a xs ((pos_num + 1), symlist, nsymlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   149
		       else
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   150
			      pos_in_list a xs ((pos_num + 1), symlist, nsymlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   151
		   else  
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   152
			   pos_in_list a xs ((pos_num + 1), symlist, nsymlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   153
	      else 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   154
		      pos_in_list a xs ((pos_num + 1), symlist, nsymlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   155
     end   
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   156
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   157
    *)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   158
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   159
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   160
(* checkorder Spass Isabelle [] *)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   161
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   162
fun checkorder [] strlist allvars (numlist, symlist, not_symlist) =
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   163
      (numlist,symlist, not_symlist)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   164
|   checkorder (x::xs) strlist allvars (numlist, symlist, not_symlist) =  
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   165
         let val (posnum, symlist', not_symlist') = 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   166
               pos_in_list x strlist allvars (0, symlist, not_symlist) 
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   167
         in
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   168
             checkorder xs  strlist allvars ((numlist@[posnum]), symlist', not_symlist') 
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   169
         end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   170
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   171
fun is_digit ch =
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   172
    ( ch >=  "0" andalso ch <=  "9")
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
fun is_alpha ch =
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   176
    (ch >=  "A" andalso  ch <=  "Z") orelse
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   177
    (ch >=  "a" andalso ch <=  "z")
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   178
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   179
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   180
fun is_alpha_space_or_neg_or_eq ch =
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   181
    (ch = "~") orelse (is_alpha ch) orelse ( ch = " ")orelse ( ch = "=")
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   182
15739
bb2acfed8212 yet more tidying up: removal of some references to Main
paulson
parents: 15702
diff changeset
   183
fun lit_string sg t = 
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   184
    let val termstr = Sign.string_of_term sg t
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   185
	val exp_term = explode termstr
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   186
    in
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   187
	implode(List.filter is_alpha_space_or_neg_or_eq exp_term)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   188
    end
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   189
15739
bb2acfed8212 yet more tidying up: removal of some references to Main
paulson
parents: 15702
diff changeset
   190
fun get_meta_lits thm = map (lit_string (sign_of_thm thm)) (prems_of thm)
15642
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_or_bracket ch =
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   194
   is_alpha_space_or_neg_or_eq 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_bracket 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_or_bracket 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_bracket thm = 
bb2acfed8212 yet more tidying up: removal of some references to Main
paulson
parents: 15702
diff changeset
   204
    map (lit_string_bracket (sign_of_thm thm)) (prems_of thm)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   205
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   206
      
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   207
fun apply_rule rule [] thm = thm
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   208
|   apply_rule rule  (x::xs) thm = let val thm' = rule RSN ((x+1),thm)
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   209
                                  in
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   210
                                      apply_rule rule xs thm'
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   211
                                  end
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   212
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   213
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   214
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   215
(* resulting thm, clause-strs in spass order, vars *)
15642
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   216
028059faa963 *** empty log message ***
quigley
parents:
diff changeset
   217
fun rearrange_clause thm res_strlist allvars = 
16061
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   218
    let val isa_strlist = get_meta_lits thm 
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   219
        (* 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
   220
	val (posns, symlist, not_symlist) = checkorder res_strlist isa_strlist allvars([],[],[])
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   221
	val symmed = apply_rule sym symlist thm
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   222
	val not_symmed = apply_rule not_sym not_symlist symmed
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   223
    in
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   224
       ((rearrange_prems posns not_symmed), posns, symlist,not_symlist)
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   225
    end
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   226
    
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   227
end;
8a139c1557bf A new structure and reduced indentation
paulson
parents: 15919
diff changeset
   228