Stage 04 · Step 18 of 50

A two-way promise.

Core Lean8 minutesLean 4.36.0

01The idea

A two-way bridge needs a route in both directions. “If and only if” also makes two promises.

Tacto · Your guide for this idea
Tacto pointing

Prove each implication to establish the equivalence.

02In maths

P ∧ Q if and only if Q ∧ P.

Picture it

“If and only if”: two one-way roadsThe start card has P Q : Prop with goal P and Q if and only if Q and P. The tactic constructor splits it into two one-way roads between two boxes: a box holding P then Q, and a box holding Q then P. The upper road, case mp, goes from P and Q to Q and P. The lower road, case mpr, goes back from Q and P to P and Q. Both roads must be built. Each one is built with intro h, then exact with the pair h.right, h.left.STARTP Q : Prop⊢ P ∧ Q ↔ Q ∧ PconstructorP ∧ QPQQ ∧ PQPcase mp⊢ P ∧ Q → Q ∧ P⊢ Q ∧ P → P ∧ Qcase mpreach road: intro h, then exact ⟨h.right, h.left⟩

Swipe sideways to see the whole picture.

↔ is two one-way roads, one in each direction. constructor splits it into the forward road (case mp) and the road back (case mpr), and you must build both. Each road is an implication: intro h takes the pair you start with, and ⟨h.right, h.left⟩ repacks its two halves in swapped order.

03In Lean

This code comes directly from the file checked by Lean.

E18.leanTry it live (opens official Lean editor)
example (P Q : Prop) : (P ∧ Q) ↔ (Q ∧ P) := by
  constructor
  · intro h
    exact ⟨h.right, h.left⟩
  · intro h
    exact ⟨h.right, h.left⟩

The symbol ↔ means “if and only if.” Type it with \iff. This is a logical equivalence.

The constructor for an equivalence asks for a forward implication and a reverse implication.

An equivalence and an equality are different kinds of statement. Here we prove the two implications directly.

04Step by step

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

After line 1
P Q : Prop
⊢ P ∧ Q ↔ Q ∧ P
After line 1: example (P Q : Prop) : (P ∧ Q) ↔ (Q ∧ P) := by
P Q : Prop
⊢ P ∧ Q ↔ Q ∧ P
After line 2: constructor
case mp
P Q : Prop
⊢ P ∧ Q → Q ∧ P

case mpr
P Q : Prop
⊢ Q ∧ P → P ∧ Q
After line 3: · intro h
case mp
P Q : Prop
h : P ∧ Q
⊢ Q ∧ P
After line 4: exact ⟨h.right, h.left⟩
no goals
After line 5: · intro h
case mpr
P Q : Prop
h : Q ∧ P
⊢ P ∧ Q
After line 6: exact ⟨h.right, h.left⟩
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

    Prove that P is equivalent to itself.

  2. A little stretch

    Show that P and P is equivalent to P.

Exercises/E18.leanTry it live (opens official Lean editor)
example (P : Prop) : P ↔ P := by
  sorry

example (P : Prop) : (P ∧ P) ↔ P := by
  sorry

08A quick check

1. What does ↔ mean?

Read the answer and explanation

If and only if. It requires an implication in each direction. Type it with \iff.

2. Does one implication always prove an equivalence?

Read the answer and explanation

No. You also need the reverse implication.

One more idea in your toolkit.

Take your time. Progress is yours to mark.