aboutsummaryrefslogtreecommitdiffstats
path: root/src/Tactics.v
blob: d6c772c5748e27bbfb60d45990de42ea7fd41765 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
(**************************************************************************)
(*                                                                        *)
(*     SMTCoq                                                             *)
(*     Copyright (C) 2011 - 2022                                          *)
(*                                                                        *)
(*     See file "AUTHORS" for the list of authors                         *)
(*                                                                        *)
(*   This file is distributed under the terms of the CeCILL-C licence     *)
(*                                                                        *)
(**************************************************************************)


Require Import PropToBool.
Require Import Int63 List PArray Bool ZArith.
Require Import SMTCoq.State SMTCoq.SMT_terms SMTCoq.Trace SMT_classes_instances QInst.

Declare ML Module "smtcoq_plugin".


(** Collect all the hypotheses from the context *)

Ltac get_hyps_acc acc :=
  match goal with
  | [ H : ?P |- _ ] =>
    let T := type of P in
    lazymatch T with
    | Prop =>
      lazymatch P with
      | id _ => fail
      | _ =>
        let _ := match goal with _ => change P with (id P) in H end in
        lazymatch acc with
        | Some ?t => get_hyps_acc (Some (H, t))
        | None => get_hyps_acc (Some H)
        end
      end
    | _ => fail
    end
  | _ => acc
  end.

Ltac eliminate_id :=
  repeat match goal with
  | [ H : ?P |- _ ] =>
    lazymatch P with
    | id ?Q => change P with Q in H
    | _ => fail
    end
  end.

Ltac get_hyps :=
  let Hs := get_hyps_acc (@None nat) in
  let _ := match goal with _ => eliminate_id end in
  Hs.


(* Section Test. *)
(*   Variable A : Type. *)
(*   Hypothesis H1 : forall a:A, a = a. *)
(*   Variable n : Z. *)
(*   Hypothesis H2 : n = 17%Z. *)

(*   Goal True. *)
(*   Proof. *)
(*     let Hs := get_hyps in idtac Hs. *)
(*   Abort. *)
(* End Test. *)


(** Tactics in bool *)

Tactic Notation "verit_bool_base_auto" constr(h) := verit_bool_base h; try (exact _).
Tactic Notation "verit_bool_no_check_base_auto" constr(h) := verit_bool_no_check_base h; try (exact _).

Tactic Notation "verit_bool" constr(h) :=
  let Hs := get_hyps in
  match Hs with
  | Some ?Hs => verit_bool_base_auto (Some (h, Hs))
  | None => verit_bool_base_auto (Some h)
  end;
  vauto.
Tactic Notation "verit_bool"           :=
  let Hs := get_hyps in
  verit_bool_base_auto Hs; vauto.

Tactic Notation "verit_bool_no_check" constr(h) :=
  let Hs := get_hyps in
  match Hs with
  | Some ?Hs => verit_bool_no_check_base_auto (Some (h, Hs))
  | None => verit_bool_no_check_base_auto (Some h)
  end;
  vauto.
Tactic Notation "verit_bool_no_check"           :=
  let Hs := get_hyps in
  fun Hs => verit_bool_no_check_base_auto Hs; vauto.


(** Tactics in bool with timeout **)

Tactic Notation "verit_bool_base_auto_timeout" constr(h) int_or_var(timeout) := verit_bool_base_timeout h timeout; auto with typeclass_instances.
Tactic Notation "verit_bool_no_check_base_auto_timeout" constr(h) int_or_var(timeout) := verit_bool_no_check_base_timeout h timeout; auto with typeclass_instances.

Tactic Notation "verit_bool_timeout" constr(h) int_or_var(timeout) :=
  let Hs := get_hyps in
  match Hs with
  | Some ?Hs => verit_bool_base_auto_timeout (Some (h, Hs)) timeout
  | None => verit_bool_base_auto_timeout (Some h) timeout
  end;
  vauto.
Tactic Notation "verit_bool_timeout"  int_or_var(timeout)         :=
  let Hs := get_hyps in
  verit_bool_base_auto_timeout Hs timeout; vauto.

Tactic Notation "verit_bool_no_check_timeout" constr(h) int_or_var (timeout) :=
  let Hs := get_hyps in
  match Hs with
  | Some ?Hs => verit_bool_no_check_base_auto_timeout (Some (h, Hs)) timeout
  | None => verit_bool_no_check_base_auto_timeout (Some h) timeout
  end;
  vauto.
Tactic Notation "verit_bool_no_check_timeout"   int_or_var(timeout)        :=
  let Hs := get_hyps in
  verit_bool_no_check_base_auto_timeout Hs timeout; vauto.


(** Tactics in Prop **)

Ltac zchaff          := add_compdecs; [ .. | prop2bool; zchaff_bool; bool2prop ].
Ltac zchaff_no_check := add_compdecs; [ .. | prop2bool; zchaff_bool_no_check; bool2prop].

Tactic Notation "verit" constr(h) :=
  intros;
  let Hs := get_hyps in
  let Hs :=
    lazymatch Hs with
    | Some ?Hs => constr:(Some (h, Hs))
    | None => constr:(Some h)
    end
  in
  add_compdecs Hs;
  [ .. | prop2bool;
         lazymatch Hs with
         | Some ?Hs => prop2bool_hyps Hs
         | None => idtac
         end;
         [ .. | verit_bool_base_auto Hs; vauto ]
  ].
Tactic Notation "verit"           :=
  intros;
  let Hs := get_hyps in
  add_compdecs Hs;
  [ .. | prop2bool;
         lazymatch Hs with
         | Some ?Hs => prop2bool_hyps Hs
         | None => idtac
         end;
         [ .. | verit_bool_base_auto Hs; vauto ]
  ].
Tactic Notation "verit_no_check" constr(h) :=
  intros;
  let Hs := get_hyps in
  let Hs :=
    lazymatch Hs with
    | Some ?Hs => constr:(Some (h, Hs))
    | None => constr:(Some h)
    end
  in
  add_compdecs Hs;
  [ .. | prop2bool;
         lazymatch Hs with
         | Some ?Hs => prop2bool_hyps Hs
         | None => idtac
         end;
         [ .. | verit_bool_no_check_base_auto Hs; vauto ]
  ].
Tactic Notation "verit_no_check"           :=
  intros;
  let Hs := get_hyps in
  add_compdecs Hs;
  [ .. | prop2bool;
         lazymatch Hs with
         | Some ?Hs => prop2bool_hyps Hs
         | None => idtac
         end;
         [ .. | verit_bool_no_check_base_auto Hs; vauto ]
  ].

Tactic Notation "verit_timeout" constr(h) int_or_var(timeout) :=
  intros;
  let Hs := get_hyps in
  let Hs :=
    lazymatch Hs with
    | Some ?Hs => constr:(Some (h, Hs))
    | None => constr:(Some h)
    end
  in
  add_compdecs Hs;
  [ .. | prop2bool;
         lazymatch Hs with
         | Some ?Hs => prop2bool_hyps Hs
         | None => idtac
         end;
         [ .. | verit_bool_base_auto_timeout Hs timeout; vauto ]
  ].
Tactic Notation "verit_timeout"           int_or_var(timeout) :=
  intros;
  let Hs := get_hyps in
  add_compdecs Hs;
  [ .. | prop2bool;
         lazymatch Hs with
         | Some ?Hs => prop2bool_hyps Hs
         | None => idtac
         end;
         [ .. | verit_bool_base_auto_timeout Hs timeout; vauto ]
  ].
Tactic Notation "verit_no_check_timeout" constr(h) int_or_var(timeout) :=
  intros;
  let Hs := get_hyps in
  let Hs :=
    lazymatch Hs with
    | Some ?Hs => constr:(Some (h, Hs))
    | None => constr:(Some h)
    end
  in
  add_compdecs Hs;
  [ .. | prop2bool;
         lazymatch Hs with
         | Some ?Hs => prop2bool_hyps Hs
         | None => idtac
         end;
         [ .. | verit_bool_no_check_base_auto_timeout Hs timeout; vauto ]
  ].
Tactic Notation "verit_no_check_timeout"           int_or_var(timeout) :=
  intros;
  let Hs := get_hyps in
  add_compdecs Hs;
  [ .. | prop2bool;
         lazymatch Hs with
         | Some ?Hs => prop2bool_hyps Hs
         | None => idtac
         end;
         [ .. | verit_bool_no_check_base_auto_timeout Hs timeout; vauto ]
  ].

Ltac cvc4            := add_compdecs; [ .. | prop2bool; cvc4_bool; bool2prop ].
Ltac cvc4_no_check   := add_compdecs; [ .. | prop2bool; cvc4_bool_no_check; bool2prop ].

Tactic Notation "smt" constr(h) :=
  add_compdecs; [ .. | prop2bool; try verit h; cvc4_bool; try verit h; bool2prop ].
Tactic Notation "smt"           :=
  add_compdecs; [ .. | prop2bool; try verit  ; cvc4_bool; try verit  ; bool2prop ].
Tactic Notation "smt_no_check" constr(h) :=
  add_compdecs; [ .. | prop2bool; try verit_no_check h; cvc4_bool_no_check; try verit_no_check h; bool2prop].
Tactic Notation "smt_no_check"           :=
  add_compdecs; [ .. | prop2bool; try verit_no_check  ; cvc4_bool_no_check; try verit_no_check  ; bool2prop].


(* 
   Local Variables:
   coq-load-path: ((rec "." "SMTCoq"))
   End: 
*)