Debian Codegraph @

theories/Ltac2/Std.v

raw
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 Require Import Ltac2.Init.
12
13 (** ML-facing types *)
14
15 Ltac2 Type hypothesis := [ AnonHyp (int) | NamedHyp (ident) ].
16
17 Ltac2 Type bindings := [
18 | NoBindings
19 | ImplicitBindings (constr list)
20 | ExplicitBindings ((hypothesis * constr) list)
21 ].
22
23 Ltac2 Type constr_with_bindings := constr * bindings.
24
25 Ltac2 Type occurrences := [
26 | AllOccurrences
27 | AllOccurrencesBut (int list)
28 | NoOccurrences
29 | OnlyOccurrences (int list)
30 ].
31
32 Ltac2 Type hyp_location_flag := [ InHyp | InHypTypeOnly | InHypValueOnly ].
33
34 Ltac2 Type clause := {
35 on_hyps : (ident * occurrences * hyp_location_flag) list option;
36 on_concl : occurrences;
37 }.
38
39 Ltac2 Type reference := [
40 | VarRef (ident)
41 | ConstRef (constant)
42 | IndRef (inductive)
43 | ConstructRef (constructor)
44 ].
45
46 Ltac2 Type strength := [ Norm | Head ].
47
48 Ltac2 Type red_flags := {
49 rStrength : strength;
50 rBeta : bool;
51 rMatch : bool;
52 rFix : bool;
53 rCofix : bool;
54 rZeta : bool;
55 rDelta : bool; (** true = delta all but rConst; false = delta only on rConst*)
56 rConst : reference list
57 }.
58
59 Ltac2 Type 'a not_implemented.
60
61 Ltac2 Type rec intro_pattern := [
62 | IntroForthcoming (bool)
63 | IntroNaming (intro_pattern_naming)
64 | IntroAction (intro_pattern_action)
65 ]
66 with intro_pattern_naming := [
67 | IntroIdentifier (ident)
68 | IntroFresh (ident)
69 | IntroAnonymous
70 ]
71 with intro_pattern_action := [
72 | IntroWildcard
73 | IntroOrAndPattern (or_and_intro_pattern)
74 | IntroInjection (intro_pattern list)
75 | IntroApplyOn ((unit -> constr), intro_pattern)
76 | IntroRewrite (bool)
77 ]
78 with or_and_intro_pattern := [
79 | IntroOrPattern (intro_pattern list list)
80 | IntroAndPattern (intro_pattern list)
81 ].
82
83 Ltac2 Type destruction_arg := [
84 | ElimOnConstr (unit -> constr_with_bindings)
85 | ElimOnIdent (ident)
86 | ElimOnAnonHyp (int)
87 ].
88
89 Ltac2 Type induction_clause := {
90 indcl_arg : destruction_arg;
91 indcl_eqn : intro_pattern_naming option;
92 indcl_as : or_and_intro_pattern option;
93 indcl_in : clause option;
94 }.
95
96 Ltac2 Type assertion := [
97 | AssertType (intro_pattern option, constr, (unit -> unit) option)
98 | AssertValue (ident, constr)
99 ].
100
101 Ltac2 Type repeat := [
102 | Precisely (int)
103 | UpTo (int)
104 | RepeatStar
105 | RepeatPlus
106 ].
107
108 Ltac2 Type orientation := [ LTR | RTL ].
109
110 Ltac2 Type rewriting := {
111 rew_orient : orientation option;
112 rew_repeat : repeat;
113 rew_equatn : (unit -> constr_with_bindings);
114 }.
115
116 Ltac2 Type evar_flag := bool.
117 Ltac2 Type advanced_flag := bool.
118
119 Ltac2 Type move_location := [
120 | MoveAfter (ident)
121 | MoveBefore (ident)
122 | MoveFirst
123 | MoveLast
124 ].
125
126 Ltac2 Type inversion_kind := [
127 | SimpleInversion
128 | FullInversion
129 | FullInversionClear
130 ].
131
132 (** Standard, built-in tactics. See Ltac1 for documentation. *)
133
134 Ltac2 @ external intros : evar_flag -> intro_pattern list -> unit := "rocq-runtime.plugins.ltac2" "tac_intros".
135
136 Ltac2 @ external apply : advanced_flag -> evar_flag ->
137 (unit -> constr_with_bindings) list -> (ident * (intro_pattern option)) option -> unit := "rocq-runtime.plugins.ltac2" "tac_apply".
138
139 Ltac2 @ external elim : evar_flag -> constr_with_bindings -> constr_with_bindings option -> unit := "rocq-runtime.plugins.ltac2" "tac_elim".
140 Ltac2 @ external case : evar_flag -> constr_with_bindings -> unit := "rocq-runtime.plugins.ltac2" "tac_case".
141
142 Ltac2 @ external generalize : (constr * occurrences * ident option) list -> unit := "rocq-runtime.plugins.ltac2" "tac_generalize".
143
144 Ltac2 @ external assert : assertion -> unit := "rocq-runtime.plugins.ltac2" "tac_assert".
145 Ltac2 @ external enough : constr -> (unit -> unit) option option -> intro_pattern option -> unit := "rocq-runtime.plugins.ltac2" "tac_enough".
146
147 Ltac2 @ external pose : ident option -> constr -> unit := "rocq-runtime.plugins.ltac2" "tac_pose".
148 Ltac2 @ external set : evar_flag -> (unit -> ident option * constr) -> clause -> unit := "rocq-runtime.plugins.ltac2" "tac_set".
149
150 Ltac2 @ external remember : evar_flag -> ident option -> (unit -> constr) -> intro_pattern option -> clause -> unit := "rocq-runtime.plugins.ltac2" "tac_remember".
151
152 Ltac2 @ external destruct : evar_flag -> induction_clause list ->
153 constr_with_bindings option -> unit := "rocq-runtime.plugins.ltac2" "tac_destruct".
154
155 Ltac2 @ external induction : evar_flag -> induction_clause list ->
156 constr_with_bindings option -> unit := "rocq-runtime.plugins.ltac2" "tac_induction".
157
158 Ltac2 @external exfalso : unit -> unit := "rocq-runtime.plugins.ltac2" "tac_exfalso".
159
160
161 (** Constructors for reduction/expansion strategies *)
162
163 Module Red.
164 Ltac2 Type t.
165
166 (** βιζ-reduction of the _head constant_ of a term. Fails if there is no
167 reducible head constant. *)
168 Ltac2 @external red : t := "rocq-runtime.plugins.ltac2" "red".
169
170 (** Full βδιζ-reduction the head of a term. Does not recurse into subterms. *)
171 Ltac2 @external hnf : t := "rocq-runtime.plugins.ltac2" "hnf".
172
173 (** Strong normalization except two key differences:
174
175 - It unfolds constants only if they lead to an ι-reduction, i.e. reducing a
176 match or unfolding a fixpoint.
177
178 - When reducing a constant unfolding to (co)fixpoints, uses the name of the
179 constant the (co)fixpoint comes from instead of the (co)fixpoint definition
180 in recursive calls.
181
182 Can unfold transparent constants as well as those designated by [Arguments]
183 commands. The second parameter can limit the application of [simpl] to
184 specific subterms matching. If the pattern resolves into a global reference,
185 it will be treated as such.
186
187 Only the following [red_flags] are relevant: [head], [delta]. *)
188 Ltac2 @external simpl : red_flags -> (pattern * occurrences) option -> t := "rocq-runtime.plugins.ltac2" "simpl".
189
190 (** Full normalization using provided reduction flags by first evaluating the
191 head of the expression into weak-head normal form in _call-by-value_ order.
192 Once a weak-head normal form is obtained, subterms are recursively reduced
193 using the same strategy. *)
194 Ltac2 @external cbv : red_flags -> t := "rocq-runtime.plugins.ltac2" "cbv".
195
196 (** [cbn] was intended to be a more principled, faster and more predictable
197 replacement for [simpl]. The main difference is that cbn may unfold constants
198 even when they cannot be reused in recursive calls. Certain modifiers are also
199 not treated the same. See the respective Ltac1 tactic documentation for more
200 details. Setting [Debug "RAKAM"] makes [cbn] print various debugging
201 information.. *)
202 Ltac2 @external cbn : red_flags -> t := "rocq-runtime.plugins.ltac2" "cbn".
203
204 (** Full normalization using provided reduction flags by first evaluating the
205 head of the expression into weak-head normal form in _call-by-need_ order.
206 Once a weak-head normal form is obtained, subterms are recursively reduced
207 using the same strategy. *)
208 Ltac2 @external lazy : red_flags -> t := "rocq-runtime.plugins.ltac2" "lazy".
209
210 (** Applies delta-reduction to the constants specified by each [reference *
211 occurrences] and then reduces to βιζ-normal form. Use the general reductions
212 if you want to only apply the δ rule, for example [cbv] with [delta]. *)
213 Ltac2 @external unfold : (reference * occurrences) list -> t := "rocq-runtime.plugins.ltac2" "unfold".
214
215 (** First, reduces each [constr] using [red]. Then, every occurrence of the
216 resulting terms will be replaced by its associated [constr]. *)
217 Ltac2 @external fold : constr list -> t := "rocq-runtime.plugins.ltac2" "fold".
218
219 (** Performs beta-expansion (the inverse of beta-reduction). The [constr]s
220 must be free subterms in the subject of reduction. The expansion is done by:
221
222 1. Replacing all selected occurrences of the [constr]s in the term with fresh
223 variables
224
225 2. Abstracting these variables
226
227 3. Applying the abstracted term to the [constr]s *)
228 Ltac2 @external pattern : (constr * occurrences) list -> t := "rocq-runtime.plugins.ltac2" "pattern".
229
230 (** Optimized _call-by-value_ evaluation on a bytecode-based virtual machine.
231 This algorithm is dramatically more efficient than the algorithm used for
232 [cbv], but it cannot be fine-tuned. It is especially useful for full
233 evaluation of algebraic objects. This includes the case of reflection-based
234 tactics. *)
235 Ltac2 @external vm : (pattern * occurrences) option -> t := "rocq-runtime.plugins.ltac2" "vm".
236
237 (** Evaluates the goal by compilation to OCaml. Depending on the
238 configuration, it can either default to [vm], recompile dependencies or fail
239 due to some missing precompiled dependencies. See the [native-compiler] option
240 for details. *)
241 Ltac2 @external native : (pattern * occurrences) option -> t := "rocq-runtime.plugins.ltac2" "native".
242 End Red.
243
244 (** Reduction/expansion tactics *)
245
246 Ltac2 @external eval_in : Red.t -> clause -> unit := "rocq-runtime.plugins.ltac2" "reduce_in".
247
248 Ltac2 red (c : clause) : unit := eval_in Red.red c.
249
250 Ltac2 hnf (c : clause) : unit := eval_in Red.hnf c.
251
252 Ltac2 simpl (flags : red_flags) (occs : (pattern * occurrences) option) (c : clause) := eval_in (Red.simpl flags occs) c.
253
254 Ltac2 cbv (flags : red_flags) (c : clause) : unit := eval_in (Red.cbv flags) c.
255
256 Ltac2 cbn (flags : red_flags) (c : clause) : unit := eval_in (Red.cbn flags) c.
257
258 Ltac2 lazy (flags : red_flags) (c : clause) : unit := eval_in (Red.lazy flags) c.
259
260 Ltac2 unfold (occs : (reference * occurrences) list) (c : clause) : unit := eval_in (Red.unfold occs) c.
261
262 Ltac2 fold (cs : constr list) (c : clause) : unit := eval_in (Red.fold cs) c.
263
264 Ltac2 pattern (occs : (constr * occurrences) list) (c : clause) : unit := eval_in (Red.pattern occs) c.
265
266 Ltac2 vm (ctx : (pattern * occurrences) option) (c : clause) : unit := eval_in (Red.vm ctx) c.
267
268 Ltac2 native (ctx : (pattern * occurrences) option) (c : clause) : unit := eval_in (Red.native ctx) c.
269
270 (** Constr reduction/expansion functions *)
271
272 Ltac2 @external eval : Red.t -> constr -> constr := "rocq-runtime.plugins.ltac2" "reduce_constr".
273
274 Ltac2 eval_red (c : constr) : constr := eval Red.red c.
275
276 Ltac2 eval_hnf (c : constr) : constr := eval Red.hnf c.
277
278 Ltac2 eval_simpl (flags : red_flags) (occs : (pattern * occurrences) option) (c : constr) := eval (Red.simpl flags occs) c.
279
280 Ltac2 eval_cbv (flags : red_flags) (c : constr) : constr := eval (Red.cbv flags) c.
281
282 Ltac2 eval_cbn (flags : red_flags) (c : constr) : constr := eval (Red.cbn flags) c.
283
284 Ltac2 eval_lazy (flags : red_flags) (c : constr) : constr := eval (Red.lazy flags) c.
285
286 Ltac2 eval_unfold (occs : (reference * occurrences) list) (c : constr) : constr := eval (Red.unfold occs) c.
287
288 Ltac2 eval_fold (cs : constr list) (c : constr) : constr := eval (Red.fold cs) c.
289
290 Ltac2 eval_pattern (occs : (constr * occurrences) list) (c : constr) : constr := eval (Red.pattern occs) c.
291
292 Ltac2 eval_vm (ctx : (pattern * occurrences) option) (c : constr) : constr := eval (Red.vm ctx) c.
293
294 Ltac2 eval_native (ctx : (pattern * occurrences) option) (c : constr) : constr := eval (Red.native ctx) c.
295
296
297 Ltac2 @ external change : pattern option -> (constr array -> constr) -> clause -> unit := "rocq-runtime.plugins.ltac2" "tac_change".
298
299 Ltac2 @ external rewrite : evar_flag -> rewriting list -> clause -> (unit -> unit) option -> unit := "rocq-runtime.plugins.ltac2" "tac_rewrite".
300
301 Ltac2 @ external setoid_rewrite : orientation -> (unit -> constr_with_bindings) -> occurrences -> ident option -> unit := "rocq-runtime.plugins.ltac2" "tac_setoid_rewrite".
302
303 Ltac2 @ external reflexivity : unit -> unit := "rocq-runtime.plugins.ltac2" "tac_reflexivity".
304
305 Ltac2 @ external assumption : unit -> unit := "rocq-runtime.plugins.ltac2" "tac_assumption".
306 Ltac2 @ external eassumption : unit -> unit := "rocq-runtime.plugins.ltac2" "tac_eassumption".
307
308 Ltac2 @ external transitivity : constr -> unit := "rocq-runtime.plugins.ltac2" "tac_transitivity".
309
310 Ltac2 @ external etransitivity : unit -> unit := "rocq-runtime.plugins.ltac2" "tac_etransitivity".
311
312 Ltac2 @ external cut : constr -> unit := "rocq-runtime.plugins.ltac2" "tac_cut".
313
314 Ltac2 @ external left : evar_flag -> bindings -> unit := "rocq-runtime.plugins.ltac2" "tac_left".
315 Ltac2 @ external right : evar_flag -> bindings -> unit := "rocq-runtime.plugins.ltac2" "tac_right".
316
317 Ltac2 @ external constructor : evar_flag -> unit := "rocq-runtime.plugins.ltac2" "tac_constructor".
318 Ltac2 @ external split : evar_flag -> bindings -> unit := "rocq-runtime.plugins.ltac2" "tac_split".
319
320 Ltac2 @ external constructor_n : evar_flag -> int -> bindings -> unit := "rocq-runtime.plugins.ltac2" "tac_constructorn".
321
322 Ltac2 @ external intros_until : hypothesis -> unit := "rocq-runtime.plugins.ltac2" "tac_introsuntil".
323
324 Ltac2 @ external symmetry : clause -> unit := "rocq-runtime.plugins.ltac2" "tac_symmetry".
325
326 Ltac2 @ external rename : (ident * ident) list -> unit := "rocq-runtime.plugins.ltac2" "tac_rename".
327
328 Ltac2 @ external revert : ident list -> unit := "rocq-runtime.plugins.ltac2" "tac_revert".
329
330 Ltac2 @ external admit : unit -> unit := "rocq-runtime.plugins.ltac2" "tac_admit".
331
332 Ltac2 @ external fix_ : ident -> int -> unit := "rocq-runtime.plugins.ltac2" "tac_fix".
333 Ltac2 @ external cofix_ : ident -> unit := "rocq-runtime.plugins.ltac2" "tac_cofix".
334
335 Ltac2 @ external clear : ident list -> unit := "rocq-runtime.plugins.ltac2" "tac_clear".
336 Ltac2 @ external keep : ident list -> unit := "rocq-runtime.plugins.ltac2" "tac_keep".
337
338 Ltac2 @ external clearbody : ident list -> unit := "rocq-runtime.plugins.ltac2" "tac_clearbody".
339
340 Ltac2 @ external exact_no_check : constr -> unit := "rocq-runtime.plugins.ltac2" "tac_exactnocheck".
341 Ltac2 @ external vm_cast_no_check : constr -> unit := "rocq-runtime.plugins.ltac2" "tac_vmcastnocheck".
342 Ltac2 @ external native_cast_no_check : constr -> unit := "rocq-runtime.plugins.ltac2" "tac_nativecastnocheck".
343
344 Ltac2 @ external inversion : inversion_kind -> destruction_arg -> intro_pattern option -> ident list option -> unit := "rocq-runtime.plugins.ltac2" "tac_inversion".
345
346 (** coretactics *)
347
348 Ltac2 @ external move : ident -> move_location -> unit := "rocq-runtime.plugins.ltac2" "tac_move".
349
350 Ltac2 @ external intro : ident option -> move_location option -> unit := "rocq-runtime.plugins.ltac2" "tac_intro".
351
352 Ltac2 @ external specialize : constr_with_bindings -> intro_pattern option -> unit := "rocq-runtime.plugins.ltac2" "tac_specialize".
353
354 (** extratactics *)
355
356 Ltac2 @ external discriminate : evar_flag -> destruction_arg option -> unit := "rocq-runtime.plugins.ltac2" "tac_discriminate".
357 Ltac2 @ external injection : evar_flag -> intro_pattern list option -> destruction_arg option -> unit := "rocq-runtime.plugins.ltac2" "tac_injection".
358
359 Ltac2 @ external absurd : constr -> unit := "rocq-runtime.plugins.ltac2" "tac_absurd".
360 Ltac2 @ external contradiction : constr_with_bindings option -> unit := "rocq-runtime.plugins.ltac2" "tac_contradiction".
361
362 Ltac2 @ external autorewrite : bool -> (unit -> unit) option -> ident list -> clause -> unit := "rocq-runtime.plugins.ltac2" "tac_autorewrite".
363
364 Ltac2 @ external subst : ident list -> unit := "rocq-runtime.plugins.ltac2" "tac_subst".
365 Ltac2 @ external subst_all : unit -> unit := "rocq-runtime.plugins.ltac2" "tac_substall".
366
367 (** auto *)
368
369 Ltac2 Type debug := [ Off | Info | Debug ].
370
371 Ltac2 Type strategy := [ BFS | DFS ].
372
373 Ltac2 @ external trivial : debug -> reference list -> ident list option -> unit := "rocq-runtime.plugins.ltac2" "tac_trivial".
374
375 Ltac2 @ external auto : debug -> int option -> reference list -> ident list option -> unit := "rocq-runtime.plugins.ltac2" "tac_auto".
376
377 Ltac2 @ external eauto : debug -> int option -> reference list -> ident list option -> unit := "rocq-runtime.plugins.ltac2" "tac_eauto".
378
379 Ltac2 @ external typeclasses_eauto : strategy option -> int option -> ident list option -> unit := "rocq-runtime.plugins.ltac2" "tac_typeclasses_eauto".
380
381 Ltac2 @ external resolve_tc : constr -> unit := "rocq-runtime.plugins.ltac2" "tac_resolve_tc".
382 (** Resolve the existential variables appearing in the constr
383 whose types are typeclasses.
384 Fail if any of them cannot be resolved.
385 Does not focus. *)
386
387 Ltac2 @ external unify : constr -> constr -> unit := "rocq-runtime.plugins.ltac2" "tac_unify".
388
389 Ltac2 @ external congruence : int option -> constr list option -> unit :=
390 "rocq-runtime.plugins.ltac2" "congruence".
391
392 Ltac2 @ external simple_congruence : int option -> constr list option -> unit :=
393 "rocq-runtime.plugins.ltac2" "simple_congruence".
394
395 Ltac2 @external f_equal : unit -> unit :=
396 "rocq-runtime.plugins.ltac2" "f_equal".