cases
Summary
cases is a general-purpose tactic for “deconstructing” hypotheses. If h is a hypothesis which somehow “bundles up” two pieces of information, then cases h with h1 h2 will make hypothesis h vanish and will replace it with the two “components” which made the proof of h in the first place.
Examples
The way to make a proof of
P ∧ Qis to use a proof ofPand a proof ofQ. If you have a hypothesish : P ∧ Q, thencases hwill delete the hypothesis and replace it with hypothesesh_left : Pandh_right : Q. These are not the best names for hypotheses; better to typecases h with hP hQ.The way to make a proof of
P ↔ Qis to proveP → QandQ → P. So faced withh : P ↔ Qone thing you can do iscases h with hPQ hQPwhich removeshand replaces it withhPQ: P → QandhQP: Q → P. Note however that this might not be the best way to proceed; whilst you canapply hPQandhQP, you lose the ability to rewritehwithrw h. If you really need to keep a copy ofharound, you could always tryhave h2 := h, cases h with hPQ hQP.There are two ways to make a proof of
P ∨ Q. You either use a proof ofP, or a proof ofQ. So ifh : P ∨ Qthencases h with hP hQhas a different effect to the first two examples; after the tactic you will be left with two goals, one with a new hypothesishP : Pand the other withhQ : Q. One way of understanding why this happens is that the inductive typeorhas two constructors, whereasandonly has one.There are two ways to make a natural number
n. Every natural number is either0orsucc(m)for some natural numberm. So ifn : ℕthencases n with mgives two goals; one wherenis replaced by0and the other where it is replaced bysucc(m). Note that this is a strictly weaker version of theinductiontactic, becausecasesdoes not give us the inductive hypothesis.If you have a hypothesis
h : ∃ a, a^3 + a = 37thencases h with x hxwill give you a numberxand a proofhx : x^3 + x = 37.
Further notes
Note that ∧ is right associative: P ∧ Q ∧ R means ``P ∧ (Q ∧ R). So if h : P ∧ Q ∧ R then cases h with h1 h2 will give you h1 : P and h2 : Q ∧ R and then you have to do cases h2 to get to the proofs of Q and R. The syntax cases h with h1 h2 h3 doesn’t work (h3 just gets ignored). A more refined version of the cases tactic is the rcases tactic (although the syntax is slightly different; you need to use pointy brackets ⟨,⟩ with rcases). For example if h : P ∧ Q ∧ R then you can do rcases h with ⟨hP, hQ, hR⟩.