src/HOL/Tools/Sledgehammer/sledgehammer_isar.ML
author blanchet
Mon, 22 Mar 2010 15:23:18 +0100
changeset 35962 0e2d57686b3c
parent 35866 513074557e06
child 35963 943e2582dc87
permissions -rw-r--r--
make "sledgehammer" and "atp_minimize" improper commands
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35866
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
     1
(*  Title:      HOL/Sledgehammer/sledgehammer_isar.ML
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
     2
    Author:     Jasmin Blanchette, TU Muenchen
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
     3
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
     4
Adds "sledgehammer" and related commands to Isabelle/Isar's outer syntax.
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
     5
*)
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
     6
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
     7
structure Sledgehammer_Isar : sig end =
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
     8
struct
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
     9
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    10
open ATP_Manager
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    11
open ATP_Minimal
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    12
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    13
structure K = OuterKeyword and P = OuterParse
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    14
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    15
val _ =
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    16
  OuterSyntax.improper_command "atp_kill" "kill all managed provers" K.diag
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    17
    (Scan.succeed (Toplevel.no_timing o Toplevel.imperative kill));
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    18
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    19
val _ =
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    20
  OuterSyntax.improper_command "atp_info" "print information about managed provers" K.diag
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    21
    (Scan.succeed (Toplevel.no_timing o Toplevel.imperative info));
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    22
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    23
val _ =
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    24
  OuterSyntax.improper_command "atp_messages" "print recent messages issued by managed provers" K.diag
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    25
    (Scan.option (P.$$$ "(" |-- P.nat --| P.$$$ ")") >>
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    26
      (fn limit => Toplevel.no_timing o Toplevel.imperative (fn () => messages limit)));
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    27
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    28
val _ =
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    29
  OuterSyntax.improper_command "print_atps" "print external provers" K.diag
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    30
    (Scan.succeed (Toplevel.no_timing o Toplevel.unknown_theory o
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    31
      Toplevel.keep (print_provers o Toplevel.theory_of)));
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    32
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    33
val _ =
35962
0e2d57686b3c make "sledgehammer" and "atp_minimize" improper commands
blanchet
parents: 35866
diff changeset
    34
  OuterSyntax.improper_command "sledgehammer"
35866
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    35
    "search for first-order proof using automatic theorem provers" K.diag
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    36
    (Scan.repeat P.xname >> (fn names => Toplevel.no_timing o Toplevel.unknown_proof o
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    37
      Toplevel.keep (sledgehammer names o Toplevel.proof_of)));
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    38
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    39
val default_minimize_prover = "remote_vampire"
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    40
val default_minimize_time_limit = 5
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    41
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    42
fun atp_minimize_command args thm_names state =
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    43
  let
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    44
    fun theorems_from_names ctxt =
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    45
      map (fn (name, interval) =>
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    46
              let
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    47
                val thmref = Facts.Named ((name, Position.none), interval)
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    48
                val ths = ProofContext.get_fact ctxt thmref
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    49
                val name' = Facts.string_of_ref thmref
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    50
              in (name', ths) end)
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    51
    fun get_time_limit_arg time_string =
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    52
      (case Int.fromString time_string of
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    53
        SOME t => t
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    54
      | NONE => error ("Invalid time limit: " ^ quote time_string))
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    55
    fun get_opt (name, a) (p, t) =
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    56
      (case name of
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    57
        "time" => (p, get_time_limit_arg a)
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    58
      | "atp" => (a, t)
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    59
      | n => error ("Invalid argument: " ^ n))
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    60
    fun get_options args =
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    61
      fold get_opt args (default_minimize_prover, default_minimize_time_limit)
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    62
    val (prover_name, time_limit) = get_options args
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    63
    val prover =
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    64
      (case ATP_Manager.get_prover (Proof.theory_of state) prover_name of
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    65
        SOME prover => prover
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    66
      | NONE => error ("Unknown prover: " ^ quote prover_name))
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    67
    val name_thms_pairs = theorems_from_names (Proof.context_of state) thm_names
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    68
  in
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    69
    writeln (#2 (minimize_theorems linear_minimize prover prover_name time_limit
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    70
                                   state name_thms_pairs))
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    71
  end
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    72
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    73
local structure K = OuterKeyword and P = OuterParse in
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    74
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    75
val parse_args =
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    76
  Scan.optional (Args.bracks (P.list (P.xname --| P.$$$ "=" -- P.xname))) []
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    77
val parse_thm_names = Scan.repeat (P.xname -- Scan.option Attrib.thm_sel)
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    78
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    79
val _ =
35962
0e2d57686b3c make "sledgehammer" and "atp_minimize" improper commands
blanchet
parents: 35866
diff changeset
    80
  OuterSyntax.improper_command "atp_minimize" "minimize theorem list with external prover" K.diag
35866
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    81
    (parse_args -- parse_thm_names >> (fn (args, thm_names) =>
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    82
      Toplevel.no_timing o Toplevel.unknown_proof o
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    83
        Toplevel.keep (atp_minimize_command args thm_names o Toplevel.proof_of)))
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    84
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    85
end
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    86
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    87
end;