Skip to content

Commit 9938d18

Browse files
Googlersloos
authored andcommitted
Project import generated by Copybara.
PiperOrigin-RevId: 250504726 Change-Id: I30b6e4f6f4856deccbb8300167ce02fcb307c808
1 parent 64b376d commit 9938d18

File tree

5 files changed

+40
-46
lines changed

5 files changed

+40
-46
lines changed

api/hol_light_prover.cc

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
// Ignore this comment (1).
44
// Ignore this comment (2).
5+
#include "proof_assistant.pb.h"
56
#include "theorem_fingerprint.h"
67
// Ignore this comment (3).
78
#include "google/protobuf/stubs/status.h"
@@ -30,8 +31,6 @@ enum Request {
3031
// LINT.ThenChange(//hol_light/sandboxee.ml)
3132

3233
constexpr int kTermEncodingSExpr = 2;
33-
34-
constexpr int kTacticTimeoutMilliseconds = 5000;
3534
} // namespace
3635

3736
HolLightProver::HolLightProver(Comm* comm) : comm_(comm) {
@@ -44,8 +43,8 @@ util::StatusOr<ApplyTacticResponse> HolLightProver::ApplyTactic(
4443
RETURN_IF_ERROR(SendGoal(request.goal()));
4544
RETURN_IF_ERROR(comm_->SendString(request.tactic()));
4645
LOG(INFO) << "Calling HOL Light to apply tactic; setting timer (in ms):"
47-
<< kTacticTimeoutMilliseconds;
48-
auto timer = comm_->GetTimer(kTacticTimeoutMilliseconds);
46+
<< request.timeout_ms();
47+
auto timer = comm_->GetTimer(request.timeout_ms());
4948
RETURN_IF_ERROR(comm_->GetStatus());
5049
ApplyTacticResponse response;
5150
int64 result;
@@ -108,9 +107,9 @@ Status HolLightProver::ReceiveGoals(GoalList* goals) {
108107
goal->set_tag(Theorem::GOAL);
109108
RETURN_IF_ERROR(comm_->ReceiveInt(&m));
110109
for (int64 j = 0; j < m; ++j) {
111-
string* term =
112-
(j == 0) ? goal->mutable_pretty_printed() :
113-
(j == 1) ? goal->mutable_conclusion() : goal->add_hypotheses();
110+
string* term = (j == 0) ? goal->mutable_pretty_printed()
111+
: (j == 1) ? goal->mutable_conclusion()
112+
: goal->add_hypotheses();
114113
RETURN_IF_ERROR(comm_->ReceiveString(term));
115114
}
116115
}
@@ -138,7 +137,7 @@ Status HolLightProver::SendTheorem(const Theorem& theorem) {
138137
}
139138

140139
Status HolLightProver::ApplyTactic(const string& tactic) {
141-
auto timer = comm_->GetTimer(kTacticTimeoutMilliseconds);
140+
auto timer = comm_->GetTimer(deepmath::ApplyTacticRequest().timeout_ms());
142141
RETURN_IF_ERROR(comm_->SendInt(kApplyTactic));
143142
RETURN_IF_ERROR(comm_->SendString(tactic));
144143
return comm_->GetStatus();
@@ -189,19 +188,14 @@ Status HolLightProver::SetTermEncoding(int encoding) {
189188
StatusOr<RegisterTheoremResponse> HolLightProver::RegisterTheorem(
190189
const RegisterTheoremRequest& request) {
191190
const auto& theorem = request.theorem();
191+
LOG(INFO) << "Registering " << theorem.fingerprint() << ".";
192192
Status status = CheatTheorem(theorem);
193193
RegisterTheoremResponse response;
194-
if (status.ok()) {
195-
status = CompareLastTheorem(theorem);
196-
if (status.ok()) {
197-
response.set_fingerprint(Fingerprint(theorem));
198-
return response;
199-
} else {
200-
response.set_error_msg(status.ToString());
201-
}
202-
} else {
194+
response.set_fingerprint(request.theorem().fingerprint());
195+
if (!status.ok()) {
203196
response.set_error_msg(status.ToString());
204197
}
198+
LOG(INFO) << "Registered " << theorem.fingerprint() << ".";
205199
return response;
206200
}
207201

@@ -210,13 +204,6 @@ Status HolLightProver::CheatTheorem(const Theorem& theorem) {
210204
case Theorem::TYPE_DEFINITION:
211205
return DefineType(theorem.type_definition());
212206
case Theorem::DEFINITION: {
213-
auto status = Define(theorem.definition());
214-
if (status.ok()) {
215-
return status;
216-
}
217-
// TODO(mrabe): remove the need to cheat-in.
218-
LOG(WARNING) << "Definition failed, will be cheating-in. Fingerprint: "
219-
<< Fingerprint(theorem) << ". Error was: " << status;
220207
RETURN_IF_ERROR(comm_->SendInt(kRegisterTheorem));
221208
RETURN_IF_ERROR(SendTheorem(theorem));
222209
RETURN_IF_ERROR(comm_->SendInt(Fingerprint(theorem)));

api/proof_assistant.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ message GoalList {
8787
message ApplyTacticRequest {
8888
optional Theorem goal = 1;
8989
optional string tactic = 2;
90+
optional int64 timeout_ms = 3 [default = 5000];
9091
}
9192

9293
message ApplyTacticResponse {

fusion.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,12 @@ module Hol : Hol_kernel = struct
198198

199199
(* order is independent of type names, but list may contain duplicates *)
200200
let rec tyvars__stable_acc acc = function
201-
Tyvar v as tv -> tv :: acc
201+
Tyvar v -> Tyvar v :: acc
202202
| Tyapp (x, []) -> acc
203203
| Tyapp (x, arg :: argr) ->
204+
(* TODO(mrabe): This is a bug. The order of processing the arguments
205+
* should be swapped here. This makes the OCaml normalization of terms
206+
* behave slightly different from normalization in Python. *)
204207
tyvars__stable_acc (tyvars__stable_acc acc arg) (Tyapp(x, argr))
205208

206209
let tyvars__stable = tyvars__stable_acc []

log.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ let tactic_argument_thm fmt ptype (srcs: src list) : unit =
573573
tactic_argument_thms
574574
fmt ptype
575575
(fun th ->
576-
print_thm_pb fmt (normalize_theorem th) "GOAL" (fun _ -> ()))
576+
print_thm_pb fmt (normalize_theorem th) "THEOREM" (fun _ -> ()))
577577
(map extract_thm srcs);;
578578

579579
let tactic_arguments_pb fmt (taclog : src tactic_log) =

pb_printer.ml

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ let print_goal_pb (fmt: Format.formatter)
169169
let print_thm_pb (fmt: Format.formatter)
170170
(th: thm) (tag: string)
171171
(definition_printer : Format.formatter -> unit) : unit =
172+
(if tag == "GOAL" then failwith "Trying to print GOAL with print_thm_pb");
172173
print_goal_pb fmt (dest_thm th) tag definition_printer;;
173174

174175
(* ---------------------------------------------------------------------------*)
@@ -212,8 +213,29 @@ let thm_db_print_definition (log: bool) (definition_type: string) (th: thm)
212213
Format.pp_print_flush fmt ()
213214
| None -> ();;
214215

216+
let thm_db_print_theorem (th: thm)
217+
(source: string) (goal_fingerprint : int option) : unit =
218+
let th = normalize_theorem th in
219+
if not (Theorem_fingerprint.thm_is_known th) then (
220+
Theorem_fingerprint.register_thm th;
221+
match thm_db_fmt with
222+
Some fmt ->
223+
pp_print_string fmt "theorems {";
224+
print_thm_pb fmt th "THEOREM" (fun _ -> ());
225+
pp_print_string fmt (" pretty_printed: \"" ^ pb_string_of_thm th ^ "\"");
226+
pb_print_library_tags fmt;
227+
pp_print_string fmt (" proof_function: \"" ^ source ^ "\"");
228+
(match goal_fingerprint with
229+
Some goal_fingerprint ->
230+
print_int_pb fmt "goal_fingerprint" goal_fingerprint;
231+
| None -> ());
232+
pp_print_string fmt "}\n";
233+
Format.pp_print_flush fmt ()
234+
| None -> ());;
235+
215236
let print_type_definition (tyname: string) (absname: string) (repname: string)
216237
(th_arg: thm) : Format.formatter -> unit =
238+
let th_arg = normalize_theorem th_arg in
217239
fun fmt ->
218240
pp_print_string fmt (" type_name: \"" ^ tyname ^ "\"");
219241
pp_print_string fmt (" abs_name: \"" ^ absname ^ "\"");
@@ -222,6 +244,7 @@ let print_type_definition (tyname: string) (absname: string) (repname: string)
222244

223245
let thm_db_print_type_definition (tyname: string)
224246
(absname: string) (repname: string) (th_arg: thm) (th_result: thm) : unit =
247+
thm_db_print_theorem th_arg "type_definition_helper" None;
225248
let th_result = normalize_theorem th_result in
226249
Theorem_fingerprint.register_thm th_result;
227250
match thm_db_fmt with
@@ -235,26 +258,6 @@ let thm_db_print_type_definition (tyname: string)
235258
Format.pp_print_flush fmt ()
236259
| None -> ();;
237260

238-
let thm_db_print_theorem (th: thm)
239-
(source: string) (goal_fingerprint : int option) : unit =
240-
let th = normalize_theorem th in
241-
if not (Theorem_fingerprint.thm_is_known th) then (
242-
Theorem_fingerprint.register_thm th;
243-
match thm_db_fmt with
244-
Some fmt ->
245-
pp_print_string fmt "theorems {";
246-
print_thm_pb fmt th "THEOREM" (fun _ -> ());
247-
pp_print_string fmt (" pretty_printed: \"" ^ pb_string_of_thm th ^ "\"");
248-
pb_print_library_tags fmt;
249-
pp_print_string fmt (" proof_function: \"" ^ source ^ "\"");
250-
(match goal_fingerprint with
251-
Some goal_fingerprint ->
252-
print_int_pb fmt "goal_fingerprint" goal_fingerprint;
253-
| None -> ());
254-
pp_print_string fmt "}\n";
255-
Format.pp_print_flush fmt ()
256-
| None -> ());;
257-
258261
let thm_db_print_specification (log: bool)
259262
(definition_type: string) (constants: string list)
260263
(thm_arg: thm) (th: thm) : unit =

0 commit comments

Comments
 (0)