Previous Up Next

Chapter 6  Vernacular commands

6.1  Displaying

6.1.1  Print qualid.

This command displays on the screen informations about the declared or defined object referred by qualid.


Error messages:

  1. qualid not a defined object


Variants:

  1. Print Term qualid.
    This is a synonym to Print qualid when qualid denotes a global constant.
  2. About qualid.
    This displays various informations about the object denoted by qualid: its kind (module, constant, assumption, inductive, constructor, abbreviation…), long name, type, implicit arguments and argument scopes.

6.1.2  Print All.

This command displays informations about the current state of the environment, including sections and modules.


Variants:

  1. Inspect num.
    This command displays the num last objects of the current environment, including sections and modules.
  2. Print Section ident.
    should correspond to a currently open section, this command displays the objects defined since the beginning of this section.

6.2  Requests to the environment

6.2.1  Check term.

This command displays the type of term. When called in proof mode, the term is checked in the local context of the current subgoal.

6.2.2  Eval convtactic in term.

This command performs the specified reduction on term, and displays the resulting term with its type. The term to be reduced may depend on hypothesis introduced in the first subgoal (if a proof is in progress).


See also: Section 8.5.

6.2.3  Extraction term.

This command displays the extracted term from term. The extraction is processed according to the distinction between Set and Prop; that is to say, between logical and computational content (see Section 4.1.1). The extracted term is displayed in Objective Caml syntax, where global identifiers are still displayed as in Coq terms.


Variants:

  1. Recursive Extraction qualid1qualidn.
    Recursively extracts all the material needed for the extraction of globals qualid1qualidn.


See also: Chapter 18.

6.2.4  Opaque qualid1qualidn.

This command tells not to unfold the the constants qualid1qualidn in tactics using δ-conversion. Unfolding a constant is replacing it by its definition. Opaque can only apply on constants originally defined as Transparent.

Constants defined by a proof ended by Qed are automatically stamped as Opaque and can no longer be considered as Transparent. This is to keep with the usual mathematical practice of proof irrelevance: what matters in a mathematical development is the sequence of lemma statements, not their actual proofs. This distinguishes lemmas from the usual defined constants, whose actual values are of course relevant in general.


See also: sections 8.5, 8.12, 7.1.4


Error messages:

  1. The reference qualid was not found in the current environment
    There is no constant referred by qualid in the environment. Nevertheless, if you asked Opaque foo bar and if bar does not exist, foo is set opaque.

6.2.5  Transparent qualid1qualidn.

This command is the converse of Opaque and can only apply on constants originally defined as Transparent to restore their initial behaviour after an Opaque command.

The constants automatically declared transparent are the ones defined by a proof ended by Defined, or by a Definition or Local with an explicit body.


Warning: Transparent and Opaque are not synchronous with the reset mechanism. If a constant was transparent at point A, if you set it opaque at point B and reset to point A, you return to state of point A with the difference that the constant is still opaque. This can cause changes in tactic scripts behaviour.

At section or module closing, a constant recovers the status it got at the time of its definition.


Error messages:

  1. The reference qualid was not found in the current environment
    There is no constant referred by qualid in the environment.


See also: sections 8.5, 8.12, 7.1.4

6.2.6  Search qualid.

This command displays the name and type of all theorems of the current context whose statement’s conclusion has the form (qualid t1 .. tn). This command is useful to remind the user of the name of library lemmas.
Error messages:

  1. The reference qualid was not found in the current environment
    There is no constant in the environment named qualid.


Variants:

  1. Search qualid inside module1modulen.

    This restricts the search to constructions defined in modules module1modulen.

  2. Search qualid outside module1modulen.

    This restricts the search to constructions not defined in modules module1modulen.


    Error messages:

    1. Module/section module not found No module module has been required (see Section 6.4.1).

6.2.7  SearchAbout qualid.

This command displays the name and type of all objects (theorems, axioms, etc) of the current context whose statement contains qualid. This command is useful to remind the user of the name of library lemmas.


Error messages:

  1. The reference qualid was not found in the current environment
    There is no constant in the environment named qualid.


Variants:

  1. SearchAbout [ qualid-or-string qualid-or-string ].
    where qualid-or-string is a qualid or a string.

    This extension of SearchAbout searches for all objects whose statement mentions all of qualid of the list and whose name contains all string of the list.


    Example:

    Coq < Require Import ZArith.

    Coq < SearchAbout [ Zmult Zplus "distr" ].
    weak_Zmult_plus_distr_r:
      forall (p : positive) (n m : Z),
      (Zpos p * (n + m))%Z = (Zpos p * n + Zpos p * m)%Z
    Zmult_plus_distr_r:
      forall n m p : Z, (n * (m + p))%Z = (n * m + n * p)%Z
    Zmult_plus_distr_l:
      forall n m p : Z, ((n + m) * p)%Z = (n * p + m * p)%Z
    OmegaLemmas.fast_Zmult_plus_distr_l:
      forall (n m p : Z) (P : Z -> Prop),
      P (n * p + m * p)%Z -> P ((n + m) * p)%Z
  2. SearchAbout term inside module1modulen.
    SearchAbout [ qualid-or-string qualid-or-string ] inside module1modulen.

    This restricts the search to constructions defined in modules module1modulen.

  3. SearchAbout term outside module1...modulen.
    SearchAbout [ qualid-or-string qualid-or-string ] outside module1...modulen.

    This restricts the search to constructions not defined in modules module1modulen.

6.2.8  SearchPattern term.

This command displays the name and type of all theorems of the current context whose statement’s conclusion matches the expression term where holes in the latter are denoted by “_”.

Coq < Require Import Arith.

Coq < SearchPattern (_ + _ = _ + _).
plus_comm: forall n m : nat, n + m = m + n
plus_Snm_nSm: forall n m : nat, S n + m = n + S m
plus_assoc: forall n m p : nat, n + (m + p) = n + m + p
plus_permute: forall n m p : nat, n + (m + p) = m + (n + p)
plus_assoc_reverse: forall n m p : nat, n + m + p = n + (m + p)
plus_permute_2_in_4:
  forall n m p q : nat, n + m + (p + q) = n + p + (m + q)

Patterns need not be linear: you can express that the same expression must occur in two places by using pattern variables ‘?ident”.

Coq < Require Import Arith.

Coq < SearchPattern (?X1 + _ = _ + ?X1).
plus_comm: forall n m : nat, n + m = m + n


Variants:

  1. SearchPattern term inside module1modulen.

    This restricts the search to constructions defined in modules module1modulen.

  2. SearchPattern term outside module1modulen.

    This restricts the search to constructions not defined in modules module1modulen.

6.2.9  SearchRewrite term.

This command displays the name and type of all theorems of the current context whose statement’s conclusion is an equality of which one side matches the expression term=. Holes in term are denoted by “_”.

Coq < Require Import Arith.

Coq < SearchRewrite (_ + _ + _).
plus_assoc: forall n m p : nat, n + (m + p) = n + m + p
plus_assoc_reverse: forall n m p : nat, n + m + p = n + (m + p)
plus_permute_2_in_4:
  forall n m p q : nat, n + m + (p + q) = n + p + (m + q)


Variants:

  1. SearchRewrite term inside module1modulen.

    This restricts the search to constructions defined in modules module1modulen.

  2. SearchRewrite term outside module1modulen.

    This restricts the search to constructions not defined in modules module1modulen.

6.2.10  Locate qualid.

This command displays the full name of the qualified identifier qualid and consequently the Coq module in which it is defined.

Coq < Locate nat.
Inductive Coq.Init.Datatypes.nat

Coq < Locate Datatypes.O.
Constructor Coq.Init.Datatypes.O
  (shorter name to refer to it in current context is O)

Coq < Locate Init.Datatypes.O.
Constructor Coq.Init.Datatypes.O
  (shorter name to refer to it in current context is O)

Coq < Locate Coq.Init.Datatypes.O.
Constructor Coq.Init.Datatypes.O
  (shorter name to refer to it in current context is O)

Coq < Locate I.Dont.Exist.
No object of suffix I.Dont.Exist


See also: Section 11.1.10

6.2.11  The Whelp searching tool

Whelp is an experimental searching and browsing tool for the whole Coq library and the whole set of Coq user contributions. Whelp requires a browser to work. Whelp has been developed at the University of Bologna as part of the HELM1 and MoWGLI2 projects. It can be invoked directly from the Coq toplevel or from CoqIDE, assuming a graphical environment is also running. The browser to use can be selected by setting the environment variable COQREMOTEBROWSER. If not explicitly set, it defaults to firefox -remote "OpenURL(%s)" or C:\\PROGRA~1\\INTERN~1\\IEXPLORE %s, depending on the underlying operating system (in the command, the string %s serves as metavariable for the url to open). The Whelp tool relies on a dedicated Whelp server and on another server called Getter that retrieves formal documents. The default Whelp server name can be obtained using the command Test Whelp Server and the default Getter can be obtained using the command: Test Whelp Getter . The Whelp server name can be changed using the command:


Set Whelp Server string.
where string is a URL (e.g. http://mowgli.cs.unibo.it:58080).

The Getter can be changed using the command:

Set Whelp Getter string.
where string is a URL (e.g. http://mowgli.cs.unibo.it:58081).



The Whelp commands are:

Whelp Locate "reg_expr".

This command opens a browser window and displays the result of seeking for all names that match the regular expression reg_expr in the Coq library and user contributions. The regular expression can contain the special operators are * and ? that respectively stand for an arbitrary substring and for exactly one character.


Variant: Whelp Locate ident.
This is equivalent to Whelp Locate "ident".

Whelp Match pattern.

This command opens a browser window and displays the result of seeking for all statements that match the pattern pattern. Holes in the pattern are represented by the wildcard character “_”.

Whelp Instance pattern.

This command opens a browser window and displays the result of seeking for all statements that are instances of the pattern pattern. The pattern is here assumed to be an universally quantified expression.

Whelp Elim qualid.

This command opens a browser window and displays the result of seeking for all statements that have the “form” of an elimination scheme over the type denoted by qualid.

Whelp Hint term.

This command opens a browser window and displays the result of seeking for all statements that can be instantiated so that to prove the statement term.


Variant: Whelp Hint.
This is equivalent to Whelp Hint goal where goal is the current goal to prove. Notice that Coq does not send the local environment of definitions to the Whelp tool so that it only works on requests strictly based on, only, definitions of the standard library and user contributions.

6.3  Loading files

Coq offers the possibility of loading different parts of a whole development stored in separate files. Their contents will be loaded as if they were entered from the keyboard. This means that the loaded files are ASCII files containing sequences of commands for Coq’s toplevel. This kind of file is called a script for Coq. The standard (and default) extension of Coq’s script files is .v.

6.3.1  Load ident.

This command loads the file named ident.v, searching successively in each of the directories specified in the loadpath. (see Section 6.5)


Variants:

  1. Load string.
    Loads the file denoted by the string string, where string is any complete filename. Then the ~ and .. abbreviations are allowed as well as shell variables. If no extension is specified, Coq will use the default extension .v
  2. Load Verbose ident., Load Verbose string
    Display, while loading, the answers of Coq to each command (including tactics) contained in the loaded file
    See also: Section 6.8.1


Error messages:

  1. Can’t find file ident on loadpath

6.4  Compiled files

This feature allows to build files for a quick loading. When loaded, the commands contained in a compiled file will not be replayed. In particular, proofs will not be replayed. This avoids a useless waste of time.


Remark: A module containing an opened section cannot be compiled.

6.4.1  Require dirpath.

This command looks in the loadpath for a file containing module dirpath, then loads and opens (imports) its contents. More precisely, if dirpath splits into a library dirpath dirpath’ and a module name ident, then the file ident.vo is searched in a physical path mapped to the logical path dirpath’.

TODO: effect on the name table.

If the module required has already been loaded, Coq simply opens it (as Import dirpath would do it).

If a module A contains a command Require B then the command Require A loads the module B but does not open it (See the Require Export variant below).


Variants:

  1. Require Export qualid.
    This command acts as Require qualid. But if a module A contains a command Require Export B, then the command Require A opens the module B as if the user would have typed RequireB.
  2. Require qualid string.
    Specifies the file to load as being string but containing module qualid which is then opened.

These different variants can be combined.


Error messages:

  1. Cannot load ident: no physical path bound to dirpath
  2. Can’t find module toto on loadpath

    The command did not find the file toto.vo. Either toto.v exists but is not compiled or toto.vo is in a directory which is not in your LoadPath (see Section 6.5).

  3. Bad magic number

    The file ident.vo was found but either it is not a Coq compiled module, or it was compiled with an older and incompatible version of Coq.


See also: Chapter 12

6.4.2  Print Modules.

This command shows the currently loaded and currently opened (imported) modules.

6.4.3  Declare ML Module string1 .. stringn.

This commands loads the Objective Caml compiled files string1stringn (dynamic link). It is mainly used to load tactics dynamically. The files are searched into the current Objective Caml loadpath (see the command Add ML Path in the Section 6.5). Loading of Objective Caml files is only possible under the bytecode version of coqtop (i.e. coqtop called with options -byte, see chapter 12).


Error messages:

  1. File not found on loadpath : string
  2. Loading of ML object file forbidden in a native Coq

6.4.4  Print ML Modules.

This print the name of all Objective Caml modules loaded with Declare ML Module. To know from where these module were loaded, the user should use the command Locate File (see Section 6.5.10)

6.5  Loadpath

There are currently two loadpaths in Coq. A loadpath where seeking Coq files (extensions .v or .vo or .vi) and one where seeking Objective Caml files. The default loadpath contains the directory “.” denoting the current directory and mapped to the empty logical path (see Section 2.6.2).

6.5.1  Pwd.

This command displays the current working directory.

6.5.2  Cd string.

This command changes the current directory according to string which can be any valid path.


Variants:

  1. Cd.
    Is equivalent to Pwd.

6.5.3  Add LoadPath string as dirpath.

This command adds the path string to the current Coq loadpath and maps it to the logical directory dirpath, which means that every file M.v physically lying in directory string becomes accessible through logical name “dirpath.M”.


Remark: Add LoadPath also adds string to the current ML loadpath.


Variants:

  1. Add LoadPath string.
    Performs as Add LoadPath string as dirpath but for the empty directory path.

6.5.4  Add Rec LoadPath string as dirpath.

This command adds the directory string and all its subdirectories to the current Coq loadpath. The top directory string is mapped to the logical directory dirpath while any subdirectory pdir is mapped to logical directory dirpath.pdir and so on.


Remark: Add Rec LoadPath also recursively adds string to the current ML loadpath.


Variants:

  1. Add Rec LoadPath string.
    Works as Add Rec LoadPath string as dirpath but for the empty logical directory path.

6.5.5  Remove LoadPath string.

This command removes the path string from the current Coq loadpath.

6.5.6  Print LoadPath.

This command displays the current Coq loadpath.

6.5.7  Add ML Path string.

This command adds the path string to the current Objective Caml loadpath (see the command Declare ML Module in the Section 6.4).


Remark: This command is implied by Add LoadPath string as dirpath.

6.5.8  Add Rec ML Path string.

This command adds the directory string and all its subdirectories to the current Objective Caml loadpath (see the command Declare ML Module in the Section 6.4).


Remark: This command is implied by Add Rec LoadPath string as dirpath.

6.5.9  Print ML Path string.

This command displays the current Objective Caml loadpath. This command makes sense only under the bytecode version of coqtop, i.e. using option -byte (see the command Declare ML Module in the section 6.4).

6.5.10  Locate File string.

This command displays the location of file string in the current loadpath. Typically, string is a .cmo or .vo or .v file.

6.5.11  Locate Library dirpath.

This command gives the status of the Coq module dirpath. It tells if the module is loaded and if not searches in the load path for a module of logical name dirpath.

6.6  States and Reset

6.6.1  Reset ident.

This command removes all the objects in the environment since ident was introduced, including ident. ident may be the name of a defined or declared object as well as the name of a section. One cannot reset over the name of a module or of an object inside a module.


Error messages:

  1. ident: no such entry

6.6.2  Back.

This commands undoes all the effects of the last vernacular command. This does not include commands that only access to the environment like those described in the previous sections of this chapter (for instance Require and Load can be undone, but not Check and Locate). Commands read from a vernacular file are considered as a single command.


Variants:

  1. Back n
    Undoes n vernacular commands.


Error messages:

  1. Reached begin of command history
    Happens when there is vernacular command to undo.

6.6.3  Backtrack num1 num2 num3.

This command is dedicated for the use in graphical interfaces. It allows to backtrack to a particular global state, i.e. typically a state corresponding to a previous line in a script. A global state includes declaration environment but also proof environment (see Chapter 7). The three numbers num1, num2 and num3 represent the following:

How to get state numbers?

Notice that when in -emacs mode, Coq displays the current proof and environment state numbers in the prompt. More precisely the prompt in -emacs mode is the following:

<prompt> idi < num1 | id1|id2||idn | num2 < </prompt>

Where:

It is then possible to compute the Backtrack command to unbury the state corresponding to a particular prompt. For example, suppose the current prompt is:

< goal4 < 35 |goal1|goal4|goal3|goal2| |8 < </prompt>

and we want to backtrack to a state labelled by:

< goal2 < 32 |goal1|goal2 |12 < </prompt>

We have to perform Backtrack 32 12 2 , i.e. perform 2 Aborts (to cancel goal4 and goal3), then rewind proof until state 12 and finally go back to environment state 32. Notice that this supposes that proofs are nested in a regular way (no Resume or Suspend commands).


Variants:

  1. BackTo n.
    Is a more basic form of Backtrack where only the first argument (global environment number) is given, no abort and no Undo is performed.

6.6.4  Restore State string.

Restores the state contained in the file string.


Variants:

  1. Restore State ident
    Equivalent to Restore State "ident.coq".
  2. Reset Initial.
    Goes back to the initial state (like after the command coqtop, when the interactive session began). This command is only available interactively.

6.6.5  Write State string.

Writes the current state into a file string for use in a further session. This file can be given as the inputstate argument of the commands coqtop and coqc.


Variants:

  1. Write State ident
    Equivalent to Write State "ident.coq". The state is saved in the current directory (see Section 6.5.1).

6.7  Quitting and debugging

6.7.1  Quit.

This command permits to quit Coq.

6.7.2  Drop.

This is used mostly as a debug facility by Coq’s implementors and does not concern the casual user. This command permits to leave Coq temporarily and enter the Objective Caml toplevel. The Objective Caml command:

#use "include";;

add the right loadpaths and loads some toplevel printers for all abstract types of Coq- section_path, identfifiers, terms, judgements, …. You can also use the file base_include instead, that loads only the pretty-printers for section_paths and identifiers. You can return back to Coq with the command:

go();;


Warnings:

  1. It only works with the bytecode version of Coq (i.e. coqtop called with option -byte, see the contents of Section 12.1).
  2. You must have compiled Coq from the source package and set the environment variable COQTOP to the root of your copy of the sources (see Section 12.4).

6.7.3  Time command.

This command executes the vernac command command and display the time needed to execute it.

6.8  Controlling display

6.8.1  Set Silent.

This command turns off the normal displaying.

6.8.2  Unset Silent.

This command turns the normal display on.

6.8.3  Set Printing Width integer.

This command sets which left-aligned part of the width of the screen is used for display.

6.8.4  Unset Printing Width.

This command resets the width of the screen used for display to its default value (which is 78 at the time of writing this documentation).

6.8.5  Test Printing Width.

This command displays the current screen width used for display.

6.8.6  Set Printing Depth integer.

This command sets the nesting depth of the formatter used for pretty-printing. Beyond this depth, display of subterms is replaced by dots.

6.8.7  Unset Printing Depth.

This command resets the nesting depth of the formatter used for pretty-printing to its default value (at the time of writing this documentation, the default value is 50).

6.8.8  Test Printing Depth.

This command displays the current nesting depth used for display.

6.9  Controlling the conversion algorithm

Coq comes with two algorithms to check the convertibility of types (see Section 4.3). The first algorithm lazily compares applicative terms while the other is a brute-force but efficient algorithm that first normalizes the terms before comparing them. The second algorithm is based on a bytecode representation of terms similar to the bytecode representation used in the ZINC virtual machine [85]. It is specially useful for intensive computation of algebraic values, such as numbers, and for reflexion-based tactics.

6.9.1  Set Virtual Machine

This activates the bytecode-based conversion algorithm.

6.9.2  Unset Virtual Machine

This deactivates the bytecode-based conversion algorithm.

6.9.3  Test Virtual Machine

This tells if the bytecode-based conversion algorithm is activated. The default behavior is to have the bytecode-based conversion algorithm deactivated.


See also: sections 8.5.1 and 12.5.


1
Hypertextual Electronic Library of Mathematics
2
Mathematics on the Web, Get it by Logics and Interfaces

Previous Up Next