156 (* print a term containing combinators, used for debugging *) |
156 (* print a term containing combinators, used for debugging *) |
157 exception TERM_COMB of term; |
157 exception TERM_COMB of term; |
158 |
158 |
159 fun string_of_term (Const(c,t)) = c |
159 fun string_of_term (Const(c,t)) = c |
160 | string_of_term (Free(v,t)) = v |
160 | string_of_term (Free(v,t)) = v |
161 | string_of_term (Var((x,n),t)) = |
161 | string_of_term (Var((x,n),t)) = x ^ "_" ^ (string_of_int n) |
162 let val xn = x ^ "_" ^ (string_of_int n) |
|
163 in xn end |
|
164 | string_of_term (P $ Q) = |
162 | string_of_term (P $ Q) = |
165 let val P' = string_of_term P |
163 "(" ^ string_of_term P ^ " " ^ string_of_term Q ^ ")" |
166 val Q' = string_of_term Q |
|
167 in |
|
168 "(" ^ P' ^ " " ^ Q' ^ ")" end |
|
169 | string_of_term t = raise TERM_COMB (t); |
164 | string_of_term t = raise TERM_COMB (t); |
170 |
165 |
171 |
166 |
172 |
167 |
173 (******************************************************) |
168 (******************************************************) |
208 datatype combterm = CombConst of string * ctyp * ctyp list |
204 datatype combterm = CombConst of string * ctyp * ctyp list |
209 | CombFree of string * ctyp |
205 | CombFree of string * ctyp |
210 | CombVar of string * ctyp |
206 | CombVar of string * ctyp |
211 | CombApp of combterm * combterm * ctyp |
207 | CombApp of combterm * combterm * ctyp |
212 | Bool of combterm; |
208 | Bool of combterm; |
|
209 |
213 datatype literal = Literal of polarity * combterm; |
210 datatype literal = Literal of polarity * combterm; |
214 |
|
215 |
|
216 |
211 |
217 datatype clause = |
212 datatype clause = |
218 Clause of {clause_id: clause_id, |
213 Clause of {clause_id: clause_id, |
219 axiom_name: axiom_name, |
214 axiom_name: axiom_name, |
220 th: thm, |
215 th: thm, |
223 ctypes_sorts: (ctyp_var * csort) list, |
218 ctypes_sorts: (ctyp_var * csort) list, |
224 ctvar_type_literals: ctype_literal list, |
219 ctvar_type_literals: ctype_literal list, |
225 ctfree_type_literals: ctype_literal list}; |
220 ctfree_type_literals: ctype_literal list}; |
226 |
221 |
227 |
222 |
228 |
|
229 fun string_of_kind (Clause cls) = name_of_kind (#kind cls); |
223 fun string_of_kind (Clause cls) = name_of_kind (#kind cls); |
230 fun get_axiomName (Clause cls) = #axiom_name cls; |
224 fun get_axiomName (Clause cls) = #axiom_name cls; |
231 fun get_clause_id (Clause cls) = #clause_id cls; |
225 fun get_clause_id (Clause cls) = #clause_id cls; |
232 |
226 |
233 fun get_literals (c as Clause(cls)) = #literals cls; |
227 fun get_literals (c as Clause(cls)) = #literals cls; |
236 (*********************************************************************) |
230 (*********************************************************************) |
237 (* convert a clause with type Term.term to a clause with type clause *) |
231 (* convert a clause with type Term.term to a clause with type clause *) |
238 (*********************************************************************) |
232 (*********************************************************************) |
239 |
233 |
240 fun isFalse (Literal(pol,Bool(CombConst(c,_,_)))) = |
234 fun isFalse (Literal(pol,Bool(CombConst(c,_,_)))) = |
241 (pol andalso c = "c_False") orelse |
235 (pol andalso c = "c_False") orelse |
242 (not pol andalso c = "c_True") |
236 (not pol andalso c = "c_True") |
243 | isFalse _ = false; |
237 | isFalse _ = false; |
244 |
238 |
245 |
239 |
246 fun isTrue (Literal (pol,Bool(CombConst(c,_,_)))) = |
240 fun isTrue (Literal (pol,Bool(CombConst(c,_,_)))) = |
247 (pol andalso c = "c_True") orelse |
241 (pol andalso c = "c_True") orelse |
427 | occurs _ _ = false |
421 | occurs _ _ = false |
428 |
422 |
429 fun too_general_terms (CombVar(v,_), t) = not (occurs v t) |
423 fun too_general_terms (CombVar(v,_), t) = not (occurs v t) |
430 | too_general_terms _ = false; |
424 | too_general_terms _ = false; |
431 |
425 |
432 fun too_general_lit (Literal(true,(Bool(CombApp(CombApp(CombConst("equal",tp,tps),t1,tp1),t2,tp2))))) = too_general_terms (t1,t2) orelse too_general_terms (t2,t1) |
426 fun too_general_lit (Literal(true,(Bool(CombApp(CombApp(CombConst("equal",tp,tps),t1,tp1),t2,tp2))))) = |
|
427 too_general_terms (t1,t2) orelse too_general_terms (t2,t1) |
433 | too_general_lit _ = false; |
428 | too_general_lit _ = false; |
434 |
429 |
435 (* forbid a clause that contains hBOOL(V) *) |
430 (* forbid a clause that contains hBOOL(V) *) |
436 fun too_general [] = false |
431 fun too_general [] = false |
437 | too_general (lit::lits) = |
432 | too_general (lit::lits) = |
446 val (lits,ctypes_sorts) = literals_of_term term' |
441 val (lits,ctypes_sorts) = literals_of_term term' |
447 val (ctvar_lits,ctfree_lits) = ResClause.add_typs_aux ctypes_sorts |
442 val (ctvar_lits,ctfree_lits) = ResClause.add_typs_aux ctypes_sorts |
448 in |
443 in |
449 if forall isFalse lits |
444 if forall isFalse lits |
450 then error "Problem too trivial for resolution (empty clause)" |
445 then error "Problem too trivial for resolution (empty clause)" |
451 else if too_general lits then (Output.debug ("Omitting " ^ axiom_name ^ ": clause contains universal predicates"); raise MAKE_CLAUSE) |
446 else if too_general lits |
|
447 then (Output.debug ("Omitting " ^ axiom_name ^ ": clause contains universal predicates"); |
|
448 raise MAKE_CLAUSE) |
452 else |
449 else |
453 if (!typ_level <> T_FULL) andalso kind=Axiom andalso forall too_general_lit lits |
450 if (!typ_level <> T_FULL) andalso kind=Axiom andalso forall too_general_lit lits |
454 then (Output.debug ("Omitting " ^ axiom_name ^ ": equalities are too general"); raise MAKE_CLAUSE) |
451 then (Output.debug ("Omitting " ^ axiom_name ^ ": equalities are too general"); |
|
452 raise MAKE_CLAUSE) |
455 else |
453 else |
456 Clause {clause_id = clause_id, axiom_name = axiom_name, th = thm, kind = kind, |
454 Clause {clause_id = clause_id, axiom_name = axiom_name, th = thm, kind = kind, |
457 literals = lits, ctypes_sorts = ctypes_sorts, |
455 literals = lits, ctypes_sorts = ctypes_sorts, |
458 ctvar_type_literals = ctvar_lits, |
456 ctvar_type_literals = ctvar_lits, |
459 ctfree_type_literals = ctfree_lits} |
457 ctfree_type_literals = ctfree_lits} |
460 end; |
458 end; |
461 |
459 |
462 |
460 |
463 fun make_axiom_clause thm (ax_name,cls_id,is_user) = make_clause(cls_id,ax_name,Axiom,thm,is_user); |
461 fun make_axiom_clause thm (ax_name,cls_id,is_user) = |
|
462 make_clause(cls_id,ax_name,Axiom,thm,is_user); |
464 |
463 |
465 fun make_axiom_clauses [] user_lemmas = [] |
464 fun make_axiom_clauses [] user_lemmas = [] |
466 | make_axiom_clauses ((thm,(name,id))::thms) user_lemmas = |
465 | make_axiom_clauses ((thm,(name,id))::thms) user_lemmas = |
467 let val is_user = name mem user_lemmas |
466 let val is_user = name mem user_lemmas |
468 val cls = SOME (make_axiom_clause thm (name,id,is_user)) handle MAKE_CLAUSE => NONE |
467 val cls = SOME (make_axiom_clause thm (name,id,is_user)) |
|
468 handle MAKE_CLAUSE => NONE |
469 val clss = make_axiom_clauses thms user_lemmas |
469 val clss = make_axiom_clauses thms user_lemmas |
470 in |
470 in |
471 case cls of NONE => clss |
471 case cls of NONE => clss |
472 | SOME(cls') => if isTaut cls' then clss else (name,cls')::clss |
472 | SOME(cls') => if isTaut cls' then clss |
473 end; |
473 else (name,cls')::clss |
474 |
474 end; |
475 |
475 |
476 fun make_conjecture_clause n thm = make_clause(n,"conjecture",Conjecture,thm,true); |
476 |
|
477 fun make_conjecture_clause n thm = |
|
478 make_clause(n,"conjecture",Conjecture,thm,true); |
477 |
479 |
478 |
480 |
479 fun make_conjecture_clauses_aux _ [] = [] |
481 fun make_conjecture_clauses_aux _ [] = [] |
480 | make_conjecture_clauses_aux n (t::ts) = |
482 | make_conjecture_clauses_aux n (t::ts) = |
481 make_conjecture_clause n t :: make_conjecture_clauses_aux (n+1) ts; |
483 make_conjecture_clause n t :: make_conjecture_clauses_aux (n+1) ts; |
611 |
613 |
612 fun tptp_type_lits (Clause cls) = |
614 fun tptp_type_lits (Clause cls) = |
613 let val lits = map tptp_literal (#literals cls) |
615 let val lits = map tptp_literal (#literals cls) |
614 val ctvar_lits_strs = |
616 val ctvar_lits_strs = |
615 case !typ_level of T_NONE => [] |
617 case !typ_level of T_NONE => [] |
616 | _ => (map ResClause.tptp_of_typeLit (#ctvar_type_literals cls)) |
618 | _ => map ResClause.tptp_of_typeLit (#ctvar_type_literals cls) |
617 val ctfree_lits = |
619 val ctfree_lits = |
618 case !typ_level of T_NONE => [] |
620 case !typ_level of T_NONE => [] |
619 | _ => (map ResClause.tptp_of_typeLit (#ctfree_type_literals cls)) |
621 | _ => map ResClause.tptp_of_typeLit (#ctfree_type_literals cls) |
620 in |
622 in |
621 (ctvar_lits_strs @ lits, ctfree_lits) |
623 (ctvar_lits_strs @ lits, ctfree_lits) |
622 end; |
624 end; |
623 |
625 |
624 |
626 |
640 fun dfg_clause_aux (Clause{literals, ctypes_sorts, ...}) = |
642 fun dfg_clause_aux (Clause{literals, ctypes_sorts, ...}) = |
641 let val lits = map dfg_literal literals |
643 let val lits = map dfg_literal literals |
642 val (tvar_lits,tfree_lits) = ResClause.add_typs_aux ctypes_sorts |
644 val (tvar_lits,tfree_lits) = ResClause.add_typs_aux ctypes_sorts |
643 val tvar_lits_strs = |
645 val tvar_lits_strs = |
644 case !typ_level of T_NONE => [] |
646 case !typ_level of T_NONE => [] |
645 | _ => map ResClause.dfg_of_typeLit tvar_lits |
647 | _ => map ResClause.dfg_of_typeLit tvar_lits |
646 val tfree_lits = |
648 val tfree_lits = |
647 case !typ_level of T_NONE => [] |
649 case !typ_level of T_NONE => [] |
648 | _ => map ResClause.dfg_of_typeLit tfree_lits |
650 | _ => map ResClause.dfg_of_typeLit tfree_lits |
649 in |
651 in |
650 (tvar_lits_strs @ lits, tfree_lits) |
652 (tvar_lits_strs @ lits, tfree_lits) |
651 end; |
653 end; |
652 |
654 |
653 fun get_uvars (CombConst(_,_,_)) vars = vars |
655 fun get_uvars (CombConst(_,_,_)) vars = vars |
671 in (cls_str, tfree_lits) end; |
673 in (cls_str, tfree_lits) end; |
672 |
674 |
673 |
675 |
674 fun init_combs (comb,funcs) = |
676 fun init_combs (comb,funcs) = |
675 case !typ_level of T_CONST => |
677 case !typ_level of T_CONST => |
676 (case comb of "c_COMBK" => Symtab.update (comb,2) funcs |
678 (case comb of "c_COMBK" => Symtab.update (comb,2) funcs |
677 | "c_COMBS" => Symtab.update (comb,3) funcs |
679 | "c_COMBS" => Symtab.update (comb,3) funcs |
678 | "c_COMBI" => Symtab.update (comb,1) funcs |
680 | "c_COMBI" => Symtab.update (comb,1) funcs |
679 | "c_COMBB" => Symtab.update (comb,3) funcs |
681 | "c_COMBB" => Symtab.update (comb,3) funcs |
680 | "c_COMBC" => Symtab.update (comb,3) funcs |
682 | "c_COMBC" => Symtab.update (comb,3) funcs |
681 | _ => funcs) |
683 | _ => funcs) |
682 | _ => Symtab.update (comb,0) funcs; |
684 | _ => Symtab.update (comb,0) funcs; |
683 |
685 |
684 fun init_funcs_tab funcs = |
686 fun init_funcs_tab funcs = |
685 let val tp = !typ_level |
687 let val tp = !typ_level |
686 val funcs0 = foldl init_combs funcs ["c_COMBK","c_COMBS","c_COMBI","c_COMBB","c_COMBC"] |
688 val funcs0 = foldl init_combs funcs ["c_COMBK","c_COMBS","c_COMBI","c_COMBB","c_COMBC"] |
687 val funcs1 = case tp of T_PARTIAL => Symtab.update ("hAPP",3) funcs0 |
689 val funcs1 = case tp of T_PARTIAL => Symtab.update ("hAPP",3) funcs0 |