| author | wenzelm | 
| Sat, 14 Sep 2013 14:01:48 +0200 | |
| changeset 53635 | b6fb9151de66 | 
| parent 53514 | fa5b34ffe4a4 | 
| child 53800 | ac1ec5065316 | 
| permissions | -rw-r--r-- | 
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 1 | (* Title: HOL/Tools/ATP/atp_util.ML | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 2 | Author: Jasmin Blanchette, TU Muenchen | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 3 | |
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 4 | General-purpose functions used by the ATP module. | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 5 | *) | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 6 | |
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 7 | signature ATP_UTIL = | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 8 | sig | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 9 | val timestamp : unit -> string | 
| 53514 | 10 | val hashw : word * word -> word | 
| 11 | val hashw_string : string * word -> word | |
| 43827 
62d64709af3b
added option to control which lambda translation to use (for experiments)
 blanchet parents: 
43572diff
changeset | 12 | val hash_string : string -> int | 
| 48323 | 13 | val chunk_list : int -> 'a list -> 'a list list | 
| 48251 
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
 blanchet parents: 
48247diff
changeset | 14 | val stringN_of_int : int -> int -> string | 
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 15 | val strip_spaces : bool -> (char -> bool) -> string -> string | 
| 44784 | 16 | val strip_spaces_except_between_idents : string -> string | 
| 48316 
252f45c04042
drastic overhaul of MaSh data structures + fixed a few performance issues
 blanchet parents: 
48251diff
changeset | 17 | val elide_string : int -> string -> string | 
| 52077 | 18 | val find_enclosed : string -> string -> string -> string list | 
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 19 | val nat_subscript : int -> string | 
| 52076 
bfa28e1cba77
freeze types in Sledgehammer goal, not just terms
 blanchet parents: 
52031diff
changeset | 20 | val unquote_tvar : string -> string | 
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 21 | val unyxml : string -> string | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 22 | val maybe_quote : string -> string | 
| 52031 
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
 blanchet parents: 
51209diff
changeset | 23 | val string_of_ext_time : bool * Time.time -> string | 
| 
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
 blanchet parents: 
51209diff
changeset | 24 | val string_of_time : Time.time -> string | 
| 47150 | 25 | val type_instance : theory -> typ -> typ -> bool | 
| 26 | val type_generalization : theory -> typ -> typ -> bool | |
| 27 | val type_intersect : theory -> typ -> typ -> bool | |
| 28 | val type_equiv : theory -> typ * typ -> bool | |
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 29 | val varify_type : Proof.context -> typ -> typ | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 30 | val instantiate_type : theory -> typ -> typ -> typ -> typ | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 31 | val varify_and_instantiate_type : Proof.context -> typ -> typ -> typ -> typ | 
| 45896 | 32 | val typ_of_dtyp : Datatype.descr -> (Datatype.dtyp * typ) list -> Datatype.dtyp -> typ | 
| 44393 | 33 | val is_type_surely_finite : Proof.context -> typ -> bool | 
| 44399 | 34 | val is_type_surely_infinite : Proof.context -> bool -> typ list -> typ -> bool | 
| 43863 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 35 | val s_not : term -> term | 
| 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 36 | val s_conj : term * term -> term | 
| 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 37 | val s_disj : term * term -> term | 
| 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 38 | val s_imp : term * term -> term | 
| 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 39 | val s_iff : term * term -> term | 
| 49983 
33e18e9916a8
use metaquantification when possible in Isar proofs
 blanchet parents: 
49982diff
changeset | 40 | val close_form : term -> term | 
| 49982 | 41 | val hol_close_form_prefix : string | 
| 42 | val hol_close_form : term -> term | |
| 43 | val hol_open_form : (string -> string) -> term -> term | |
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 44 | val monomorphic_term : Type.tyenv -> term -> term | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 45 | val eta_expand : typ list -> term -> int -> term | 
| 47954 
aada9fd08b58
make higher-order goals more first-order via extensionality
 blanchet parents: 
47953diff
changeset | 46 | val cong_extensionalize_term : theory -> term -> term | 
| 47953 
a2c3706c4cb1
added "ext_cong_neq" lemma (not used yet); tuning
 blanchet parents: 
47718diff
changeset | 47 | val abs_extensionalize_term : Proof.context -> term -> term | 
| 47991 
3eb598b044ad
make Nitpick's handling of definitions more robust in the face of formulas that don't have the expected format (needed for soundness, cf. RNG100+1)
 blanchet parents: 
47954diff
changeset | 48 | val unextensionalize_def : term -> term | 
| 
3eb598b044ad
make Nitpick's handling of definitions more robust in the face of formulas that don't have the expected format (needed for soundness, cf. RNG100+1)
 blanchet parents: 
47954diff
changeset | 49 | val is_legitimate_tptp_def : term -> bool | 
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 50 | val transform_elim_prop : term -> term | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 51 | val specialize_type : theory -> (string * typ) -> term -> term | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 52 | val strip_subgoal : | 
| 52196 
2281f33e8da6
redid rac7830871177 to avoid duplicate fixed variable (e.g. lemma "P (a::nat)" proof - have "!!a::int. Q a" sledgehammer [e])
 blanchet parents: 
52125diff
changeset | 53 | thm -> int -> Proof.context -> (string * typ) list * term list * term | 
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 54 | end; | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 55 | |
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 56 | structure ATP_Util : ATP_UTIL = | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 57 | struct | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 58 | |
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 59 | val timestamp = Date.fmt "%Y-%m-%d %H:%M:%S" o Date.fromTimeLocal o Time.now | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 60 | |
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 61 | (* This hash function is recommended in "Compilers: Principles, Techniques, and | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 62 | Tools" by Aho, Sethi, and Ullman. The "hashpjw" function, which they | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 63 | particularly recommend, triggers a bug in versions of Poly/ML up to 4.2.0. *) | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 64 | fun hashw (u, w) = Word.+ (u, Word.* (0w65599, w)) | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 65 | fun hashw_char (c, w) = hashw (Word.fromInt (Char.ord c), w) | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 66 | fun hashw_string (s : string, w) = CharVector.foldl hashw_char w s | 
| 43827 
62d64709af3b
added option to control which lambda translation to use (for experiments)
 blanchet parents: 
43572diff
changeset | 67 | fun hash_string s = Word.toInt (hashw_string (s, 0w0)) | 
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 68 | |
| 48323 | 69 | fun chunk_list _ [] = [] | 
| 70 | | chunk_list k xs = | |
| 71 | let val (xs1, xs2) = chop k xs in xs1 :: chunk_list k xs2 end | |
| 72 | ||
| 48251 
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
 blanchet parents: 
48247diff
changeset | 73 | fun stringN_of_int 0 _ = "" | 
| 
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
 blanchet parents: 
48247diff
changeset | 74 | | stringN_of_int k n = | 
| 
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
 blanchet parents: 
48247diff
changeset | 75 | stringN_of_int (k - 1) (n div 10) ^ string_of_int (n mod 10) | 
| 
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
 blanchet parents: 
48247diff
changeset | 76 | |
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 77 | fun strip_spaces skip_comments is_evil = | 
| 44935 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 78 | let | 
| 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 79 | fun strip_c_style_comment [] accum = accum | 
| 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 80 | | strip_c_style_comment (#"*" :: #"/" :: cs) accum = | 
| 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 81 | strip_spaces_in_list true cs accum | 
| 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 82 | | strip_c_style_comment (_ :: cs) accum = strip_c_style_comment cs accum | 
| 48766 
553ad5f99968
fixed "double rev" bug that arose in situations where a % comment arose on the last line of a file without \n at the end
 blanchet parents: 
48323diff
changeset | 83 | and strip_spaces_in_list _ [] accum = accum | 
| 44935 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 84 | | strip_spaces_in_list true (#"%" :: cs) accum = | 
| 48902 
44a6967240b7
prefer classic take_prefix/take_suffix over chop_while (cf. 0659e84bdc5f);
 wenzelm parents: 
48766diff
changeset | 85 | strip_spaces_in_list true (cs |> take_prefix (not_equal #"\n") |> snd) | 
| 44935 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 86 | accum | 
| 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 87 | | strip_spaces_in_list true (#"/" :: #"*" :: cs) accum = | 
| 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 88 | strip_c_style_comment cs accum | 
| 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 89 | | strip_spaces_in_list _ [c1] accum = | 
| 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 90 | accum |> not (Char.isSpace c1) ? cons c1 | 
| 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 91 | | strip_spaces_in_list skip_comments (cs as [_, _]) accum = | 
| 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 92 | accum |> fold (strip_spaces_in_list skip_comments o single) cs | 
| 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 93 | | strip_spaces_in_list skip_comments (c1 :: c2 :: c3 :: cs) accum = | 
| 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 94 | if Char.isSpace c1 then | 
| 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 95 | strip_spaces_in_list skip_comments (c2 :: c3 :: cs) accum | 
| 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 96 | else if Char.isSpace c2 then | 
| 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 97 | if Char.isSpace c3 then | 
| 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 98 | strip_spaces_in_list skip_comments (c1 :: c3 :: cs) accum | 
| 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 99 | else | 
| 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 100 | strip_spaces_in_list skip_comments (c3 :: cs) | 
| 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 101 | (c1 :: accum |> forall is_evil [c1, c3] ? cons #" ") | 
| 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 102 | else | 
| 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 103 | strip_spaces_in_list skip_comments (c2 :: c3 :: cs) (cons c1 accum) | 
| 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 104 | in | 
| 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 105 | String.explode | 
| 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 106 | #> rpair [] #-> strip_spaces_in_list skip_comments | 
| 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 107 | #> rev #> String.implode | 
| 
2e812384afa8
tail recursive proof preprocessing (needed for huge proofs)
 blanchet parents: 
44893diff
changeset | 108 | end | 
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 109 | |
| 44784 | 110 | fun is_ident_char c = Char.isAlphaNum c orelse c = #"_" | 
| 111 | val strip_spaces_except_between_idents = strip_spaces true is_ident_char | |
| 112 | ||
| 48316 
252f45c04042
drastic overhaul of MaSh data structures + fixed a few performance issues
 blanchet parents: 
48251diff
changeset | 113 | fun elide_string threshold s = | 
| 
252f45c04042
drastic overhaul of MaSh data structures + fixed a few performance issues
 blanchet parents: 
48251diff
changeset | 114 | if size s > threshold then | 
| 
252f45c04042
drastic overhaul of MaSh data structures + fixed a few performance issues
 blanchet parents: 
48251diff
changeset | 115 | String.extract (s, 0, SOME (threshold div 2 - 5)) ^ " ...... " ^ | 
| 
252f45c04042
drastic overhaul of MaSh data structures + fixed a few performance issues
 blanchet parents: 
48251diff
changeset | 116 | String.extract (s, size s - (threshold + 1) div 2 + 6, NONE) | 
| 
252f45c04042
drastic overhaul of MaSh data structures + fixed a few performance issues
 blanchet parents: 
48251diff
changeset | 117 | else | 
| 
252f45c04042
drastic overhaul of MaSh data structures + fixed a few performance issues
 blanchet parents: 
48251diff
changeset | 118 | s | 
| 
252f45c04042
drastic overhaul of MaSh data structures + fixed a few performance issues
 blanchet parents: 
48251diff
changeset | 119 | |
| 52077 | 120 | fun find_enclosed left right s = | 
| 121 | case first_field left s of | |
| 122 | SOME (_, s) => | |
| 123 | (case first_field right s of | |
| 124 | SOME (enclosed, s) => enclosed :: find_enclosed left right s | |
| 125 | | NONE => []) | |
| 126 | | NONE => [] | |
| 127 | ||
| 53015 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 wenzelm parents: 
52196diff
changeset | 128 | val subscript = implode o map (prefix "\<^sub>") o raw_explode (* FIXME Symbol.explode (?) *) | 
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 129 | fun nat_subscript n = | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 130 | n |> string_of_int |> print_mode_active Symbol.xsymbolsN ? subscript | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 131 | |
| 52076 
bfa28e1cba77
freeze types in Sledgehammer goal, not just terms
 blanchet parents: 
52031diff
changeset | 132 | val unquote_tvar = perhaps (try (unprefix "'")) | 
| 
bfa28e1cba77
freeze types in Sledgehammer goal, not just terms
 blanchet parents: 
52031diff
changeset | 133 | val unquery_var = perhaps (try (unprefix "?")) | 
| 
bfa28e1cba77
freeze types in Sledgehammer goal, not just terms
 blanchet parents: 
52031diff
changeset | 134 | |
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 135 | val unyxml = XML.content_of o YXML.parse_body | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 136 | |
| 50239 | 137 | val is_long_identifier = forall Symbol_Pos.is_identifier o Long_Name.explode | 
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 138 | fun maybe_quote y = | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 139 | let val s = unyxml y in | 
| 52076 
bfa28e1cba77
freeze types in Sledgehammer goal, not just terms
 blanchet parents: 
52031diff
changeset | 140 | y |> ((not (is_long_identifier (unquote_tvar s)) andalso | 
| 
bfa28e1cba77
freeze types in Sledgehammer goal, not just terms
 blanchet parents: 
52031diff
changeset | 141 | not (is_long_identifier (unquery_var s))) orelse | 
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 142 | Keyword.is_keyword s) ? quote | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 143 | end | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 144 | |
| 52031 
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
 blanchet parents: 
51209diff
changeset | 145 | fun string_of_ext_time (plus, time) = | 
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 146 | let val ms = Time.toMilliseconds time in | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 147 | (if plus then "> " else "") ^ | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 148 | (if plus andalso ms mod 1000 = 0 then | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 149 | signed_string_of_int (ms div 1000) ^ " s" | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 150 | else if ms < 1000 then | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 151 | signed_string_of_int ms ^ " ms" | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 152 | else | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 153 | string_of_real (0.01 * Real.fromInt (ms div 10)) ^ " s") | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 154 | end | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 155 | |
| 52031 
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
 blanchet parents: 
51209diff
changeset | 156 | val string_of_time = string_of_ext_time o pair false | 
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 157 | |
| 47150 | 158 | fun type_instance thy T T' = Sign.typ_instance thy (T, T') | 
| 159 | fun type_generalization thy T T' = Sign.typ_instance thy (T', T) | |
| 48247 
8f37d2ddabc8
optimized type intersection, hoping this will reduce the number of sudden Interrupts in the "incr_tvar" code
 blanchet parents: 
48238diff
changeset | 160 | |
| 
8f37d2ddabc8
optimized type intersection, hoping this will reduce the number of sudden Interrupts in the "incr_tvar" code
 blanchet parents: 
48238diff
changeset | 161 | fun type_intersect _ (TVar _) _ = true | 
| 
8f37d2ddabc8
optimized type intersection, hoping this will reduce the number of sudden Interrupts in the "incr_tvar" code
 blanchet parents: 
48238diff
changeset | 162 | | type_intersect _ _ (TVar _) = true | 
| 
8f37d2ddabc8
optimized type intersection, hoping this will reduce the number of sudden Interrupts in the "incr_tvar" code
 blanchet parents: 
48238diff
changeset | 163 | | type_intersect thy T T' = | 
| 
8f37d2ddabc8
optimized type intersection, hoping this will reduce the number of sudden Interrupts in the "incr_tvar" code
 blanchet parents: 
48238diff
changeset | 164 | let | 
| 
8f37d2ddabc8
optimized type intersection, hoping this will reduce the number of sudden Interrupts in the "incr_tvar" code
 blanchet parents: 
48238diff
changeset | 165 | val tvars = Term.add_tvar_namesT T [] | 
| 
8f37d2ddabc8
optimized type intersection, hoping this will reduce the number of sudden Interrupts in the "incr_tvar" code
 blanchet parents: 
48238diff
changeset | 166 | val tvars' = Term.add_tvar_namesT T' [] | 
| 50968 
3686bc0d4df2
pass correct index to "Sign.typ_unify" -- this is important to avoid what appears to be an infinite loop in the unifier
 blanchet parents: 
50239diff
changeset | 167 | val maxidx' = maxidx_of_typ T' | 
| 48247 
8f37d2ddabc8
optimized type intersection, hoping this will reduce the number of sudden Interrupts in the "incr_tvar" code
 blanchet parents: 
48238diff
changeset | 168 | val T = | 
| 50968 
3686bc0d4df2
pass correct index to "Sign.typ_unify" -- this is important to avoid what appears to be an infinite loop in the unifier
 blanchet parents: 
50239diff
changeset | 169 | T |> exists (member (op =) tvars') tvars ? Logic.incr_tvar (maxidx' + 1) | 
| 
3686bc0d4df2
pass correct index to "Sign.typ_unify" -- this is important to avoid what appears to be an infinite loop in the unifier
 blanchet parents: 
50239diff
changeset | 170 | val maxidx = Integer.max (maxidx_of_typ T) maxidx' | 
| 
3686bc0d4df2
pass correct index to "Sign.typ_unify" -- this is important to avoid what appears to be an infinite loop in the unifier
 blanchet parents: 
50239diff
changeset | 171 | in can (Sign.typ_unify thy (T, T')) (Vartab.empty, maxidx) end | 
| 48247 
8f37d2ddabc8
optimized type intersection, hoping this will reduce the number of sudden Interrupts in the "incr_tvar" code
 blanchet parents: 
48238diff
changeset | 172 | |
| 47150 | 173 | val type_equiv = Sign.typ_equiv | 
| 44399 | 174 | |
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 175 | fun varify_type ctxt T = | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 176 |   Variable.polymorphic_types ctxt [Const (@{const_name undefined}, T)]
 | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 177 | |> snd |> the_single |> dest_Const |> snd | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 178 | |
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 179 | (* TODO: use "Term_Subst.instantiateT" instead? *) | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 180 | fun instantiate_type thy T1 T1' T2 = | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 181 | Same.commit (Envir.subst_type_same | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 182 | (Sign.typ_match thy (T1, T1') Vartab.empty)) T2 | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 183 |   handle Type.TYPE_MATCH => raise TYPE ("instantiate_type", [T1, T1'], [])
 | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 184 | |
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 185 | fun varify_and_instantiate_type ctxt T1 T1' T2 = | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 186 | let val thy = Proof_Context.theory_of ctxt in | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 187 | instantiate_type thy (varify_type ctxt T1) T1' (varify_type ctxt T2) | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 188 | end | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 189 | |
| 45896 | 190 | fun typ_of_dtyp _ typ_assoc (Datatype.DtTFree a) = | 
| 191 | the (AList.lookup (op =) typ_assoc (Datatype.DtTFree a)) | |
| 192 | | typ_of_dtyp descr typ_assoc (Datatype.DtType (s, Us)) = | |
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 193 | Type (s, map (typ_of_dtyp descr typ_assoc) Us) | 
| 45896 | 194 | | typ_of_dtyp descr typ_assoc (Datatype.DtRec i) = | 
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 195 | let val (s, ds, _) = the (AList.lookup (op =) descr i) in | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 196 | Type (s, map (typ_of_dtyp descr typ_assoc) ds) | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 197 | end | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 198 | |
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 199 | fun datatype_constrs thy (T as Type (s, Ts)) = | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 200 | (case Datatype.get_info thy s of | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 201 |        SOME {index, descr, ...} =>
 | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 202 | let val (_, dtyps, constrs) = AList.lookup (op =) descr index |> the in | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 203 | map (apsnd (fn Us => map (typ_of_dtyp descr (dtyps ~~ Ts)) Us ---> T)) | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 204 | constrs | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 205 | end | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 206 | | NONE => []) | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 207 | | datatype_constrs _ _ = [] | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 208 | |
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 209 | (* Similar to "Nitpick_HOL.bounded_exact_card_of_type". | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 210 | 0 means infinite type, 1 means singleton type (e.g., "unit"), and 2 means | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 211 | cardinality 2 or more. The specified default cardinality is returned if the | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 212 | cardinality of the type can't be determined. *) | 
| 44500 | 213 | fun tiny_card_of_type ctxt sound assigns default_card T = | 
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 214 | let | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 215 | val thy = Proof_Context.theory_of ctxt | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 216 | val max = 2 (* 1 would be too small for the "fun" case *) | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 217 | fun aux slack avoid T = | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 218 | if member (op =) avoid T then | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 219 | 0 | 
| 47150 | 220 | else case AList.lookup (type_equiv thy) assigns T of | 
| 44393 | 221 | SOME k => k | 
| 222 | | NONE => | |
| 44392 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 223 | case T of | 
| 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 224 |           Type (@{type_name fun}, [T1, T2]) =>
 | 
| 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 225 | (case (aux slack avoid T1, aux slack avoid T2) of | 
| 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 226 | (k, 1) => if slack andalso k = 0 then 0 else 1 | 
| 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 227 | | (0, _) => 0 | 
| 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 228 | | (_, 0) => 0 | 
| 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 229 | | (k1, k2) => | 
| 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 230 | if k1 >= max orelse k2 >= max then max | 
| 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 231 | else Int.min (max, Integer.pow k2 k1)) | 
| 48230 
0feb93dfb268
gracefully compute cardinality of sets (to avoid type protectors)
 blanchet parents: 
47991diff
changeset | 232 |         | Type (@{type_name set}, [T']) => aux slack avoid (T' --> @{typ bool})
 | 
| 44392 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 233 |         | @{typ prop} => 2
 | 
| 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 234 |         | @{typ bool} => 2 (* optimization *)
 | 
| 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 235 |         | @{typ nat} => 0 (* optimization *)
 | 
| 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 236 |         | Type ("Int.int", []) => 0 (* optimization *)
 | 
| 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 237 | | Type (s, _) => | 
| 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 238 | (case datatype_constrs thy T of | 
| 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 239 | constrs as _ :: _ => | 
| 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 240 | let | 
| 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 241 | val constr_cards = | 
| 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 242 | map (Integer.prod o map (aux slack (T :: avoid)) o binder_types | 
| 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 243 | o snd) constrs | 
| 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 244 | in | 
| 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 245 | if exists (curry (op =) 0) constr_cards then 0 | 
| 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 246 | else Int.min (max, Integer.sum constr_cards) | 
| 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 247 | end | 
| 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 248 | | [] => | 
| 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 249 | case Typedef.get_info ctxt s of | 
| 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 250 |                ({abs_type, rep_type, ...}, _) :: _ =>
 | 
| 45299 
ee584ff987c3
check "sound" flag before doing something unsound...
 blanchet parents: 
44935diff
changeset | 251 | if not sound then | 
| 
ee584ff987c3
check "sound" flag before doing something unsound...
 blanchet parents: 
44935diff
changeset | 252 | (* We cheat here by assuming that typedef types are infinite if | 
| 
ee584ff987c3
check "sound" flag before doing something unsound...
 blanchet parents: 
44935diff
changeset | 253 | their underlying type is infinite. This is unsound in | 
| 
ee584ff987c3
check "sound" flag before doing something unsound...
 blanchet parents: 
44935diff
changeset | 254 | general but it's hard to think of a realistic example where | 
| 
ee584ff987c3
check "sound" flag before doing something unsound...
 blanchet parents: 
44935diff
changeset | 255 | this would not be the case. We are also slack with | 
| 
ee584ff987c3
check "sound" flag before doing something unsound...
 blanchet parents: 
44935diff
changeset | 256 | representation types: If a representation type has the form | 
| 
ee584ff987c3
check "sound" flag before doing something unsound...
 blanchet parents: 
44935diff
changeset | 257 | "sigma => tau", we consider it enough to check "sigma" for | 
| 
ee584ff987c3
check "sound" flag before doing something unsound...
 blanchet parents: 
44935diff
changeset | 258 | infiniteness. *) | 
| 
ee584ff987c3
check "sound" flag before doing something unsound...
 blanchet parents: 
44935diff
changeset | 259 | (case varify_and_instantiate_type ctxt | 
| 
ee584ff987c3
check "sound" flag before doing something unsound...
 blanchet parents: 
44935diff
changeset | 260 | (Logic.varifyT_global abs_type) T | 
| 
ee584ff987c3
check "sound" flag before doing something unsound...
 blanchet parents: 
44935diff
changeset | 261 | (Logic.varifyT_global rep_type) | 
| 
ee584ff987c3
check "sound" flag before doing something unsound...
 blanchet parents: 
44935diff
changeset | 262 | |> aux true avoid of | 
| 
ee584ff987c3
check "sound" flag before doing something unsound...
 blanchet parents: 
44935diff
changeset | 263 | 0 => 0 | 
| 
ee584ff987c3
check "sound" flag before doing something unsound...
 blanchet parents: 
44935diff
changeset | 264 | | 1 => 1 | 
| 
ee584ff987c3
check "sound" flag before doing something unsound...
 blanchet parents: 
44935diff
changeset | 265 | | _ => default_card) | 
| 
ee584ff987c3
check "sound" flag before doing something unsound...
 blanchet parents: 
44935diff
changeset | 266 | else | 
| 
ee584ff987c3
check "sound" flag before doing something unsound...
 blanchet parents: 
44935diff
changeset | 267 | default_card | 
| 44392 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 268 | | [] => default_card) | 
| 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 269 | (* Very slightly unsound: Type variables are assumed not to be | 
| 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 270 | constrained to cardinality 1. (In practice, the user would most | 
| 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 271 | likely have used "unit" directly anyway.) *) | 
| 44500 | 272 | | TFree _ => | 
| 273 | if not sound andalso default_card = 1 then 2 else default_card | |
| 44392 
6750b4297691
reintroduced slightly unsound optimization taken out in 717880e98e6b, but only if "sound" is false
 blanchet parents: 
43864diff
changeset | 274 | | TVar _ => default_card | 
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 275 | in Int.min (max, aux false [] T) end | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 276 | |
| 44500 | 277 | fun is_type_surely_finite ctxt T = tiny_card_of_type ctxt true [] 0 T <> 0 | 
| 278 | fun is_type_surely_infinite ctxt sound infinite_Ts T = | |
| 279 | tiny_card_of_type ctxt sound (map (rpair 0) infinite_Ts) 1 T = 0 | |
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 280 | |
| 43863 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 281 | (* Simple simplifications to ensure that sort annotations don't leave a trail of | 
| 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 282 | spurious "True"s. *) | 
| 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 283 | fun s_not (Const (@{const_name All}, T) $ Abs (s, T', t')) =
 | 
| 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 284 |     Const (@{const_name Ex}, T) $ Abs (s, T', s_not t')
 | 
| 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 285 |   | s_not (Const (@{const_name Ex}, T) $ Abs (s, T', t')) =
 | 
| 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 286 |     Const (@{const_name All}, T) $ Abs (s, T', s_not t')
 | 
| 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 287 |   | s_not (@{const HOL.implies} $ t1 $ t2) = @{const HOL.conj} $ t1 $ s_not t2
 | 
| 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 288 |   | s_not (@{const HOL.conj} $ t1 $ t2) =
 | 
| 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 289 |     @{const HOL.disj} $ s_not t1 $ s_not t2
 | 
| 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 290 |   | s_not (@{const HOL.disj} $ t1 $ t2) =
 | 
| 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 291 |     @{const HOL.conj} $ s_not t1 $ s_not t2
 | 
| 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 292 |   | s_not (@{const False}) = @{const True}
 | 
| 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 293 |   | s_not (@{const True}) = @{const False}
 | 
| 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 294 |   | s_not (@{const Not} $ t) = t
 | 
| 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 295 |   | s_not t = @{const Not} $ t
 | 
| 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 296 | fun s_conj (@{const True}, t2) = t2
 | 
| 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 297 |   | s_conj (t1, @{const True}) = t1
 | 
| 51209 | 298 |   | s_conj (@{const False}, _) = @{const False}
 | 
| 299 |   | s_conj (_, @{const False}) = @{const False}
 | |
| 51197 | 300 | | s_conj (t1, t2) = if t1 aconv t2 then t1 else HOLogic.mk_conj (t1, t2) | 
| 43863 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 301 | fun s_disj (@{const False}, t2) = t2
 | 
| 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 302 |   | s_disj (t1, @{const False}) = t1
 | 
| 51209 | 303 |   | s_disj (@{const True}, _) = @{const True}
 | 
| 304 |   | s_disj (_, @{const True}) = @{const True}
 | |
| 51197 | 305 | | s_disj (t1, t2) = if t1 aconv t2 then t1 else HOLogic.mk_disj (t1, t2) | 
| 43863 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 306 | fun s_imp (@{const True}, t2) = t2
 | 
| 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 307 |   | s_imp (t1, @{const False}) = s_not t1
 | 
| 51209 | 308 |   | s_imp (@{const False}, _) = @{const True}
 | 
| 309 |   | s_imp (_, @{const True}) = @{const True}
 | |
| 43863 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 310 | | s_imp p = HOLogic.mk_imp p | 
| 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 311 | fun s_iff (@{const True}, t2) = t2
 | 
| 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 312 |   | s_iff (t1, @{const True}) = t1
 | 
| 51209 | 313 |   | s_iff (@{const False}, t2) = s_not t2
 | 
| 314 |   | s_iff (t1, @{const False}) = s_not t1
 | |
| 43863 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 315 | | s_iff (t1, t2) = HOLogic.eq_const HOLogic.boolT $ t1 $ t2 | 
| 
a43d61270142
ensure that the lambda translation procedure is called only once with all the facts, which is necessary for soundness of lambda-lifting (freshness of new names)
 blanchet parents: 
43827diff
changeset | 316 | |
| 49983 
33e18e9916a8
use metaquantification when possible in Isar proofs
 blanchet parents: 
49982diff
changeset | 317 | (* cf. "close_form" in "refute.ML" *) | 
| 
33e18e9916a8
use metaquantification when possible in Isar proofs
 blanchet parents: 
49982diff
changeset | 318 | fun close_form t = | 
| 
33e18e9916a8
use metaquantification when possible in Isar proofs
 blanchet parents: 
49982diff
changeset | 319 | fold (fn ((s, i), T) => fn t' => | 
| 
33e18e9916a8
use metaquantification when possible in Isar proofs
 blanchet parents: 
49982diff
changeset | 320 | Logic.all_const T $ Abs (s, T, abstract_over (Var ((s, i), T), t'))) | 
| 
33e18e9916a8
use metaquantification when possible in Isar proofs
 blanchet parents: 
49982diff
changeset | 321 | (Term.add_vars t []) t | 
| 
33e18e9916a8
use metaquantification when possible in Isar proofs
 blanchet parents: 
49982diff
changeset | 322 | |
| 49982 | 323 | val hol_close_form_prefix = "ATP.close_form." | 
| 46385 
0ccf458a3633
third attempt at lambda lifting that works for both Sledgehammer and Metis (cf. dce6c3a460a9)
 blanchet parents: 
45896diff
changeset | 324 | |
| 49982 | 325 | fun hol_close_form t = | 
| 45570 
6d95a66cce00
pull variables (Var) out of lambdas, so that the Isabelle theorems closely mirror the Metis lambda-lifted ones
 blanchet parents: 
45511diff
changeset | 326 | fold (fn ((s, i), T) => fn t' => | 
| 45511 
9b0f8ca4388e
continued implementation of lambda-lifting in Metis
 blanchet parents: 
45299diff
changeset | 327 | HOLogic.all_const T | 
| 49982 | 328 | $ Abs (hol_close_form_prefix ^ s, T, | 
| 46385 
0ccf458a3633
third attempt at lambda lifting that works for both Sledgehammer and Metis (cf. dce6c3a460a9)
 blanchet parents: 
45896diff
changeset | 329 | abstract_over (Var ((s, i), T), t'))) | 
| 43864 
58a7b3fdc193
fixed lambda-liftg: must ensure the formulas are in close form
 blanchet parents: 
43863diff
changeset | 330 | (Term.add_vars t []) t | 
| 
58a7b3fdc193
fixed lambda-liftg: must ensure the formulas are in close form
 blanchet parents: 
43863diff
changeset | 331 | |
| 49982 | 332 | fun hol_open_form unprefix | 
| 333 |       (t as Const (@{const_name All}, _) $ Abs (s, T, t')) =
 | |
| 47718 
39229c760636
smoother handling of conjecture, so that its Skolem constants get displayed in countermodels
 blanchet parents: 
47715diff
changeset | 334 | (case try unprefix s of | 
| 
39229c760636
smoother handling of conjecture, so that its Skolem constants get displayed in countermodels
 blanchet parents: 
47715diff
changeset | 335 | SOME s => | 
| 
39229c760636
smoother handling of conjecture, so that its Skolem constants get displayed in countermodels
 blanchet parents: 
47715diff
changeset | 336 | let | 
| 
39229c760636
smoother handling of conjecture, so that its Skolem constants get displayed in countermodels
 blanchet parents: 
47715diff
changeset | 337 | val names = Name.make_context (map fst (Term.add_var_names t' [])) | 
| 
39229c760636
smoother handling of conjecture, so that its Skolem constants get displayed in countermodels
 blanchet parents: 
47715diff
changeset | 338 | val (s, _) = Name.variant s names | 
| 49982 | 339 | in hol_open_form unprefix (subst_bound (Var ((s, 0), T), t')) end | 
| 47718 
39229c760636
smoother handling of conjecture, so that its Skolem constants get displayed in countermodels
 blanchet parents: 
47715diff
changeset | 340 | | NONE => t) | 
| 49982 | 341 | | hol_open_form _ t = t | 
| 47718 
39229c760636
smoother handling of conjecture, so that its Skolem constants get displayed in countermodels
 blanchet parents: 
47715diff
changeset | 342 | |
| 43171 
37e1431cc213
gracefully handle the case where a constant is partially or not instantiated at all, as may happen when reconstructing Metis proofs for polymorphic type encodings
 blanchet parents: 
43085diff
changeset | 343 | fun monomorphic_term subst = | 
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 344 | map_types (map_type_tvar (fn v => | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 345 | case Type.lookup subst v of | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 346 | SOME typ => typ | 
| 43171 
37e1431cc213
gracefully handle the case where a constant is partially or not instantiated at all, as may happen when reconstructing Metis proofs for polymorphic type encodings
 blanchet parents: 
43085diff
changeset | 347 | | NONE => TVar v)) | 
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 348 | |
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 349 | fun eta_expand _ t 0 = t | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 350 | | eta_expand Ts (Abs (s, T, t')) n = | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 351 | Abs (s, T, eta_expand (T :: Ts) t' (n - 1)) | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 352 | | eta_expand Ts t n = | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 353 |     fold_rev (fn T => fn t' => Abs ("x" ^ nat_subscript n, T, t'))
 | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 354 | (List.take (binder_types (fastype_of1 (Ts, t)), n)) | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 355 | (list_comb (incr_boundvars n t, map Bound (n - 1 downto 0))) | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 356 | |
| 47954 
aada9fd08b58
make higher-order goals more first-order via extensionality
 blanchet parents: 
47953diff
changeset | 357 | fun cong_extensionalize_term thy t = | 
| 
aada9fd08b58
make higher-order goals more first-order via extensionality
 blanchet parents: 
47953diff
changeset | 358 |   if exists_Const (fn (s, _) => s = @{const_name Not}) t then
 | 
| 
aada9fd08b58
make higher-order goals more first-order via extensionality
 blanchet parents: 
47953diff
changeset | 359 | t |> Skip_Proof.make_thm thy | 
| 
aada9fd08b58
make higher-order goals more first-order via extensionality
 blanchet parents: 
47953diff
changeset | 360 | |> Meson.cong_extensionalize_thm thy | 
| 
aada9fd08b58
make higher-order goals more first-order via extensionality
 blanchet parents: 
47953diff
changeset | 361 | |> prop_of | 
| 
aada9fd08b58
make higher-order goals more first-order via extensionality
 blanchet parents: 
47953diff
changeset | 362 | else | 
| 
aada9fd08b58
make higher-order goals more first-order via extensionality
 blanchet parents: 
47953diff
changeset | 363 | t | 
| 
aada9fd08b58
make higher-order goals more first-order via extensionality
 blanchet parents: 
47953diff
changeset | 364 | |
| 47715 
04400144c6fc
handle TPTP definitions as definitions in Nitpick rather than as axioms
 blanchet parents: 
47150diff
changeset | 365 | fun is_fun_equality (@{const_name HOL.eq},
 | 
| 
04400144c6fc
handle TPTP definitions as definitions in Nitpick rather than as axioms
 blanchet parents: 
47150diff
changeset | 366 |                      Type (_, [Type (@{type_name fun}, _), _])) = true
 | 
| 
04400144c6fc
handle TPTP definitions as definitions in Nitpick rather than as axioms
 blanchet parents: 
47150diff
changeset | 367 | | is_fun_equality _ = false | 
| 
04400144c6fc
handle TPTP definitions as definitions in Nitpick rather than as axioms
 blanchet parents: 
47150diff
changeset | 368 | |
| 47953 
a2c3706c4cb1
added "ext_cong_neq" lemma (not used yet); tuning
 blanchet parents: 
47718diff
changeset | 369 | fun abs_extensionalize_term ctxt t = | 
| 47715 
04400144c6fc
handle TPTP definitions as definitions in Nitpick rather than as axioms
 blanchet parents: 
47150diff
changeset | 370 | if exists_Const is_fun_equality t then | 
| 
04400144c6fc
handle TPTP definitions as definitions in Nitpick rather than as axioms
 blanchet parents: 
47150diff
changeset | 371 | let val thy = Proof_Context.theory_of ctxt in | 
| 47953 
a2c3706c4cb1
added "ext_cong_neq" lemma (not used yet); tuning
 blanchet parents: 
47718diff
changeset | 372 | t |> cterm_of thy |> Meson.abs_extensionalize_conv ctxt | 
| 47715 
04400144c6fc
handle TPTP definitions as definitions in Nitpick rather than as axioms
 blanchet parents: 
47150diff
changeset | 373 | |> prop_of |> Logic.dest_equals |> snd | 
| 
04400144c6fc
handle TPTP definitions as definitions in Nitpick rather than as axioms
 blanchet parents: 
47150diff
changeset | 374 | end | 
| 
04400144c6fc
handle TPTP definitions as definitions in Nitpick rather than as axioms
 blanchet parents: 
47150diff
changeset | 375 | else | 
| 
04400144c6fc
handle TPTP definitions as definitions in Nitpick rather than as axioms
 blanchet parents: 
47150diff
changeset | 376 | t | 
| 
04400144c6fc
handle TPTP definitions as definitions in Nitpick rather than as axioms
 blanchet parents: 
47150diff
changeset | 377 | |
| 47991 
3eb598b044ad
make Nitpick's handling of definitions more robust in the face of formulas that don't have the expected format (needed for soundness, cf. RNG100+1)
 blanchet parents: 
47954diff
changeset | 378 | fun unextensionalize_def t = | 
| 
3eb598b044ad
make Nitpick's handling of definitions more robust in the face of formulas that don't have the expected format (needed for soundness, cf. RNG100+1)
 blanchet parents: 
47954diff
changeset | 379 | case t of | 
| 
3eb598b044ad
make Nitpick's handling of definitions more robust in the face of formulas that don't have the expected format (needed for soundness, cf. RNG100+1)
 blanchet parents: 
47954diff
changeset | 380 |     @{const Trueprop} $ (Const (@{const_name HOL.eq}, _) $ lhs $ rhs) =>
 | 
| 
3eb598b044ad
make Nitpick's handling of definitions more robust in the face of formulas that don't have the expected format (needed for soundness, cf. RNG100+1)
 blanchet parents: 
47954diff
changeset | 381 | (case strip_comb lhs of | 
| 
3eb598b044ad
make Nitpick's handling of definitions more robust in the face of formulas that don't have the expected format (needed for soundness, cf. RNG100+1)
 blanchet parents: 
47954diff
changeset | 382 | (c as Const (_, T), args) => | 
| 
3eb598b044ad
make Nitpick's handling of definitions more robust in the face of formulas that don't have the expected format (needed for soundness, cf. RNG100+1)
 blanchet parents: 
47954diff
changeset | 383 | if forall is_Var args andalso not (has_duplicates (op =) args) then | 
| 
3eb598b044ad
make Nitpick's handling of definitions more robust in the face of formulas that don't have the expected format (needed for soundness, cf. RNG100+1)
 blanchet parents: 
47954diff
changeset | 384 |          @{const Trueprop}
 | 
| 
3eb598b044ad
make Nitpick's handling of definitions more robust in the face of formulas that don't have the expected format (needed for soundness, cf. RNG100+1)
 blanchet parents: 
47954diff
changeset | 385 |          $ (Const (@{const_name HOL.eq}, T --> T --> @{typ bool})
 | 
| 
3eb598b044ad
make Nitpick's handling of definitions more robust in the face of formulas that don't have the expected format (needed for soundness, cf. RNG100+1)
 blanchet parents: 
47954diff
changeset | 386 | $ c $ fold_rev lambda args rhs) | 
| 
3eb598b044ad
make Nitpick's handling of definitions more robust in the face of formulas that don't have the expected format (needed for soundness, cf. RNG100+1)
 blanchet parents: 
47954diff
changeset | 387 | else | 
| 
3eb598b044ad
make Nitpick's handling of definitions more robust in the face of formulas that don't have the expected format (needed for soundness, cf. RNG100+1)
 blanchet parents: 
47954diff
changeset | 388 | t | 
| 
3eb598b044ad
make Nitpick's handling of definitions more robust in the face of formulas that don't have the expected format (needed for soundness, cf. RNG100+1)
 blanchet parents: 
47954diff
changeset | 389 | | _ => t) | 
| 
3eb598b044ad
make Nitpick's handling of definitions more robust in the face of formulas that don't have the expected format (needed for soundness, cf. RNG100+1)
 blanchet parents: 
47954diff
changeset | 390 | | _ => t | 
| 
3eb598b044ad
make Nitpick's handling of definitions more robust in the face of formulas that don't have the expected format (needed for soundness, cf. RNG100+1)
 blanchet parents: 
47954diff
changeset | 391 | |
| 
3eb598b044ad
make Nitpick's handling of definitions more robust in the face of formulas that don't have the expected format (needed for soundness, cf. RNG100+1)
 blanchet parents: 
47954diff
changeset | 392 | fun is_legitimate_tptp_def (@{const Trueprop} $ t) = is_legitimate_tptp_def t
 | 
| 
3eb598b044ad
make Nitpick's handling of definitions more robust in the face of formulas that don't have the expected format (needed for soundness, cf. RNG100+1)
 blanchet parents: 
47954diff
changeset | 393 |   | is_legitimate_tptp_def (Const (@{const_name HOL.eq}, _) $ t $ u) =
 | 
| 
3eb598b044ad
make Nitpick's handling of definitions more robust in the face of formulas that don't have the expected format (needed for soundness, cf. RNG100+1)
 blanchet parents: 
47954diff
changeset | 394 | (is_Const t orelse is_Free t) andalso | 
| 
3eb598b044ad
make Nitpick's handling of definitions more robust in the face of formulas that don't have the expected format (needed for soundness, cf. RNG100+1)
 blanchet parents: 
47954diff
changeset | 395 | not (exists_subterm (curry (op =) t) u) | 
| 
3eb598b044ad
make Nitpick's handling of definitions more robust in the face of formulas that don't have the expected format (needed for soundness, cf. RNG100+1)
 blanchet parents: 
47954diff
changeset | 396 | | is_legitimate_tptp_def _ = false | 
| 
3eb598b044ad
make Nitpick's handling of definitions more robust in the face of formulas that don't have the expected format (needed for soundness, cf. RNG100+1)
 blanchet parents: 
47954diff
changeset | 397 | |
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 398 | (* Converts an elim-rule into an equivalent theorem that does not have the | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 399 | predicate variable. Leaves other theorems unchanged. We simply instantiate | 
| 44460 | 400 | the conclusion variable to "False". (Cf. "transform_elim_theorem" in | 
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 401 | "Meson_Clausify".) *) | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 402 | fun transform_elim_prop t = | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 403 | case Logic.strip_imp_concl t of | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 404 |     @{const Trueprop} $ Var (z, @{typ bool}) =>
 | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 405 |     subst_Vars [(z, @{const False})] t
 | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 406 |   | Var (z, @{typ prop}) => subst_Vars [(z, @{prop False})] t
 | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 407 | | _ => t | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 408 | |
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 409 | fun specialize_type thy (s, T) t = | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 410 | let | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 411 | fun subst_for (Const (s', T')) = | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 412 | if s = s' then | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 413 | SOME (Sign.typ_match thy (T', T) Vartab.empty) | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 414 | handle Type.TYPE_MATCH => NONE | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 415 | else | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 416 | NONE | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 417 | | subst_for (t1 $ t2) = | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 418 | (case subst_for t1 of SOME x => SOME x | NONE => subst_for t2) | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 419 | | subst_for (Abs (_, _, t')) = subst_for t' | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 420 | | subst_for _ = NONE | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 421 | in | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 422 | case subst_for t of | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 423 | SOME subst => monomorphic_term subst t | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 424 | | NONE => raise Type.TYPE_MATCH | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 425 | end | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 426 | |
| 52125 
ac7830871177
improved handling of free variables' types in Isar proofs
 blanchet parents: 
52077diff
changeset | 427 | fun strip_subgoal goal i ctxt = | 
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 428 | let | 
| 52196 
2281f33e8da6
redid rac7830871177 to avoid duplicate fixed variable (e.g. lemma "P (a::nat)" proof - have "!!a::int. Q a" sledgehammer [e])
 blanchet parents: 
52125diff
changeset | 429 | val (t, (frees, params)) = | 
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 430 | Logic.goal_params (prop_of goal) i | 
| 52196 
2281f33e8da6
redid rac7830871177 to avoid duplicate fixed variable (e.g. lemma "P (a::nat)" proof - have "!!a::int. Q a" sledgehammer [e])
 blanchet parents: 
52125diff
changeset | 431 | ||> (map dest_Free #> Variable.variant_frees ctxt [] #> `(map Free)) | 
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 432 | val hyp_ts = t |> Logic.strip_assums_hyp |> map (curry subst_bounds frees) | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 433 | val concl_t = t |> Logic.strip_assums_concl |> curry subst_bounds frees | 
| 52196 
2281f33e8da6
redid rac7830871177 to avoid duplicate fixed variable (e.g. lemma "P (a::nat)" proof - have "!!a::int. Q a" sledgehammer [e])
 blanchet parents: 
52125diff
changeset | 434 | in (rev params, hyp_ts, concl_t) end | 
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 435 | |
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: diff
changeset | 436 | end; |