The interactive theorem prover known as Coq for over 35 years took the name The Rocq Prover (or simply Rocq) starting with version 9.0. Older books and papers referring to Coq describe the exact same tool. This series targets Rocq 9, and its source files use the .v extension.1
1. Installation and the Three Languages Inside a .v File
Choose your operating system on the official Rocq installation guide to install Rocq and its standard library. If you are new to Rocq, following the Rocq Platform instructions is the easiest route. Once installed, open a fresh terminal and verify the version.
Rocq Platform packages Rocq with commonly used libraries and tools. Once setup is complete, type rocq -v in a terminal, the window where you enter commands and see their results. This command checks which version you installed.
rocq -vTo follow along in VS Code, install the official VsRocq extension and connect the language server as shown in the editor setup section of the same installation guide. Opening a .v file will display command outputs and proof goals in the side panel.
The language server checks Rocq commands behind the scenes and sends their results to the editor. VsRocq puts those results in the VS Code panel. The terminal prints output from the whole file; in the editor you can look at one command or see which part of a proof is left.
Opening a Rocq file for the first time can feel unfamiliar for one specific reason: three distinct sub-languages are layered together inside a single file.
Gallina: the purely functional specification language used to define types, functions, and mathematical propositions (
nat,fun x => x + 1,forall n, n + 0 = n).Vernacular: top-level commands that tell the system what to do next, such as ‘tell me the type of this expression’ or ‘begin a theorem declaration’ (
Check,Compute,Definition,Theorem).Ltac: the tactic language used between
Proof.andQed.to break down proof goals step by step (intros,simpl,reflexivity).
Every command in our exercises ends with a period (.). Each tactic step written inside a proof ends with a period in the same way.
The tactic language introduced here is Ltac1, often called Ltac. Rocq also has Ltac2, which type-checks tactic code before it runs. This series starts with the Ltac1 syntax.
2. Asking for Values and Types with Compute and Check
Create an empty Scratch.v file and enter the commands below. Check expr. shows the type of an expression so you can check whether a term is a natural number or a boolean, while Compute expr. evaluates the expression and prints both the resulting value and its type side by side, which is handy whenever you want to verify that a subtraction or function call produces the value you expect. Unlike Definition, which binds a new name, both are query commands.2
A single expression answers two distinct questions: its type and its computed value. In mathematical notation, a colon (:) denotes the type of the expression on its left, and the downward arrow points to the value obtained by evaluating that expression to the end.
When you are unsure of the type of an expression you want to pass to a list or function, reach for Check; when you want to see whether it evaluates to an expected number like 7, reach for Compute. Because Rocq’s Compute prints the type right next to the evaluated value, it answers the first question at the same time.3
Open an empty practice folder in VS Code and save the code below as Scratch.v. The expression 1 + 2 * 3 is Gallina; the Compute before it is the Vernacular command that tells Rocq what to do with it.
Check 42.
Check true.
Compute 1 + 2 * 3.
Compute 10 - 3.
Compute 2 - 5.Open a terminal in the folder containing the practice file. The compile step below reads and checks it from the start and saves a compiled module for later imports.
Running rocq compile Scratch.v in a terminal prints a response for each command. The terminal puts the value and its type on separate lines; below, they share a line so you can match each response to its command. In VsRocq, place the cursor after the period of the command you want to inspect.
A successful compile also writes Scratch.vo and Scratch.glob next to the source file. Rocq loads definitions from the .vo file when another file imports the module; the documentation tool uses the .glob file to link names to their definitions. Rocq 9.2 also leaves a hidden .Scratch.aux file.
Output:
42 : nat
true : bool
= 7 : nat
= 7 : nat
= 0 : natCompare the output format of the first two lines against the last three lines. The first two lines come from Check, so they perform no computation and simply report ‘term : type’ as 42 : nat (natural number) and true : bool (boolean). The last three lines come from Compute, so they start with an equals sign (=) in the format = value : type.
Both 1 + 2 * 3 and 10 - 3 evaluate to = 7 : nat, and the fifth line is the key: why did 2 - 5 evaluate to = 0 : nat instead of -3? Because Rocq’s default number literals are natural numbers (nat) starting at 0, subtraction uses truncated subtraction, clamping any result that would drop below 0 back to 0 so the result never leaves the set of natural numbers.
To compare the two commands on the same expression, try putting Check (1 + 2 * 3). temporarily before Compute 1 + 2 * 3. in the editor. Check reports 1 + 2 * 3 : nat. The original Compute line gives you the value as well.
3. Naming Values with Definition and Calculating with %Z
Start with From Stdlib Require Import ZArith. to load the integer module from Rocq’s standard library. The suffix %Z selects the integer notation scope for one expression. In (2 - 5)%Z, Rocq reads the numerals and the minus sign as integer arithmetic inside the parentheses. The next command keeps its own notation context.
A notation scope is a set of rules for reading symbols such as + and -. Z is the type of integers, including negatives; Z_scope is the name of the scope that reads those symbols as integer operations.
For several lines of integer arithmetic, use Open Scope Z_scope. to keep that notation active. Inside that scope, Compute 2 - 5. returns -3 without %Z. Below, each integer expression keeps its %Z suffix instead.
Definition name : Type := expr. gives a value a name so you can use it again. Append the example to Scratch.v and run the file again. You’ll see the earlier results too; the output below captures only what the added commands print.4
Even when written identically as 2 - 5, the operation changes depending on which numeric scope interprets it. In the formula below, the subscript denotes truncated subtraction on natural numbers (nat, ), while the subscript denotes ordinary subtraction on signed integers (Z, ).
Under truncated subtraction on nat, (2 - 5) + 5 evaluates to 5 rather than recovering 2. A count such as an inventory total can stop at zero, while a signed change needs to keep its minus sign. For the integer subtraction below, the notation delimiter is %Z.56
From Stdlib Require Import ZArith.
Definition max_retry : nat := 3.
Definition temp_delta : Z := (-4)%Z.
Compute (2 - 5)%Z.
Compute (temp_delta + 10)%Z.
Check max_retry.
Print max_retry.Output:
= (-3)%Z : Z
= 6%Z : Z
max_retry : nat
max_retry = 3 : natEach of the four output lines answers a different query. The first line, = (-3)%Z : Z, evaluates (2 - 5)%Z over the integers, and the second line, = 6%Z : Z, adds 10 to the -4 stored in temp_delta. Rocq prints %Z after the resulting numeral as well to distinguish the integer 6%Z from the default natural number 6.
Third, Check max_retry. reports only the name’s type as max_retry : nat, whereas on the fourth line Print max_retry. unfolds the definition’s body to show max_retry = 3 : nat. In Part 2, we will attach parameters to Definition to build functions and see why recursive functions require the separate keyword Fixpoint.
The Definition in our third exercise records two facts: and . Use Check to inspect the type on the left, and use Print whenever you want to inspect the body where the number 3 was defined.7
Optional: Proving an Equality by Computation
Now check 1 + 1 = 2 as a proof. You can append the code below to the same Scratch.v file. Example names the equality to prove, and the proof is written between Proof. and Qed..
Example one_plus_one : 1 + 1 = 2.
Proof.
reflexivity.
Qed.reflexivity. is an Ltac1 tactic. It solves this equality because both sides reduce to the same value by computation. Qed. records the completed proof once no goals remain. Compile the file again and these four lines won't print a separate value.
When a claim has a premise, use intros to bring it into the proof as a hypothesis. Use simpl when you want to reduce the expressions in a goal. Here there are no premises to move, and both sides already compute to the same value, so reflexivity. is enough. In Part 5, you'll move the cursor through a proof and see how those three tactics change the goal.
Footnotes
- The Rocq Prover. About The Rocq Prover. Introduces the project’s history and the rename from Coq to Rocq. ↩
- The Rocq Prover Reference Manual 9.2. Commands. Summarizes what query commands such as
CheckandPrintdisplay. ↩ - The Rocq Prover Reference Manual 9.2. Commands: Query Commands · Reasoning with Equalities: Computing in a Term.
Checkqueries a term’s type, whileComputeevaluates a term viaEval vm_compute. ↩ - The Rocq Prover Reference Manual 9.2. Command level processing. Gives examples of interpreting arithmetic expressions in integer scope with
%Z. ↩ - Rocq Core Library 9.2. Corelib.Init.Nat. Truncation at 0 in natural-number subtraction can be seen in the definition of
Nat.sub. ↩ - The Rocq Prover Reference Manual 9.2. Command Level Processing. Provides examples of attaching
%Zto read arithmetic notation over integers. ↩ - The Rocq Prover Reference Manual 9.2. Commands: Displaying. Confirms that
Printdisplays both the type and the body of a declaration. ↩