src/HOL/TPTP/atp_theory_export.ML
author blanchet
Tue, 17 Dec 2013 14:03:29 +0100
changeset 54788 a898e15b522a
parent 54197 994ebb795b75
child 57268 027feff882c4
permissions -rw-r--r--
primitive support for SPASS-Pirate (Daniel Wand's polymorphic SPASS prototype)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46321
484dc68c8c89 renamed theory exporter
blanchet
parents: 46320
diff changeset
     1
(*  Title:      HOL/TPTP/atp_theory_export.ML
42602
a2db47fa015e added TPTP exporter facility -- useful to do experiments with machine learning
blanchet
parents:
diff changeset
     2
    Author:     Jasmin Blanchette, TU Muenchen
a2db47fa015e added TPTP exporter facility -- useful to do experiments with machine learning
blanchet
parents:
diff changeset
     3
    Copyright   2011
a2db47fa015e added TPTP exporter facility -- useful to do experiments with machine learning
blanchet
parents:
diff changeset
     4
48234
06216c789ac9 moved MaSh into own files
blanchet
parents: 48233
diff changeset
     5
Export Isabelle theories as first-order TPTP inferences.
42602
a2db47fa015e added TPTP exporter facility -- useful to do experiments with machine learning
blanchet
parents:
diff changeset
     6
*)
a2db47fa015e added TPTP exporter facility -- useful to do experiments with machine learning
blanchet
parents:
diff changeset
     7
46321
484dc68c8c89 renamed theory exporter
blanchet
parents: 46320
diff changeset
     8
signature ATP_THEORY_EXPORT =
42602
a2db47fa015e added TPTP exporter facility -- useful to do experiments with machine learning
blanchet
parents:
diff changeset
     9
sig
45305
3e09961326ce also export DFG formats
blanchet
parents: 45301
diff changeset
    10
  type atp_format = ATP_Problem.atp_format
3e09961326ce also export DFG formats
blanchet
parents: 45301
diff changeset
    11
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    12
  datatype inference_policy =
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    13
    No_Inferences | Unchecked_Inferences | Checked_Inferences
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    14
48234
06216c789ac9 moved MaSh into own files
blanchet
parents: 48233
diff changeset
    15
  val generate_atp_inference_file_for_theory :
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    16
    Proof.context -> theory -> atp_format -> inference_policy -> string
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    17
    -> string -> unit
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    18
  val generate_casc_lbt_isa_files_for_theory :
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    19
    Proof.context -> theory -> atp_format -> inference_policy -> string
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    20
    -> string -> unit
42602
a2db47fa015e added TPTP exporter facility -- useful to do experiments with machine learning
blanchet
parents:
diff changeset
    21
end;
a2db47fa015e added TPTP exporter facility -- useful to do experiments with machine learning
blanchet
parents:
diff changeset
    22
48234
06216c789ac9 moved MaSh into own files
blanchet
parents: 48233
diff changeset
    23
structure ATP_Theory_Export : ATP_THEORY_EXPORT =
42602
a2db47fa015e added TPTP exporter facility -- useful to do experiments with machine learning
blanchet
parents:
diff changeset
    24
struct
a2db47fa015e added TPTP exporter facility -- useful to do experiments with machine learning
blanchet
parents:
diff changeset
    25
43479
5af1abc13c1f only refer to facts found in TPTP file -- e.g. facts that simplify to true are excluded
blanchet
parents: 43468
diff changeset
    26
open ATP_Problem
43566
a818d5a34cca filter out some tautologies using an ATP, especially for those theories that are known for producing such things
blanchet
parents: 43499
diff changeset
    27
open ATP_Proof
46320
0b8b73b49848 renamed two files to make room for a new file
blanchet
parents: 46301
diff changeset
    28
open ATP_Problem_Generate
43566
a818d5a34cca filter out some tautologies using an ATP, especially for those theories that are known for producing such things
blanchet
parents: 43499
diff changeset
    29
open ATP_Systems
42602
a2db47fa015e added TPTP exporter facility -- useful to do experiments with machine learning
blanchet
parents:
diff changeset
    30
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    31
datatype inference_policy =
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    32
  No_Inferences | Unchecked_Inferences | Checked_Inferences
42602
a2db47fa015e added TPTP exporter facility -- useful to do experiments with machine learning
blanchet
parents:
diff changeset
    33
53980
7e6a82c593f4 made SML/NJ happy (NB: toplevel ML environment is unmanaged);
wenzelm
parents: 53586
diff changeset
    34
val prefix = Library.prefix
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    35
val fact_name_of = prefix fact_prefix o ascii_of
43479
5af1abc13c1f only refer to facts found in TPTP file -- e.g. facts that simplify to true are excluded
blanchet
parents: 43468
diff changeset
    36
54197
994ebb795b75 use definitions for LEO-II as well -- this simplifies the code and matches some users' expectations
blanchet
parents: 53980
diff changeset
    37
fun atp_of_format (THF (Polymorphic, _)) = dummy_thfN
994ebb795b75 use definitions for LEO-II as well -- this simplifies the code and matches some users' expectations
blanchet
parents: 53980
diff changeset
    38
  | atp_of_format (THF (Monomorphic, _)) = satallaxN
54788
a898e15b522a primitive support for SPASS-Pirate (Daniel Wand's polymorphic SPASS prototype)
blanchet
parents: 54197
diff changeset
    39
  | atp_of_format (DFG Polymorphic) = spass_pirateN
51998
f732a674db1b renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents: 51652
diff changeset
    40
  | atp_of_format (DFG Monomorphic) = spassN
52995
ab98feb66684 Vampire 3.0 requires types to be declared -- make it happy (and get rid of "implicit" types since only Satallax seems to support them anymore)
blanchet
parents: 52754
diff changeset
    41
  | atp_of_format (TFF Polymorphic) = alt_ergoN
ab98feb66684 Vampire 3.0 requires types to be declared -- make it happy (and get rid of "implicit" types since only Satallax seems to support them anymore)
blanchet
parents: 52754
diff changeset
    42
  | atp_of_format (TFF Monomorphic) = vampireN
51998
f732a674db1b renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents: 51652
diff changeset
    43
  | atp_of_format FOF = eN
f732a674db1b renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents: 51652
diff changeset
    44
  | atp_of_format CNF_UEQ = waldmeisterN
f732a674db1b renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents: 51652
diff changeset
    45
  | atp_of_format CNF = eN
48318
325c8fd0d762 more consolidation of MaSh code
blanchet
parents: 48316
diff changeset
    46
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    47
val atp_timeout = seconds 0.5
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    48
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    49
fun run_atp ctxt format problem =
43566
a818d5a34cca filter out some tautologies using an ATP, especially for those theories that are known for producing such things
blanchet
parents: 43499
diff changeset
    50
  let
a818d5a34cca filter out some tautologies using an ATP, especially for those theories that are known for producing such things
blanchet
parents: 43499
diff changeset
    51
    val thy = Proof_Context.theory_of ctxt
47055
16e2633f3b4b made "spass" a "metaprover" that uses either the new SPASS or the old SPASS, to preserve backward compatibility and prepare for the upcoming release
blanchet
parents: 47038
diff changeset
    52
    val prob_file = File.tmp_path (Path.explode "prob")
51998
f732a674db1b renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents: 51652
diff changeset
    53
    val atp = atp_of_format format
47606
06dde48a1503 true delayed evaluation of "SPASS_VERSION" environment variable
blanchet
parents: 47055
diff changeset
    54
    val {exec, arguments, proof_delims, known_failures, ...} =
06dde48a1503 true delayed evaluation of "SPASS_VERSION" environment variable
blanchet
parents: 47055
diff changeset
    55
      get_atp thy atp ()
47038
2409b484e1cc continued implementation of term ordering attributes
blanchet
parents: 46734
diff changeset
    56
    val ord = effective_term_order ctxt atp
51998
f732a674db1b renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents: 51652
diff changeset
    57
    val _ = problem |> lines_of_atp_problem format ord (K [])
46442
1e07620d724c added possibility of generating KBO weights to DFG problems
blanchet
parents: 46409
diff changeset
    58
                    |> File.write_list prob_file
52754
d9d90d29860e added support for E 1.8's internal proof objects (eliminating the need for "eproof_ram")
blanchet
parents: 52031
diff changeset
    59
    val exec = exec ()
48376
416e4123baf3 use "eproof_ram" script if available (plug-in replacement for "eproof", but faster)
blanchet
parents: 48324
diff changeset
    60
    val path = getenv (List.last (fst exec)) ^ "/" ^ List.last (snd exec)
43566
a818d5a34cca filter out some tautologies using an ATP, especially for those theories that are known for producing such things
blanchet
parents: 43499
diff changeset
    61
    val command =
50927
31d864d5057a added E-Par support
blanchet
parents: 50735
diff changeset
    62
      File.shell_path (Path.explode path) ^ " " ^
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    63
      arguments ctxt false "" atp_timeout (File.shell_path prob_file)
50927
31d864d5057a added E-Par support
blanchet
parents: 50735
diff changeset
    64
                (ord, K [], K [])
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    65
    val outcome =
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    66
      TimeLimit.timeLimit atp_timeout Isabelle_System.bash_output command
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    67
      |> fst
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    68
      |> extract_tstplike_proof_and_outcome false proof_delims known_failures
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    69
      |> snd
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    70
      handle TimeLimit.TimeOut => SOME TimedOut
51647
25acf689a53e no need to filter tautologies anymore -- they are prefiltered by "all_facts"'
blanchet
parents: 51646
diff changeset
    71
    val _ =
25acf689a53e no need to filter tautologies anymore -- they are prefiltered by "all_facts"'
blanchet
parents: 51646
diff changeset
    72
      tracing ("Ran ATP: " ^
51649
5d882158c221 compile + fixed naming convention
blanchet
parents: 51647
diff changeset
    73
               (case outcome of
5d882158c221 compile + fixed naming convention
blanchet
parents: 51647
diff changeset
    74
                  NONE => "Success"
53586
bd5fa6425993 prefixed types and some functions with "atp_" for disambiguation
blanchet
parents: 52995
diff changeset
    75
                | SOME failure => string_of_atp_failure failure))
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    76
  in outcome end
43566
a818d5a34cca filter out some tautologies using an ATP, especially for those theories that are known for producing such things
blanchet
parents: 43499
diff changeset
    77
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    78
fun is_problem_line_reprovable ctxt format prelude axioms deps
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    79
                               (Formula (ident', _, phi, _, _)) =
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    80
    is_none (run_atp ctxt format
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    81
        ((factsN, Formula (ident', Conjecture, phi, NONE, []) ::
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    82
                  map_filter (Symtab.lookup axioms) deps) ::
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    83
         prelude))
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    84
  | is_problem_line_reprovable _ _ _ _ _ _ = false
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    85
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    86
fun inference_term _ [] = NONE
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    87
  | inference_term check_infs ss =
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    88
    ATerm (("inference", []),
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    89
        [ATerm (("checked_isabelle" |> not check_infs ? prefix "un", []), []),
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    90
         ATerm ((tptp_empty_list, []), []),
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    91
         ATerm ((tptp_empty_list, []),
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    92
         map (fn s => ATerm ((s, []), [])) ss)])
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    93
    |> SOME
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    94
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    95
fun add_inferences_to_problem_line ctxt format check_infs prelude axioms infers
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    96
        (line as Formula ((ident, alt), Axiom, phi, NONE, tms)) =
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    97
    let
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    98
      val deps =
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
    99
        case these (AList.lookup (op =) infers ident) of
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   100
          [] => []
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   101
        | deps =>
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   102
          if check_infs andalso
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   103
             not (is_problem_line_reprovable ctxt format prelude axioms deps
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   104
                                             line) then
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   105
            []
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   106
          else
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   107
            deps
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   108
    in
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   109
      Formula ((ident, alt), Lemma, phi, inference_term check_infs deps, tms)
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   110
    end
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   111
  | add_inferences_to_problem_line _ _ _ _ _ _ line = line
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   112
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   113
fun add_inferences_to_problem ctxt format check_infs prelude infers problem =
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   114
  let
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   115
    fun add_if_axiom (axiom as Formula ((ident, _), Axiom, _, _, _)) =
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   116
        Symtab.default (ident, axiom)
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   117
      | add_if_axiom _ = I
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   118
    val add_axioms_of_problem = fold (fold add_if_axiom o snd)
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   119
    val axioms = Symtab.empty |> check_infs ? add_axioms_of_problem problem
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   120
  in
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   121
    map (apsnd (map (add_inferences_to_problem_line ctxt format check_infs
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   122
                         prelude axioms infers))) problem
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   123
  end
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   124
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   125
fun ident_of_problem_line (Class_Decl (ident, _, _)) = ident
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   126
  | ident_of_problem_line (Type_Decl (ident, _, _)) = ident
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   127
  | ident_of_problem_line (Sym_Decl (ident, _, _)) = ident
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   128
  | ident_of_problem_line (Class_Memb (ident, _, _, _)) = ident
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   129
  | ident_of_problem_line (Formula ((ident, _), _, _, _, _)) = ident
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   130
43499
9ca694caa61b order generated facts topologically
blanchet
parents: 43498
diff changeset
   131
fun order_facts ord = sort (ord o pairself ident_of_problem_line)
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   132
43499
9ca694caa61b order generated facts topologically
blanchet
parents: 43498
diff changeset
   133
fun order_problem_facts _ [] = []
9ca694caa61b order generated facts topologically
blanchet
parents: 43498
diff changeset
   134
  | order_problem_facts ord ((heading, lines) :: problem) =
9ca694caa61b order generated facts topologically
blanchet
parents: 43498
diff changeset
   135
    if heading = factsN then (heading, order_facts ord lines) :: problem
9ca694caa61b order generated facts topologically
blanchet
parents: 43498
diff changeset
   136
    else (heading, lines) :: order_problem_facts ord problem
9ca694caa61b order generated facts topologically
blanchet
parents: 43498
diff changeset
   137
45305
3e09961326ce also export DFG formats
blanchet
parents: 45301
diff changeset
   138
(* A fairly random selection of types used for monomorphizing. *)
3e09961326ce also export DFG formats
blanchet
parents: 45301
diff changeset
   139
val ground_types =
3e09961326ce also export DFG formats
blanchet
parents: 45301
diff changeset
   140
  [@{typ nat}, HOLogic.intT, HOLogic.realT, @{typ "nat => bool"}, @{typ bool},
3e09961326ce also export DFG formats
blanchet
parents: 45301
diff changeset
   141
   @{typ unit}]
3e09961326ce also export DFG formats
blanchet
parents: 45301
diff changeset
   142
51998
f732a674db1b renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents: 51652
diff changeset
   143
fun ground_type_of_tvar _ [] tvar =
f732a674db1b renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents: 51652
diff changeset
   144
    raise TYPE ("ground_type_of_tvar", [TVar tvar], [])
f732a674db1b renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents: 51652
diff changeset
   145
  | ground_type_of_tvar thy (T :: Ts) tvar =
45305
3e09961326ce also export DFG formats
blanchet
parents: 45301
diff changeset
   146
    if can (Sign.typ_match thy (TVar tvar, T)) Vartab.empty then T
51998
f732a674db1b renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents: 51652
diff changeset
   147
    else ground_type_of_tvar thy Ts tvar
45305
3e09961326ce also export DFG formats
blanchet
parents: 45301
diff changeset
   148
3e09961326ce also export DFG formats
blanchet
parents: 45301
diff changeset
   149
fun monomorphize_term ctxt t =
3e09961326ce also export DFG formats
blanchet
parents: 45301
diff changeset
   150
  let val thy = Proof_Context.theory_of ctxt in
51998
f732a674db1b renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents: 51652
diff changeset
   151
    t |> map_types (map_type_tvar (ground_type_of_tvar thy ground_types))
45305
3e09961326ce also export DFG formats
blanchet
parents: 45301
diff changeset
   152
    handle TYPE _ => @{prop True}
3e09961326ce also export DFG formats
blanchet
parents: 45301
diff changeset
   153
  end
3e09961326ce also export DFG formats
blanchet
parents: 45301
diff changeset
   154
51633
f11a1498dfdc try to preserve original linearization
blanchet
parents: 51632
diff changeset
   155
fun heading_sort_key heading =
f11a1498dfdc try to preserve original linearization
blanchet
parents: 51632
diff changeset
   156
  if String.isPrefix "Relevant fact" heading then "_" ^ heading else heading
f11a1498dfdc try to preserve original linearization
blanchet
parents: 51632
diff changeset
   157
51998
f732a674db1b renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents: 51652
diff changeset
   158
fun problem_of_theory ctxt thy format infer_policy type_enc =
42602
a2db47fa015e added TPTP exporter facility -- useful to do experiments with machine learning
blanchet
parents:
diff changeset
   159
  let
48299
5e5c6616f0fe centrally construct expensive data structures
blanchet
parents: 48251
diff changeset
   160
    val css_table = Sledgehammer_Fact.clasimpset_rule_table_of ctxt
48315
82d6e46c673f fixed order of accessibles + other tweaks to MaSh
blanchet
parents: 48301
diff changeset
   161
    val type_enc =
52031
9a9238342963 tuning -- renamed '_from_' to '_of_' in Sledgehammer
blanchet
parents: 51998
diff changeset
   162
      type_enc |> type_enc_of_string Non_Strict
48315
82d6e46c673f fixed order of accessibles + other tweaks to MaSh
blanchet
parents: 48301
diff changeset
   163
               |> adjust_type_enc format
48131
1016664b8feb started adding polymophic SPASS output
blanchet
parents: 48130
diff changeset
   164
    val mono = not (is_type_enc_polymorphic type_enc)
48438
3e45c98fe127 distinguish between recursive and nonrecursive definitions + clean up typedef dependencies in MaSh
blanchet
parents: 48406
diff changeset
   165
    val facts =
50442
4f6a4d32522c don't blacklist "case" theorems -- this causes problems in MaSh later
blanchet
parents: 48716
diff changeset
   166
      Sledgehammer_Fact.all_facts (Proof_Context.init_global thy) true false
48530
d443166f9520 repaired accessibility chains generated by MaSh exporter + tuned one function out
blanchet
parents: 48438
diff changeset
   167
                                  Symtab.empty [] [] css_table
51633
f11a1498dfdc try to preserve original linearization
blanchet
parents: 51632
diff changeset
   168
      |> sort (Sledgehammer_MaSh.crude_thm_ord o pairself snd)
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   169
    val problem =
43576
ebeda6275027 don't export any metastrange or other nonatomizable formulas, since these don't help proving normal things, they are somewhat broken in the ATP output, and they are atypical
blanchet
parents: 43572
diff changeset
   170
      facts
45305
3e09961326ce also export DFG formats
blanchet
parents: 45301
diff changeset
   171
      |> map (fn ((_, loc), th) =>
3e09961326ce also export DFG formats
blanchet
parents: 45301
diff changeset
   172
                 ((Thm.get_name_hint th, loc),
3e09961326ce also export DFG formats
blanchet
parents: 45301
diff changeset
   173
                   th |> prop_of |> mono ? monomorphize_term ctxt))
47946
33afcfad3f8d add an experimental "aggressive" mode to Sledgehammer, to experiment with more complete translations of higher-order features without breaking "metis"
blanchet
parents: 47912
diff changeset
   174
      |> prepare_atp_problem ctxt format Axiom type_enc Exporter combsN false
33afcfad3f8d add an experimental "aggressive" mode to Sledgehammer, to experiment with more complete translations of higher-order features without breaking "metis"
blanchet
parents: 47912
diff changeset
   175
                             false true [] @{prop False}
51647
25acf689a53e no need to filter tautologies anymore -- they are prefiltered by "all_facts"'
blanchet
parents: 51646
diff changeset
   176
      |> #1 |> sort_wrt (heading_sort_key o fst)
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   177
    val prelude = fst (split_last problem)
50735
6b232d76cbc9 refined class handling, to prevent cycles in fact graph
blanchet
parents: 50521
diff changeset
   178
    val name_tabs = Sledgehammer_Fact.build_name_tables Thm.get_name_hint facts
42602
a2db47fa015e added TPTP exporter facility -- useful to do experiments with machine learning
blanchet
parents:
diff changeset
   179
    val infers =
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   180
      if infer_policy = No_Inferences then
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   181
        []
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   182
      else
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   183
        facts
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   184
        |> map (fn (_, th) =>
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   185
                   (fact_name_of (Thm.get_name_hint th),
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   186
                    th |> Sledgehammer_Util.thms_in_proof (SOME name_tabs)
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   187
                       |> map fact_name_of))
51650
3dd495cd98a2 smoothly handle cyclic graphs
blanchet
parents: 51649
diff changeset
   188
    val all_problem_names =
3dd495cd98a2 smoothly handle cyclic graphs
blanchet
parents: 51649
diff changeset
   189
      problem |> maps (map ident_of_problem_line o snd)
3dd495cd98a2 smoothly handle cyclic graphs
blanchet
parents: 51649
diff changeset
   190
              |> distinct (op =)
3dd495cd98a2 smoothly handle cyclic graphs
blanchet
parents: 51649
diff changeset
   191
    val all_problem_name_set = Symtab.make (map (rpair ()) all_problem_names)
42602
a2db47fa015e added TPTP exporter facility -- useful to do experiments with machine learning
blanchet
parents:
diff changeset
   192
    val infers =
51650
3dd495cd98a2 smoothly handle cyclic graphs
blanchet
parents: 51649
diff changeset
   193
      infers |> filter (Symtab.defined all_problem_name_set o fst)
3dd495cd98a2 smoothly handle cyclic graphs
blanchet
parents: 51649
diff changeset
   194
             |> map (apsnd (filter (Symtab.defined all_problem_name_set)))
3dd495cd98a2 smoothly handle cyclic graphs
blanchet
parents: 51649
diff changeset
   195
    val maybe_add_edge = perhaps o try o String_Graph.add_edge_acyclic
43499
9ca694caa61b order generated facts topologically
blanchet
parents: 43498
diff changeset
   196
    val ordered_names =
9ca694caa61b order generated facts topologically
blanchet
parents: 43498
diff changeset
   197
      String_Graph.empty
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   198
      |> fold (String_Graph.new_node o rpair ()) all_problem_names
43499
9ca694caa61b order generated facts topologically
blanchet
parents: 43498
diff changeset
   199
      |> fold (fn (to, froms) =>
51650
3dd495cd98a2 smoothly handle cyclic graphs
blanchet
parents: 51649
diff changeset
   200
                  fold (fn from => maybe_add_edge (from, to)) froms)
43566
a818d5a34cca filter out some tautologies using an ATP, especially for those theories that are known for producing such things
blanchet
parents: 43499
diff changeset
   201
              infers
51650
3dd495cd98a2 smoothly handle cyclic graphs
blanchet
parents: 51649
diff changeset
   202
      |> fold (fn (to, from) => maybe_add_edge (from, to))
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   203
              (tl all_problem_names ~~ fst (split_last all_problem_names))
43499
9ca694caa61b order generated facts topologically
blanchet
parents: 43498
diff changeset
   204
      |> String_Graph.topological_order
9ca694caa61b order generated facts topologically
blanchet
parents: 43498
diff changeset
   205
    val order_tab =
9ca694caa61b order generated facts topologically
blanchet
parents: 43498
diff changeset
   206
      Symtab.empty
9ca694caa61b order generated facts topologically
blanchet
parents: 43498
diff changeset
   207
      |> fold (Symtab.insert (op =))
9ca694caa61b order generated facts topologically
blanchet
parents: 43498
diff changeset
   208
              (ordered_names ~~ (1 upto length ordered_names))
9ca694caa61b order generated facts topologically
blanchet
parents: 43498
diff changeset
   209
    val name_ord = int_ord o pairself (the o Symtab.lookup order_tab)
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   210
  in
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   211
    problem
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   212
    |> (case format of
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   213
          DFG _ => I
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   214
        | _ => add_inferences_to_problem ctxt format
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   215
                   (infer_policy = Checked_Inferences) prelude infers)
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   216
    |> order_problem_facts name_ord
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   217
  end
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   218
51998
f732a674db1b renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents: 51652
diff changeset
   219
fun lines_of_problem ctxt format =
f732a674db1b renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents: 51652
diff changeset
   220
  lines_of_atp_problem format (effective_term_order ctxt eN (* dummy *)) (K [])
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   221
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   222
fun write_lines path ss =
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   223
  let
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   224
    val _ = File.write path ""
42602
a2db47fa015e added TPTP exporter facility -- useful to do experiments with machine learning
blanchet
parents:
diff changeset
   225
    val _ = app (File.append path) ss
a2db47fa015e added TPTP exporter facility -- useful to do experiments with machine learning
blanchet
parents:
diff changeset
   226
  in () end
a2db47fa015e added TPTP exporter facility -- useful to do experiments with machine learning
blanchet
parents:
diff changeset
   227
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   228
fun generate_atp_inference_file_for_theory ctxt thy format infer_policy type_enc
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   229
                                           file_name =
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   230
  let
51998
f732a674db1b renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents: 51652
diff changeset
   231
    val problem = problem_of_theory ctxt thy format infer_policy type_enc
f732a674db1b renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents: 51652
diff changeset
   232
    val ss = lines_of_problem ctxt format problem
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   233
  in write_lines (Path.explode file_name) ss end
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   234
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   235
fun ap dir = Path.append dir o Path.explode
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   236
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   237
fun chop_maximal_groups eq xs =
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   238
  let
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   239
    val rev_xs = rev xs
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   240
    fun chop_group _ [] = []
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   241
      | chop_group n (xs as x :: _) =
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   242
        let
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   243
          val n' = find_index (curry eq x) rev_xs
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   244
          val (ws', xs') = chop (n - n') xs
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   245
        in ws' :: chop_group n' xs' end
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   246
   in chop_group (length xs) xs end
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   247
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   248
fun theory_name_of_fact (Formula ((_, alt), _, _, _, _)) =
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   249
    (case first_field Long_Name.separator alt of
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   250
       NONE => alt
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   251
     | SOME (thy, _) => thy)
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   252
  | theory_name_of_fact _ = ""
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   253
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   254
val problem_suffix = ".p"
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   255
val include_suffix = ".ax"
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   256
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   257
val file_order_name = "FilesInProcessingOrder"
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   258
val problem_order_name = "ProblemsInProcessingOrder"
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   259
val problem_name = "problems"
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   260
val include_name = "incl"
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   261
val prelude_base_name = "prelude"
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   262
val prelude_name = prelude_base_name ^ include_suffix
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   263
51652
5ff01d585a8c handle case clashes on Mac file system by encoding goal numbers
blanchet
parents: 51650
diff changeset
   264
val encode_meta = Sledgehammer_MaSh.encode_str
5ff01d585a8c handle case clashes on Mac file system by encoding goal numbers
blanchet
parents: 51650
diff changeset
   265
53980
7e6a82c593f4 made SML/NJ happy (NB: toplevel ML environment is unmanaged);
wenzelm
parents: 53586
diff changeset
   266
fun include_base_name_of_fact x = encode_meta (theory_name_of_fact x)
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   267
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   268
fun include_line base_name =
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   269
  "include('" ^ include_name ^ "/" ^ base_name ^ include_suffix ^ "').\n"
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   270
51652
5ff01d585a8c handle case clashes on Mac file system by encoding goal numbers
blanchet
parents: 51650
diff changeset
   271
val hol_base_name = encode_meta "HOL"
5ff01d585a8c handle case clashes on Mac file system by encoding goal numbers
blanchet
parents: 51650
diff changeset
   272
5ff01d585a8c handle case clashes on Mac file system by encoding goal numbers
blanchet
parents: 51650
diff changeset
   273
fun should_generate_problem thy base_name (Formula ((_, alt), _, _, _, _)) =
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   274
  case try (Global_Theory.get_thm thy) alt of
51652
5ff01d585a8c handle case clashes on Mac file system by encoding goal numbers
blanchet
parents: 51650
diff changeset
   275
    SOME th =>
5ff01d585a8c handle case clashes on Mac file system by encoding goal numbers
blanchet
parents: 51650
diff changeset
   276
    (* This is a crude hack to detect theorems stated and proved by the user (as
5ff01d585a8c handle case clashes on Mac file system by encoding goal numbers
blanchet
parents: 51650
diff changeset
   277
       opposed to those derived by various packages). In addition, we leave out
5ff01d585a8c handle case clashes on Mac file system by encoding goal numbers
blanchet
parents: 51650
diff changeset
   278
       everything in "HOL" as too basic to be interesting. *)
5ff01d585a8c handle case clashes on Mac file system by encoding goal numbers
blanchet
parents: 51650
diff changeset
   279
    Thm.legacy_get_kind th <> "" andalso base_name <> hol_base_name
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   280
  | NONE => false
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   281
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   282
(* Convention: theoryname__goalname *)
51652
5ff01d585a8c handle case clashes on Mac file system by encoding goal numbers
blanchet
parents: 51650
diff changeset
   283
fun problem_name_of base_name n alt =
5ff01d585a8c handle case clashes on Mac file system by encoding goal numbers
blanchet
parents: 51650
diff changeset
   284
  base_name ^ "__" ^ string_of_int n ^ "_" ^
5ff01d585a8c handle case clashes on Mac file system by encoding goal numbers
blanchet
parents: 51650
diff changeset
   285
  perhaps (try (unprefix (base_name ^ "_"))) alt ^ problem_suffix
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   286
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   287
fun generate_casc_lbt_isa_files_for_theory ctxt thy format infer_policy type_enc
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   288
                                           dir_name =
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   289
  let
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   290
    val dir = Path.explode dir_name
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   291
    val _ = Isabelle_System.mkdir dir
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   292
    val file_order_path = ap dir file_order_name
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   293
    val _ = File.write file_order_path ""
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   294
    val problem_order_path = ap dir problem_order_name
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   295
    val _ = File.write problem_order_path ""
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   296
    val problem_dir = ap dir problem_name
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   297
    val _ = Isabelle_System.mkdir problem_dir
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   298
    val include_dir = ap problem_dir include_name
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   299
    val _ = Isabelle_System.mkdir include_dir
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   300
    val (prelude, groups) =
51998
f732a674db1b renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents: 51652
diff changeset
   301
      problem_of_theory ctxt thy format infer_policy type_enc
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   302
      |> split_last
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   303
      ||> (snd
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   304
           #> chop_maximal_groups (op = o pairself theory_name_of_fact)
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   305
           #> map (`(include_base_name_of_fact o hd)))
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   306
    fun write_prelude () =
51998
f732a674db1b renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents: 51652
diff changeset
   307
      let val ss = lines_of_problem ctxt format prelude in
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   308
        File.append file_order_path (prelude_base_name ^ "\n");
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   309
        write_lines (ap include_dir prelude_name) ss
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   310
      end
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   311
    fun write_include_file (base_name, facts) =
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   312
      let
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   313
        val name = base_name ^ include_suffix
51998
f732a674db1b renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents: 51652
diff changeset
   314
        val ss = lines_of_problem ctxt format [(factsN, facts)]
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   315
      in
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   316
        File.append file_order_path (base_name ^ "\n");
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   317
        write_lines (ap include_dir name) ss
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   318
      end
51652
5ff01d585a8c handle case clashes on Mac file system by encoding goal numbers
blanchet
parents: 51650
diff changeset
   319
    fun write_problem_files _ _ _ [] = ()
5ff01d585a8c handle case clashes on Mac file system by encoding goal numbers
blanchet
parents: 51650
diff changeset
   320
      | write_problem_files _ includes [] groups =
5ff01d585a8c handle case clashes on Mac file system by encoding goal numbers
blanchet
parents: 51650
diff changeset
   321
        write_problem_files 1 includes includes groups
5ff01d585a8c handle case clashes on Mac file system by encoding goal numbers
blanchet
parents: 51650
diff changeset
   322
      | write_problem_files n includes _ ((base_name, []) :: groups) =
5ff01d585a8c handle case clashes on Mac file system by encoding goal numbers
blanchet
parents: 51650
diff changeset
   323
        write_problem_files n (includes @ [include_line base_name]) [] groups
5ff01d585a8c handle case clashes on Mac file system by encoding goal numbers
blanchet
parents: 51650
diff changeset
   324
      | write_problem_files n includes seen
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   325
                            ((base_name, fact :: facts) :: groups) =
51998
f732a674db1b renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents: 51652
diff changeset
   326
        let val fact_s = tptp_string_of_line format fact in
51652
5ff01d585a8c handle case clashes on Mac file system by encoding goal numbers
blanchet
parents: 51650
diff changeset
   327
          (if should_generate_problem thy base_name fact then
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   328
             let
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   329
               val (name, conj) =
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   330
                 (case fact of
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   331
                    Formula ((ident, alt), _, phi, _, _) =>
51652
5ff01d585a8c handle case clashes on Mac file system by encoding goal numbers
blanchet
parents: 51650
diff changeset
   332
                    (problem_name_of base_name n (encode_meta alt),
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   333
                     Formula ((ident, alt), Conjecture, phi, NONE, [])))
51998
f732a674db1b renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents: 51652
diff changeset
   334
               val conj_s = tptp_string_of_line format conj
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   335
             in
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   336
               File.append problem_order_path (name ^ "\n");
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   337
               write_lines (ap problem_dir name) (seen @ [conj_s])
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   338
             end
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   339
           else
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   340
             ();
51652
5ff01d585a8c handle case clashes on Mac file system by encoding goal numbers
blanchet
parents: 51650
diff changeset
   341
           write_problem_files (n + 1) includes (seen @ [fact_s])
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   342
                               ((base_name, facts) :: groups))
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   343
        end
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   344
    val _ = write_prelude ()
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   345
    val _ = app write_include_file groups
51652
5ff01d585a8c handle case clashes on Mac file system by encoding goal numbers
blanchet
parents: 51650
diff changeset
   346
    val _ = write_problem_files 1 [include_line prelude_base_name] [] groups
51646
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   347
  in () end
005b7682178b work on CASC LTB ISA exporter
blanchet
parents: 51633
diff changeset
   348
42602
a2db47fa015e added TPTP exporter facility -- useful to do experiments with machine learning
blanchet
parents:
diff changeset
   349
end;