src/HOL/TPTP/TPTP_Parser_Example.thy
author blanchet
Fri Apr 27 15:24:37 2012 +0200 (2012-04-27)
changeset 47790 2e1636e45770
parent 47687 bfbd2d0bb348
child 48891 c0eafbd55de3
permissions -rw-r--r--
move file to where it belongs
sultana@47366
     1
(*  Title:      HOL/TPTP/TPTP_Parser_Example.thy
sultana@47366
     2
    Author:     Nik Sultana, Cambridge University Computer Laboratory
sultana@47366
     3
sultana@47366
     4
Example of importing a TPTP problem and trying to prove it in Isabelle/HOL.
sultana@47366
     5
*)
sultana@47366
     6
sultana@47366
     7
theory TPTP_Parser_Example
sultana@47518
     8
imports TPTP_Parser TPTP_Interpret
blanchet@47790
     9
uses "sledgehammer_tactics.ML"
sultana@47366
    10
begin
sultana@47366
    11
sultana@47687
    12
import_tptp "$TPTP/Problems/CSR/CSR077+1.p"
sultana@47366
    13
sultana@47366
    14
ML {*
sultana@47366
    15
val an_fmlas =
sultana@47366
    16
  TPTP_Interpret.get_manifests @{theory}
sultana@47366
    17
  |> hd (*FIXME use named lookup*)
sultana@47366
    18
  |> #2 (*get problem contents*)
sultana@47366
    19
  |> #3 (*get formulas*)
sultana@47366
    20
*}
sultana@47366
    21
sultana@47366
    22
(*Display nicely.*)
sultana@47366
    23
ML {*
sultana@47548
    24
List.app (fn (n, role, fmla, _) =>
sultana@47366
    25
  Pretty.writeln
sultana@47366
    26
    (Pretty.block [Pretty.str ("\"" ^ n ^ "\"" ^ "(" ^
sultana@47366
    27
      TPTP_Syntax.role_to_string role  ^ "): "), Syntax.pretty_term @{context} fmla])
sultana@47366
    28
  ) (rev an_fmlas)
sultana@47366
    29
*}
sultana@47366
    30
sultana@47366
    31
ML {*
sultana@47366
    32
(*Extract the (name, term) pairs of formulas having roles belonging to a
sultana@47366
    33
 user-supplied set*)
sultana@47366
    34
fun extract_terms roles : TPTP_Interpret.tptp_formula_meaning list ->
sultana@47366
    35
 (string * term) list =
sultana@47366
    36
   let
sultana@47548
    37
     fun role_predicate (_, role, _, _) =
sultana@47366
    38
       fold (fn r1 => fn b => role = r1 orelse b) roles false
sultana@47548
    39
   in filter role_predicate #> map (fn (n, _, t, _) => (n, t)) end
sultana@47366
    40
*}
sultana@47366
    41
sultana@47366
    42
ML {*
sultana@47366
    43
(*Use a given tactic on a goal*)
sultana@47366
    44
fun prove_conjectures tactic ctxt an_fmlas =
sultana@47366
    45
  let
sultana@47366
    46
    val assumptions =
sultana@47366
    47
      extract_terms
sultana@47366
    48
       [TPTP_Syntax.Role_Definition (*FIXME include axioms, etc here*)]
sultana@47366
    49
       an_fmlas
sultana@47366
    50
      |> map snd
sultana@47366
    51
    val goals = extract_terms [TPTP_Syntax.Role_Conjecture] an_fmlas
sultana@47366
    52
    fun driver (n, goal) =
sultana@47366
    53
      (n, Goal.prove ctxt [] assumptions goal (fn _ => tactic ctxt))
sultana@47366
    54
  in map driver goals end
sultana@47366
    55
sultana@47366
    56
val auto_prove = prove_conjectures auto_tac
sultana@47366
    57
val sh_prove = prove_conjectures (fn ctxt =>
sultana@47366
    58
  Sledgehammer_Tactics.sledgehammer_with_metis_tac ctxt []
sultana@47366
    59
  (*FIXME use relevance_override*)
sultana@47366
    60
  {add = [], del = [], only = false} 1)
sultana@47366
    61
*}
sultana@47366
    62
sultana@47366
    63
ML "auto_prove @{context} an_fmlas"
sultana@47366
    64
sultana@47366
    65
sledgehammer_params [provers = z3_tptp leo2, debug]
sultana@47366
    66
ML "sh_prove @{context} an_fmlas"
sultana@47366
    67
sultana@47366
    68
end