Plan a proof, then fill it in

Write the structure first with sorry in the holes, and let Lean show what each hole needs.

17 minBeginnersorryproof skeletonsunsolved goalsworking on one hole at a time
0/13 completed in this course

Longer proofs are easier to write in two passes. First write the structure: the intro, the obtain, the constructor and one bullet per branch. Then fill in the branches one at a time. sorry is what makes the first pass possible: it closes any goal without proving it, as a placeholder.

Lean still checks everything around a sorry. If the skeleton itself is wrong, say you split a goal that is not a conjunction, you find out immediately instead of after writing every branch. A file that uses sorry compiles with the warning declaration uses 'sorry', and an Academy exercise never counts as complete while one is left.

To see what a hole still needs, replace its sorry with skip, which does nothing. Lean then reports unsolved goals for that bullet and prints the goal, with its hypotheses above the line. Fill in the proof there, check again, and move to the next hole.

This is how people work in real Lean projects as well: sketch the argument with holes, confirm that the outline compiles, and make the holes smaller until none are left.

Worked example

example (A B : Prop) (ha : A) (hb : B) : B ∧ A := by
  constructor
  · exact hb
  · exact ha

-- The same proof halfway through, with one hole left:
--   constructor
--   · exact hb
--   · sorry
--
--   warning: declaration uses 'sorry'
--
-- With `skip` in place of `sorry`, Lean shows what the hole needs:
--   error: unsolved goals
--   case right
--   A B : Prop
--   ha : A
--   hb : B
--   ⊢ A

The finished proof is on top; the comments show the two messages you see on the way there. case right names the branch: the right half of the conjunction.

Takeaway

Write the structure first with sorry in the holes, confirm it compiles, then fill one hole at a time. An exercise completes only when no sorry is left.

Exercise 1 of 3

The starter is a complete skeleton with two holes. Check it first: it compiles with a sorry warning. Then replace each sorry with a real proof. Use skip if you want Lean to show you what a hole needs.

Suggested steps
  1. Keep the skeleton: introduce, open and split (done)
  2. Fill the first hole: the goal is R
  3. No sorry is left

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

Exercise.lean
1theorem exercise (P Q R : Prop) (hqr : Q → R) : P ∧ Q → R ∧ P := by
given
Loading editor…

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

P Q R:Prop
hqr:Q → R
⊢P ∧ Q → R ∧ 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 3What does sorry do in a proof?
Question 2 of 3Why check a skeleton before filling it in?
Question 3 of 3How do you make Lean show the goal of one hole?