src/HOL/Tools/res_axioms.ML
changeset 15955 87cf2ce8ede8
parent 15872 8336ff711d80
child 15956 0da64b5a9a00
equal deleted inserted replaced
15954:dd516176043a 15955:87cf2ce8ede8
   209 val recon_thy = ThyInfo.get_theory"Reconstruction";
   209 val recon_thy = ThyInfo.get_theory"Reconstruction";
   210 
   210 
   211 fun transfer_to_Reconstruction thm =
   211 fun transfer_to_Reconstruction thm =
   212     transfer recon_thy thm handle THM _ => thm;
   212     transfer recon_thy thm handle THM _ => thm;
   213 
   213 
   214 (* remove "True" clause *)
   214 fun is_taut th =
   215 fun rm_redundant_cls [] = []
   215       case (prop_of th) of
   216   | rm_redundant_cls (thm::thms) =
   216            (Const ("Trueprop", _) $ Const ("True", _)) => true
   217     let val t = prop_of thm
   217          | _ => false;
   218     in
   218 
   219 	case t of (Const ("Trueprop", _) $ Const ("True", _)) => rm_redundant_cls thms
   219 (* remove tautologous clauses *)
   220 		| _ => thm::(rm_redundant_cls thms)
   220 val rm_redundant_cls = List.filter (not o is_taut);
   221     end;
       
   222 
   221 
   223 (* transform an Isabelle thm into CNF *)
   222 (* transform an Isabelle thm into CNF *)
   224 fun cnf_axiom thm =
   223 fun cnf_axiom_aux thm =
   225     let val thm' = transfer_to_Reconstruction thm
   224     let val thm' = transfer_to_Reconstruction thm
   226 	val thm'' = if (is_elimR thm') then (cnf_elim thm')  else cnf_rule thm'
   225 	val thm'' = if (is_elimR thm') then (cnf_elim thm')  else cnf_rule thm'
   227     in
   226     in
   228 	map Thm.varifyT (rm_redundant_cls thm'')
   227 	map (zero_var_indexes o Thm.varifyT) (rm_redundant_cls thm'')
   229     end;
   228     end;
       
   229     
       
   230 (*Cache for clauses: could be a hash table if we provided them.*)
       
   231 val clause_cache = ref (Symtab.empty : (thm * thm list) Symtab.table)
       
   232 
       
   233 fun cnf_axiom th =
       
   234     case Thm.name_of_thm th of
       
   235 	  "" => cnf_axiom_aux th (*no name, so can't cache*)
       
   236 	| s  => case Symtab.lookup (!clause_cache,s) of
       
   237 	  	  NONE => 
       
   238 		    let val cls = cnf_axiom_aux th
       
   239 		    in  clause_cache := Symtab.update ((s, (th,cls)), !clause_cache); cls
       
   240 		    end
       
   241 	        | SOME(th',cls) =>
       
   242 		    if eq_thm(th,th') then cls
       
   243 		    else (*New theorem stored under the same name? Possible??*)
       
   244 		      let val cls = cnf_axiom_aux th
       
   245 		      in  clause_cache := Symtab.update ((s, (th,cls)), !clause_cache); cls
       
   246 		      end;
   230 
   247 
   231 fun meta_cnf_axiom thm = 
   248 fun meta_cnf_axiom thm = 
   232     map (zero_var_indexes o Meson.make_meta_clause) (cnf_axiom thm);
   249     map Meson.make_meta_clause (cnf_axiom thm);
   233 
   250 
   234 
   251 
   235 (* changed: with one extra case added *)
   252 (* changed: with one extra case added *)
   236 fun univ_vars_of_aux (Const ("Hilbert_Choice.Eps",_) $ Abs(_,_,body)) vars = univ_vars_of_aux body vars
   253 fun univ_vars_of_aux (Const ("Hilbert_Choice.Eps",_) $ Abs(_,_,body)) vars = univ_vars_of_aux body vars
   237   | univ_vars_of_aux (Const ("Ex",_) $ Abs(_,_,body)) vars = univ_vars_of_aux body vars (* EX x. body *)
   254   | univ_vars_of_aux (Const ("Ex",_) $ Abs(_,_,body)) vars = univ_vars_of_aux body vars (* EX x. body *)