aboutsummaryrefslogtreecommitdiff
path: root/doc/sphinx/proof-engine
diff options
context:
space:
mode:
Diffstat (limited to 'doc/sphinx/proof-engine')
-rw-r--r--doc/sphinx/proof-engine/ltac.rst94
-rw-r--r--doc/sphinx/proof-engine/ltac2.rst1270
-rw-r--r--doc/sphinx/proof-engine/proof-handling.rst51
-rw-r--r--doc/sphinx/proof-engine/ssreflect-proof-language.rst70
-rw-r--r--doc/sphinx/proof-engine/tactics.rst336
-rw-r--r--doc/sphinx/proof-engine/vernacular-commands.rst40
6 files changed, 1352 insertions, 509 deletions
diff --git a/doc/sphinx/proof-engine/ltac.rst b/doc/sphinx/proof-engine/ltac.rst
index b0b0367d6d..f18569c7fd 100644
--- a/doc/sphinx/proof-engine/ltac.rst
+++ b/doc/sphinx/proof-engine/ltac.rst
@@ -74,7 +74,7 @@ The constructs in :token:`ltac_expr` are :term:`left associative`.
ltac_expr0 ::= ( @ltac_expr )
| [> @for_each_goal ]
| @tactic_atom
- tactic_atom ::= @int
+ tactic_atom ::= @integer
| @qualid
| ()
@@ -188,7 +188,7 @@ examining the part at the end under "Entry tactic:tactic_arg".
-
* - ``integer``
- - :token:`int`
+ - :token:`integer`
- an integer
-
@@ -375,8 +375,14 @@ behavior.)
| !
| par
- Applies :token:`ltac_expr` to the selected goals. It can only be used at the top
- level of a tactic expression; it cannot be used within a tactic expression.
+ Reorders the goals and applies :token:`ltac_expr` to the selected goals. It can
+ only be used at the top level of a tactic expression; it cannot be used within a
+ tactic expression. The selected goals are reordered so they appear after the
+ lowest-numbered selected goal, ordered by goal number. :ref:`Example
+ <reordering_goals_ex>`. If the selector applies
+ to a single goal or to all goals, the reordering will not be apparent. The order of
+ the goals in the :token:`selector` is irrelevant. (This may not be what you expect;
+ see `#8481 <https://github.com/coq/coq/issues/8481>`_.)
.. todo why shouldn't "all" and "!" be accepted anywhere a @selector is accepted?
It would be simpler to explain.
@@ -391,7 +397,7 @@ behavior.)
`par`
Applies :n:`@ltac_expr` to all focused goals in parallel.
The number of workers can be controlled via the command line option
- :n:`-async-proofs-tac-j @num` to specify the desired number of workers.
+ :n:`-async-proofs-tac-j @natural` to specify the desired number of workers.
Limitations: ``par:`` only works on goals that don't contain existential
variables. :n:`@ltac_expr` must either solve the goal completely or do
nothing (i.e. it cannot make some progress).
@@ -406,8 +412,8 @@ Selectors can also be used nested within a tactic expression with the
.. prodn::
selector ::= {+, @range_selector }
| [ @ident ]
- range_selector ::= @num - @num
- | @num
+ range_selector ::= @natural - @natural
+ | @natural
Applies :token:`ltac_expr3` to the selected goals.
@@ -420,16 +426,29 @@ Selectors can also be used nested within a tactic expression with the
Limits the application of :token:`ltac_expr3` to the goal previously named :token:`ident`
by the user (see :ref:`existential-variables`).
- :n:`@num__1 - @num__2`
- Selects the goals :n:`@num__1` through :n:`@num__2`, inclusive.
+ :n:`@natural__1 - @natural__2`
+ Selects the goals :n:`@natural__1` through :n:`@natural__2`, inclusive.
- :n:`@num`
+ :n:`@natural`
Selects a single goal.
.. exn:: No such goal.
:name: No such goal. (Goal selector)
:undocumented:
+.. _reordering_goals_ex:
+
+.. example:: Selector reordering goals
+
+ .. coqtop:: reset in
+
+ Goal 1=0 /\ 2=0 /\ 3=0.
+
+ .. coqtop:: all
+
+ repeat split.
+ 1,3: idtac.
+
.. TODO change error message index entry
@@ -857,7 +876,7 @@ Print/identity tactic: idtac
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-.. tacn:: idtac {* {| @ident | @string | @int } }
+.. tacn:: idtac {* {| @ident | @string | @natural } }
:name: idtac
Leaves the proof unchanged and prints the given tokens. Strings and integers are printed
@@ -869,7 +888,7 @@ Print/identity tactic: idtac
Failing
~~~~~~~
-.. tacn:: {| fail | gfail } {? @int_or_var } {* {| @ident | @string | @int } }
+.. tacn:: {| fail | gfail } {? @int_or_var } {* {| @ident | @string | @integer } }
:name: fail; gfail
:tacn:`fail` is the always-failing tactic: it does not solve any
@@ -897,17 +916,17 @@ Failing
(backtracking). If nonzero, the current :tacn:`match goal` block, :tacn:`try`,
:tacn:`repeat`, or branching command is aborted and the level is decremented. In
the case of :n:`+`, a nonzero level skips the first backtrack point, even if
- the call to :tacn:`fail` :n:`@num` is not enclosed in a :n:`+` construct,
+ the call to :tacn:`fail` :n:`@natural` is not enclosed in a :n:`+` construct,
respecting the algebraic identity.
- :n:`{* {| @ident | @string | @int } }`
+ :n:`{* {| @ident | @string | @integer } }`
The given tokens are used for printing the failure message. If :token:`ident`
is an |Ltac| variable, its contents are printed; if not, it is an error.
.. exn:: Tactic failure.
:undocumented:
- .. exn:: Tactic failure (level @num).
+ .. exn:: Tactic failure (level @natural).
:undocumented:
.. exn:: No such goal.
@@ -957,7 +976,7 @@ amount of time:
:name: timeout
:n:`@ltac_expr3` is evaluated to ``v`` which must be a tactic value. The tactic value
- ``v`` is applied normally, except that it is interrupted after :n:`@num` seconds
+ ``v`` is applied normally, except that it is interrupted after :n:`@natural` seconds
if it is still running. In this case the outcome is a failure.
:tacn:`timeout` is an :token:`l3_tactic`.
@@ -1122,12 +1141,14 @@ Pattern matching on terms: match
then the :token:`ltac_expr` can't use `S` to refer to the constructor of `nat`
without qualifying the constructor as `Datatypes.S`.
- .. todo below: is matching non-linear unification? is it the same or different
- from unification elsewhere in Coq?
+ .. todo how does this differ from the 1-2 other unification routines elsewhere in Coq?
+ Does it use constr_eq or eq_constr_nounivs?
Matching is non-linear: if a
metavariable occurs more than once, each occurrence must match the same
- expression. Matching is first-order except on variables of the form :n:`@?@ident`
+ expression. Expressions match if they are syntactically equal or are
+ :term:`α-convertible <alpha-convertible>`.
+ Matching is first-order except on variables of the form :n:`@?@ident`
that occur in the head position of an application. For these variables,
matching is second-order and returns a functional term.
@@ -1305,20 +1326,20 @@ Pattern matching on terms: match
.. example:: Multiple matches for a "context" pattern.
- Internally "x <> y" is represented as "(not x y)", which produces the
+ Internally "x <> y" is represented as "(~ (x = y))", which produces the
first match.
.. coqtop:: in reset
Ltac f t := match t with
- | context [ (not ?t) ] => idtac "?t = " t; fail
+ | context [ (~ ?t) ] => idtac "?t = " t; fail
| _ => idtac
end.
Goal True.
.. coqtop:: all
- f ((not True) <> (not False)).
+ f ((~ True) <> (~ False)).
.. _ltac-match-goal:
@@ -1345,6 +1366,13 @@ Pattern matching on goals and hypotheses: match goal
differences noted below, this works the same as the corresponding :n:`@match_key @ltac_expr` construct
(see :tacn:`match`). Each current goal is processed independently.
+ Matching is non-linear: if a
+ metavariable occurs more than once, each occurrence must match the same
+ expression. Within a single term, expressions match if they are syntactically equal or
+ :term:`α-convertible <alpha-convertible>`. When a metavariable is used across
+ multiple hypotheses or across a hypothesis and the current goal, the expressions match if
+ they are :term:`convertible`.
+
:n:`{*, @match_hyp }`
Patterns to match with hypotheses. Each pattern must match a distinct hypothesis in order
for the branch to match.
@@ -1381,7 +1409,7 @@ Pattern matching on goals and hypotheses: match goal
:cmd:`Import` `ListNotations`) must be parenthesized or, for the fourth form,
use double brackets: `[ [ ?l ] ]`.
- :n:`@term__binder`\s in the form `[?x ; ?y]` for a list is not parsed correctly. The workaround is
+ :n:`@term__binder`\s in the form `[?x ; ?y]` for a list are not parsed correctly. The workaround is
to add parentheses or to use the underlying term instead of the notation, i.e. `(cons ?x ?y)`.
If there are multiple :token:`match_hyp`\s in a branch, there may be multiple ways to match them to hypotheses.
@@ -1647,8 +1675,8 @@ Proving a subgoal as a separate lemma: abstract
Does a :tacn:`solve` :n:`[ @ltac_expr2 ]` and saves the subproof as an auxiliary lemma.
if :n:`@ident__name` is specified, the lemma is saved with that name; otherwise
- the lemma is saved with the name :n:`@ident`\ `_subproof`\ :n:`{? @num }` where
- :token:`ident` is the name of the current goal (e.g. the theorem name) and :token:`num`
+ the lemma is saved with the name :n:`@ident`\ `_subproof`\ :n:`{? @natural }` where
+ :token:`ident` is the name of the current goal (e.g. the theorem name) and :token:`natural`
is chosen to get a fresh name. If the proof is closed with :cmd:`Qed`, the auxiliary lemma
is inlined in the final proof term.
@@ -1681,7 +1709,7 @@ Proving a subgoal as a separate lemma: abstract
.. tacn:: transparent_abstract @ltac_expr3 {? using @ident }
Like :tacn:`abstract`, but save the subproof in a transparent lemma with a name in
- the form :n:`@ident`\ :n:`_subterm`\ :n:`{? @num }`.
+ the form :n:`@ident`\ :n:`_subterm`\ :n:`{? @natural }`.
.. warning::
@@ -2169,7 +2197,7 @@ Backtraces
Tracing execution
~~~~~~~~~~~~~~~~~
-.. cmd:: Info @num @ltac_expr
+.. cmd:: Info @natural @ltac_expr
Applies :token:`ltac_expr` and prints a trace of the tactics that were successfully
applied, discarding branches that failed.
@@ -2177,7 +2205,7 @@ Tracing execution
This command is valid only in proof mode. It accepts :ref:`goal-selectors`.
- The number :n:`@num` is the unfolding level of tactics in the trace. At level
+ The number :n:`@natural` is the unfolding level of tactics in the trace. At level
0, the trace contains a sequence of tactics in the actual script, at level 1,
the trace will be the concatenation of the traces of these tactics, etc…
@@ -2209,12 +2237,12 @@ Tracing execution
position in the script. In particular, the calls to idtac in branches which failed are
not printed.
- .. opt:: Info Level @num
+ .. opt:: Info Level @natural
:name: Info Level
This option is an alternative to the :cmd:`Info` command.
- This will automatically print the same trace as :n:`Info @num` at each
+ This will automatically print the same trace as :n:`Info @natural` at each
tactic call. The unfolding level can be overridden by a call to the
:cmd:`Info` command.
@@ -2274,11 +2302,11 @@ performance issue.
This flag enables and disables the profiler.
-.. cmd:: Show Ltac Profile {? {| CutOff @int | @string } }
+.. cmd:: Show Ltac Profile {? {| CutOff @integer | @string } }
Prints the profile.
- :n:`CutOff @int`
+ :n:`CutOff @integer`
By default, tactics that account for less than 2% of the total time are not displayed.
`CutOff` lets you specify a different percentage.
@@ -2345,7 +2373,7 @@ performance issue.
Equivalent to the :cmd:`Reset Ltac Profile` command, which allows
resetting the profile from tactic scripts for benchmarking purposes.
-.. tacn:: show ltac profile {? {| cutoff @int | @string } }
+.. tacn:: show ltac profile {? {| cutoff @integer | @string } }
:name: show ltac profile
Equivalent to the :cmd:`Show Ltac Profile` command,
diff --git a/doc/sphinx/proof-engine/ltac2.rst b/doc/sphinx/proof-engine/ltac2.rst
index 1e35160205..773e393eb6 100644
--- a/doc/sphinx/proof-engine/ltac2.rst
+++ b/doc/sphinx/proof-engine/ltac2.rst
@@ -27,6 +27,50 @@ especially wherever an advanced tactic language is needed. The previous
implementation of Ltac, described in the previous chapter, will be referred to
as Ltac1.
+Current limitations include:
+
+- There are a number of tactics that are not yet supported in Ltac2 because
+ the interface OCaml and/or Ltac2 notations haven't been written. See
+ :ref:`defining_tactics`.
+
+- Missing usability features such as:
+
+ - Printing functions are limited and awkward to use. Only a few data types are
+ printable.
+ - Deep pattern matching and matching on tuples don't work.
+ - If statements on Ltac2 boolean values
+ - A convenient way to build terms with casts through the low-level API. Because the
+ cast type is opaque, building terms with casts currently requires an awkward construction like the
+ following, which also incurs extra overhead to repeat typechecking for each
+ call to `get_vm_cast`:
+
+ .. coqdoc::
+
+ Constr.Unsafe.make (Constr.Unsafe.Cast 'I (get_vm_cast ()) 'True)
+
+ with:
+
+ .. coqtop:: none
+
+ From Ltac2 Require Import Ltac2.
+
+ .. coqtop:: in
+
+ Ltac2 get_vm_cast () :=
+ match Constr.Unsafe.kind '(I <: True) with
+ | Constr.Unsafe.Cast _ cst _ => cst
+ | _ => Control.throw Not_found
+ end.
+
+- Missing low-level primitives that are convenient for writing automation, such as:
+
+ - An easy way to get the number of constructors of an inductive type.
+ Currently only way to do this is to destruct a variable of the inductive type
+ and count the number of goals that result.
+- The :attr:`deprecated` attribute is not supported for Ltac2 definitions.
+
+- Error messages may be cryptic.
+
.. _ltac2_design:
General design
@@ -49,7 +93,7 @@ In particular, Ltac2 is:
Coq-side terms
- a language featuring notation facilities to help write palatable scripts
-We describe more in details each point in the remainder of this document.
+We describe these in more detail in the remainder of this document.
ML component
------------
@@ -84,7 +128,7 @@ which allows to ensure that Ltac2 satisfies the same equations as a generic ML
with unspecified effects would do, e.g. function reduction is substitution
by a value.
-To import Ltac2, use the following command:
+Use the following command to import Ltac2:
.. coqtop:: in
@@ -96,17 +140,20 @@ Type Syntax
At the level of terms, we simply elaborate on Ltac1 syntax, which is quite
close to OCaml. Types follow the simply-typed syntax of OCaml.
-The non-terminal :production:`lident` designates identifiers starting with a
-lowercase.
+.. insertprodn ltac2_type ltac2_typevar
-.. productionlist:: coq
- ltac2_type : ( `ltac2_type`, ... , `ltac2_type` ) `ltac2_typeconst`
- : ( `ltac2_type` * ... * `ltac2_type` )
- : `ltac2_type` -> `ltac2_type`
- : `ltac2_typevar`
- ltac2_typeconst : ( `modpath` . )* `lident`
- ltac2_typevar : '`lident`
- ltac2_typeparams : ( `ltac2_typevar`, ... , `ltac2_typevar` )
+.. prodn::
+ ltac2_type ::= @ltac2_type2 -> @ltac2_type
+ | @ltac2_type2
+ ltac2_type2 ::= @ltac2_type1 * {+* @ltac2_type1 }
+ | @ltac2_type1
+ ltac2_type1 ::= @ltac2_type0 @qualid
+ | @ltac2_type0
+ ltac2_type0 ::= ( {+, @ltac2_type } ) {? @qualid }
+ | @ltac2_typevar
+ | _
+ | @qualid
+ ltac2_typevar ::= ' @ident
The set of base types can be extended thanks to the usual ML type
declarations such as algebraic datatypes and records.
@@ -126,114 +173,156 @@ Type declarations
One can define new types with the following commands.
-.. cmd:: Ltac2 Type {? @ltac2_typeparams } @lident
+.. cmd:: Ltac2 Type {? rec } @tac2typ_def {* with @tac2typ_def }
:name: Ltac2 Type
- This command defines an abstract type. It has no use for the end user and
- is dedicated to types representing data coming from the OCaml world.
+ .. insertprodn tac2typ_def tac2rec_field
-.. cmdv:: Ltac2 Type {? rec} {? @ltac2_typeparams } @lident := @ltac2_typedef
+ .. prodn::
+ tac2typ_def ::= {? @tac2typ_prm } @qualid {? {| := | ::= } @tac2typ_knd }
+ tac2typ_prm ::= @ltac2_typevar
+ | ( {+, @ltac2_typevar } )
+ tac2typ_knd ::= @ltac2_type
+ | [ {? {? %| } {+| @tac2alg_constructor } } ]
+ | [ .. ]
+ | %{ {? {+; @tac2rec_field } {? ; } } %}
+ tac2alg_constructor ::= @ident
+ | @ident ( {*, @ltac2_type } )
+ tac2rec_field ::= {? mutable } @ident : @ltac2_type
- This command defines a type with a manifest. There are four possible
- kinds of such definitions: alias, variant, record and open variant types.
+ :n:`:=`
+ Defines a type with with an explicit set of constructors
- .. productionlist:: coq
- ltac2_typedef : `ltac2_type`
- : [ `ltac2_constructordef` | ... | `ltac2_constructordef` ]
- : { `ltac2_fielddef` ; ... ; `ltac2_fielddef` }
- : [ .. ]
- ltac2_constructordef : `uident` [ ( `ltac2_type` , ... , `ltac2_type` ) ]
- ltac2_fielddef : [ mutable ] `ident` : `ltac2_type`
+ :n:`::=`
+ Extends an existing open variant type, a special kind of variant type whose constructors are not
+ statically defined, but can instead be extended dynamically. A typical example
+ is the standard `exn` type for exceptions. Pattern matching on open variants must always
+ include a catch-all clause. They can be extended with this form, in which case
+ :token:`tac2typ_knd` should be in the form :n:`[ {? {? %| } {+| @tac2alg_constructor } } ]`.
- Aliases are just a name for a given type expression and are transparently
- unfoldable to it. They cannot be recursive. The non-terminal
- :production:`uident` designates identifiers starting with an uppercase.
+ Without :n:`{| := | ::= }`
+ Defines an abstract type for use representing data from OCaml. Not for
+ end users.
+
+ :n:`with @tac2typ_def`
+ Permits definition of mutually recursive type definitions.
+
+ Each production of :token:`tac2typ_knd` defines one of four possible kinds
+ of definitions, respectively: alias, variant, open variant and record types.
+
+ Aliases are names for a given type expression and are transparently
+ unfoldable to that expression. They cannot be recursive.
+
+ .. The non-terminal :token:`uident` designates identifiers starting with an uppercase.
Variants are sum types defined by constructors and eliminated by
pattern-matching. They can be recursive, but the `rec` flag must be
explicitly set. Pattern matching must be exhaustive.
+ Open variants can be extended with additional constructors using the `::=` form.
+
Records are product types with named fields and eliminated by projection.
Likewise they can be recursive if the `rec` flag is set.
- .. cmdv:: Ltac2 Type {? @ltac2_typeparams } @ltac2_qualid ::= [ @ltac2_constructordef ]
+.. cmd:: Ltac2 @ external @ident : @ltac2_type := @string @string
+ :name: Ltac2 external
+
+ Declares abstract terms. Frequently, these declare OCaml functions
+ defined in |Coq| and give their type information. They can also declare
+ data structures from OCaml. This command has no use for the end user.
+
+APIs
+~~~~
+
+Ltac2 provides over 150 API functions that provide various capabilities. These
+are declared with :cmd:`Ltac2 external` in :n:`lib/coq/user-contrib/Ltac2/*.v`.
+For example, `Message.print` defined in `Message.v` is used to print messages:
- Open variants are a special kind of variant types whose constructors are not
- statically defined, but can instead be extended dynamically. A typical example
- is the standard `exn` type. Pattern matching on open variants must always include a catch-all
- clause. They can be extended with this command.
+.. coqtop:: none
+
+ Goal True.
+
+.. coqtop:: all abort
+
+ Message.print (Message.of_string "fully qualified calls").
+ From Ltac2 Require Import Message.
+ print (of_string "unqualified calls").
Term Syntax
~~~~~~~~~~~
-The syntax of the functional fragment is very close to the one of Ltac1, except
+The syntax of the functional fragment is very close to that of Ltac1, except
that it adds a true pattern-matching feature, as well as a few standard
constructs from ML.
-.. productionlist:: coq
- ltac2_var : `lident`
- ltac2_qualid : ( `modpath` . )* `lident`
- ltac2_constructor: `uident`
- ltac2_term : `ltac2_qualid`
- : `ltac2_constructor`
- : `ltac2_term` `ltac2_term` ... `ltac2_term`
- : fun `ltac2_var` => `ltac2_term`
- : let `ltac2_var` := `ltac2_term` in `ltac2_term`
- : let rec `ltac2_var` := `ltac2_term` in `ltac2_term`
- : match `ltac2_term` with `ltac2_branch` ... `ltac2_branch` end
- : `int`
- : `string`
- : `ltac2_term` ; `ltac2_term`
- : [| `ltac2_term` ; ... ; `ltac2_term` |]
- : ( `ltac2_term` , ... , `ltac2_term` )
- : { `ltac2_field` `ltac2_field` ... `ltac2_field` }
- : `ltac2_term` . ( `ltac2_qualid` )
- : `ltac2_term` . ( `ltac2_qualid` ) := `ltac2_term`
- : [; `ltac2_term` ; ... ; `ltac2_term` ]
- : `ltac2_term` :: `ltac2_term`
- : ...
- ltac2_branch : `ltac2_pattern` => `ltac2_term`
- ltac2_pattern : `ltac2_var`
- : _
- : ( `ltac2_pattern` , ... , `ltac2_pattern` )
- : `ltac2_constructor` `ltac2_pattern` ... `ltac2_pattern`
- : [ ]
- : `ltac2_pattern` :: `ltac2_pattern`
- ltac2_field : `ltac2_qualid` := `ltac2_term`
-
-In practice, there is some additional syntactic sugar that allows e.g. to
-bind a variable and match on it at the same time, in the usual ML style.
+In practice, there is some additional syntactic sugar that allows the
+user to bind a variable and match on it at the same time, in the usual ML style.
There is dedicated syntax for list and array literals.
-.. note::
+.. insertprodn ltac2_expr ltac2_tactic_atom
+
+.. prodn::
+ ltac2_expr ::= @ltac2_expr5 ; @ltac2_expr
+ | @ltac2_expr5
+ ltac2_expr5 ::= fun {+ @tac2pat0 } => @ltac2_expr
+ | let {? rec } @ltac2_let_clause {* with @ltac2_let_clause } in @ltac2_expr
+ | @ltac2_expr3
+ ltac2_let_clause ::= {+ @tac2pat0 } := @ltac2_expr
+ ltac2_expr3 ::= {+, @ltac2_expr2 }
+ ltac2_expr2 ::= @ltac2_expr1 :: @ltac2_expr2
+ | @ltac2_expr1
+ ltac2_expr1 ::= @ltac2_expr0 {+ @ltac2_expr0 }
+ | @ltac2_expr0 .( @qualid )
+ | @ltac2_expr0 .( @qualid ) := @ltac2_expr5
+ | @ltac2_expr0
+ tac2rec_fieldexpr ::= @qualid := @ltac2_expr1
+ ltac2_expr0 ::= ( @ltac2_expr )
+ | ( @ltac2_expr : @ltac2_type )
+ | ()
+ | [ {*; @ltac2_expr5 } ]
+ | %{ {? {+ @tac2rec_fieldexpr } {? ; } } %}
+ | @ltac2_tactic_atom
+ ltac2_tactic_atom ::= @integer
+ | @string
+ | @qualid
+ | @ @ident
+ | & @lident
+ | ' @term
+ | @ltac2_quotations
+
+The non-terminal :production:`lident` designates identifiers starting with a
+lowercase letter.
+
+:n:`'@term` is equivalent to :n:`open_constr:(@term)`.
- For now, deep pattern matching is not implemented.
-Ltac Definitions
-~~~~~~~~~~~~~~~~
-.. cmd:: Ltac2 {? mutable} {? rec} @lident := @ltac2_value
+Ltac2 Definitions
+~~~~~~~~~~~~~~~~~
+
+.. cmd:: Ltac2 {? mutable } {? rec } @tac2def_body {* with @tac2def_body }
:name: Ltac2
- This command defines a new global Ltac2 value.
+ .. insertprodn tac2def_body tac2def_body
+
+ .. prodn::
+ tac2def_body ::= {| _ | @ident } {* @tac2pat0 } := @ltac2_expr
+
+ This command defines a new global Ltac2 value. If one or more :token:`tac2pat0`
+ are specified, the new value is a function. This is a shortcut for one of the
+ :token:`ltac2_expr5` productions. For example: :n:`Ltac2 foo a b := …` is equivalent
+ to :n:`Ltac2 foo := fun a b => …`.
The body of an Ltac2 definition is required to be a syntactical value
that is, a function, a constant, a pure constructor recursively applied to
values or a (non-recursive) let binding of a value in a value.
- .. productionlist:: coq
- ltac2_value: fun `ltac2_var` => `ltac2_term`
- : `ltac2_qualid`
- : `ltac2_constructor` `ltac2_value` ... `ltac2_value`
- : `ltac2_var`
- : let `ltac2_var` := `ltac2_value` in `ltac2_value`
-
If ``rec`` is set, the tactic is expanded into a recursive binding.
If ``mutable`` is set, the definition can be redefined at a later stage (see below).
-.. cmd:: Ltac2 Set @qualid {? as @lident} := @ltac2_term
+.. cmd:: Ltac2 Set @qualid {? as @ident } := @ltac2_expr
:name: Ltac2 Set
This command redefines a previous ``mutable`` definition.
@@ -254,7 +343,6 @@ Ltac Definitions
.. example:: Interaction with recursive calls
-
.. coqtop:: all
Ltac2 mutable rec f b := match b with true => 0 | _ => f true end.
@@ -334,7 +422,7 @@ Intuitively a thunk of type :n:`unit -> 'a` can do the following:
i.e. thunks can produce a lazy list of results where each
tail is waiting for a continuation exception.
- It can access a backtracking proof state, consisting among other things of
- the current evar assignation and the list of goals under focus.
+ the current evar assignment and the list of goals under focus.
We now describe more thoroughly the various effects in Ltac2.
@@ -348,8 +436,8 @@ Mutable fields of records can be modified using the set syntax. Likewise,
built-in types like `string` and `array` feature imperative assignment. See
modules `String` and `Array` respectively.
-A few printing primitives are provided in the `Message` module, allowing to
-display information to the user.
+A few printing primitives are provided in the `Message` module for
+displaying information to the user.
Fatal errors
++++++++++++
@@ -458,20 +546,27 @@ Ltac2 makes these explicit using quoting and unquoting notation, although there
are notations to do it in a short and elegant way so as not to be too cumbersome
to the user.
-Generic Syntax for Quotations
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-In general, quotations can be introduced in terms using the following syntax, where
-:production:`quotentry` is some parsing entry.
-
-.. prodn::
- ltac2_term += @ident : ( @quotentry )
+Quotations
+~~~~~~~~~~
.. _ltac2_built-in-quotations:
Built-in quotations
+++++++++++++++++++
+.. insertprodn ltac2_quotations ltac1_expr_in_env
+
+.. prodn::
+ ltac2_quotations ::= ident : ( @lident )
+ | constr : ( @term )
+ | open_constr : ( @term )
+ | pattern : ( @cpattern )
+ | reference : ( {| & @ident | @qualid } )
+ | ltac1 : ( @ltac1_expr_in_env )
+ | ltac1val : ( @ltac1_expr_in_env )
+ ltac1_expr_in_env ::= @ltac_expr
+ | {* @ident } |- @ltac_expr
+
The current implementation recognizes the following built-in quotations:
- ``ident``, which parses identifiers (type ``Init.ident``).
@@ -481,16 +576,17 @@ The current implementation recognizes the following built-in quotations:
holes at runtime (type ``Init.constr`` as well).
- ``pattern``, which parses Coq patterns and produces a pattern used for term
matching (type ``Init.pattern``).
-- ``reference``, which parses either a :n:`@qualid` or :n:`&@ident`. Qualified names
+- ``reference`` Qualified names
are globalized at internalization into the corresponding global reference,
while ``&id`` is turned into ``Std.VarRef id``. This produces at runtime a
- ``Std.reference``. There shall be no white space between the ampersand
- symbol (``&``) and the identifier (:n:`@ident`).
+ ``Std.reference``.
+- ``ltac1``, for calling Ltac1 code, described in :ref:`simple_api`.
+- ``ltac1val``, for manipulating Ltac1 values, described in :ref:`low_level_api`.
-The following syntactic sugar is provided for two common cases.
+The following syntactic sugar is provided for two common cases:
- ``@id`` is the same as ``ident:(id)``
-- ``'t`` is the same as ``open_constr:(t)``
+- :n:`'@term` is the same as :n:`open_constr:(@term)`
Strict vs. non-strict mode
++++++++++++++++++++++++++
@@ -521,11 +617,11 @@ Term Antiquotations
Syntax
++++++
-One can also insert Ltac2 code into Coq terms, similarly to what is possible in
+One can also insert Ltac2 code into Coq terms, similar to what is possible in
Ltac1.
.. prodn::
- term += ltac2:( @ltac2_term )
+ term += ltac2:( @ltac2_expr )
Antiquoted terms are expected to have type ``unit``, as they are only evaluated
for their side-effects.
@@ -659,168 +755,473 @@ insert in a concise way an Ltac2 variable of type :n:`constr` into a Coq term.
Match over terms
~~~~~~~~~~~~~~~~
-Ltac2 features a construction similar to Ltac1 :n:`match` over terms, although
+Ltac2 features a construction similar to Ltac1 :tacn:`match` over terms, although
in a less hard-wired way.
-.. productionlist:: coq
- ltac2_term : match! `ltac2_term` with `constrmatching` .. `constrmatching` end
- : lazy_match! `ltac2_term` with `constrmatching` .. `constrmatching` end
- : multi_match! `ltac2_term` with `constrmatching` .. `constrmatching` end
- constrmatching : | `constrpattern` => `ltac2_term`
- constrpattern : `term`
- : context [ `term` ]
- : context `lident` [ `term` ]
-
-This construction is not primitive and is desugared at parsing time into
-calls to term matching functions from the `Pattern` module. Internally, it is
-implemented thanks to a specific scope accepting the :n:`@constrmatching` syntax.
-
-Variables from the :n:`@constrpattern` are statically bound in the body of the branch, to
-values of type `constr` for the variables from the :n:`@term` pattern and to a
-value of type `Pattern.context` for the variable :n:`@lident`.
-
-Note that unlike Ltac, only lowercase identifiers are valid as Ltac2
-bindings, so that there will be a syntax error if one of the bound variables
+.. tacn:: @ltac2_match_key @ltac2_expr__term with @ltac2_match_list end
+ :name: lazy_match!; match!; multi_match!
+
+ .. insertprodn ltac2_match_key ltac2_match_pattern
+
+ .. prodn::
+ ltac2_match_key ::= lazy_match!
+ | match!
+ | multi_match!
+ ltac2_match_list ::= {? %| } {+| @ltac2_match_rule }
+ ltac2_match_rule ::= @ltac2_match_pattern => @ltac2_expr
+ ltac2_match_pattern ::= @cpattern
+ | context {? @ident } [ @cpattern ]
+
+ Evaluates :n:`@ltac2_expr__term`, which must yield a term, and matches it
+ sequentially with the :token:`ltac2_match_pattern`\s, which may contain
+ metavariables. When a match is found, metavariable values are substituted
+ into :n:`@ltac2_expr`, which is then applied.
+
+ Matching may continue depending on whether `lazy_match!`, `match!` or `multi_match!`
+ is specified.
+
+ In the :token:`ltac2_match_pattern`\s, metavariables have the form :n:`?@ident`, whereas
+ in the :n:`@ltac2_expr`\s, the question mark is omitted.
+
+ .. todo how does this differ from the 1-2 other unification routines elsewhere in Coq?
+
+ Matching is non-linear: if a
+ metavariable occurs more than once, each occurrence must match the same
+ expression. Expressions match if they are syntactically equal or are
+ :term:`α-convertible <alpha-convertible>`.
+ Matching is first-order except on variables of the form :n:`@?@ident`
+ that occur in the head position of an application. For these variables,
+ matching is second-order and returns a functional term.
+
+ .. todo the `@?ident` form is in dangling_pattern_extension_rule, not included in the doc yet
+ maybe belongs with "Applications"
+
+ `lazy_match!`
+ Causes the match to commit to the first matching branch
+ rather than trying a new match if :n:`@ltac2_expr` fails.
+ :ref:`Example<ltac2_match_vs_lazymatch_ex>`.
+
+ `match!`
+ If :n:`@ltac2_expr` fails, continue matching with the next branch.
+ Failures in subsequent tactics (after the `match!`) will not cause selection
+ of a new branch. Examples :ref:`here<ltac2_match_vs_lazymatch_ex>` and
+ :ref:`here<ltac2_match_vs_multimatch_ex>`.
+
+ `multi_match!`
+ If :n:`@ltac2_expr` fails, continue matching with the next branch.
+ When a :n:`@ltac2_expr` succeeds for a branch, subsequent failures
+ (after the `multi_match!`) causing consumption of all the successes
+ of :n:`@ltac2_expr` trigger selection of a new matching branch.
+ :ref:`Example<ltac2_match_vs_multimatch_ex>`.
+
+ :n:`@cpattern`
+ The syntax of :token:`cpattern` is
+ the same as that of :token:`term`\s, but it can contain pattern matching
+ metavariables in the form :n:`?@ident` and :n:`@?@ident`. :g:`_` can be used to match
+ irrelevant terms.
+
+ .. todo more on @?@ident here: https://github.com/coq/coq/pull/12085#discussion_r467504046
+ .. todo Example is broken :ref:`Example<ltac2_match_with_holes_ex>`.
+
+ .. todo Didn't understand the following 2 paragraphs well enough to revise
+ see https://github.com/coq/coq/pull/12103#discussion_r436297754 for a
+ possible example
+
+ Unlike Ltac1, Ltac2 :n:`?id` metavariables only match closed terms.
+
+ There is also a special notation for second-order pattern matching: in an
+ applicative pattern of the form :n:`@?@ident @ident__1 … @ident__n`,
+ the variable :token:`ident` matches any complex expression with (possible)
+ dependencies in the variables :n:`@ident__i` and returns a functional term
+ of the form :n:`fun @ident__1 … @ident__n => @term`.
+
+ .. _match_term_context:
+
+ :n:`context {? @ident } [ @cpattern ]`
+ Matches any term with a subterm matching :token:`cpattern`. If there is a match
+ and :n:`@ident` is present, it is assigned the "matched
+ context", i.e. the initial term where the matched subterm is replaced by a
+ hole. This hole in the matched context can be filled with the expression
+ :n:`Pattern.instantiate @ident @cpattern`.
+
+ For :tacn:`match!` and :tacn:`multi_match!`, if the evaluation of the :token:`ltac2_expr`
+ fails, the next matching subterm is tried. If no further subterm matches, the next branch
+ is tried. Matching subterms are considered from top to bottom and from left to
+ right (with respect to the raw printing obtained by setting the
+ :flag:`Printing All` flag). :ref:`Example<ltac2_match_term_context_ex>`.
+
+ .. todo There's a more realistic example from @JasonGross here:
+ https://github.com/coq/coq/pull/12103#discussion_r432996954
+
+ :n:`@ltac2_expr`
+ The tactic to apply if the construct matches. Metavariable values from the pattern
+ match are statically bound as Ltac2 variables in :n:`@ltac2_expr` before
+ it is applied.
+
+ If :n:`@ltac2_expr` is a tactic with backtracking points, then subsequent
+ failures after a :tacn:`lazy_match!` or :tacn:`multi_match!` (but not :tacn:`match!`) can cause
+ backtracking into :n:`@ltac2_expr` to select its next success.
+
+ Variables from the :n:`@tac2pat1` are statically bound in the body of the branch.
+ Variables from the :n:`@term` pattern have values of type `constr`.
+ Variables from the :n:`@ident` in the `context` construct have values of type
+ `Pattern.context` (defined in `Pattern.v`).
+
+Note that unlike Ltac1, only lowercase identifiers are valid as Ltac2
+bindings. Ltac2 will report an error if one of the bound variables
starts with an uppercase character.
-The semantics of this construction is otherwise the same as the corresponding
+The semantics of this construction are otherwise the same as the corresponding
one from Ltac1, except that it requires the goal to be focused.
+.. _ltac2_match_vs_lazymatch_ex:
+
+.. example:: Ltac2 Comparison of lazy_match! and match!
+
+ (Equivalent to this :ref:`Ltac1 example<match_vs_lazymatch_ex>`.)
+
+ These lines define a `msg` tactic that's used in several examples as a more-succinct
+ alternative to `print (to_string "...")`:
+
+ .. coqtop:: in
+
+ From Ltac2 Require Import Message.
+ Ltac2 msg x := print (of_string x).
+
+ .. coqtop:: none
+
+ Goal True.
+
+ In :tacn:`lazy_match!`, if :token:`ltac2_expr` fails, the :tacn:`lazy_match!` fails;
+ it doesn't look for further matches. In :tacn:`match!`, if :token:`ltac2_expr` fails
+ in a matching branch, it will try to match on subsequent branches. Note that
+ :n:`'@term` below is equivalent to :n:`open_constr:(@term)`.
+
+ .. coqtop:: all
+
+ Fail lazy_match! 'True with
+ | True => msg "branch 1"; fail
+ | _ => msg "branch 2"
+ end.
+
+ match! 'True with
+ | True => msg "branch 1"; fail
+ | _ => msg "branch 2"
+ end.
+
+.. _ltac2_match_vs_multimatch_ex:
+
+.. example:: Ltac2 Comparison of match! and multi_match!
+
+ (Equivalent to this :ref:`Ltac1 example<match_vs_multimatch_ex>`.)
+
+ :tacn:`match!` tactics are only evaluated once, whereas :tacn:`multi_match!`
+ tactics may be evaluated more than once if the following constructs trigger backtracking:
+
+ .. coqtop:: all
+
+ Fail match! 'True with
+ | True => msg "branch 1"
+ | _ => msg "branch 2"
+ end ;
+ msg "branch A"; fail.
+
+ .. coqtop:: all
+
+ Fail multi_match! 'True with
+ | True => msg "branch 1"
+ | _ => msg "branch 2"
+ end ;
+ msg "branch A"; fail.
+
+.. _ltac2_match_with_holes_ex:
+
+.. todo EXAMPLE DOESN'T WORK: Ltac2 does not (yet?) handle pattern variables matching open terms.
+ Matching a pattern with holes
+
+ (Equivalent to this :ref:`Ltac1 example<match_with_holes_ex>`.)
+
+ Notice the :tacn:`idtac` prints ``(z + 1)`` while the :tacn:`pose` substitutes
+ ``(x + 1)``.
+
+ .. coqtop:: all
+
+ match! constr:(fun x => (x + 1) * 3) with
+ | fun z => ?y * 3 => print (of_constr y); pose (fun z: nat => $y * 5)
+ end.
+
+.. _ltac2_match_term_context_ex:
+
+.. example:: Ltac2 Multiple matches for a "context" pattern.
+
+ (Equivalent to this :ref:`Ltac1 example<match_term_context_ex>`.)
+
+ Internally "x <> y" is represented as "(~ (x = y))", which produces the
+ first match.
+
+ .. coqtop:: in
+
+ Ltac2 f2 t := match! t with
+ | context [ (~ ?t) ] => print (of_constr t); fail
+ | _ => ()
+ end.
+
+ .. coqtop:: all abort
+
+ f2 constr:((~ True) <> (~ False)).
+
Match over goals
~~~~~~~~~~~~~~~~
-Similarly, there is a way to match over goals in an elegant way, which is
-just a notation desugared at parsing time.
+.. tacn:: @ltac2_match_key {? reverse } goal with @goal_match_list end
+ :name: lazy_match! goal; match! goal; multi_match! goal
-.. productionlist:: coq
- ltac2_term : match! [ reverse ] goal with `goalmatching` ... `goalmatching` end
- : lazy_match! [ reverse ] goal with `goalmatching` ... `goalmatching` end
- : multi_match! [ reverse ] goal with `goalmatching` ... `goalmatching` end
- goalmatching : | [ `hypmatching` ... `hypmatching` |- `constrpattern` ] => `ltac2_term`
- hypmatching : `lident` : `constrpattern`
- : _ : `constrpattern`
+ .. insertprodn goal_match_list gmatch_hyp_pattern
-Variables from :n:`@hypmatching` and :n:`@constrpattern` are bound in the body of the
-branch. Their types are:
+ .. prodn::
+ goal_match_list ::= {? %| } {+| @gmatch_rule }
+ gmatch_rule ::= @gmatch_pattern => @ltac2_expr
+ gmatch_pattern ::= [ {*, @gmatch_hyp_pattern } |- @ltac2_match_pattern ]
+ gmatch_hyp_pattern ::= @name : @ltac2_match_pattern
-- ``constr`` for pattern variables appearing in a :n:`@term`
-- ``Pattern.context`` for variables binding a context
-- ``ident`` for variables binding a hypothesis name.
+ Matches over goals, similar to Ltac1 :tacn:`match goal`.
+ Use this form to match hypotheses and/or goals in the proof context. These patterns have zero or
+ more subpatterns to match hypotheses followed by a subpattern to match the conclusion. Except for the
+ differences noted below, this works the same as the corresponding :n:`@ltac2_match_key @ltac2_expr` construct
+ (see :tacn:`match!`). Each current goal is processed independently.
-The same identifier caveat as in the case of matching over constr applies, and
-this features has the same semantics as in Ltac1. In particular, a ``reverse``
-flag can be specified to match hypotheses from the more recently introduced to
-the least recently introduced one.
+ Matching is non-linear: if a
+ metavariable occurs more than once, each occurrence must match the same
+ expression. Within a single term, expressions match if they are syntactically equal or
+ :term:`α-convertible <alpha-convertible>`. When a metavariable is used across
+ multiple hypotheses or across a hypothesis and the current goal, the expressions match if
+ they are :term:`convertible`.
-.. _ltac2_notations:
+ .. more detail here: https://github.com/coq/coq/pull/12085#discussion_r470406466
-Notations
----------
+ :n:`{*, @gmatch_pattern }`
+ Patterns to match with hypotheses. Each pattern must match a distinct hypothesis in order
+ for the branch to match.
-Notations are the crux of the usability of Ltac1. We should be able to recover
-a feeling similar to the old implementation by using and abusing notations.
+ Hypotheses have the form :n:`@name {? := @term__binder } : @type`. Currently Ltac2 doesn't
+ allow matching on or capturing the value of :n:`@term__binder`. It only supports matching on
+ the :token:`name` and the :token:`type`, for example `n : ?t`.
-Scopes
-~~~~~~
+ .. currently only supports the first row
+ :list-table::
+ :widths: 2 1
+ :header-rows: 1
-A scope is a name given to a grammar entry used to produce some Ltac2 expression
-at parsing time. Scopes are described using a form of S-expression.
+ * - Pattern syntax
+ - Example pattern
-.. prodn::
- ltac2_scope ::= {| @string | @int | @lident ({+, @ltac2_scope}) }
+ * - :n:`@name : @ltac2_match_pattern`
+ - `n : ?t`
-A few scopes contain antiquotation features. For the sake of uniformity, all
-antiquotations are introduced by the syntax :n:`$@lident`.
+ * - :n:`@name := @match_pattern__binder`
+ - `n := ?b`
-The following scopes are built-in.
+ * - :n:`@name := @term__binder : @type`
+ - `n := ?b : ?t`
-- :n:`constr`:
+ * - :n:`@name := [ @match_pattern__binder ] : @ltac2_match_pattern`
+ - `n := [ ?b ] : ?t`
- + parses :n:`c = @term` and produces :n:`constr:(c)`
+ :token:`name` can't have a `?`. Note that the last two forms are equivalent except that:
- This scope can be parameterized by a list of delimiting keys of notation
- scopes (as described in :ref:`LocalInterpretationRulesForNotations`),
- describing how to interpret the parsed term. For instance, :n:`constr(A, B)`
- parses :n:`c = @term` and produces :n:`constr:(c%A%B)`.
+ - if the `:` in the third form has been bound to something else in a notation, you must use the fourth form.
+ Note that cmd:`Require Import` `ssreflect` loads a notation that does this.
+ - a :n:`@term__binder` such as `[ ?l ]` (e.g., denoting a singleton list after
+ :cmd:`Import` `ListNotations`) must be parenthesized or, for the fourth form,
+ use double brackets: `[ [ ?l ] ]`.
-- :n:`ident`:
+ If there are multiple :token:`gmatch_hyp_pattern`\s in a branch, there may be multiple ways to match them to hypotheses.
+ For :tacn:`match! goal` and :tacn:`multi_match! goal`, if the evaluation of the :token:`ltac2_expr` fails,
+ matching will continue with the next hypothesis combination. When those are exhausted,
+ the next alternative from any `context` construct in the :token:`ltac2_match_pattern`\s is tried and then,
+ when the context alternatives are exhausted, the next branch is tried.
+ :ref:`Example<ltac2_match_goal_multiple_hyps_ex>`.
- + parses :n:`id = @ident` and produces :n:`ident:(id)`
- + parses :n:`$(x = @ident)` and produces the variable :n:`x`
+ `reverse`
+ Hypothesis matching for :token:`gmatch_hyp_pattern`\s normally begins by matching them from left to right,
+ to hypotheses, last to first. Specifying `reverse` begins matching in the reverse order, from
+ first to last. :ref:`Normal<ltac2_match_goal_hyps_ex>` and :ref:`reverse<ltac2_match_goal_hyps_rev_ex>` examples.
-- :n:`list0(@ltac2_scope)`:
+ :n:`|- @ltac2_match_pattern`
+ A pattern to match with the current goal
- + if :n:`@ltac2_scope` parses :n:`@quotentry`,
- then it parses :n:`(@quotentry__0, ..., @quotentry__n)` and produces
- :n:`[@quotentry__0; ...; @quotentry__n]`.
+ Note that unlike Ltac1, only lowercase identifiers are valid as Ltac2
+ bindings. Ltac2 will report an error if you try to use a bound variable
+ that starts with an uppercase character.
-- :n:`list0(@ltac2_scope, sep = @string__sep)`:
+ Variables from :n:`@gmatch_hyp_pattern` and :n:`@ltac2_match_pattern` are
+ bound in the body of the branch. Their types are:
- + if :n:`@ltac2_scope` parses :n:`@quotentry`,
- then it parses :n:`(@quotentry__0 @string__sep ... @string__sep @quotentry__n)`
- and produce :n:`[@quotentry__0; ...; @quotentry__n]`.
+ - ``constr`` for pattern variables appearing in a :n:`@term`
+ - ``Pattern.context`` for variables binding a context
+ - ``ident`` for variables binding a hypothesis name.
-- :n:`list1`: same as :n:`list0` (with or without separator) but parses :n:`{+ @quotentry}` instead
- of :n:`{* @quotentry}`.
+ The same identifier caveat as in the case of matching over constr applies, and
+ this feature has the same semantics as in Ltac1.
-- :n:`opt(@ltac2_scope)`
+.. _ltac2_match_goal_hyps_ex:
- + if :n:`@ltac2_scope` parses :n:`@quotentry`, parses :n:`{? @quotentry}` and produces either :n:`None` or
- :n:`Some x` where :n:`x` is the parsed expression.
+.. example:: Ltac2 Matching hypotheses
-- :n:`self`:
+ (Equivalent to this :ref:`Ltac1 example<match_goal_hyps_ex>`.)
- + parses a Ltac2 expression at the current level and returns it as is.
+ Hypotheses are matched from the last hypothesis (which is by default the newest
+ hypothesis) to the first until the :tacn:`apply` succeeds.
-- :n:`next`:
+ .. coqtop:: all abort
- + parses a Ltac2 expression at the next level and returns it as is.
+ Goal forall A B : Prop, A -> B -> (A->B).
+ intros.
+ match! goal with
+ | [ h : _ |- _ ] => let h := Control.hyp h in print (of_constr h); apply $h
+ end.
-- :n:`tactic(n = @int)`:
+.. _ltac2_match_goal_hyps_rev_ex:
- + parses a Ltac2 expression at the provided level :n:`n` and returns it as is.
+.. example:: Matching hypotheses with reverse
-- :n:`thunk(@ltac2_scope)`:
+ (Equivalent to this :ref:`Ltac1 example<match_goal_hyps_rev_ex>`.)
- + parses the same as :n:`scope`, and if :n:`e` is the parsed expression, returns
- :n:`fun () => e`.
+ Hypotheses are matched from the first hypothesis to the last until the :tacn:`apply` succeeds.
-- :n:`STRING`:
+ .. coqtop:: all abort
- + parses the corresponding string as an identifier and returns :n:`()`.
+ Goal forall A B : Prop, A -> B -> (A->B).
+ intros.
+ match! reverse goal with
+ | [ h : _ |- _ ] => let h := Control.hyp h in print (of_constr h); apply $h
+ end.
-- :n:`keyword(s = @string)`:
+.. _ltac2_match_goal_multiple_hyps_ex:
- + parses the string :n:`s` as a keyword and returns `()`.
+.. example:: Multiple ways to match a hypotheses
-- :n:`terminal(s = @string)`:
+ (Equivalent to this :ref:`Ltac1 example<match_goal_multiple_hyps_ex>`.)
- + parses the string :n:`s` as a keyword, if it is already a
- keyword, otherwise as an :n:`@ident`. Returns `()`.
+ Every possible match for the hypotheses is evaluated until the right-hand
+ side succeeds. Note that `h1` and `h2` are never matched to the same hypothesis.
+ Observe that the number of permutations can grow as the factorial
+ of the number of hypotheses and hypothesis patterns.
-- :n:`seq(@ltac2_scope__1, ..., @ltac2_scope__2)`:
+ .. coqtop:: all abort
- + parses :n:`scope__1`, ..., :n:`scope__n` in this order, and produces a tuple made
- out of the parsed values in the same order. As an optimization, all
- subscopes of the form :n:`STRING` are left out of the returned tuple, instead
- of returning a useless unit value. It is forbidden for the various
- subscopes to refer to the global entry using :n:`self` or :n:`next`.
+ Goal forall A B : Prop, A -> B -> (A->B).
+ intros A B H.
+ match! goal with
+ | [ h1 : _, h2 : _ |- _ ] =>
+ print (concat (of_string "match ")
+ (concat (of_constr (Control.hyp h1))
+ (concat (of_string " ")
+ (of_constr (Control.hyp h2)))));
+ fail
+ | [ |- _ ] => ()
+ end.
-A few other specific scopes exist to handle Ltac1-like syntax, but their use is
-discouraged and they are thus not documented.
-For now there is no way to declare new scopes from Ltac2 side, but this is
-planned.
+Match on values
+~~~~~~~~~~~~~~~
-Notations
-~~~~~~~~~
+.. tacn:: match @ltac2_expr5 with {? @ltac2_branches } end
+ :name: match (Ltac2)
+
+ Matches a value, akin to the OCaml `match` construct. By itself, it doesn't cause backtracking
+ as do the `*match*!` and `*match*! goal` constructs.
+
+ .. insertprodn ltac2_branches atomic_tac2pat
-The Ltac2 parser can be extended with syntactic notations.
+ .. prodn::
+ ltac2_branches ::= {? %| } {+| @tac2pat1 => @ltac2_expr }
+ tac2pat1 ::= @qualid {+ @tac2pat0 }
+ | @qualid
+ | [ ]
+ | @tac2pat0 :: @tac2pat0
+ | @tac2pat0
+ tac2pat0 ::= _
+ | ()
+ | @qualid
+ | ( {? @atomic_tac2pat } )
+ atomic_tac2pat ::= @tac2pat1 : @ltac2_type
+ | @tac2pat1 , {*, @tac2pat1 }
+ | @tac2pat1
-.. cmd:: Ltac2 Notation {+ {| @lident (@ltac2_scope) | @string } } {? : @int} := @ltac2_term
+.. note::
+
+ For now, deep pattern matching is not implemented.
+
+
+.. _ltac2_notations:
+
+Notations
+---------
+
+.. cmd:: Ltac2 Notation {+ @ltac2_scope } {? : @natural } := @ltac2_expr
:name: Ltac2 Notation
- A Ltac2 notation adds a parsing rule to the Ltac2 grammar, which is expanded
+ .. todo seems like name maybe should use lident rather than ident, considering:
+
+ Ltac2 Notation "ex1" X(constr) := print (of_constr X).
+ ex1 1.
+
+ Unbound constructor X
+
+ This works fine with lower-case "x" in place of "X"
+
+ .. todo Ltac2 Notation := permits redefining same symbol (no warning)
+ Also allows defining a symbol beginning with uppercase, which is prohibited
+ in similar constructs.
+
+ :cmd:`Ltac2 Notation` provides a way to extend the syntax of Ltac2 tactics. The left-hand
+ side (before the `:=`) defines the syntax to recognize and gives formal parameter
+ names for the syntactic values. :n:`@integer` is the level of the notation.
+ When the notation is used, the values are substituted
+ into the right-hand side. The right-hand side is typechecked when the notation is used,
+ not when it is defined. In the following example, `x` is the formal parameter name and
+ `constr` is its :ref:`syntactic class<syntactic_classes>`. `print` and `of_constr` are
+ functions provided by |Coq| through `Message.v`.
+
+ .. todo "print" doesn't seem to pay attention to "Set Printing All"
+
+ .. example:: Printing a :n:`@term`
+
+ .. coqtop:: none
+
+ Goal True.
+
+ .. coqtop:: all
+
+ From Ltac2 Require Import Message.
+ Ltac2 Notation "ex1" x(constr) := print (of_constr x).
+ ex1 (1 + 2).
+
+ You can also print terms with a regular Ltac2 definition, but then the :n:`@term` must be in
+ the quotation `constr:( … )`:
+
+ .. coqtop:: all
+
+ Ltac2 ex2 x := print (of_constr x).
+ ex2 constr:(1+2).
+
+ There are also metasyntactic classes described :ref:`here<syntactic_classes>`
+ that combine other items. For example, `list1(constr, ",")`
+ recognizes a comma-separated list of one or more :token:`term`\s.
+
+ .. example:: Parsing a list of :n:`@term`\s
+
+ .. coqtop:: abort all
+
+ Ltac2 rec print_list x := match x with
+ | a :: t => print (of_constr a); print_list t
+ | [] => ()
+ end.
+ Ltac2 Notation "ex2" x(list1(constr, ",")) := print_list x.
+ ex2 1, 2, 3.
+
+ An Ltac2 notation adds a parsing rule to the Ltac2 grammar, which is expanded
to the provided body where every token from the notation is let-bound to the
corresponding generated expression.
@@ -848,37 +1249,432 @@ The Ltac2 parser can be extended with syntactic notations.
Abbreviations
~~~~~~~~~~~~~
-.. cmdv:: Ltac2 Notation @lident := @ltac2_term
+.. cmd:: Ltac2 Notation {| @string | @lident } := @ltac2_expr
+ :name: Ltac2 Notation (abbreviation)
- This command introduces a special kind of notation, called an abbreviation,
- that is designed so that it does not add any parsing rules. It is similar in
- spirit to Coq abbreviations, insofar as its main purpose is to give an
- absolute name to a piece of pure syntax, which can be transparently referred to
- by this name as if it were a proper definition.
+ Introduces a special kind of notation, called an abbreviation,
+ that does not add any parsing rules. It is similar in
+ spirit to Coq abbreviations (see :cmd:`Notation (abbreviation)`,
+ insofar as its main purpose is to give an
+ absolute name to a piece of pure syntax, which can be transparently referred to
+ by this name as if it were a proper definition.
- The abbreviation can then be manipulated just as a normal Ltac2 definition,
- except that it is expanded at internalization time into the given expression.
- Furthermore, in order to make this kind of construction useful in practice in
- an effectful language such as Ltac2, any syntactic argument to an abbreviation
- is thunked on-the-fly during its expansion.
+ The abbreviation can then be manipulated just like a normal Ltac2 definition,
+ except that it is expanded at internalization time into the given expression.
+ Furthermore, in order to make this kind of construction useful in practice in
+ an effectful language such as Ltac2, any syntactic argument to an abbreviation
+ is thunked on-the-fly during its expansion.
-For instance, suppose that we define the following.
+ For instance, suppose that we define the following.
-:n:`Ltac2 Notation foo := fun x => x ().`
+ :n:`Ltac2 Notation foo := fun x => x ().`
-Then we have the following expansion at internalization time.
+ Then we have the following expansion at internalization time.
-:n:`foo 0 ↦ (fun x => x ()) (fun _ => 0)`
+ :n:`foo 0 ↦ (fun x => x ()) (fun _ => 0)`
-Note that abbreviations are not typechecked at all, and may result in typing
-errors after expansion.
+ Note that abbreviations are not type checked at all, and may result in typing
+ errors after expansion.
+
+.. _defining_tactics:
+
+Defining tactics
+~~~~~~~~~~~~~~~~
+
+Built-in tactics (those defined in OCaml code in the |Coq| executable) and Ltac1 tactics,
+which are defined in `.v` files, must be defined through notations. (Ltac2 tactics can be
+defined with :cmd:`Ltac2`.
+
+Notations for many but not all built-in tactics are defined in `Notations.v`, which is automatically
+loaded with Ltac2. The Ltac2 syntax for these tactics is often identical or very similar to the
+tactic syntax described in other chapters of this documentation. These notations rely on tactic functions
+declared in `Std.v`. Functions corresponding to some built-in tactics may not yet be defined in the
+|Coq| executable or declared in `Std.v`. Adding them may require code changes to |Coq| or defining
+workarounds through Ltac1 (described below).
+
+Two examples of syntax differences:
+
+- There is no notation defined that's equivalent to :n:`intros until {| @ident | @natural }`. There is,
+ however, already an ``intros_until`` tactic function defined ``Std.v``, so it may be possible for a user
+ to add the necessary notation.
+- The built-in `simpl` tactic in Ltac1 supports the use of scope keys in delta flags, e.g. :n:`simpl ["+"%nat]`
+ which is not accepted by Ltac2. This is because Ltac2 uses a different
+ definition for :token:`delta_flag`; compare it to :token:`ltac2_delta_flag`. This also affects
+ :tacn:`compute`.
+
+Ltac1 tactics are not automatically available in Ltac2. (Note that some of the tactics described
+in the documentation are defined with Ltac1.)
+You can make them accessible in Ltac2 with commands similar to the following:
+
+.. coqtop:: in
+
+ From Coq Require Import Lia.
+ Local Ltac2 lia_ltac1 () := ltac1:(lia).
+ Ltac2 Notation "lia" := lia_ltac1 ().
+
+A similar approach can be used to access missing built-in tactics. See :ref:`simple_api` for an
+example that passes two parameters to a missing build-in tactic.
+
+.. _syntactic_classes:
+
+Syntactic classes
+~~~~~~~~~~~~~~~~~
+
+The simplest syntactic classes in Ltac2 notations represent individual nonterminals
+from the |Coq| grammar. Only a few selected nonterminals are available as syntactic classes.
+In addition, there are metasyntactic operations for describing
+more complex syntax, such as making an item optional or representing a list of items.
+When parsing, each syntactic class expression returns a value that's bound to a name in the
+notation definition.
+
+Syntactic classes are described with a form of S-expression:
+
+ .. insertprodn ltac2_scope ltac2_scope
+
+ .. prodn::
+ ltac2_scope ::= @string
+ | @integer
+ | @name
+ | @name ( {+, @ltac2_scope } )
+
+.. todo no syn class for ints or strings?
+ parm names are not reserved (e.g the var can be named "list1")
+
+Metasyntactic operations that can be applied to other syntactic classes are:
+
+ :n:`opt(@ltac2_scope)`
+ Parses an optional :token:`ltac2_scope`. The associated value is either :n:`None` or
+ enclosed in :n:`Some`
+
+ :n:`list1(@ltac2_scope {? , @string })`
+ Parses a list of one or more :token:`ltac2_scope`\s. If :token:`string` is specified,
+ items must be separated by :token:`string`.
+
+ :n:`list0(@ltac2_scope {? , @string })`
+ Parses a list of zero or more :token:`ltac2_scope`\s. If :token:`string` is specified,
+ items must be separated by :token:`string`. For zero items, the associated value
+ is an empty list.
+
+ :n:`seq({+, @ltac2_scope })`
+ Parses the :token:`ltac2_scope`\s in order. The associated value is a tuple,
+ omitting :token:`ltac2_scope`\s that are :token:`string`\s.
+ `self` and `next` are not permitted within `seq`.
+
+The following classes represent nonterminals with some special handling. The
+table further down lists the classes that that are handled plainly.
+
+ :n:`constr {? ( {+, @scope_key } ) }`
+ Parses a :token:`term`. If specified, the :token:`scope_key`\s are used to interpret
+ the term (as described in :ref:`LocalInterpretationRulesForNotations`). The last
+ :token:`scope_key` is the top of the scope stack that's applied to the :token:`term`.
+
+ :n:`open_constr`
+ Parses an open :token:`term`.
+
+ :n:`ident`
+ Parses :token:`ident` or :n:`$@ident`. The first form returns :n:`ident:(@ident)`,
+ while the latter form returns the variable :n:`@ident`.
+
+ :n:`@string`
+ Accepts the specified string that is not a keyword, returning a value of `()`.
+
+ :n:`keyword(@string)`
+ Accepts the specified string that is a keyword, returning a value of `()`.
+
+ :n:`terminal(@string)`
+ Accepts the specified string whether it's a keyword or not, returning a value of `()`.
+
+ :n:`tactic {? (@integer) }`
+ Parses an :token:`ltac2_expr`. If :token:`integer` is specified, the construct
+ parses a :n:`ltac2_expr@integer`, for example `tactic(5)` parses :token:`ltac2_expr5`.
+ `tactic(6)` parses :token:`ltac2_expr`.
+ :token:`integer` must be in the range `0 .. 6`.
+
+ You can also use `tactic` to accept an :token:`integer` or a :token:`string`, but there's
+ no syntactic class that accepts *only* an :token:`integer` or a :token:`string`.
+
+ .. todo this doesn't work as expected: "::" is in ltac2_expr1
+ Ltac2 Notation "ex4" x(tactic(0)) := x.
+ ex4 auto :: [auto].
+
+ .. not sure "self" and "next" do anything special. I get the same error
+ message for both from constructs like
+
+ Ltac2 Notation "ex5" x(self) := auto.
+ ex5 match.
+
+ Syntax error: [tactic:tac2expr level 5] expected after 'match' (in [tactic:tac2expr]).
+
+ :n:`self`
+ parses an Ltac2 expression at the current level and returns it as is.
+
+ :n:`next`
+ parses an Ltac2 expression at the next level and returns it as is.
+
+ :n:`thunk(@ltac2_scope)`
+ Used for semantic effect only, parses the same as :token:`ltac2_scope`.
+ If :n:`e` is the parsed expression for :token:`ltac2_scope`, `thunk`
+ returns :n:`fun () => e`.
+
+ :n:`pattern`
+ parses a :token:`cpattern`
+
+A few syntactic classes contain antiquotation features. For the sake of uniformity, all
+antiquotations are introduced by the syntax :n:`$@lident`.
+
+A few other specific syntactic classes exist to handle Ltac1-like syntax, but their use is
+discouraged and they are thus not documented.
+
+For now there is no way to declare new syntactic classes from the Ltac2 side, but this is
+planned.
+
+Other nonterminals that have syntactic classes are listed here.
+
+ .. list-table::
+ :header-rows: 1
+
+ * - Syntactic class name
+ - Nonterminal
+ - Similar non-Ltac2 syntax
+
+ * - :n:`intropatterns`
+ - :token:`ltac2_intropatterns`
+ - :token:`intropattern_list`
+
+ * - :n:`intropattern`
+ - :token:`ltac2_simple_intropattern`
+ - :token:`simple_intropattern`
+
+ * - :n:`ident`
+ - :token:`ident_or_anti`
+ - :token:`ident`
+
+ * - :n:`destruction_arg`
+ - :token:`ltac2_destruction_arg`
+ - :token:`destruction_arg`
+
+ * - :n:`with_bindings`
+ - :token:`q_with_bindings`
+ - :n:`{? with @bindings }`
+
+ * - :n:`bindings`
+ - :token:`ltac2_bindings`
+ - :token:`bindings`
+
+ * - :n:`strategy`
+ - :token:`ltac2_strategy_flag`
+ - :token:`strategy_flag`
+
+ * - :n:`reference`
+ - :token:`refglobal`
+ - :token:`reference`
+
+ * - :n:`clause`
+ - :token:`ltac2_clause`
+ - :token:`clause_dft_concl`
+
+ * - :n:`occurrences`
+ - :token:`q_occurrences`
+ - :n:`{? at @occs_nums }`
+
+ * - :n:`induction_clause`
+ - :token:`ltac2_induction_clause`
+ - :token:`induction_clause`
+
+ * - :n:`conversion`
+ - :token:`ltac2_conversion`
+ - :token:`conversion`
+
+ * - :n:`rewriting`
+ - :token:`ltac2_oriented_rewriter`
+ - :token:`oriented_rewriter`
+
+ * - :n:`dispatch`
+ - :token:`ltac2_for_each_goal`
+ - :token:`for_each_goal`
+
+ * - :n:`hintdb`
+ - :token:`hintdb`
+ - :token:`hintbases`
+
+ * - :n:`move_location`
+ - :token:`move_location`
+ - :token:`where`
+
+ * - :n:`pose`
+ - :token:`pose`
+ - :token:`bindings_with_parameters`
+
+ * - :n:`assert`
+ - :token:`assertion`
+ - :n:`( @ident := @term )`
+
+ * - :n:`constr_matching`
+ - :token:`ltac2_match_list`
+ - See :tacn:`match`
+
+ * - :n:`goal_matching`
+ - :token:`goal_match_list`
+ - See :tacn:`match goal`
+
+Here is the syntax for the :n:`q_*` nonterminals:
+
+.. insertprodn ltac2_intropatterns nonsimple_intropattern
+
+.. prodn::
+ ltac2_intropatterns ::= {* @nonsimple_intropattern }
+ nonsimple_intropattern ::= *
+ | **
+ | @ltac2_simple_intropattern
+
+.. insertprodn ltac2_simple_intropattern ltac2_naming_intropattern
+
+.. prodn::
+ ltac2_simple_intropattern ::= @ltac2_naming_intropattern
+ | _
+ | @ltac2_or_and_intropattern
+ | @ltac2_equality_intropattern
+ ltac2_or_and_intropattern ::= [ {+| @ltac2_intropatterns } ]
+ | ()
+ | ( {+, @ltac2_simple_intropattern } )
+ | ( {+& @ltac2_simple_intropattern } )
+ ltac2_equality_intropattern ::= ->
+ | <-
+ | [= @ltac2_intropatterns ]
+ ltac2_naming_intropattern ::= ? @lident
+ | ?$ @lident
+ | ?
+ | @ident_or_anti
+
+.. insertprodn ident_or_anti ident_or_anti
+
+.. prodn::
+ ident_or_anti ::= @lident
+ | $ @ident
+
+.. insertprodn ltac2_destruction_arg ltac2_constr_with_bindings
+
+.. prodn::
+ ltac2_destruction_arg ::= @natural
+ | @lident
+ | @ltac2_constr_with_bindings
+ ltac2_constr_with_bindings ::= @term {? with @ltac2_bindings }
+
+.. insertprodn q_with_bindings qhyp
+
+.. prodn::
+ q_with_bindings ::= {? with @ltac2_bindings }
+ ltac2_bindings ::= {+ @ltac2_simple_binding }
+ | {+ @term }
+ ltac2_simple_binding ::= ( @qhyp := @term )
+ qhyp ::= $ @ident
+ | @natural
+ | @lident
+
+.. insertprodn ltac2_strategy_flag ltac2_delta_flag
+
+.. prodn::
+ ltac2_strategy_flag ::= {+ @ltac2_red_flag }
+ | {? @ltac2_delta_flag }
+ ltac2_red_flag ::= beta
+ | iota
+ | match
+ | fix
+ | cofix
+ | zeta
+ | delta {? @ltac2_delta_flag }
+ ltac2_delta_flag ::= {? - } [ {+ @refglobal } ]
+
+.. insertprodn refglobal refglobal
+
+.. prodn::
+ refglobal ::= & @ident
+ | @qualid
+ | $ @ident
+
+.. insertprodn ltac2_clause ltac2_in_clause
+
+.. prodn::
+ ltac2_clause ::= in @ltac2_in_clause
+ | at @ltac2_occs_nums
+ ltac2_in_clause ::= * {? @ltac2_occs }
+ | * |- {? @ltac2_concl_occ }
+ | {*, @ltac2_hypident_occ } {? |- {? @ltac2_concl_occ } }
+
+.. insertprodn q_occurrences ltac2_hypident
+
+.. prodn::
+ q_occurrences ::= {? @ltac2_occs }
+ ltac2_occs ::= at @ltac2_occs_nums
+ ltac2_occs_nums ::= {? - } {+ {| @natural | $ @ident } }
+ ltac2_concl_occ ::= * {? @ltac2_occs }
+ ltac2_hypident_occ ::= @ltac2_hypident {? @ltac2_occs }
+ ltac2_hypident ::= @ident_or_anti
+ | ( type of @ident_or_anti )
+ | ( value of @ident_or_anti )
+
+.. insertprodn ltac2_induction_clause ltac2_eqn_ipat
+
+.. prodn::
+ ltac2_induction_clause ::= @ltac2_destruction_arg {? @ltac2_as_or_and_ipat } {? @ltac2_eqn_ipat } {? @ltac2_clause }
+ ltac2_as_or_and_ipat ::= as @ltac2_or_and_intropattern
+ ltac2_eqn_ipat ::= eqn : @ltac2_naming_intropattern
+
+.. insertprodn ltac2_conversion ltac2_conversion
+
+.. prodn::
+ ltac2_conversion ::= @term
+ | @term with @term
+
+.. insertprodn ltac2_oriented_rewriter ltac2_rewriter
+
+.. prodn::
+ ltac2_oriented_rewriter ::= {| -> | <- } @ltac2_rewriter
+ ltac2_rewriter ::= {? @natural } {? {| ? | ! } } @ltac2_constr_with_bindings
+
+.. insertprodn ltac2_for_each_goal ltac2_goal_tactics
+
+.. prodn::
+ ltac2_for_each_goal ::= @ltac2_goal_tactics
+ | {? @ltac2_goal_tactics %| } {? @ltac2_expr } .. {? %| @ltac2_goal_tactics }
+ ltac2_goal_tactics ::= {*| {? @ltac2_expr } }
+
+.. insertprodn hintdb hintdb
+
+.. prodn::
+ hintdb ::= *
+ | {+ @ident_or_anti }
+
+.. insertprodn move_location move_location
+
+.. prodn::
+ move_location ::= at top
+ | at bottom
+ | after @ident_or_anti
+ | before @ident_or_anti
+
+.. insertprodn pose ltac2_as_name
+
+.. prodn::
+ pose ::= ( @ident_or_anti := @term )
+ | @term {? @ltac2_as_name }
+ ltac2_as_name ::= as @ident_or_anti
+
+.. insertprodn assertion ltac2_by_tactic
+
+.. prodn::
+ assertion ::= ( @ident_or_anti := @term )
+ | ( @ident_or_anti : @term ) {? @ltac2_by_tactic }
+ | @term {? @ltac2_as_ipat } {? @ltac2_by_tactic }
+ ltac2_as_ipat ::= as @ltac2_simple_intropattern
+ ltac2_by_tactic ::= by @ltac2_expr
Evaluation
----------
Ltac2 features a toplevel loop that can be used to evaluate expressions.
-.. cmd:: Ltac2 Eval @ltac2_term
+.. cmd:: Ltac2 Eval @ltac2_expr
:name: Ltac2 Eval
This command evaluates the term in the current proof if there is one, or in the
@@ -899,22 +1695,26 @@ Compatibility layer with Ltac1
Ltac1 from Ltac2
~~~~~~~~~~~~~~~~
+.. _simple_api:
+
Simple API
++++++++++
-One can call Ltac1 code from Ltac2 by using the :n:`ltac1` quotation. It parses
+One can call Ltac1 code from Ltac2 by using the :n:`ltac1:(@ltac1_expr_in_env)` quotation.
+See :ref:`ltac2_built-in-quotations`. It parses
a Ltac1 expression, and semantics of this quotation is the evaluation of the
corresponding code for its side effects. In particular, it cannot return values,
and the quotation has type :n:`unit`.
-.. productionlist:: coq
- ltac2_term : ltac1 : ( `ltac_expr` )
-
Ltac1 **cannot** implicitly access variables from the Ltac2 scope, but this can
-be done with an explicit annotation on the :n:`ltac1` quotation.
+be done with an explicit annotation on the :n:`ltac1:({* @ident } |- @ltac_expr)`
+quotation. See :ref:`ltac2_built-in-quotations`. For example:
-.. productionlist:: coq
- ltac2_term : ltac1 : ( `ident` ... `ident` |- `ltac_expr` )
+.. coqtop:: in
+
+ Local Ltac2 replace_with (lhs: constr) (rhs: constr) :=
+ ltac1:(lhs rhs |- replace lhs with rhs) (Ltac1.of_constr lhs) (Ltac1.of_constr rhs).
+ Ltac2 Notation "replace" lhs(constr) "with" rhs(constr) := replace_with lhs rhs.
The return type of this expression is a function of the same arity as the number
of identifiers, with arguments of type `Ltac2.Ltac1.t` (see below). This syntax
@@ -922,6 +1722,8 @@ will bind the variables in the quoted Ltac1 code as if they had been bound from
Ltac1 itself. Similarly, the arguments applied to the quotation will be passed
at runtime to the Ltac1 code.
+.. _low_level_api:
+
Low-level API
+++++++++++++
@@ -948,8 +1750,8 @@ Same as above by switching Ltac1 by Ltac2 and using the `ltac2` quotation
instead.
.. prodn::
- ltac_expr += ltac2 : ( `ltac2_term` )
- | ltac2 : ( `ident` ... `ident` |- `ltac2_term` )
+ ltac_expr += ltac2 : ( @ltac2_expr )
+ | ltac2 : ( {+ @ident } |- @ltac2_expr )
The typing rules are dual, that is, the optional identifiers are bound
with type `Ltac2.Ltac1.t` in the Ltac2 expression, which is expected to have
@@ -992,7 +1794,7 @@ Transition from Ltac1
Owing to the use of a lot of notations, the transition should not be too
difficult. In particular, it should be possible to do it incrementally. That
-said, we do *not* guarantee you it is going to be a blissful walk either.
+said, we do *not* guarantee it will be a blissful walk either.
Hopefully, owing to the fact Ltac2 is typed, the interactive dialogue with Coq
will help you.
diff --git a/doc/sphinx/proof-engine/proof-handling.rst b/doc/sphinx/proof-engine/proof-handling.rst
index 00aafe1266..f90ebadb3a 100644
--- a/doc/sphinx/proof-engine/proof-handling.rst
+++ b/doc/sphinx/proof-engine/proof-handling.rst
@@ -156,6 +156,10 @@ list of assertion commands is given in :ref:`Assertions`. The command
``T``, then the commands ``Proof using a`` and ``Proof using T a``
are equivalent.
+ The set of declared variables always includes the variables used by
+ the statement. In other words ``Proof using e`` is equivalent to
+ ``Proof using Type + e`` for any declaration expression ``e``.
+
.. cmdv:: Proof using {+ @ident } with @tactic
Combines in a single line :cmd:`Proof with` and :cmd:`Proof using`.
@@ -255,9 +259,9 @@ Name a set of section hypotheses for ``Proof using``
-.. cmd:: Existential @num := @term
+.. cmd:: Existential @natural := @term
- This command instantiates an existential variable. :token:`num` is an index in
+ This command instantiates an existential variable. :token:`natural` is an index in
the list of uninstantiated existential variables displayed by :cmd:`Show Existentials`.
This command is intended to be used to instantiate existential
@@ -309,9 +313,9 @@ Navigation in the proof tree
This command cancels the effect of the last command. Thus, it
backtracks one step.
-.. cmdv:: Undo @num
+.. cmdv:: Undo @natural
- Repeats Undo :token:`num` times.
+ Repeats Undo :token:`natural` times.
.. cmdv:: Restart
:name: Restart
@@ -332,9 +336,9 @@ Navigation in the proof tree
Prefer the use of bullets or focusing brackets (see below).
-.. cmdv:: Focus @num
+.. cmdv:: Focus @natural
- This focuses the attention on the :token:`num` th subgoal to prove.
+ This focuses the attention on the :token:`natural` th subgoal to prove.
.. deprecated:: 8.8
@@ -369,9 +373,9 @@ Navigation in the proof tree
together with a suggestion about the right bullet or ``}`` to unfocus it
or focus the next one.
- .. cmdv:: @num: %{
+ .. cmdv:: @natural: %{
- This focuses on the :token:`num`\-th subgoal to prove.
+ This focuses on the :token:`natural`\-th subgoal to prove.
.. cmdv:: [@ident]: %{
@@ -435,7 +439,7 @@ Navigation in the proof tree
You are trying to use ``}`` but the current subproof has not been fully solved.
- .. exn:: No such goal (@num).
+ .. exn:: No such goal (@natural).
:undocumented:
.. exn:: No such goal (@ident).
@@ -555,9 +559,9 @@ Requesting information
.. exn:: No focused proof.
:undocumented:
- .. cmdv:: Show @num
+ .. cmdv:: Show @natural
- Displays only the :token:`num`\-th subgoal.
+ Displays only the :token:`natural`\-th subgoal.
.. exn:: No such goal.
:undocumented:
@@ -645,7 +649,7 @@ Requesting information
its normalized form at the current stage of the proof, useful for
debugging universe inconsistencies.
- .. cmdv:: Show Goal @num at @num
+ .. cmdv:: Show Goal @natural at @natural
:name: Show Goal
This command is only available in coqtop. Displays a goal at a
@@ -834,7 +838,7 @@ Controlling the effect of proof editing commands
------------------------------------------------
-.. opt:: Hyps Limit @num
+.. opt:: Hyps Limit @natural
:name: Hyps Limit
This option controls the maximum number of hypotheses displayed in goals
@@ -858,19 +862,28 @@ Controlling the effect of proof editing commands
Controlling memory usage
------------------------
+.. cmd:: Print Debug GC
+
+ Prints heap usage statistics, which are values from the `stat` type of the `Gc` module
+ described
+ `here <https://caml.inria.fr/pub/docs/manual-ocaml/libref/Gc.html#TYPEstat>`_
+ in the OCaml documentation.
+ The `live_words`, `heap_words` and `top_heap_words` values give the basic information.
+ Words are 8 bytes or 4 bytes, respectively, for 64- and 32-bit executables.
+
When experiencing high memory usage the following commands can be used
to force |Coq| to optimize some of its internal data structures.
-
.. cmd:: Optimize Proof
- This command forces |Coq| to shrink the data structure used to represent
- the ongoing proof.
+ Shrink the data structure used to represent the current proof.
.. cmd:: Optimize Heap
- This command forces the |OCaml| runtime to perform a heap compaction.
- This is in general an expensive operation.
- See: `OCaml Gc <http://caml.inria.fr/pub/docs/manual-ocaml/libref/Gc.html#VALcompact>`_
+ Perform a heap compaction. This is generally an expensive operation.
+ See: `OCaml Gc.compact <http://caml.inria.fr/pub/docs/manual-ocaml/libref/Gc.html#VALcompact>`_
There is also an analogous tactic :tacn:`optimize_heap`.
+
+Memory usage parameters can be set through the :ref:`OCAMLRUNPARAM <OCAMLRUNPARAM>`
+environment variable.
diff --git a/doc/sphinx/proof-engine/ssreflect-proof-language.rst b/doc/sphinx/proof-engine/ssreflect-proof-language.rst
index 3b4b80ca21..ca50a02562 100644
--- a/doc/sphinx/proof-engine/ssreflect-proof-language.rst
+++ b/doc/sphinx/proof-engine/ssreflect-proof-language.rst
@@ -617,7 +617,7 @@ Abbreviations
selected occurrences of a term.
.. prodn::
- occ_switch ::= { {? {| + | - } } {* @num } }
+ occ_switch ::= { {? {| + | - } } {* @natural } }
where:
@@ -1211,6 +1211,8 @@ The move tactic.
:tacn:`revert`, :tacn:`rename`, :tacn:`clear` and :tacn:`pattern` tactics.
+.. _the_case_tactic_ssr:
+
The case tactic
```````````````
@@ -1235,7 +1237,17 @@ The case tactic
x = 1 -> y = 2 -> G.
- Note also that the case of |SSR| performs :g:`False` elimination, even
+ The :tacn:`case` can generate the following warning:
+
+ .. warn:: SSReflect: cannot obtain new equations out of ...
+
+ The tactic was run on an equation that cannot generate simpler equations,
+ for example `x = 1`.
+
+ The warning can be silenced or made fatal by using the :opt:`Warnings` option
+ and the `spurious-ssr-injection` key.
+
+ Finally the :tacn:`case` tactic of |SSR| performs :g:`False` elimination, even
if no branch is generated by this case operation. Hence the tactic
:tacn:`case` on a goal of the form :g:`False -> G` will succeed and
prove the goal.
@@ -1568,7 +1580,7 @@ whose general syntax is
i_pattern ::= {| @ident | > | _ | ? | * | + | {? @occ_switch } {| -> | <- } | [ {?| @i_item } ] | - | [: {+ @ident } ] }
.. prodn::
- i_block ::= {| [^ @ident ] | [^~ {| @ident | @num } ] }
+ i_block ::= {| [^ @ident ] | [^~ {| @ident | @natural } ] }
The ``=>`` tactical first executes :token:`tactic`, then the :token:`i_item`\s,
left to right. An :token:`s_item` specifies a
@@ -1830,8 +1842,8 @@ Block introduction
:n:`[^~ @ident ]`
*block destructing* using :token:`ident` as a suffix.
-:n:`[^~ @num ]`
- *block destructing* using :token:`num` as a suffix.
+:n:`[^~ @natural ]`
+ *block destructing* using :token:`natural` as a suffix.
Only a :token:`s_item` is allowed between the elimination tactic and
the block destructing.
@@ -2224,17 +2236,17 @@ tactics to *permute* the subgoals generated by a tactic.
These two equivalent tactics invert the order of the subgoals in focus.
- .. tacv:: last @num first
+ .. tacv:: last @natural first
- If :token:`num`\'s value is :math:`k`,
+ If :token:`natural`\'s value is :math:`k`,
this tactic rotates the :math:`n` subgoals :math:`G_1` , …, :math:`G_n`
in focus. Subgoal :math:`G_{n + 1 − k}` becomes the first, and the
circular order of subgoals remains unchanged.
- .. tacn:: first @num last
+ .. tacn:: first @natural last
:name: first (ssreflect)
- If :token:`num`\'s value is :math:`k`,
+ If :token:`natural`\'s value is :math:`k`,
this tactic rotates the :math:`n` subgoals :math:`G_1` , …, :math:`G_n`
in focus. Subgoal :math:`G_{k + 1 \bmod n}` becomes the first, and the circular order
of subgoals remains unchanged.
@@ -2307,7 +2319,7 @@ tactic should be repeated on the current subgoal.
There are four kinds of multipliers:
.. prodn::
- mult ::= {| @num ! | ! | @num ? | ? }
+ mult ::= {| @natural ! | ! | @natural ? | ? }
Their meaning is:
@@ -3098,7 +3110,7 @@ An :token:`r_item` can be:
+ A list of terms ``(t1 ,…,tn)``, each ``ti`` having a type above.
The tactic: ``rewrite r_prefix (t1 ,…,tn ).``
is equivalent to: ``do [rewrite r_prefix t1 | … | rewrite r_prefix tn ].``
- + An anonymous rewrite lemma ``(_ : term)``, where term has a type as above. tactic: ``rewrite (_ : term)`` is in fact synonym of: ``cutrewrite (term).``.
+ + An anonymous rewrite lemma ``(_ : term)``, where term has a type as above.
.. example::
@@ -4074,7 +4086,7 @@ will generally fail to perform congruence simplification, even on
rather simple cases. We therefore provide a more robust alternative in
which the function is supplied:
-.. tacn:: congr {? @num } @term
+.. tacn:: congr {? @natural } @term
:name: congr
This tactic:
@@ -4108,7 +4120,7 @@ which the function is supplied:
Lemma test (x y z : nat) : x = y -> x = z.
congr (_ = _).
- The optional :token:`num` forces the number of arguments for which the
+ The optional :token:`natural` forces the number of arguments for which the
tactic should generate equality proof obligations.
This tactic supports equalities between applications with dependent
@@ -5380,8 +5392,8 @@ In this context, the identity view can be used when no view has to be applied:
Declaring new Hint Views
~~~~~~~~~~~~~~~~~~~~~~~~
-.. cmd:: Hint View for move / @ident {? | @num }
- Hint View for apply / @ident {? | @num }
+.. cmd:: Hint View for move / @ident {? | @natural }
+ Hint View for apply / @ident {? | @natural }
This command can be used to extend the database of hints for the view
mechanism.
@@ -5398,7 +5410,7 @@ Declaring new Hint Views
views. The optional natural number is the number of implicit
arguments to be considered for the declared hint view lemma.
- .. cmdv:: Hint View for apply//@ident {? | @num }
+ .. cmdv:: Hint View for apply//@ident {? | @natural }
This variant with a double slash ``//``, declares hint views for right
hand sides of double views.
@@ -5559,9 +5571,9 @@ Module name
Natural number
-.. prodn:: natural ::= {| @num | @ident }
+.. prodn:: nat_or_ident ::= {| @natural | @ident }
-where :token:`ident` is an Ltac variable denoting a standard |Coq| numeral
+where :token:`ident` is an Ltac variable denoting a standard |Coq| number
(should not be the name of a tactic which can be followed by a
bracket ``[``, like ``do``, ``have``,…)
@@ -5584,11 +5596,11 @@ context pattern see :ref:`contextual_patterns_ssr`
discharge item see :ref:`discharge_ssr`
-.. prodn:: gen_item ::= {| {? @ } @ident | ( @ident ) | ( {? @ } @ident := @c_pattern ) }
+.. prodn:: gen_item ::= {| {? @ } @ident | ( @ident ) | ( {? @ } @ident := @c_pattern ) }
generalization item see :ref:`structure_ssr`
-.. prodn:: i_pattern ::= {| @ident | > | _ | ? | * | + | {? @occ_switch } {| -> | <- } | [ {?| @i_item } ] | - | [: {+ @ident } ] }
+.. prodn:: i_pattern ::= {| @ident | > | _ | ? | * | + | {? @occ_switch } {| -> | <- } | [ {?| @i_item } ] | - | [: {+ @ident } ] }
intro pattern :ref:`introduction_ssr`
@@ -5602,19 +5614,19 @@ view :ref:`introduction_ssr`
intro block :ref:`introduction_ssr`
.. prodn::
- i_block ::= {| [^ @ident ] | [^~ {| @ident | @num } ] }
+ i_block ::= {| [^ @ident ] | [^~ {| @ident | @natural } ] }
intro item see :ref:`introduction_ssr`
-.. prodn:: int_mult ::= {? @num } @mult_mark
+.. prodn:: int_mult ::= {? @natural } @mult_mark
multiplier see :ref:`iteration_ssr`
-.. prodn:: occ_switch ::= { {? {| + | - } } {* @num } }
+.. prodn:: occ_switch ::= { {? {| + | - } } {* @natural } }
occur. switch see :ref:`occurrence_selection_ssr`
-.. prodn:: mult ::= {? @num } @mult_mark
+.. prodn:: mult ::= {? @natural } @mult_mark
multiplier see :ref:`iteration_ssr`
@@ -5729,7 +5741,7 @@ respectively.
unlock (see :ref:`locking_ssr`)
-.. tacn:: congr {? @num } @term
+.. tacn:: congr {? @natural } @term
congruence (see :ref:`congruence_ssr`)
@@ -5753,11 +5765,11 @@ localization see :ref:`localization_ssr`
iteration see :ref:`iteration_ssr`
-.. prodn:: tactic += @tactic ; {| first | last } {? @num } {| @tactic | [ {+| @tactic } ] }
+.. prodn:: tactic += @tactic ; {| first | last } {? @natural } {| @tactic | [ {+| @tactic } ] }
selector see :ref:`selectors_ssr`
-.. prodn:: tactic += @tactic ; {| first | last } {? @num }
+.. prodn:: tactic += @tactic ; {| first | last } {? @natural }
rotation see :ref:`selectors_ssr`
@@ -5768,11 +5780,11 @@ closing see :ref:`terminators_ssr`
Commands
~~~~~~~~
-.. cmd:: Hint View for {| move | apply } / @ident {? | @num }
+.. cmd:: Hint View for {| move | apply } / @ident {? | @natural }
view hint declaration (see :ref:`declaring_new_hints_ssr`)
-.. cmd:: Hint View for apply // @ident {? @num }
+.. cmd:: Hint View for apply // @ident {? @natural }
right hand side double , view hint declaration (see :ref:`declaring_new_hints_ssr`)
diff --git a/doc/sphinx/proof-engine/tactics.rst b/doc/sphinx/proof-engine/tactics.rst
index 25c4de7389..2f505e7448 100644
--- a/doc/sphinx/proof-engine/tactics.rst
+++ b/doc/sphinx/proof-engine/tactics.rst
@@ -54,14 +54,14 @@ Invocation of tactics
~~~~~~~~~~~~~~~~~~~~~
A tactic is applied as an ordinary command. It may be preceded by a
-goal selector (see Section :ref:`ltac-semantics`). If no selector is
+goal selector (see Section :ref:`goal-selectors`). If no selector is
specified, the default selector is used.
.. _tactic_invocation_grammar:
- .. productionlist:: sentence
- tactic_invocation : `toplevel_selector` : `tactic`.
- : `tactic`.
+ .. prodn::
+ tactic_invocation ::= @toplevel_selector : @tactic.
+ | @tactic.
.. todo: fully describe selectors. At the moment, ltac has a fairly complete description
@@ -98,14 +98,14 @@ The general form of a term with a bindings list is
.. _bindings_list_grammar:
- .. productionlist:: bindings_list
- ref : `ident`
- : `num`
- bindings_list : (`ref` := `term`) ... (`ref` := `term`)
- : `term` ... `term`
+ .. prodn::
+ ref ::= @ident
+ | @natural
+ bindings_list ::= {+ (@ref := @term) }
+ | {+ @term }
+ In a bindings list of the form :n:`{+ (@ref:= @term)}`, :n:`@ref` is either an
- :n:`@ident` or a :n:`@num`. The references are determined according to the type of
+ :n:`@ident` or a :n:`@natural`. The references are determined according to the type of
:n:`@term`. If :n:`@ref` is an identifier, this identifier has to be bound in the
type of :n:`@term` and the binding provides the tactic with an instance for the
parameter of this name. If :n:`@ref` is a number ``n``, it refers to
@@ -137,30 +137,28 @@ introduced by tactics. They also let you split an introduced hypothesis into
multiple hypotheses or subgoals. Common tactics that accept intro patterns
include :tacn:`assert`, :tacn:`intros` and :tacn:`destruct`.
-.. productionlist:: coq
- intropattern_list : `intropattern` ... `intropattern`
- : `empty`
- empty :
- intropattern : *
- : **
- : `simple_intropattern`
- simple_intropattern : `simple_intropattern_closed` [ % `term` ... % `term` ]
- simple_intropattern_closed : `naming_intropattern`
- : _
- : `or_and_intropattern`
- : `rewriting_intropattern`
- : `injection_intropattern`
- naming_intropattern : `ident`
- : ?
- : ?`ident`
- or_and_intropattern : [ `intropattern_list` | ... | `intropattern_list` ]
- : ( `simple_intropattern` , ... , `simple_intropattern` )
- : ( `simple_intropattern` & ... & `simple_intropattern` )
- rewriting_intropattern : ->
- : <-
- injection_intropattern : [= `intropattern_list` ]
- or_and_intropattern_loc : `or_and_intropattern`
- : `ident`
+.. prodn::
+ intropattern_list ::= {* @intropattern }
+ intropattern ::= *
+ | **
+ | @simple_intropattern
+ simple_intropattern ::= @simple_intropattern_closed {* % @term0 }
+ simple_intropattern_closed ::= @naming_intropattern
+ | _
+ | @or_and_intropattern
+ | @rewriting_intropattern
+ | @injection_intropattern
+ naming_intropattern ::= @ident
+ | ?
+ | ?@ident
+ or_and_intropattern ::= [ {*| @intropattern_list } ]
+ | ( {*, @simple_intropattern } )
+ | ( {*& @simple_intropattern } )
+ rewriting_intropattern ::= ->
+ | <-
+ injection_intropattern ::= [= @intropattern_list ]
+ or_and_intropattern_loc ::= @or_and_intropattern
+ | ident
Note that the intro pattern syntax varies between tactics.
Most tactics use :n:`@simple_intropattern` in the grammar.
@@ -480,13 +478,13 @@ Occurrence sets and occurrence clauses
An occurrence clause is a modifier to some tactics that obeys the
following syntax:
- .. productionlist:: coq
- occurrence_clause : in `goal_occurrences`
- goal_occurrences : [`ident` [`at_occurrences`], ... , `ident` [`at_occurrences`] [|- [* [`at_occurrences`]]]]
- : * |- [* [`at_occurrences`]]
- : *
- at_occurrences : at `occurrences`
- occurrences : [-] `num` ... `num`
+ .. prodn::
+ occurrence_clause ::= in @goal_occurrences
+ goal_occurrences ::= {*, @ident {? @at_occurrences } } {? |- {? * {? @at_occurrences } } }
+ | * |- {? * {? @at_occurrences } }
+ | *
+ at_occurrences ::= at @occurrences
+ occurrences ::= {? - } {* @natural }
The role of an occurrence clause is to select a set of occurrences of a term
in a goal. In the first case, the :n:`@ident {? at {* num}}` parts indicate
@@ -923,11 +921,11 @@ Applying theorems
This summarizes the different syntactic variants of :n:`apply @term in @ident`
and :n:`eapply @term in @ident`.
-.. tacn:: constructor @num
+.. tacn:: constructor @natural
:name: constructor
This tactic applies to a goal such that its conclusion is an inductive
- type (say :g:`I`). The argument :token:`num` must be less or equal to the
+ type (say :g:`I`). The argument :token:`natural` must be less or equal to the
numbers of constructor(s) of :g:`I`. Let :n:`c__i` be the i-th
constructor of :g:`I`, then :g:`constructor i` is equivalent to
:n:`intros; apply c__i`.
@@ -944,7 +942,7 @@ Applying theorems
:g:`constructor n` where ``n`` is the number of constructors of the head
of the goal.
- .. tacv:: constructor @num with @bindings_list
+ .. tacv:: constructor @natural with @bindings_list
Let ``c`` be the i-th constructor of :g:`I`, then
:n:`constructor i with @bindings_list` is equivalent to
@@ -1075,9 +1073,9 @@ Managing the local context
.. exn:: No such hypothesis in current goal.
:undocumented:
- .. tacv:: intros until @num
+ .. tacv:: intros until @natural
- This repeats :tacn:`intro` until the :token:`num`\-th non-dependent
+ This repeats :tacn:`intro` until the :token:`natural`\-th non-dependent
product.
.. example::
@@ -1093,7 +1091,7 @@ Managing the local context
.. exn:: No such hypothesis in current goal.
- This happens when :token:`num` is 0 or is greater than the number of
+ This happens when :token:`natural` is 0 or is greater than the number of
non-dependent products of the goal.
.. tacv:: intro {? @ident__1 } after @ident__2
@@ -1578,7 +1576,7 @@ name of the variable (here :g:`n`) is chosen based on :g:`T`.
This is equivalent to :n:`generalize @term; ... ; generalize @term`.
Note that the sequence of term :sub:`i` 's are processed from n to 1.
-.. tacv:: generalize @term at {+ @num}
+.. tacv:: generalize @term at {+ @natural}
This is equivalent to :n:`generalize @term` but it generalizes only over the
specified occurrences of :n:`@term` (counting from left to right on the
@@ -1589,7 +1587,7 @@ name of the variable (here :g:`n`) is chosen based on :g:`T`.
This is equivalent to :n:`generalize @term` but it uses :n:`@ident` to name
the generalized hypothesis.
-.. tacv:: generalize {+, @term at {+ @num} as @ident}
+.. tacv:: generalize {+, @term at {+ @natural} as @ident}
This is the most general form of :n:`generalize` that combines the previous
behaviors.
@@ -1621,16 +1619,16 @@ name of the variable (here :g:`n`) is chosen based on :g:`T`.
name the variable in the current goal and in the context of the
existential variable. This can lead to surprising behaviors.
-.. tacv:: instantiate (@num := @term)
+.. tacv:: instantiate (@natural := @term)
This variant allows to refer to an existential variable which was not named
- by the user. The :n:`@num` argument is the position of the existential variable
+ by the user. The :n:`@natural` argument is the position of the existential variable
from right to left in the goal. Because this variant is not robust to slight
changes in the goal, its use is strongly discouraged.
-.. tacv:: instantiate ( @num := @term ) in @ident
- instantiate ( @num := @term ) in ( value of @ident )
- instantiate ( @num := @term ) in ( type of @ident )
+.. tacv:: instantiate ( @natural := @term ) in @ident
+ instantiate ( @natural := @term ) in ( value of @ident )
+ instantiate ( @natural := @term ) in ( type of @ident )
These allow to refer respectively to existential variables occurring in a
hypothesis or in the body or the type of a local definition.
@@ -1730,13 +1728,13 @@ analysis on inductive or co-inductive objects (see :ref:`inductive-definitions`)
of :tacn:`destruct`, it is erased (to avoid erasure, use parentheses, as
in :n:`destruct (@ident)`).
- .. tacv:: destruct @num
+ .. tacv:: destruct @natural
- :n:`destruct @num` behaves as :n:`intros until @num`
+ :n:`destruct @natural` behaves as :n:`intros until @natural`
followed by destruct applied to the last introduced hypothesis.
.. note::
- For destruction of a numeral, use syntax :n:`destruct (@num)` (not
+ For destruction of a number, use syntax :n:`destruct (@natural)` (not
very interesting anyway).
.. tacv:: destruct @pattern
@@ -1829,10 +1827,10 @@ analysis on inductive or co-inductive objects (see :ref:`inductive-definitions`)
This tactic behaves as :n:`intros until @ident; case @ident` when :n:`@ident`
is a quantified variable of the goal.
-.. tacv:: simple destruct @num
+.. tacv:: simple destruct @natural
- This tactic behaves as :n:`intros until @num; case @ident` where :n:`@ident`
- is the name given by :n:`intros until @num` to the :n:`@num` -th
+ This tactic behaves as :n:`intros until @natural; case @ident` where :n:`@ident`
+ is the name given by :n:`intros until @natural` to the :n:`@natural` -th
non-dependent premise of the goal.
.. tacv:: case_eq @term
@@ -1863,12 +1861,12 @@ analysis on inductive or co-inductive objects (see :ref:`inductive-definitions`)
@ident; induction @ident`. If :n:`@ident` is not anymore dependent in the
goal after application of :n:`induction`, it is erased (to avoid erasure,
use parentheses, as in :n:`induction (@ident)`).
- + If :n:`@term` is a :n:`@num`, then :n:`induction @num` behaves as
- :n:`intros until @num` followed by :n:`induction` applied to the last
+ + If :n:`@term` is a :n:`@natural`, then :n:`induction @natural` behaves as
+ :n:`intros until @natural` followed by :n:`induction` applied to the last
introduced hypothesis.
.. note::
- For simple induction on a numeral, use syntax induction (num)
+ For simple induction on a number, use syntax induction (number)
(not very interesting anyway).
+ In case term is a hypothesis :n:`@ident` of the context, and :n:`@ident`
@@ -2026,10 +2024,10 @@ analysis on inductive or co-inductive objects (see :ref:`inductive-definitions`)
This tactic behaves as :n:`intros until @ident; elim @ident` when
:n:`@ident` is a quantified variable of the goal.
-.. tacv:: simple induction @num
+.. tacv:: simple induction @natural
- This tactic behaves as :n:`intros until @num; elim @ident` where :n:`@ident`
- is the name given by :n:`intros until @num` to the :n:`@num`-th non-dependent
+ This tactic behaves as :n:`intros until @natural; elim @ident` where :n:`@ident`
+ is the name given by :n:`intros until @natural` to the :n:`@natural`-th non-dependent
premise of the goal.
.. tacn:: double induction @ident @ident
@@ -2039,7 +2037,7 @@ analysis on inductive or co-inductive objects (see :ref:`inductive-definitions`)
:n:`induction @ident; induction @ident` (or
:n:`induction @ident ; destruct @ident` depending on the exact needs).
-.. tacv:: double induction @num__1 @num__2
+.. tacv:: double induction @natural__1 @natural__2
This tactic is deprecated and should be replaced by
:n:`induction num1; induction num3` where :n:`num3` is the result
@@ -2148,9 +2146,9 @@ and an explanation of the underlying technique.
.. exn:: Not a discriminable equality.
:undocumented:
-.. tacv:: discriminate @num
+.. tacv:: discriminate @natural
- This does the same thing as :n:`intros until @num` followed by
+ This does the same thing as :n:`intros until @natural` followed by
:n:`discriminate @ident` where :n:`@ident` is the identifier for the last
introduced hypothesis.
@@ -2159,12 +2157,12 @@ and an explanation of the underlying technique.
This does the same thing as :n:`discriminate @term` but using the given
bindings to instantiate parameters or hypotheses of :n:`@term`.
-.. tacv:: ediscriminate @num
+.. tacv:: ediscriminate @natural
ediscriminate @term {? with @bindings_list}
:name: ediscriminate; _
This works the same as :tacn:`discriminate` but if the type of :token:`term`, or the
- type of the hypothesis referred to by :token:`num`, has uninstantiated
+ type of the hypothesis referred to by :token:`natural`, has uninstantiated
parameters, these parameters are left as existential variables.
.. tacv:: discriminate
@@ -2227,9 +2225,6 @@ and an explanation of the underlying technique.
then :n:`injection @ident` first introduces the hypothesis in the local
context using :n:`intros until @ident`.
- .. exn:: Not a projectable equality but a discriminable one.
- :undocumented:
-
.. exn:: Nothing to do, it is an equality between convertible terms.
:undocumented:
@@ -2237,11 +2232,12 @@ and an explanation of the underlying technique.
:undocumented:
.. exn:: Nothing to inject.
- :undocumented:
- .. tacv:: injection @num
+ This error is given when one side of the equality is not a constructor.
- This does the same thing as :n:`intros until @num` followed by
+ .. tacv:: injection @natural
+
+ This does the same thing as :n:`intros until @natural` followed by
:n:`injection @ident` where :n:`@ident` is the identifier for the last
introduced hypothesis.
@@ -2250,12 +2246,12 @@ and an explanation of the underlying technique.
This does the same as :n:`injection @term` but using the given bindings to
instantiate parameters or hypotheses of :n:`@term`.
- .. tacv:: einjection @num
+ .. tacv:: einjection @natural
einjection @term {? with @bindings_list}
:name: einjection; _
This works the same as :n:`injection` but if the type of :n:`@term`, or the
- type of the hypothesis referred to by :n:`@num`, has uninstantiated
+ type of the hypothesis referred to by :n:`@natural`, has uninstantiated
parameters, these parameters are left as existential variables.
.. tacv:: injection
@@ -2267,10 +2263,10 @@ and an explanation of the underlying technique.
:undocumented:
.. tacv:: injection @term {? with @bindings_list} as {+ @simple_intropattern}
- injection @num as {+ @simple_intropattern}
+ injection @natural as {+ @simple_intropattern}
injection as {+ @simple_intropattern}
einjection @term {? with @bindings_list} as {+ @simple_intropattern}
- einjection @num as {+ @simple_intropattern}
+ einjection @natural as {+ @simple_intropattern}
einjection as {+ @simple_intropattern}
These variants apply :n:`intros {+ @simple_intropattern}` after the call to
@@ -2282,10 +2278,10 @@ and an explanation of the underlying technique.
corresponds to a hypothesis.
.. tacv:: injection @term {? with @bindings_list} as @injection_intropattern
- injection @num as @injection_intropattern
+ injection @natural as @injection_intropattern
injection as @injection_intropattern
einjection @term {? with @bindings_list} as @injection_intropattern
- einjection @num as @injection_intropattern
+ einjection @natural as @injection_intropattern
einjection as @injection_intropattern
These are equivalent to the previous variants but using instead the
@@ -2334,9 +2330,9 @@ and an explanation of the underlying technique.
:g:`Prop`). This behavior can be turned off by using the
:flag:`Keep Proof Equalities` setting.
-.. tacv:: inversion @num
+.. tacv:: inversion @natural
- This does the same thing as :n:`intros until @num` then :n:`inversion @ident`
+ This does the same thing as :n:`intros until @natural` then :n:`inversion @ident`
where :n:`@ident` is the identifier for the last introduced hypothesis.
.. tacv:: inversion_clear @ident
@@ -2379,9 +2375,9 @@ and an explanation of the underlying technique.
Goal forall l:list nat, contains0 (1 :: l) -> contains0 l.
intros l H; inversion H as [ | l' p Hl' [Heqp Heql'] ].
-.. tacv:: inversion @num as @or_and_intropattern_loc
+.. tacv:: inversion @natural as @or_and_intropattern_loc
- This allows naming the hypotheses introduced by :n:`inversion @num` in the
+ This allows naming the hypotheses introduced by :n:`inversion @natural` in the
context.
.. tacv:: inversion_clear @ident as @or_and_intropattern_loc
@@ -2629,7 +2625,7 @@ and an explanation of the underlying technique.
.. seealso:: :tacn:`functional inversion`
-.. tacn:: fix @ident @num
+.. tacn:: fix @ident @natural
:name: fix
This tactic is a primitive tactic to start a proof by induction. In
@@ -2637,11 +2633,11 @@ and an explanation of the underlying technique.
as the ones described in :tacn:`induction`.
In the syntax of the tactic, the identifier :n:`@ident` is the name given to
- the induction hypothesis. The natural number :n:`@num` tells on which
+ the induction hypothesis. The natural number :n:`@natural` tells on which
premise of the current goal the induction acts, starting from 1,
counting both dependent and non dependent products, but skipping local
definitions. Especially, the current lemma must be composed of at
- least :n:`@num` products.
+ least :n:`@natural` products.
Like in a fix expression, the induction hypotheses have to be used on
structurally smaller arguments. The verification that inductive proof
@@ -2650,7 +2646,7 @@ and an explanation of the underlying technique.
is correct at some time of the interactive development of a proof, use
the command ``Guarded`` (see Section :ref:`requestinginformation`).
-.. tacv:: fix @ident @num with {+ (@ident {+ @binder} [{struct @ident}] : @type)}
+.. tacv:: fix @ident @natural with {+ (@ident {+ @binder} [{struct @ident}] : @type)}
This starts a proof by mutual induction. The statements to be simultaneously
proved are respectively :g:`forall binder ... binder, type`.
@@ -2760,11 +2756,11 @@ simply :g:`t=u` dropping the implicit type of :g:`t` and :g:`u`.
+ `?` : the tactic :n:`rewrite ?@term` performs the rewrite of :token:`term` as many
times as possible (perhaps zero time). This form never fails.
- + :n:`@num?` : works similarly, except that it will do at most :token:`num` rewrites.
+ + :n:`@natural?` : works similarly, except that it will do at most :token:`natural` rewrites.
+ `!` : works as `?`, except that at least one rewrite should succeed, otherwise
the tactic fails.
- + :n:`@num!` (or simply :n:`@num`) : precisely :token:`num` rewrites of :token:`term` will be done,
- leading to failure if these :token:`num` rewrites are not possible.
+ + :n:`@natural!` (or simply :n:`@natural`) : precisely :token:`natural` rewrites of :token:`term` will be done,
+ leading to failure if these :token:`natural` rewrites are not possible.
.. tacv:: erewrite @term
:name: erewrite
@@ -2821,20 +2817,6 @@ simply :g:`t=u` dropping the implicit type of :g:`t` and :g:`u`.
only in the conclusion of the goal. The clause argument must not contain
any ``type of`` nor ``value of``.
- .. tacv:: cutrewrite <- (@term = @term’)
- :name: cutrewrite
-
- .. deprecated:: 8.5
-
- This tactic can be replaced by :n:`enough (@term = @term’) as <-`.
-
- .. tacv:: cutrewrite -> (@term = @term’)
-
- .. deprecated:: 8.5
-
- This tactic can be replaced by :n:`enough (@term = @term’) as ->`.
-
-
.. tacn:: subst @ident
:name: subst
@@ -2955,15 +2937,15 @@ simply :g:`t=u` dropping the implicit type of :g:`t` and :g:`u`.
This replaces the occurrences of :n:`@term` by :n:`@term’` in the current goal.
The term :n:`@term` and :n:`@term’` must be convertible.
- .. tacv:: change @term at {+ @num} with @term’
+ .. tacv:: change @term at {+ @natural} with @term’
- This replaces the occurrences numbered :n:`{+ @num}` of :n:`@term` by :n:`@term’`
+ This replaces the occurrences numbered :n:`{+ @natural}` of :n:`@term` by :n:`@term’`
in the current goal. The terms :n:`@term` and :n:`@term’` must be convertible.
.. exn:: Too few occurrences.
:undocumented:
- .. tacv:: change @term {? {? at {+ @num}} with @term} in @ident
+ .. tacv:: change @term {? {? at {+ @natural}} with @term} in @ident
This applies the :tacn:`change` tactic not to the goal but to the hypothesis :n:`@ident`.
@@ -2997,9 +2979,9 @@ Performing computations
| pattern {+, @pattern_occ }
| @ident
delta_flag ::= {? - } [ {+ @reference } ]
- strategy_flag ::= {+ @red_flags }
+ strategy_flag ::= {+ @red_flag }
| @delta_flag
- red_flags ::= beta
+ red_flag ::= beta
| iota
| match
| fix
@@ -3008,9 +2990,9 @@ Performing computations
| delta {? @delta_flag }
ref_or_pattern_occ ::= @reference {? at @occs_nums }
| @one_term {? at @occs_nums }
- occs_nums ::= {+ {| @num | @ident } }
- | - {| @num | @ident } {* @int_or_var }
- int_or_var ::= @int
+ occs_nums ::= {+ {| @natural | @ident } }
+ | - {| @natural | @ident } {* @int_or_var }
+ int_or_var ::= @integer
| @ident
unfold_occ ::= @reference {? at @occs_nums }
pattern_occ ::= @one_term {? at @occs_nums }
@@ -3246,9 +3228,9 @@ the conversion in hypotheses :n:`{+ @ident}`.
This applies :tacn:`simpl` only to the subterms matching
:n:`@pattern` in the current goal.
-.. tacv:: simpl @pattern at {+ @num}
+.. tacv:: simpl @pattern at {+ @natural}
- This applies :tacn:`simpl` only to the :n:`{+ @num}` occurrences of the subterms
+ This applies :tacn:`simpl` only to the :n:`{+ @natural}` occurrences of the subterms
matching :n:`@pattern` in the current goal.
.. exn:: Too few occurrences.
@@ -3261,10 +3243,10 @@ the conversion in hypotheses :n:`{+ @ident}`.
is the unfoldable constant :n:`@qualid` (the constant can be referred to by
its notation using :n:`@string` if such a notation exists).
-.. tacv:: simpl @qualid at {+ @num}
- simpl @string at {+ @num}
+.. tacv:: simpl @qualid at {+ @natural}
+ simpl @string at {+ @natural}
- This applies :tacn:`simpl` only to the :n:`{+ @num}` applicative subterms whose
+ This applies :tacn:`simpl` only to the :n:`{+ @natural}` applicative subterms whose
head occurrence is :n:`@qualid` (or :n:`@string`).
.. flag:: Debug RAKAM
@@ -3392,14 +3374,14 @@ the conversion in hypotheses :n:`{+ @ident}`.
:g:`(fun x:A =>` :math:`\varphi`:g:`(x)) t`. This tactic can be used, for
instance, when the tactic ``apply`` fails on matching.
-.. tacv:: pattern @term at {+ @num}
+.. tacv:: pattern @term at {+ @natural}
- Only the occurrences :n:`{+ @num}` of :n:`@term` are considered for
+ Only the occurrences :n:`{+ @natural}` of :n:`@term` are considered for
:math:`\beta`-expansion. Occurrences are located from left to right.
-.. tacv:: pattern @term at - {+ @num}
+.. tacv:: pattern @term at - {+ @natural}
- All occurrences except the occurrences of indexes :n:`{+ @num }`
+ All occurrences except the occurrences of indexes :n:`{+ @natural }`
of :n:`@term` are considered for :math:`\beta`-expansion. Occurrences are located from
left to right.
@@ -3412,12 +3394,12 @@ the conversion in hypotheses :n:`{+ @ident}`.
If :g:`t`:sub:`i` occurs in one of the generated types :g:`A`:sub:`j` these
occurrences will also be considered and possibly abstracted.
-.. tacv:: pattern {+, @term at {+ @num}}
+.. tacv:: pattern {+, @term at {+ @natural}}
- This behaves as above but processing only the occurrences :n:`{+ @num}` of
+ This behaves as above but processing only the occurrences :n:`{+ @natural}` of
:n:`@term` starting from :n:`@term`.
-.. tacv:: pattern {+, @term {? at {? -} {+, @num}}}
+.. tacv:: pattern {+, @term {? at {? -} {+, @natural}}}
This is the most general syntax that combines the different variants.
@@ -3574,9 +3556,9 @@ Automation
:tacn:`simple apply` so it is expected that sometimes :tacn:`auto` will
fail even if applying manually one of the hints would succeed.
- .. tacv:: auto @num
+ .. tacv:: auto @natural
- Forces the search depth to be :token:`num`. The maximal search depth
+ Forces the search depth to be :token:`natural`. The maximal search depth
is 5 by default.
.. tacv:: auto with {+ @ident}
@@ -3627,7 +3609,7 @@ Automation
Behaves like :tacn:`auto` but shows the tactics it tries to solve the goal,
including failing paths.
- .. tacv:: {? info_}auto {? @num} {? using {+ @qualid}} {? with {+ @ident}}
+ .. tacv:: {? info_}auto {? @natural} {? using {+ @qualid}} {? with {+ @ident}}
This is the most general form, combining the various options.
@@ -3682,7 +3664,7 @@ Automation
Note that ``ex_intro`` should be declared as a hint.
- .. tacv:: {? info_}eauto {? @num} {? using {+ @qualid}} {? with {+ @ident}}
+ .. tacv:: {? info_}eauto {? @natural} {? using {+ @qualid}} {? with {+ @ident}}
The various options for :tacn:`eauto` are the same as for :tacn:`auto`.
@@ -3845,12 +3827,12 @@ automatically created.
.. deprecated:: 8.10
- .. cmdv:: Hint Resolve @qualid {? | {? @num} {? @pattern}} : @ident
+ .. cmdv:: Hint Resolve @qualid {? | {? @natural} {? @pattern}} : @ident
:name: Hint Resolve
This command adds :n:`simple apply @qualid` to the hint list with the head
symbol of the type of :n:`@qualid`. The cost of that hint is the number of
- subgoals generated by :n:`simple apply @qualid` or :n:`@num` if specified. The
+ subgoals generated by :n:`simple apply @qualid` or :n:`@natural` if specified. The
associated :n:`@pattern` is inferred from the conclusion of the type of
:n:`@qualid` or the given :n:`@pattern` if specified. In case the inferred type
of :n:`@qualid` does not start with a product the tactic added in the hint list
@@ -3948,7 +3930,7 @@ automatically created.
overwriting the existing settings of opacity. It is advised
to use this just after a :cmd:`Create HintDb` command.
- .. cmdv:: Hint Extern @num {? @pattern} => @tactic : @ident
+ .. cmdv:: Hint Extern @natural {? @pattern} => @tactic : @ident
:name: Hint Extern
This hint type is to extend :tacn:`auto` with tactics other than :tacn:`apply` and
@@ -3991,15 +3973,15 @@ automatically created.
the following. Beware, there is no operator precedence during parsing, one can
check with :cmd:`Print HintDb` to verify the current cut expression:
- .. productionlist:: regexp
- regexp : `ident` (hint or instance identifier)
- : _ (any hint)
- : `regexp` | `regexp` (disjunction)
- : `regexp` `regexp` (sequence)
- : `regexp` * (Kleene star)
- : emp (empty)
- : eps (epsilon)
- : ( `regexp` )
+ .. prodn::
+ regexp ::= @ident (hint or instance identifier)
+ | _ (any hint)
+ | @regexp | @regexp (disjunction)
+ | @regexp @regexp (sequence)
+ | @regexp * (Kleene star)
+ | emp (empty)
+ | eps (epsilon)
+ | ( @regexp )
The `emp` regexp does not match any search path while `eps`
matches the empty path. During proof search, the path of
@@ -4377,7 +4359,7 @@ some incompatibilities.
This combines the effects of the different variants of :tacn:`firstorder`.
-.. opt:: Firstorder Depth @num
+.. opt:: Firstorder Depth @natural
:name: Firstorder Depth
This option controls the proof-search depth bound.
@@ -4414,10 +4396,10 @@ some incompatibilities.
congruence.
Qed.
-.. tacv:: congruence @num
+.. tacv:: congruence @natural
- Tries to add at most :token:`num` instances of hypotheses stating quantified equalities
- to the problem in order to solve it. A bigger value of :token:`num` does not make
+ Tries to add at most :token:`natural` instances of hypotheses stating quantified equalities
+ to the problem in order to solve it. A bigger value of :token:`natural` does not make
success slower, only failure. You might consider adding some lemmas as
hypotheses using assert in order for :tacn:`congruence` to use them.
@@ -4616,9 +4598,9 @@ symbol :g:`=`.
then :n:`simplify_eq @ident` first introduces the hypothesis in the local
context using :n:`intros until @ident`.
-.. tacv:: simplify_eq @num
+.. tacv:: simplify_eq @natural
- This does the same thing as :n:`intros until @num` then
+ This does the same thing as :n:`intros until @natural` then
:n:`simplify_eq @ident` where :n:`@ident` is the identifier for the last
introduced hypothesis.
@@ -4627,12 +4609,12 @@ symbol :g:`=`.
This does the same as :n:`simplify_eq @term` but using the given bindings to
instantiate parameters or hypotheses of :n:`@term`.
-.. tacv:: esimplify_eq @num
+.. tacv:: esimplify_eq @natural
esimplify_eq @term {? with @bindings_list}
:name: esimplify_eq; _
This works the same as :tacn:`simplify_eq` but if the type of :n:`@term`, or the
- type of the hypothesis referred to by :n:`@num`, has uninstantiated
+ type of the hypothesis referred to by :n:`@natural`, has uninstantiated
parameters, these parameters are left as existential variables.
.. tacv:: simplify_eq
@@ -4688,17 +4670,15 @@ Automating
tautologies. It solves goals of the form :g:`t = u` where `t` and `u` are
constructed over the following grammar:
- .. _btauto_grammar:
-
- .. productionlist:: sentence
- btauto_term : `ident`
- : true
- : false
- : orb `btauto_term` `btauto_term`
- : andb `btauto_term` `btauto_term`
- : xorb `btauto_term` `btauto_term`
- : negb `btauto_term`
- : if `btauto_term` then `btauto_term` else `btauto_term`
+ .. prodn::
+ btauto_term ::= @ident
+ | true
+ | false
+ | orb @btauto_term @btauto_term
+ | andb @btauto_term @btauto_term
+ | xorb @btauto_term @btauto_term
+ | negb @btauto_term
+ | if @btauto_term then @btauto_term else @btauto_term
Whenever the formula supplied is not a tautology, it also provides a
counter-example.
@@ -4757,12 +4737,16 @@ Non-logical tactics
------------------------
-.. tacn:: cycle @num
+.. tacn:: cycle @integer
:name: cycle
- This tactic puts the :n:`@num` first goals at the end of the list of goals.
- If :n:`@num` is negative, it will put the last :math:`|num|` goals at the
+ Reorders the selected goals so that the first :n:`@integer` goals appear after the
+ other selected goals.
+ If :n:`@integer` is negative, it puts the last :n:`@integer` goals at the
beginning of the list.
+ The tactic is only useful with a goal selector, most commonly `all:`.
+ Note that other selectors reorder goals; `1,3: cycle 1` is not equivalent
+ to `all: cycle 1`. See :tacn:`… : … (goal selector)`.
.. example::
@@ -4777,13 +4761,15 @@ Non-logical tactics
all: cycle 2.
all: cycle -3.
-.. tacn:: swap @num @num
+.. tacn:: swap @integer @integer
:name: swap
- This tactic switches the position of the goals of indices :n:`@num` and
- :n:`@num`. Negative values for:n:`@num` indicate counting goals
- backward from the end of the focused goal list. Goals are indexed from 1,
- there is no goal with position 0.
+ Exchanges the position of the specified goals.
+ Negative values for :n:`@integer` indicate counting goals
+ backward from the end of the list of selected goals. Goals are indexed from 1.
+ The tactic is only useful with a goal selector, most commonly `all:`.
+ Note that other selectors reorder goals; `1,3: swap 1 3` is not equivalent
+ to `all: swap 1 3`. See :tacn:`… : … (goal selector)`.
.. example::
@@ -4797,7 +4783,9 @@ Non-logical tactics
.. tacn:: revgoals
:name: revgoals
- This tactics reverses the list of the focused goals.
+ Reverses the order of the selected goals. The tactic is only useful with a goal
+ selector, most commonly `all :`. Note that other selectors reorder goals;
+ `1,3: revgoals` is not equivalent to `all: revgoals`. See :tacn:`… : … (goal selector)`.
.. example::
@@ -4925,10 +4913,10 @@ Performance-oriented tactic variants
.. tacv:: change_no_check @term with @term’
:undocumented:
- .. tacv:: change_no_check @term at {+ @num} with @term’
+ .. tacv:: change_no_check @term at {+ @natural} with @term’
:undocumented:
- .. tacv:: change_no_check @term {? {? at {+ @num}} with @term} in @ident
+ .. tacv:: change_no_check @term {? {? at {+ @natural}} with @term} in @ident
.. example::
diff --git a/doc/sphinx/proof-engine/vernacular-commands.rst b/doc/sphinx/proof-engine/vernacular-commands.rst
index ad0aab19b5..6c07253bce 100644
--- a/doc/sphinx/proof-engine/vernacular-commands.rst
+++ b/doc/sphinx/proof-engine/vernacular-commands.rst
@@ -32,7 +32,7 @@ Displaying
.. exn:: @qualid not a defined object.
:undocumented:
- .. exn:: Universe instance should have length @num.
+ .. exn:: Universe instance should have length @natural.
:undocumented:
.. exn:: This object does not support universe names.
@@ -44,9 +44,9 @@ Displaying
This command displays information about the current state of the
environment, including sections and modules.
-.. cmd:: Inspect @num
+.. cmd:: Inspect @natural
- This command displays the :n:`@num` last objects of the
+ This command displays the :n:`@natural` last objects of the
current environment, including sections and modules.
.. cmd:: Print Section @qualid
@@ -60,7 +60,7 @@ Query commands
--------------
Unlike other commands, :production:`query_command`\s may be prefixed with
-a goal selector (:n:`@num:`) to specify which goal context it applies to.
+a goal selector (:n:`@natural:`) to specify which goal context it applies to.
If no selector is provided,
the command applies to the current goal. If no proof is open, then the command only applies
to accessible objects. (see Section :ref:`invocation-of-tactics`).
@@ -757,10 +757,10 @@ interactively, they cannot be part of a vernacular file loaded via
of the interactive session.
-.. cmd:: Back {? @num }
+.. cmd:: Back {? @natural }
- Undoes all the effects of the last :n:`@num @sentence`\s. If
- :n:`@num` is not specified, the command undoes one sentence.
+ Undoes all the effects of the last :n:`@natural @sentence`\s. If
+ :n:`@natural` is not specified, the command undoes one sentence.
Sentences read from a `.v` file via a :cmd:`Load` are considered a
single sentence. While :cmd:`Back` can undo tactics and commands executed
within proof mode, once you exit proof mode, such as with :cmd:`Qed`, all
@@ -772,14 +772,14 @@ interactively, they cannot be part of a vernacular file loaded via
The user wants to undo more commands than available in the history.
-.. cmd:: BackTo @num
+.. cmd:: BackTo @natural
- This command brings back the system to the state labeled :n:`@num`,
+ This command brings back the system to the state labeled :n:`@natural`,
forgetting the effect of all commands executed after this state. The
state label is an integer which grows after each successful command.
It is displayed in the prompt when in -emacs mode. Just as :cmd:`Back` (see
above), the :cmd:`BackTo` command now handles proof states. For that, it may
- have to undo some extra commands and end on a state :n:`@num′ ≤ @num` if
+ have to undo some extra commands and end on a state :n:`@natural′ ≤ @natural` if
necessary.
.. _quitting-and-debugging:
@@ -834,16 +834,16 @@ Quitting and debugging
output to the file ":n:`@string`.out".
-.. cmd:: Timeout @num @sentence
+.. cmd:: Timeout @natural @sentence
Executes :n:`@sentence`. If the operation
- has not terminated after :n:`@num` seconds, then it is interrupted and an error message is
+ has not terminated after :n:`@natural` seconds, then it is interrupted and an error message is
displayed.
- .. opt:: Default Timeout @num
+ .. opt:: Default Timeout @natural
:name: Default Timeout
- If set, each :n:`@sentence` is treated as if it was prefixed with :cmd:`Timeout` :n:`@num`,
+ If set, each :n:`@sentence` is treated as if it was prefixed with :cmd:`Timeout` :n:`@natural`,
except for :cmd:`Timeout` commands themselves. If unset,
no timeout is applied.
@@ -890,14 +890,14 @@ Controlling display
interpreted from left to right, so in case of an overlap, the flags on the
right have higher priority, meaning that `A,-A` is equivalent to `-A`.
-.. opt:: Printing Width @num
+.. opt:: Printing Width @natural
:name: Printing Width
This command sets which left-aligned part of the width of the screen is used
for display. At the time of writing this documentation, the default value
is 78.
-.. opt:: Printing Depth @num
+.. opt:: Printing Depth @natural
:name: Printing Depth
This option controls the nesting depth of the formatter used for pretty-
@@ -1028,7 +1028,7 @@ described first.
.. prodn::
strategy_level ::= opaque
- | @int
+ | @integer
| expand
| transparent
strategy_level_or_var ::= @strategy_level
@@ -1052,7 +1052,7 @@ described first.
+ ``opaque`` : level of opaque constants. They cannot be expanded by
tactics (behaves like +∞, see next item).
- + :n:`@int` : levels indexed by an integer. Level 0 corresponds to the
+ + :n:`@integer` : levels indexed by an integer. Level 0 corresponds to the
default behavior, which corresponds to transparent constants. This
level can also be referred to as ``transparent``. Negative levels
correspond to constants to be expanded before normal transparent
@@ -1265,9 +1265,9 @@ Inlining hints for the fast reduction machines
Registering primitive operations
````````````````````````````````
-.. cmd:: Primitive @ident {? : @term } := #@ident__prim
+.. cmd:: Primitive @ident_decl {? : @term } := #@ident
- Makes the primitive type or primitive operator :n:`#@ident__prim` defined in OCaml
+ Makes the primitive type or primitive operator :n:`#@ident` defined in OCaml
accessible in |Coq| commands and tactics.
For internal use by implementors of |Coq|'s standard library or standard library
replacements. No space is allowed after the `#`. Invalid values give a syntax