I saw from various tutorials that many proofs in lean 4 can be given using tactics or using proof terms (or a mixture of both). This makes sense to me given the constructive view of proofs as inductive data structures.
However, I cannot figure out how to convert proof tactics involving classical logic into proof terms. This includes by_cases
and certain tactics about negation (by_contra
, contrapose
). For example, below is a proof about contrapose:
example (P Q : Prop) (h : ¬P → ¬Q) : Q → P := by
intro hq
by_cases hp : P
· exact hp
· have := h hp
contradiction
My question is:
How can I convert a proof with such tactics into a pure proof term (i.e. without entering the tactical mode or using the by
)?
example (P Q : Prop) (h : ¬P → ¬Q) : Q → P := _
Note: the above proof may not be optimal. It's just something I came up with as an example. There is also another proof, but it requires mathlib:
import Mathlib.Data.Real.Basic
example (P Q : Prop) (h : ¬P → ¬Q) : Q → P := by
contrapose! h
apply and_comm.mp
exact h