132 |
120 |
133 fun compact_comb t Bnds count_comb = |
121 fun compact_comb t Bnds count_comb = |
134 if !use_Turner then mk_compact_comb t Bnds count_comb else t; |
122 if !use_Turner then mk_compact_comb t Bnds count_comb else t; |
135 |
123 |
136 fun lam2comb (Abs(x,tp,Bound 0)) _ count_comb = |
124 fun lam2comb (Abs(x,tp,Bound 0)) _ count_comb = |
137 let val tpI = Type("fun",[tp,tp]) |
125 let val _ = increI count_comb |
138 val _ = increI count_comb |
|
139 in |
126 in |
140 Const("Reconstruction.COMBI",tpI) |
127 Const("Reconstruction.COMBI",tp-->tp) |
141 end |
128 end |
142 | lam2comb (Abs(x,tp,Bound n)) Bnds count_comb = |
129 | lam2comb (Abs(x,tp,Bound n)) Bnds count_comb = |
143 let val (Bound n') = decre_bndVar (Bound n) |
130 let val tb = List.nth(Bnds,n-1) |
144 val tb = List.nth(Bnds,n') |
|
145 val tK = Type("fun",[tb,Type("fun",[tp,tb])]) |
|
146 val _ = increK count_comb |
131 val _ = increK count_comb |
147 in |
132 in |
148 Const("Reconstruction.COMBK",tK) $ (Bound n') |
133 Const("Reconstruction.COMBK", [tb,tp] ---> tb) $ (Bound (n-1)) |
149 end |
134 end |
150 | lam2comb (Abs(x,t1,Const(c,t2))) _ count_comb = |
135 | lam2comb (Abs(x,t1,Const(c,t2))) _ count_comb = |
151 let val tK = Type("fun",[t2,Type("fun",[t1,t2])]) |
136 let val _ = increK count_comb |
152 val _ = increK count_comb |
|
153 in |
137 in |
154 Const("Reconstruction.COMBK",tK) $ Const(c,t2) |
138 Const("Reconstruction.COMBK",[t2,t1] ---> t2) $ Const(c,t2) |
155 end |
139 end |
156 | lam2comb (Abs(x,t1,Free(v,t2))) _ count_comb = |
140 | lam2comb (Abs(x,t1,Free(v,t2))) _ count_comb = |
157 let val tK = Type("fun",[t2,Type("fun",[t1,t2])]) |
141 let val _ = increK count_comb |
158 val _ = increK count_comb |
|
159 in |
142 in |
160 Const("Reconstruction.COMBK",tK) $ Free(v,t2) |
143 Const("Reconstruction.COMBK",[t2,t1] ---> t2) $ Free(v,t2) |
161 end |
144 end |
162 | lam2comb (Abs(x,t1,Var(ind,t2))) _ count_comb = |
145 | lam2comb (Abs(x,t1,Var(ind,t2))) _ count_comb = |
163 let val tK = Type("fun",[t2,Type("fun",[t1,t2])]) |
146 let val _ = increK count_comb |
164 val _ = increK count_comb |
|
165 in |
147 in |
166 Const("Reconstruction.COMBK",tK) $ Var(ind,t2) |
148 Const("Reconstruction.COMBK", [t2,t1] ---> t2) $ Var(ind,t2) |
167 end |
149 end |
168 | lam2comb (t as (Abs(x,t1,P$(Bound 0)))) Bnds count_comb = |
150 | lam2comb (t as (Abs(x,t1,P$(Bound 0)))) Bnds count_comb = |
169 let val nfreeP = not(is_free P 0) |
151 let val tr = Term.type_of1(t1::Bnds,P) |
170 val tr = Term.type_of1(t1::Bnds,P) |
|
171 in |
152 in |
172 if nfreeP then (decre_bndVar P) |
153 if not(is_free P 0) then (incr_boundvars ~1 P) |
173 else |
154 else |
174 let val tI = Type("fun",[t1,t1]) |
155 let val tI = [t1] ---> t1 |
175 val P' = lam2comb (Abs(x,t1,P)) Bnds count_comb |
156 val P' = lam2comb (Abs(x,t1,P)) Bnds count_comb |
176 val tp' = Term.type_of1(Bnds,P') |
157 val tp' = Term.type_of1(Bnds,P') |
177 val tS = Type("fun",[tp',Type("fun",[tI,tr])]) |
158 val tS = [tp',tI] ---> tr |
178 val _ = increI count_comb |
159 val _ = increI count_comb |
179 val _ = increS count_comb |
160 val _ = increS count_comb |
180 in |
161 in |
181 compact_comb (Const("Reconstruction.COMBS",tS) $ P' $ Const("Reconstruction.COMBI",tI)) Bnds count_comb |
162 compact_comb (Const("Reconstruction.COMBS",tS) $ P' $ |
|
163 Const("Reconstruction.COMBI",tI)) Bnds count_comb |
182 end |
164 end |
183 end |
165 end |
184 |
|
185 | lam2comb (t as (Abs(x,t1,P$Q))) Bnds count_comb = |
166 | lam2comb (t as (Abs(x,t1,P$Q))) Bnds count_comb = |
186 let val nfreeP = not(is_free P 0) |
167 let val nfreeP = not(is_free P 0) |
187 and nfreeQ = not(is_free Q 0) |
168 and nfreeQ = not(is_free Q 0) |
188 val tpq = Term.type_of1(t1::Bnds, P$Q) |
169 val tpq = Term.type_of1(t1::Bnds, P$Q) |
189 in |
170 in |
190 if nfreeP andalso nfreeQ |
171 if nfreeP andalso nfreeQ |
191 then |
172 then |
192 let val tK = Type("fun",[tpq,Type("fun",[t1,tpq])]) |
173 let val tK = [tpq,t1] ---> tpq |
193 val PQ' = decre_bndVar(P $ Q) |
174 val PQ' = incr_boundvars ~1(P $ Q) |
194 val _ = increK count_comb |
175 val _ = increK count_comb |
195 in |
176 in |
196 Const("Reconstruction.COMBK",tK) $ PQ' |
177 Const("Reconstruction.COMBK",tK) $ PQ' |
197 end |
178 end |
198 else if nfreeP then |
179 else if nfreeP then |
199 let val Q' = lam2comb (Abs(x,t1,Q)) Bnds count_comb |
180 let val Q' = lam2comb (Abs(x,t1,Q)) Bnds count_comb |
200 val P' = decre_bndVar P |
181 val P' = incr_boundvars ~1 P |
201 val tp = Term.type_of1(Bnds,P') |
182 val tp = Term.type_of1(Bnds,P') |
202 val tq' = Term.type_of1(Bnds, Q') |
183 val tq' = Term.type_of1(Bnds, Q') |
203 val tB = Type("fun",[tp,Type("fun",[tq',Type("fun",[t1,tpq])])]) |
184 val tB = [tp,tq',t1] ---> tpq |
204 val _ = increB count_comb |
185 val _ = increB count_comb |
205 in |
186 in |
206 compact_comb (Const("Reconstruction.COMBB",tB) $ P' $ Q') Bnds count_comb |
187 compact_comb (Const("Reconstruction.COMBB",tB) $ P' $ Q') Bnds count_comb |
207 end |
188 end |
208 else if nfreeQ then |
189 else if nfreeQ then |
209 let val P' = lam2comb (Abs(x,t1,P)) Bnds count_comb |
190 let val P' = lam2comb (Abs(x,t1,P)) Bnds count_comb |
210 val Q' = decre_bndVar Q |
191 val Q' = incr_boundvars ~1 Q |
211 val tq = Term.type_of1(Bnds,Q') |
192 val tq = Term.type_of1(Bnds,Q') |
212 val tp' = Term.type_of1(Bnds, P') |
193 val tp' = Term.type_of1(Bnds, P') |
213 val tC = Type("fun",[tp',Type("fun",[tq,Type("fun",[t1,tpq])])]) |
194 val tC = [tp',tq,t1] ---> tpq |
214 val _ = increC count_comb |
195 val _ = increC count_comb |
215 in |
196 in |
216 compact_comb (Const("Reconstruction.COMBC",tC) $ P' $ Q') Bnds count_comb |
197 compact_comb (Const("Reconstruction.COMBC",tC) $ P' $ Q') Bnds count_comb |
217 end |
198 end |
218 else |
199 else |
219 let val P' = lam2comb (Abs(x,t1,P)) Bnds count_comb |
200 let val P' = lam2comb (Abs(x,t1,P)) Bnds count_comb |
220 val Q' = lam2comb (Abs(x,t1,Q)) Bnds count_comb |
201 val Q' = lam2comb (Abs(x,t1,Q)) Bnds count_comb |
221 val tp' = Term.type_of1(Bnds,P') |
202 val tp' = Term.type_of1(Bnds,P') |
222 val tq' = Term.type_of1(Bnds,Q') |
203 val tq' = Term.type_of1(Bnds,Q') |
223 val tS = Type("fun",[tp',Type("fun",[tq',Type("fun",[t1,tpq])])]) |
204 val tS = [tp',tq',t1] ---> tpq |
224 val _ = increS count_comb |
205 val _ = increS count_comb |
225 in |
206 in |
226 compact_comb (Const("Reconstruction.COMBS",tS) $ P' $ Q') Bnds count_comb |
207 compact_comb (Const("Reconstruction.COMBS",tS) $ P' $ Q') Bnds count_comb |
227 end |
208 end |
228 end |
209 end |
442 | occurs _ _ = false |
423 | occurs _ _ = false |
443 |
424 |
444 fun too_general_terms (CombVar(v,_), t) = not (occurs v t) |
425 fun too_general_terms (CombVar(v,_), t) = not (occurs v t) |
445 | too_general_terms _ = false; |
426 | too_general_terms _ = false; |
446 |
427 |
447 fun too_general_lit (Literal(true,(Bool(CombApp(CombApp(CombConst("equal",tp,tps),t1,tp1),t2,tp2))))) = |
428 fun too_general_equality (Literal(true,(Bool(CombApp(CombApp(CombConst("equal",tp,tps),t1,tp1),t2,tp2))))) = |
448 too_general_terms (t1,t2) orelse too_general_terms (t2,t1) |
429 too_general_terms (t1,t2) orelse too_general_terms (t2,t1) |
449 | too_general_lit _ = false; |
430 | too_general_equality _ = false; |
450 |
431 |
451 (* forbid a clause that contains hBOOL(V) *) |
432 (* forbid the literal hBOOL(V) *) |
452 fun too_general [] = false |
433 fun too_general_bool (Literal(_,Bool(CombVar _))) = true |
453 | too_general (lit::lits) = |
434 | too_general_bool _ = false; |
454 case lit of Literal(_,Bool(CombVar(_,_))) => true |
|
455 | _ => too_general lits; |
|
456 |
435 |
457 (* making axiom and conjecture clauses *) |
436 (* making axiom and conjecture clauses *) |
458 exception MAKE_CLAUSE |
437 exception MAKE_CLAUSE |
459 fun make_clause(clause_id,axiom_name,kind,thm,is_user) = |
438 fun make_clause(clause_id,axiom_name,kind,thm,is_user) = |
460 let val term = prop_of thm |
439 let val term = prop_of thm |
543 end |
519 end |
544 | string_of_combterm1_aux is_pred (CombApp(t1,t2,tp)) = |
520 | string_of_combterm1_aux is_pred (CombApp(t1,t2,tp)) = |
545 let val (s1,tp1) = string_of_combterm1_aux is_pred t1 |
521 let val (s1,tp1) = string_of_combterm1_aux is_pred t1 |
546 val (s2,tp2) = string_of_combterm1_aux is_pred t2 |
522 val (s2,tp2) = string_of_combterm1_aux is_pred t2 |
547 val tp' = ResClause.string_of_fol_type tp |
523 val tp' = ResClause.string_of_fol_type tp |
548 val r = case !typ_level of T_FULL => type_wrapper ^ (ResClause.paren_pack [(app_str ^ (ResClause.paren_pack [s1,s2])),tp']) |
524 val r = case !typ_level of |
549 | T_PARTIAL => app_str ^ (ResClause.paren_pack [s1,s2,tp1]) |
525 T_FULL => type_wrapper ^ ResClause.paren_pack [(app_str ^ ResClause.paren_pack [s1,s2]),tp'] |
550 | T_NONE => app_str ^ (ResClause.paren_pack [s1,s2]) |
526 | T_PARTIAL => app_str ^ ResClause.paren_pack [s1,s2,tp1] |
551 | T_CONST => raise STRING_OF_COMBTERM (1) (*should not happen, if happened may be a bug*) |
527 | T_NONE => app_str ^ ResClause.paren_pack [s1,s2] |
552 in (r,tp') |
528 | T_CONST => raise STRING_OF_COMBTERM 1 (*should not happen, if happened may be a bug*) |
553 |
529 in (r,tp') end |
554 end |
|
555 | string_of_combterm1_aux is_pred (Bool(CombApp(CombApp(CombConst("equal",tp,tps),t1,tp1),t2,tp2))) = |
530 | string_of_combterm1_aux is_pred (Bool(CombApp(CombApp(CombConst("equal",tp,tps),t1,tp1),t2,tp2))) = |
556 if is_pred then |
531 if is_pred then |
557 let val (s1,_) = string_of_combterm1_aux false t1 |
532 let val (s1,_) = string_of_combterm1_aux false t1 |
558 val (s2,_) = string_of_combterm1_aux false t2 |
533 val (s2,_) = string_of_combterm1_aux false t2 |
559 in |
534 in |
560 ("equal" ^ (ResClause.paren_pack [s1,s2]),bool_tp) |
535 ("equal" ^ ResClause.paren_pack [s1,s2], bool_tp) |
561 end |
536 end |
562 else |
537 else |
563 let val (t,_) = string_of_combterm1_aux false (CombApp(CombApp(CombConst("equal",tp,tps),t1,tp1),t2,tp2)) |
538 let val (t,_) = string_of_combterm1_aux false (CombApp(CombApp(CombConst("equal",tp,tps),t1,tp1),t2,tp2)) |
564 in |
539 in |
565 (t,bool_tp) |
540 (t,bool_tp) |
566 end |
541 end |
567 | string_of_combterm1_aux is_pred (Bool(t)) = |
542 | string_of_combterm1_aux is_pred (Bool(t)) = |
568 let val (t',_) = string_of_combterm1_aux false t |
543 let val (t',_) = string_of_combterm1_aux false t |
569 val r = if is_pred then bool_str ^ (ResClause.paren_pack [t']) |
544 val r = if is_pred then bool_str ^ ResClause.paren_pack [t'] |
570 else t' |
545 else t' |
571 in |
546 in |
572 (r,bool_tp) |
547 (r,bool_tp) |
573 end; |
548 end; |
574 |
549 |
576 |
551 |
577 fun string_of_combterm2 _ (CombConst(c,tp,tvars)) = |
552 fun string_of_combterm2 _ (CombConst(c,tp,tvars)) = |
578 let val tvars' = map string_of_ctyp tvars |
553 let val tvars' = map string_of_ctyp tvars |
579 val c' = if c = "equal" then "c_fequal" else c |
554 val c' = if c = "equal" then "c_fequal" else c |
580 in |
555 in |
581 c' ^ (ResClause.paren_pack tvars') |
556 c' ^ ResClause.paren_pack tvars' |
582 end |
557 end |
583 | string_of_combterm2 _ (CombFree(v,tp)) = v |
558 | string_of_combterm2 _ (CombFree(v,tp)) = v |
584 | string_of_combterm2 _ (CombVar(v,tp)) = v |
559 | string_of_combterm2 _ (CombVar(v,tp)) = v |
585 | string_of_combterm2 is_pred (CombApp(t1,t2,tp)) = |
560 | string_of_combterm2 is_pred (CombApp(t1,t2,tp)) = |
586 let val s1 = string_of_combterm2 is_pred t1 |
561 let val s1 = string_of_combterm2 is_pred t1 |
587 val s2 = string_of_combterm2 is_pred t2 |
562 val s2 = string_of_combterm2 is_pred t2 |
588 in |
563 in |
589 app_str ^ (ResClause.paren_pack [s1,s2]) |
564 app_str ^ ResClause.paren_pack [s1,s2] |
590 end |
565 end |
591 | string_of_combterm2 is_pred (Bool(CombApp(CombApp(CombConst("equal",tp,tps),t1,tp1),t2,tp2))) = |
566 | string_of_combterm2 is_pred (Bool(CombApp(CombApp(CombConst("equal",tp,tps),t1,tp1),t2,tp2))) = |
592 if is_pred then |
567 if is_pred then |
593 let val s1 = string_of_combterm2 false t1 |
568 let val s1 = string_of_combterm2 false t1 |
594 val s2 = string_of_combterm2 false t2 |
569 val s2 = string_of_combterm2 false t2 |
595 in |
570 in |
596 ("equal" ^ (ResClause.paren_pack [s1,s2])) |
571 ("equal" ^ ResClause.paren_pack [s1,s2]) |
597 end |
572 end |
598 else |
573 else |
599 string_of_combterm2 false (CombApp(CombApp(CombConst("equal",tp,tps),t1,tp1),t2,tp2)) |
574 string_of_combterm2 false (CombApp(CombApp(CombConst("equal",tp,tps),t1,tp1),t2,tp2)) |
600 |
575 |
601 | string_of_combterm2 is_pred (Bool(t)) = |
576 | string_of_combterm2 is_pred (Bool(t)) = |
602 let val t' = string_of_combterm2 false t |
577 let val t' = string_of_combterm2 false t |
603 in |
578 in |
604 if is_pred then bool_str ^ (ResClause.paren_pack [t']) |
579 if is_pred then bool_str ^ ResClause.paren_pack [t'] |
605 else t' |
580 else t' |
606 end; |
581 end; |
607 |
|
608 |
|
609 |
582 |
610 fun string_of_combterm is_pred term = |
583 fun string_of_combterm is_pred term = |
611 case !typ_level of T_CONST => string_of_combterm2 is_pred term |
584 case !typ_level of T_CONST => string_of_combterm2 is_pred term |
612 | _ => string_of_combterm1 is_pred term; |
585 | _ => string_of_combterm1 is_pred term; |
613 |
|
614 |
586 |
615 fun string_of_clausename (cls_id,ax_name) = |
587 fun string_of_clausename (cls_id,ax_name) = |
616 ResClause.clause_prefix ^ ResClause.ascii_of ax_name ^ "_" ^ Int.toString cls_id; |
588 ResClause.clause_prefix ^ ResClause.ascii_of ax_name ^ "_" ^ Int.toString cls_id; |
617 |
589 |
618 fun string_of_type_clsname (cls_id,ax_name,idx) = |
590 fun string_of_type_clsname (cls_id,ax_name,idx) = |
735 |
707 |
736 (**********************************************************************) |
708 (**********************************************************************) |
737 (* write clauses to files *) |
709 (* write clauses to files *) |
738 (**********************************************************************) |
710 (**********************************************************************) |
739 |
711 |
740 local |
|
741 |
|
742 val cnf_helper_thms = ResAxioms.cnf_rules_pairs o (map ResAxioms.pairname) |
712 val cnf_helper_thms = ResAxioms.cnf_rules_pairs o (map ResAxioms.pairname) |
743 |
713 |
744 in |
714 (*Simulate the result of conversion to CNF*) |
|
715 fun pretend_cnf s = (thm s, (s,0)); |
|
716 |
|
717 (*These theorems allow the proof of P=Q from P-->Q and Q-->P, so they are necessary for |
|
718 completeness. Unfortunately, they are very prolific, causing greatly increased runtimes. |
|
719 They also lead to many unsound proofs. Thus it is well that the "exists too_general_bool" |
|
720 test deletes them except with the full-typed translation.*) |
|
721 val iff_thms = [pretend_cnf "Reconstruction.iff_positive", |
|
722 pretend_cnf "Reconstruction.iff_negative"]; |
745 |
723 |
746 fun get_helper_clauses () = |
724 fun get_helper_clauses () = |
747 let val IK = if !combI_count > 0 orelse !combK_count > 0 then (Output.debug "Include combinator I K"; cnf_helper_thms [comb_I,comb_K]) else [] |
725 let val IK = if !combI_count > 0 orelse !combK_count > 0 |
748 val BC = if !combB_count > 0 orelse !combC_count > 0 then (Output.debug "Include combinator B C"; cnf_helper_thms [comb_B,comb_C]) else [] |
726 then (Output.debug "Include combinator I K"; cnf_helper_thms [comb_I,comb_K]) |
749 val S = if !combS_count > 0 then (Output.debug "Include combinator S"; cnf_helper_thms [comb_S]) else [] |
727 else [] |
750 val B'C' = if !combB'_count > 0 orelse !combC'_count > 0 then (Output.debug "Include combinator B' C'"; cnf_helper_thms [comb_B', comb_C']) else [] |
728 val BC = if !combB_count > 0 orelse !combC_count > 0 |
751 val S' = if !combS'_count > 0 then (Output.debug "Include combinator S'"; cnf_helper_thms [comb_S']) else [] |
729 then (Output.debug "Include combinator B C"; cnf_helper_thms [comb_B,comb_C]) |
|
730 else [] |
|
731 val S = if !combS_count > 0 |
|
732 then (Output.debug "Include combinator S"; cnf_helper_thms [comb_S]) |
|
733 else [] |
|
734 val B'C' = if !combB'_count > 0 orelse !combC'_count > 0 |
|
735 then (Output.debug "Include combinator B' C'"; cnf_helper_thms [comb_B', comb_C']) |
|
736 else [] |
|
737 val S' = if !combS'_count > 0 |
|
738 then (Output.debug "Include combinator S'"; cnf_helper_thms [comb_S']) |
|
739 else [] |
752 val other = cnf_helper_thms [ext,fequal_imp_equal,equal_imp_fequal] |
740 val other = cnf_helper_thms [ext,fequal_imp_equal,equal_imp_fequal] |
753 in |
741 in |
754 make_axiom_clauses (other @ IK @ BC @ S @ B'C' @ S') [] |
742 make_axiom_clauses (iff_thms @ other @ IK @ BC @ S @ B'C' @ S') [] |
755 end |
743 end |
756 |
744 |
757 end |
|
758 |
745 |
759 (* tptp format *) |
746 (* tptp format *) |
760 |
747 |
761 (* write TPTP format to a single file *) |
748 (* write TPTP format to a single file *) |
762 (* when "get_helper_clauses" is called, "include_combS" and "include_min_comb" should have correct values already *) |
749 (* when "get_helper_clauses" is called, "include_combS" and "include_min_comb" should have correct values already *) |