Skip to content

Commit 004b4f2

Browse files
committed
Waterproof proof mode, first version.
1 parent f62a9d9 commit 004b4f2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+1386
-1110
lines changed

src/g_waterproof.mlg

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,55 @@ DECLARE PLUGIN "coq-waterproof.plugin"
2121
{
2222
open Exceptions
2323
open Waterprove
24+
open Vernacextend
25+
open G_vernac
26+
open Ltac2_plugin
27+
open Ltac2_plugin.G_ltac2
2428

2529
let waterproof_version : string = "3.1.1+dev"
30+
31+
let wp_command_entry = Procq.Entry.make "waterproof_command"
32+
33+
(* The actual custom entry is not yet created at plugin linking time
34+
and may be re-created at summary unfreeze time, but we need a truly
35+
global entry to use in VERNAC EXTEND.
36+
37+
To solve this we use indirection: the global entry calls a dynamic
38+
parser which looks up the custom entry. *)
39+
let wp_entry_name = Names.Id.of_string "waterproof_tactic"
40+
41+
let wp_entry_full_name =
42+
(Libnames.add_path_suffix (Libnames.path_of_string "Waterproof.Waterproof") wp_entry_name)
43+
44+
let parse_wp_tactic _kwstate strm =
45+
let entry = Tac2entries.CustomTab.of_path wp_entry_full_name in
46+
let entry = Tac2entries.find_custom_entry entry in
47+
Procq.Entry.parse_token_stream entry strm
48+
49+
let wp_tactic_entry = Procq.Entry.of_parser "waterproof_tactic" { parser_fun = parse_wp_tactic }
50+
let _wp_tactic_entry = wp_tactic_entry
51+
52+
let _ : Pvernac.proof_mode = Pvernac.register_proof_mode "Waterproof"
53+
(ProofMode {
54+
command_entry = wp_command_entry;
55+
wit_tactic_expr = Tac2env.wit_ltac2_tac;
56+
tactic_expr_entry = wp_tactic_entry;
57+
})
58+
59+
(* Duplicated with g_ltac2 *)
60+
let pr_ltac2expr e = Tac2print.pr_rawexpr_gen E5 ~avoid:Names.Id.Set.empty e
61+
62+
let () = "coq-waterproof.plugin" |> Mltop.declare_cache_obj @@ fun () ->
63+
Tac2entries.register_custom_entry (CAst.make wp_entry_name)
64+
65+
let waterproof_set_default_notation_target = function
66+
| (Some _, _) as v -> v
67+
| None, lev ->
68+
let qid = Libnames.qualid_of_path wp_entry_full_name in
69+
Some qid, Some (Option.default 5 lev)
70+
71+
let raw_attributes = Attributes.raw_attributes
72+
2673
}
2774

2875
(* Add any words that occur right after mathematical expressions as keywords *)
@@ -35,6 +82,39 @@ let () = Mltop.add_init_function "coq-waterproof.plugin" @@ fun () ->
3582
(fun kw -> CLexer.add_keyword_tok kw (Tok.PKEYWORD s)))
3683
["and"; "as"; "hold"; "holds"; "it"; "or"; "we"; "that"]
3784
}
85+
86+
VERNAC ARGUMENT EXTEND wp_tactic_entry
87+
PRINTED BY { pr_ltac2expr }
88+
| [ _wp_tactic_entry(e) ] -> { e }
89+
END
90+
91+
VERNAC { wp_command_entry } EXTEND VernacLtac2Alt
92+
| ![proof] [ wp_tactic_entry(t) "." ] =>
93+
{ classify_as_proofstep } -> { fun ~pstate ->
94+
Tac2entries.call ~pstate None ~with_end_tac:(CAst.make false) t
95+
}
96+
END
97+
98+
VERNAC COMMAND EXTEND WaterproofNotation
99+
| #[ raw_attributes ] [ "Waterproof" "Notation" ltac2def_syn(e) ] => { Vernacextend.(VtSideff ([], VtNow)) } SYNTERP AS synterpv {
100+
let (toks, n, body) = e in
101+
let n = waterproof_set_default_notation_target n in
102+
Tac2entries.register_notation raw_attributes toks n body
103+
} ->
104+
{
105+
Tac2entries.register_notation_interpretation synterpv
106+
}
107+
END
108+
109+
GRAMMAR EXTEND Gram
110+
GLOBAL: wp_command_entry;
111+
wp_command_entry: TOP
112+
[ [ p = subprf -> { Vernacexpr.VernacSynPure p }
113+
| g = OPT toplevel_selector; p = subprf_with_selector -> { Vernacexpr.VernacSynPure (p g) }
114+
] ];
115+
END
116+
117+
(* Rest of waterproof *)
38118
VERNAC COMMAND EXTEND AutomationShieldEnableSideEff CLASSIFIED AS SIDEFF
39119
| [ "Waterproof" "Enable" "Automation" "Shield" ] ->
40120
{

tests/automation/Chains.v

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Waterproof Enable Redirect Feedback.
3434
Local Parameter X : Type.
3535
Local Parameter a b c : X.
3636

37+
Set Default Proof Mode "Ltac2".
38+
3739
(* Test 1: first equality does not hold. *)
3840
Goal (& a = b = c).
3941
Proof.

tests/automation/Shield.v

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,14 @@ Abort.
128128
(** Testing de Morgan laws. *)
129129

130130
Require Import Waterproof.Libs.Negation.
131-
#[export] Hint Extern 1 => solve_by_manipulating_negation (fun () => ()) : wp_negation_logic.
131+
#[export] Hint Extern 1 => ltac2: solve_by_manipulating_negation (fun () => ()) : wp_negation_logic.
132132

133133
(** Level 1 *)
134134
Local Parameter P1 : R -> Prop.
135135
(* Test 15 *)
136136
Goal ~ (forall x : R, P1 x) -> (exists x : R, ~ (P1 x)).
137137
Proof.
138-
intro H.
138+
ltac2: intro H.
139139
We conclude that (there exists x : ℝ, ¬ P1 x).
140140
Qed.
141141

@@ -150,14 +150,14 @@ Local Parameter P2 : R -> R -> Prop.
150150
(* Test 17 *)
151151
Goal ~ (forall x : R, exists y : R, P2 x y) -> (exists x : R, ~ (exists y : R, P2 x y)).
152152
Proof.
153-
intro H.
153+
ltac2: intro H.
154154
We conclude that (there exists x : ℝ, ~ (exists y : R, P2 x y)).
155155
Qed.
156156

157157
(* Test 17 *)
158158
Goal (exists x : R, ~ (exists y : R, P2 x y)) -> (exists x : R, forall y : R, ~ P2 x y).
159159
Proof.
160-
intro H.
160+
ltac2: intro H.
161161
We conclude that (exists x : R, forall y : R, ~ P2 x y).
162162
Qed.
163163

@@ -166,7 +166,7 @@ Qed.
166166
Local Parameter P3 : R -> R -> R -> Prop.
167167
Goal ~ (forall x : R, exists y : R, P2 x y) -> (exists x : R, ~ (exists y : R, P2 x y)).
168168
Proof.
169-
intro H.
169+
ltac2: intro H.
170170
We conclude that (there exists x : ℝ, ~ (exists y : R, P2 x y)).
171171
Qed.
172172

@@ -180,7 +180,7 @@ Goal ~ (forall eps : R, eps > 0 -> exists delta : R, delta > 0 -> forall x : R,
180180
(exists eps : R, eps > 0 /\ ~(exists delta : R, delta > 0 -> forall x : R,
181181
0 < Rdist x a < delta -> Rdist (f x) L < eps)).
182182
Proof.
183-
intro H.
183+
ltac2: intro H.
184184
We conclude that (there exists eps : ℝ , eps > 0
185185
∧ ¬ (there exists delta : ℝ, delta > 0 ⇨ for all x : ℝ,
186186
0 < Rdist x a < delta ⇨ Rdist (f x) L < eps)).
@@ -233,13 +233,13 @@ Abort.
233233
(** Testing de Morgan laws. *)
234234

235235
Require Import Waterproof.Libs.Negation.
236-
#[export] Hint Extern 1 => (solve_by_manipulating_negation (fun () => ())) : wp_negation_logic.
236+
#[export] Hint Extern 1 => ltac2: (solve_by_manipulating_negation (fun () => ())) : wp_negation_logic.
237237

238238
(** Level 1 *)
239239
(* Test 25 *)
240240
Goal ~ (∀ x ∈ R, P1 x) -> (∃ x ∈ R, ~ (P1 x)).
241241
Proof.
242-
intro H.
242+
ltac2: intro H.
243243
We conclude that (∃ x ∈ ℝ, ¬ P1 x).
244244
Qed.
245245

@@ -253,22 +253,22 @@ Abort.
253253
(* Test 27 *)
254254
Goal ~ (∀ x ∈ R, ∃ y ∈ R, P2 x y) -> (∃ x ∈ R, ~ (∃ y ∈ R, P2 x y)).
255255
Proof.
256-
intro H.
256+
ltac2: intro H.
257257
We conclude that (∃ x ∈ ℝ, ~ (∃ y ∈ R, P2 x y)).
258258
Qed.
259259

260260
(* Test 28 *)
261261
Goal (∃ x < 5, ~ (∃ y ≥ 7, P2 x y)) -> (∃ x < 5, ∀ y ≥ 7, ~ P2 x y).
262262
Proof.
263-
intro H.
263+
ltac2: intro H.
264264
We conclude that (∃ x < 5, ∀ y ≥ 7, ~ P2 x y).
265265
Qed.
266266

267267
(** Level 3 *)
268268
(* Test 29 *)
269269
Goal ~ (∀ x ≤ 30, ∃ y ∈ R, P2 x y) -> (∃ x ≤ 30, ~ (∃ y ∈ R, P2 x y)).
270270
Proof.
271-
intro H.
271+
ltac2: intro H.
272272
We conclude that (∃ x ≤ 30, ~ (∃ y ∈ R, P2 x y)).
273273
Qed.
274274

@@ -280,7 +280,7 @@ Goal ~ (∀ eps ∈ R, eps > 0 -> ∃ delta ∈ R, delta > 0 -> ∀ x ∈ R,
280280
(∃ eps ∈ R, eps > 0 /\ ~(∃ delta ∈ R, delta > 0 -> ∀ x ∈ R,
281281
0 < Rdist x a < delta -> Rdist (f x) L < eps)).
282282
Proof.
283-
intro H.
283+
ltac2: intro H.
284284
We conclude that (∃ eps ∈ R, eps > 0 /\ ~(∃ delta ∈ R, delta > 0 -> ∀ x ∈ R,
285285
0 < Rdist x a < delta -> Rdist (f x) L < eps)).
286286
Qed.

tests/automation/databases/Decidability.v

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,61 +21,61 @@ Require Import Waterproof.Automation.
2121

2222
Goal forall P : Prop, {P} + {~P}.
2323
Proof.
24-
auto with wp_decidability_epsilon.
24+
ltac2: auto with wp_decidability_epsilon.
2525
Qed.
2626

2727
Goal forall P Q : Prop, P \/ Q -> {P} + {Q}.
2828
Proof.
29-
auto with wp_decidability_epsilon.
29+
ltac2: auto with wp_decidability_epsilon.
3030
Qed.
3131

3232
Goal forall P : Prop, P \/ ~P.
3333
Proof.
34-
auto with wp_decidability_classical.
34+
ltac2: auto with wp_decidability_classical.
3535
Qed.
3636

3737
Goal forall P Q : Prop, {P} + {Q} -> P \/ Q.
38-
auto with wp_decidability_constructive.
38+
ltac2: auto with wp_decidability_constructive.
3939
Qed.
4040

4141
Goal forall P Q : Prop, {Q} + {P} -> Q \/ P.
42-
auto with wp_decidability_constructive.
42+
ltac2: auto with wp_decidability_constructive.
4343
Qed.
4444

4545
Goal forall P Q R: Prop, {P} + {Q} + {R} -> P \/ Q \/ R.
46-
auto with wp_decidability_constructive.
46+
ltac2: auto with wp_decidability_constructive.
4747
Qed.
4848

4949
Goal forall P Q R: Prop, {P} + {R} + {Q} -> P \/ Q \/ R.
50-
auto with wp_decidability_constructive.
50+
ltac2: auto with wp_decidability_constructive.
5151
Qed.
5252

5353
Goal forall P Q R: Prop, {Q} + {P} + {R} -> P \/ Q \/ R.
54-
auto with wp_decidability_constructive.
54+
ltac2: auto with wp_decidability_constructive.
5555
Qed.
5656

5757
Goal forall P Q R: Prop, {Q} + {R} + {P} -> P \/ Q \/ R.
58-
auto with wp_decidability_constructive.
58+
ltac2: auto with wp_decidability_constructive.
5959
Qed.
6060

6161
Goal forall P Q R: Prop, {R} + {P} + {Q} -> P \/ Q \/ R.
62-
auto with wp_decidability_constructive.
62+
ltac2: auto with wp_decidability_constructive.
6363
Qed.
6464

6565
Goal forall P Q R: Prop, {R} + {P} + {Q} -> P \/ Q \/ R.
66-
auto with wp_decidability_constructive.
66+
ltac2: auto with wp_decidability_constructive.
6767
Qed.
6868

6969
Goal forall n : nat, n < 5 \/ n > 4.
7070
Proof.
71-
intro n.
72-
auto with wp_decidability_nat.
71+
ltac2: intro n.
72+
ltac2: auto with wp_decidability_nat.
7373
Qed.
7474

7575
From Stdlib Require Import Reals.Reals.
7676
Open Scope R_scope.
7777
Goal forall x : R, x < 5 \/ x > 4.
7878
Proof.
79-
intro x.
80-
auto with wp_decidability_reals.
79+
ltac2: intro x.
80+
ltac2: auto with wp_decidability_reals.
8181
Qed.

tests/automation/databases/Integers.v

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,28 @@ From Stdlib Require Import Lia.
3030

3131
Goal ∀ n : ℕ -> ℕ, (∀ k : ℕ, (n (k + 1) > n k)%nat) ⇒
3232
∀ k : ℕ, (n k ≥ k)%nat.
33-
intro n.
34-
intro H.
35-
induction k as [| k IHk].
36-
- solve [auto with wp_integers zarith].
37-
- assert (H1 : S k = k + 1) by (auto with wp_integers zarith).
38-
rewrite H1.
39-
assert (H2 : n (k + 1) > n k) by (auto with wp_integers zarith).
40-
auto with wp_integers zarith.
33+
ltac2: intro n.
34+
ltac2: intro H.
35+
ltac2: induction k as [| k IHk].
36+
- ltac2: solve [auto with wp_integers zarith].
37+
- ltac2: assert (H1 : S k = k + 1) by (auto with wp_integers zarith).
38+
ltac2: rewrite H1.
39+
ltac2: assert (H2 : n (k + 1) > n k) by (auto with wp_integers zarith).
40+
ltac2: auto with wp_integers zarith.
4141
Qed.
4242

4343
Goal (& 3 < 4 <= 5).
44-
cbn; repeat split; solve [ltac1:(auto with wp_core wp_integers)].
44+
ltac2: (cbn; repeat split; solve [ltac1:(auto with wp_core wp_integers)]).
4545
Qed.
4646

4747
Goal (& 3 = 3 = 3).
48-
cbn; repeat split; solve [auto with wp_core wp_integers].
48+
ltac2: (cbn; repeat split; solve [auto with wp_core wp_integers]).
4949
Qed.
5050

5151
(* Test 1: check if terms of a subset can be coerced to terms of the underlying set (here: [R]). *)
5252
Goal forall x : nat, (& x < 5 = 2 + 3) -> (x < 5).
53-
intro x.
54-
intro H.
55-
simpl_ineq_chains ().
56-
solve [auto with wp_integers zarith].
53+
ltac2: intro x.
54+
ltac2: intro H.
55+
ltac2: simpl_ineq_chains ().
56+
ltac2: solve [auto with wp_integers zarith].
5757
Qed.

tests/automation/databases/RealsAndIntegers.v

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,47 +30,47 @@ Open Scope R_scope.
3030

3131
Goal forall x y: R, forall f: R -> R, x = y -> f (x + 1) = f (y + 1).
3232
Proof.
33-
waterprove 5 false Main.
33+
ltac2: waterprove 5 false Main.
3434
Qed.
3535

3636
Goal forall x y: R, forall f: R -> R, x = y -> f x = f y /\ x = y.
3737
Proof.
38-
waterprove 5 false Main.
38+
ltac2: waterprove 5 false Main.
3939
Qed.
4040

4141
Goal (& 3 < 4 <= 5).
42-
cbn; repeat split; auto with wp_core wp_reals.
42+
ltac2: (cbn; repeat split; auto with wp_core wp_reals).
4343
Qed.
4444

4545
Goal (& 3 = 3 = 3).
46-
cbn; repeat split; auto with wp_core wp_reals.
46+
ltac2: (cbn; repeat split; auto with wp_core wp_reals).
4747
Qed.
4848

4949
Goal forall x : R, (& x < 5 = 2 + 3) -> (x < 5).
50-
intro x.
51-
intro H.
52-
auto with wp_core wp_reals.
50+
ltac2: intro x.
51+
ltac2: intro H.
52+
ltac2: auto with wp_core wp_reals.
5353
Qed.
5454

5555
(** ** Testcases to deal with Rabs Rmin Rmax *)
5656

5757
Goal forall b: R, b > 0 -> - Rmax( 0, 1 - b/2) >= - 1.
58-
auto with wp_reals.
58+
ltac2: auto with wp_reals.
5959
Qed.
6060

6161
Goal forall b: R, b > 0 -> Rmin( 0, -1 + b/2) <= 1.
62-
auto with wp_reals.
62+
ltac2: auto with wp_reals.
6363
Qed.
6464

6565
Goal forall r : R, r > 0 ->
6666
| Rmax 0 (1 - r/2) - 1 | = 1 - (Rmax 0 (1 - r/2)).
67-
auto with wp_reals.
67+
ltac2: auto with wp_reals.
6868
Qed.
6969

7070
Goal forall x r : R, r > 0 ->
7171
x = Rmax 0 (1 - r/2) -> Rabs (x - 1) < r.
72-
intros x r r_gt_0 x_eq_Rmax.
73-
auto with wp_reals.
72+
ltac2: intros x r r_gt_0 x_eq_Rmax.
73+
ltac2: auto with wp_reals.
7474
Qed.
7575

7676
Close Scope R_scope.

0 commit comments

Comments
 (0)