While the data types and functions we wrote in Parts 1 through 4 live in the computational universe (Type / Set), the mathematical statements we want to prove live in the universe of propositions (**`Prop`**).
Put the Rocq code from Sections 1 and 3 into FirstProofs.v in that order. Use rocq compile FirstProofs.v to check each group. A successful compile of these proofs prints no result, so use the cursor in VsRocq to inspect the goal state in Section 2.
1. Opening a Proof with Proof and Closing It with Qed
To prove a theorem, declare its name and statement with Theorem (or Lemma), type Proof. to enter Ltac tactic mode, and close the proof with Qed. once every subgoal has been solved. In our earlier computation examples, Compute checked the result for one specific number at a time.
In a theorem, writing forall n : nat states a claim about every natural number, rather than choosing one value to test. In the proof, running intros n. places an arbitrary natural number n into your context of hypotheses so you can proceed with the proof.1
Theorem and Lemma both name propositions to prove. Writers often use Theorem for a main result and Lemma for a smaller one that supports another proof; Rocq checks the evidence the same way. The tactics you write below Proof. build that evidence, and Qed. records the finished proof.
Each symbol in the inference rule below plays a specific role. The upside-down A symbol (written forall n : nat in code) means “for every natural number , no matter which one is chosen.” The horizontal bar is a logical inference rule meaning that establishing the upper judgment completes the lower theorem.
Above the bar, to the left of the turnstile is the arbitrary natural number introduced into the context by intros n., and to the right of is the equality proof we need to construct for that .
Above the horizontal bar, the left side of is our context of assumptions and the right side is the evidence and type to be found under those assumptions. After using intros n to move into that upper state and finding the evidence , Rocq packages it into a universal proof that accepts any natural number.2
Theorem two_plus_three : 2 + 3 = 5.
Proof.
simpl.
reflexivity.
Qed.
Theorem zero_add_left : forall n : nat, 0 + n = n.
Proof.
intros n.
simpl.
reflexivity.
Qed.
Theorem rewrite_example : forall a b : nat,
a = b -> a + 1 = b + 1.
Proof.
intros a b H.
rewrite -> H.
reflexivity.
Qed.2. Reading the Right-Hand Goal Panel
As you move your cursor down each line below Proof., the side panel displays the current proof state divided by a horizontal line (========): above the line is your context of available variables and hypotheses, and below the line is the remaining goal you must prove. The snapshot below is from rewrite_example just after intros a b H. runs.
The four basic tactics in the code above transform the Goal panel as follows:
Read the names in intros a b H. in order. The first two stand for the numbers in forall a b : nat; H names the premise a = b on the left of the arrow. That's why rewrite -> H. gets an equality to work with, rather than a number.
intros name...: moves leadingforall xvariables or implication premises (theAinA -> B) above the horizontal line into your hypothesis context (runningintros a b H.placesa, b : natand the equality hypothesisH : a = binto your context).simpl: unfolds function definitions and simplifies the goal as far as computation can go (0 + nimmediately reduces tonby the first branch| 0 => nofNat.add).reflexivity: finishes the proof whenever both sides of=evaluate to the exact same term by definition. In fact, the first two addition theorems above close withreflexivity.in a single line even if you omitsimpl..3rewrite -> H(orrewrite <- H): uses an equality hypothesisH : a = bto replace the left-hand sideawith the right-hand sidebin the goal (or right-to-left when written<-).
The two proofs make both sides of their goal equal for different reasons. Below, denotes definitional equality obtained by unfolding definitions and computing, whereas the arrow in the second equation shows the new goal left behind after rewrite:
In the first line, because the first argument to addition is 0, Rocq can reduce to even without knowing the value of . In the second line, and do not become equal by computation; instead, we substitute using the hypothesis introduced by intros. Once both sides of the resulting goal match, reflexivity supplies the final proof term.4
3. Assembling Implication (->) Proofs with exact and apply
For general logical propositions beyond equalities, we use exact to submit an existing hypothesis directly, and apply to apply an implication hypothesis (P -> Q) backward to reduce the goal.
Theorem modus_ponens : forall (P Q : Prop),
P -> (P -> Q) -> Q.
Proof.
intros P Q HP HPQ.
apply HPQ.
exact HP.
Qed.Watch how the Goal panel changes across the three tactic lines of modus_ponens. Running intros P Q HP HPQ. moves both propositions P, Q : Prop and both hypotheses HP : P and HPQ : P -> Q above the horizontal line, leaving only the final conclusion Q below the line as the goal.
Next, running apply HPQ. (‘to prove Q, it suffices to prove P’) replaces the goal below the line with the premise P, and supplying HP : P from our context with exact HP. closes the proof. In Part 6, we will bring out case analysis (destruct) and mathematical induction (induction) to prove properties of conditional branches and recursive functions that these basic tactics alone cannot unlock.
Viewing an implication as a function that turns evidence for into evidence for makes the proof read like a one-line function application:
To obtain the right-hand side , apply HPQ turns the open argument slot into the new subgoal, and exact HP fills that slot with the evidence already in context. Whenever you want to reason backward from your target conclusion to the premise needed to produce it, use apply.5
Footnotes
- The Rocq Prover Reference Manual 9.2. Proof handling. Covers opening a theorem, solving its goals, and sealing the proof. ↩
- The Rocq Prover Reference Manual 9.2. Functions and Assumptions: Functions and Function Types · Proof Mode: Proof State. Explains how variables bound by
forallenter the proof context and leave the body as the goal. ↩ - The Rocq Prover Reference Manual 9.2. Reasoning with equalities. Explains how
reflexivityandrewriteoperate on equality goals. ↩ - The Rocq Prover Reference Manual 9.2. Conversion Rules · Reasoning with Equalities: Tactics for Simple Equalities · Reasoning with Equalities: Rewriting. Contrasts definitional conversion with rewriting by an assumed equality. ↩
- The Rocq Prover Reference Manual 9.2. Functions and Assumptions: Functions and Function Types · Common Elements of Tactics. Explains treating implication proofs as functions and how
applyturns a premise into the next goal. ↩