Skip to content

Commit 1052076

Browse files
committed
Merge branch 'main' into feat/expand-definition-2
2 parents 1d59a1a + 12464fc commit 1052076

File tree

19 files changed

+738
-132
lines changed

19 files changed

+738
-132
lines changed

src/g_waterproof.mlg

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,10 @@ let () = add_scope "open_lconstr" (fun arg ->
7272
(* Doing this enables parsing the mathematical expressions without parentheses *)
7373
(* The cost of this is that these words are no longer allowed to be variables *)
7474
{
75-
let () = Procq.set_keyword_state (
76-
(CLexer.add_keyword (
77-
(CLexer.add_keyword (
78-
(CLexer.add_keyword (
79-
(CLexer.add_keyword (
80-
(CLexer.add_keyword (
81-
(CLexer.add_keyword (
82-
CLexer.add_keyword (Procq.get_keyword_state()) "and"
83-
) "as")
84-
) "hold")
85-
) "holds")
86-
) "it")
87-
) "or")
88-
) "we")
89-
)
75+
let () = Mltop.add_init_function "coq-waterproof.plugin" @@ fun () ->
76+
Procq.set_keyword_state
77+
(List.fold_left CLexer.add_keyword (Procq.get_keyword_state())
78+
["and"; "as"; "hold"; "holds"; "it"; "or"; "we"; "that"])
9079
}
9180
VERNAC COMMAND EXTEND AutomationShieldEnableSideEff CLASSIFIED AS SIDEFF
9281
| [ "Waterproof" "Enable" "Automation" "Shield" ] ->

src/waterprove.ml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ open Wp_eauto
2727
open Wp_rewrite
2828

2929
(**
30-
Is automation shield enabled ?
30+
Is automation shield enabled ?
3131
*)
3232
let automation_shield: bool ref = Summary.ref ~name:"automation_shield" true
3333

3434
(**
35-
Do we want to debug the automation ?
35+
Do we want to debug the automation ?
3636
*)
3737
let automation_debug : bool ref = Summary.ref ~name:"automation_debug" false
3838

@@ -76,15 +76,17 @@ let restricted_automation_routine (depth: int) (lems: Tactypes.delayed_open_cons
7676
- [depth] ([int]): max depth of the proof search
7777
- [shield] ([bool]): if set to [true], will stop the proof search if a forbidden pattern is found
7878
- [lems] ([Tactypes.delayed_open_constr list]): additional lemmas that are given to solve the proof
79+
- [dbs] ([hint_db_name list]): list of additional hint databases to use
7980
- [database_type] ([Hint_dataset_declarations]): type of databases that will be use as hint databases
8081
*)
81-
let waterprove (depth: int) ?(shield: bool = false) (lems: Tactypes.delayed_open_constr list) (database_type: database_type): unit tactic =
82+
let waterprove (depth: int) ?(shield: bool = false) (lems: Tactypes.delayed_open_constr list)
83+
(dbs: hint_db_name list) (database_type: database_type): unit tactic =
8284
Proofview.Goal.enter @@ fun goal ->
8385
begin
84-
if shield && !automation_shield then
85-
automation_routine 3 lems (get_current_databases Shorten)
86+
if shield && !automation_shield then
87+
automation_routine 3 lems (dbs @ (get_current_databases Shorten))
8688
else
87-
automation_routine depth lems (get_current_databases database_type)
89+
automation_routine depth lems (dbs @ get_current_databases database_type)
8890
end
8991

9092
(**
@@ -96,19 +98,21 @@ let waterprove (depth: int) ?(shield: bool = false) (lems: Tactypes.delayed_open
9698
- [depth] ([int]): max depth of the proof search
9799
- [shield] ([bool]): if set to [true], will stop the proof search if a forbidden pattern is found
98100
- [lems] ([Tactypes.delayed_open_constr list]): additional lemmas that are given to solve the proof
101+
- [dbs] ([hint_db_name list]): list of additional hint databases to use
99102
- [database_type] ([Hint_dataset_declarations]): type of databases that will be use as hint databases
100103
- [must_use] ([string list]): list of hints that have to be used during the automatic solving
101104
- [forbidden] ([string list]): list of hints that must not be used during the automatic solving
102105
*)
103-
let rwaterprove (depth: int) ?(shield: bool = false) (lems: Tactypes.delayed_open_constr list) (database_type: database_type) (must_use: constr list) (forbidden: constr list): unit tactic =
106+
let rwaterprove (depth: int) ?(shield: bool = false) (lems: Tactypes.delayed_open_constr list)
107+
(dbs : hint_db_name list) (database_type: database_type) (must_use: constr list) (forbidden: constr list): unit tactic =
104108
Proofview.Goal.enter @@ fun goal ->
105109
begin
106110
let env = Proofview.Goal.env goal in
107111
let sigma = Proofview.Goal.sigma goal in
108112
let must_use_tactics = List.map (Printer.pr_econstr_env env sigma) must_use in
109113
let forbidden_tactics = List.map (Printer.pr_econstr_env env sigma) forbidden in
110114
if shield && !automation_shield then
111-
restricted_automation_routine 3 lems (get_current_databases Shorten) must_use_tactics forbidden_tactics
115+
restricted_automation_routine 3 lems (dbs @ (get_current_databases Shorten)) must_use_tactics forbidden_tactics
112116
else
113-
restricted_automation_routine depth lems (get_current_databases database_type) must_use_tactics forbidden_tactics
117+
restricted_automation_routine depth lems (dbs @ (get_current_databases database_type)) must_use_tactics forbidden_tactics
114118
end

src/waterprove.mli

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
(******************************************************************************)
1818

1919
(**
20-
Is automation shield enabled ?
20+
Is automation shield enabled ?
2121
*)
2222
val automation_shield : bool ref
2323

2424
(**
25-
Do we want to debug the automation ?
25+
Do we want to debug the automation ?
2626
*)
2727
val automation_debug : bool ref
2828

@@ -44,12 +44,14 @@ val print_rewrite_hints: bool ref
4444
- [depth] ([int]): max depth of the proof search
4545
- [shield] ([bool]): if set to [true], will stop the proof search if a forbidden pattern is found
4646
- [lems] ([Tactypes.delayed_open_constr list]): additional lemmas that are given to solve the proof
47+
- [dbs] ([hint_db_name list]): list of additional hint databases to use
4748
- [database_type] ([Hint_dataset_declarations]): type of databases that will be use as hint databases
4849
*)
4950
val waterprove :
5051
int ->
5152
?shield:bool ->
5253
Tactypes.delayed_open_constr list ->
54+
Hints.hint_db_name list ->
5355
Hint_dataset_declarations.database_type ->
5456
unit Proofview.tactic
5557

@@ -62,6 +64,7 @@ val waterprove :
6264
- [depth] ([int]): max depth of the proof search
6365
- [shield] ([bool]): if set to [true], will stop the proof search if a forbidden pattern is found
6466
- [lems] ([Tactypes.delayed_open_constr list]): additional lemmas that are given to solve the proof
67+
- [dbs] ([hint_db_name list]): list of additional hint databases to use
6568
- [database_type] ([Hint_dataset_declarations]): type of databases that will be use as hint databases
6669
- [must_use] ([string list]): list of hints that have to be used during the automatic solving
6770
- [forbidden] ([string list]): list of hints that must not be used during the automatic solving
@@ -70,6 +73,7 @@ val rwaterprove :
7073
int ->
7174
?shield:bool ->
7275
Tactypes.delayed_open_constr list ->
76+
Hints.hint_db_name list ->
7377
Hint_dataset_declarations.database_type ->
7478
Evd.econstr list ->
7579
Evd.econstr list ->

src/wp_ffi.ml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,26 +121,28 @@ let feedback_level = make_repr of_feedback_level to_feedback_level
121121

122122
(* Exports {! Waterprove.waterprove} to Ltac2 *)
123123
let () =
124-
define "waterprove" (int @-> bool @-> (list (thunk constr)) @-> database_type @-> tac unit) @@
125-
fun depth shield lems database_type ->
124+
define "waterprove" (int @-> bool @-> (list (thunk constr)) @-> list string @-> database_type @-> tac unit) @@
125+
fun depth shield lems dbs database_type ->
126126
begin
127127
waterprove
128128
depth
129129
~shield
130130
(List.map (fun lem -> delayed_of_thunk constr lem) lems)
131+
dbs
131132
database_type
132133
end
133134

134135
(* Exports {! Waterprove.rwaterprove} to Ltac2 *)
135136
let () =
136-
define "rwaterprove" (int @-> bool @-> (list (thunk constr))
137+
define "rwaterprove" (int @-> bool @-> (list (thunk constr)) @-> list string
137138
@-> database_type @-> list constr @-> list constr @-> tac unit) @@
138-
fun depth shield lems database_type must_use forbidden ->
139+
fun depth shield lems dbs database_type must_use forbidden ->
139140
begin
140141
rwaterprove
141142
depth
142143
~shield
143144
(List.map (fun lem -> delayed_of_thunk constr lem) lems)
145+
dbs
144146
database_type
145147
must_use
146148
forbidden

tests/automation/Chains.v

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,26 @@ Abort.
5757
Goal P -> (& a = b = b = b = b = b).
5858
Proof.
5959
intro H.
60-
rwaterprove 5 true Main constr:(h).
60+
rwaterprove 5 true Main [constr:(h)] [].
6161
Abort.
6262

6363
(* Test 5: extra lemma has to be used in last equality. *)
6464
Goal P -> (& b = b = b = b = b = a).
6565
Proof.
6666
intro H.
67-
rwaterprove 5 true Main constr:(h).
67+
rwaterprove 5 true Main [constr:(h)] [].
6868
Abort.
6969

7070
(* Test 6: extra lemma has to be used in 2nd and 2nd-to-last equality. *)
7171
Goal P -> (& b = b = a = b = b = a = a).
7272
Proof.
7373
intro H.
74-
rwaterprove 5 true Main constr:(h).
74+
rwaterprove 5 true Main [constr:(h)] [].
7575
Abort.
7676

7777
(* Test 7: Fails if extra lemma is never used. *)
7878
Goal P -> (P -> b = c) -> (& b = b = c = b = b = c = c).
7979
Proof.
8080
intros H1 H2.
81-
Fail rwaterprove 5 true Main constr:(h).
81+
Fail rwaterprove 5 true Main [constr:(h)] [].
8282
Abort.

tests/tactics/Conclusion.v

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ Proof.
141141
reflexivity.
142142
assert_fails_with_string
143143
(fun () => By test_by_we_conclude_1 we conclude that (1 < 2))
144-
"Could not verify this follows from test_by_we_conclude_1.".
144+
"Could not verify this follows from the provided reasons.".
145145
Abort.
146146

147147
(** Additional tests 'By ...' clause. *)
@@ -307,3 +307,73 @@ Proof.
307307
It holds that (true).
308308
Since true we conclude that true.
309309
Qed.
310+
311+
(** Test 11: Test concluding from multiple reasons.
312+
*)
313+
314+
Local Parameter P Q R T : Prop.
315+
Local Parameter HP : P.
316+
Local Parameter HPQ : P -> Q.
317+
Local Parameter HQR : Q -> R.
318+
Local Parameter HRT : R -> T.
319+
320+
Local Parameter U V : Prop.
321+
Local Parameter HUV : U -> V.
322+
Local Parameter HVP : V -> P.
323+
324+
Local Create HintDb my_reason.
325+
From Stdlib Require Import String.
326+
327+
Goal T.
328+
By HP, HPQ, HQR and HRT we conclude that T.
329+
Qed.
330+
331+
(** Test 12: Conclude from multiple reasons, one of them is also a local hypothesis. *)
332+
333+
Goal P -> T.
334+
intro H.
335+
By HP, HPQ, HQR and HRT we conclude that T.
336+
Qed.
337+
338+
(** Test 13: Conclude from multiple reasons, one of
339+
them is a local hypothesis, using the local hypothesis. *)
340+
Goal P -> T.
341+
intro H.
342+
By H, HPQ, HQR and HRT we conclude that T.
343+
Qed.
344+
345+
(** Test 14: Conclude using an extra database. *)
346+
Notation "'my' 'reason'" := "my_reason"%string.
347+
Hint Resolve HUV : my_reason.
348+
349+
Notation "'my' 'other' 'reason'" := "my_other_reason"%string.
350+
Hint Resolve HVP : my_other_reason.
351+
352+
Goal U -> V.
353+
intro H.
354+
By my reason we conclude that V.
355+
Qed.
356+
357+
(** Test 15: Use two extra databases.*)
358+
359+
Goal U -> P.
360+
intro H.
361+
By my reason and my other reason we conclude that P.
362+
Qed.
363+
364+
(** Test 16: Use two extra databases and extra lemmas. *)
365+
366+
Goal U -> R.
367+
intro H.
368+
By my reason, my other reason, HPQ and HQR we conclude that R.
369+
Qed.
370+
371+
(** Test 17: Fail when a reason is given that is not
372+
used. *)
373+
374+
Goal U -> R.
375+
intro H.
376+
assert_fails_with_string
377+
(fun () => By my reason, my other reason, HPQ, HQR and HRT we conclude that R)
378+
"Could not verify this follows from the provided reasons.".
379+
Abort.

tests/tactics/Help.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Require Import Waterproof.Tactics.Help.
2424
Require Import Waterproof.Util.MessagesToUser.
2525
Require Import Waterproof.Util.Assertions.
2626
Require Import Waterproof.Notations.Sets.
27+
Require Import Waterproof.Tactics.By.
2728
Open Scope subset_scope.
2829

2930
Waterproof Enable Hypothesis Help.

tests/tactics/ItHolds.v

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,3 +401,69 @@ Proof.
401401
Use x := 6 in (H1).
402402
Fail It holds that (6 >= 5 -> True) as (H1).
403403
Abort.
404+
405+
(** Test 29: Use multiple hypotheses,
406+
hypothesis of same type already in local context *)
407+
408+
Local Parameter a b c : Prop.
409+
Local Parameter Ha : a.
410+
Local Parameter Hab : a -> b.
411+
Local Parameter Hbc : b -> c.
412+
413+
Goal a -> b.
414+
Proof.
415+
intro H.
416+
By Ha, Hab and Hbc it holds that c.
417+
Abort.
418+
419+
(** Test 30: Use multiple hypothesis,
420+
use one hypothesis from context *)
421+
422+
Goal a -> b.
423+
Proof.
424+
intro H.
425+
By H, Hab and Hbc it holds that c.
426+
Abort.
427+
428+
Waterproof Enable Redirect Errors.
429+
Waterproof Enable Logging.
430+
431+
(** Test 31: Multiple hypotheses, mention hypothesis that is not useful *)
432+
433+
Goal a -> b.
434+
Proof.
435+
assert_fails_with_string (fun () => By Ha, Hab and Hbc it holds that b)
436+
"Could not verify this follows from the provided reasons.".
437+
Abort.
438+
439+
Local Parameter d : Prop.
440+
Local Parameter Hd : d.
441+
442+
Local Create HintDb my_reason.
443+
From Stdlib Require Import String.
444+
445+
Notation "'my' 'reason'" := "my_reason"%string.
446+
Hint Resolve Hd : my_reason.
447+
448+
(** Test 32: Use extra database *)
449+
450+
Goal a -> b.
451+
Proof.
452+
assert_fails_with_string
453+
(fun () =>It holds that d)
454+
"Could not verify that d.".
455+
By my reason it holds that d.
456+
Abort.
457+
458+
Local Create HintDb my_second_reason.
459+
Notation "'my' 'second' 'reason'" := "my_second_reason"%string.
460+
Local Parameter Hda : d -> a.
461+
Hint Resolve Hda : my_second_reason.
462+
463+
(** Test 33: Use extra databases and additional lemmas *)
464+
465+
Goal b.
466+
By my reason, my second reason and Hab it holds that b as (i).
467+
clear i.
468+
By my reason, my second reason, Hab and Hbc it holds that c.
469+
Abort.

0 commit comments

Comments
 (0)