lib/scripts/SystemOnTPTP
author wenzelm
Tue, 04 Aug 2009 13:35:33 +0200
changeset 32321 13920dbe4547
parent 31833 9ab1326ed98d
permissions -rwxr-xr-x
more uniform handling of ISABELLE_HOME_USER component; discontinued ISABELLE_IGNORE_USER_SETTINGS (ever used? cf. c567f9fd61a2);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28573
6403f0e16269 ** Update from Fabian **
wenzelm
parents:
diff changeset
     1
#!/usr/bin/env perl
6403f0e16269 ** Update from Fabian **
wenzelm
parents:
diff changeset
     2
#
6403f0e16269 ** Update from Fabian **
wenzelm
parents:
diff changeset
     3
# Wrapper for custom remote provers on SystemOnTPTP
6403f0e16269 ** Update from Fabian **
wenzelm
parents:
diff changeset
     4
# Author: Fabian Immler, TU Muenchen
6403f0e16269 ** Update from Fabian **
wenzelm
parents:
diff changeset
     5
#
6403f0e16269 ** Update from Fabian **
wenzelm
parents:
diff changeset
     6
6403f0e16269 ** Update from Fabian **
wenzelm
parents:
diff changeset
     7
use warnings;
6403f0e16269 ** Update from Fabian **
wenzelm
parents:
diff changeset
     8
use strict;
6403f0e16269 ** Update from Fabian **
wenzelm
parents:
diff changeset
     9
use Getopt::Std;
6403f0e16269 ** Update from Fabian **
wenzelm
parents:
diff changeset
    10
use HTTP::Request::Common;
29590
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    11
use LWP;
28573
6403f0e16269 ** Update from Fabian **
wenzelm
parents:
diff changeset
    12
31833
9ab1326ed98d use X2TPTP optionally and only for remote_spass;
immler@in.tum.de
parents: 30979
diff changeset
    13
my $SystemOnTPTPFormReplyURL =
9ab1326ed98d use X2TPTP optionally and only for remote_spass;
immler@in.tum.de
parents: 30979
diff changeset
    14
  "http://www.cs.miami.edu/~tptp/cgi-bin/SystemOnTPTPFormReply";
28573
6403f0e16269 ** Update from Fabian **
wenzelm
parents:
diff changeset
    15
29590
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    16
# default parameters
28573
6403f0e16269 ** Update from Fabian **
wenzelm
parents:
diff changeset
    17
my %URLParameters = (
6403f0e16269 ** Update from Fabian **
wenzelm
parents:
diff changeset
    18
    "NoHTML" => 1,
6403f0e16269 ** Update from Fabian **
wenzelm
parents:
diff changeset
    19
    "QuietFlag" => "-q01",
6403f0e16269 ** Update from Fabian **
wenzelm
parents:
diff changeset
    20
    "SubmitButton" => "RunSelectedSystems",
6403f0e16269 ** Update from Fabian **
wenzelm
parents:
diff changeset
    21
    "ProblemSource" => "UPLOAD",
29590
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    22
    );
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    23
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    24
#----Get format and transform options if specified
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    25
my %Options;
31833
9ab1326ed98d use X2TPTP optionally and only for remote_spass;
immler@in.tum.de
parents: 30979
diff changeset
    26
getopts("hwxs:t:c:",\%Options);
29590
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    27
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    28
#----Usage
30874
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
    29
sub usage() {
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
    30
  print("Usage: remote [<options>] <File name>\n");
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
    31
  print("    <options> are ...\n");
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
    32
  print("    -h            - print this help\n");
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
    33
  print("    -w            - list available ATP systems\n");
31833
9ab1326ed98d use X2TPTP optionally and only for remote_spass;
immler@in.tum.de
parents: 30979
diff changeset
    34
  print("    -x            - use X2TPTP to convert output of prover\n");
30874
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
    35
  print("    -s<system>    - specified system to use\n");
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
    36
  print("    -t<timelimit> - CPU time limit for system\n");
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
    37
  print("    -c<command>   - custom command for system\n");
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
    38
  print("    <File name>   - TPTP problem file\n");
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
    39
  exit(0);
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
    40
}
29590
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    41
if (exists($Options{'h'})) {
30874
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
    42
  usage();
29590
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    43
}
31833
9ab1326ed98d use X2TPTP optionally and only for remote_spass;
immler@in.tum.de
parents: 30979
diff changeset
    44
29590
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    45
#----What systems flag
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    46
if (exists($Options{'w'})) {
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    47
    $URLParameters{"SubmitButton"} = "ListSystems";
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    48
    delete($URLParameters{"ProblemSource"});
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    49
}
31833
9ab1326ed98d use X2TPTP optionally and only for remote_spass;
immler@in.tum.de
parents: 30979
diff changeset
    50
9ab1326ed98d use X2TPTP optionally and only for remote_spass;
immler@in.tum.de
parents: 30979
diff changeset
    51
#----X2TPTP
9ab1326ed98d use X2TPTP optionally and only for remote_spass;
immler@in.tum.de
parents: 30979
diff changeset
    52
if (exists($Options{'x'})) {
9ab1326ed98d use X2TPTP optionally and only for remote_spass;
immler@in.tum.de
parents: 30979
diff changeset
    53
    $URLParameters{"X2TPTP"} = "-S";
9ab1326ed98d use X2TPTP optionally and only for remote_spass;
immler@in.tum.de
parents: 30979
diff changeset
    54
}
9ab1326ed98d use X2TPTP optionally and only for remote_spass;
immler@in.tum.de
parents: 30979
diff changeset
    55
29590
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    56
#----Selected system
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    57
my $System;
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    58
if (exists($Options{'s'})) {
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    59
    $System = $Options{'s'};
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    60
} else {
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    61
    # use Vampire as default
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    62
    $System = "Vampire---9.0";
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    63
}
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    64
$URLParameters{"System___$System"} = $System;
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    65
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    66
#----Time limit
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    67
if (exists($Options{'t'})) {
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    68
    $URLParameters{"TimeLimit___$System"} = $Options{'t'};
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    69
}
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    70
#----Custom command
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    71
if (exists($Options{'c'})) {
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    72
    $URLParameters{"Command___$System"} = $Options{'c'};
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    73
}
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    74
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    75
#----Get single file name
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    76
if (exists($URLParameters{"ProblemSource"})) {
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    77
    if (scalar(@ARGV) >= 1) {
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    78
        $URLParameters{"UPLOADProblem"} = [shift(@ARGV)];
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    79
    } else {
30874
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
    80
      print("Missing problem file\n");
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
    81
      usage();
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
    82
      die;
29590
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    83
    }
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    84
}
28573
6403f0e16269 ** Update from Fabian **
wenzelm
parents:
diff changeset
    85
6403f0e16269 ** Update from Fabian **
wenzelm
parents:
diff changeset
    86
# Query Server
6403f0e16269 ** Update from Fabian **
wenzelm
parents:
diff changeset
    87
my $Agent = LWP::UserAgent->new;
29590
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    88
if (exists($Options{'t'})) {
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    89
  # give server more time to respond
30534
0ac3db5a59a8 removed connection check;
immler@in.tum.de
parents: 29590
diff changeset
    90
  $Agent->timeout($Options{'t'} + 10);
29590
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    91
}
28573
6403f0e16269 ** Update from Fabian **
wenzelm
parents:
diff changeset
    92
my $Request = POST($SystemOnTPTPFormReplyURL,
6403f0e16269 ** Update from Fabian **
wenzelm
parents:
diff changeset
    93
	Content_Type => 'form-data',Content => \%URLParameters);
6403f0e16269 ** Update from Fabian **
wenzelm
parents:
diff changeset
    94
my $Response = $Agent->request($Request);
29590
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    95
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
    96
#catch errors / failure
31833
9ab1326ed98d use X2TPTP optionally and only for remote_spass;
immler@in.tum.de
parents: 30979
diff changeset
    97
if(!$Response->is_success) {
30535
db8b10fd51a4 show certain errors to the user
immler@in.tum.de
parents: 30534
diff changeset
    98
  print "HTTP-Error: " . $Response->message . "\n";
db8b10fd51a4 show certain errors to the user
immler@in.tum.de
parents: 30534
diff changeset
    99
  exit(-1);
29590
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
   100
} elsif (exists($Options{'w'})) {
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
   101
  print $Response->content;
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
   102
  exit (0);
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
   103
} elsif ($Response->content =~ /WARNING: (\S*) does not exist/) {
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
   104
  print "Specified System $1 does not exist\n";
479a2fce65e6 modified remote script;
immler@in.tum.de
parents: 29588
diff changeset
   105
  exit(-1);
31833
9ab1326ed98d use X2TPTP optionally and only for remote_spass;
immler@in.tum.de
parents: 30979
diff changeset
   106
} elsif (exists($Options{'x'}) &&
9ab1326ed98d use X2TPTP optionally and only for remote_spass;
immler@in.tum.de
parents: 30979
diff changeset
   107
  $Response->content =~
9ab1326ed98d use X2TPTP optionally and only for remote_spass;
immler@in.tum.de
parents: 30979
diff changeset
   108
    /%\s*Result\s*:\s*Unsatisfiable.*\n%\s*Output\s*:\s*(CNF)?Refutation.*\n%/ &&
9ab1326ed98d use X2TPTP optionally and only for remote_spass;
immler@in.tum.de
parents: 30979
diff changeset
   109
  $Response->content !~ /ERROR: Could not form TPTP format derivation/ )
9ab1326ed98d use X2TPTP optionally and only for remote_spass;
immler@in.tum.de
parents: 30979
diff changeset
   110
{
9ab1326ed98d use X2TPTP optionally and only for remote_spass;
immler@in.tum.de
parents: 30979
diff changeset
   111
  # converted output: extract proof
30874
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
   112
  my @lines = split( /\n/, $Response->content);
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
   113
  my $extract = "";
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
   114
  foreach my $line (@lines){
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
   115
      #ignore comments
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
   116
      if ($line !~ /^%/ && !($line eq "")) {
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
   117
          $extract .= "$line";
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
   118
      }
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
   119
  }
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
   120
  # insert newlines after ').'
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
   121
  $extract =~ s/\s//g;
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
   122
  $extract =~ s/\)\.cnf/\)\.\ncnf/g;
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
   123
31833
9ab1326ed98d use X2TPTP optionally and only for remote_spass;
immler@in.tum.de
parents: 30979
diff changeset
   124
  print "========== ~~/lib/scripts/SystemOnTPTP extracted proof: ==========\n";
30874
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
   125
  # orientation for res_reconstruct.ML
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
   126
  print "# SZS output start CNFRefutation.\n";
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
   127
  print "$extract\n";
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
   128
  print "# SZS output end CNFRefutation.\n";
31833
9ab1326ed98d use X2TPTP optionally and only for remote_spass;
immler@in.tum.de
parents: 30979
diff changeset
   129
  # can be useful for debugging; Isabelle ignores this
9ab1326ed98d use X2TPTP optionally and only for remote_spass;
immler@in.tum.de
parents: 30979
diff changeset
   130
  print "============== original response from SystemOnTPTP: ==============\n";
9ab1326ed98d use X2TPTP optionally and only for remote_spass;
immler@in.tum.de
parents: 30979
diff changeset
   131
  print $Response->content;
30874
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
   132
  exit(0);
31833
9ab1326ed98d use X2TPTP optionally and only for remote_spass;
immler@in.tum.de
parents: 30979
diff changeset
   133
} elsif (!exists($Options{'x'})) {
9ab1326ed98d use X2TPTP optionally and only for remote_spass;
immler@in.tum.de
parents: 30979
diff changeset
   134
  # pass output directly to Isabelle
9ab1326ed98d use X2TPTP optionally and only for remote_spass;
immler@in.tum.de
parents: 30979
diff changeset
   135
  print $Response->content;
9ab1326ed98d use X2TPTP optionally and only for remote_spass;
immler@in.tum.de
parents: 30979
diff changeset
   136
  exit(0);
9ab1326ed98d use X2TPTP optionally and only for remote_spass;
immler@in.tum.de
parents: 30979
diff changeset
   137
}else {
30874
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
   138
  print "Remote-script could not extract proof:\n".$Response->content;
34927a1e0ae8 reverted to explicitly check the presence of a refutation
immler@in.tum.de
parents: 30535
diff changeset
   139
  exit(-1);
28573
6403f0e16269 ** Update from Fabian **
wenzelm
parents:
diff changeset
   140
}
6403f0e16269 ** Update from Fabian **
wenzelm
parents:
diff changeset
   141