Stage 09 · Step 43 of 50

Keep a clue in both cases.

Core Lean12 minutesLean 4.36.0

01The idea

Everyone on the trip has a ticket and either a red wristband or a blue one. Sort the group by wristband.

Goalie · Your guide for this idea
Goalie pointing

Each group still has its tickets.

02In maths

P and (Q or R) implies (P and Q) or (P and R).

Picture it

Split only the wristband; the ticket goes into both casesLeft: the clue h : P and (Q or R) holds two things. h.1 : P is a gold ticket. h.2 : Q or R is a wristband that is red or blue. The goal is P and Q, or P and R. The tactic cases h.2 splits only the wristband. Top case inl q, red band: the same ticket h.1 : P plus q : Q make the pair P and Q, and exact Or.inl ⟨h.1, q⟩ picks the left side. Bottom case inr r, blue band: the ticket h.1 : P plus r : R make the pair P and R, and exact Or.inr ⟨h.1, r⟩ picks the right side.h : P ∧ (Q ∨ R)Ph.1 : Pa ticketorh.2 : Q ∨ Rred or blue bandgoal (in both cases):⊢ P ∧ Q ∨ P ∧ Rcases h.2case inl q: red bandh.1 : P+q : QP ∧ Qexact Or.inl ⟨h.1, q⟩case inr r: blue bandh.1 : P+r : RP ∧ Rexact Or.inr ⟨h.1, r⟩

Swipe sideways to see the whole picture.

The clue h holds a ticket h.1 and a wristband choice h.2. cases h.2 sorts people by wristband, but the ticket is untouched, so it is still there in both cases. Each case pairs the ticket with its band using ⟨h.1, …⟩, then Or.inl or Or.inr says which side of the goal that pair proves.

03In Lean

This code comes directly from the file checked by Lean.

E43.leanTry it live (opens official Lean editor)
example (P Q R : Prop) (h : P ∧ (Q ∨ R)) : (P ∧ Q) ∨ (P ∧ R) := by
  cases h.2 with
  | inl q => exact Or.inl ⟨h.1, q⟩
  | inr r => exact Or.inr ⟨h.1, r⟩

h.1 is the ticket, and h.2 carries the wristband choice. Split only h.2 so you can reuse the ticket in either branch.

In Or.inl ⟨h.1, q⟩, the angle brackets build a pair of proofs. The outer constructor identifies which alternative that pair establishes.

04Step by step

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

After line 1
P Q R : Prop
h : P ∧ (Q ∨ R)
⊢ P ∧ Q ∨ P ∧ R
After line 1: example (P Q R : Prop) (h : P ∧ (Q ∨ R)) : (P ∧ Q) ∨ (P ∧ R) := by
P Q R : Prop
h : P ∧ (Q ∨ R)
⊢ P ∧ Q ∨ P ∧ R
After line 2: cases h.2 with
P Q R : Prop
h : P ∧ (Q ∨ R)
x✝ : Q ∨ R
⊢ P ∧ Q ∨ P ∧ R
After line 3: | inl q => exact Or.inl ⟨h.1, q⟩
no goals
After line 4: | inr r => exact Or.inr ⟨h.1, r⟩
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

    Given P and R separately, build the right-hand alternative.

  2. A little stretch

    Reverse the worked proof and recover the shared clue.

Exercises/E43.leanTry it live (opens official Lean editor)
example (P Q R : Prop) (p : P) (r : R) : (P ∧ Q) ∨ (P ∧ R) := by
  sorry

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

08A quick check

1. Which part of h is available in both branches?

Read the answer and explanation

h.1 proves P. The first component of the conjunction is separate from the wristband choice.

2. Which constructor announces that the right alternative holds?

Read the answer and explanation

Or.inr. Or.inr packages evidence for the proposition on the right.

One more idea in your toolkit.

Take your time. Progress is yours to mark.