src/HOL/Tools/res_atp_setup.ML
changeset 18086 051b7f323b4c
parent 18014 8bedb073e628
child 18141 89e2e8bed08f
equal deleted inserted replaced
18085:ec9e36ece6bb 18086:051b7f323b4c
     8 
     8 
     9 val keep_atp_input = ref false;
     9 val keep_atp_input = ref false;
    10 val debug = ref true;
    10 val debug = ref true;
    11 val filter_ax = ref false;
    11 val filter_ax = ref false;
    12 
    12 
    13 
       
    14 fun warning_thm thm nm = warning (nm ^ " " ^ (string_of_thm thm));
       
    15 
       
    16 fun warning_thms_n n thms nm =
       
    17     let val _ = warning ("total " ^ (string_of_int n) ^ " " ^ nm)
       
    18 	fun warning_thms_aux [] = warning ("no more " ^ nm)
       
    19 	  | warning_thms_aux (th::ths) = (warning_thm th nm; warning_thms_aux ths)
       
    20     in
       
    21 	warning_thms_aux thms
       
    22     end;
       
    23 
       
    24 
       
    25 (*******************************************************)
    13 (*******************************************************)
    26 (* set up the output paths                             *)
    14 (* set up the output paths                             *)
    27 (*******************************************************)
    15 (*******************************************************)
    28 
    16 
    29 val claset_file = File.tmp_path (Path.basic "claset");
    17 val claset_file = File.tmp_path (Path.basic "claset");
    30 val simpset_file = File.tmp_path (Path.basic "simp");
    18 val simpset_file = File.tmp_path (Path.basic "simp");
       
    19 val local_lemma_file = File.tmp_path (Path.basic "locallemmas");
    31 
    20 
    32 val prob_file = File.tmp_path (Path.basic "prob");
    21 val prob_file = File.tmp_path (Path.basic "prob");
    33 val hyps_file = File.tmp_path (Path.basic "hyps");
    22 val hyps_file = File.tmp_path (Path.basic "hyps");
    34 
    23 
    35 val types_sorts_file =  File.tmp_path (Path.basic "typsorts");
    24 val types_sorts_file =  File.tmp_path (Path.basic "typsorts");
    51 val add_claset = (fn () => include_claset:=true);
    40 val add_claset = (fn () => include_claset:=true);
    52 val add_clasimp = (fn () => include_simpset:=true;include_claset:=true);
    41 val add_clasimp = (fn () => include_simpset:=true;include_claset:=true);
    53 val rm_simpset = (fn () => include_simpset:=false);
    42 val rm_simpset = (fn () => include_simpset:=false);
    54 val rm_claset = (fn () => include_claset:=false);
    43 val rm_claset = (fn () => include_claset:=false);
    55 val rm_clasimp = (fn () => include_simpset:=false;include_claset:=false);
    44 val rm_clasimp = (fn () => include_simpset:=false;include_claset:=false);
    56 
       
    57 
       
    58 
       
    59 val rules_modifiers =
       
    60   Simplifier.simp_modifiers @ Splitter.split_modifiers @
       
    61   Classical.cla_modifiers @ iff_modifiers;
       
    62 
       
    63 
    45 
    64 
    46 
    65 fun get_local_claR ctxt = 
    47 fun get_local_claR ctxt = 
    66     let val cla_rules = rep_cs (Classical.get_local_claset ctxt) 
    48     let val cla_rules = rep_cs (Classical.get_local_claset ctxt) 
    67 	val safeEs = #safeEs cla_rules
    49 	val safeEs = #safeEs cla_rules
   137  
   119  
   138 
   120 
   139 val tptp_hyps = tptp_hyps_g true;
   121 val tptp_hyps = tptp_hyps_g true;
   140 val tptp_hypsH = tptp_hyps_g false;
   122 val tptp_hypsH = tptp_hyps_g false;
   141 
   123 
   142 fun subtract_simpset thy ctxt =
       
   143   let
       
   144     val rules1 = #rules (#1 (rep_ss (simpset_of thy)));
       
   145     val rules2 = #rules (#1 (rep_ss (local_simpset_of ctxt)));
       
   146   in map ResAxioms.pairname (map #thm (Net.subtract MetaSimplifier.eq_rrule rules1 rules2)) end;
       
   147 
       
   148 fun subtract_claset thy ctxt =
       
   149   let
       
   150     val (netI1, netE1) = #xtra_netpair (rep_cs (claset_of thy));
       
   151     val (netI2, netE2) = #xtra_netpair (rep_cs (local_claset_of ctxt));
       
   152     val subtract = map (#2 o #2) oo Net.subtract Tactic.eq_kbrl;
       
   153   in map ResAxioms.pairname (subtract netI1 netI2 @ subtract netE1 netE2) end;
       
   154 
       
   155 
       
   156 fun mk_axioms is_fol rules =
   124 fun mk_axioms is_fol rules =
   157     if is_fol then 
   125     if is_fol then 
   158 	(let val  clss = ResClause.union_all(ResAxioms.clausify_rules_pairs rules)
   126 	(let val  clss = ResClause.union_all(ResAxioms.clausify_rules_pairs rules)
   159 	     val (clss',names) = ListPair.unzip clss
   127 	     val (clss',names) = ListPair.unzip clss
   160 	     val (tptpclss,_) = ListPair.unzip(map ResClause.clause2tptp clss')
   128 	     val (tptpclss,_) = ListPair.unzip(map ResClause.clause2tptp clss')
   164 	     val (clss',names) = ListPair.unzip clss
   132 	     val (clss',names) = ListPair.unzip clss
   165 	     val (tptpclss,_) = ListPair.unzip(map ResHolClause.clause2tptp clss')
   133 	     val (tptpclss,_) = ListPair.unzip(map ResHolClause.clause2tptp clss')
   166 	 in tptpclss end)
   134 	 in tptpclss end)
   167 
   135 
   168 
   136 
   169 local
       
   170 
   137 
   171 fun write_rules_g is_fol [] file = [](* no rules, then no need to write anything, thus no clasimp file *)
   138 fun write_rules_g is_fol [] file = [](* no rules, then no need to write anything, thus no clasimp file *)
   172   | write_rules_g is_fol rules file =
   139   | write_rules_g is_fol rules file =
   173     let val out = TextIO.openOut(file)
   140     let val out = TextIO.openOut(file)
   174 	val tptpclss = mk_axioms is_fol rules
   141 	val tptpclss = mk_axioms is_fol rules
   180 
   147 
   181 
   148 
   182 val write_rules = write_rules_g true;
   149 val write_rules = write_rules_g true;
   183 val write_rulesH = write_rules_g false;
   150 val write_rulesH = write_rules_g false;
   184 
   151 
   185 in
   152 
   186 
   153 
   187 (* TPTP Isabelle theorems *)
   154 (* TPTP Isabelle theorems *)
   188 fun tptp_cnf_rules_g write_rules (clasetR,simpsetR) =
   155 fun tptp_cnf_rules_g write_rules ths (clasetR,simpsetR) =
   189     let val simpfile = File.platform_path simpset_file
   156     let val simpfile = File.platform_path simpset_file
   190 	val clafile =  File.platform_path claset_file
   157 	val clafile =  File.platform_path claset_file
   191     in
   158 	val local_lemfile = File.platform_path local_lemma_file
   192 	(write_rules clasetR clafile) @ (write_rules simpsetR simpfile)
   159     in
       
   160 	(write_rules clasetR clafile) @ (write_rules simpsetR simpfile) @ (write_rules ths local_lemfile)
   193     end;
   161     end;
   194 
   162 
   195 val tptp_cnf_rules = tptp_cnf_rules_g write_rules;
   163 val tptp_cnf_rules = tptp_cnf_rules_g write_rules;
   196 val tptp_cnf_rulesH = tptp_cnf_rules_g write_rulesH;
   164 val tptp_cnf_rulesH = tptp_cnf_rules_g write_rulesH;
   197 
   165 
   198 end
   166 
   199 
   167 fun tptp_cnf_clasimp_g tptp_cnf_rules ths ctxt (include_claset,include_simpset) =
   200 fun tptp_cnf_clasimp_g tptp_cnf_rules ctxt (include_claset,include_simpset) =
   168     let val local_claR = if include_claset then get_local_claR ctxt else []
   201     let val local_claR = if include_claset then get_local_claR ctxt else (subtract_claset (ProofContext.theory_of ctxt) ctxt)
   169 	val local_simpR = if include_simpset then get_local_simpR ctxt else []
   202 	val local_simpR = if include_simpset then get_local_simpR ctxt else (subtract_simpset (ProofContext.theory_of ctxt) ctxt)
   170 	val ths_names = map ResAxioms.pairname ths
   203 
   171     in
   204     in
   172 	tptp_cnf_rules ths_names (local_claR,local_simpR)
   205 	tptp_cnf_rules (local_claR,local_simpR)
   173     end;
   206     end;
   174 
   207 
   175 
   208 
   176 val tptp_cnf_clasimp  = tptp_cnf_clasimp_g tptp_cnf_rules;
   209 val tptp_cnf_clasimp = tptp_cnf_clasimp_g tptp_cnf_rules;
       
   210 val tptp_cnf_clasimpH = tptp_cnf_clasimp_g tptp_cnf_rulesH;
   177 val tptp_cnf_clasimpH = tptp_cnf_clasimp_g tptp_cnf_rulesH;
   211 
   178 
   212 
   179 
   213 fun tptp_types_sorts thy = 
   180 fun tptp_types_sorts thy = 
   214     let val classrel_clauses = ResClause.classrel_clauses_thy thy
   181     let val classrel_clauses = ResClause.classrel_clauses_thy thy
   230     end;
   197     end;
   231 
   198 
   232 
   199 
   233 
   200 
   234 (*FIXME: a function that does not perform any filtering now *)
   201 (*FIXME: a function that does not perform any filtering now *)
   235 fun find_relevant_ax ctxt = tptp_cnf_clasimp ctxt (true,true);
   202 fun find_relevant_ax tptp_cnf_clasimp ths ctxt = tptp_cnf_clasimp ths ctxt (true,true);
   236 
   203 
   237 
   204 
   238 (***************************************************************)
   205 (***************************************************************)
   239 (* setup ATPs as Isabelle methods                               *)
   206 (* setup ATPs as Isabelle methods                              *)
   240 (***************************************************************)
   207 (***************************************************************)
   241 fun atp_meth_g tptp_hyps tptp_cnf_clasimp tac prems ctxt = 
   208 fun atp_meth_g tptp_hyps tptp_cnf_clasimp tac ths ctxt = 
   242     let val rules = if !filter_ax then find_relevant_ax ctxt 
   209     let val rules = if !filter_ax then find_relevant_ax tptp_cnf_clasimp ths ctxt 
   243 		    else tptp_cnf_clasimp ctxt (!include_claset, !include_simpset) 
   210 		    else tptp_cnf_clasimp ths ctxt (!include_claset, !include_simpset) 
   244 	val (hyps,tfrees) = tptp_hyps (ProofContext.prems_of ctxt)
   211 	val (hyps,tfrees) = tptp_hyps (ProofContext.prems_of ctxt)
   245 	val thy = ProofContext.theory_of ctxt
   212 	val thy = ProofContext.theory_of ctxt
   246 	val tsfile = tptp_types_sorts thy
   213 	val tsfile = tptp_types_sorts thy
   247 	val files = hyps @ rules @ tsfile
   214 	val files = hyps @ rules @ tsfile
   248     in
   215     in
   249 	Method.METHOD (fn facts =>
   216 	Method.SIMPLE_METHOD' HEADGOAL
   250 			  if !debug then (warning_thms_n (length facts) facts "facts";HEADGOAL (tac ctxt files tfrees)) 
   217 	(tac ctxt files tfrees)
   251 			  else HEADGOAL (tac ctxt files tfrees))
   218     end;
   252     end;
   219 fun atp_meth_f tac ths ctxt = atp_meth_g tptp_hyps tptp_cnf_clasimp tac ths ctxt;
   253 
   220 fun atp_meth_h tac ths ctxt = atp_meth_g tptp_hypsH tptp_cnf_clasimpH tac ths ctxt;
   254 fun atp_meth_f tac = atp_meth_g tptp_hyps tptp_cnf_clasimp tac;
   221 
   255 
   222 
   256 fun atp_meth_h tac = atp_meth_g tptp_hypsH tptp_cnf_clasimpH tac;
   223 fun atp_meth_G atp_meth tac ths ctxt =
   257 
   224     let val _  = ResClause.init (ProofContext.theory_of ctxt)
   258 fun atp_meth_G atp_meth tac prems ctxt =
   225     in
   259     let val _ = ResClause.init (ProofContext.theory_of ctxt)
   226 	atp_meth tac ths ctxt
   260     in    
   227     end;
   261 	if not(List.null prems) then (warning_thms_n (length prems) prems "prems!!!"; atp_meth tac prems ctxt)
   228 fun atp_meth_H tac ths ctxt = atp_meth_G atp_meth_h tac ths ctxt;
   262 	else (atp_meth tac prems ctxt)
   229 fun atp_meth_F tac ths ctxt = atp_meth_G atp_meth_f tac ths ctxt;
   263     end;
   230 
   264 	
   231 
   265 
   232 fun atp_method_H tac = Method.thms_ctxt_args (atp_meth_H tac);
   266 fun atp_meth_H tac = atp_meth_G atp_meth_h tac;
   233 fun atp_method_F tac = Method.thms_ctxt_args (atp_meth_F tac);
   267 
       
   268 fun atp_meth_F tac = atp_meth_G atp_meth_f tac;
       
   269 
       
   270 
       
   271 val atp_method_H = Method.bang_sectioned_args rules_modifiers o atp_meth_H;
       
   272 
       
   273 val atp_method_F = Method.bang_sectioned_args rules_modifiers o atp_meth_F;
       
   274 
   234 
   275 
   235 
   276 
   236 
   277 (*************Remove tmp files********************************)
   237 (*************Remove tmp files********************************)
   278 fun rm_tmp_files1 [] = ()
   238 fun rm_tmp_files1 [] = ()