115 open ATP_Util |
115 open ATP_Util |
116 open ATP_Problem |
116 open ATP_Problem |
117 |
117 |
118 type name = string * string |
118 type name = string * string |
119 |
119 |
|
120 datatype scope = Global | Local | Assum | Chained |
|
121 datatype status = General | Induction | Intro | Inductive | Elim | Simp | Def |
|
122 type stature = scope * status |
|
123 |
|
124 datatype order = |
|
125 First_Order | |
|
126 Higher_Order of thf_flavor |
|
127 datatype polymorphism = Polymorphic | Raw_Monomorphic | Mangled_Monomorphic |
|
128 datatype strictness = Strict | Non_Strict |
|
129 datatype granularity = All_Vars | Positively_Naked_Vars | Ghost_Type_Arg_Vars |
|
130 datatype type_level = |
|
131 All_Types | |
|
132 Noninf_Nonmono_Types of strictness * granularity | |
|
133 Fin_Nonmono_Types of granularity | |
|
134 Const_Arg_Types | |
|
135 No_Types |
|
136 |
|
137 datatype type_enc = |
|
138 Native of order * polymorphism * type_level | |
|
139 Guards of polymorphism * type_level | |
|
140 Tags of polymorphism * type_level |
|
141 |
|
142 fun is_type_enc_native (Native _) = true |
|
143 | is_type_enc_native _ = false |
|
144 fun is_type_enc_higher_order (Native (Higher_Order _, _, _)) = true |
|
145 | is_type_enc_higher_order _ = false |
|
146 |
|
147 fun polymorphism_of_type_enc (Native (_, poly, _)) = poly |
|
148 | polymorphism_of_type_enc (Guards (poly, _)) = poly |
|
149 | polymorphism_of_type_enc (Tags (poly, _)) = poly |
|
150 |
|
151 fun level_of_type_enc (Native (_, _, level)) = level |
|
152 | level_of_type_enc (Guards (_, level)) = level |
|
153 | level_of_type_enc (Tags (_, level)) = level |
|
154 |
|
155 fun granularity_of_type_level (Noninf_Nonmono_Types (_, grain)) = grain |
|
156 | granularity_of_type_level (Fin_Nonmono_Types grain) = grain |
|
157 | granularity_of_type_level _ = All_Vars |
|
158 |
|
159 fun is_type_level_quasi_sound All_Types = true |
|
160 | is_type_level_quasi_sound (Noninf_Nonmono_Types _) = true |
|
161 | is_type_level_quasi_sound _ = false |
|
162 val is_type_enc_quasi_sound = is_type_level_quasi_sound o level_of_type_enc |
|
163 |
|
164 fun is_type_level_fairly_sound (Fin_Nonmono_Types _) = true |
|
165 | is_type_level_fairly_sound level = is_type_level_quasi_sound level |
|
166 val is_type_enc_fairly_sound = is_type_level_fairly_sound o level_of_type_enc |
|
167 |
|
168 fun is_type_level_monotonicity_based (Noninf_Nonmono_Types _) = true |
|
169 | is_type_level_monotonicity_based (Fin_Nonmono_Types _) = true |
|
170 | is_type_level_monotonicity_based _ = false |
|
171 |
120 val no_lamsN = "no_lams" (* used internally; undocumented *) |
172 val no_lamsN = "no_lams" (* used internally; undocumented *) |
121 val hide_lamsN = "hide_lams" |
173 val hide_lamsN = "hide_lams" |
122 val liftingN = "lifting" |
174 val liftingN = "lifting" |
123 val combsN = "combs" |
175 val combsN = "combs" |
124 val combs_and_liftingN = "combs_and_lifting" |
176 val combs_and_liftingN = "combs_and_lifting" |
516 else |
568 else |
517 (s, T) |> Sign.const_typargs thy |
569 (s, T) |> Sign.const_typargs thy |
518 |
570 |
519 (* Converts an Isabelle/HOL term (with combinators) into an intermediate term. |
571 (* Converts an Isabelle/HOL term (with combinators) into an intermediate term. |
520 Also accumulates sort infomation. *) |
572 Also accumulates sort infomation. *) |
521 fun iterm_from_term thy format bs (P $ Q) = |
573 fun iterm_from_term thy type_enc bs (P $ Q) = |
522 let |
574 let |
523 val (P', P_atomics_Ts) = iterm_from_term thy format bs P |
575 val (P', P_atomics_Ts) = iterm_from_term thy type_enc bs P |
524 val (Q', Q_atomics_Ts) = iterm_from_term thy format bs Q |
576 val (Q', Q_atomics_Ts) = iterm_from_term thy type_enc bs Q |
525 in (IApp (P', Q'), union (op =) P_atomics_Ts Q_atomics_Ts) end |
577 in (IApp (P', Q'), union (op =) P_atomics_Ts Q_atomics_Ts) end |
526 | iterm_from_term thy format _ (Const (c, T)) = |
578 | iterm_from_term thy type_enc _ (Const (c, T)) = |
527 (IConst (`(make_fixed_const (SOME format)) c, T, |
579 (IConst (`(make_fixed_const (SOME type_enc)) c, T, |
528 robust_const_typargs thy (c, T)), |
580 robust_const_typargs thy (c, T)), |
529 atomic_types_of T) |
581 atomic_types_of T) |
530 | iterm_from_term _ _ _ (Free (s, T)) = |
582 | iterm_from_term _ _ _ (Free (s, T)) = |
531 (IConst (`make_fixed_var s, T, []), atomic_types_of T) |
583 (IConst (`make_fixed_var s, T, []), atomic_types_of T) |
532 | iterm_from_term _ format _ (Var (v as (s, _), T)) = |
584 | iterm_from_term _ type_enc _ (Var (v as (s, _), T)) = |
533 (if String.isPrefix Meson_Clausify.new_skolem_var_prefix s then |
585 (if String.isPrefix Meson_Clausify.new_skolem_var_prefix s then |
534 let |
586 let |
535 val Ts = T |> strip_type |> swap |> op :: |
587 val Ts = T |> strip_type |> swap |> op :: |
536 val s' = new_skolem_const_name s (length Ts) |
588 val s' = new_skolem_const_name s (length Ts) |
537 in IConst (`(make_fixed_const (SOME format)) s', T, Ts) end |
589 in IConst (`(make_fixed_const (SOME type_enc)) s', T, Ts) end |
538 else |
590 else |
539 IVar ((make_schematic_var v, s), T), atomic_types_of T) |
591 IVar ((make_schematic_var v, s), T), atomic_types_of T) |
540 | iterm_from_term _ _ bs (Bound j) = |
592 | iterm_from_term _ _ bs (Bound j) = |
541 nth bs j |> (fn (_, (name, T)) => (IConst (name, T, []), atomic_types_of T)) |
593 nth bs j |> (fn (_, (name, T)) => (IConst (name, T, []), atomic_types_of T)) |
542 | iterm_from_term thy format bs (Abs (s, T, t)) = |
594 | iterm_from_term thy type_enc bs (Abs (s, T, t)) = |
543 let |
595 let |
544 fun vary s = s |> AList.defined (op =) bs s ? vary o Symbol.bump_string |
596 fun vary s = s |> AList.defined (op =) bs s ? vary o Symbol.bump_string |
545 val s = vary s |
597 val s = vary s |
546 val name = `make_bound_var s |
598 val name = `make_bound_var s |
547 val (tm, atomic_Ts) = iterm_from_term thy format ((s, (name, T)) :: bs) t |
599 val (tm, atomic_Ts) = |
|
600 iterm_from_term thy type_enc ((s, (name, T)) :: bs) t |
548 in (IAbs ((name, T), tm), union (op =) atomic_Ts (atomic_types_of T)) end |
601 in (IAbs ((name, T), tm), union (op =) atomic_Ts (atomic_types_of T)) end |
549 |
|
550 datatype scope = Global | Local | Assum | Chained |
|
551 datatype status = General | Induction | Intro | Inductive | Elim | Simp | Def |
|
552 type stature = scope * status |
|
553 |
|
554 datatype order = First_Order | Higher_Order |
|
555 datatype polymorphism = Polymorphic | Raw_Monomorphic | Mangled_Monomorphic |
|
556 datatype strictness = Strict | Non_Strict |
|
557 datatype granularity = All_Vars | Positively_Naked_Vars | Ghost_Type_Arg_Vars |
|
558 datatype type_level = |
|
559 All_Types | |
|
560 Noninf_Nonmono_Types of strictness * granularity | |
|
561 Fin_Nonmono_Types of granularity | |
|
562 Const_Arg_Types | |
|
563 No_Types |
|
564 |
|
565 datatype type_enc = |
|
566 Native of order * polymorphism * type_level | |
|
567 Guards of polymorphism * type_level | |
|
568 Tags of polymorphism * type_level |
|
569 |
|
570 fun is_type_enc_higher_order (Native (Higher_Order, _, _)) = true |
|
571 | is_type_enc_higher_order _ = false |
|
572 |
|
573 fun polymorphism_of_type_enc (Native (_, poly, _)) = poly |
|
574 | polymorphism_of_type_enc (Guards (poly, _)) = poly |
|
575 | polymorphism_of_type_enc (Tags (poly, _)) = poly |
|
576 |
|
577 fun level_of_type_enc (Native (_, _, level)) = level |
|
578 | level_of_type_enc (Guards (_, level)) = level |
|
579 | level_of_type_enc (Tags (_, level)) = level |
|
580 |
|
581 fun granularity_of_type_level (Noninf_Nonmono_Types (_, grain)) = grain |
|
582 | granularity_of_type_level (Fin_Nonmono_Types grain) = grain |
|
583 | granularity_of_type_level _ = All_Vars |
|
584 |
|
585 fun is_type_level_quasi_sound All_Types = true |
|
586 | is_type_level_quasi_sound (Noninf_Nonmono_Types _) = true |
|
587 | is_type_level_quasi_sound _ = false |
|
588 val is_type_enc_quasi_sound = is_type_level_quasi_sound o level_of_type_enc |
|
589 |
|
590 fun is_type_level_fairly_sound (Fin_Nonmono_Types _) = true |
|
591 | is_type_level_fairly_sound level = is_type_level_quasi_sound level |
|
592 val is_type_enc_fairly_sound = is_type_level_fairly_sound o level_of_type_enc |
|
593 |
|
594 fun is_type_level_monotonicity_based (Noninf_Nonmono_Types _) = true |
|
595 | is_type_level_monotonicity_based (Fin_Nonmono_Types _) = true |
|
596 | is_type_level_monotonicity_based _ = false |
|
597 |
602 |
598 (* "_query", "_bang", and "_at" are for the ASCII-challenged Metis and |
603 (* "_query", "_bang", and "_at" are for the ASCII-challenged Metis and |
599 Mirabelle. *) |
604 Mirabelle. *) |
600 val queries = ["?", "_query"] |
605 val queries = ["?", "_query"] |
601 val bangs = ["!", "_bang"] |
606 val bangs = ["!", "_bang"] |
641 raise Same.SAME |
646 raise Same.SAME |
642 | _ => raise Same.SAME) |
647 | _ => raise Same.SAME) |
643 | ("native_higher", (SOME poly, _)) => |
648 | ("native_higher", (SOME poly, _)) => |
644 (case (poly, level) of |
649 (case (poly, level) of |
645 (Polymorphic, All_Types) => |
650 (Polymorphic, All_Types) => |
646 Native (Higher_Order, Polymorphic, All_Types) |
651 Native (Higher_Order THF_With_Choice, Polymorphic, All_Types) |
647 | (_, Noninf_Nonmono_Types _) => raise Same.SAME |
652 | (_, Noninf_Nonmono_Types _) => raise Same.SAME |
648 | (Mangled_Monomorphic, _) => |
653 | (Mangled_Monomorphic, _) => |
649 if granularity_of_type_level level = All_Vars then |
654 if granularity_of_type_level level = All_Vars then |
650 Native (Higher_Order, Mangled_Monomorphic, level) |
655 Native (Higher_Order THF_With_Choice, Mangled_Monomorphic, |
|
656 level) |
651 else |
657 else |
652 raise Same.SAME |
658 raise Same.SAME |
653 | _ => raise Same.SAME) |
659 | _ => raise Same.SAME) |
654 | ("guards", (SOME poly, _)) => |
660 | ("guards", (SOME poly, _)) => |
655 if poly = Mangled_Monomorphic andalso |
661 if poly = Mangled_Monomorphic andalso |
667 | ("erased", (NONE, All_Types (* naja *))) => |
673 | ("erased", (NONE, All_Types (* naja *))) => |
668 Guards (Polymorphic, No_Types) |
674 Guards (Polymorphic, No_Types) |
669 | _ => raise Same.SAME) |
675 | _ => raise Same.SAME) |
670 handle Same.SAME => error ("Unknown type encoding: " ^ quote s ^ ".") |
676 handle Same.SAME => error ("Unknown type encoding: " ^ quote s ^ ".") |
671 |
677 |
672 fun adjust_type_enc (THF (TPTP_Monomorphic, _, _)) (Native (order, _, level)) = |
678 fun adjust_order THF_Without_Choice (Higher_Order _) = |
673 Native (order, Mangled_Monomorphic, level) |
679 Higher_Order THF_Without_Choice |
674 | adjust_type_enc (THF _) type_enc = type_enc |
680 | adjust_order _ type_enc = type_enc |
|
681 |
|
682 fun adjust_type_enc (THF (TPTP_Polymorphic, _, flavor)) |
|
683 (Native (order, poly, level)) = |
|
684 Native (adjust_order flavor order, poly, level) |
|
685 | adjust_type_enc (THF (TPTP_Monomorphic, _, flavor)) |
|
686 (Native (order, _, level)) = |
|
687 Native (adjust_order flavor order, Mangled_Monomorphic, level) |
675 | adjust_type_enc (TFF (TPTP_Monomorphic, _)) (Native (_, _, level)) = |
688 | adjust_type_enc (TFF (TPTP_Monomorphic, _)) (Native (_, _, level)) = |
676 Native (First_Order, Mangled_Monomorphic, level) |
689 Native (First_Order, Mangled_Monomorphic, level) |
677 | adjust_type_enc (DFG DFG_Sorted) (Native (_, _, level)) = |
690 | adjust_type_enc (DFG DFG_Sorted) (Native (_, _, level)) = |
678 Native (First_Order, Mangled_Monomorphic, level) |
691 Native (First_Order, Mangled_Monomorphic, level) |
679 | adjust_type_enc (TFF _) (Native (_, poly, level)) = |
692 | adjust_type_enc (TFF _) (Native (_, poly, level)) = |
921 val fused_infinite_type_name = "ATP.fused_inf" (* shouldn't clash *) |
934 val fused_infinite_type_name = "ATP.fused_inf" (* shouldn't clash *) |
922 val fused_infinite_type = Type (fused_infinite_type_name, []) |
935 val fused_infinite_type = Type (fused_infinite_type_name, []) |
923 |
936 |
924 fun tvar_name (x as (s, _)) = (make_schematic_type_var x, s) |
937 fun tvar_name (x as (s, _)) = (make_schematic_type_var x, s) |
925 |
938 |
926 fun ho_term_from_typ format type_enc = |
939 fun ho_term_from_typ type_enc = |
927 let |
940 let |
928 fun term (Type (s, Ts)) = |
941 fun term (Type (s, Ts)) = |
929 ATerm (case (is_type_enc_higher_order type_enc, s) of |
942 ATerm (case (is_type_enc_higher_order type_enc, s) of |
930 (true, @{type_name bool}) => `I tptp_bool_type |
943 (true, @{type_name bool}) => `I tptp_bool_type |
931 | (true, @{type_name fun}) => `I tptp_fun_type |
944 | (true, @{type_name fun}) => `I tptp_fun_type |
932 | _ => if s = fused_infinite_type_name andalso |
945 | _ => if s = fused_infinite_type_name andalso |
933 is_format_typed format then |
946 is_type_enc_native type_enc then |
934 `I tptp_individual_type |
947 `I tptp_individual_type |
935 else |
948 else |
936 `make_fixed_type_const s, |
949 `make_fixed_type_const s, |
937 map term Ts) |
950 map term Ts) |
938 | term (TFree (s, _)) = ATerm (`make_fixed_type_var s, []) |
951 | term (TFree (s, _)) = ATerm (`make_fixed_type_var s, []) |
939 | term (TVar (x, _)) = ATerm (tvar_name x, []) |
952 | term (TVar (x, _)) = ATerm (tvar_name x, []) |
940 in term end |
953 in term end |
941 |
954 |
942 fun ho_term_for_type_arg format type_enc T = |
955 fun ho_term_for_type_arg type_enc T = |
943 if T = dummyT then NONE else SOME (ho_term_from_typ format type_enc T) |
956 if T = dummyT then NONE else SOME (ho_term_from_typ type_enc T) |
944 |
957 |
945 (* This shouldn't clash with anything else. *) |
958 (* This shouldn't clash with anything else. *) |
946 val uncurried_alias_sep = "\000" |
959 val uncurried_alias_sep = "\000" |
947 val mangled_type_sep = "\001" |
960 val mangled_type_sep = "\001" |
948 |
961 |
981 fun to_ho (ty as ATerm ((s, _), tys)) = |
994 fun to_ho (ty as ATerm ((s, _), tys)) = |
982 if s = tptp_fun_type then to_afun to_ho to_ho tys else to_atype ty |
995 if s = tptp_fun_type then to_afun to_ho to_ho tys else to_atype ty |
983 | to_ho _ = raise Fail "unexpected type abstraction" |
996 | to_ho _ = raise Fail "unexpected type abstraction" |
984 in if is_type_enc_higher_order type_enc then to_ho else to_fo ary end |
997 in if is_type_enc_higher_order type_enc then to_ho else to_fo ary end |
985 |
998 |
986 fun ho_type_from_typ format type_enc pred_sym ary = |
999 fun ho_type_from_typ type_enc pred_sym ary = |
987 ho_type_from_ho_term type_enc pred_sym ary |
1000 ho_type_from_ho_term type_enc pred_sym ary |
988 o ho_term_from_typ format type_enc |
1001 o ho_term_from_typ type_enc |
989 |
1002 |
990 fun aliased_uncurried ary (s, s') = |
1003 fun aliased_uncurried ary (s, s') = |
991 (s ^ ascii_of_uncurried_alias_sep ^ string_of_int ary, s' ^ string_of_int ary) |
1004 (s ^ ascii_of_uncurried_alias_sep ^ string_of_int ary, s' ^ string_of_int ary) |
992 fun unaliased_uncurried (s, s') = |
1005 fun unaliased_uncurried (s, s') = |
993 case space_explode uncurried_alias_sep s of |
1006 case space_explode uncurried_alias_sep s of |
1074 else IConst (name, T, T_args)) |
1087 else IConst (name, T, T_args)) |
1075 | intro _ _ (IAbs (bound, tm)) = IAbs (bound, intro false [] tm) |
1088 | intro _ _ (IAbs (bound, tm)) = IAbs (bound, intro false [] tm) |
1076 | intro _ _ tm = tm |
1089 | intro _ _ tm = tm |
1077 in intro true [] end |
1090 in intro true [] end |
1078 |
1091 |
1079 fun mangle_type_args_in_const format type_enc (name as (s, _)) T_args = |
1092 fun mangle_type_args_in_const type_enc (name as (s, _)) T_args = |
1080 case unprefix_and_unascii const_prefix s of |
1093 case unprefix_and_unascii const_prefix s of |
1081 NONE => (name, T_args) |
1094 NONE => (name, T_args) |
1082 | SOME s'' => |
1095 | SOME s'' => |
1083 case type_arg_policy [] type_enc (invert_const s'') of |
1096 case type_arg_policy [] type_enc (invert_const s'') of |
1084 Mangled_Type_Args => (mangled_const_name format type_enc T_args name, []) |
1097 Mangled_Type_Args => (mangled_const_name type_enc T_args name, []) |
1085 | _ => (name, T_args) |
1098 | _ => (name, T_args) |
1086 fun mangle_type_args_in_iterm format type_enc = |
1099 fun mangle_type_args_in_iterm type_enc = |
1087 if polymorphism_of_type_enc type_enc = Mangled_Monomorphic then |
1100 if polymorphism_of_type_enc type_enc = Mangled_Monomorphic then |
1088 let |
1101 let |
1089 fun mangle (IApp (tm1, tm2)) = IApp (mangle tm1, mangle tm2) |
1102 fun mangle (IApp (tm1, tm2)) = IApp (mangle tm1, mangle tm2) |
1090 | mangle (tm as IConst (_, _, [])) = tm |
1103 | mangle (tm as IConst (_, _, [])) = tm |
1091 | mangle (IConst (name, T, T_args)) = |
1104 | mangle (IConst (name, T, T_args)) = |
1092 mangle_type_args_in_const format type_enc name T_args |
1105 mangle_type_args_in_const type_enc name T_args |
1093 |> (fn (name, T_args) => IConst (name, T, T_args)) |
1106 |> (fn (name, T_args) => IConst (name, T, T_args)) |
1094 | mangle (IAbs (bound, tm)) = IAbs (bound, mangle tm) |
1107 | mangle (IAbs (bound, tm)) = IAbs (bound, mangle tm) |
1095 | mangle tm = tm |
1108 | mangle tm = tm |
1096 in mangle end |
1109 in mangle end |
1097 else |
1110 else |
1141 |> (fn T_args => IConst (name, T, T_args)) |
1154 |> (fn T_args => IConst (name, T, T_args)) |
1142 | filt _ (IAbs (bound, tm)) = IAbs (bound, filt 0 tm) |
1155 | filt _ (IAbs (bound, tm)) = IAbs (bound, filt 0 tm) |
1143 | filt _ tm = tm |
1156 | filt _ tm = tm |
1144 in filt 0 end |
1157 in filt 0 end |
1145 |
1158 |
1146 fun iformula_from_prop ctxt format type_enc eq_as_iff = |
1159 fun iformula_from_prop ctxt type_enc eq_as_iff = |
1147 let |
1160 let |
1148 val thy = Proof_Context.theory_of ctxt |
1161 val thy = Proof_Context.theory_of ctxt |
1149 fun do_term bs t atomic_Ts = |
1162 fun do_term bs t atomic_Ts = |
1150 iterm_from_term thy format bs (Envir.eta_contract t) |
1163 iterm_from_term thy type_enc bs (Envir.eta_contract t) |
1151 |>> (introduce_proxies_in_iterm type_enc |
1164 |>> (introduce_proxies_in_iterm type_enc |
1152 #> mangle_type_args_in_iterm format type_enc #> AAtom) |
1165 #> mangle_type_args_in_iterm type_enc #> AAtom) |
1153 ||> union (op =) atomic_Ts |
1166 ||> union (op =) atomic_Ts |
1154 fun do_quant bs q pos s T t' = |
1167 fun do_quant bs q pos s T t' = |
1155 let |
1168 let |
1156 val s = singleton (Name.variant_list (map fst bs)) s |
1169 val s = singleton (Name.variant_list (map fst bs)) s |
1157 val universal = Option.map (q = AExists ? not) pos |
1170 val universal = Option.map (q = AExists ? not) pos |
1231 |> presimplify_term thy |
1244 |> presimplify_term thy |
1232 |> HOLogic.dest_Trueprop |
1245 |> HOLogic.dest_Trueprop |
1233 end |
1246 end |
1234 handle TERM _ => @{const True} |
1247 handle TERM _ => @{const True} |
1235 |
1248 |
1236 fun make_formula ctxt format type_enc eq_as_iff name stature kind t = |
1249 fun make_formula ctxt type_enc eq_as_iff name stature kind t = |
1237 let |
1250 let |
1238 val (iformula, atomic_Ts) = |
1251 val (iformula, atomic_Ts) = |
1239 iformula_from_prop ctxt format type_enc eq_as_iff |
1252 iformula_from_prop ctxt type_enc eq_as_iff (SOME (kind <> Conjecture)) t |
1240 (SOME (kind <> Conjecture)) t [] |
1253 [] |
1241 |>> close_iformula_universally |
1254 |>> close_iformula_universally |
1242 in |
1255 in |
1243 {name = name, stature = stature, kind = kind, iformula = iformula, |
1256 {name = name, stature = stature, kind = kind, iformula = iformula, |
1244 atomic_types = atomic_Ts} |
1257 atomic_types = atomic_Ts} |
1245 end |
1258 end |
1246 |
1259 |
1247 fun make_fact ctxt format type_enc eq_as_iff ((name, stature), t) = |
1260 fun make_fact ctxt format type_enc eq_as_iff ((name, stature), t) = |
1248 case t |> make_formula ctxt format type_enc (eq_as_iff andalso format <> CNF) |
1261 case t |> make_formula ctxt type_enc (eq_as_iff andalso format <> CNF) name |
1249 name stature Axiom of |
1262 stature Axiom of |
1250 formula as {iformula = AAtom (IConst ((s, _), _, _)), ...} => |
1263 formula as {iformula = AAtom (IConst ((s, _), _, _)), ...} => |
1251 if s = tptp_true then NONE else SOME formula |
1264 if s = tptp_true then NONE else SOME formula |
1252 | formula => SOME formula |
1265 | formula => SOME formula |
1253 |
1266 |
1254 fun s_not_prop (@{const Trueprop} $ t) = @{const Trueprop} $ s_not t |
1267 fun s_not_prop (@{const Trueprop} $ t) = @{const Trueprop} $ s_not t |
1541 IConst (`(make_fixed_const NONE) predicator_name, @{typ "bool => bool"}, []) |
1553 IConst (`(make_fixed_const NONE) predicator_name, @{typ "bool => bool"}, []) |
1542 |
1554 |
1543 fun list_app head args = fold (curry (IApp o swap)) args head |
1555 fun list_app head args = fold (curry (IApp o swap)) args head |
1544 fun predicator tm = IApp (predicator_combconst, tm) |
1556 fun predicator tm = IApp (predicator_combconst, tm) |
1545 |
1557 |
1546 fun mk_app_op format type_enc head arg = |
1558 fun mk_app_op type_enc head arg = |
1547 let |
1559 let |
1548 val head_T = ityp_of head |
1560 val head_T = ityp_of head |
1549 val (arg_T, res_T) = dest_funT head_T |
1561 val (arg_T, res_T) = dest_funT head_T |
1550 val app = |
1562 val app = |
1551 IConst (app_op, head_T --> head_T, [arg_T, res_T]) |
1563 IConst (app_op, head_T --> head_T, [arg_T, res_T]) |
1552 |> mangle_type_args_in_iterm format type_enc |
1564 |> mangle_type_args_in_iterm type_enc |
1553 in list_app app [head, arg] end |
1565 in list_app app [head, arg] end |
1554 |
1566 |
1555 fun firstorderize_fact thy monom_constrs format type_enc sym_tab |
1567 fun firstorderize_fact thy monom_constrs type_enc sym_tab uncurried_aliases = |
1556 uncurried_aliases = |
1568 let |
1557 let |
1569 fun do_app arg head = mk_app_op type_enc head arg |
1558 fun do_app arg head = mk_app_op format type_enc head arg |
|
1559 fun list_app_ops head args = fold do_app args head |
1570 fun list_app_ops head args = fold do_app args head |
1560 fun introduce_app_ops tm = |
1571 fun introduce_app_ops tm = |
1561 let val (head, args) = tm |> strip_iterm_comb ||> map introduce_app_ops in |
1572 let val (head, args) = tm |> strip_iterm_comb ||> map introduce_app_ops in |
1562 case head of |
1573 case head of |
1563 IConst (name as (s, _), T, T_args) => |
1574 IConst (name as (s, _), T, T_args) => |
1866 | should_generate_tag_bound_decl ctxt mono (Tags (_, level)) _ T = |
1877 | should_generate_tag_bound_decl ctxt mono (Tags (_, level)) _ T = |
1867 granularity_of_type_level level <> All_Vars andalso |
1878 granularity_of_type_level level <> All_Vars andalso |
1868 should_encode_type ctxt mono level T |
1879 should_encode_type ctxt mono level T |
1869 | should_generate_tag_bound_decl _ _ _ _ _ = false |
1880 | should_generate_tag_bound_decl _ _ _ _ _ = false |
1870 |
1881 |
1871 fun mk_aterm format type_enc name T_args args = |
1882 fun mk_aterm type_enc name T_args args = |
1872 ATerm (name, map_filter (ho_term_for_type_arg format type_enc) T_args @ args) |
1883 ATerm (name, map_filter (ho_term_for_type_arg type_enc) T_args @ args) |
1873 |
1884 |
1874 fun do_bound_type ctxt format mono type_enc = |
1885 fun do_bound_type ctxt mono type_enc = |
1875 case type_enc of |
1886 case type_enc of |
1876 Native (_, _, level) => |
1887 Native (_, _, level) => |
1877 fused_type ctxt mono level 0 |
1888 fused_type ctxt mono level 0 #> ho_type_from_typ type_enc false 0 #> SOME |
1878 #> ho_type_from_typ format type_enc false 0 #> SOME |
|
1879 | _ => K NONE |
1889 | _ => K NONE |
1880 |
1890 |
1881 fun tag_with_type ctxt format mono type_enc pos T tm = |
1891 fun tag_with_type ctxt mono type_enc pos T tm = |
1882 IConst (type_tag, T --> T, [T]) |
1892 IConst (type_tag, T --> T, [T]) |
1883 |> mangle_type_args_in_iterm format type_enc |
1893 |> mangle_type_args_in_iterm type_enc |
1884 |> ho_term_from_iterm ctxt format mono type_enc pos |
1894 |> ho_term_from_iterm ctxt mono type_enc pos |
1885 |> (fn ATerm (s, tms) => ATerm (s, tms @ [tm]) |
1895 |> (fn ATerm (s, tms) => ATerm (s, tms @ [tm]) |
1886 | _ => raise Fail "unexpected lambda-abstraction") |
1896 | _ => raise Fail "unexpected lambda-abstraction") |
1887 and ho_term_from_iterm ctxt format mono type_enc pos = |
1897 and ho_term_from_iterm ctxt mono type_enc pos = |
1888 let |
1898 let |
1889 fun beta_red bs (IApp (IAbs ((name, _), tm), tm')) = |
1899 fun beta_red bs (IApp (IAbs ((name, _), tm), tm')) = |
1890 beta_red ((name, beta_red bs tm') :: bs) tm |
1900 beta_red ((name, beta_red bs tm') :: bs) tm |
1891 | beta_red bs (IApp tmp) = IApp (pairself (beta_red bs) tmp) |
1901 | beta_red bs (IApp tmp) = IApp (pairself (beta_red bs) tmp) |
1892 | beta_red bs (tm as IConst (name, _, _)) = |
1902 | beta_red bs (tm as IConst (name, _, _)) = |
1907 val t = |
1917 val t = |
1908 case head of |
1918 case head of |
1909 IConst (name as (s, _), _, T_args) => |
1919 IConst (name as (s, _), _, T_args) => |
1910 let |
1920 let |
1911 val arg_site = if is_tptp_equal s then Eq_Arg pos else Elsewhere |
1921 val arg_site = if is_tptp_equal s then Eq_Arg pos else Elsewhere |
1912 in |
1922 in map (term arg_site) args |> mk_aterm type_enc name T_args end |
1913 map (term arg_site) args |> mk_aterm format type_enc name T_args |
|
1914 end |
|
1915 | IVar (name, _) => |
1923 | IVar (name, _) => |
1916 map (term Elsewhere) args |> mk_aterm format type_enc name [] |
1924 map (term Elsewhere) args |> mk_aterm type_enc name [] |
1917 | IAbs ((name, T), tm) => |
1925 | IAbs ((name, T), tm) => |
1918 if is_type_enc_higher_order type_enc then |
1926 if is_type_enc_higher_order type_enc then |
1919 AAbs ((name, ho_type_from_typ format type_enc true 0 T), |
1927 AAbs ((name, ho_type_from_typ type_enc true 0 T), |
1920 term Elsewhere tm) |
1928 term Elsewhere tm) |
1921 else |
1929 else |
1922 raise Fail "unexpected lambda-abstraction" |
1930 raise Fail "unexpected lambda-abstraction" |
1923 | IApp _ => raise Fail "impossible \"IApp\"" |
1931 | IApp _ => raise Fail "impossible \"IApp\"" |
1924 val T = ityp_of u |
1932 val T = ityp_of u |
1925 in |
1933 in |
1926 if should_tag_with_type ctxt mono type_enc site u T then |
1934 if should_tag_with_type ctxt mono type_enc site u T then |
1927 tag_with_type ctxt format mono type_enc pos T t |
1935 tag_with_type ctxt mono type_enc pos T t |
1928 else |
1936 else |
1929 t |
1937 t |
1930 end |
1938 end |
1931 in term (Top_Level pos) o beta_red [] end |
1939 in term (Top_Level pos) o beta_red [] end |
1932 and formula_from_iformula ctxt polym_constrs format mono type_enc |
1940 and formula_from_iformula ctxt polym_constrs mono type_enc should_guard_var = |
1933 should_guard_var = |
|
1934 let |
1941 let |
1935 val thy = Proof_Context.theory_of ctxt |
1942 val thy = Proof_Context.theory_of ctxt |
1936 val level = level_of_type_enc type_enc |
1943 val level = level_of_type_enc type_enc |
1937 val do_term = ho_term_from_iterm ctxt format mono type_enc |
1944 val do_term = ho_term_from_iterm ctxt mono type_enc |
1938 fun do_out_of_bound_type pos phi universal (name, T) = |
1945 fun do_out_of_bound_type pos phi universal (name, T) = |
1939 if should_guard_type ctxt mono type_enc |
1946 if should_guard_type ctxt mono type_enc |
1940 (fn () => should_guard_var thy polym_constrs level pos phi |
1947 (fn () => should_guard_var thy polym_constrs level pos phi |
1941 universal name) T then |
1948 universal name) T then |
1942 IVar (name, T) |
1949 IVar (name, T) |
1943 |> type_guard_iterm format type_enc T |
1950 |> type_guard_iterm type_enc T |
1944 |> do_term pos |> AAtom |> SOME |
1951 |> do_term pos |> AAtom |> SOME |
1945 else if should_generate_tag_bound_decl ctxt mono type_enc universal T then |
1952 else if should_generate_tag_bound_decl ctxt mono type_enc universal T then |
1946 let |
1953 let |
1947 val var = ATerm (name, []) |
1954 val var = ATerm (name, []) |
1948 val tagged_var = tag_with_type ctxt format mono type_enc pos T var |
1955 val tagged_var = tag_with_type ctxt mono type_enc pos T var |
1949 in SOME (AAtom (ATerm (`I tptp_equal, [tagged_var, var]))) end |
1956 in SOME (AAtom (ATerm (`I tptp_equal, [tagged_var, var]))) end |
1950 else |
1957 else |
1951 NONE |
1958 NONE |
1952 fun do_formula pos (AQuant (q, xs, phi)) = |
1959 fun do_formula pos (AQuant (q, xs, phi)) = |
1953 let |
1960 let |
1954 val phi = phi |> do_formula pos |
1961 val phi = phi |> do_formula pos |
1955 val universal = Option.map (q = AExists ? not) pos |
1962 val universal = Option.map (q = AExists ? not) pos |
1956 val do_bound_type = do_bound_type ctxt format mono type_enc |
1963 val do_bound_type = do_bound_type ctxt mono type_enc |
1957 in |
1964 in |
1958 AQuant (q, xs |> map (apsnd (fn NONE => NONE |
1965 AQuant (q, xs |> map (apsnd (fn NONE => NONE |
1959 | SOME T => do_bound_type T)), |
1966 | SOME T => do_bound_type T)), |
1960 (if q = AForall then mk_ahorn else fold_rev (mk_aconn AAnd)) |
1967 (if q = AForall then mk_ahorn else fold_rev (mk_aconn AAnd)) |
1961 (map_filter |
1968 (map_filter |
1970 in do_formula end |
1977 in do_formula end |
1971 |
1978 |
1972 (* Each fact is given a unique fact number to avoid name clashes (e.g., because |
1979 (* Each fact is given a unique fact number to avoid name clashes (e.g., because |
1973 of monomorphization). The TPTP explicitly forbids name clashes, and some of |
1980 of monomorphization). The TPTP explicitly forbids name clashes, and some of |
1974 the remote provers might care. *) |
1981 the remote provers might care. *) |
1975 fun formula_line_for_fact ctxt polym_constrs format prefix encode freshen pos |
1982 fun formula_line_for_fact ctxt polym_constrs prefix encode freshen pos |
1976 mono type_enc rank (j, {name, stature, kind, iformula, atomic_types}) = |
1983 mono type_enc rank (j, {name, stature, kind, iformula, atomic_types}) = |
1977 (prefix ^ (if freshen then string_of_int j ^ "_" else "") ^ encode name, kind, |
1984 (prefix ^ (if freshen then string_of_int j ^ "_" else "") ^ encode name, kind, |
1978 iformula |
1985 iformula |
1979 |> formula_from_iformula ctxt polym_constrs format mono type_enc |
1986 |> formula_from_iformula ctxt polym_constrs mono type_enc |
1980 should_guard_var_in_formula (if pos then SOME true else NONE) |
1987 should_guard_var_in_formula (if pos then SOME true else NONE) |
1981 |> close_formula_universally |
1988 |> close_formula_universally |
1982 |> bound_tvars type_enc true atomic_types, |
1989 |> bound_tvars type_enc true atomic_types, |
1983 NONE, |
1990 NONE, |
1984 let val rank = rank j in |
1991 let val rank = rank j in |
2015 (formula_from_arity_atom type_enc concl_atom) |
2022 (formula_from_arity_atom type_enc concl_atom) |
2016 |> mk_aquant AForall |
2023 |> mk_aquant AForall |
2017 (map (rpair (atype_of_type_vars type_enc)) (#3 concl_atom)), |
2024 (map (rpair (atype_of_type_vars type_enc)) (#3 concl_atom)), |
2018 NONE, isabelle_info inductiveN helper_rank) |
2025 NONE, isabelle_info inductiveN helper_rank) |
2019 |
2026 |
2020 fun formula_line_for_conjecture ctxt polym_constrs format mono type_enc |
2027 fun formula_line_for_conjecture ctxt polym_constrs mono type_enc |
2021 ({name, kind, iformula, atomic_types, ...} : translated_formula) = |
2028 ({name, kind, iformula, atomic_types, ...} : translated_formula) = |
2022 Formula (conjecture_prefix ^ name, kind, |
2029 Formula (conjecture_prefix ^ name, kind, |
2023 iformula |
2030 iformula |
2024 |> formula_from_iformula ctxt polym_constrs format mono type_enc |
2031 |> formula_from_iformula ctxt polym_constrs mono type_enc |
2025 should_guard_var_in_formula (SOME false) |
2032 should_guard_var_in_formula (SOME false) |
2026 |> close_formula_universally |
2033 |> close_formula_universally |
2027 |> bound_tvars type_enc true atomic_types, NONE, []) |
2034 |> bound_tvars type_enc true atomic_types, NONE, []) |
2028 |
2035 |
2029 fun type_enc_needs_free_types (Native (_, Polymorphic, _)) = true |
2036 fun type_enc_needs_free_types (Native (_, Polymorphic, _)) = true |
2220 is_type_level_monotonicity_based level andalso |
2226 is_type_level_monotonicity_based level andalso |
2221 granularity_of_type_level level <> Ghost_Type_Arg_Vars) |
2227 granularity_of_type_level level <> Ghost_Type_Arg_Vars) |
2222 ? fold (add_fact_monotonic_types ctxt mono type_enc) facts |
2228 ? fold (add_fact_monotonic_types ctxt mono type_enc) facts |
2223 end |
2229 end |
2224 |
2230 |
2225 fun formula_line_for_guards_mono_type ctxt format mono type_enc T = |
2231 fun formula_line_for_guards_mono_type ctxt mono type_enc T = |
2226 Formula (guards_sym_formula_prefix ^ |
2232 Formula (guards_sym_formula_prefix ^ |
2227 ascii_of (mangled_type format type_enc T), |
2233 ascii_of (mangled_type type_enc T), |
2228 Axiom, |
2234 Axiom, |
2229 IConst (`make_bound_var "X", T, []) |
2235 IConst (`make_bound_var "X", T, []) |
2230 |> type_guard_iterm format type_enc T |
2236 |> type_guard_iterm type_enc T |
2231 |> AAtom |
2237 |> AAtom |
2232 |> formula_from_iformula ctxt [] format mono type_enc |
2238 |> formula_from_iformula ctxt [] mono type_enc |
2233 always_guard_var_in_formula (SOME true) |
2239 always_guard_var_in_formula (SOME true) |
2234 |> close_formula_universally |
2240 |> close_formula_universally |
2235 |> bound_tvars type_enc true (atomic_types_of T), |
2241 |> bound_tvars type_enc true (atomic_types_of T), |
2236 NONE, isabelle_info inductiveN helper_rank) |
2242 NONE, isabelle_info inductiveN helper_rank) |
2237 |
2243 |
2238 fun formula_line_for_tags_mono_type ctxt format mono type_enc T = |
2244 fun formula_line_for_tags_mono_type ctxt mono type_enc T = |
2239 let val x_var = ATerm (`make_bound_var "X", []) in |
2245 let val x_var = ATerm (`make_bound_var "X", []) in |
2240 Formula (tags_sym_formula_prefix ^ |
2246 Formula (tags_sym_formula_prefix ^ |
2241 ascii_of (mangled_type format type_enc T), |
2247 ascii_of (mangled_type type_enc T), |
2242 Axiom, |
2248 Axiom, |
2243 eq_formula type_enc (atomic_types_of T) [] false |
2249 eq_formula type_enc (atomic_types_of T) [] false |
2244 (tag_with_type ctxt format mono type_enc NONE T x_var) x_var, |
2250 (tag_with_type ctxt mono type_enc NONE T x_var) x_var, |
2245 NONE, isabelle_info defN helper_rank) |
2251 NONE, isabelle_info defN helper_rank) |
2246 end |
2252 end |
2247 |
2253 |
2248 fun problem_lines_for_mono_types ctxt format mono type_enc Ts = |
2254 fun problem_lines_for_mono_types ctxt mono type_enc Ts = |
2249 case type_enc of |
2255 case type_enc of |
2250 Native _ => [] |
2256 Native _ => [] |
2251 | Guards _ => |
2257 | Guards _ => map (formula_line_for_guards_mono_type ctxt mono type_enc) Ts |
2252 map (formula_line_for_guards_mono_type ctxt format mono type_enc) Ts |
2258 | Tags _ => map (formula_line_for_tags_mono_type ctxt mono type_enc) Ts |
2253 | Tags _ => map (formula_line_for_tags_mono_type ctxt format mono type_enc) Ts |
2259 |
2254 |
2260 fun decl_line_for_sym ctxt mono type_enc s |
2255 fun decl_line_for_sym ctxt format mono type_enc s |
|
2256 (s', T_args, T, pred_sym, ary, _) = |
2261 (s', T_args, T, pred_sym, ary, _) = |
2257 let |
2262 let |
2258 val thy = Proof_Context.theory_of ctxt |
2263 val thy = Proof_Context.theory_of ctxt |
2259 val (T, T_args) = |
2264 val (T, T_args) = |
2260 if null T_args then |
2265 if null T_args then |
2267 in (T, robust_const_typargs thy (s', T)) end |
2272 in (T, robust_const_typargs thy (s', T)) end |
2268 | NONE => raise Fail "unexpected type arguments" |
2273 | NONE => raise Fail "unexpected type arguments" |
2269 in |
2274 in |
2270 Decl (sym_decl_prefix ^ s, (s, s'), |
2275 Decl (sym_decl_prefix ^ s, (s, s'), |
2271 T |> fused_type ctxt mono (level_of_type_enc type_enc) ary |
2276 T |> fused_type ctxt mono (level_of_type_enc type_enc) ary |
2272 |> ho_type_from_typ format type_enc pred_sym ary |
2277 |> ho_type_from_typ type_enc pred_sym ary |
2273 |> not (null T_args) |
2278 |> not (null T_args) |
2274 ? curry ATyAbs (map (tvar_name o fst o dest_TVar) T_args)) |
2279 ? curry ATyAbs (map (tvar_name o fst o dest_TVar) T_args)) |
2275 end |
2280 end |
2276 |
2281 |
2277 fun honor_conj_sym_kind in_conj conj_sym_kind = |
2282 fun honor_conj_sym_kind in_conj conj_sym_kind = |
2278 if in_conj then (conj_sym_kind, conj_sym_kind = Conjecture ? mk_anot) |
2283 if in_conj then (conj_sym_kind, conj_sym_kind = Conjecture ? mk_anot) |
2279 else (Axiom, I) |
2284 else (Axiom, I) |
2280 |
2285 |
2281 fun formula_line_for_guards_sym_decl ctxt format conj_sym_kind mono type_enc n s |
2286 fun formula_line_for_guards_sym_decl ctxt conj_sym_kind mono type_enc n s j |
2282 j (s', T_args, T, _, ary, in_conj) = |
2287 (s', T_args, T, _, ary, in_conj) = |
2283 let |
2288 let |
2284 val thy = Proof_Context.theory_of ctxt |
2289 val thy = Proof_Context.theory_of ctxt |
2285 val (kind, maybe_negate) = honor_conj_sym_kind in_conj conj_sym_kind |
2290 val (kind, maybe_negate) = honor_conj_sym_kind in_conj conj_sym_kind |
2286 val (arg_Ts, res_T) = chop_fun ary T |
2291 val (arg_Ts, res_T) = chop_fun ary T |
2287 val bound_names = 1 upto ary |> map (`I o make_bound_var o string_of_int) |
2292 val bound_names = 1 upto ary |> map (`I o make_bound_var o string_of_int) |
2304 in |
2309 in |
2305 Formula (guards_sym_formula_prefix ^ s ^ |
2310 Formula (guards_sym_formula_prefix ^ s ^ |
2306 (if n > 1 then "_" ^ string_of_int j else ""), kind, |
2311 (if n > 1 then "_" ^ string_of_int j else ""), kind, |
2307 IConst ((s, s'), T, T_args) |
2312 IConst ((s, s'), T, T_args) |
2308 |> fold (curry (IApp o swap)) bounds |
2313 |> fold (curry (IApp o swap)) bounds |
2309 |> type_guard_iterm format type_enc res_T |
2314 |> type_guard_iterm type_enc res_T |
2310 |> AAtom |> mk_aquant AForall (bound_names ~~ bound_Ts) |
2315 |> AAtom |> mk_aquant AForall (bound_names ~~ bound_Ts) |
2311 |> formula_from_iformula ctxt [] format mono type_enc |
2316 |> formula_from_iformula ctxt [] mono type_enc |
2312 always_guard_var_in_formula (SOME true) |
2317 always_guard_var_in_formula (SOME true) |
2313 |> close_formula_universally |
2318 |> close_formula_universally |
2314 |> bound_tvars type_enc (n > 1) (atomic_types_of T) |
2319 |> bound_tvars type_enc (n > 1) (atomic_types_of T) |
2315 |> maybe_negate, |
2320 |> maybe_negate, |
2316 NONE, isabelle_info inductiveN helper_rank) |
2321 NONE, isabelle_info inductiveN helper_rank) |
2317 end |
2322 end |
2318 |
2323 |
2319 fun formula_lines_for_tags_sym_decl ctxt format conj_sym_kind mono type_enc n s |
2324 fun formula_lines_for_tags_sym_decl ctxt conj_sym_kind mono type_enc n s |
2320 (j, (s', T_args, T, pred_sym, ary, in_conj)) = |
2325 (j, (s', T_args, T, pred_sym, ary, in_conj)) = |
2321 let |
2326 let |
2322 val thy = Proof_Context.theory_of ctxt |
2327 val thy = Proof_Context.theory_of ctxt |
2323 val level = level_of_type_enc type_enc |
2328 val level = level_of_type_enc type_enc |
2324 val grain = granularity_of_type_level level |
2329 val grain = granularity_of_type_level level |
2327 (if n > 1 then "_" ^ string_of_int j else "") |
2332 (if n > 1 then "_" ^ string_of_int j else "") |
2328 val (kind, maybe_negate) = honor_conj_sym_kind in_conj conj_sym_kind |
2333 val (kind, maybe_negate) = honor_conj_sym_kind in_conj conj_sym_kind |
2329 val (arg_Ts, res_T) = chop_fun ary T |
2334 val (arg_Ts, res_T) = chop_fun ary T |
2330 val bound_names = 1 upto ary |> map (`I o make_bound_var o string_of_int) |
2335 val bound_names = 1 upto ary |> map (`I o make_bound_var o string_of_int) |
2331 val bounds = bound_names |> map (fn name => ATerm (name, [])) |
2336 val bounds = bound_names |> map (fn name => ATerm (name, [])) |
2332 val cst = mk_aterm format type_enc (s, s') T_args |
2337 val cst = mk_aterm type_enc (s, s') T_args |
2333 val eq = maybe_negate oo eq_formula type_enc (atomic_types_of T) [] pred_sym |
2338 val eq = maybe_negate oo eq_formula type_enc (atomic_types_of T) [] pred_sym |
2334 val should_encode = should_encode_type ctxt mono level |
2339 val should_encode = should_encode_type ctxt mono level |
2335 val tag_with = tag_with_type ctxt format mono type_enc NONE |
2340 val tag_with = tag_with_type ctxt mono type_enc NONE |
2336 val add_formula_for_res = |
2341 val add_formula_for_res = |
2337 if should_encode res_T then |
2342 if should_encode res_T then |
2338 let |
2343 let |
2339 val tagged_bounds = |
2344 val tagged_bounds = |
2340 if grain = Ghost_Type_Arg_Vars then |
2345 if grain = Ghost_Type_Arg_Vars then |
2365 else |
2370 else |
2366 decls |
2371 decls |
2367 end |
2372 end |
2368 | rationalize_decls _ decls = decls |
2373 | rationalize_decls _ decls = decls |
2369 |
2374 |
2370 fun problem_lines_for_sym_decls ctxt format conj_sym_kind mono type_enc |
2375 fun problem_lines_for_sym_decls ctxt conj_sym_kind mono type_enc (s, decls) = |
2371 (s, decls) = |
|
2372 case type_enc of |
2376 case type_enc of |
2373 Native _ => [decl_line_for_sym ctxt format mono type_enc s (hd decls)] |
2377 Native _ => [decl_line_for_sym ctxt mono type_enc s (hd decls)] |
2374 | Guards (_, level) => |
2378 | Guards (_, level) => |
2375 let |
2379 let |
2376 val thy = Proof_Context.theory_of ctxt |
2380 val thy = Proof_Context.theory_of ctxt |
2377 val decls = decls |> rationalize_decls thy |
2381 val decls = decls |> rationalize_decls thy |
2378 val n = length decls |
2382 val n = length decls |
2379 val decls = |
2383 val decls = |
2380 decls |> filter (should_encode_type ctxt mono level |
2384 decls |> filter (should_encode_type ctxt mono level |
2381 o result_type_of_decl) |
2385 o result_type_of_decl) |
2382 in |
2386 in |
2383 (0 upto length decls - 1, decls) |
2387 (0 upto length decls - 1, decls) |
2384 |-> map2 (formula_line_for_guards_sym_decl ctxt format conj_sym_kind mono |
2388 |-> map2 (formula_line_for_guards_sym_decl ctxt conj_sym_kind mono |
2385 type_enc n s) |
2389 type_enc n s) |
2386 end |
2390 end |
2387 | Tags (_, level) => |
2391 | Tags (_, level) => |
2388 if granularity_of_type_level level = All_Vars then |
2392 if granularity_of_type_level level = All_Vars then |
2389 [] |
2393 [] |
2390 else |
2394 else |
2391 let val n = length decls in |
2395 let val n = length decls in |
2392 (0 upto n - 1 ~~ decls) |
2396 (0 upto n - 1 ~~ decls) |
2393 |> maps (formula_lines_for_tags_sym_decl ctxt format conj_sym_kind mono |
2397 |> maps (formula_lines_for_tags_sym_decl ctxt conj_sym_kind mono |
2394 type_enc n s) |
2398 type_enc n s) |
2395 end |
2399 end |
2396 |
2400 |
2397 fun problem_lines_for_sym_decl_table ctxt format conj_sym_kind mono type_enc |
2401 fun problem_lines_for_sym_decl_table ctxt conj_sym_kind mono type_enc mono_Ts |
2398 mono_Ts sym_decl_tab = |
2402 sym_decl_tab = |
2399 let |
2403 let |
2400 val syms = sym_decl_tab |> Symtab.dest |> sort_wrt fst |
2404 val syms = sym_decl_tab |> Symtab.dest |> sort_wrt fst |
2401 val mono_lines = |
2405 val mono_lines = problem_lines_for_mono_types ctxt mono type_enc mono_Ts |
2402 problem_lines_for_mono_types ctxt format mono type_enc mono_Ts |
|
2403 val decl_lines = |
2406 val decl_lines = |
2404 fold_rev (append o problem_lines_for_sym_decls ctxt format conj_sym_kind |
2407 fold_rev (append o problem_lines_for_sym_decls ctxt conj_sym_kind mono |
2405 mono type_enc) |
2408 type_enc) |
2406 syms [] |
2409 syms [] |
2407 in mono_lines @ decl_lines end |
2410 in mono_lines @ decl_lines end |
2408 |
2411 |
2409 fun pair_append (xs1, xs2) (ys1, ys2) = (xs1 @ ys1, xs2 @ ys2) |
2412 fun pair_append (xs1, xs2) (ys1, ys2) = (xs1 @ ys1, xs2 @ ys2) |
2410 |
2413 |
2411 fun do_uncurried_alias_lines_for_sym ctxt monom_constrs format conj_sym_kind |
2414 fun do_uncurried_alias_lines_for_sym ctxt monom_constrs conj_sym_kind mono |
2412 mono type_enc sym_tab0 sym_tab base_s0 types in_conj = |
2415 type_enc sym_tab0 sym_tab base_s0 types in_conj = |
2413 let |
2416 let |
2414 fun do_alias ary = |
2417 fun do_alias ary = |
2415 let |
2418 let |
2416 val thy = Proof_Context.theory_of ctxt |
2419 val thy = Proof_Context.theory_of ctxt |
2417 val (kind, maybe_negate) = honor_conj_sym_kind in_conj conj_sym_kind |
2420 val (kind, maybe_negate) = honor_conj_sym_kind in_conj conj_sym_kind |
2418 val base_name = base_s0 |> `(make_fixed_const (SOME format)) |
2421 val base_name = base_s0 |> `(make_fixed_const (SOME type_enc)) |
2419 val T = case types of [T] => T | _ => robust_const_type thy base_s0 |
2422 val T = case types of [T] => T | _ => robust_const_type thy base_s0 |
2420 val T_args = robust_const_typargs thy (base_s0, T) |
2423 val T_args = robust_const_typargs thy (base_s0, T) |
2421 val (base_name as (base_s, _), T_args) = |
2424 val (base_name as (base_s, _), T_args) = |
2422 mangle_type_args_in_const format type_enc base_name T_args |
2425 mangle_type_args_in_const type_enc base_name T_args |
2423 val base_ary = min_ary_of sym_tab0 base_s |
2426 val base_ary = min_ary_of sym_tab0 base_s |
2424 fun do_const name = IConst (name, T, T_args) |
2427 fun do_const name = IConst (name, T, T_args) |
2425 val filter_ty_args = |
2428 val filter_ty_args = |
2426 filter_type_args_in_iterm thy monom_constrs type_enc |
2429 filter_type_args_in_iterm thy monom_constrs type_enc |
2427 val ho_term_of = |
2430 val ho_term_of = ho_term_from_iterm ctxt mono type_enc (SOME true) |
2428 ho_term_from_iterm ctxt format mono type_enc (SOME true) |
|
2429 val name1 as (s1, _) = |
2431 val name1 as (s1, _) = |
2430 base_name |> ary - 1 > base_ary ? aliased_uncurried (ary - 1) |
2432 base_name |> ary - 1 > base_ary ? aliased_uncurried (ary - 1) |
2431 val name2 as (s2, _) = base_name |> aliased_uncurried ary |
2433 val name2 as (s2, _) = base_name |> aliased_uncurried ary |
2432 val (arg_Ts, _) = chop_fun ary T |
2434 val (arg_Ts, _) = chop_fun ary T |
2433 val bound_names = |
2435 val bound_names = |
2434 1 upto ary |> map (`I o make_bound_var o string_of_int) |
2436 1 upto ary |> map (`I o make_bound_var o string_of_int) |
2435 val bounds = bound_names ~~ arg_Ts |
2437 val bounds = bound_names ~~ arg_Ts |
2436 val (first_bounds, last_bound) = |
2438 val (first_bounds, last_bound) = |
2437 bounds |> map (fn (name, T) => IConst (name, T, [])) |> split_last |
2439 bounds |> map (fn (name, T) => IConst (name, T, [])) |> split_last |
2438 val tm1 = |
2440 val tm1 = |
2439 mk_app_op format type_enc (list_app (do_const name1) first_bounds) |
2441 mk_app_op type_enc (list_app (do_const name1) first_bounds) last_bound |
2440 last_bound |
|
2441 |> filter_ty_args |
2442 |> filter_ty_args |
2442 val tm2 = |
2443 val tm2 = |
2443 list_app (do_const name2) (first_bounds @ [last_bound]) |
2444 list_app (do_const name2) (first_bounds @ [last_bound]) |
2444 |> filter_ty_args |
2445 |> filter_ty_args |
2445 val do_bound_type = do_bound_type ctxt format mono type_enc |
2446 val do_bound_type = do_bound_type ctxt mono type_enc |
2446 val eq = |
2447 val eq = |
2447 eq_formula type_enc (atomic_types_of T) |
2448 eq_formula type_enc (atomic_types_of T) |
2448 (map (apsnd do_bound_type) bounds) false |
2449 (map (apsnd do_bound_type) bounds) false |
2449 (ho_term_of tm1) (ho_term_of tm2) |
2450 (ho_term_of tm1) (ho_term_of tm2) |
2450 in |
2451 in |
2453 NONE, isabelle_info defN helper_rank)]) |
2454 NONE, isabelle_info defN helper_rank)]) |
2454 |> (if ary - 1 = base_ary orelse Symtab.defined sym_tab s1 then I |
2455 |> (if ary - 1 = base_ary orelse Symtab.defined sym_tab s1 then I |
2455 else pair_append (do_alias (ary - 1))) |
2456 else pair_append (do_alias (ary - 1))) |
2456 end |
2457 end |
2457 in do_alias end |
2458 in do_alias end |
2458 fun uncurried_alias_lines_for_sym ctxt monom_constrs format conj_sym_kind mono |
2459 fun uncurried_alias_lines_for_sym ctxt monom_constrs conj_sym_kind mono type_enc |
2459 type_enc sym_tab0 sym_tab |
2460 sym_tab0 sym_tab (s, {min_ary, types, in_conj, ...} : sym_info) = |
2460 (s, {min_ary, types, in_conj, ...} : sym_info) = |
|
2461 case unprefix_and_unascii const_prefix s of |
2461 case unprefix_and_unascii const_prefix s of |
2462 SOME mangled_s => |
2462 SOME mangled_s => |
2463 if String.isSubstring uncurried_alias_sep mangled_s then |
2463 if String.isSubstring uncurried_alias_sep mangled_s then |
2464 let |
2464 let |
2465 val base_s0 = mangled_s |> unmangled_const_name |> hd |> invert_const |
2465 val base_s0 = mangled_s |> unmangled_const_name |> hd |> invert_const |
2466 in |
2466 in |
2467 do_uncurried_alias_lines_for_sym ctxt monom_constrs format conj_sym_kind |
2467 do_uncurried_alias_lines_for_sym ctxt monom_constrs conj_sym_kind mono |
2468 mono type_enc sym_tab0 sym_tab base_s0 types in_conj min_ary |
2468 type_enc sym_tab0 sym_tab base_s0 types in_conj min_ary |
2469 end |
2469 end |
2470 else |
2470 else |
2471 ([], []) |
2471 ([], []) |
2472 | NONE => ([], []) |
2472 | NONE => ([], []) |
2473 fun uncurried_alias_lines_for_sym_table ctxt monom_constrs format conj_sym_kind |
2473 fun uncurried_alias_lines_for_sym_table ctxt monom_constrs conj_sym_kind mono |
2474 mono type_enc uncurried_aliases sym_tab0 sym_tab = |
2474 type_enc uncurried_aliases sym_tab0 sym_tab = |
2475 ([], []) |
2475 ([], []) |
2476 |> uncurried_aliases |
2476 |> uncurried_aliases |
2477 ? Symtab.fold_rev |
2477 ? Symtab.fold_rev |
2478 (pair_append |
2478 (pair_append |
2479 o uncurried_alias_lines_for_sym ctxt monom_constrs format |
2479 o uncurried_alias_lines_for_sym ctxt monom_constrs conj_sym_kind |
2480 conj_sym_kind mono type_enc sym_tab0 sym_tab) sym_tab |
2480 mono type_enc sym_tab0 sym_tab) sym_tab |
2481 |
2481 |
2482 val implicit_declsN = "Should-be-implicit typings" |
2482 val implicit_declsN = "Should-be-implicit typings" |
2483 val explicit_declsN = "Explicit typings" |
2483 val explicit_declsN = "Explicit typings" |
2484 val uncurried_alias_eqsN = "Uncurried aliases" |
2484 val uncurried_alias_eqsN = "Uncurried aliases" |
2485 val factsN = "Relevant facts" |
2485 val factsN = "Relevant facts" |
2594 \encoding.") |
2594 \encoding.") |
2595 else |
2595 else |
2596 lam_trans |
2596 lam_trans |
2597 val (fact_names, classes, conjs, facts, class_rel_clauses, arity_clauses, |
2597 val (fact_names, classes, conjs, facts, class_rel_clauses, arity_clauses, |
2598 lifted) = |
2598 lifted) = |
2599 translate_formulas ctxt format prem_kind type_enc lam_trans preproc hyp_ts |
2599 translate_formulas ctxt prem_kind format type_enc lam_trans preproc hyp_ts |
2600 concl_t facts |
2600 concl_t facts |
2601 val sym_tab0 = sym_table_for_facts ctxt type_enc app_op_level conjs facts |
2601 val sym_tab0 = sym_table_for_facts ctxt type_enc app_op_level conjs facts |
2602 val mono = conjs @ facts |> mononotonicity_info_for_facts ctxt type_enc |
2602 val mono = conjs @ facts |> mononotonicity_info_for_facts ctxt type_enc |
2603 val (polym_constrs, monom_constrs) = |
2603 val (polym_constrs, monom_constrs) = |
2604 all_constrs_of_polymorphic_datatypes thy |
2604 all_constrs_of_polymorphic_datatypes thy |
2605 |>> map (make_fixed_const (SOME format)) |
2605 |>> map (make_fixed_const (SOME type_enc)) |
2606 fun firstorderize in_helper = |
2606 fun firstorderize in_helper = |
2607 firstorderize_fact thy monom_constrs format type_enc sym_tab0 |
2607 firstorderize_fact thy monom_constrs type_enc sym_tab0 |
2608 (uncurried_aliases andalso not in_helper) |
2608 (uncurried_aliases andalso not in_helper) |
2609 val (conjs, facts) = (conjs, facts) |> pairself (map (firstorderize false)) |
2609 val (conjs, facts) = (conjs, facts) |> pairself (map (firstorderize false)) |
2610 val sym_tab = sym_table_for_facts ctxt type_enc Min_App_Op conjs facts |
2610 val sym_tab = sym_table_for_facts ctxt type_enc Min_App_Op conjs facts |
2611 val helpers = |
2611 val helpers = |
2612 sym_tab |> helper_facts_for_sym_table ctxt format type_enc |
2612 sym_tab |> helper_facts_for_sym_table ctxt format type_enc |
2613 |> map (firstorderize true) |
2613 |> map (firstorderize true) |
2614 val mono_Ts = |
2614 val mono_Ts = |
2615 helpers @ conjs @ facts |> monotonic_types_for_facts ctxt mono type_enc |
2615 helpers @ conjs @ facts |> monotonic_types_for_facts ctxt mono type_enc |
2616 val class_decl_lines = decl_lines_for_classes type_enc classes |
2616 val class_decl_lines = decl_lines_for_classes type_enc classes |
2617 val (uncurried_alias_eq_tms, uncurried_alias_eq_lines) = |
2617 val (uncurried_alias_eq_tms, uncurried_alias_eq_lines) = |
2618 uncurried_alias_lines_for_sym_table ctxt monom_constrs format |
2618 uncurried_alias_lines_for_sym_table ctxt monom_constrs conj_sym_kind mono |
2619 conj_sym_kind mono type_enc uncurried_aliases sym_tab0 sym_tab |
2619 type_enc uncurried_aliases sym_tab0 sym_tab |
2620 val sym_decl_lines = |
2620 val sym_decl_lines = |
2621 (conjs, helpers @ facts, uncurried_alias_eq_tms) |
2621 (conjs, helpers @ facts, uncurried_alias_eq_tms) |
2622 |> sym_decl_table_for_facts thy format type_enc sym_tab |
2622 |> sym_decl_table_for_facts thy type_enc sym_tab |
2623 |> problem_lines_for_sym_decl_table ctxt format conj_sym_kind mono |
2623 |> problem_lines_for_sym_decl_table ctxt conj_sym_kind mono type_enc |
2624 type_enc mono_Ts |
2624 mono_Ts |
2625 val num_facts = length facts |
2625 val num_facts = length facts |
2626 val fact_lines = |
2626 val fact_lines = |
2627 map (formula_line_for_fact ctxt polym_constrs format fact_prefix |
2627 map (formula_line_for_fact ctxt polym_constrs fact_prefix |
2628 ascii_of (not exporter) (not exporter) mono type_enc |
2628 ascii_of (not exporter) (not exporter) mono type_enc |
2629 (rank_of_fact_num num_facts)) |
2629 (rank_of_fact_num num_facts)) |
2630 (0 upto num_facts - 1 ~~ facts) |
2630 (0 upto num_facts - 1 ~~ facts) |
2631 val helper_lines = |
2631 val helper_lines = |
2632 0 upto length helpers - 1 ~~ helpers |
2632 0 upto length helpers - 1 ~~ helpers |
2633 |> map (formula_line_for_fact ctxt polym_constrs format helper_prefix I |
2633 |> map (formula_line_for_fact ctxt polym_constrs helper_prefix I false |
2634 false true mono type_enc (K default_rank)) |
2634 true mono type_enc (K default_rank)) |
2635 (* Reordering these might confuse the proof reconstruction code or the SPASS |
2635 (* Reordering these might confuse the proof reconstruction code or the SPASS |
2636 FLOTTER hack. *) |
2636 FLOTTER hack. *) |
2637 val problem = |
2637 val problem = |
2638 [(explicit_declsN, class_decl_lines @ sym_decl_lines), |
2638 [(explicit_declsN, class_decl_lines @ sym_decl_lines), |
2639 (uncurried_alias_eqsN, uncurried_alias_eq_lines), |
2639 (uncurried_alias_eqsN, uncurried_alias_eq_lines), |