Debian Codegraph @

builtin-doc/coq-builtin.elpi

raw
1
2
3 % Coq terms as the object language of elpi and basic API to access Coq
4 % license: GNU Lesser General Public License Version 2.1 or later
5 % -------------------------------------------------------------------------
6
7 % This file is automatically generated from
8 % - coq-HOAS.elpi
9 % - rocq_elpi_builtin.ml
10 % and contains the description of the data type of Coq terms and the
11 % API to access Coq.
12
13
14
15
16 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17 %%%%%%%%%%%%%%%%%%%%%%%%%%%% coq-arg-HOAS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19
20 % This section contains the low level data types linking Coq and elpi.
21 % In particular the entry points for commands
22
23
24 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25 % Entry points
26 %
27 % Command and tactic invocation
28 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29
30 % Entry point for commands. Eg. "#[att=true] Elpi mycommand foo 3 (f x)." becomes
31 % main [str "foo", int 3, trm (app[f,x])]
32 % in a context where
33 % attributes [attribute "att" (leaf "true")]
34 % holds. The encoding of terms is described below.
35 % See also the coq.parse-attributes utility.
36 external pred main i:list argument.
37
38 % Commands with a non-trivial parsing phase can thread data between
39 % from the parsing phase to the interp one in an untyped way using the
40 % following two entrypoints
41 external pred main-interp i:list argument, i:any.
42 external pred main-synterp i:list argument, o:any.
43
44 % Commands starting/closing proofs have to use the following entrypoints.
45 % The minimal working snippet is:
46 %
47 % main-interp-proof [trm P] _ P GL _ :-
48 % coq.typecheck P _ ok, coq.ltac.collect-goals P GL _.
49 % main-interp-qed _ _ P _GL _ :-
50 % coq.env.add-const "it" P _ _ _.
51 %
52 % Where GL are the goals to prove, and _GL (unused here) are the same goals
53 % with their current proof. The term P can be used as the root proof term,
54 % where GL are missing pieces. One is not obliged to use P as is, i.e. he
55 % can inspect _GL and declare each proof independenlty, or combine these proofs
56 % as he likes and ignore P completely. When a main-interp-qed is used to end
57 % a proof stated by a standard Rocq Lemma/Definition statement, the data from
58 % the proof opening command is the lemma name, _GL is the empty list and P the
59 % proof term.
60 external pred main-interp-proof
61 i:list argument, % arguments passed to the command
62 i:any, % data from the parsing phase (defaults to _)
63 o:term, % proof data for the corresponding proof-closing command
64 o:list sealed-goal, % the sequents to prove
65 o:any. % any data for the corresponding proof-closing command
66 external pred main-interp-qed
67 i:list argument, % arguments passed to the command
68 i:any, % data from the parsing phase (defaults to _)
69 i:term, % proof data from the corresponding proof-opening command
70 i:list sealed-goal, % the sequents from the corresponding proof-opening command, but with proofs
71 i:any. % any data from the corresponding proof-opening command
72
73 pred usage.
74 external func attributes -> list attribute.
75
76 % see coq-lib.elpi for coq.parse-attributes generating the options below
77 external pred get-option o:string, o:A.
78
79 % The data type of arguments (for commands or tactics)
80 kind argument type.
81 external symbol int : int -> argument. % Eg. 1 -2.
82 external symbol str : string -> argument. % Eg. x "y" z.w. or any Coq keyword/symbol
83 external symbol trm : term -> argument. % Eg. (t).
84 external symbol open-trm : int -> term -> argument.
85
86 % Extra arguments for commands. [Definition], [Axiom], [Record] and [Context]
87 % take precedence over the [str] argument above (when not "quoted").
88 %
89 % Eg. Record or Inductive
90 external symbol indt-decl : indt-decl -> argument.
91 % Eg. #[universes(polymorphic,...)] Record or Inductive
92 external symbol upoly-indt-decl : indt-decl -> upoly-decl -> argument.
93 % Eg. Definition or Axiom (when the body is none)
94 external symbol const-decl : id -> option term -> arity -> argument.
95 % Eg. #[universes(polymorphic,...)] Definition or Axiom
96 external symbol upoly-const-decl : id -> option term -> arity -> upoly-decl -> argument.
97 % Eg. Context A (b : A).
98 external symbol ctx-decl : context-decl -> argument.
99
100 % Declaration of inductive types %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101
102 kind indt-decl type.
103 kind indc-decl type.
104 kind record-decl type.
105
106 % An arity is written, in Coq syntax, as:
107 % (x : T1) .. (xn : Tn) : S1 -> ... -> Sn -> U
108 % This syntax is used, for example, in the type of an inductive type or
109 % in the type of constructors. We call the abstractions on the left of ":"
110 % "parameters" while we call the type following the ":" (proper) arity.
111
112 % Note: in some contexts, like the type of an inductive type constructor,
113 % Coq makes no distinction between these two writings
114 % (xn : Tn) : forall y1 : S1, ... and (xn : Tn) (y1 : S1) : ...
115 % while Elpi is a bit more restrictive, since it understands user directives
116 % such as the implicit status of an arguments (eg, using {} instead of () around
117 % the binder), only on parameters.
118 % Moreover parameters carry the name given by the user as an "id", while binders
119 % in terms only carry it as a "name", an irrelevant pretty pringintg hint (see
120 % also the HOAS of terms). A user command can hence only use the names of
121 % parameters, and not the names of "forall" quantified variables in the arity.
122 %
123 % See also the arity->term predicate in coq-lib.elpi
124
125 kind arity type.
126 external symbol parameter : id -> implicit_kind -> term -> (term -> arity) -> arity = "1".
127 external symbol arity : term -> arity.
128
129 external symbol parameter : id -> implicit_kind -> term -> (term -> indt-decl) -> indt-decl = "2".
130 external symbol inductive : id -> bool -> arity -> (term -> list indc-decl) -> indt-decl. % tt means inductive, ff coinductive
131 external symbol minductive : id -> bool -> arity -> (term -> indt-decl) -> indt-decl. % one type of a mutual block
132 external symbol mblock : list (list indc-decl) -> indt-decl. % constructor blocks for minductive declarations
133 external symbol record : id -> term -> id -> record-decl -> indt-decl.
134
135 external symbol constructor : id -> arity -> indc-decl.
136
137 external symbol field : field-attributes -> id -> term -> (term -> record-decl) -> record-decl.
138 external symbol end-record : record-decl.
139
140 % Example.
141 % Remark that A is a regular parameter; y is a non-uniform parameter and t
142 % also features an index of type bool.
143 %
144 % Inductive t (A : Type) | (y : nat) : bool -> Type :=
145 % | K1 (x : A) {n : nat} : S n = y -> t A n true -> t A y true
146 % | K2 : t A y false
147 %
148 % is written
149 %
150 % (parameter "A" explicit {{ Type }} a\
151 % inductive "t" tt (parameter "y" explicit {{ nat }} _\
152 % arity {{ bool -> Type }})
153 % t\
154 % [ constructor "K1"
155 % (parameter "y" explicit {{ nat }} y\
156 % (parameter "x" explicit a x\
157 % (parameter "n" maximal {{ nat }} n\
158 % arity {{ S lp:n = lp:y -> lp:t lp:n true -> lp:t lp:y true }})))
159 % , constructor "K2"
160 % (parameter "y" explicit {{ nat }} y\
161 % arity {{ lp:t lp:y false }}) ])
162 %
163 % Remark that the uniform parameters are not passed to occurrences of t, since
164 % they never change, while non-uniform parameters are both abstracted
165 % in each constructor type and passed as arguments to t.
166 %
167 % The coq.typecheck-indt-decl API can be used to fill in implicit arguments
168 % an infer universe constraints in the declaration above (e.g. the hidden
169 % argument of "=" in the arity of K1).
170 %
171 % Note: when and inductive type declaration is passed as an argument to an
172 % Elpi command non uniform parameters must be separated from the uniform ones
173 % with a | (a syntax introduced in Coq 8.12 and accepted by rocq-elpi since
174 % version 1.4, in Coq this separator is optional, but not in Elpi).
175
176 % Context declaration (used as an argument to Elpi commands)
177 kind context-decl type.
178 % Eg. (x : T) or (x := B), body is optional, type may be a variable
179 external symbol context-item : id -> implicit_kind -> term -> option term -> (term -> context-decl) -> context-decl.
180 external symbol context-end : context-decl.
181
182 typeabbrev field-attributes (list field-attribute).
183
184 macro @global! :- get-option "coq:locality" "global".
185 macro @local! :- get-option "coq:locality" "local".
186
187
188
189 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% coq-HOAS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
191 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
192
193 % This section contains the low level data types linking Coq and elpi.
194 % In particular the data type for terms and the evar_map entries (a sequent)
195 % and the entry points for tactics
196
197 % Entry point for tactics. Eg. "elpi mytactic foo 3 (f x)." becomes
198 % solve <goal> <new goals>
199 % Where [str "foo", int 3, trm (app[f,x])] is part of <goal>.
200 % The encoding of goals is described below.
201 % msolve is for tactics that operate on multiple goals (called via all: ).
202 external pred solve i:goal, o:list sealed-goal.
203 external pred msolve i:list sealed-goal, o:list sealed-goal.
204
205 % Extra arguments for tactics
206 external symbol tac : ltac1-tactic -> argument.
207
208 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
209 % Coq's terms
210 %
211 % Types of term formers
212 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
213
214 % -- terms --------------------------------------------------------------------
215 kind term type.
216
217 external symbol sort : sort -> term. % Prop, Type@{i}
218
219 % constants: inductive types, inductive constructors, definitions
220 external symbol global : gref -> term.
221 external symbol pglobal : gref -> univ-instance -> term.
222
223 % binders: to form functions, arities and local definitions
224 external symbol fun : name -> term -> (term -> term) -> term. % fun x : t =>
225 external symbol prod : name -> term -> (term -> term) -> term. % forall x : t,
226 external symbol let : name -> term -> term -> (term -> term) -> term. % let x : T := v in
227
228 % other term formers: function application, pattern matching and recursion
229 external symbol app : list term -> term. % app [hd|args]
230 external symbol match : term -> term -> list term -> term. % match t p [branch])
231 external symbol fix : name -> int -> term -> (term -> term) -> term. % fix name rno ty bo
232 external symbol mfix : int -> int -> mfix-block -> term. % mfix block-idx rno
233
234 external symbol primitive : primitive-value -> term.
235
236 kind mfix-block type.
237 external symbol mfix-ty : name -> int -> term -> (term -> mfix-block) -> mfix-block. % mfix-ty name rno ty rest
238 external symbol mfix-bo : list term -> mfix-block.
239
240 % NYI
241 %type cofix name -> term -> (term -> term) -> term. % cofix name ty bo
242
243 % Notes about (match Scrutinee TypingFunction Branches) when
244 % Inductive i A : A -> nat -> Type := K : forall a : A, i A a 0
245 % and
246 % Scrutinee be a term of type (i bool true 7)
247 %
248 % - TypingFunction has a very rigid shape that depends on i. Namely
249 % as many lambdas as indexes plus one lambda for the inductive itself
250 % where the value of the parameters are taken from the type of the scrutinee:
251 % fun `a` (indt "bool") a\
252 % fun `n` (indt "nat) n\
253 % fun `i` (app[indt "i", indt "bool", a n) i\ ..
254 % Such spine of fun cannot be omitted; else elpi cannot read the term back.
255 % See also coq.bind-ind-arity-no-let in coq-lib.elpi, that builds such spine for you,
256 % or the higher level api coq.build-match (same file) that also takes
257 % care of branches.
258 % - Branches is a list of terms, the order is the canonical one (the order
259 % of the constructors as they were declared). If the constructor has arguments
260 % (excluding the parameters) then the corresponding term shall be a Coq
261 % function. In this case
262 % fun `x` (indt "bool") x\ ..
263
264 % -- helpers ------------------------------------------------------------------
265 macro @cast T TY :- (let `cast` TY T x\x).
266
267 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
268 % Coq's evar_map
269 %
270 % Context and evar declaration
271 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
272
273 % An evar_info (displayed as a Coq goal) is essentially a sequent:
274 %
275 % x : t
276 % y := v : x
277 % ----------
278 % p x y
279 %
280 % is coded as an Elpi query
281 %
282 % pi x1\ decl x1 `x` <t> =>
283 % pi x2\ def x2 `y` x1 <v> =>
284 % declare-evar
285 % [def x2 `y` x1 <v> , decl x1 `x` <t>]
286 % (RawEvar x1 x2) (<p> x1 x2) (Ev x1 x2)
287 %
288 % where, by default, declare-evar creates a syntactic constraint as
289 %
290 % {x1 x2} :
291 % decl x1 `x` <t>, def x2 `y` x1 <v> ?-
292 % evar (RawEvar x1 x2) (<p> x1 x2) (Ev x1 x2) /* suspended on RawEvar, Ev */
293 %
294 % When the program is over, a remaining syntactic constraint like the one above
295 % is read back and transformed into the corresponding evar_info.
296
297 external func decl term -> name, term. % Var Name Ty
298 external func def term -> name, term, term. % Var Name Ty Bo
299 external func cache term -> term.
300
301 external func declare-evar list prop, term, term, term. % Ctx RawEvar Ty Evar
302
303 :name "default-declare-evar"
304 declare-evar Ctx RawEv Ty Ev :-
305 declare_constraint (declare-evar Ctx RawEv Ty Ev) [RawEv].
306
307 % When a goal (evar _ _ _) is turned into a constraint the context is filtered
308 % to only contain decl, def, pp. For now no handling rules for this set of
309 % constraints other than one to remove a constraint
310
311 external func rm-evar term, term.
312 rm-evar (uvar as X) (uvar as Y):- !, declare_constraint (rm-evar X Y) [X,Y].
313 rm-evar _ _.
314
315 constraint declare-evar evar def decl cache rm-evar {
316
317 % Override the actual context
318 rule \ (declare-evar Ctx RawEv Ty Ev) <=> (Ctx =!=> evar RawEv Ty Ev).
319
320 rule \ (rm-evar (uvar X _) (uvar Y _)) (evar (uvar X _) _ (uvar Y _)).
321 rule \ (rm-evar (uvar X _) (uvar Y _)).
322
323 }
324
325 % The (evar R Ty E) predicate suspends when R and E are flexible,
326 % and is solved otherwise.
327 % The client may want to provide an alternative implementation of
328 % the clause "default-assign-evar", for example to typechecks that the
329 % term assigned to E has type Ty, or that the term assigned to R
330 % elaborates to a term of type Ty that gets assigned to E.
331 % In tactic mode, elpi/coq-elaborator.elpi wires things up that way.
332
333 external func evar term, term -> term. % Evar Ty RefinedSolution
334 evar (uvar as X) T S :- var S _ VL, !,
335 prune T VL, prune X VL, declare_constraint (evar X T S) [X, S].
336
337 :name "default-assign-evar"
338 evar _ _ _. % volatile, only unresolved evars are considered as evars
339
340 % To ease the creation of a context with decl and def
341 % Eg. @pi-decl `x` <t> x1\ @pi-def `y` <t> <v> y\ ...
342 macro @pi-decl N T F :- pi x\ decl x N T => F x.
343 macro @pi-def N T B F :- pi x\ def x N T B => cache x B_ => F x.
344
345 % Converts an arity to a term
346 func coq.arity->term arity -> term.
347 coq.arity->term (parameter ID _ Ty Rest) (prod Name Ty R) :-
348 coq.id->name ID Name,
349 @pi-decl Name Ty x\ coq.arity->term (Rest x) (R x).
350 coq.arity->term (arity A) A.
351
352 macro @pi-parameter ID T F :-
353 sigma N\ (coq.id->name ID N, pi x\ decl x N T => F x).
354 macro @pi-inductive ID A F :-
355 sigma N\ (coq.id->name ID N, coq.arity->term A T, pi x\ decl x N T => F x).
356
357
358 % Sometimes it can be useful to pass to Coq a term with unification variables
359 % representing "untyped holes" like an implicit argument _. In particular
360 % a unification variable may exit the so called pattern fragment (applied
361 % to distinct variables) and hence cannot be reliably mapped to Coq as an evar,
362 % but can still be considered as an implicit argument.
363 % By loading in the context get-option "HOAS:holes" tt one forces that
364 % behavior. Here a convenience macro to be put on the LHS of =>
365 macro @holes! :- get-option "HOAS:holes" tt.
366
367 % Similarly, some APIs take a term skeleton in input. In that case unification
368 % variables are totally disregarded (not even mapped to Coq evars). They are
369 % interpreted as the {{ lib:elpi.hole }} constant, which represents an implicit
370 % argument. As a consequence these APIs don't modify the input term at all, but
371 % rather return a copy. Note that if {{ lib:elpi.hole }} is used directly, then
372 % it has to be applied to all variables in scope, since Coq erases variables
373 % that are not used. For example using {{ forall x : nat, lib:elpi.hole }} as
374 % a term skeleton is equivalent to {{ nat -> lib:elpi.hole }}, while
375 % {{ forall x : nat, lib:elpi.hole x lib:elpi.hole more args }} puts x in
376 % the scope of the hole (and passes to is more args).
377
378 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
379 % Coq's goals and tactic invocation
380 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
381
382 % A Coq goal is essentially a sequent, like the evar_info above, but since it
383 % has to be manipulated as first class Elpi data, it is represented in a slightly
384 % different way. For example
385 %
386 % x : t
387 % y := v : x
388 % ----------
389 % g x y
390 %
391 % is represented by the following term of type sealed-goal
392 %
393 % nabla x1\
394 % nabla x2\
395 % seal
396 % (goal
397 % [def x2 `y` x1 <v> , decl x1 `x` <t>]
398 % (RawEvar x1 x2) (<g> x1 x2) (Evar x1 x2)
399 % (Arguments x1 x2))
400
401 kind goal type.
402 kind sealed-goal type.
403 external symbol nabla : (term -> sealed-goal) -> sealed-goal.
404 external symbol seal : goal -> sealed-goal.
405
406 typeabbrev goal-ctx (list prop).
407 external symbol goal : goal-ctx -> term -> term -> term -> list argument -> goal.
408
409 % A sealed-goal closes with nabla the bound names of a
410 %
411 % (goal Ctx RawSolution Ty Solution Arguments)
412 %
413 % where Ctx is a list of decl or def and Solution is a unification variable
414 % to be assigned to a term of type Ty in order to make progress.
415 % RawSolution is used as a trigger: when a term is assigned to it, it is
416 % elaborated against Ty and the resulting term is assigned to Solution.
417 %
418 % Arguments contains data attached to the goal, which lives in its context
419 % and can be used by tactics to solve the goals.
420
421 % A tactic (an elpi predicate which makes progress on a Coq goal) is
422 % a predicate of type
423 % sealed-goal -> list sealed-goal -> prop
424 %
425 % while the main entry point for a tactic written in Elpi is solve
426 % which has type
427 % goal -> list sealed-goal -> prop
428 %
429 % The utility (coq.ltac.open T G GL) postulates all the variables bounds
430 % by nabla and loads the goal context before calling T on the unsealed
431 % goal. The invocation of a tactic with arguments
432 % 3 x "y" (h x)
433 % on the previous goal results in the following Elpi query:
434 %
435 % (pi x1\ decl x1 `x` <t> =>
436 % pi x2\ def x2 `y` x1 <v> =>
437 % declare-evar
438 % [def x2 `y` x1 <v> , decl x1 `x` <t>]
439 % (RawEvar x1 x2) (<g> x1 x2) (Evar x1 x2)),
440 % (coq.ltac.open solve
441 % (nabla x1\ nabla x2\ seal
442 % (goal
443 % [def x2 `y` x1 <v> , decl x1 `x` <t>]
444 % (RawEvar x1 x2) (<g> x1 x2) (Evar x1 x2)
445 % [int 3, str `x`, str`y`, trm (app[const `h`,x1])]))
446 % NewGoals)
447 %
448 % If the goal sequent contains other evars, then a tactic invocation is
449 % an Elpi query made of the conjunction of all the declare-evar queries
450 % corresponding to these evars and the query corresponding to the goal
451 % sequent. NewGoals can be assigned to a list of goals that should be
452 % declared as open. Omitted goals are shelved. If NewGoals is not
453 % assigned, then all unresolved evars become new goals, but the order
454 % of such goals is not specified.
455
456 % The file elpi-ltac.elpi provides a few combinators (other than coq.ltac.open)
457 % in the tradition of LCF tacticals. The main difference is that the arguments
458 % of custom written tactics must not be passed as predicate arguments but rather
459 % put in the goal they receive. Indeed these arguments can contain terms, and
460 % their bound variables cannot escape the seal. coq.ltac.set-goal-arguments
461 % can be used to put an argument from the current goal context into another
462 % goal. The coq.ltac.call utility can call Ltac1 code (written in Coq) and
463 % pass arguments via this mechanism.
464
465 % Last, since Elpi is already a logic programming language with primitive
466 % support for unification variables, most of the work of a tactic can be
467 % performed without using tacticals (which work on sealed goals) but rather
468 % in the context of the original goal. The last step is typically to call
469 % the refine utility with a term synthesized by the tactic or invoke some
470 % Ltac1 code on that term (e.g. to call vm_compute, see also the example
471 % on the reflexive tactic).
472
473 % ----- Multi goals tactics. ----
474 % Coq provides goal selectors, such as all:, to pass to a tactic more than one
475 % goal. In order to write such a tactic, Coq-Elpi provides another entry point
476 % called msolve. To be precise, if there are two goals under focus, say <g1> and
477 % <g2>, then all: elpi tac <t> runs the following query
478 %
479 % msolve [<g1>,<g2>] NewGoals ; % note the disjunction
480 % coq.ltac.all (coq.ltac.open solve) [<g1>,<g2>] NewGoals
481 %
482 % So, if msolve has no clause, Coq-Elpi will use solve on all the goals
483 % independently. If msolve has a clause, then it can manipulate the entire list
484 % of sealed goals. Note that the argument <t> is in both <g1> and <g2> but
485 % it is interpreted in both contexts independently. If both goals have a proof
486 % variable named "x" then passing (@eq_refl _ x) as <t> equips both goals with
487 % a (raw) proof that "x = x", no matter what their type is.
488
489 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
490 % Declarations for Coq's API (environment read/write access, etc).
491 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
492
493
494 % tt = Yes, ff = No, unspecified = No (unspecified means "_" or a variable).
495 typeabbrev opaque? bool. macro @opaque! :- tt. macro @transparent! :- ff.
496
497 %%%%%%% Attributes to be passed to APIs as in @local! => coq.something %%%%%%%%
498
499 macro @keep-alg-univs! :- get-option "coq:keepalgunivs" tt.
500
501 macro @primitive! :- get-option "coq:primitive" tt. % primitive records
502 macro @reversible! :- get-option "coq:reversible" tt. % coercions
503 macro @no-tc! :- get-option "coq:no_tc" tt. % skip typeclass inference
504
505 macro @uinstance! I :- get-option "coq:uinstance" I. % universe instance
506
507 % declaration of universe polymorphic constants
508 % The first list is the one of the universe variables being bound
509 % The first boolean is tt if this list can be extended by Coq (or it has to
510 % mention all universes actually used)
511 % The second list is the one with the constraints amond where universes
512 % The second boolean is tt if this list can be extended by Coq or it has to
513 % mention all universe constraints actually required to type check the
514 % declaration)
515 macro @udecl! Vs LV Cs LC :- get-option "coq:udecl" (upoly-decl Vs LV Cs LC).
516 macro @udecl-cumul! Vs LV Cs LC :- get-option "coq:udecl-cumul" (upoly-decl-cumul Vs LV Cs LC).
517 macro @univpoly! :- @udecl! [] tt [] tt.
518 macro @univpoly-cumul! :- @udecl-cumul! [] tt [] tt.
519
520 macro @ppwidth! N :- get-option "coq:ppwidth" N. % printing width
521 macro @ppall! :- get-option "coq:pp" "all". % printing all
522 macro @ppmost! :- get-option "coq:pp" "most". % printing most of contents
523 macro @pplevel! N :- get-option "coq:pplevel" N. % printing precedence (for parentheses)
524
525 macro @keepunivs! :- get-option "coq:keepunivs" tt. % skeletons elaboration
526 macro @dropunivs! :- get-option "coq:keepunivs" ff. % add-indt/add-const
527
528 macro @using! S :- get-option "coq:using" S. % like the #[using=S] attribute
529
530 macro @inline-at! N :- get-option "coq:inline" (coq.inline.at N). % like Inline(N)
531 macro @inline! N :- get-option "coq:inline" coq.inline.default. % like
532
533 macro @redflags! F :- get-option "coq:redflags" (F : coq.redflags). % for whd & co
534
535 % both arguments are strings eg "8.12.0" "use foo instead"
536 macro @deprecated! Since Msg :-
537 get-option "coq:deprecated" (pr Since Msg).
538
539 macro @ltacfail! N :- get-option "ltac:fail" N.
540
541 % retrocompatibility macro for Coq v8.10
542 macro @coercion! :- [coercion reversible].
543
544
545 % Attributes for a record field. Can be left unspecified, see defaults
546 % below.
547 kind field-attribute type.
548 external symbol coercion : coercion-status -> field-attribute = "1". % default off
549 external symbol canonical : bool -> field-attribute = "1". % default true, if field is named
550
551 % Status of a record field w.r.t. coercions
552 kind coercion-status type.
553 external symbol regular : coercion-status = "1".
554 external symbol reversible : coercion-status = "1".
555 external symbol off : coercion-status = "1".
556
557
558 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
559 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% builtins %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
560 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
561
562 % This section contains the API to access Coq
563 % The marker *E* means *experimental*, i.e. use at your own risk, it may change
564 % substantially or even disappear in future versions.
565
566
567 % -- Misc ---------------------------------------------------------
568
569 % [coq.info ...] Prints an info message
570 external type coq.info variadic any (func).
571
572 % [coq.notice ...] Prints a notice message
573 external type coq.notice variadic any (func).
574
575 % [coq.say ...] Prints a notice message
576 external type coq.say variadic any (func).
577
578 % [coq.debug ...] Prints a debug message
579 external type coq.debug variadic any (func).
580
581 % [coq.warn ...] Prints a generic warning message
582 external type coq.warn variadic any (func).
583
584 % [coq.warning Category Name ...]
585 % Prints a warning message with a Name and Category which can be used
586 % to silence this warning or turn it into an error. See coqc -w command
587 % line option
588 external type coq.warning string -> string -> variadic any (func).
589
590 % [coq.error ...] Prints and *aborts* the program. It is a fatal error for
591 % Elpi and Ltac
592 external type coq.error variadic any (func).
593
594 % [coq.version VersionString Major Minor Patch] Fetches the version of Coq,
595 % as a string and as 3 numbers
596 external func coq.version -> string, int, int, int.
597
598
599 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
600 % API for objects belonging to the logic
601 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
602
603 % -- Environment: names -----------------------------------------------
604
605 % To make the API more precise we use different data types for the names
606 % of global objects.
607 % Note: [ctype "bla"] is an opaque data type and by convention it is written
608 % [@bla].
609
610 % Global constant name
611 kind constant type.
612
613
614 % Inductive type name
615 kind inductive type.
616
617
618 % Inductive constructor name
619 kind constructor type.
620
621
622 % Global objects: inductive types, inductive constructors, definitions
623 kind gref type.
624 external symbol const : constant -> gref. % Nat.add, List.append, ...
625 external symbol indt : inductive -> gref. % nat, list, ...
626 external symbol indc : constructor -> gref. % O, S, nil, cons, ...
627
628 % [id] is a name that matters, we piggy back on Elpi's strings.
629 % Note: [name] is a name that does not matter.
630 typeabbrev id string.
631
632
633 % Name of a module /*E*/
634 kind modpath type.
635
636
637 % Name of a module type /*E*/
638 kind modtypath type.
639
640
641 % Result of coq.locate-all
642 kind located type.
643 external symbol loc-gref : gref -> located = "1".
644 external symbol loc-modpath : modpath -> located = "1".
645 external symbol loc-modtypath : modtypath -> located = "1".
646 external symbol loc-abbreviation : abbreviation -> located = "1".
647
648 % [coq.locate-all Name Located] finds all possible meanings of a string.
649 % Does not fail.
650 external func coq.locate-all id -> list located.
651
652 % [coq.locate Name GlobalReference] locates a global definition, inductive
653 % type or constructor via its name.
654 % It unfolds syntactic notations, e.g. "Notation old_name := new_name."
655 % It understands qualified names, e.g. "Nat.t".
656 % It understands Rocqlib Registered names using the "lib:" prefix,
657 % eg "lib:core.bool.true".
658 % It's a fatal error if Name cannot be located.
659 external func coq.locate id -> gref.
660
661 % -- Environment: read ------------------------------------------------
662
663 % Note: The type [term] is defined in coq-HOAS.elpi
664
665 % [coq.env.typeof GR Ty] reads the type Ty of a global reference.
666 % Supported attributes:
667 % - @uinstance! I (default: fresh instance I)
668 external func coq.env.typeof gref -> term.
669
670 % [coq.env.global GR T] turns a global reference GR into a term, or
671 % viceversa.
672 % T = (global GR) or, if GR points to a universe polymorphic term,
673 % T = (pglobal GR I).
674 % Supported attributes:
675 % - @uinstance! I (default: fresh instance I)
676 external func coq.env.global -> gref, term.
677
678 external func coq.env.indt % reads the inductive type declaration for the environment.
679 % Supported attributes:
680 % - @uinstance! I (default: fresh instance I)
681 inductive % reference to the inductive type
682 -> bool, % tt if the type is inductive (ff for co-inductive)
683 int, % number of parameters
684 int, % number of parameters that are uniform (<= parameters)
685 term, % type of the inductive type constructor including parameters
686 list constructor,
687 % list of constructor names
688 list term. % list of the types of the constructors (type of KNames) including parameters
689
690 external func coq.env.indt-block % reads the inductive type declaration for the environment.
691 inductive % Ind
692 -> bool, % tt if the type is inductive (ff for co-inductive)
693 int, % number of parameters
694 int, % number of parameters that are uniform (<= parameters)
695 list inductive, % all inductives in the block
696 list term, % types of the inductive types constructors including parameters
697 list (list constructor),
698 % lists of constructor names
699 list (list term). % lists of the types of the constructors (type of KNames) including parameters
700
701 external func coq.env.indt-decl % reads the inductive type declaration for the environment.
702 % Supported attributes:
703 % - @uinstance! I (default: fresh instance I)
704 inductive % reference to the inductive type
705 -> indt-decl.
706 % HOAS description of the inductive type
707
708 % [coq.env.indc->indt K I N] finds the inductive I to which constructor K
709 % belongs and its position N among the other constructors
710 external func coq.env.indc->indt constructor -> inductive, int.
711
712 % [coq.env.indc GR ParamNo UnifParamNo Kno Ty] reads the type Ty of an
713 % inductive constructor GR, as well as
714 % the number of parameters ParamNo and uniform parameters
715 % UnifParamNo and the number of the constructor Kno (0 based).
716 % Supported attributes:
717 % - @uinstance! I (default: fresh instance I)
718 external func coq.env.indc constructor -> int, int, int, term.
719
720 % [coq.env.informative? Ind] Checks if Ind is informative, that is, if
721 % it can be eliminated to build a Type. Inductive types in Type
722 % are
723 % informative, as well a singleton types in Prop (which are
724 % regarded as not non-informative).
725 external func coq.env.informative? inductive.
726
727 % [coq.env.record? Ind PrimProjs] checks if Ind is a record (PrimProjs = tt
728 % if Ind has primitive projections)
729 external func coq.env.record? inductive -> bool.
730
731 % [coq.env.recursive? Ind] checks if Ind is recursive
732 external func coq.env.recursive? inductive.
733
734 % [coq.env.opaque? GR] checks if GR is an opaque constant
735 external func coq.env.opaque? constant.
736
737 % [coq.env.univpoly? GR PolyArity] checks if GR is universe polymorphic and
738 % if so returns the number of universe variables
739 external func coq.env.univpoly? gref -> int.
740
741 % [coq.env.const GR Bo Ty] reads the type Ty and the body Bo of constant
742 % GR.
743 % Opaque constants have Bo = none.
744 % Supported attributes:
745 % - @uinstance! I (default: fresh instance I)
746 external func coq.env.const constant -> option term, term.
747
748 % [coq.env.const-body GR Bo] reads the body of a constant, even if it is
749 % opaque.
750 % If such body is none, then the constant is a true axiom.
751 % Supported attributes:
752 % - @uinstance! I (default: fresh instance I)
753 external func coq.env.const-body constant -> option term.
754
755 % [coq.env.primitive? GR] tests if GR is a primitive constant (like uin63
756 % addition) or a primitive type (like uint63)
757 external func coq.env.primitive? constant.
758
759 % [coq.locate-module ModName ModPath] locates a module. It's a fatal error
760 % if ModName cannot be located. *E*
761 external func coq.locate-module id -> modpath.
762
763 % [coq.locate-module-type ModName ModPath] locates a module. It's a fatal
764 % error if ModName cannot be located. *E*
765 external func coq.locate-module-type id -> modtypath.
766
767 % Contents of a module
768 kind module-item type.
769 external symbol submodule : modpath -> list module-item -> module-item = "1".
770 external symbol module-type : modtypath -> module-item = "1".
771 external symbol gref : gref -> module-item = "1".
772 external symbol module-functor : modpath -> list modtypath -> module-item = "1".
773 external symbol module-type-functor : modtypath -> list modtypath ->
774 module-item = "1".
775
776 % [coq.env.module MP Contents] lists the contents of a module (recurses on
777 % submodules) *E*
778 external func coq.env.module modpath -> list module-item.
779
780 % [coq.env.module-type MTP Entries] lists the items made visible by module
781 % type (does not recurse on submodules) *E*
782 external func coq.env.module-type modtypath -> list id.
783
784 % [coq.env.section-variables ConstantsRepresentingVariables] lists all the
785 % section variables, i.e. the global objects that are marked as to be
786 % abstracted at the end of the enclosing sections
787 external func coq.env.section-variables -> list constant.
788
789 % [coq.env.section-contents GlobalObjects] lists the global objects that are
790 % defined withing the open sections. Inner section first.
791 external func coq.env.section-contents -> list (list gref).
792
793 % Deprecated, use coq.env.section-variables
794 func coq.env.section -> list constant.
795 coq.env.section L :-
796 coq.warning "elpi.deprecated" "elpi.env.section" "use coq.env.section-variables in place of coq.env.section",
797 coq.env.section-variables L.
798
799
800 % [coq.env.dependencies GR MP Deps] Computes the direct dependencies of GR.
801 % If MP is given, Deps only contains grefs from that module
802 external func coq.env.dependencies gref, modpath -> coq.gref.set.
803
804 % [coq.env.transitive-dependencies GR MP Deps] Computes the transitive
805 % dependencies of GR. If MP is given, Deps only contains grefs from that
806 % module
807 external func coq.env.transitive-dependencies gref,
808 modpath -> coq.gref.set.
809
810 % [coq.env.term-dependencies T S] Computes all the grefs S occurring in the
811 % term T
812 external func coq.env.term-dependencies term -> coq.gref.set.
813
814 % [coq.env.current-path Path] lists the current module path
815 external func coq.env.current-path -> list string.
816
817 % [coq.env.current-section-path Path] lists the current section path
818 external func coq.env.current-section-path -> list string.
819
820 % Deprecated, use coq.env.opaque?
821 pred coq.env.const-opaque? i:constant.
822 coq.env.const-opaque? C :-
823 coq.warning "elpi.deprecated" "elpi.const-opaque" "use coq.env.opaque? in place of coq.env.const-opaque?",
824 coq.env.opaque? C.
825
826
827 % Deprecated, use coq.env.primitive?
828 pred coq.env.const-primitive? i:constant.
829 coq.env.const-primitive? C :-
830 coq.warning "elpi.deprecated" "elpi.const-primitive" "use coq.env.primitive? in place of coq.env.const-primitive?",
831 coq.env.primitive? C.
832
833
834 % -- Environment: write -----------------------------------------------
835
836 % Note: (monomorphic) universe constraints are taken from ELPI's
837 % constraints store. Use coq.univ-* in order to add constraints (or any
838 % higher level facility as coq.typecheck). Load in the context attributes
839 % such as @univpoly!, @univpoly-cumul!, @udecl! or @udecl-cumul! in order to
840 % declare universe polymorphic constants or inductives.
841
842 % [coq.env.add-const Name Bo Ty Opaque C] Declare a new constant: C gets a
843 % constant derived from Name
844 % and the current module; Ty can be left unspecified and in that case
845 % the
846 % inferred one is taken (as in writing Definition x := t); Bo can be
847 % left
848 % unspecified and in that case an axiom is added (or a section variable,
849 % if a section is open and @local! is used). Omitting the body and the type
850 % is
851 % an error. Note: using this API for declaring an axiom or a section
852 % variable is
853 % deprecated, use coq.env.add-axiom or coq.env.add-section-variable
854 % instead.
855 % Supported attributes:
856 % - @local! (default: false)
857 % - @using! (default: section variables actually used)
858 % - @univpoly! (default unset)
859 % - @udecl! (default unset)
860 % - @dropunivs! (default: false, drops all universe constraints from the
861 % store after the definition)
862 %
863 external func coq.env.add-const id, term, term, opaque? -> constant.
864
865 % [coq.env.add-axiom Name Ty C] Declare a new axiom: C gets a constant
866 % derived from Name
867 % and the current module.
868 % Supported attributes:
869 % - @local! (default: false)
870 % - @univpoly! (default unset)
871 % - @using! (default: section variables actually used)
872 % - @inline! (default: no inlining)
873 % - @inline-at! N (default: no inlining)
874 external func coq.env.add-axiom id, term -> constant.
875
876 % [coq.env.add-section-variable Name I Ty C] Declare a new section variable:
877 % C gets a constant derived from Name
878 % and the current module.
879 %
880 external func coq.env.add-section-variable id, implicit_kind,
881 term -> constant.
882
883
884 pred coq.env.add-context i:context-decl.
885 coq.env.add-context context-end.
886 coq.env.add-context (context-item Name I Ty none Rest) :-
887 coq.env.add-section-variable Name I Ty C,
888 coq.env.add-context (Rest {coq.env.global (const C)}).
889 coq.env.add-context (context-item Name _I Ty (some Bo) Rest) :-
890 coq.env.add-const Name Bo Ty ff C,
891 coq.env.add-context (Rest {coq.env.global (const C)}).
892
893
894 % [coq.env.add-indt Decl I] Declares an inductive type.
895 % Supported attributes:
896 % - @dropunivs! (default: false, drops all universe constraints from the
897 % store after the definition)
898 % - @primitive! (default: false, makes records primitive)
899 external func coq.env.add-indt indt-decl -> inductive.
900
901 % Interactive module construction
902
903 % Coq Module inline directive
904 kind coq.inline type.
905 external symbol coq.inline.no : coq.inline = "1". % Coq's [no inline] (aka !)
906 external symbol coq.inline.default : coq.inline = "1". % The default, can be omitted
907 external symbol coq.inline.at : int -> coq.inline = "1". % Coq's [inline at <num>]
908
909 % [coq.env.fresh-global-id ID FID] Generates an id FID which is fresh in
910 % the current module and looks similar to ID, i.e. it is ID concatenated
911 % with a number, starting from 1.
912 % [coq.env.fresh-global-id X X] can be used to check if X is taken
913 external func coq.env.fresh-global-id id -> id.
914
915 external func coq.env.begin-module-functor % Starts a functor. bla bla
916 id, % The name of the functor
917 option modtypath, % Its module type (optional)
918 list (pair id modtypath). % Parameters of the functor (optional)
919
920
921 func coq.env.begin-module id, option modtypath -> .
922 coq.env.begin-module Name MP :- coq.env.begin-module-functor Name MP [].
923
924
925 % [coq.env.end-module ModPath] end the current module that becomes known as
926 % ModPath *E*. bla bla
927 external func coq.env.end-module -> modpath.
928
929 external func coq.env.begin-module-type-functor % Starts a module type functor *E*. bla bla
930 id, % The name of the functor
931 list (pair id modtypath). % The parameters of the functor (optional)
932
933
934 func coq.env.begin-module-type id ->.
935 coq.env.begin-module-type Name :-
936 coq.env.begin-module-type-functor Name [].
937
938
939 % [coq.env.end-module-type ModTyPath] end the current module type that
940 % becomes known as ModPath *E*. bla bla
941 external func coq.env.end-module-type -> modtypath.
942
943 external func coq.env.apply-module-functor % Applies a functor *E*. bla bla
944 id, % The name of the new module
945 option modtypath, % Its module type (optional)
946 modpath, % The functor being applied (optional)
947 list modpath, % Its arguments (optional)
948 coq.inline % Arguments inlining (optional)
949 -> modpath. % The modpath of the new module
950
951 external func coq.env.apply-module-type-functor % Applies a type functor *E*. bla bla
952 id, % The name of the new module type
953 modtypath, % The functor (optional)
954 list modpath, % Its arguments (optional)
955 coq.inline % Arguments inlining (optional)
956 -> modtypath. % The modtypath of the new module type
957
958 % [coq.env.include-module ModPath Inline (optional)] is like the vernacular
959 % Include, Inline can be omitted *E*. bla bla
960 external func coq.env.include-module modpath, coq.inline.
961
962 % [coq.env.include-module-type ModTyPath Inline (optional)] is like the
963 % vernacular Include Type, Inline can be omitted *E*. bla bla
964 external func coq.env.include-module-type modtypath, coq.inline.
965
966 % [coq.env.import-module ModPath] is like the vernacular Import *E*
967 external func coq.env.import-module modpath.
968
969 % [coq.env.export-module ModPath] is like the vernacular Export *E*
970 external func coq.env.export-module modpath.
971
972 % Support for sections is limited, in particular sections and
973 % Coq quotations may interact in surprising ways. For example
974 % Section Test.
975 % Variable x : nat.
976 % Elpi Query lp:{{ coq.say {{ x }} }}.
977 % works since x is a global Coq term while
978 % Elpi Query lp:{{
979 % coq.env.begin-section "Test",
980 % coq.env.add-const "x" _ {{ nat }} _ @local! GRX,
981 % coq.say {{ x }}
982 % }}.
983 % may work in a surprising way or may not work at all since
984 % x is resolved before the section is started hence it cannot
985 % denote the same x as before.
986
987 % [coq.env.begin-section Name] starts a section named Name *E*
988 external func coq.env.begin-section id.
989
990 % [coq.env.end-section] end the current section *E*
991 external func coq.env.end-section.
992
993 % [coq.env.projections StructureName Projections] given a record
994 % StructureName lists all projections
995 external func coq.env.projections inductive -> list (option constant).
996
997 % [coq.env.projection? Constant Number of parameters] if the constant is a
998 % projection, returns the number of parameters of its record.
999 external func coq.env.projection? constant -> int.
1000
1001 % [coq.env.primitive-projections StructureName Projections] given a record
1002 % StructureName lists all primitive projections
1003 external func coq.env.primitive-projections inductive -> list (option (pair projection int)).
1004
1005 % [coq.env.primitive-projection? Projection Compatibility constant Index]
1006 % Relates a primitive projection to its compatibility constant. Index is set
1007 % to the constructor argument extracted by the projection (starting from 0).
1008 external func coq.env.primitive-projection? -> projection, constant, int.
1009
1010 % -- Sorts (and their universe level, if applicable) ----------------
1011
1012 % Warning: universe polymorphism has to be considered experimental *E* as
1013 % a feature, not just as a set of APIs. Unfortunately some of the
1014 % current complexity is exposed to the programmer, bare with us.
1015 %
1016 % The big bang is that in Coq one has terms, types and sorts (which are
1017 % the types of types). Some sorts (as of today only Type) some with
1018 % a universe level, on paper Type_i for some i. At the sort level
1019 % Coq features some form of subtyping: a function expecting a function
1020 % to Type, e.g. nat -> Type, can receive a function to Prop, since
1021 % Prop <= Type. So far, so good. But what are these levels i
1022 % exactly?
1023 %
1024 % Universe levels are said to be "algebraic", they are made of
1025 % variables (see the next section) and the two operators +1 and max.
1026 % This is a sort of internal optimization that leaks to the
1027 % user/programmer. Indeed these universe levels cannot be (directly) used
1028 % in all APIs morally expecting a universe level "i", in particular
1029 % the current constraint engine cannot handle constraint with an
1030 % algebraic level on the right, e.g. i <= j+1. Since some APIs only
1031 % accept universe variables, we provide the coq.univ.variable API
1032 % which is able to craft a universe variable which is roughly
1033 % equivalent to an algebraic universe, e.g. k such that j+1 = k.
1034 %
1035 % Rocq-Elpi systematically purges algebraic universes from terms (and
1036 % types and sorts) when one reads them from the environment. This
1037 % makes the embedding of terms less precise than what it could be.
1038 % The different data types stay, since Coq will eventually become
1039 % able to handle algebraic universes consistently, making this purging
1040 % phase unnecessary.
1041
1042 % universe level (algebraic: max, +1, univ.variable)
1043 kind univ type.
1044
1045
1046 % Sorts (kinds of types)
1047 kind sort type.
1048 external symbol prop : sort. % impredicative sort of propositions
1049 external symbol sprop : sort. % impredicative sort of propositions with definitional proof irrelevance
1050 external symbol typ : univ -> sort. % predicative sort of data (carries a universe level)
1051
1052 % [coq.sort.leq S1 S2] constrains S1 <= S2
1053 external func coq.sort.leq sort, sort.
1054
1055 % [coq.sort.eq S1 S2] constrains S1 = S2
1056 external func coq.sort.eq sort, sort.
1057
1058 % [coq.sort.sup S1 S2] constrains S2 = S1 + 1
1059 external func coq.sort.sup sort, sort.
1060
1061 % [coq.sort.pts-triple S1 S2 S3] constrains S3 = sort of product with domain
1062 % in S1 and codomain in S2
1063 external func coq.sort.pts-triple sort, sort -> sort.
1064
1065 % [coq.univ.print] prints the set of universe constraints
1066 external func coq.univ.print.
1067
1068 % [coq.univ.new U] A fresh universe.
1069 external func coq.univ.new -> univ.
1070
1071 % [coq.univ.alg-super U V] relates a univ U to its algebraic successor V,
1072 % that is U+1 and not any V s.t. U < V
1073 external func coq.univ.alg-super univ -> univ.
1074
1075 % [coq.univ.alg-max U1 U2 UMax] relates univs U1 and U2 to their algebraic
1076 % maximum UMax, that is max(U1, U2)
1077 external func coq.univ.alg-max univ, univ -> univ.
1078
1079 % [coq.univ Name U] Finds a named unvierse. Can fail.
1080 external func coq.univ -> id, univ.
1081
1082 % [coq.univ.global? U] succeeds if U is a global universe
1083 external func coq.univ.global? univ.
1084
1085 % [coq.univ.constraints CL] gives the list of constraints, see also
1086 % coq.univ.variable.constraints
1087 external func coq.univ.constraints -> list univ-constraint.
1088
1089 % -- Universe variables ------
1090
1091 % universe level variable
1092 kind univ.variable type.
1093
1094
1095 % [coq.univ.variable U L] relates a univ.variable L to a univ U
1096 external func coq.univ.variable -> univ, univ.variable.
1097
1098 % [coq.univ.variable.constraints L CL] gives the list of constraints on L.
1099 % Can be used to craft a strict upoly-decl
1100 external func coq.univ.variable.constraints univ.variable -> list univ-constraint.
1101
1102 % [coq.univ.variable.of-term T S] collects all univ.variables occurring in T
1103 external func coq.univ.variable.of-term term -> coq.univ.variable.set.
1104
1105 % -- Universe instance (for universe polymorphic global terms) ------
1106
1107 % As of today a universe polymorphic constant can only be instantiated
1108 % with universe level variables. That is f@{Prop} is not valid, nor
1109 % is f@{u+1}. One can only write f@{u} for any u.
1110 %
1111 % A univ-instance is morally a list of universe level variables,
1112 % but its list syntax is hidden in the terms. If you really need to
1113 % craft or inspect one of these, the following APIs can help you.
1114 %
1115 % Most of the time the user is expected to use coq.env.global which
1116 % crafts a fresh, appropriate, universe instance and possibly unify that
1117 % term (of the instance it contains) with another one.
1118
1119 % Universes level instance for a universe-polymorphic constant
1120 kind univ-instance type.
1121
1122
1123 % [coq.univ-instance UI UL] relates a univ-instance UI and a list of
1124 % universe level variables UL
1125 external func coq.univ-instance -> univ-instance, list univ.variable.
1126
1127 % [coq.univ-instance.unify-eq GR UI1 UI2 Diagnostic] unifies the two
1128 % universe instances for the same gref
1129 external func coq.univ-instance.unify-eq gref, univ-instance,
1130 univ-instance -> diagnostic.
1131
1132 % [coq.univ-instance.unify-leq GR UI1 UI2 Diagnostic] unifies the two
1133 % universe instances for the same gref. Note: if the GR is not *cumulative*
1134 % (see Cumulative or #[universes(cumulative)]) then this API imposes an
1135 % equality constraint.
1136 external func coq.univ-instance.unify-leq gref, univ-instance,
1137 univ-instance -> diagnostic.
1138
1139 % -- Declaration of universe polymorphic global terms -----------
1140
1141 % These are the data types used to declare how constants
1142 % and inductive types should be declared (see also the @udecl!
1143 % and
1144 % @udecl-cumul! macros). Note that only inductive types can be
1145 % declared as cumulative.
1146
1147 % Constraint between two universes level variables
1148 kind univ-constraint type.
1149 external symbol lt : univ.variable -> univ.variable -> univ-constraint = "2".
1150 external symbol le : univ.variable -> univ.variable -> univ-constraint = "1".
1151 external symbol eq : univ.variable -> univ.variable -> univ-constraint = "2".
1152
1153 % Variance of a universe level variable
1154 kind univ-variance type.
1155 external symbol auto : univ.variable -> univ-variance = "1".
1156 external symbol covariant : univ.variable -> univ-variance = "1".
1157 external symbol invariant : univ.variable -> univ-variance = "1".
1158 external symbol irrelevant : univ.variable -> univ-variance = "1".
1159
1160 % Constraints for a non-cumulative declaration. Boolean tt means loose
1161 % (e.g. the '+' in f@{u v + | u < v +})
1162 kind upoly-decl type.
1163 external symbol upoly-decl : list univ.variable -> bool ->
1164 list univ-constraint -> bool -> upoly-decl = "1".
1165 external symbol upoly-decl-cumul : list univ-variance -> bool ->
1166 list univ-constraint -> bool ->
1167 upoly-decl = "1".
1168
1169 % -- Primitive --------------------------------------------------------
1170
1171 kind uint63 type.
1172
1173
1174 kind float64 type.
1175
1176
1177 kind pstring type.
1178
1179
1180 kind projection type.
1181
1182
1183 % Primitive values
1184 kind primitive-value type.
1185 external symbol uint63 : uint63 -> primitive-value = "1". % unsigned integers over 63 bits
1186 external symbol float64 : float64 -> primitive-value = "1". % double precision foalting points
1187 external symbol pstring : pstring -> primitive-value = "1". % primitive string
1188 external symbol proj : projection -> int -> primitive-value = "1". % primitive projection
1189
1190 % [coq.uint63->int U I] Transforms a primitive unsigned integer U into an
1191 % elpi integer I. Fails if it does not fit.
1192 external func coq.uint63->int uint63 -> int.
1193
1194 % [coq.int->uint63 I U] Transforms an elpi integer I into a primitive
1195 % unsigned integer U. Fails if I is negative.
1196 external func coq.int->uint63 int -> uint63.
1197
1198 % [coq.float64->float F64 F] Transforms a primitive float on 64 bits to an
1199 % elpi one. Currently, it should not fail.
1200 external func coq.float64->float float64 -> float.
1201
1202 % [coq.float->float64 F F64] Transforms an elpi float F to a primitive float
1203 % on 64 bits. Currently, it should not fail.
1204 external func coq.float->float64 float -> float64.
1205
1206 % [coq.primitive.projection-unfolded P PU] Relates a primitive projection P
1207 % to its unfolded version PU. PU is still a primitive projection, but it is
1208 % displayed as a match and some Ltac code can see that.
1209 external func coq.primitive.projection-unfolded -> projection, projection.
1210
1211 % [coq.pstring->string PS S] Transforms a Coq primitive string to an elpi
1212 % string. It does not fail.
1213 external func coq.pstring->string pstring -> string.
1214
1215 % [coq.string->pstring S PS] Transforms an elpi string into a Coq primitive
1216 % string. It fails if the lenght of S is greater than the maximal primitive
1217 % string length.
1218 external func coq.string->pstring string -> pstring.
1219
1220
1221 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1222 % API for extra logical objects
1223 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1224
1225 % -- Databases (TC, CS, Coercions) ------------------------------------
1226
1227 % Pattern for canonical values
1228 kind cs-pattern type.
1229 external symbol cs-gref : gref -> cs-pattern = "1".
1230 external symbol cs-prod : cs-pattern = "1".
1231 external symbol cs-default : cs-pattern = "1".
1232 external symbol cs-sort : sort -> cs-pattern = "1".
1233
1234 % Canonical Structure instances: (cs-instance Proj ValPat Inst)
1235 kind cs-instance type.
1236 external symbol cs-instance : gref -> cs-pattern -> gref -> cs-instance = "1".
1237
1238 % [coq.CS.declare-instance GR] Declares GR as a canonical structure
1239 % instance.
1240 % Supported attributes:
1241 % - @local! (default: false)
1242 external func coq.CS.declare-instance gref.
1243
1244 % [coq.CS.db Db] reads all instances
1245 external func coq.CS.db -> list cs-instance.
1246
1247 % [coq.CS.db-for Proj Value Db] reads all instances for a given Projection
1248 % or canonical Value, or both
1249 external func coq.CS.db-for gref, cs-pattern -> list cs-instance.
1250
1251 % [coq.CS.canonical-projection? Projection] Tells if the projection can be
1252 % used for CS inference.
1253 external func coq.CS.canonical-projection? constant.
1254
1255 % [coq.TC.declare-class GR] Declare GR as a type class
1256 external func coq.TC.declare-class gref.
1257
1258 % [coq.elpi.toposort Graph Nodes in toposort order] takes a graph and
1259 % returns the nodes in topological order
1260 external func coq.elpi.toposort list (pair A (list A)) -> list A.
1261
1262 % Type class instance with priority
1263 kind tc-instance type.
1264 external symbol tc-instance : gref -> int -> tc-instance = "1".
1265
1266 % [coq.TC.declare-instance GR Priority] Declare GR as a Global type class
1267 % instance with Priority.
1268 % Supported attributes:
1269 % - @global! (default: true)
1270 external func coq.TC.declare-instance gref, int.
1271
1272 % [coq.TC.db Instances] reads all type class instances
1273 external func coq.TC.db -> list tc-instance.
1274
1275 % [coq.TC.db-tc TypeClasses] reads all type classes
1276 external func coq.TC.db-tc -> list gref.
1277
1278 % [coq.TC.db-for GR InstanceList] reads all instances of the given class GR.
1279 % Instances are in their precedence order.
1280 external func coq.TC.db-for gref -> list tc-instance.
1281
1282 % [coq.TC.get-inst-prio ClassGR InstGR InstPrio] reads the priority of an
1283 % instance
1284 external func coq.TC.get-inst-prio gref, gref -> int.
1285
1286 % [coq.TC.class? GR] checks if GR is a class
1287 external func coq.TC.class? gref.
1288
1289 % Node of the coercion graph
1290 kind class type.
1291 external symbol funclass : class = "1".
1292 external symbol sortclass : class = "1".
1293 external symbol grefclass : gref -> class = "1".
1294
1295 % Edge of the coercion graph
1296 kind coercion type.
1297 external symbol coercion : gref -> int -> gref -> class -> coercion = "2". % ref, nparams, src, tgt
1298
1299 % [coq.coercion.declare C] Declares C = (coercion GR NParams From To) as a
1300 % coercion From >-> To.
1301 % NParams can always be omitted, since it is inferred.
1302 % If From or To is unspecified, then the endpoints are inferred.
1303 % Supported attributes:
1304 % - @global! (default: false)
1305 % - @nonuniform! (default: false)
1306 % - @reversible! (default: false)
1307 external func coq.coercion.declare coercion.
1308
1309 % [coq.coercion.db L] reads all declared coercions
1310 external func coq.coercion.db -> list coercion.
1311
1312 % [coq.coercion.db-for From To L] L is a path From -> To
1313 external func coq.coercion.db-for class, class -> list (pair gref int).
1314
1315 % Deprecated, use coq.env.projections
1316 pred coq.CS.canonical-projections i:inductive, o:list (option constant).
1317 coq.CS.canonical-projections I L :-
1318 coq.warning "elpi.deprecated" "elpi.canonical-projections" "use coq.env.projections in place of coq.CS.canonical-projections",
1319 coq.env.projections I L.
1320
1321
1322 % -- Coq's Hint DB -------------------------------------
1323
1324 % Locality of hints is a delicate matter since the Coq default
1325 % is, in some cases, to make an hint active even if the module it belongs
1326 % to is not imported (just merely required, which can happen
1327 % transitively).
1328 % Coq is aiming at changing the default to #[export], that makes an
1329 % hint active only when its enclosing module is imported.
1330 % See:
1331 % https://coq.discourse.group/t/change-of-default-locality-for-hint-commands-in-coq-8-13/1140
1332 %
1333 % This old behavior is available via the @global! flag, but is discouraged.
1334 %
1335
1336 % Hint Mode
1337 kind hint-mode type.
1338 external symbol mode-ground : hint-mode = "1". % No Evar
1339 external symbol mode-input : hint-mode = "1". % No Head Evar
1340 external symbol mode-output : hint-mode = "1". % Anything
1341
1342 % [coq.hints.add-mode GR DB Mode] Adds a mode declaration to DB about
1343 % GR.
1344 % Supported attributes:
1345 % - @local! (default is export)
1346 % - @global! (discouraged, may become deprecated)
1347 external func coq.hints.add-mode gref, string, list hint-mode.
1348
1349 % [coq.hints.modes GR DB Modes] Gets all the mode declarations in DB about
1350 % GR
1351 external func coq.hints.modes gref, string -> list (list hint-mode).
1352
1353 % [coq.hints.set-opaque C DB Opaque] Like Hint Opaque C : DB (or Hint
1354 % Transparent, if the boolean is ff).
1355 % Supported attributes:
1356 % - @local! (default is export)
1357 % - @global! (discouraged, may become deprecated)
1358 external func coq.hints.set-opaque constant, string, bool.
1359
1360 % [coq.hints.opaque C DB Opaque] Reads if constant C is opaque (tt) or
1361 % transparent (ff) in DB
1362 external func coq.hints.opaque constant, string -> bool.
1363
1364 % [coq.hints.add-resolve GR DB Priority Pattern] Like Hint Resolve GR |
1365 % Priority Pattern : DB.
1366 % Supported attributes:
1367 % - @local! (default is export)
1368 % - @global! (discouraged, may become deprecated)
1369 external func coq.hints.add-resolve gref, string, int, term.
1370
1371 % -- Coq's notational mechanisms -------------------------------------
1372
1373 % Implicit status of an argument
1374 kind implicit_kind type.
1375 external symbol implicit : implicit_kind = "1". % regular implicit argument, eg Arguments foo [x]
1376 external symbol maximal : implicit_kind = "1". % maximally inserted implicit argument, eg Arguments foo {x}
1377 external symbol explicit : implicit_kind = "1". % explicit argument, eg Arguments foo x
1378
1379 % [coq.arguments.implicit GR Imps] reads the implicit arguments declarations
1380 % associated to a global reference. See also the [] and {} flags for the
1381 % Arguments command.
1382 external func coq.arguments.implicit gref -> list (list implicit_kind).
1383
1384 % [coq.arguments.set-implicit GR Imps] sets the implicit arguments
1385 % declarations associated to a global reference.
1386 % Unspecified means explicit.
1387 % See also the [] and {} flags for the Arguments command.
1388 % Supported attributes:
1389 % - @global! (default: false)
1390 external func coq.arguments.set-implicit gref, list (list implicit_kind).
1391
1392 % [coq.arguments.set-default-implicit GR] sets the default implicit
1393 % arguments declarations associated to a global reference.
1394 % See also the "default implicits" flag to the Arguments command.
1395 % Supported attributes:
1396 % - @global! (default: false)
1397 external func coq.arguments.set-default-implicit gref.
1398
1399 % [coq.arguments.name GR Names] reads the Names of the arguments of a global
1400 % reference. See also the (f (A := v)) syntax.
1401 external func coq.arguments.name gref -> list (option id).
1402
1403 % [coq.arguments.set-name GR Names] sets the Names of the arguments of a
1404 % global reference.
1405 % See also the :rename flag to the Arguments command.
1406 % Supported attributes:
1407 % - @global! (default: false)
1408 external func coq.arguments.set-name gref, list (option id).
1409
1410 % [coq.arguments.scope GR Scopes] reads the notation scope of the arguments
1411 % of a global reference. See also the %scope modifier for the Arguments
1412 % command
1413 external func coq.arguments.scope gref -> list (list id).
1414
1415 % [coq.arguments.set-scope GR Scopes] sets the notation scope of the
1416 % arguments of a global reference.
1417 % Scope can be a scope name or its delimiter.
1418 % See also the %scope modifier for the Arguments command.
1419 % Supported attributes:
1420 % - @global! (default: false)
1421 external func coq.arguments.set-scope gref, list (list id).
1422
1423 % Strategy for simplification tactics
1424 kind simplification_strategy type.
1425 external symbol never : simplification_strategy = "1". % Arguments foo : simpl never
1426 external symbol when : list int -> option int -> simplification_strategy = "1". % Arguments foo .. / .. ! ..
1427 external symbol when-nomatch : list int -> option int ->
1428 simplification_strategy = "1". % Arguments foo .. / .. ! .. : simpl nomatch
1429
1430 % [coq.arguments.simplification GR Strategy] reads the behavior of the
1431 % simplification tactics. Positions are 0 based. See also the ! and /
1432 % modifiers for the Arguments command
1433 external func coq.arguments.simplification gref -> option simplification_strategy.
1434
1435 % [coq.arguments.set-simplification GR Strategy] sets the behavior of the
1436 % simplification tactics.
1437 % Positions are 0 based.
1438 % See also the ! and / modifiers for the Arguments command.
1439 % Supported attributes:
1440 % - @global! (default: false)
1441 external func coq.arguments.set-simplification gref,
1442 simplification_strategy.
1443
1444 % [coq.arguments.reset-simplification GR] resets the behavior of the
1445 % simplification tactics.
1446 % Also resets the ! and / modifiers for the Arguments command.
1447 % Supported attributes:
1448 % - @global! (default: false)
1449 external func coq.arguments.reset-simplification gref.
1450
1451 % [coq.locate-abbreviation Name Abbreviation] locates an abbreviation. It's
1452 % a fatal error if Name cannot be located.
1453 external func coq.locate-abbreviation id -> abbreviation.
1454
1455 % Name of an abbreviation
1456 kind abbreviation type.
1457
1458
1459 % [coq.notation.add-abbreviation Name Nargs Body OnlyParsing Abbreviation]
1460 % Declares an abbreviation Name with Nargs arguments.
1461 % The term must begin with at least Nargs "fun" nodes whose domain is
1462 % ignored, eg (fun _ _ x\ fun _ _ y\ app[global "add",x,y]).
1463 % Supported attributes:
1464 % - @deprecated! (default: not deprecated)
1465 % - @warn! (default: no warning)
1466 % - @global! (default: false)
1467 external func coq.notation.add-abbreviation id, int, term,
1468 bool -> abbreviation.
1469
1470 % [coq.notation.abbreviation Abbreviation Args Body] Unfolds an abbreviation
1471 external func coq.notation.abbreviation abbreviation, list term -> term.
1472
1473 % [coq.notation.abbreviation-body Abbreviation Nargs Body] Retrieves the
1474 % body of an abbreviation
1475 external func coq.notation.abbreviation-body abbreviation -> int, term.
1476
1477 % [coq.notation.add-abbreviation-for-tactic Name TacticName FixedArgs]
1478 % Declares a parsing rule similar to
1479 % Notation Name X1..Xn := ltac:(elpi TacticName FixedArgs (X1)..(Xn))
1480 % so that Name can be used in the middle of a term to invoke an
1481 % elpi tactic. While FixedArgs can contain str, int, and trm all
1482 % other arguments will necessarily be terms, and their number is
1483 % not fixed (the user can pass as many as he likes).
1484 % The tactic receives as the elpi.loc attribute the precise location
1485 % at which the term is written (unlike if a regular abbreviation was
1486 % declared by hand).
1487 % A call to coq.notation.add-abbreviation-for-tactic TacName TacName []
1488 % is equivalent to Elpi Export TacName.
1489 external func coq.notation.add-abbreviation-for-tactic string, string,
1490 list argument.
1491
1492 % Generic attribute value
1493 kind attribute-value type.
1494 external symbol leaf-str : string -> attribute-value = "1".
1495 external symbol leaf-loc : loc -> attribute-value = "1".
1496 external symbol node : list attribute -> attribute-value = "1".
1497
1498 % Generic attribute
1499 kind attribute type.
1500 external symbol attribute : string -> attribute-value -> attribute = "1".
1501
1502 % -- Coq's pretyper ---------------------------------------------------
1503
1504 % [coq.sigma.print] Prints Coq's Evarmap and the mapping to/from Elpi's
1505 % unification variables
1506 external func coq.sigma.print.
1507
1508 % [coq.typecheck T Ty Diagnostic] typchecks a term T returning its type Ty.
1509 % If Ty is provided, then
1510 % the inferred type is unified (see unify-leq) with it.
1511 % Universe constraints are put in the constraint store.
1512 external func coq.typecheck term -> term, diagnostic.
1513
1514 % [coq.typecheck-ty Ty U Diagnostic] typchecks a type Ty returning its
1515 % universe U. If U is provided, then
1516 % the inferred universe is unified (see unify-leq) with it.
1517 % Universe constraints are put in the constraint store.
1518 external func coq.typecheck-ty term -> sort, diagnostic.
1519
1520 % [coq.unify-eq A B Diagnostic] unifies the two terms
1521 external func coq.unify-eq term, term -> diagnostic.
1522
1523 % [coq.unify-leq A B Diagnostic] unifies the two terms (with cumulativity,
1524 % if they are types)
1525 external func coq.unify-leq term, term -> diagnostic.
1526
1527 % [coq.elaborate-skeleton T ETy E Diagnostic] elaborates T against the
1528 % expected type ETy.
1529 % T is allowed to contain holes (unification variables) but these are
1530 % not assigned even if the elaborated term has a term in place of the
1531 % hole. Similarly universe levels present in T are disregarded.
1532 % Supported attributes:
1533 % - @keepunivs! (default false, do not disregard universe levels)
1534 % - @no-tc! (default false, do not infer typeclasses)
1535 external func coq.elaborate-skeleton term -> term, term, diagnostic.
1536
1537 % [coq.elaborate-ty-skeleton T U E Diagnostic] elaborates T expecting it to
1538 % be a type of sort U.
1539 % T is allowed to contain holes (unification variables) but these are
1540 % not assigned even if the elaborated term has a term in place of the
1541 % hole. Similarly universe levels present in T are disregarded.
1542 % Supported attributes:
1543 % - @keepunivs! (default false, do not disregard universe levels)
1544 % - @no-tc! (default false, do not infer typeclasses)
1545 external func coq.elaborate-ty-skeleton term -> sort, term, diagnostic.
1546
1547 % -- Coq's reduction flags ------------------------------------
1548
1549 % Flags for lazy, cbv, ... reductions
1550 kind coq.redflag type.
1551 external symbol coq.redflags.beta : coq.redflag = "2".
1552 external symbol coq.redflags.delta : coq.redflag = "2". % if set then coq.redflags.const disables unfolding
1553 external symbol coq.redflags.match : coq.redflag = "1".
1554 external symbol coq.redflags.fix : coq.redflag = "1".
1555 external symbol coq.redflags.cofix : coq.redflag = "1".
1556 external symbol coq.redflags.zeta : coq.redflag = "2".
1557 external symbol coq.redflags.const : constant -> coq.redflag = "1". % enable/disable unfolding
1558 external symbol coq.redflags.proj : projection -> coq.redflag = "1". % enable/disable unfolding
1559
1560 % Set of flags for lazy, cbv, ... reductions
1561 kind coq.redflags type.
1562
1563 external symbol coq.redflags.nored : coq.redflags = "1".
1564 external symbol coq.redflags.zeta : coq.redflags = "1".
1565 external symbol coq.redflags.delta : coq.redflags = "1".
1566 external symbol coq.redflags.betazeta : coq.redflags = "1".
1567 external symbol coq.redflags.betaiotazeta : coq.redflags = "1".
1568 external symbol coq.redflags.betaiota : coq.redflags = "1".
1569 external symbol coq.redflags.betadeltazeta : coq.redflags = "1".
1570 external symbol coq.redflags.beta : coq.redflags = "1".
1571 external symbol coq.redflags.allnolet : coq.redflags = "1".
1572 external symbol coq.redflags.all : coq.redflags = "1".
1573
1574 % [coq.redflags.add Flags Options NewFlags] Updates reduction Flags by
1575 % adding Options
1576 external func coq.redflags.add coq.redflags,
1577 list coq.redflag -> coq.redflags.
1578
1579 % [coq.redflags.sub Flags Options NewFlags] Updates reduction Flags by
1580 % removing Options
1581 external func coq.redflags.sub coq.redflags,
1582 list coq.redflag -> coq.redflags.
1583
1584 % -- Coq's reduction machines ------------------------------------
1585
1586 % [coq.reduction.lazy.whd T Tred] Puts T in weak head normal form.
1587 % Supported attributes:
1588 % - @redflags! (default coq.redflags.all)
1589 external func coq.reduction.lazy.whd term -> term.
1590
1591 % [coq.reduction.lazy.norm T Tred] Puts T in normal form.
1592 % Supported attributes:
1593 % - @redflags! (default coq.redflags.all)
1594 external func coq.reduction.lazy.norm term -> term.
1595
1596 % [coq.reduction.lazy.bi-norm T Tred] Puts T in normal form only reducing
1597 % beta and iota redexes
1598 external func coq.reduction.lazy.bi-norm term -> term.
1599
1600 % [coq.reduction.cbv.norm T Tred] Puts T in normal form using the call by
1601 % value strategy.
1602 % Supported attributes:
1603 % - @redflags! (default coq.redflags.all)
1604 external func coq.reduction.cbv.norm term -> term.
1605
1606 % [coq.reduction.vm.norm T Ty Tred] Puts T in normal form using
1607 % [vm_compute]'s machinery. Its type Ty can be omitted (but is recomputed)
1608 external func coq.reduction.vm.norm term, term -> term.
1609
1610 % [coq.reduction.native.norm T Ty Tred] Puts T in normal form using
1611 % [native_compute]'s machinery. Its type Ty can be omitted (but is
1612 % recomputed). Falls back to vm.norm if native compilation is not available.
1613 external func coq.reduction.native.norm term, term -> term.
1614
1615 % [coq.reduction.native.available?] Is native compilation available on this
1616 % system/configuration?
1617 external func coq.reduction.native.available?.
1618
1619 % Deprecated, use coq.reduction.cbv.norm
1620 pred coq.reduction.cbv.whd_all i:term, o:term.
1621 coq.reduction.cbv.whd_all T R :-
1622 coq.warning "elpi.deprecated" "elpi.cbv-whd-all" "use coq.reduction.cbv.norm in place of coq.reduction.cbv.whd_all",
1623 coq.reduction.cbv.norm T R.
1624
1625
1626 % Deprecated, use coq.reduction.vm.norm
1627 pred coq.reduction.vm.whd_all i:term, i:term, o:term.
1628 coq.reduction.vm.whd_all T TY R :-
1629 coq.warning "elpi.deprecated" "elpi.vm-whd-all" "use coq.reduction.vm.norm in place of coq.reduction.vm.whd_all",
1630 coq.reduction.vm.norm T TY R.
1631
1632
1633
1634 func coq.reduction.lazy.whd_all term -> term.
1635 coq.reduction.lazy.whd_all X Y :-
1636 @redflags! coq.redflags.all => coq.reduction.lazy.whd X Y.
1637
1638
1639 % [coq.reduction.eta-contract T Tred] Removes all eta expansions from T
1640 external func coq.reduction.eta-contract term -> term.
1641
1642 % -- Coq's conversion strategy tweaks --------------------------
1643
1644 % Strategy for conversion test
1645 % expand < ... < level -1 < level 0 < level 1 < ... < opaque
1646 kind conversion_strategy type.
1647 external symbol opaque : conversion_strategy = "1".
1648 external symbol expand : conversion_strategy = "1".
1649 external symbol level : int -> conversion_strategy = "1". % default is 0, aka transparent
1650
1651 % [coq.strategy.set CL Level] Sets the unfolding priority for all the
1652 % constants in the list CL. See the command Strategy.
1653 external func coq.strategy.set list constant, conversion_strategy.
1654
1655 % [coq.strategy.get C Level] Gets the unfolding priority for C
1656 external func coq.strategy.get constant -> conversion_strategy.
1657
1658 % -- Coq's tactics --------------------------------------------
1659
1660 % LTac1 tactic expression
1661 kind ltac1-tactic type.
1662
1663
1664 % [coq.ltac.fail Level ...] Interrupts the Elpi program and calls Ltac's
1665 % fail Level Msg, where Msg is the printing of the remaining arguments.
1666 % Level can be left unspecified and defaults to 0
1667 external type coq.ltac.fail int -> variadic any (func).
1668
1669 % [coq.ltac.collect-sealed-goals T Goals ShelvedGoals]
1670 % Turns the holes in T into Goals.
1671 % Goals are closed with nablas.
1672 % ShelvedGoals are goals which can be solved by side effect (they occur
1673 % in the type of the other goals).
1674 % The order of Goals is given by the traversal order of EConstr.fold
1675 % (a
1676 % fold_left over the terms, letin body comes before the type).
1677 %
1678 external func coq.ltac.collect-sealed-goals term -> list sealed-goal,
1679 list sealed-goal.
1680
1681
1682 func coq.ltac.collect-goals term -> list sealed-goal, list sealed-goal.
1683 coq.ltac.collect-goals T GA GB :- coq.ltac.collect-sealed-goals T GA GB.
1684
1685
1686 % [coq.ltac.collect-simple-goals T Goals ShelvedGoals] Like
1687 % coq.ltac.collect-sealed-goals turns the holes in T into
1688 % Goals but fails if the goals do not live in the current proof context.
1689 %
1690 external func coq.ltac.collect-simple-goals term -> list goal,
1691 list sealed-goal.
1692
1693 % [coq.ltac.call-mltac PluginName BlockName BlockIndex G GL Diagnostic]
1694 % Calls OCaml code bound via TACTIC EXTEND. For example the
1695 % OCaml code for lia looks like:
1696 %
1697 % DECLARE PLUGIN "rocq-runtime.plugins.micromega"
1698 % ...
1699 % TACTIC EXTEND Lia
1700 % | [ "xlia" tactic(t) ] -> { Coq_micromega.xlia
1701 % (Tacinterp.tactic_of_value ist t) }
1702 % END
1703 %
1704 % In order to call the code between curly braces one has to run
1705 %
1706 % coq.ltac.call-mltac "rocq-runtime.plugins.micromega" "Lia" 0 G GL
1707 %
1708 % Note that each TACTIC EXTEND block can have many entries and their
1709 % numbering
1710 % starts from 0. Also, each block has a name, "Lia" in this case.
1711 %
1712 % When the diagnostic is (error Msg), then GL is not set.
1713 %
1714 % Supported attributes:
1715 % - @no-tc! (default false, do not infer typeclasses)
1716 external func coq.ltac.call-mltac string, string, int,
1717 goal -> list sealed-goal, diagnostic.
1718
1719 % [coq.ltac.call-simple-mltac PluginName BlockName BlockIndex G GL
1720 % Diagnostic] Like coq.ltac.call-mltac but Tac is not allowed to
1721 % generate new goals GL in different contexts. For example "intro" does
1722 % not
1723 % obey this restriction.
1724 %
1725 % Supported attributes:
1726 % - @no-tc! (default false, do not infer typeclasses)
1727 external func coq.ltac.call-simple-mltac string, string, int,
1728 goal -> list goal, diagnostic.
1729
1730 % [coq.ltac.call-ltac1 Tac G GL ...] Calls Ltac1 tactic Tac on goal G
1731 % (passing the arguments of G, see coq.ltac.call for a handy wrapper).
1732 % It accepts one diagnostic argument, defaults to ok if omitted.
1733 % Tac can either be a string (the tactic name), or a value
1734 % of type ltac1-tactic, see the tac argument constructor
1735 % and the ltac_tactic:(...) syntax to pass arguments to
1736 % an elpi tactic.
1737 % Caveat:
1738 % if Tac is a tactic name, then the tactic must be defined using
1739 % "Ltac name := body", it cannot be a builtin one. For example
1740 % "Ltac myapply x := apply x." lets one call apply by running
1741 % coq.ltac.call-ltac1 "myapply" G GL.
1742 %
1743 % When the diagnostic is (error Msg), then GL is not set.
1744 %
1745 % Supported attributes:
1746 % - @no-tc! (default false, do not infer typeclasses)
1747 external func coq.ltac.call-ltac1 any, goal -> list sealed-goal,
1748 diagnostic.. .
1749
1750 % [coq.ltac.call-simple-ltac1 Tac G GL Diagnostic] Like coq.ltac.call-ltac1
1751 % but Tac is not allowed to
1752 % generate new goals GL in different contexts. For example "intro" does
1753 % not
1754 % obey this restriction.
1755 %
1756 % Supported attributes:
1757 % - @no-tc! (default false, do not infer typeclasses)
1758 external func coq.ltac.call-simple-ltac1 any, goal -> list goal,
1759 diagnostic.
1760
1761 % [coq.ltac.id-free? ID G]
1762 % Fails if ID is already used in G. Note that ids which are taken are
1763 % renamed
1764 % on the fly (since in the HOAS of terms, names are just pretty printing
1765 % hints), but for the ergonomy of a tactic it may help to know if an
1766 % hypothesis name is already taken.
1767 %
1768 external func coq.ltac.id-free? id, goal.
1769
1770 % [coq.ltac.fresh-id Default Ty FreshID] TODO
1771 external func coq.ltac.fresh-id id, term -> id.
1772
1773 % -- Coq's options system --------------------------------------------
1774
1775 % Coq option value
1776 kind coq.option type.
1777 external symbol coq.option.int : option int -> coq.option = "1". % none means unset
1778 external symbol coq.option.string : option string -> coq.option = "1". % none means unset
1779 external symbol coq.option.bool : bool -> coq.option = "1".
1780
1781 % [coq.option.get Option Value] reads Option. Reading a non existing option
1782 % is a fatal error.
1783 external func coq.option.get list string -> coq.option.
1784
1785 % [coq.option.set Option Value] writes Option. Writing a non existing option
1786 % is a fatal error.
1787 external func coq.option.set list string, coq.option.
1788
1789 % [coq.option.available? Option Deprecated] checks if Option exists and
1790 % tells if is deprecated (tt) or not (ff)
1791 external func coq.option.available? list string -> bool.
1792
1793 % [coq.option.add Option Value Deprecated]
1794 % adds a new option to Coq setting its current value (and type).
1795 % Deprecated can be left unspecified and defaults to ff.
1796 % This call cannot be undone in a Coq interactive session, use it once
1797 % and for all in a .v file which your clients will load. Eg.
1798 %
1799 % Elpi Query lp:{{ coq.option.add ... }}.
1800 %
1801 %
1802 external func coq.option.add list string, coq.option, bool.
1803
1804 % -- Datatypes conversions --------------------------------------------
1805
1806 % Name.Name.t: Name hints (in binders), can be input writing a name
1807 % between backticks, e.g. `x` or `_` for anonymous. Important: these are
1808 % just printing hints with no meaning, hence in elpi two name are always
1809 % related: `x` = `y`
1810 kind name type.
1811
1812
1813 % [coq.name-suffix Name Suffix NameSuffix] suffixes a Name with a string or
1814 % an int or another name
1815 external func coq.name-suffix name, any -> name.
1816
1817 % [coq.string->name Hint Name] creates a name hint using a relevance
1818 % variable
1819 external func coq.string->name string -> name.
1820
1821 % [coq.string->name-relevant Hint Name] creates a name hint with the
1822 % relevant mark (see SProp)
1823 external func coq.string->name-relevant string -> name.
1824
1825
1826 func coq.id->name id -> name.
1827 coq.id->name S N :- coq.string->name-relevant S N.
1828
1829
1830 % [coq.name->id Name Id] tuns a pretty printing hint into a string. This API
1831 % is for internal use, no guarantee on its behavior.
1832 external func coq.name->id name -> id.
1833
1834 % [coq.name.relevant? Name Relevance] Reads the relevance mark. none means
1835 % unset, some tt means relevant.
1836 external func coq.name.relevant? name -> option bool.
1837
1838 % [coq.gref->id GR Id] extracts the label (last component of a full kernel
1839 % name)
1840 external func coq.gref->id gref -> id.
1841
1842 % [coq.gref->string GR FullPath] extract the full kernel name
1843 external func coq.gref->string gref -> string.
1844
1845 % [coq.gref->path GR FullPath] extract the full path (kernel name without
1846 % final id), each component is a separate list item
1847 external func coq.gref->path gref -> list string.
1848
1849 % [coq.modpath->path MP FullPath] extract the full kernel name, each
1850 % component is a separate list item
1851 external func coq.modpath->path modpath -> list string.
1852
1853 % [coq.modtypath->path MTP FullPath] extract the full kernel name, each
1854 % component is a separate list item
1855 external func coq.modtypath->path modtypath -> list string.
1856
1857 % [coq.modpath->library MP LibraryPath] extract the enclosing module which
1858 % can be Required
1859 external func coq.modpath->library modpath -> modpath.
1860
1861 % [coq.modtypath->library MTP LibraryPath] extract the enclosing module
1862 % which can be Required
1863 external func coq.modtypath->library modtypath -> modpath.
1864
1865 % [coq.term->string T S] prints a term T to a string S using Coq's pretty
1866 % printer
1867 % Supported attributes:
1868 % - @ppwidth! N (default 80, max line length)
1869 % - @ppall! (default: false, prints all details)
1870 % - @ppmost! (default: false, prints most details)
1871 % - @pplevel! (default: _, prints parentheses to reach that level, 200 =
1872 % off)
1873 % - @holes! (default: false, prints evars as _)
1874 external func coq.term->string term -> string.
1875
1876 % [coq.term->pp T B] prints a term T to a pp.t B using Coq's pretty
1877 % printer"
1878 % Supported attributes:
1879 % - @ppall! (default: false, prints all details)
1880 % - @ppmost! (default: false, prints most details)
1881 % - @pplevel! (default: _, prints parentheses to reach that level, 200 =
1882 % off)
1883 % - @holes! (default: false, prints evars as _)
1884 external func coq.term->pp term -> coq.pp.
1885
1886 % [coq.goal->pp G B] prints a goal G to a pp.t B using Coq's pretty
1887 % printer"
1888 % Supported attributes:
1889 % - @ppall! (default: false, prints all details)
1890 % - @ppmost! (default: false, prints most details)
1891 % - @pplevel! (default: _, prints parentheses to reach that level, 200 =
1892 % off)
1893 % - @holes! (default: false, prints evars as _)
1894 external func coq.goal->pp goal -> coq.pp.
1895
1896 % -- Register -----------------------------------------------
1897
1898 % Coq scheme kind (currently undocumented in Rocq)
1899 kind coq.register.scheme-kind type.
1900 external symbol coq.register.scheme.rect_dep : coq.register.scheme-kind = "1".
1901 external symbol coq.register.scheme.rec_dep : coq.register.scheme-kind = "1".
1902 external symbol coq.register.scheme.ind_dep : coq.register.scheme-kind = "1".
1903 external symbol coq.register.scheme.sind_dep : coq.register.scheme-kind = "1".
1904 external symbol coq.register.scheme.rect_nodep : coq.register.scheme-kind = "1".
1905 external symbol coq.register.scheme.rec_nodep : coq.register.scheme-kind = "1".
1906 external symbol coq.register.scheme.ind_nodep : coq.register.scheme-kind = "1".
1907 external symbol coq.register.scheme.sind_nodep : coq.register.scheme-kind = "1".
1908 external symbol coq.register.scheme.case_dep : coq.register.scheme-kind = "1".
1909 external symbol coq.register.scheme.case_nodep : coq.register.scheme-kind = "1".
1910 external symbol coq.register.scheme.casep_dep : coq.register.scheme-kind = "1".
1911 external symbol coq.register.scheme.casep_nodep : coq.register.scheme-kind = "1".
1912 external symbol coq.register.scheme.sym_internal : coq.register.scheme-kind = "1".
1913 external symbol coq.register.scheme.sym_involutive : coq.register.scheme-kind = "1".
1914 external symbol coq.register.scheme.rew_r_dep : coq.register.scheme-kind = "1".
1915 external symbol coq.register.scheme.rew_dep : coq.register.scheme-kind = "1".
1916 external symbol coq.register.scheme.rew_fwd_dep : coq.register.scheme-kind = "1".
1917 external symbol coq.register.scheme.rew_fwd_r_dep : coq.register.scheme-kind = "1".
1918 external symbol coq.register.scheme.rew_r : coq.register.scheme-kind = "1".
1919 external symbol coq.register.scheme.rew : coq.register.scheme-kind = "1".
1920 external symbol coq.register.scheme.congr : coq.register.scheme-kind = "1".
1921 external symbol coq.register.scheme.beq : coq.register.scheme-kind = "1".
1922 external symbol coq.register.scheme.dec_bl : coq.register.scheme-kind = "1".
1923 external symbol coq.register.scheme.dec_lb : coq.register.scheme-kind = "1".
1924 external symbol coq.register.scheme.eq_dec : coq.register.scheme-kind = "1".
1925 external symbol coq.register.scheme.other : string ->
1926 coq.register.scheme-kind = "1".
1927
1928 % Coq register value
1929 kind coq.register type.
1930 external symbol coq.register.inline : coq.register = "1".
1931 external symbol coq.register.lib : string -> coq.register = "1".
1932 external symbol coq.register.scheme : gref -> coq.register.scheme-kind ->
1933 coq.register = "1".
1934
1935 % [coq.register GR R] Registers GR as R (See Register Inline, Register
1936 % Scheme)
1937 external func coq.register gref, coq.register.
1938
1939 % [coq.scheme Kind GR Scheme] looks up the scheme of the given kind for GR.
1940 % Returns none if GR is not an inductive or no such scheme is registered.
1941 external func coq.scheme coq.register.scheme-kind, gref -> option gref.
1942
1943 % -- Extra Dependencies -----------------------------------------------
1944
1945 % [coq.extra-dep Identifier FileName] Resolve the file name of an extra
1946 % dependency. See also Coq's From xxx Extra Dependency yyy as zzz.
1947 external func coq.extra-dep id -> option id.
1948
1949 % -- Access to Elpi's data --------------------------------------------
1950
1951 % clauses
1952 %
1953 % A clause like
1954 % :name "foo" :before "bar" foo X Y :- bar X Z, baz Z Y
1955 % is represented as
1956 % clause "foo" (before "bar") (pi x y z\ foo x y :- bar x z, baz z y)
1957 % that is exactly what one would load in the context using =>.
1958 %
1959 % The name and the grafting specification can be left unspecified.
1960 kind clause type.
1961 external symbol clause : id -> grafting -> prop -> clause = "1".
1962
1963 % Specify if the clause has to be grafted before, grafted after or replace
1964 % a named clause
1965 kind grafting type.
1966 external symbol before : id -> grafting = "1".
1967 external symbol after : id -> grafting = "1".
1968 external symbol remove : id -> grafting = "1".
1969 external symbol replace : id -> grafting = "1".
1970
1971 % Specify to which module the clause should be attached to
1972 kind scope type.
1973 external symbol execution-site : scope = "1". % The module inside which the Elpi program is run
1974 external symbol current : scope = "1". % The module being defined (see begin/end-module)
1975 external symbol library : scope = "1". % The outermost module (carrying the file name)
1976
1977
1978 % see coq.elpi.accumulate-clauses
1979 :index (1)
1980 func coq.elpi.accumulate scope, id, clause.
1981 coq.elpi.accumulate S N C :- coq.elpi.accumulate-clauses S N [C].
1982
1983
1984 % [coq.elpi.accumulate-clauses Scope DbName Clauses]
1985 % Declare that the given clauses have to be added to the given db (see Elpi
1986 % Db).
1987 % Clauses usually belong to Coq modules: the Scope argument lets one
1988 % select which module:
1989 % - execution site (default) is the module in which the program is
1990 % invoked, the clauses will be accumulated when the execution of the
1991 % program ends
1992 % - current is the module currently being constructed (see
1993 % begin/end-module), the clauses will be accumulated when the execution of
1994 % the program ends
1995 % or the start of another program (whichever comes first)
1996 % - library is the current file (the module that is named after the file),
1997 % the clauses will be accumulated when the execution of the program
1998 % ends
1999 % The clauses are visible as soon as the enclosing module is Imported.
2000 % A clause that mentions a section variable is automatically discarded
2001 % at the end of the section.
2002 % Clauses cannot be accumulated inside functors.
2003 % Supported attributes:
2004 % - @local! (default: false, discard at the end of section or module)
2005 % - @global! (default: false, always active, only if Scope is
2006 % execution-site, discouraged)
2007 external func coq.elpi.accumulate-clauses scope, id, list clause.
2008
2009 % Specify if a predicate argument is in input or output mode
2010 kind argument_mode type.
2011 external symbol in : argument_mode = "1".
2012 external symbol out : argument_mode = "1".
2013
2014 % [coq.elpi.add-predicate Db Indexing PredName Spec] Declares a new
2015 % predicate PredName in the data base Db.
2016 % Indexing can be left unspecified. Spec gathers a mode and a
2017 % type for each argument. CAVEAT: types and indexing are strings
2018 % instead of proper data types; beware parsing errors are fatal.
2019 % Supported attributes:
2020 % - @local! (default: false, discard at the end of section or module)
2021 % - @global! (default: false, always active
2022 external func coq.elpi.add-predicate string, string, string,
2023 list (pair argument_mode string).
2024
2025 % [coq.elpi.predicate? PredName] Tells if a predicate called PredName exists
2026 external func coq.elpi.predicate? string.
2027
2028 % [coq.elpi.predicate PredName Args Pred] Pred is the application of
2029 % PredName to Args
2030 external func coq.elpi.predicate string, list any -> prop.
2031
2032 % -- Synterp ----------------------------------------------------------
2033
2034 % Action executed during the parsing phase (aka synterp)
2035 kind synterp-action type.
2036 external symbol begin-module : id -> synterp-action = "1".
2037 external symbol begin-module-type : id -> synterp-action = "1".
2038 external symbol begin-section : id -> synterp-action = "1".
2039 external symbol end-module : modpath -> synterp-action = "1".
2040 external symbol end-module-type : modtypath -> synterp-action = "1".
2041 external symbol end-section : synterp-action = "1".
2042 external symbol apply-module-functor : id -> synterp-action = "1".
2043 external symbol apply-module-type-functor : id -> synterp-action = "1".
2044 external symbol include-module : modpath -> synterp-action = "1".
2045 external symbol include-module-type : modtypath -> synterp-action = "1".
2046 external symbol import-module : modpath -> synterp-action = "1".
2047 external symbol export-module : modpath -> synterp-action = "1".
2048
2049 % Synterp action group
2050 kind group type.
2051
2052
2053 % [coq.next-synterp-action A] Get the next action performed during parsing
2054 % (aka synterp), that is also the next action to be performed during
2055 % execution (aka interp). See also coq.replay-synterp-action
2056 external func coq.next-synterp-action -> synterp-action.
2057
2058 % [coq.replay-synterp-action-group ID] Execute all actions of synterp action
2059 % group ID. ID must be the name of the next group, it must not be opened
2060 % already, and there must not be any actions before it.
2061 external func coq.replay-synterp-action-group id.
2062
2063 % [coq.begin-synterp-group ID Group] Match a begin-synterp-group synterp
2064 % operation. ID must be the name of the next synterp action group and there
2065 % must not be any actions before it.
2066 external func coq.begin-synterp-group id -> group.
2067
2068 % [coq.end-synterp-group Group] Match a end-synterp-group synterp operation.
2069 % Group must be the currently opened synterp action group and the group must
2070 % not have any more synterp actions or groups left to replay.
2071 external func coq.end-synterp-group group.
2072
2073 % -- Utils ------------------------------------------------------------
2074
2075 kind coq.gref.set type.
2076
2077 % [coq.gref.set.empty A] The empty set
2078 external func coq.gref.set.empty -> coq.gref.set.
2079
2080 % [coq.gref.set.mem Elem A] Checks if Elem is in a
2081 external func coq.gref.set.mem gref, coq.gref.set.
2082
2083 % [coq.gref.set.add Elem A B] B is A union {Elem}
2084 external func coq.gref.set.add gref, coq.gref.set -> coq.gref.set.
2085
2086 % [coq.gref.set.remove Elem A B] B is A \ {Elem}
2087 external func coq.gref.set.remove gref, coq.gref.set -> coq.gref.set.
2088
2089 % [coq.gref.set.union A B X] X is A union B
2090 external func coq.gref.set.union coq.gref.set,
2091 coq.gref.set -> coq.gref.set.
2092
2093 % [coq.gref.set.inter A B X] X is A intersection B
2094 external func coq.gref.set.inter coq.gref.set,
2095 coq.gref.set -> coq.gref.set.
2096
2097 % [coq.gref.set.diff A B X] X is A \ B
2098 external func coq.gref.set.diff coq.gref.set,
2099 coq.gref.set -> coq.gref.set.
2100
2101 % [coq.gref.set.equal A B] tests A and B for equality
2102 external func coq.gref.set.equal coq.gref.set, coq.gref.set.
2103
2104 % [coq.gref.set.subset A B] tests if A is a subset of B
2105 external func coq.gref.set.subset coq.gref.set, coq.gref.set.
2106
2107 % [coq.gref.set.elements M L] L is M transformed into list
2108 external func coq.gref.set.elements coq.gref.set -> list gref.
2109
2110 % [coq.gref.set.choose M X] X is an element of M
2111 external func coq.gref.set.choose coq.gref.set -> gref.
2112
2113 % [coq.gref.set.min M X] X is the smallest element of M
2114 external func coq.gref.set.min coq.gref.set -> gref.
2115
2116 % [coq.gref.set.max M X] X is the bigger of M
2117 external func coq.gref.set.max coq.gref.set -> gref.
2118
2119 % [coq.gref.set.cardinal M N] N is the number of elements of M
2120 external func coq.gref.set.cardinal coq.gref.set -> int.
2121
2122 % [coq.gref.set.filter M F M1] Filter M w.r.t. the predicate F
2123 external func coq.gref.set.filter coq.gref.set,
2124 (gref -> (func)) -> coq.gref.set.
2125
2126 % [coq.gref.set.map M F M1] Map M w.r.t. the predicate F
2127 external func coq.gref.set.map coq.gref.set,
2128 (gref -> gref -> prop) -> coq.gref.set.
2129
2130 % [coq.gref.set.fold M Acc F Acc1] fold M w.r.t. the predicate F
2131 external func coq.gref.set.fold coq.gref.set, A,
2132 (gref -> A -> A -> prop) -> A.
2133
2134 % [coq.gref.set.partition M F M1 M2] Partitions M w.r.t. the predicate F, M1
2135 % is where F holds
2136 external func coq.gref.set.partition coq.gref.set,
2137 (gref -> (func)) -> coq.gref.set,
2138 coq.gref.set.
2139
2140 % CAVEAT: the type parameter of coq.gref.map must be a closed term
2141
2142 kind coq.gref.map type -> type.
2143
2144 % [coq.gref.map.empty M] The empty map
2145 external func coq.gref.map.empty -> coq.gref.map A.
2146
2147 % [coq.gref.map.mem S M] Checks if S is bound in M
2148 external func coq.gref.map.mem gref, coq.gref.map A.
2149
2150 % [coq.gref.map.add S V M M1] M1 is M where V is bound to S
2151 external func coq.gref.map.add gref, A, coq.gref.map A -> coq.gref.map A.
2152
2153 % [coq.gref.map.remove S M M1] M1 is M where S is unbound
2154 external func coq.gref.map.remove gref, coq.gref.map A -> coq.gref.map A.
2155
2156 % [coq.gref.map.find S M V] V is the binding of S in M
2157 external func coq.gref.map.find gref, coq.gref.map A -> A.
2158
2159 % [coq.gref.map.bindings M L] L is M transformed into an associative list
2160 external func coq.gref.map.bindings coq.gref.map A -> list (pair gref A).
2161
2162 % [coq.gref.map.filter M F M1] Filter M w.r.t. the predicate F
2163 external func coq.gref.map.filter coq.gref.map A,
2164 (gref -> A -> prop) -> coq.gref.map A.
2165
2166 % [coq.gref.map.map M F M1] Map M w.r.t. the predicate F
2167 external func coq.gref.map.map coq.gref.map A,
2168 (gref -> A -> B -> prop) -> coq.gref.map B.
2169
2170 % [coq.gref.map.fold M Acc F Acc1] fold M w.r.t. the predicate F
2171 external func coq.gref.map.fold coq.gref.map A, C,
2172 (gref -> A -> C -> C -> prop) -> C.
2173
2174 kind coq.univ.set type.
2175
2176 % [coq.univ.set.empty A] The empty set
2177 external func coq.univ.set.empty -> coq.univ.set.
2178
2179 % [coq.univ.set.mem Elem A] Checks if Elem is in a
2180 external func coq.univ.set.mem univ, coq.univ.set.
2181
2182 % [coq.univ.set.add Elem A B] B is A union {Elem}
2183 external func coq.univ.set.add univ, coq.univ.set -> coq.univ.set.
2184
2185 % [coq.univ.set.remove Elem A B] B is A \ {Elem}
2186 external func coq.univ.set.remove univ, coq.univ.set -> coq.univ.set.
2187
2188 % [coq.univ.set.union A B X] X is A union B
2189 external func coq.univ.set.union coq.univ.set,
2190 coq.univ.set -> coq.univ.set.
2191
2192 % [coq.univ.set.inter A B X] X is A intersection B
2193 external func coq.univ.set.inter coq.univ.set,
2194 coq.univ.set -> coq.univ.set.
2195
2196 % [coq.univ.set.diff A B X] X is A \ B
2197 external func coq.univ.set.diff coq.univ.set,
2198 coq.univ.set -> coq.univ.set.
2199
2200 % [coq.univ.set.equal A B] tests A and B for equality
2201 external func coq.univ.set.equal coq.univ.set, coq.univ.set.
2202
2203 % [coq.univ.set.subset A B] tests if A is a subset of B
2204 external func coq.univ.set.subset coq.univ.set, coq.univ.set.
2205
2206 % [coq.univ.set.elements M L] L is M transformed into list
2207 external func coq.univ.set.elements coq.univ.set -> list univ.
2208
2209 % [coq.univ.set.choose M X] X is an element of M
2210 external func coq.univ.set.choose coq.univ.set -> univ.
2211
2212 % [coq.univ.set.min M X] X is the smallest element of M
2213 external func coq.univ.set.min coq.univ.set -> univ.
2214
2215 % [coq.univ.set.max M X] X is the bigger of M
2216 external func coq.univ.set.max coq.univ.set -> univ.
2217
2218 % [coq.univ.set.cardinal M N] N is the number of elements of M
2219 external func coq.univ.set.cardinal coq.univ.set -> int.
2220
2221 % [coq.univ.set.filter M F M1] Filter M w.r.t. the predicate F
2222 external func coq.univ.set.filter coq.univ.set,
2223 (univ -> (func)) -> coq.univ.set.
2224
2225 % [coq.univ.set.map M F M1] Map M w.r.t. the predicate F
2226 external func coq.univ.set.map coq.univ.set,
2227 (univ -> univ -> prop) -> coq.univ.set.
2228
2229 % [coq.univ.set.fold M Acc F Acc1] fold M w.r.t. the predicate F
2230 external func coq.univ.set.fold coq.univ.set, A,
2231 (univ -> A -> A -> prop) -> A.
2232
2233 % [coq.univ.set.partition M F M1 M2] Partitions M w.r.t. the predicate F, M1
2234 % is where F holds
2235 external func coq.univ.set.partition coq.univ.set,
2236 (univ -> (func)) -> coq.univ.set,
2237 coq.univ.set.
2238
2239 % CAVEAT: the type parameter of coq.univ.map must be a closed term
2240
2241 kind coq.univ.map type -> type.
2242
2243 % [coq.univ.map.empty M] The empty map
2244 external func coq.univ.map.empty -> coq.univ.map A.
2245
2246 % [coq.univ.map.mem S M] Checks if S is bound in M
2247 external func coq.univ.map.mem univ, coq.univ.map A.
2248
2249 % [coq.univ.map.add S V M M1] M1 is M where V is bound to S
2250 external func coq.univ.map.add univ, A, coq.univ.map A -> coq.univ.map A.
2251
2252 % [coq.univ.map.remove S M M1] M1 is M where S is unbound
2253 external func coq.univ.map.remove univ, coq.univ.map A -> coq.univ.map A.
2254
2255 % [coq.univ.map.find S M V] V is the binding of S in M
2256 external func coq.univ.map.find univ, coq.univ.map A -> A.
2257
2258 % [coq.univ.map.bindings M L] L is M transformed into an associative list
2259 external func coq.univ.map.bindings coq.univ.map A -> list (pair univ A).
2260
2261 % [coq.univ.map.filter M F M1] Filter M w.r.t. the predicate F
2262 external func coq.univ.map.filter coq.univ.map A,
2263 (univ -> A -> prop) -> coq.univ.map A.
2264
2265 % [coq.univ.map.map M F M1] Map M w.r.t. the predicate F
2266 external func coq.univ.map.map coq.univ.map A,
2267 (univ -> A -> B -> prop) -> coq.univ.map B.
2268
2269 % [coq.univ.map.fold M Acc F Acc1] fold M w.r.t. the predicate F
2270 external func coq.univ.map.fold coq.univ.map A, C,
2271 (univ -> A -> C -> C -> prop) -> C.
2272
2273 kind coq.univ.variable.set type.
2274
2275 % [coq.univ.variable.set.empty A] The empty set
2276 external func coq.univ.variable.set.empty -> coq.univ.variable.set.
2277
2278 % [coq.univ.variable.set.mem Elem A] Checks if Elem is in a
2279 external func coq.univ.variable.set.mem univ.variable,
2280 coq.univ.variable.set.
2281
2282 % [coq.univ.variable.set.add Elem A B] B is A union {Elem}
2283 external func coq.univ.variable.set.add univ.variable,
2284 coq.univ.variable.set -> coq.univ.variable.set.
2285
2286 % [coq.univ.variable.set.remove Elem A B] B is A \ {Elem}
2287 external func coq.univ.variable.set.remove univ.variable,
2288 coq.univ.variable.set -> coq.univ.variable.set.
2289
2290 % [coq.univ.variable.set.union A B X] X is A union B
2291 external func coq.univ.variable.set.union coq.univ.variable.set,
2292 coq.univ.variable.set -> coq.univ.variable.set.
2293
2294 % [coq.univ.variable.set.inter A B X] X is A intersection B
2295 external func coq.univ.variable.set.inter coq.univ.variable.set,
2296 coq.univ.variable.set -> coq.univ.variable.set.
2297
2298 % [coq.univ.variable.set.diff A B X] X is A \ B
2299 external func coq.univ.variable.set.diff coq.univ.variable.set,
2300 coq.univ.variable.set -> coq.univ.variable.set.
2301
2302 % [coq.univ.variable.set.equal A B] tests A and B for equality
2303 external func coq.univ.variable.set.equal coq.univ.variable.set,
2304 coq.univ.variable.set.
2305
2306 % [coq.univ.variable.set.subset A B] tests if A is a subset of B
2307 external func coq.univ.variable.set.subset coq.univ.variable.set,
2308 coq.univ.variable.set.
2309
2310 % [coq.univ.variable.set.elements M L] L is M transformed into list
2311 external func coq.univ.variable.set.elements coq.univ.variable.set -> list univ.variable.
2312
2313 % [coq.univ.variable.set.choose M X] X is an element of M
2314 external func coq.univ.variable.set.choose coq.univ.variable.set -> univ.variable.
2315
2316 % [coq.univ.variable.set.min M X] X is the smallest element of M
2317 external func coq.univ.variable.set.min coq.univ.variable.set -> univ.variable.
2318
2319 % [coq.univ.variable.set.max M X] X is the bigger of M
2320 external func coq.univ.variable.set.max coq.univ.variable.set -> univ.variable.
2321
2322 % [coq.univ.variable.set.cardinal M N] N is the number of elements of M
2323 external func coq.univ.variable.set.cardinal coq.univ.variable.set -> int.
2324
2325 % [coq.univ.variable.set.filter M F M1] Filter M w.r.t. the predicate F
2326 external func coq.univ.variable.set.filter coq.univ.variable.set,
2327 (univ.variable -> (func)) -> coq.univ.variable.set.
2328
2329 % [coq.univ.variable.set.map M F M1] Map M w.r.t. the predicate F
2330 external func coq.univ.variable.set.map coq.univ.variable.set,
2331 (univ.variable -> univ.variable -> prop) -> coq.univ.variable.set.
2332
2333 % [coq.univ.variable.set.fold M Acc F Acc1] fold M w.r.t. the predicate F
2334 external func coq.univ.variable.set.fold coq.univ.variable.set, A,
2335 (univ.variable -> A -> A -> prop) -> A.
2336
2337 % [coq.univ.variable.set.partition M F M1 M2] Partitions M w.r.t. the
2338 % predicate F, M1 is where F holds
2339 external func coq.univ.variable.set.partition coq.univ.variable.set,
2340 (univ.variable -> (func)) -> coq.univ.variable.set,
2341 coq.univ.variable.set.
2342
2343 % CAVEAT: the type parameter of coq.univ.variable.map must be a closed
2344 % term
2345
2346 kind coq.univ.variable.map type -> type.
2347
2348 % [coq.univ.variable.map.empty M] The empty map
2349 external func coq.univ.variable.map.empty -> coq.univ.variable.map A.
2350
2351 % [coq.univ.variable.map.mem S M] Checks if S is bound in M
2352 external func coq.univ.variable.map.mem univ.variable,
2353 coq.univ.variable.map A.
2354
2355 % [coq.univ.variable.map.add S V M M1] M1 is M where V is bound to S
2356 external func coq.univ.variable.map.add univ.variable, A,
2357 coq.univ.variable.map A -> coq.univ.variable.map A.
2358
2359 % [coq.univ.variable.map.remove S M M1] M1 is M where S is unbound
2360 external func coq.univ.variable.map.remove univ.variable,
2361 coq.univ.variable.map A -> coq.univ.variable.map A.
2362
2363 % [coq.univ.variable.map.find S M V] V is the binding of S in M
2364 external func coq.univ.variable.map.find univ.variable,
2365 coq.univ.variable.map A -> A.
2366
2367 % [coq.univ.variable.map.bindings M L] L is M transformed into an
2368 % associative list
2369 external func coq.univ.variable.map.bindings coq.univ.variable.map A -> list (pair univ.variable A).
2370
2371 % [coq.univ.variable.map.filter M F M1] Filter M w.r.t. the predicate F
2372 external func coq.univ.variable.map.filter coq.univ.variable.map A,
2373 (univ.variable -> A -> prop) -> coq.univ.variable.map A.
2374
2375 % [coq.univ.variable.map.map M F M1] Map M w.r.t. the predicate F
2376 external func coq.univ.variable.map.map coq.univ.variable.map A,
2377 (univ.variable -> A -> B -> prop) -> coq.univ.variable.map B.
2378
2379 % [coq.univ.variable.map.fold M Acc F Acc1] fold M w.r.t. the predicate F
2380 external func coq.univ.variable.map.fold coq.univ.variable.map A, C,
2381 (univ.variable -> A -> C -> C -> prop) -> C.
2382
2383 % Coq box types for pretty printing:
2384 % - Vertical block: each break leads to a new line
2385 % - Horizontal block: no line breaking
2386 % - Horizontal-vertical block: same as Vertical block, except if this block
2387 % is small enough to fit on a single line in which case it is the same
2388 % as a Horizontal block
2389 % - Horizontal or Vertical block: breaks lead to new line only when
2390 % necessary to print the content of the block (the contents flow
2391 % inside the box)
2392 kind coq.pp.box type.
2393 external symbol coq.pp.v : int -> coq.pp.box = "1".
2394 external symbol coq.pp.h : coq.pp.box = "1".
2395 external symbol coq.pp.hv : int -> coq.pp.box = "1".
2396 external symbol coq.pp.hov : int -> coq.pp.box = "1".
2397
2398 % Coq box model for pretty printing. Items:
2399 % - empty
2400 % - spc: a spacem, also a breaking hint
2401 % - str: a non breakable string
2402 % - brk L I: a breaking hint of a given length L contributing I spaces to
2403 % indentation when taken
2404 % - glue: puts things together
2405 % - box B: a box with automatic line breaking according to B
2406 % - comment: embedded \\n are turned into nl (see below)
2407 % - tag: ignored
2408 % - nl: break the line (should not be used)
2409 kind coq.pp type.
2410 external symbol coq.pp.empty : coq.pp = "1".
2411 external symbol coq.pp.spc : coq.pp = "1".
2412 external symbol coq.pp.str : string -> coq.pp = "1".
2413 external symbol coq.pp.brk : int -> int -> coq.pp = "1".
2414 external symbol coq.pp.glue : list coq.pp -> coq.pp = "1".
2415 external symbol coq.pp.box : coq.pp.box -> list coq.pp -> coq.pp = "1".
2416 external symbol coq.pp.comment : list string -> coq.pp = "1".
2417 external symbol coq.pp.tag : string -> coq.pp -> coq.pp = "1".
2418 external symbol coq.pp.nl : coq.pp = "1".
2419
2420 % [coq.pp->string B S] Prints a pp.t box expression B to a string S
2421 % Supported attributes:
2422 % - @ppwidth! N (default 80, max line length)
2423 external func coq.pp->string coq.pp -> string.
2424
2425
2426
2427