src/HOL/Tools/Sledgehammer/sledgehammer_util.ML
author wenzelm
Fri, 17 Sep 2010 15:51:11 +0200
changeset 39439 1c294d150ded
parent 39357 fe84bc307be6
child 39457 b505208f435d
permissions -rw-r--r--
eliminated markup "location" in favour of more explicit "no_report", which is actually deleted from messages;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36062
194cb6e3c13f get rid of Polyhash, since it's no longer used
blanchet
parents: 35963
diff changeset
     1
(*  Title:      HOL/Tools/Sledgehammer/sledgehammer_util.ML
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
     2
    Author:     Jasmin Blanchette, TU Muenchen
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
     3
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
     4
General-purpose functions used by the Sledgehammer modules.
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
     5
*)
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
     6
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
     7
signature SLEDGEHAMMER_UTIL =
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
     8
sig
38818
61cf050f8b2e improve SPASS hack, when a clause comes from several facts
blanchet
parents: 38752
diff changeset
     9
  val find_first_in_list_vector : (''a * 'b) list vector -> ''a -> 'b option
36142
f5e15e9aae10 make Sledgehammer "minimize" output less confusing + round up (not down) time limits to nearest second
blanchet
parents: 36062
diff changeset
    10
  val plural_s : int -> string
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    11
  val serial_commas : string -> string list -> string list
38738
0ce517c1970f make sure that "undo_ascii_of" is the inverse of "ascii_of", also for non-printable characters -- and avoid those in ``-style facts
blanchet
parents: 38698
diff changeset
    12
  val simplify_spaces : string -> string
0ce517c1970f make sure that "undo_ascii_of" is the inverse of "ascii_of", also for non-printable characters -- and avoid those in ``-style facts
blanchet
parents: 38698
diff changeset
    13
  val strip_spaces_except_between_ident_chars : string -> string
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    14
  val parse_bool_option : bool -> string -> string -> bool option
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    15
  val parse_time_option : string -> string -> Time.time option
37962
d7dbe01f48d7 keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents: 37575
diff changeset
    16
  val scan_integer : string list -> int * string list
36486
c2d7e2dff59e support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents: 36478
diff changeset
    17
  val nat_subscript : int -> string
36478
1aba777a367f fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents: 36402
diff changeset
    18
  val unyxml : string -> string
1aba777a367f fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents: 36402
diff changeset
    19
  val maybe_quote : string -> string
36555
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
    20
  val monomorphic_term : Type.tyenv -> term -> term
38652
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38608
diff changeset
    21
  val eta_expand : typ list -> term -> int -> term
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38608
diff changeset
    22
  val transform_elim_term : term -> term
36555
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
    23
  val specialize_type : theory -> (string * typ) -> term -> term
38044
463177795c49 minor refactoring
blanchet
parents: 38019
diff changeset
    24
  val subgoal_count : Proof.state -> int
37995
06f02b15ef8a generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents: 37962
diff changeset
    25
  val strip_subgoal : thm -> int -> (string * typ) list * term list * term
38696
4c6b65d6a135 quote facts whose names collide with a keyword or command name (cf. "subclass" in "Jinja/J/TypeSafe.thy")
blanchet
parents: 38652
diff changeset
    26
  val reserved_isar_keyword_table : unit -> unit Symtab.table
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    27
end;
39318
ad9a1f9b0558 implemented Auto Sledgehammer
blanchet
parents: 38818
diff changeset
    28
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    29
structure Sledgehammer_Util : SLEDGEHAMMER_UTIL =
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    30
struct
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    31
38818
61cf050f8b2e improve SPASS hack, when a clause comes from several facts
blanchet
parents: 38752
diff changeset
    32
fun find_first_in_list_vector vec key =
61cf050f8b2e improve SPASS hack, when a clause comes from several facts
blanchet
parents: 38752
diff changeset
    33
  Vector.foldl (fn (ps, NONE) => AList.lookup (op =) ps key
61cf050f8b2e improve SPASS hack, when a clause comes from several facts
blanchet
parents: 38752
diff changeset
    34
                 | (_, value) => value) NONE vec
38698
d19c3a7ce38b clean handling of whether a fact is chained or not;
blanchet
parents: 38696
diff changeset
    35
36142
f5e15e9aae10 make Sledgehammer "minimize" output less confusing + round up (not down) time limits to nearest second
blanchet
parents: 36062
diff changeset
    36
fun plural_s n = if n = 1 then "" else "s"
36062
194cb6e3c13f get rid of Polyhash, since it's no longer used
blanchet
parents: 35963
diff changeset
    37
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    38
fun serial_commas _ [] = ["??"]
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    39
  | serial_commas _ [s] = [s]
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    40
  | serial_commas conj [s1, s2] = [s1, conj, s2]
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    41
  | serial_commas conj [s1, s2, s3] = [s1 ^ ",", s2 ^ ",", conj, s3]
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    42
  | serial_commas conj (s :: ss) = s ^ "," :: serial_commas conj ss
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    43
39357
fe84bc307be6 speed up helper function
blanchet
parents: 39318
diff changeset
    44
fun strip_spaces_in_list _ [] = []
fe84bc307be6 speed up helper function
blanchet
parents: 39318
diff changeset
    45
  | strip_spaces_in_list _ [c1] = if Char.isSpace c1 then [] else [str c1]
38738
0ce517c1970f make sure that "undo_ascii_of" is the inverse of "ascii_of", also for non-printable characters -- and avoid those in ``-style facts
blanchet
parents: 38698
diff changeset
    46
  | strip_spaces_in_list is_evil [c1, c2] =
39357
fe84bc307be6 speed up helper function
blanchet
parents: 39318
diff changeset
    47
    strip_spaces_in_list is_evil [c1] @ strip_spaces_in_list is_evil [c2]
38738
0ce517c1970f make sure that "undo_ascii_of" is the inverse of "ascii_of", also for non-printable characters -- and avoid those in ``-style facts
blanchet
parents: 38698
diff changeset
    48
  | strip_spaces_in_list is_evil (c1 :: c2 :: c3 :: cs) =
37962
d7dbe01f48d7 keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents: 37575
diff changeset
    49
    if Char.isSpace c1 then
38738
0ce517c1970f make sure that "undo_ascii_of" is the inverse of "ascii_of", also for non-printable characters -- and avoid those in ``-style facts
blanchet
parents: 38698
diff changeset
    50
      strip_spaces_in_list is_evil (c2 :: c3 :: cs)
37962
d7dbe01f48d7 keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents: 37575
diff changeset
    51
    else if Char.isSpace c2 then
d7dbe01f48d7 keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents: 37575
diff changeset
    52
      if Char.isSpace c3 then
38738
0ce517c1970f make sure that "undo_ascii_of" is the inverse of "ascii_of", also for non-printable characters -- and avoid those in ``-style facts
blanchet
parents: 38698
diff changeset
    53
        strip_spaces_in_list is_evil (c1 :: c3 :: cs)
37962
d7dbe01f48d7 keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents: 37575
diff changeset
    54
      else
39357
fe84bc307be6 speed up helper function
blanchet
parents: 39318
diff changeset
    55
        str c1 :: (if forall is_evil [c1, c3] then [" "] else []) @
38738
0ce517c1970f make sure that "undo_ascii_of" is the inverse of "ascii_of", also for non-printable characters -- and avoid those in ``-style facts
blanchet
parents: 38698
diff changeset
    56
        strip_spaces_in_list is_evil (c3 :: cs)
37962
d7dbe01f48d7 keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents: 37575
diff changeset
    57
    else
39357
fe84bc307be6 speed up helper function
blanchet
parents: 39318
diff changeset
    58
      str c1 :: strip_spaces_in_list is_evil (c2 :: c3 :: cs)
fe84bc307be6 speed up helper function
blanchet
parents: 39318
diff changeset
    59
fun strip_spaces is_evil =
fe84bc307be6 speed up helper function
blanchet
parents: 39318
diff changeset
    60
  implode o strip_spaces_in_list is_evil o String.explode
38738
0ce517c1970f make sure that "undo_ascii_of" is the inverse of "ascii_of", also for non-printable characters -- and avoid those in ``-style facts
blanchet
parents: 38698
diff changeset
    61
0ce517c1970f make sure that "undo_ascii_of" is the inverse of "ascii_of", also for non-printable characters -- and avoid those in ``-style facts
blanchet
parents: 38698
diff changeset
    62
val simplify_spaces = strip_spaces (K true)
0ce517c1970f make sure that "undo_ascii_of" is the inverse of "ascii_of", also for non-printable characters -- and avoid those in ``-style facts
blanchet
parents: 38698
diff changeset
    63
0ce517c1970f make sure that "undo_ascii_of" is the inverse of "ascii_of", also for non-printable characters -- and avoid those in ``-style facts
blanchet
parents: 38698
diff changeset
    64
fun is_ident_char c = Char.isAlphaNum c orelse c = #"_"
0ce517c1970f make sure that "undo_ascii_of" is the inverse of "ascii_of", also for non-printable characters -- and avoid those in ``-style facts
blanchet
parents: 38698
diff changeset
    65
val strip_spaces_except_between_ident_chars = strip_spaces is_ident_char
37962
d7dbe01f48d7 keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents: 37575
diff changeset
    66
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    67
fun parse_bool_option option name s =
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    68
  (case s of
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    69
     "smart" => if option then NONE else raise Option
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    70
   | "false" => SOME false
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    71
   | "true" => SOME true
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    72
   | "" => SOME true
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    73
   | _ => raise Option)
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    74
  handle Option.Option =>
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    75
         let val ss = map quote ((option ? cons "smart") ["true", "false"]) in
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    76
           error ("Parameter " ^ quote name ^ " must be assigned " ^
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    77
                  space_implode " " (serial_commas "or" ss) ^ ".")
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    78
         end
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    79
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    80
fun parse_time_option _ "none" = NONE
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    81
  | parse_time_option name s =
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    82
    let
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    83
      val msecs =
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    84
        case space_explode " " s of
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    85
          [s1, "min"] => 60000 * the (Int.fromString s1)
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    86
        | [s1, "s"] => 1000 * the (Int.fromString s1)
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    87
        | [s1, "ms"] => the (Int.fromString s1)
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    88
        | _ => 0
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    89
    in
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    90
      if msecs <= 0 then
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    91
        error ("Parameter " ^ quote name ^ " must be assigned a positive time \
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    92
               \value (e.g., \"60 s\", \"200 ms\") or \"none\".")
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    93
      else
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    94
        SOME (Time.fromMilliseconds msecs)
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    95
    end
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    96
37962
d7dbe01f48d7 keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents: 37575
diff changeset
    97
fun is_head_digit s = Char.isDigit (String.sub (s, 0))
d7dbe01f48d7 keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents: 37575
diff changeset
    98
val scan_integer = Scan.many1 is_head_digit >> (the o Int.fromString o implode)
d7dbe01f48d7 keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents: 37575
diff changeset
    99
36486
c2d7e2dff59e support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents: 36478
diff changeset
   100
val subscript = implode o map (prefix "\<^isub>") o explode
37321
9d7cfae95b30 honor "xsymbols"
blanchet
parents: 36960
diff changeset
   101
fun nat_subscript n =
9d7cfae95b30 honor "xsymbols"
blanchet
parents: 36960
diff changeset
   102
  n |> string_of_int |> print_mode_active Symbol.xsymbolsN ? subscript
36486
c2d7e2dff59e support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents: 36478
diff changeset
   103
36478
1aba777a367f fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents: 36402
diff changeset
   104
fun plain_string_from_xml_tree t =
1aba777a367f fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents: 36402
diff changeset
   105
  Buffer.empty |> XML.add_content t |> Buffer.content
1aba777a367f fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents: 36402
diff changeset
   106
val unyxml = plain_string_from_xml_tree o YXML.parse
1aba777a367f fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents: 36402
diff changeset
   107
1aba777a367f fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents: 36402
diff changeset
   108
val is_long_identifier = forall Syntax.is_identifier o space_explode "."
1aba777a367f fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents: 36402
diff changeset
   109
fun maybe_quote y =
1aba777a367f fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents: 36402
diff changeset
   110
  let val s = unyxml y in
1aba777a367f fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents: 36402
diff changeset
   111
    y |> ((not (is_long_identifier (perhaps (try (unprefix "'")) s)) andalso
1aba777a367f fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents: 36402
diff changeset
   112
           not (is_long_identifier (perhaps (try (unprefix "?")) s))) orelse
36960
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36555
diff changeset
   113
           Keyword.is_keyword s) ? quote
36478
1aba777a367f fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents: 36402
diff changeset
   114
  end
1aba777a367f fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents: 36402
diff changeset
   115
36555
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   116
fun monomorphic_term subst t =
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   117
  map_types (map_type_tvar (fn v =>
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   118
      case Type.lookup subst v of
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   119
        SOME typ => typ
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   120
      | NONE => raise TERM ("monomorphic_term: uninstanitated schematic type \
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   121
                            \variable", [t]))) t
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   122
38652
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38608
diff changeset
   123
fun eta_expand _ t 0 = t
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38608
diff changeset
   124
  | eta_expand Ts (Abs (s, T, t')) n =
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38608
diff changeset
   125
    Abs (s, T, eta_expand (T :: Ts) t' (n - 1))
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38608
diff changeset
   126
  | eta_expand Ts t n =
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38608
diff changeset
   127
    fold_rev (fn T => fn t' => Abs ("x" ^ nat_subscript n, T, t'))
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38608
diff changeset
   128
             (List.take (binder_types (fastype_of1 (Ts, t)), n))
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38608
diff changeset
   129
             (list_comb (incr_boundvars n t, map Bound (n - 1 downto 0)))
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38608
diff changeset
   130
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38608
diff changeset
   131
(* Converts an elim-rule into an equivalent theorem that does not have the
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38608
diff changeset
   132
   predicate variable. Leaves other theorems unchanged. We simply instantiate
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38608
diff changeset
   133
   the conclusion variable to False. (Cf. "transform_elim_theorem" in
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38608
diff changeset
   134
   "Clausifier".) *)
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38608
diff changeset
   135
fun transform_elim_term t =
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38608
diff changeset
   136
  case Logic.strip_imp_concl t of
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38608
diff changeset
   137
    @{const Trueprop} $ Var (z, @{typ bool}) =>
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38608
diff changeset
   138
    subst_Vars [(z, @{const False})] t
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38608
diff changeset
   139
  | Var (z, @{typ prop}) => subst_Vars [(z, @{prop False})] t
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38608
diff changeset
   140
  | _ => t
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38608
diff changeset
   141
36555
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   142
fun specialize_type thy (s, T) t =
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   143
  let
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   144
    fun subst_for (Const (s', T')) =
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   145
      if s = s' then
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   146
        SOME (Sign.typ_match thy (T', T) Vartab.empty)
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   147
        handle Type.TYPE_MATCH => NONE
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   148
      else
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   149
        NONE
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   150
    | subst_for (t1 $ t2) =
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   151
      (case subst_for t1 of SOME x => SOME x | NONE => subst_for t2)
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   152
    | subst_for (Abs (_, _, t')) = subst_for t'
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   153
    | subst_for _ = NONE
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   154
  in
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   155
    case subst_for t of
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   156
      SOME subst => monomorphic_term subst t
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   157
    | NONE => raise Type.TYPE_MATCH
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   158
  end
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   159
38044
463177795c49 minor refactoring
blanchet
parents: 38019
diff changeset
   160
val subgoal_count = Logic.count_prems o prop_of o #goal o Proof.goal
463177795c49 minor refactoring
blanchet
parents: 38019
diff changeset
   161
37995
06f02b15ef8a generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents: 37962
diff changeset
   162
fun strip_subgoal goal i =
06f02b15ef8a generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents: 37962
diff changeset
   163
  let
06f02b15ef8a generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents: 37962
diff changeset
   164
    val (t, frees) = Logic.goal_params (prop_of goal) i
06f02b15ef8a generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents: 37962
diff changeset
   165
    val hyp_ts = t |> Logic.strip_assums_hyp |> map (curry subst_bounds frees)
06f02b15ef8a generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents: 37962
diff changeset
   166
    val concl_t = t |> Logic.strip_assums_concl |> curry subst_bounds frees
06f02b15ef8a generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents: 37962
diff changeset
   167
  in (rev (map dest_Free frees), hyp_ts, concl_t) end
36555
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   168
38696
4c6b65d6a135 quote facts whose names collide with a keyword or command name (cf. "subclass" in "Jinja/J/TypeSafe.thy")
blanchet
parents: 38652
diff changeset
   169
fun reserved_isar_keyword_table () =
4c6b65d6a135 quote facts whose names collide with a keyword or command name (cf. "subclass" in "Jinja/J/TypeSafe.thy")
blanchet
parents: 38652
diff changeset
   170
  union (op =) (Keyword.dest_keywords ()) (Keyword.dest_commands ())
4c6b65d6a135 quote facts whose names collide with a keyword or command name (cf. "subclass" in "Jinja/J/TypeSafe.thy")
blanchet
parents: 38652
diff changeset
   171
  |> map (rpair ()) |> Symtab.make
4c6b65d6a135 quote facts whose names collide with a keyword or command name (cf. "subclass" in "Jinja/J/TypeSafe.thy")
blanchet
parents: 38652
diff changeset
   172
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
   173
end;