Rewrite through a chain

Use two equality hypotheses in a readable calc proof.

11 minBeginnerrwcalcequality as substitution
0/10 completed in this course

An equality hypothesis lets you replace one expression by another. With hab : a = b, the tactic rw [hab] changes occurrences of a into b in the goal.

Two equalities can be chained. A calc block records the intermediate expression, and every line supplies its own justification. The underscore begins where the previous line ended.

This is more informative than asking automation to normalize everything. A reader sees that the argument first moves from a to b, then from b to c.

The additions by one are deliberately carried through the chain. Rewriting works inside a larger expression, not only when the whole goal is exactly the equality from the context.

Worked example

example (x y : Nat) (h : x = y) : x + 2 = y + 2 := by
  rw [h]

One equality needs one rewrite. Your exercise composes two equalities and makes the middle expression visible.

Takeaway

Equality is a substitution rule. calc turns several substitutions into a proof whose intermediate steps remain visible.

Your exercise

Use hab and hbc in a two-step calc proof from a + 1 to c + 1.

Suggested steps
  1. Open a calc chain at a + 1
  2. Rewrite the first step with hab
  3. Continue from _ and rewrite with hbc

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

Exercise.lean
1theorem exercise (a b c : Nat) (hab : a = b) (hbc : b = c) : a + 1 = c + 1 := by
given
Loading editor…

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

a b c:Nat
hab:a = b
hbc:b = c
a + 1 = c + 1
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 rw [hab] do when hab : a = b?
Question 2 of 3What does _ mean in the second line of a calc block?
Question 3 of 3Why show the middle expression b + 1?