src/HOL/TPTP/TPTP_Parser_Example.thy
author sultana
Tue Apr 17 16:14:07 2012 +0100 (2012-04-17)
changeset 47518 b2f209258621
parent 47366 f5a304ca037e
child 47548 60849d8c457d
permissions -rw-r--r--
more cleaning of tptp tests;
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
sultana@47366
     9
uses "~~/src/HOL/ex/sledgehammer_tactics.ML"
sultana@47366
    10
begin
sultana@47366
    11
sultana@47366
    12
import_tptp "$TPTP_PROBLEMS_PATH/ALG/ALG001^5.p" (*FIXME multiple imports*)
sultana@47366
    13
(*import_tptp "$TPTP_PROBLEMS_PATH/NUM/NUM021^1.p"*)
sultana@47366
    14
sultana@47366
    15
ML {*
sultana@47366
    16
val an_fmlas =
sultana@47366
    17
  TPTP_Interpret.get_manifests @{theory}
sultana@47366
    18
  |> hd (*FIXME use named lookup*)
sultana@47366
    19
  |> #2 (*get problem contents*)
sultana@47366
    20
  |> #3 (*get formulas*)
sultana@47366
    21
*}
sultana@47366
    22
sultana@47366
    23
(*Display nicely.*)
sultana@47366
    24
ML {*
sultana@47366
    25
List.app (fn (n, role, _, fmla, _) =>
sultana@47366
    26
  Pretty.writeln
sultana@47366
    27
    (Pretty.block [Pretty.str ("\"" ^ n ^ "\"" ^ "(" ^
sultana@47366
    28
      TPTP_Syntax.role_to_string role  ^ "): "), Syntax.pretty_term @{context} fmla])
sultana@47366
    29
  ) (rev an_fmlas)
sultana@47366
    30
*}
sultana@47366
    31
sultana@47366
    32
ML {*
sultana@47366
    33
(*Extract the (name, term) pairs of formulas having roles belonging to a
sultana@47366
    34
 user-supplied set*)
sultana@47366
    35
fun extract_terms roles : TPTP_Interpret.tptp_formula_meaning list ->
sultana@47366
    36
 (string * term) list =
sultana@47366
    37
   let
sultana@47366
    38
     fun role_predicate (_, role, _, _, _) =
sultana@47366
    39
       fold (fn r1 => fn b => role = r1 orelse b) roles false
sultana@47366
    40
   in filter role_predicate #> map (fn (n, _, _, t, _) => (n, t)) end
sultana@47366
    41
*}
sultana@47366
    42
sultana@47366
    43
ML {*
sultana@47366
    44
(*Use a given tactic on a goal*)
sultana@47366
    45
fun prove_conjectures tactic ctxt an_fmlas =
sultana@47366
    46
  let
sultana@47366
    47
    val assumptions =
sultana@47366
    48
      extract_terms
sultana@47366
    49
       [TPTP_Syntax.Role_Definition (*FIXME include axioms, etc here*)]
sultana@47366
    50
       an_fmlas
sultana@47366
    51
      |> map snd
sultana@47366
    52
    val goals = extract_terms [TPTP_Syntax.Role_Conjecture] an_fmlas
sultana@47366
    53
    fun driver (n, goal) =
sultana@47366
    54
      (n, Goal.prove ctxt [] assumptions goal (fn _ => tactic ctxt))
sultana@47366
    55
  in map driver goals end
sultana@47366
    56
sultana@47366
    57
val auto_prove = prove_conjectures auto_tac
sultana@47366
    58
val sh_prove = prove_conjectures (fn ctxt =>
sultana@47366
    59
  Sledgehammer_Tactics.sledgehammer_with_metis_tac ctxt []
sultana@47366
    60
  (*FIXME use relevance_override*)
sultana@47366
    61
  {add = [], del = [], only = false} 1)
sultana@47366
    62
*}
sultana@47366
    63
sultana@47366
    64
ML "auto_prove @{context} an_fmlas"
sultana@47366
    65
sultana@47366
    66
sledgehammer_params [provers = z3_tptp leo2, debug]
sultana@47366
    67
ML "sh_prove @{context} an_fmlas"
sultana@47366
    68
sultana@47366
    69
end