85 val rhs = list_abs_free (map dest_Free args, HOLogic.choice_const T $ xtp) |
85 val rhs = list_abs_free (map dest_Free args, HOLogic.choice_const T $ xtp) |
86 (*Forms a lambda-abstraction over the formal parameters*) |
86 (*Forms a lambda-abstraction over the formal parameters*) |
87 val (c, thy') = Sign.declare_const [Markup.property_internal] (cname, cT, NoSyn) thy |
87 val (c, thy') = Sign.declare_const [Markup.property_internal] (cname, cT, NoSyn) thy |
88 val cdef = cname ^ "_def" |
88 val cdef = cname ^ "_def" |
89 val thy'' = Theory.add_defs_i true false [(cdef, equals cT $ c $ rhs)] thy' |
89 val thy'' = Theory.add_defs_i true false [(cdef, equals cT $ c $ rhs)] thy' |
90 handle ERROR _ => raise Clausify_failure thy' |
|
91 val ax = Thm.get_axiom_i thy'' (Sign.full_name thy'' cdef) |
90 val ax = Thm.get_axiom_i thy'' (Sign.full_name thy'' cdef) |
92 in dec_sko (subst_bound (list_comb (c, args), p)) (ax :: axs, thy'') end |
91 in dec_sko (subst_bound (list_comb (c, args), p)) (ax :: axs, thy'') end |
93 | dec_sko (Const ("All", _) $ (xtp as Abs (a, T, p))) thx = |
92 | dec_sko (Const ("All", _) $ (xtp as Abs (a, T, p))) thx = |
94 (*Universal quant: insert a free variable into body and continue*) |
93 (*Universal quant: insert a free variable into body and continue*) |
95 let val fname = Name.variant (add_term_names (p, [])) a |
94 let val fname = Name.variant (add_term_names (p, [])) a |
371 val s = flatten_name name |
370 val s = flatten_name name |
372 val (defs, thy') = declare_skofuns s nnfth thy |
371 val (defs, thy') = declare_skofuns s nnfth thy |
373 val (cnfs, ctxt2) = Meson.make_cnf (map skolem_of_def defs) nnfth ctxt1 |
372 val (cnfs, ctxt2) = Meson.make_cnf (map skolem_of_def defs) nnfth ctxt1 |
374 val cnfs' = cnfs |> map combinators |> Variable.export ctxt2 ctxt0 |
373 val cnfs' = cnfs |> map combinators |> Variable.export ctxt2 ctxt0 |
375 |> Meson.finish_cnf |> map Thm.close_derivation |
374 |> Meson.finish_cnf |> map Thm.close_derivation |
376 in (cnfs', thy') end |
375 in (cnfs', thy') end) |
377 handle Clausify_failure thy_e => ([], thy_e)) (* FIXME !? *) |
|
378 end; |
376 end; |
379 |
377 |
380 (*The cache prevents repeated clausification of a theorem, and also repeated declaration of |
378 (*The cache prevents repeated clausification of a theorem, and also repeated declaration of |
381 Skolem functions.*) |
379 Skolem functions.*) |
382 structure ThmCache = TheoryDataFun |
380 structure ThmCache = TheoryDataFun |
449 |
447 |
450 (**** Convert all facts of the theory into clauses (ResClause.clause, or ResHolClause.clause) ****) |
448 (**** Convert all facts of the theory into clauses (ResClause.clause, or ResHolClause.clause) ****) |
451 |
449 |
452 (*Populate the clause cache using the supplied theorem. Return the clausal form |
450 (*Populate the clause cache using the supplied theorem. Return the clausal form |
453 and modified theory.*) |
451 and modified theory.*) |
454 fun skolem_cache_thm (name, th) thy = |
452 fun skolem_cache_thm name (i, th) thy = |
455 if bad_for_atp th then thy |
453 if bad_for_atp th then thy |
456 else |
454 else |
457 (case lookup_cache thy th of |
455 (case lookup_cache thy th of |
458 SOME _ => thy |
456 SOME _ => thy |
459 | NONE => |
457 | NONE => |
460 (case skolem (name, th) thy of |
458 (case skolem (name ^ "_" ^ string_of_int (i + 1), th) thy of |
461 NONE => thy |
459 NONE => thy |
462 | SOME (cls, thy') => update_cache (th, cls) thy')); |
460 | SOME (cls, thy') => update_cache (th, cls) thy')); |
463 |
461 |
464 fun skolem_cache_fact (name, ths) (changed, thy) = |
462 fun skolem_cache_fact (name, ths) (changed, thy) = |
465 if (Sign.base_name name) mem_string multi_base_blacklist orelse already_seen thy name |
463 if (Sign.base_name name) mem_string multi_base_blacklist orelse already_seen thy name |
466 then (changed, thy) |
464 then (changed, thy) |
467 else (true, thy |> mark_seen name |> fold skolem_cache_thm (PureThy.name_multi name ths)); |
465 else (true, thy |> mark_seen name |> fold_index (skolem_cache_thm name) ths); |
468 |
466 |
469 fun saturate_skolem_cache thy = |
467 fun saturate_skolem_cache thy = |
470 (case Facts.fold_static skolem_cache_fact (PureThy.facts_of thy) (false, thy) of |
468 (case Facts.fold_static skolem_cache_fact (PureThy.facts_of thy) (false, thy) of |
471 (false, _) => NONE |
469 (false, _) => NONE |
472 | (true, thy') => SOME thy'); |
470 | (true, thy') => SOME thy'); |