src/HOL/TPTP/TPTP_Interpret_Test.thy
author blanchet
Wed, 18 Apr 2012 22:39:35 +0200
changeset 47558 55b42f9af99d
parent 47548 60849d8c457d
child 47693 64023cf4d148
permissions -rw-r--r--
phase out "$TPTP_PROBLEMS_PATH"; prefer "$TPTP" for consistency with CASC setup
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
     1
(*  Title:      HOL/TPTP/TPTP_Interpret_Test.thy
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
     2
    Author:     Nik Sultana, Cambridge University Computer Laboratory
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
     3
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
     4
Some tests for the TPTP interface. Some of the tests rely on the Isabelle
47558
55b42f9af99d phase out "$TPTP_PROBLEMS_PATH"; prefer "$TPTP" for consistency with CASC setup
blanchet
parents: 47548
diff changeset
     5
environment variable $TPTP, which should point to the TPTP-vX.Y.Z directory.
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
     6
*)
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
     7
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
     8
theory TPTP_Interpret_Test
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
     9
imports TPTP_Test TPTP_Interpret
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    10
begin
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    11
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    12
section "Interpreter tests"
47518
b2f209258621 more cleaning of tptp tests;
sultana
parents: 47516
diff changeset
    13
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    14
text "Interpret a problem."
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    15
ML {*
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    16
  val (time, ((type_map, const_map, fmlas), thy)) =
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    17
    Timing.timing
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    18
      (TPTP_Interpret.interpret_file
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    19
       false
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    20
       (Path.dir tptp_probs_dir)
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    21
      (Path.append tptp_probs_dir (Path.explode "LCL/LCL825-1.p"))
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    22
       []
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    23
       [])
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    24
      @{theory}
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    25
*}
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    26
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    27
text "... and display nicely."
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    28
ML {*
47548
60849d8c457d fixed type interpretation;
sultana
parents: 47547
diff changeset
    29
  List.app (Pretty.writeln o (Syntax.pretty_term @{context}) o #3) fmlas;
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    30
*}
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    31
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    32
subsection "Multiple tests"
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    33
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    34
ML {*
47518
b2f209258621 more cleaning of tptp tests;
sultana
parents: 47516
diff changeset
    35
  (*default timeout is 1 min*)
47516
9c29589c9b31 improved tptp interpretation test thy
sultana
parents: 47512
diff changeset
    36
  fun interpret timeout file thy =
47518
b2f209258621 more cleaning of tptp tests;
sultana
parents: 47516
diff changeset
    37
    TimeLimit.timeLimit (Time.fromSeconds (if timeout = 0 then 60 else timeout))
47516
9c29589c9b31 improved tptp interpretation test thy
sultana
parents: 47512
diff changeset
    38
     (TPTP_Interpret.interpret_file
9c29589c9b31 improved tptp interpretation test thy
sultana
parents: 47512
diff changeset
    39
       false
9c29589c9b31 improved tptp interpretation test thy
sultana
parents: 47512
diff changeset
    40
       (Path.dir tptp_probs_dir)
9c29589c9b31 improved tptp interpretation test thy
sultana
parents: 47512
diff changeset
    41
       file
9c29589c9b31 improved tptp interpretation test thy
sultana
parents: 47512
diff changeset
    42
       []
9c29589c9b31 improved tptp interpretation test thy
sultana
parents: 47512
diff changeset
    43
       []) thy
9c29589c9b31 improved tptp interpretation test thy
sultana
parents: 47512
diff changeset
    44
9c29589c9b31 improved tptp interpretation test thy
sultana
parents: 47512
diff changeset
    45
  fun interpret_timed timeout file thy =
9c29589c9b31 improved tptp interpretation test thy
sultana
parents: 47512
diff changeset
    46
    Timing.timing (interpret timeout file) thy
9c29589c9b31 improved tptp interpretation test thy
sultana
parents: 47512
diff changeset
    47
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    48
  fun interpretation_test timeout ctxt =
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    49
    test_fn ctxt
47518
b2f209258621 more cleaning of tptp tests;
sultana
parents: 47516
diff changeset
    50
     (fn file => interpret timeout file (Proof_Context.theory_of ctxt))
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    51
     "interpreter"
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    52
     ()
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    53
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    54
  fun interpretation_tests timeout ctxt probs =
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    55
    List.app
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    56
     (interpretation_test timeout ctxt)
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    57
     (List.map situate probs)
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    58
*}
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    59
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    60
ML {*
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    61
  val some_probs =
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    62
    ["LCL/LCL825-1.p",
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    63
     "ALG/ALG001^5.p",
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    64
     "COM/COM003+2.p",
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    65
     "COM/COM003-1.p",
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    66
     "COM/COM024^5.p",
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    67
     "DAT/DAT017=1.p",
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    68
     "NUM/NUM021^1.p",
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    69
     "NUM/NUM858=1.p",
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    70
     "SYN/SYN000^2.p"]
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    71
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    72
  val take_too_long =
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    73
    ["NLP/NLP562+1.p",
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    74
     "SWV/SWV546-1.010.p",
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    75
     "SWV/SWV567-1.015.p",
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    76
     "LCL/LCL680+1.020.p"]
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    77
47516
9c29589c9b31 improved tptp interpretation test thy
sultana
parents: 47512
diff changeset
    78
  val timeouts =
9c29589c9b31 improved tptp interpretation test thy
sultana
parents: 47512
diff changeset
    79
    ["NUM/NUM923^4.p",
9c29589c9b31 improved tptp interpretation test thy
sultana
parents: 47512
diff changeset
    80
    "NUM/NUM926^4.p",
9c29589c9b31 improved tptp interpretation test thy
sultana
parents: 47512
diff changeset
    81
    "NUM/NUM925^4.p",
9c29589c9b31 improved tptp interpretation test thy
sultana
parents: 47512
diff changeset
    82
    "NUM/NUM924^4.p",
9c29589c9b31 improved tptp interpretation test thy
sultana
parents: 47512
diff changeset
    83
    "CSR/CSR153^3.p",
9c29589c9b31 improved tptp interpretation test thy
sultana
parents: 47512
diff changeset
    84
    "CSR/CSR151^3.p",
9c29589c9b31 improved tptp interpretation test thy
sultana
parents: 47512
diff changeset
    85
    "CSR/CSR148^3.p",
9c29589c9b31 improved tptp interpretation test thy
sultana
parents: 47512
diff changeset
    86
    "CSR/CSR120^3.p",
9c29589c9b31 improved tptp interpretation test thy
sultana
parents: 47512
diff changeset
    87
    "CSR/CSR150^3.p",
9c29589c9b31 improved tptp interpretation test thy
sultana
parents: 47512
diff changeset
    88
    "CSR/CSR119^3.p",
9c29589c9b31 improved tptp interpretation test thy
sultana
parents: 47512
diff changeset
    89
    "CSR/CSR149^3.p"]
9c29589c9b31 improved tptp interpretation test thy
sultana
parents: 47512
diff changeset
    90
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    91
  val more_probs =
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    92
    ["GEG/GEG014^1.p",
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    93
     "GEG/GEG009^1.p",
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    94
     "GEG/GEG004^1.p",
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    95
     "GEG/GEG007^1.p",
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    96
     "GEG/GEG016^1.p",
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    97
     "GEG/GEG024=1.p",
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    98
     "GEG/GEG010^1.p",
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
    99
     "GEG/GEG003^1.p",
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   100
     "GEG/GEG018^1.p",
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   101
     "SYN/SYN045^4.p",
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   102
     "SYN/SYN001^4.001.p",
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   103
     "SYN/SYN000^2.p",
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   104
     "SYN/SYN387^4.p",
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   105
     "SYN/SYN393^4.002.p",
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   106
     "SYN/SYN978^4.p",
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   107
     "SYN/SYN044^4.p",
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   108
     "SYN/SYN393^4.003.p",
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   109
     "SYN/SYN389^4.p"]
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   110
*}
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   111
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   112
ML {*
47547
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   113
 interpretation_tests (get_timeout @{context}) @{context}
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   114
   (some_probs @ take_too_long @ timeouts @ more_probs)
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   115
*}
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   116
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   117
ML {*
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   118
  parse_timed (situate "NUM/NUM923^4.p");
47516
9c29589c9b31 improved tptp interpretation test thy
sultana
parents: 47512
diff changeset
   119
  interpret_timed 0 (situate "NUM/NUM923^4.p") @{theory}
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   120
*}
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   121
47516
9c29589c9b31 improved tptp interpretation test thy
sultana
parents: 47512
diff changeset
   122
ML {*
47547
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   123
  fun interp_gain timeout thy file =
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   124
    let
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   125
      val t1 = (parse_timed file |> fst)
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   126
      val t2 = (interpret_timed timeout file thy |> fst)
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   127
        handle exn => (*FIXME*)
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   128
          if Exn.is_interrupt exn then reraise exn
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   129
          else
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   130
            (warning (" test: file " ^ Path.print file ^
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   131
             " raised exception: " ^ ML_Compiler.exn_message exn);
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   132
             {gc = Time.zeroTime, cpu = Time.zeroTime, elapsed = Time.zeroTime})
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   133
      val to_real = Time.toReal
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   134
      val diff_elapsed =
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   135
        #elapsed t2 - #elapsed t1
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   136
        |> to_real
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   137
      val elapsed = to_real (#elapsed t2)
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   138
    in
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   139
      (Path.base file, diff_elapsed,
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   140
       diff_elapsed / elapsed,
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   141
       elapsed)
1a5dc8377b5c more tptp testing support functions;
sultana
parents: 47518
diff changeset
   142
    end
47516
9c29589c9b31 improved tptp interpretation test thy
sultana
parents: 47512
diff changeset
   143
*}
9c29589c9b31 improved tptp interpretation test thy
sultana
parents: 47512
diff changeset
   144
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   145
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   146
subsection "Test against whole TPTP"
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   147
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   148
text "Run interpretation over all problems. This works only for logics
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   149
 for which interpretation is defined (in TPTP_Parser/tptp_interpret.ML)."
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   150
ML {*
47518
b2f209258621 more cleaning of tptp tests;
sultana
parents: 47516
diff changeset
   151
  if test_all @{context} then
b2f209258621 more cleaning of tptp tests;
sultana
parents: 47516
diff changeset
   152
    (report @{context} "Interpreting all problems";
b2f209258621 more cleaning of tptp tests;
sultana
parents: 47516
diff changeset
   153
     S timed_test (interpretation_test (get_timeout @{context})) @{context})
b2f209258621 more cleaning of tptp tests;
sultana
parents: 47516
diff changeset
   154
  else ()
47512
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   155
*}
b381d428a725 reorganised tptp testing thys
sultana
parents:
diff changeset
   156
47518
b2f209258621 more cleaning of tptp tests;
sultana
parents: 47516
diff changeset
   157
end