4.1. Backward Proofs
A tactic operates on a proof goal and either proves it or creates new subgoals. A goal consists of a local context, which lists variable declarations x : σ and hypotheses h : P, and a conclusion, the proposition to prove. We write the goal as the sequent C ⊢ Q, whose antecedent C is the local context and whose consequent Q is the conclusion.J. Avigad, L. de Moura, S. Kong, S. Ullrich, Theorem Proving in Lean 4, chapter 5.
Tactics are a backward proof mechanism. A backward proof starts at the goal and works towards the available hypotheses and theorems, and its characteristic phrase is "it suffices to prove". A forward proof starts at the hypotheses and works towards the goal, and Lecture 5 develops it. Given hypotheses ha : a, hab : a → b, hbc : b → c and the conclusion c, the two directions read as follows.
Backward, from the goal: to prove c, by hbc it suffices to prove b; to prove b, by hab it suffices to prove a; and ha proves a. Forward, from the hypotheses: from ha and hab, we have b; from b and hbc, we have c.
A derivation in the natural deduction of Lecture 1 is written by stacking rule applications, with the premises of each rule above the inference line and its conclusion below it. The top formulas, which no rule derives, are the assumptions and the axioms, and the end formula, at the bottom, is the conclusion of the derivation. The derivation admits both readings, forward from the assumptions to the conclusion, and backward from the conclusion to the assumptions.G. Gentzen, Investigations into Logical Deduction, in M. E. Szabo (ed.), The Collected Papers of Gerhard Gentzen, North-Holland, 1969, pp. 68–131.
The keyword by enters tactic mode, and each line after it is one tactic. The proof below introduces the universally quantified variables and the two hypotheses, and closes the goal. The trace_state lines print the goal between the steps, and the outputs follow the code.
namespace Backward
theorem fst_of_two_props :
∀ a b : Prop, a → b → a := ⊢ ∀ (a b : Prop), a → b → a
a:Propb:Prop⊢ a → b → a
a:Propb:Prop⊢ a → b → a
a:Propb:Propha:ahb:b⊢ a
a:Propb:Propha:ahb:b⊢ a
All goals completed! 🐙
end Backward
After intro a b the two propositions have entered the context, and the conclusion is the implication that remains.
After intro ha hb the two hypotheses are available, and the conclusion is a.
The proof below chains two implications. Read it as three "it suffices to" steps: to prove c, by hbc it suffices to prove b; to prove b, by hab it suffices to prove a; and ha proves a.
namespace Backward
theorem prop_comp (a b c : Prop) (hab : a → b)
(hbc : b → c) : a → c := a:Propb:Propc:Prophab:a → bhbc:b → c⊢ a → c
a:Propb:Propc:Prophab:a → bhbc:b → cha:a⊢ c
a:Propb:Propc:Prophab:a → bhbc:b → cha:a⊢ b
a:Propb:Propc:Prophab:a → bhbc:b → cha:a⊢ a
All goals completed! 🐙
end Backward