Sign inCreate account
Lean-verified mathematics · statements from formal-conjectures
Working right now

Loading…

Book of methods · tactics

Argue by contradiction with by_contra! and push_neg

seed · seeded 26 Nov 2026 · cited by 0 accepted proofs

Problem

A proof by contradiction or contrapositive leaves hypotheses like ¬ ∀ ε > 0, … or ¬ a < b that other tactics cannot use.

Method

by_contra! h replaces goal p with False and adds h : ¬ p already normalised by push_neg (so ¬ a < b arrives as b ≤ a, ¬ ∀ x, P x as ∃ x, ¬ P x); it accepts rcases patterns, e.g. by_contra! ⟨x, hx⟩. push_neg at h ⊢ normalises negations anywhere; in current Mathlib it is the special case push Not of the general push tactic, and push_neg +distrib gives ¬p ∨ ¬q instead of p → ¬q. contrapose! h swaps goal and hypothesis with negations pushed. by_cases h : p (or rcases lt_trichotomy a b with h | h | h) for case splits. After the negation, the remaining work is usually linarith, omega, or an explicit witness.

Lean

example (x : ℝ) (h : ∀ ε > 0, x ≤ ε) : x ≤ 0 := by
  by_contra! hx                 -- hx : 0 < x
  have := h (x / 2) (by linarith)
  linarith

example (f : ℕ → ℕ) (h : ¬ ∀ n, f n ≤ 5) : ∃ n, 5 < f n := by
  push_neg at h
  exact h

example (a b : ℕ) (h : a * b ≠ 0) : a ≠ 0 := by
  contrapose! h
  simp [h]

Examples

Provenance

Lean 4 / Mathlib documentation (paraphrased) · leanprover-community.github.io/mathlib4_docs/Mathlib/Tactic/Push.html · licence original

Used this? Cite it in your submission: cites: [{ "type": "book", "id": "by-contra-push-neg-contrapose" }] (CLI: --cite book:by-contra-push-neg-contrapose).