Stage 03 · Step 13 of 50

Unpack an and.

Core Lean8 minutesLean 4.36.0

01The idea

A packed lunch contains both a drink and a sandwich. You can unpack the pair and use either part.

Goalie · Your guide for this idea
Goalie pointing

A proof of “and” also carries two component proofs.

02In maths

If P ∧ Q holds, then Q ∧ P holds.

Picture it

Using an “and”: unpack the pair, then repack itTop: h, a proof of P and Q, is drawn as a lunch box with two compartments, P and Q. Unpacking it gives two separate proofs, hP : P and hQ : Q. Repacking them in the other order, written with angle brackets as hQ comma hP, gives a box with compartments Q and P, a proof of Q and P. Bottom: three goal cards. The start card has P Q : Prop and h : P and Q, with goal Q and P. The tactic cases h, with the pattern intro hP hQ, replaces h by hP : P and hQ : Q; the goal is still Q and P. Then exact with the pair hQ, hP closes the goal, leaving no goals.h : P ∧ QPQa packed pairhP : PhQ : Qunpacked: two separate proofs⟨hQ, hP⟩ : Q ∧ PQPrepacked, swappedSTARTP Q : Proph : P ∧ Q⊢ Q ∧ Pcases hUNPACKEDP Q : ProphP : PhQ : Q⊢ Q ∧ Pexact ⟨hQ, hP⟩REPACKEDno goals

Swipe sideways to see the whole picture.

A proof of P ∧ Q is a packed pair: a proof of P and a proof of Q in one box. cases h opens the box and gives you the two parts as hP and hQ. The angle brackets ⟨hQ, hP⟩ pack them again in the other order, which is exactly a proof of Q ∧ P.

03In Lean

This code comes directly from the file checked by Lean.

E13.leanTry it live (opens official Lean editor)
example (P Q : Prop) (h : P ∧ Q) : Q ∧ P := by
  cases h with
  | intro hP hQ =>
    exact ⟨hQ, hP⟩

The tactic cases examines the constructor used to build a value. A conjunction has one constructor, with two components.

The symbols ⟨ and ⟩ form an anonymous constructor. Type them with \langle and \rangle.

For a conjunction proof, the fields left and right also retrieve its two component proofs.

04Step by step

Choose a line to see Lean’s recorded goal state after that line.

After line 1
P Q : Prop
h : P ∧ Q
⊢ Q ∧ P
After line 1: example (P Q : Prop) (h : P ∧ Q) : Q ∧ P := by
P Q : Prop
h : P ∧ Q
⊢ Q ∧ P
After line 2: cases h with
P Q : Prop
h : P ∧ Q
⊢ Q ∧ P
After line 3: | intro hP hQ =>
case intro
P Q : Prop
hP : P
hQ : Q
⊢ Q ∧ P
After line 4: exact ⟨hQ, hP⟩
no goals

05Lean says

Captured from Lean 4.36.0
no goals

A goal is what remains to prove. The symbol ⊢ points to it. Meet the turnstile.

07Your turn

sorry is a placeholder for unfinished work. Replace it as you solve each task. A finished proof has no placeholders.

  1. Warm-up

    Extract a proof of P from the supplied conjunction.

  2. A little stretch

    Extract R from P and (Q and R).

Exercises/E13.leanTry it live (opens official Lean editor)
example (P Q : Prop) (h : P ∧ Q) : P := by
  sorry

example (P Q R : Prop) (h : P ∧ (Q ∧ R)) : R := by
  sorry

08A quick check

1. What information does a proof of P ∧ Q contain?

Read the answer and explanation

A proof of each side. Conjunction packages both proofs.

2. What do the angle brackets build here?

Read the answer and explanation

A pair of proofs. The expected conjunction type tells Lean how to interpret the anonymous constructor.

One more idea in your toolkit.

Take your time. Progress is yours to mark.