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