src/HOL/Tools/Sledgehammer/sledgehammer_util.ML
author blanchet
Tue, 24 Aug 2010 18:03:43 +0200
changeset 38698 d19c3a7ce38b
parent 38696 4c6b65d6a135
child 38738 0ce517c1970f
permissions -rw-r--r--
clean handling of whether a fact is chained or not; more elegant and reliable than encoding it in the name
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
38698
d19c3a7ce38b clean handling of whether a fact is chained or not;
blanchet
parents: 38696
diff changeset
     9
  val is_true_for : (string * bool) vector -> string -> bool
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
37962
d7dbe01f48d7 keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents: 37575
diff changeset
    12
  val strip_spaces : string -> string
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    13
  val parse_bool_option : bool -> string -> string -> bool option
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    14
  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
    15
  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
    16
  val nat_subscript : int -> string
36478
1aba777a367f fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents: 36402
diff changeset
    17
  val unyxml : string -> string
1aba777a367f fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents: 36402
diff changeset
    18
  val maybe_quote : string -> string
36555
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
    19
  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
    20
  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
    21
  val transform_elim_term : term -> term
36555
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
    22
  val specialize_type : theory -> (string * typ) -> term -> term
38044
463177795c49 minor refactoring
blanchet
parents: 38019
diff changeset
    23
  val subgoal_count : Proof.state -> int
37995
06f02b15ef8a generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents: 37962
diff changeset
    24
  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
    25
  val reserved_isar_keyword_table : unit -> unit Symtab.table
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    26
end;
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
    27
 
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    28
structure Sledgehammer_Util : SLEDGEHAMMER_UTIL =
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    29
struct
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    30
38698
d19c3a7ce38b clean handling of whether a fact is chained or not;
blanchet
parents: 38696
diff changeset
    31
fun is_true_for v s =
d19c3a7ce38b clean handling of whether a fact is chained or not;
blanchet
parents: 38696
diff changeset
    32
  Vector.foldl (fn ((s', b'), b) => if s' = s then b' else b) false v
d19c3a7ce38b clean handling of whether a fact is chained or not;
blanchet
parents: 38696
diff changeset
    33
36142
f5e15e9aae10 make Sledgehammer "minimize" output less confusing + round up (not down) time limits to nearest second
blanchet
parents: 36062
diff changeset
    34
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
    35
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    36
fun serial_commas _ [] = ["??"]
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    37
  | serial_commas _ [s] = [s]
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    38
  | serial_commas conj [s1, s2] = [s1, conj, s2]
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    39
  | serial_commas conj [s1, s2, s3] = [s1 ^ ",", s2 ^ ",", conj, s3]
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    40
  | serial_commas conj (s :: ss) = s ^ "," :: serial_commas conj ss
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    41
37962
d7dbe01f48d7 keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents: 37575
diff changeset
    42
fun is_ident_char c = Char.isAlphaNum c orelse c = #"_"
d7dbe01f48d7 keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents: 37575
diff changeset
    43
d7dbe01f48d7 keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents: 37575
diff changeset
    44
fun strip_spaces_in_list [] = ""
d7dbe01f48d7 keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents: 37575
diff changeset
    45
  | strip_spaces_in_list [c1] = if Char.isSpace c1 then "" else str c1
d7dbe01f48d7 keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents: 37575
diff changeset
    46
  | strip_spaces_in_list [c1, c2] =
d7dbe01f48d7 keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents: 37575
diff changeset
    47
    strip_spaces_in_list [c1] ^ strip_spaces_in_list [c2]
d7dbe01f48d7 keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents: 37575
diff changeset
    48
  | strip_spaces_in_list (c1 :: c2 :: c3 :: cs) =
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
d7dbe01f48d7 keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents: 37575
diff changeset
    50
      strip_spaces_in_list (c2 :: c3 :: cs)
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
d7dbe01f48d7 keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents: 37575
diff changeset
    53
        strip_spaces_in_list (c1 :: c3 :: cs)
d7dbe01f48d7 keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents: 37575
diff changeset
    54
      else
d7dbe01f48d7 keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents: 37575
diff changeset
    55
        str c1 ^ (if forall is_ident_char [c1, c3] then " " else "") ^
d7dbe01f48d7 keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents: 37575
diff changeset
    56
        strip_spaces_in_list (c3 :: cs)
d7dbe01f48d7 keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents: 37575
diff changeset
    57
    else
d7dbe01f48d7 keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents: 37575
diff changeset
    58
      str c1 ^ strip_spaces_in_list (c2 :: c3 :: cs)
d7dbe01f48d7 keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents: 37575
diff changeset
    59
val strip_spaces = strip_spaces_in_list o String.explode
d7dbe01f48d7 keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents: 37575
diff changeset
    60
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    61
fun parse_bool_option option name s =
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    62
  (case s of
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    63
     "smart" => if option then NONE else raise Option
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    64
   | "false" => SOME false
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    65
   | "true" => SOME true
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    66
   | "" => SOME true
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    67
   | _ => raise Option)
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    68
  handle Option.Option =>
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    69
         let val ss = map quote ((option ? cons "smart") ["true", "false"]) in
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    70
           error ("Parameter " ^ quote name ^ " must be assigned " ^
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    71
                  space_implode " " (serial_commas "or" ss) ^ ".")
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    72
         end
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    73
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    74
fun parse_time_option _ "none" = NONE
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    75
  | parse_time_option name s =
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    76
    let
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    77
      val msecs =
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    78
        case space_explode " " s of
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    79
          [s1, "min"] => 60000 * the (Int.fromString s1)
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    80
        | [s1, "s"] => 1000 * the (Int.fromString s1)
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    81
        | [s1, "ms"] => the (Int.fromString s1)
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    82
        | _ => 0
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    83
    in
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    84
      if msecs <= 0 then
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    85
        error ("Parameter " ^ quote name ^ " must be assigned a positive time \
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    86
               \value (e.g., \"60 s\", \"200 ms\") or \"none\".")
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    87
      else
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    88
        SOME (Time.fromMilliseconds msecs)
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    89
    end
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
    90
37962
d7dbe01f48d7 keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents: 37575
diff changeset
    91
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
    92
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
    93
36486
c2d7e2dff59e support Vampire definitions of constants as "let" constructs in Isar proofs
blanchet
parents: 36478
diff changeset
    94
val subscript = implode o map (prefix "\<^isub>") o explode
37321
9d7cfae95b30 honor "xsymbols"
blanchet
parents: 36960
diff changeset
    95
fun nat_subscript n =
9d7cfae95b30 honor "xsymbols"
blanchet
parents: 36960
diff changeset
    96
  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
    97
36478
1aba777a367f fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents: 36402
diff changeset
    98
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
    99
  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
   100
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
   101
1aba777a367f fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents: 36402
diff changeset
   102
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
   103
fun maybe_quote y =
1aba777a367f fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents: 36402
diff changeset
   104
  let val s = unyxml y in
1aba777a367f fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents: 36402
diff changeset
   105
    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
   106
           not (is_long_identifier (perhaps (try (unprefix "?")) s))) orelse
36960
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36555
diff changeset
   107
           Keyword.is_keyword s) ? quote
36478
1aba777a367f fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents: 36402
diff changeset
   108
  end
1aba777a367f fix types of "fix" variables to help proof reconstruction and aid readability
blanchet
parents: 36402
diff changeset
   109
36555
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   110
fun monomorphic_term subst t =
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   111
  map_types (map_type_tvar (fn v =>
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   112
      case Type.lookup subst v of
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   113
        SOME typ => typ
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   114
      | NONE => raise TERM ("monomorphic_term: uninstanitated schematic type \
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   115
                            \variable", [t]))) t
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   116
38652
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38608
diff changeset
   117
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
   118
  | 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
   119
    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
   120
  | 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
   121
    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
   122
             (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
   123
             (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
   124
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38608
diff changeset
   125
(* 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
   126
   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
   127
   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
   128
   "Clausifier".) *)
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38608
diff changeset
   129
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
   130
  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
   131
    @{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
   132
    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
   133
  | 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
   134
  | _ => t
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38608
diff changeset
   135
36555
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   136
fun specialize_type thy (s, T) t =
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   137
  let
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   138
    fun subst_for (Const (s', T')) =
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   139
      if s = s' then
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   140
        SOME (Sign.typ_match thy (T', T) Vartab.empty)
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   141
        handle Type.TYPE_MATCH => NONE
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   142
      else
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   143
        NONE
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   144
    | subst_for (t1 $ t2) =
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   145
      (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
   146
    | subst_for (Abs (_, _, t')) = subst_for t'
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   147
    | subst_for _ = NONE
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   148
  in
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   149
    case subst_for t of
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   150
      SOME subst => monomorphic_term subst t
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   151
    | NONE => raise Type.TYPE_MATCH
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   152
  end
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36496
diff changeset
   153
38044
463177795c49 minor refactoring
blanchet
parents: 38019
diff changeset
   154
val subgoal_count = Logic.count_prems o prop_of o #goal o Proof.goal
463177795c49 minor refactoring
blanchet
parents: 38019
diff changeset
   155
37995
06f02b15ef8a generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents: 37962
diff changeset
   156
fun strip_subgoal goal i =
06f02b15ef8a generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents: 37962
diff changeset
   157
  let
06f02b15ef8a generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents: 37962
diff changeset
   158
    val (t, frees) = Logic.goal_params (prop_of goal) i
06f02b15ef8a generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents: 37962
diff changeset
   159
    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
   160
    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
   161
  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
   162
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
   163
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
   164
  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
   165
  |> 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
   166
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents:
diff changeset
   167
end;