194 else |
194 else |
195 let |
195 let |
196 val binding = mk_binding config type_name |
196 val binding = mk_binding config type_name |
197 val final_fqn = Sign.full_name thy binding |
197 val final_fqn = Sign.full_name thy binding |
198 val tyargs = |
198 val tyargs = |
199 List.tabulate (arity, rpair @{sort type} o prefix "'" o string_of_int) |
199 List.tabulate (arity, rpair \<^sort>\<open>type\<close> o prefix "'" o string_of_int) |
200 val (_, thy') = |
200 val (_, thy') = |
201 Typedecl.typedecl_global {final = true} (mk_binding config type_name, tyargs, NoSyn) thy |
201 Typedecl.typedecl_global {final = true} (mk_binding config type_name, tyargs, NoSyn) thy |
202 val typ_map_entry = (thf_type, (final_fqn, arity)) |
202 val typ_map_entry = (thf_type, (final_fqn, arity)) |
203 val ty_map' = typ_map_entry :: ty_map |
203 val ty_map' = typ_map_entry :: ty_map |
204 in (ty_map', thy') end |
204 in (ty_map', thy') end |
252 | fmlatype_to_type (Fmla (Interpreted_ExtraLogic Apply, [tm1, tm2])) = |
252 | fmlatype_to_type (Fmla (Interpreted_ExtraLogic Apply, [tm1, tm2])) = |
253 (case fmlatype_to_type tm1 of |
253 (case fmlatype_to_type tm1 of |
254 Atom_type (str, tys) => Atom_type (str, tys @ [fmlatype_to_type tm2])) |
254 Atom_type (str, tys) => Atom_type (str, tys @ [fmlatype_to_type tm2])) |
255 |
255 |
256 fun tfree_name_of_var_type str = "'" ^ Name.desymbolize (SOME false) str |
256 fun tfree_name_of_var_type str = "'" ^ Name.desymbolize (SOME false) str |
257 fun tfree_of_var_type str = TFree (tfree_name_of_var_type str, @{sort type}) |
257 fun tfree_of_var_type str = TFree (tfree_name_of_var_type str, \<^sort>\<open>type\<close>) |
258 |
258 |
259 fun interpret_type config thy type_map thf_ty = |
259 fun interpret_type config thy type_map thf_ty = |
260 let |
260 let |
261 fun lookup_type ty_map ary str = |
261 fun lookup_type ty_map ary str = |
262 (case AList.lookup (op =) ty_map str of |
262 (case AList.lookup (op =) ty_map str of |
271 raise MISINTERPRET_SYMBOL ("TPTP type used with wrong arity", |
271 raise MISINTERPRET_SYMBOL ("TPTP type used with wrong arity", |
272 Uninterpreted str)) |
272 Uninterpreted str)) |
273 in |
273 in |
274 case thf_ty of |
274 case thf_ty of |
275 Prod_type (thf_ty1, thf_ty2) => |
275 Prod_type (thf_ty1, thf_ty2) => |
276 Type (@{type_name prod}, |
276 Type (\<^type_name>\<open>prod\<close>, |
277 [interpret_type config thy type_map thf_ty1, |
277 [interpret_type config thy type_map thf_ty1, |
278 interpret_type config thy type_map thf_ty2]) |
278 interpret_type config thy type_map thf_ty2]) |
279 | Fn_type (thf_ty1, thf_ty2) => |
279 | Fn_type (thf_ty1, thf_ty2) => |
280 Type (@{type_name fun}, |
280 Type (\<^type_name>\<open>fun\<close>, |
281 [interpret_type config thy type_map thf_ty1, |
281 [interpret_type config thy type_map thf_ty1, |
282 interpret_type config thy type_map thf_ty2]) |
282 interpret_type config thy type_map thf_ty2]) |
283 | Atom_type (str, thf_tys) => |
283 | Atom_type (str, thf_tys) => |
284 Type (lookup_type type_map (length thf_tys) str, |
284 Type (lookup_type type_map (length thf_tys) str, |
285 map (interpret_type config thy type_map) thf_tys) |
285 map (interpret_type config thy type_map) thf_tys) |
286 | Var_type str => tfree_of_var_type str |
286 | Var_type str => tfree_of_var_type str |
287 | Defined_type tptp_base_type => |
287 | Defined_type tptp_base_type => |
288 (case tptp_base_type of |
288 (case tptp_base_type of |
289 Type_Ind => @{typ ind} |
289 Type_Ind => \<^typ>\<open>ind\<close> |
290 | Type_Bool => HOLogic.boolT |
290 | Type_Bool => HOLogic.boolT |
291 | Type_Type => raise MISINTERPRET_TYPE ("No type interpretation", thf_ty) |
291 | Type_Type => raise MISINTERPRET_TYPE ("No type interpretation", thf_ty) |
292 (*FIXME these types are currently unsupported, so they're treated as |
292 (*FIXME these types are currently unsupported, so they're treated as |
293 individuals*) |
293 individuals*) |
294 (* |
294 (* |
397 |> (Term.absdummy dummyT #> Term.absdummy dummyT) |
397 |> (Term.absdummy dummyT #> Term.absdummy dummyT) |
398 | Or => HOLogic.disj |
398 | Or => HOLogic.disj |
399 | And => HOLogic.conj |
399 | And => HOLogic.conj |
400 | Iff => HOLogic.eq_const HOLogic.boolT |
400 | Iff => HOLogic.eq_const HOLogic.boolT |
401 | If => HOLogic.imp |
401 | If => HOLogic.imp |
402 | Fi => @{term "\<lambda> x. \<lambda> y. y \<longrightarrow> x"} |
402 | Fi => \<^term>\<open>\<lambda> x. \<lambda> y. y \<longrightarrow> x\<close> |
403 | Xor => |
403 | Xor => |
404 @{term |
404 \<^term>\<open>\<lambda> x. \<lambda> y. \<not> (x \<longleftrightarrow> y)\<close> |
405 "\<lambda> x. \<lambda> y. \<not> (x \<longleftrightarrow> y)"} |
405 | Nor => \<^term>\<open>\<lambda> x. \<lambda> y. \<not> (x \<or> y)\<close> |
406 | Nor => @{term "\<lambda> x. \<lambda> y. \<not> (x \<or> y)"} |
406 | Nand => \<^term>\<open>\<lambda> x. \<lambda> y. \<not> (x \<and> y)\<close> |
407 | Nand => @{term "\<lambda> x. \<lambda> y. \<not> (x \<and> y)"} |
|
408 | Not => HOLogic.Not |
407 | Not => HOLogic.Not |
409 | Op_Forall => HOLogic.all_const dummyT |
408 | Op_Forall => HOLogic.all_const dummyT |
410 | Op_Exists => HOLogic.exists_const dummyT |
409 | Op_Exists => HOLogic.exists_const dummyT |
411 | True => @{term "True"} |
410 | True => \<^term>\<open>True\<close> |
412 | False => @{term "False"} |
411 | False => \<^term>\<open>False\<close> |
413 ) |
412 ) |
414 | TypeSymbol _ => |
413 | TypeSymbol _ => |
415 raise MISINTERPRET_SYMBOL |
414 raise MISINTERPRET_SYMBOL |
416 ("Cannot have TypeSymbol in term", symb) |
415 ("Cannot have TypeSymbol in term", symb) |
417 | System _ => |
416 | System _ => |
427 in (mapply args f', thy') end |
426 in (mapply args f', thy') end |
428 |
427 |
429 (*As above, but for products*) |
428 (*As above, but for products*) |
430 fun mtimes thy = |
429 fun mtimes thy = |
431 fold (fn x => fn y => |
430 fold (fn x => fn y => |
432 Sign.mk_const thy (@{const_name Pair}, [dummyT, dummyT]) $ y $ x) |
431 Sign.mk_const thy (\<^const_name>\<open>Pair\<close>, [dummyT, dummyT]) $ y $ x) |
433 |
432 |
434 fun mtimes' (args, thy) f = |
433 fun mtimes' (args, thy) f = |
435 let |
434 let |
436 val (f', thy') = f thy |
435 val (f', thy') = f thy |
437 in (mtimes thy' args f', thy') end |
436 in (mtimes thy' args f', thy') end |
483 fold (add_interp_symbol_to_thy false) ind_symbols thy |
482 fold (add_interp_symbol_to_thy false) ind_symbols thy |
484 |> fold (add_interp_symbol_to_thy true) bool_symbols |
483 |> fold (add_interp_symbol_to_thy true) bool_symbols |
485 end |
484 end |
486 |
485 |
487 (*Next batch of functions give info about Isabelle/HOL types*) |
486 (*Next batch of functions give info about Isabelle/HOL types*) |
488 fun is_fun (Type (@{type_name fun}, _)) = true |
487 fun is_fun (Type (\<^type_name>\<open>fun\<close>, _)) = true |
489 | is_fun _ = false |
488 | is_fun _ = false |
490 fun is_prod (Type (@{type_name prod}, _)) = true |
489 fun is_prod (Type (\<^type_name>\<open>prod\<close>, _)) = true |
491 | is_prod _ = false |
490 | is_prod _ = false |
492 fun dom_type (Type (@{type_name fun}, [ty1, _])) = ty1 |
491 fun dom_type (Type (\<^type_name>\<open>fun\<close>, [ty1, _])) = ty1 |
493 fun is_prod_typed thy config symb = |
492 fun is_prod_typed thy config symb = |
494 let |
493 let |
495 fun symb_type const_name = |
494 fun symb_type const_name = |
496 Sign.the_const_type thy (full_name thy config const_name) |
495 Sign.the_const_type thy (full_name thy config const_name) |
497 in |
496 in |
598 val (t_fmla, thy') = |
597 val (t_fmla, thy') = |
599 interpret_formula config language const_map var_types type_map tptp_formula thy |
598 interpret_formula config language const_map var_types type_map tptp_formula thy |
600 val ([t1, t2], thy'') = |
599 val ([t1, t2], thy'') = |
601 fold_map (interpret_term formula_level config language const_map var_types type_map) |
600 fold_map (interpret_term formula_level config language const_map var_types type_map) |
602 [tptp_t1, tptp_t2] thy' |
601 [tptp_t1, tptp_t2] thy' |
603 in (mk_n_fun 3 @{const_name If} $ t_fmla $ t1 $ t2, thy'') end |
602 in (mk_n_fun 3 \<^const_name>\<open>If\<close> $ t_fmla $ t1 $ t2, thy'') end |
604 | Term_Num (number_kind, num) => |
603 | Term_Num (number_kind, num) => |
605 let |
604 let |
606 (*FIXME hack*) |
605 (*FIXME hack*) |
607 (* |
606 (* |
608 val tptp_type = case number_kind of |
607 val tptp_type = case number_kind of |
716 in ((HOLogic.choice_const dummyT) $ t, thy') end |
715 in ((HOLogic.choice_const dummyT) $ t, thy') end |
717 | Iota => |
716 | Iota => |
718 let val (t, thy') = |
717 let val (t, thy') = |
719 interpret_formula config language const_map var_types type_map |
718 interpret_formula config language const_map var_types type_map |
720 (Quant (Lambda, bindings, tptp_formula)) thy |
719 (Quant (Lambda, bindings, tptp_formula)) thy |
721 in (Const (@{const_name The}, dummyT) $ t, thy') end |
720 in (Const (\<^const_name>\<open>The\<close>, dummyT) $ t, thy') end |
722 | Dep_Prod => |
721 | Dep_Prod => |
723 raise MISINTERPRET_FORMULA ("Unsupported", tptp_fmla) |
722 raise MISINTERPRET_FORMULA ("Unsupported", tptp_fmla) |
724 | Dep_Sum => |
723 | Dep_Sum => |
725 raise MISINTERPRET_FORMULA ("Unsupported", tptp_fmla) |
724 raise MISINTERPRET_FORMULA ("Unsupported", tptp_fmla) |
726 end |
725 end |
966 interpret_file cautious path_prefixes file_name type_map const_map thy |
965 interpret_file cautious path_prefixes file_name type_map const_map thy |
967 (*FIXME doesn't check if problem has already been interpreted*) |
966 (*FIXME doesn't check if problem has already been interpreted*) |
968 in TPTP_Data.map (cons ((prob_name, result))) thy' end |
967 in TPTP_Data.map (cons ((prob_name, result))) thy' end |
969 |
968 |
970 val _ = |
969 val _ = |
971 Outer_Syntax.command @{command_keyword import_tptp} "import TPTP problem" |
970 Outer_Syntax.command \<^command_keyword>\<open>import_tptp\<close> "import TPTP problem" |
972 (Parse.path >> (fn name => |
971 (Parse.path >> (fn name => |
973 Toplevel.theory (fn thy => |
972 Toplevel.theory (fn thy => |
974 let val path = Path.explode name |
973 let val path = Path.explode name |
975 (*NOTE: assumes include files are located at $TPTP/Axioms |
974 (*NOTE: assumes include files are located at $TPTP/Axioms |
976 (which is how TPTP is organised)*) |
975 (which is how TPTP is organised)*) |