Use what you already know

Hypotheses are proofs you already hold. exact hands one to Lean.

12 minBeginnerhypothesiscontextexactproofs are values
0/13 completed in this course

Everything before the final colon in a statement is context. In theorem exercise (P : Prop) (h : P) : P, the context holds a proposition P and a proof h of it, and the goal is P. The panel shows P : Prop, then h : P, then ⊢ P.

In Lean a proof of P is a value whose type is P, the same way 3 is a value whose type is Nat. That is why hypotheses are named like variables and used like variables. h is not a note saying “P is true”; h is the evidence.

exact e closes the goal when e has exactly the type of the goal. When the types do not line up, Lean prints what it got and what it wanted, which is the error you will read most often.

A common slip is to write exact P. P is the proposition, not a proof of it: its type is Prop, not P. The message says so in those words, and recognising it once saves a lot of time later.

Worked example

-- Two proofs are available; the goal decides which one fits.
example (A B : Prop) (ha : A) (hb : B) : B := by
  exact hb

-- Handing Lean the proposition instead of a proof of it:
--   example (P : Prop) (h : P) : P := by exact P
--
--   Type mismatch
--     P
--   has type
--     Prop
--   of sort `Type` but is expected to have type
--     P
--   of sort `Prop`

Lean also warns that ha went unused in the first example. It keeps track of assumptions you never touch, which is a useful signal when a proof has grown longer than it should be.

Takeaway

Hypotheses are proofs you already hold. exact h finishes a goal whose type is the type of h.

Exercise 1 of 2

Close the goal with the proof you are already holding.

Suggested steps
  1. Hand the hypothesis to Lean

These marks only recognize text. Another correct proof may use different steps; Lean checks whether it works.

Exercise.lean
1theorem exercise (P : Prop) (h : P) : P := by
given
Loading editor…

Where you start. Everything above ⊢ may be assumed; the line below it is what you must prove.

P:Prop
h:P
⊢P
ReadyLn 1, Col 1Lean 4
Draft saved in this browser
Stuck?
Recall and apply

Knowledge check

Answer without looking back, then check your reasoning.

0of 3
correct
Question 1 of 3The goal is Q and the context contains hq : Q. Which tactic closes it?
Question 2 of 3What does it mean that a proof is a value?
Question 3 of 3Two hypotheses ha : A and hb : B are in context and the goal is A. What does exact hb report?