Two logics in one system
In Module 6 you built natural-deduction proofs on paper. You started from the formula you wanted, chose the rule that could have produced it, and worked upwards until every branch ended in an assumption. Isabelle builds proofs in exactly this way, and checks every step. In this module you redo the proofs of Module 6 in Isabelle, rule by rule, so that each paper tree becomes a short proof script.
Before the first proof you need to read the notation Isabelle uses for rules and goals. It involves a second, smaller logic underneath HOL.
Pure, the meta-logic
Module 1 described Isabelle as a framework in which many logics can be defined. The framework has a small logic of its own, Isabelle/Pure, or Pure for short. Its only job is to say what rules and proofs are. Every other logic, HOL included, is defined inside Pure.
A meta-logic is a logic for stating rules and proofs about another logic, the object logic. In Isabelle the meta-logic is Pure and the object logic is HOL. Pure has three symbols of its own: ⟹ (“from … infer”), ⋀ (“for an arbitrary …”) and ≡, Pure’s own equality, which Isabelle uses above all to state definitions.
Each Pure symbol has a HOL counterpart that you already know from Modules 2 and 3:
| Pure | Read it as | HOL | Read it as |
|---|---|---|---|
A ⟹ B |
from A, infer B | A ⟶ B |
A implies B |
⋀x. P x |
for an arbitrary x, P x | ∀x. P x |
for all x, P x |
a ≡ b |
a equals b; in a definition, a is defined as b | a = b |
a equals b |
In Isabelle/jEdit you type ⟹ as ==>, ⋀ as !! and ≡ as ==. The brackets ⟦ and ⟧, which appear
below, are [| and |].
Why does Isabelle need two arrows? Because a rule of natural deduction is not a formula. The rule (∧I) of Module 6 does not say “A ∧ B is true”. It says “if you have derived A and you have derived B, you may write down A ∧ B”. It is a statement about derivations, which Module 6 drew as a horizontal line. Pure gives Isabelle a language for statements of this kind. In Pure, (∧I) reads
“from A and B, infer A ∧ B”. The formulas A, B and A ∧ B belong to HOL; the brackets, the semicolon and
⟹ belong to Pure. HOL formulas have the type bool. Pure statements have a type of their own, prop,
and Isabelle turns each HOL formula into a Pure statement where one is needed, without showing you.
A₁ ⟹ A₂ ⟹ … ⟹ Aₙ ⟹ C means A₁ ⟹ (A₂ ⟹ … ⟹ (Aₙ ⟹ C)), and Isabelle prints it as
⟦A₁; A₂; …; Aₙ⟧ ⟹ C: from the premises A₁ to Aₙ, infer the conclusion C. A premise can itself be a
rule: in (A ⟹ B) ⟹ C, the premise A ⟹ B is a derivation of B that may assume A.
Figure 7.1 shows the two layers, and how one rule uses both.
Isabelle’s two layers. HOL formulas, of type bool, are written with ¬ ∧ ∨ ⟶ ∀ ∃ and =. Rules and
goals are Pure statements, of type prop, built from HOL formulas with ⟹, ⋀ and ≡.
Goals use the same arrow
Isabelle writes goals with ⟹ too. Compare two lemmas:
lemma "A ⟹ A ∨ B"proof (prove)
goal (1 subgoal):
1. A ⟹ A ∨ BThis goal is a rule: from A, infer A ∨ B. A is an assumption you may use, and A ∨ B is the
conclusion you must reach. blast, from Module 2, proves it:
by blastlemma "A ⟶ A ∨ B"proof (prove)
goal (1 subgoal):
1. A ⟶ A ∨ BHere the whole goal is one HOL formula, and there are no assumptions yet. It says the same thing, and
blast proves it too:
by blastThe difference lies in how you work with the two forms. On paper, the first step of a proof of A ⟶ A ∨ B is (⟶I): assume A, then prove A ∨ B. In Isabelle that step turns the ⟶ of the goal into ⟹, after which the goal looks exactly like the first lemma. You will take this step in Section 7.3.
The manual Programming and Proving in Isabelle/HOL gives a practical rule: state a lemma as ⟦A₁; …; Aₙ⟧ ⟹ C rather than A₁ ∧ … ∧ Aₙ ⟶ C when you want to use it as a rule later, because Isabelle can apply the first form directly. In this module the lemmas keep the ⟶ form of Module 6, so that each Isabelle proof follows its paper tree step by step.
Definitions with ≡
The third symbol of Pure, ≡, appears in definitions. Module 6 explained ¬A as A ⟶ ⊥. HOL defines
negation in the same way, as the command thm shows (it displays a stored theorem by its
name; Section 7.2 uses it all the time):
thm not_def¬ ?P ≡ ?P ⟶ FalseRead it as “¬P is defined as P ⟶ False”. Isabelle writes ⊥ as False. The question marks are explained
in Section 7.2.
⟹ belongs to Pure. It joins statements, but it can never appear inside a HOL formula:
lemma "(A ⟹ B) ∧ C"Inner syntax error⌂
at "∧ C"
Failed to parse propIsabelle read (A ⟹ B) as a Pure statement and then could not go on with ∧ C, because ∧ joins HOL
formulas. Inside a formula, write ⟶. Note also that ⟹ binds more weakly than every symbol of HOL:
A ∧ B ⟹ C means (A ∧ B) ⟹ C.
Rules are theorems
Look a rule up with thm
In Isabelle a rule is not a separate kind of object. It is a theorem whose statement uses ⟹, and thm
shows it:
thm conjI⟦?P; ?Q⟧ ⟹ ?P ∧ ?QCompare it with (∧I) as Module 6 drew it:
The premises above the line become the premises before ⟹, and the conclusion below the line becomes the conclusion after it. The name, conjI, is short for conjunction introduction.
A schematic variable, or unknown, is a variable written with a question mark, such as ?P. It is
a placeholder: when a theorem is used, Isabelle may replace it with any term of the right type, the same
term at every occurrence. When Isabelle stores a proved lemma, it turns the lemma’s free variables into
schematic variables, which records that the lemma holds for all their values.
So conjI works for any two formulas. You can choose them yourself with of, which replaces the schematic
variables from left to right:
thm conjI[of "door_closed" "lift_stopped"]⟦door_closed; lift_stopped⟧ ⟹ door_closed ∧ lift_stoppedHere door_closed and lift_stopped are free variables of type bool: two facts about a lift, say.
Usually you do not choose by hand. Isabelle finds the right replacement itself, by unification
(Section 7.3).
The rules of Module 6
Here are the rules of Module 6 as Isabelle states them. Each thm command below shows several rules, one
per line, in the order of their names:
thm conjI conjunct1 conjunct2 conjE disjI1 disjI2 disjE ⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q
?P ∧ ?Q ⟹ ?P
?P ∧ ?Q ⟹ ?Q
⟦?P ∧ ?Q; ⟦?P; ?Q⟧ ⟹ ?R⟧ ⟹ ?R
?P ⟹ ?P ∨ ?Q
?Q ⟹ ?P ∨ ?Q
⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?Rthm impI mp impE notI notE FalseE (?P ⟹ ?Q) ⟹ ?P ⟶ ?Q
⟦?P ⟶ ?Q; ?P⟧ ⟹ ?Q
⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R
(?P ⟹ False) ⟹ ¬ ?P
⟦¬ ?P; ?P⟧ ⟹ ?R
False ⟹ ?Pthm allI spec allE exI exE (⋀x. ?P x) ⟹ ∀x. ?P x
∀x. ?P x ⟹ ?P ?x
⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R
?P ?x ⟹ ∃x. ?P x
⟦∃x. ?P x; ⋀x. ?P x ⟹ ?Q⟧ ⟹ ?Qthm ccontr classical refl subst ssubst iffI iffD1 iffD2 (¬ ?P ⟹ False) ⟹ ?P
(¬ ?P ⟹ ?P) ⟹ ?P
?t = ?t
⟦?s = ?t; ?P ?s⟧ ⟹ ?P ?t
⟦?t = ?s; ?P ?s⟧ ⟹ ?P ?t
⟦?P ⟹ ?Q; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q
⟦?Q = ?P; ?Q⟧ ⟹ ?P
⟦?P = ?Q; ?Q⟧ ⟹ ?PThe table puts each one next to its paper rule:
| Paper rule (Module 6) | Isabelle name | Statement, as thm prints it |
|---|---|---|
| (∧I) | conjI |
⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q |
| (∧E₁) | conjunct1 |
?P ∧ ?Q ⟹ ?P |
| (∧E₂) | conjunct2 |
?P ∧ ?Q ⟹ ?Q |
| (∧E₁) and (∧E₂) at once | conjE |
⟦?P ∧ ?Q; ⟦?P; ?Q⟧ ⟹ ?R⟧ ⟹ ?R |
| (∨I₁) | disjI1 |
?P ⟹ ?P ∨ ?Q |
| (∨I₂) | disjI2 |
?Q ⟹ ?P ∨ ?Q |
| (∨E) | disjE |
⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R |
| (⟶I) | impI |
(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q |
| (⟶E) | mp |
⟦?P ⟶ ?Q; ?P⟧ ⟹ ?Q |
| (⟶E), elimination form | impE |
⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R |
| (¬I) | notI |
(?P ⟹ False) ⟹ ¬ ?P |
| (¬E), with ⊥ as ?R | notE |
⟦¬ ?P; ?P⟧ ⟹ ?R |
| (⊥E) | FalseE |
False ⟹ ?P |
| (∀I) | allI |
(⋀x. ?P x) ⟹ ∀x. ?P x |
| (∀E) | spec |
∀x. ?P x ⟹ ?P ?x |
| (∀E), elimination form | allE |
⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R |
| (∃I) | exI |
?P ?x ⟹ ∃x. ?P x |
| (∃E) | exE |
⟦∃x. ?P x; ⋀x. ?P x ⟹ ?Q⟧ ⟹ ?Q |
| (RAA) | ccontr |
(¬ ?P ⟹ False) ⟹ ?P |
| (RAA), variant | classical |
(¬ ?P ⟹ ?P) ⟹ ?P |
| (=I) | refl |
?t = ?t |
| (=E) | subst |
⟦?s = ?t; ?P ?s⟧ ⟹ ?P ?t |
| (=E), right to left | ssubst |
⟦?t = ?s; ?P ?s⟧ ⟹ ?P ?t |
| none | iffI |
⟦?P ⟹ ?Q; ?Q ⟹ ?P⟧ ⟹ ?P = ?Q |
| none | iffD1 |
⟦?Q = ?P; ?Q⟧ ⟹ ?P |
| none | iffD2 |
⟦?P = ?Q; ?Q⟧ ⟹ ?P |
A few things to notice:
- The names follow a pattern:
Ifor introduction,Efor elimination,Dfor destruction (explained below), and1and2for the two versions of a rule.mpis modus ponens,specis specialisation,reflis reflexivity. - ⊥ is
False, and Isabelle prints ¬ followed by a space:¬ ?P. notEconcludes any formula?R. With?Rtaken to beFalseit is (¬E), which derives ⊥ from ¬P and P. With any other?Rit is (¬E) followed by (⊥E), which derives anything from ⊥.ccontris (RAA) exactly: if assuming ¬P leads to ⊥, then P. Section 7.7 explainsclassical.- On formulas, Isabelle prints ⟷ as
=(Module 3), so?P = ?QiniffIis ?P ⟷ ?Q. Module 6’s list has no rules for ⟷:iffIproves an equivalence from the two implications, andiffD1andiffD2use one in either direction.
Three shapes of rule
Most rules in the table come in one of three shapes. The shape decides how you use a rule (Sections 7.3 and 7.4), so it is worth learning to see it.
- An introduction rule has the connective in its conclusion:
conjI,disjI1,disjI2,impI,notI,allI,exI,iffI. - An elimination rule has the connective (or
False) in its first premise, the major premise, and an arbitrary formula, a schematic variable such as?R, as its conclusion. Its other premises say what you may assume while you prove that formula:conjE,disjE,impE,notE,FalseE,allE,exE. - A destruction rule has the connective in its major premise and a part or instance of the major premise as its
conclusion:
conjunct1,conjunct2,mp,spec,iffD1,iffD2.
Isabelle often offers two versions of one paper rule: a destruction rule that reads like the paper rule
(conjunct1, mp, spec), and an elimination rule that does the same work in a form better suited to
reasoning about assumptions (conjE, impE, allE). Section 7.4 shows why the second form helps.
The rules that discharge assumptions or need an eigenvariable deserve a closer look, because Pure states their side conditions without any words.
- In
impI,(?P ⟹ ?Q) ⟹ ?P ⟶ ?Q, the premise?P ⟹ ?Qis a derivation of ?Q that may use the assumption ?P: the [A]¹ of Module 6. The assumption is available exactly inside that premise, so no discharge numbers are needed. - In
disjE, the premises?P ⟹ ?Rand?Q ⟹ ?Rare the two cases, each with its own assumption. - In
allI,(⋀x. ?P x) ⟹ ∀x. ?P x, the premise says “?P x for an arbitrary x”. The variable x is local to the premise, so it cannot occur in any assumption from outside. This is the eigenvariable condition of (∀I). - In
exE,⟦∃x. ?P x; ⋀x. ?P x ⟹ ?Q⟧ ⟹ ?Q, the second premise says “for an arbitrary x with ?P x, derive ?Q”. ?Q stands outside the scope of ⋀x, so it cannot mention x. This is the condition of (∃E) that the eigenvariable must not occur in the conclusion.
Proving backwards: rule and assumption
The plan
Take the first theorem that Module 6 derived with natural deduction, A ∧ B ⟶ B ∧ A (Section 6.4). Here is its tree:
Read it from the bottom up, the way you found it. The formula is an implication, so the last step is (⟶I): assume A ∧ B and prove B ∧ A. That is a conjunction, so the step above is (∧I), which leaves B and A. Each of them comes out of the assumption, by (∧E₂) and (∧E₁). In Isabelle you take the same steps in the same order. Each step names a rule; Isabelle applies it to the goal and shows you what is left.
Applying a rule
State the lemma. The name swap_and lets you refer to it later:
lemma swap_and: "A ∧ B ⟶ B ∧ A"proof (prove)
goal (1 subgoal):
1. A ∧ B ⟶ B ∧ Aproof (prove) means that Isabelle is waiting for proof steps. Below it are the subgoals still to be
proved, numbered. At the start there is one: the whole statement.
A subgoal has the form ⋀x₁ … xₖ. ⟦H₁; …; Hₙ⟧ ⟹ C: for arbitrary values of the variables x₁ … xₖ
(Section 7.6), and under the assumptions H₁ … Hₙ, prove the conclusion C. The variables and the
assumptions may be missing. The proof state is the list of subgoals. The proof is complete when the
list is empty.
A subgoal is the goal Γ ⊢ C of Module 6’s backward search (Section 6.7), written in Pure: the assumptions Γ go before ⟹, and the conclusion C after it.
apply (rule r) applies the rule r backwards to subgoal 1. It unifies the conclusion of r with the
conclusion of the subgoal (see “Unification” below), and replaces the subgoal with one new subgoal for
each premise of r. Each new subgoal keeps the assumptions of the old one; a premise of the form P ⟹ Q
adds P to them.
The first step is (⟶I):
apply (rule impI)proof (prove)
goal (1 subgoal):
1. A ∧ B ⟹ B ∧ AimpI is (?P ⟹ ?Q) ⟹ ?P ⟶ ?Q. Its conclusion ?P ⟶ ?Q matches the goal with ?P = A ∧ B and
?Q = B ∧ A, so the new subgoal is the premise, A ∧ B ⟹ B ∧ A. A ∧ B is now an assumption. It is
available in this subgoal and in every subgoal that grows out of it, exactly like the open assumption
[A ∧ B]¹ in the tree.
Next, (∧I):
apply (rule conjI)proof (prove)
goal (2 subgoals):
1. A ∧ B ⟹ B
2. A ∧ B ⟹ AconjI has two premises, so there are now two subgoals, one for each branch of the tree. Both keep the
assumption A ∧ B. The rule and assumption steps used here act on subgoal 1; subgoal 2 waits its turn.
Other methods, such as auto and simp_all, can work on all subgoals (Module 5).
Now (∧E₂), used backwards:
apply (rule conjunct2)proof (prove)
goal (2 subgoals):
1. A ∧ B ⟹ ?P5 ∧ B
2. A ∧ B ⟹ Aconjunct2 is ?P ∧ ?Q ⟹ ?Q. Its conclusion ?Q matches B, so its premise becomes a conjunction whose
right half is B and whose left half is not yet known. Isabelle keeps that left half as a schematic
variable in the new subgoal, ?P5: the variable ?P with the number 5 attached, its index, so that
it cannot clash with other variables (the index has no other meaning). On paper you would look at the assumptions and write A ∧ B at once. Isabelle postpones
the choice until a later step settles it.
Closing a subgoal with an assumption
apply assumption proves subgoal 1 if its conclusion unifies with one of its assumptions. Schematic
variables in the conclusion are instantiated as needed, everywhere in the proof state.
apply assumptionproof (prove)
goal (1 subgoal):
1. A ∧ B ⟹ AUnifying ?P5 ∧ B with the assumption A ∧ B sets ?P5 to A, and the subgoal is closed: that is the leaf
[A ∧ B]¹ of the left branch. The right branch goes the same way with conjunct1, whose premise becomes a
conjunction with A on the left:
apply (rule conjunct1)proof (prove)
goal (1 subgoal):
1. A ∧ B ⟹ A ∧ ?Q7 apply assumptionproof (prove)
goal:
No subgoals!No subgoals are left. done ends the proof:
donedone finishes a proof when no subgoals are left. It does not prove anything itself: if any subgoal
remains, done fails (Section 7.8).
Isabelle has now stored the lemma under its name:
thm swap_and?A ∧ ?B ⟶ ?B ∧ ?AThe free variables A and B have become schematic. swap_and holds for any two formulas, and you can use
it as a rule, like conjI. Figure 7.2 puts the tree and the script side by side.
The tree of A ∧ B ⟶ B ∧ A and its proof script. Each rule step adds one inference to the tree,
starting at the root; each assumption step closes one leaf. The goal after each step lists the
branches that are still open.
The proof state is a to-do list. In these rule-by-rule scripts, apply replaces the first item with
the subgoals of the chosen step; done checks that the list is empty.
Unification
Unification makes two terms identical by choosing values for their schematic variables. Isabelle uses
it whenever it applies a rule: in rule, between the conclusion of the rule and the conclusion of the
subgoal; in assumption, between the conclusion of the subgoal and an assumption. If no choice of values
makes the two terms identical, that application cannot succeed. Isabelle also respects types and
variable scopes, and compares terms modulo bound-variable renaming and lambda conversion; it does
not prove arbitrary arithmetic identities while unifying. Higher-order unification is not a general
decision procedure, so a search need not find every possible instantiation.
| Unify | with | Result |
|---|---|---|
?P ⟶ ?Q |
A ∧ B ⟶ B ∧ A |
?P = A ∧ B and ?Q = B ∧ A |
?P5 ∧ B |
A ∧ B |
?P5 = A |
?P ∧ ?Q |
A ∧ (B ∨ C) |
?P = A and ?Q = B ∨ C |
?P ∨ ?Q |
B ∧ A |
impossible: ∨ is not ∧ |
A ∧ ?Q |
B ∧ A |
impossible: A is not B |
The last row matters. A and B in the goal are not schematic: they are free variables that stand for fixed but arbitrary formulas, and unification never replaces them. That is why the proof works for every A and B. It never used anything about them.
Proving in Isabelle is building the paper tree from the root upwards. rule adds an inference on top of
an open branch, assumption closes a branch at an open assumption, and schematic variables are the parts
of the tree you have not filled in yet.
Using assumptions: erule, drule and frule
In Section 7.3 the conjunction A ∧ B sat among the assumptions, and you reached its parts by working backwards from B and from A, leaving Isabelle to guess ?P5 on the way. On paper you think the other way round: you have A ∧ B, so you take it apart. Elimination and destruction rules are made for that, and Isabelle has three methods that apply them to assumptions.
erule: take an assumption apart
apply (erule r) applies an elimination rule r to an assumption of subgoal 1. It unifies the major
premise of r with an assumption, and the conclusion of r with the conclusion of the subgoal. It removes
that assumption and adds one new subgoal for each of the other premises of r.
With conjE, ⟦?P ∧ ?Q; ⟦?P; ?Q⟧ ⟹ ?R⟧ ⟹ ?R, the effect is to replace an assumption P ∧ Q with the two
assumptions P and Q. The swap proof becomes shorter:
lemma "A ∧ B ⟶ B ∧ A"
apply (rule impI)proof (prove)
goal (1 subgoal):
1. A ∧ B ⟹ B ∧ A apply (erule conjE)proof (prove)
goal (1 subgoal):
1. ⟦A; B⟧ ⟹ B ∧ A apply (rule conjI)proof (prove)
goal (2 subgoals):
1. ⟦A; B⟧ ⟹ B
2. ⟦A; B⟧ ⟹ A apply assumption
apply assumption
doneAfter erule conjE, A and B are separate assumptions, so each half of B ∧ A is closed by assumption
with nothing to guess. This is the usual way to use a conjunction you have.
Proof by cases: disjE
Disjunction elimination, (∨E), is a proof by cases: to use A ∨ B, prove the goal once assuming A and once assuming B. Here is A ∨ B ⟶ B ∨ A from Module 6:
lemma swap_or: "A ∨ B ⟶ B ∨ A"
apply (rule impI)proof (prove)
goal (1 subgoal):
1. A ∨ B ⟹ B ∨ A apply (erule disjE)proof (prove)
goal (2 subgoals):
1. A ⟹ B ∨ A
2. B ⟹ B ∨ AdisjE is ⟦?P ∨ ?Q; ?P ⟹ ?R; ?Q ⟹ ?R⟧ ⟹ ?R. erule matched its major premise with the assumption
A ∨ B and removed it. The two other premises became the two cases, each with its own assumption: [A]²
and [B]² in the tree. In the first case, B ∨ A follows from A by (∨I₂):
apply (rule disjI2)proof (prove)
goal (2 subgoals):
1. A ⟹ A
2. B ⟹ B ∨ A apply assumptionproof (prove)
goal (1 subgoal):
1. B ⟹ B ∨ AThe second case uses (∨I₁):
apply (rule disjI1)proof (prove)
goal (1 subgoal):
1. B ⟹ B apply assumption
donedrule and frule: reason forwards
apply (drule r) applies a destruction rule r forwards. It unifies the major premise of r with an
assumption of subgoal 1 and removes that assumption. Each other premise of r becomes a new subgoal, and
then the original subgoal comes back with the conclusion of r as a new assumption. apply (frule r) does
the same but keeps the assumption it used.
Modus ponens is the typical destruction rule. Module 6 proved (A ⟶ B) ⟶ (B ⟶ C) ⟶ (A ⟶ C) with three (⟶I) steps and two (⟶E) steps:
In Isabelle the three implications become three assumptions, one rule impI for each (⟶I) of the
tree:
lemma imp_chain: "(A ⟶ B) ⟶ (B ⟶ C) ⟶ (A ⟶ C)"
apply (rule impI)proof (prove)
goal (1 subgoal):
1. A ⟶ B ⟹ (B ⟶ C) ⟶ A ⟶ C apply (rule impI)proof (prove)
goal (1 subgoal):
1. ⟦A ⟶ B; B ⟶ C⟧ ⟹ A ⟶ C apply (rule impI)proof (prove)
goal (1 subgoal):
1. ⟦A ⟶ B; B ⟶ C; A⟧ ⟹ CThe assumptions appear in the order of the discharge numbers, [A ⟶ B]¹, [B ⟶ C]² and [A]³, and Isabelle has dropped the parentheses around A ⟶ C because ⟶ groups to the right (Module 2). Now reason forwards, from the leaves of the tree: A and A ⟶ B give B.
apply (drule mp)proof (prove)
goal (2 subgoals):
1. ⟦B ⟶ C; A⟧ ⟹ A
2. ⟦B ⟶ C; A; B⟧ ⟹ Cmp is ⟦?P ⟶ ?Q; ?P⟧ ⟹ ?Q. drule matched its major premise with the first implication among the
assumptions, A ⟶ B, and removed it. The second premise of mp, here A, became subgoal 1: to use A ⟶ B,
you must show A. Subgoal 2 is the original goal with the conclusion B added to the assumptions.
apply assumptionproof (prove)
goal (1 subgoal):
1. ⟦B ⟶ C; A; B⟧ ⟹ CThe same again, with B ⟶ C:
apply (drule mp)proof (prove)
goal (2 subgoals):
1. ⟦A; B⟧ ⟹ B
2. ⟦A; B; C⟧ ⟹ C apply assumption
apply assumption
doneerule impE does the same work as drule mp, since impE is the elimination form of mp; which of the
two you use is a matter of taste.
frule matters when you need an assumption again after using it. A small demonstration: frule conjunct1 adds A but keeps A ∧ B, so that drule conjunct2 can still take B from it.
lemma "A ∧ B ⟶ B ∧ A"
apply (rule impI)
apply (frule conjunct1)proof (prove)
goal (1 subgoal):
1. ⟦A ∧ B; A⟧ ⟹ B ∧ A apply (drule conjunct2)proof (prove)
goal (1 subgoal):
1. ⟦A; B⟧ ⟹ B ∧ A apply (rule conjI)
apply assumption
apply assumption
doneSection 7.6 has a case where frule is useful: a quantified assumption that is needed twice.
Many steps at once: intro and elim
apply (intro r₁ … rₙ) applies the given introduction rules to subgoal 1, then again to the subgoals
that result, for as long as one of them applies. apply (elim r₁ … rₙ) does the same with elimination
rules on assumptions.
lemma "A ∧ B ⟶ B ∧ A"
apply (intro impI conjI)proof (prove)
goal (2 subgoals):
1. A ∧ B ⟹ B
2. A ∧ B ⟹ A apply (elim conjE)proof (prove)
goal (2 subgoals):
1. ⟦A; B⟧ ⟹ B
2. A ∧ B ⟹ A apply assumption
apply (elim conjE)
apply assumption
doneintro applied impI and then conjI, which split the goal; elim took the conjunction apart in
subgoal 1 only. In imp_chain above, apply (intro impI) would replace the three rule impI steps.
Which method when
| Situation | Kind of rule | Method | Example |
|---|---|---|---|
| The conclusion has a connective to break up | introduction | rule |
apply (rule conjI) |
| An assumption has a connective to take apart | elimination | erule |
apply (erule disjE) |
| An assumption gives a new fact | destruction | drule, or frule to keep it |
apply (drule mp) |
| The conclusion is one of the assumptions | none | assumption |
apply assumption |
| Many steps of one kind | introduction or elimination | intro, elim |
apply (intro impI conjI) |
These are customary pairings, not restrictions enforced by the method names. rule can use an
elimination or destruction theorem backwards too, as rule conjunct2 already did. Likewise, erule
can use a theorem such as mp when its first premise and conclusion fit. The methods differ in how
they resolve the theorem against the subgoal and its assumptions.
Look at the subgoal before you look for a rule. If you want to attack the main connective of the
conclusion, apply its introduction rule with rule. If you want to use an assumption, apply the
elimination rule of its connective with erule. Section 7.8 shows what happens when the two are mixed
up.
Negation and falsity
Section 7.1 showed that HOL defines ¬A as A ⟶ False, in the same way as Module 6. The negation rules follow from that definition:
notI,(?P ⟹ False) ⟹ ¬ ?P, is (¬I): to prove ¬A, assume A and derive False.notE,⟦¬ ?P; ?P⟧ ⟹ ?R, is (¬E) when ?R is False, and (¬E) followed by (⊥E) otherwise: from ¬A and A, anything follows.FalseE,False ⟹ ?P, is (⊥E).
You use notE with erule, and its effect is worth remembering: to use an assumption ¬A, prove A.
erule notE removes ¬A, and whatever the conclusion was, it becomes A. Here is
¬(A ∨ B) ⟶ ¬A ∧ ¬B from Module 6:
lemma "¬ (A ∨ B) ⟶ ¬ A ∧ ¬ B"
apply (rule impI)
apply (rule conjI)proof (prove)
goal (2 subgoals):
1. ¬ (A ∨ B) ⟹ ¬ A
2. ¬ (A ∨ B) ⟹ ¬ BTo prove ¬A, assume A and derive False, (¬I²):
apply (rule notI)proof (prove)
goal (2 subgoals):
1. ⟦¬ (A ∨ B); A⟧ ⟹ False
2. ¬ (A ∨ B) ⟹ ¬ BFalse follows from ¬(A ∨ B) once you show A ∨ B, (¬E):
apply (erule notE)proof (prove)
goal (2 subgoals):
1. A ⟹ A ∨ B
2. ¬ (A ∨ B) ⟹ ¬ B apply (rule disjI1)
apply assumptionproof (prove)
goal (1 subgoal):
1. ¬ (A ∨ B) ⟹ ¬ BThe second half is the same with disjI2:
apply (rule notI)
apply (erule notE)
apply (rule disjI2)
apply assumption
doneWhen False itself is among the assumptions, erule FalseE closes the subgoal at once, because FalseE
has no other premises:
lemma "False ⟶ A"
apply (rule impI)proof (prove)
goal (1 subgoal):
1. False ⟹ A apply (erule FalseE)
doneerule uses the first assumption that fits. With several negated assumptions, erule notE takes the
first one, which may not be the one you want. Section 7.7 has a proof where the first one is right, and
Section 7.6 shows how to name the formula you want (Exercise 7.5 needs it).
Quantifiers and fixed variables
∀ and fixed variables
Module 6 proved that a universally quantified conjunction gives two universally quantified formulas:
Some books write this formula ∀x.(P x ∧ Q x) ⟶ (∀x. P x) ∧ (∀x. Q x), with the quantifier applying only
to the bracket after it. In Isabelle, as in Modules 3 and 6, the body of ∀x reaches as far to the right
as possible, so ∀x. (P x ∧ Q x) ⟶ … would put the whole implication inside the quantifier. Put the
parentheses around the quantifier instead: (∀x. P x ∧ Q x) ⟶ ….
lemma "(∀x. P x ∧ Q x) ⟶ (∀x. P x) ∧ (∀x. Q x)"
apply (rule impI)
apply (rule conjI)proof (prove)
goal (2 subgoals):
1. ∀x. P x ∧ Q x ⟹ ∀x. P x
2. ∀x. P x ∧ Q x ⟹ ∀x. Q xSubgoal 1 asks for ∀x. P x, so the next step is (∀I):
apply (rule allI)proof (prove)
goal (2 subgoals):
1. ⋀x. ∀x. P x ∧ Q x ⟹ P x
2. ∀x. P x ∧ Q x ⟹ ∀x. Q xallI, (⋀x. ?P x) ⟹ ∀x. ?P x, replaced the HOL quantifier ∀x with the Pure quantifier ⋀x. The subgoal
now reads: for an arbitrary x, assuming ∀x. P x ∧ Q x, prove P x. The x inside the assumption is bound by
its own ∀ and is a different variable that happens to have the same name. The x after ⋀ is the arbitrary
one; the paper tree calls it a.
A variable bound by ⋀ at the front of a subgoal is a fixed variable; Isabelle also calls it a
parameter. It stands for an arbitrary value: it belongs to its subgoal alone, and unification never
replaces it. allI creates one, and in doing so enforces the eigenvariable condition of (∀I).
Now use the assumption, by (∀E) in its elimination form allE:
apply (erule allE)proof (prove)
goal (2 subgoals):
1. ⋀x. P (?x7 x) ∧ Q (?x7 x) ⟹ P x
2. ∀x. P x ∧ Q x ⟹ ∀x. Q xallE, ⟦∀x. ?P x; ?P ?x ⟹ ?R⟧ ⟹ ?R, replaced the assumption ∀x. P x ∧ Q x with an instance P t ∧ Q t
for a term t that is not chosen yet. Isabelle writes that term as ?x7 x: a schematic variable applied
to the fixed variable x. This records that the term may be built from x, since x was fixed before the
unknown was created.
apply (erule conjE)proof (prove)
goal (2 subgoals):
1. ⋀x. ⟦P (?x7 x); Q (?x7 x)⟧ ⟹ P x
2. ∀x. P x ∧ Q x ⟹ ∀x. Q x apply assumptionproof (prove)
goal (1 subgoal):
1. ∀x. P x ∧ Q x ⟹ ∀x. Q xassumption unified P (?x7 x) with P x, which makes the term x itself: the instance chosen for (∀E) is
the arbitrary x, as the tree uses a in both places. The second half goes the same way. This time it
uses spec, the destruction form of (∀E), through drule:
apply (rule allI)
apply (drule spec)proof (prove)
goal (1 subgoal):
1. ⋀x. P (?x13 x) ∧ Q (?x13 x) ⟹ Q x apply (erule conjE)
apply assumption
done⟹ binds more weakly than ∀. So ∀x. P x ⟹ P x is not a statement about one x: it means
(∀x. P x) ⟹ P x, and the x of the conclusion is a free variable, unrelated to the bound one. The stored
theorem shows it:
lemma all_inst: "∀x. P x ⟹ P x"
apply (erule allE)
apply assumption
done
thm all_inst∀x. ?P x ⟹ ?P ?xThe x of the conclusion has become ?x, a separate schematic variable. Here no harm is done, since the
lemma is (∀E) itself. But if you mean “for every x, P x implies P x”, write ⋀x. P x ⟹ P x or
∀x. P x ⟶ P x.
∃ and the order of steps
exI, ?P ?x ⟹ ∃x. ?P x, is (∃I): to prove ∃x. P x, prove P t for some term t, the witness. Used
backwards, it leaves the witness as an unknown, to be settled later by unification. exE,
⟦∃x. ?P x; ⋀x. ?P x ⟹ ?Q⟧ ⟹ ?Q, is (∃E): to use ∃x. P x, take a new x for which P x holds. Used with
erule, it turns the assumption ∃x. P x into a fixed variable x and an assumption P x.
Module 6’s example swaps the quantifiers of ∃x. ∀y. R x y. Read R x y as “key x opens door y”: a master key opens every door, so every door has a key.
Read from the bottom: (⟶I), then (∀I) with the eigenvariable b, then (∃E) with the eigenvariable a, then (∃I) with the witness a, then (∀E) with the instance b. In Isabelle:
lemma ex_all: "(∃x. ∀y. R x y) ⟶ (∀y. ∃x. R x y)"
apply (rule impI)
apply (rule allI)proof (prove)
goal (1 subgoal):
1. ⋀y. ∃x. ∀y. R x y ⟹ ∃x. R x y apply (erule exE)proof (prove)
goal (1 subgoal):
1. ⋀y x. ∀y. R x y ⟹ ∃x. R x yTwo fixed variables now: y, which allI fixed (the b of the tree), and x, which exE fixed (the a).
apply (rule exI)proof (prove)
goal (1 subgoal):
1. ⋀y x. ∀y. R x y ⟹ R (?x6 y x) yThe witness is an unknown applied to both fixed variables: it may be built from y and from x.
apply (erule allE)proof (prove)
goal (1 subgoal):
1. ⋀y x. R x (?y8 y x) ⟹ R (?x6 y x) y apply assumption
doneassumption made the two sides of ⟹ identical, by taking x as the witness and y as the instance of ∀y.
Fix first, guess later
What if you introduce the existential quantifier before eliminating the other one? Apply exI before
exE:
lemma "(∃x. ∀y. R x y) ⟶ (∀y. ∃x. R x y)"
apply (rule impI)
apply (rule allI)
apply (rule exI)proof (prove)
goal (1 subgoal):
1. ⋀y. ∃x. ∀y. R x y ⟹ R (?x4 y) y apply (erule exE)proof (prove)
goal (1 subgoal):
1. ⋀y x. ∀y. R x y ⟹ R (?x4 y) y apply (erule allE)proof (prove)
goal (1 subgoal):
1. ⋀y x. R x (?y8 y x) ⟹ R (?x4 y) yThe witness is now ?x4 y. It was created when only y was fixed, so it may be built from y but not from
x, which exE fixed afterwards. To close the subgoal, Isabelle would have to make the two sides of ⟹
identical, and that needs the witness to be x. Unification may not do that, so assumption fails:
apply assumption
doneFailed to apply proof method⌂:
goal (1 subgoal):
1. ⋀y x. R x (?y8 y x) ⟹ R (?x4 y) yThis direct rule sequence has blocked the intended assumption step. For this proof, restart with
exE before exI, so that the witness can depend on the named master key:
oopsOn paper, this attempted tree would use the eigenvariable a as an existential witness outside the
scope of its (∃E). That violates the side condition. Isabelle’s refusal to instantiate ?x4 y with
the later fixed x enforces the same scope restriction. This does not prove that no HOL method could
solve the remaining schematic goal: HOL’s choice operator can express a master key without referring
to that local name. The point is the dependency required by this particular rule-by-rule proof.
Fix first, guess later. rule allI and erule exE fix variables; rule exI, erule allE and
drule spec create unknowns. An unknown can only become a term built from variables that were fixed
before it was created, as recorded by its arguments in the displayed subgoal. Context parameters and
constants remain available too. Fixing variables first is a useful strategy for these proofs, rather
than a requirement on every possible HOL proof. This is the advice of Section 6.7, to open existential assumptions first and then choose
instances and witnesses, and Isabelle’s unknowns show why it works.
For a statement that is not valid, no order works. The converse, (∀y. ∃x. R x y) ⟶ (∃x. ∀y. R x y), says that if every door has a key, there is a master key. Section 6.6 gave a countermodel, and Exercise 7.9 lets you watch the attempt get stuck.
Choosing an instance yourself
Unification finds a witness only when the goal shows what it must be. Here it does not:
lemma "∃n::nat. n + n = 6"
apply (rule exI)proof (prove)
goal (1 subgoal):
1. ?n + ?n = 6No assumption fixes ?n, and simp (Module 1) does not solve this equation by searching for a
numerical witness:
apply simp
doneFailed to apply proof method⌂:
goal (1 subgoal):
1. ?n + ?n = 6 oopsName the witness yourself:
lemma "∃n::nat. n + n = 6"
apply (rule_tac x = 3 in exI)proof (prove)
goal (1 subgoal):
1. 3 + 3 = 6 apply simp
doneapply (rule_tac x = t in r) applies the rule r as rule does, after replacing its schematic variable
?x with the term t. Name the variable as thm r shows it, without the question mark, and put t in
quotation marks unless it is a single name or number; several instantiations are separated by and.
erule_tac, drule_tac and frule_tac work in the same way. Alternatively, instantiate the rule with
of (Section 7.2) and apply the result: apply (rule exI[of _ 3]), where _ skips ?P.
Unification can also choose wrongly. Here is a small invariant argument: if every step from a safe state leads to a safe state, and s is safe, then two steps from s lead to a safe state.
lemma "⟦∀x. safe x ⟶ safe (step x); safe s⟧ ⟹ safe (step (step s))"
apply (frule spec)proof (prove)
goal (1 subgoal):
1. ⟦∀x. safe x ⟶ safe (step x); safe s; safe ?x ⟶ safe (step ?x)⟧
⟹ safe (step (step s))The quantified assumption is needed twice, once for each step, so frule spec keeps it while adding an
instance with an unknown ?x. erule impE uses that instance; its premise safe ?x becomes subgoal 1,
which assumption closes with ?x = s:
apply (erule impE)
apply assumptionproof (prove)
goal (1 subgoal):
1. ⟦∀x. safe x ⟶ safe (step x); safe s; safe (step s)⟧
⟹ safe (step (step s))For the second step, the same three methods:
apply (erule allE)
apply (erule impE)
apply assumptionproof (prove)
goal (1 subgoal):
1. ⟦safe s; safe (step s); safe (step s)⟧ ⟹ safe (step (step s))This time assumption had two candidates for safe ?x: safe s and safe (step s). It took the first,
so the unknown became s again, and the proof is stuck: no assumption says safe (step (step s)).
oopsTell Isabelle which instance you want:
lemma safe_twice: "⟦∀x. safe x ⟶ safe (step x); safe s⟧ ⟹ safe (step (step s))"
apply (frule spec)
apply (erule impE)
apply assumption
apply (erule_tac x = "step s" in allE)proof (prove)
goal (1 subgoal):
1. ⟦safe s; safe (step s); safe (step s) ⟶ safe (step (step s))⟧
⟹ safe (step (step s)) apply (erule impE)
apply assumption
apply assumption
doneArguments of this kind, about every state a system can reach, return in Module 13.
Classical reasoning and equality
Proof by contradiction
The explicit natural-deduction rules used so far have intuitionistic counterparts; none is (RAA). This does not make the underlying HOL theory intuitionistic or classify every library fact used by automation as constructive. Module 6 explained that some tautologies cannot be derived without (RAA) (Section 6.5), and A ∨ ¬A, the law of excluded middle, is the standard example. Try it without:
lemma "A ∨ ¬ A"
apply (rule disjI1)proof (prove)
goal (1 subgoal):
1. AA is not provable: nothing is known about A. disjI2 would leave ¬A, which is no better. Abandon the
attempt:
oopsThe way out is (RAA), which in Isabelle is ccontr. Here is the derivation from Section 6.5:
lemma "A ∨ ¬ A"
apply (rule ccontr)proof (prove)
goal (1 subgoal):
1. ¬ (A ∨ ¬ A) ⟹ False(RAA¹): assume the negation, and derive False. The next step is the (¬E) at the bottom of the tree, used backwards:
apply (rule notE)proof (prove)
goal (2 subgoals):
1. ¬ (A ∨ ¬ A) ⟹ ¬ ?P2
2. ¬ (A ∨ ¬ A) ⟹ ?P2To derive False, find a formula ?P2 such that both ¬?P2 and ?P2 hold. This step uses rule notE, not
erule notE, because the assumption ¬(A ∨ ¬A) is needed again further up the tree, and erule would
remove it.
apply assumptionproof (prove)
goal (1 subgoal):
1. ¬ (A ∨ ¬ A) ⟹ A ∨ ¬ ASubgoal 1 unified with the assumption, which set ?P2 to A ∨ ¬A: that is the leaf [¬(A ∨ ¬A)]¹. The rest follows the tree: (∨I₂), (¬I²), (¬E) and (∨I₁).
apply (rule disjI2)
apply (rule notI)proof (prove)
goal (1 subgoal):
1. ⟦¬ (A ∨ ¬ A); A⟧ ⟹ False apply (erule notE)proof (prove)
goal (1 subgoal):
1. A ⟹ A ∨ ¬ A apply (rule disjI1)
apply assumption
doneThe first three steps, rule ccontr, rule notE and assumption, together do the work of a single
rule, classical, (¬ ?P ⟹ ?P) ⟹ ?P: assume the negation of the goal, and prove the goal itself.
lemma "A ∨ ¬ A"
apply (rule classical)proof (prove)
goal (1 subgoal):
1. ¬ (A ∨ ¬ A) ⟹ A ∨ ¬ A apply (rule disjI2)
apply (rule notI)
apply (erule notE)
apply (rule disjI1)
apply assumption
doneThe library has this law already, with the disjuncts the other way round:
thm excluded_middle¬ ?P ∨ ?PA De Morgan law
Of the four directions of De Morgan’s laws, Section 6.5 stated that one needs (RAA): ¬(A ∧ B) ⟶ ¬A ∨ ¬B. The idea: suppose ¬A ∨ ¬B were false. Then A would have to hold, since otherwise ¬A ∨ ¬B would; and B likewise. But A ∧ B contradicts ¬(A ∧ B).
lemma de_morgan_and: "¬ (A ∧ B) ⟶ ¬ A ∨ ¬ B"
apply (rule impI)
apply (rule ccontr)proof (prove)
goal (1 subgoal):
1. ⟦¬ (A ∧ B); ¬ (¬ A ∨ ¬ B)⟧ ⟹ False apply (erule notE)proof (prove)
goal (1 subgoal):
1. ¬ (¬ A ∨ ¬ B) ⟹ A ∧ Berule notE took the first negated assumption, ¬(A ∧ B), and left its opposite, A ∧ B, to prove: the
(¬E) at the bottom of the tree, with [¬(A ∧ B)]¹ as its first premise. Each half of A ∧ B is another
proof by contradiction:
apply (rule conjI)
apply (rule ccontr)proof (prove)
goal (2 subgoals):
1. ⟦¬ (¬ A ∨ ¬ B); ¬ A⟧ ⟹ False
2. ¬ (¬ A ∨ ¬ B) ⟹ B apply (erule notE)
apply (rule disjI1)
apply assumptionproof (prove)
goal (1 subgoal):
1. ¬ (¬ A ∨ ¬ B) ⟹ B apply (rule ccontr)
apply (erule notE)
apply (rule disjI2)
apply assumption
doneThe other three directions of the De Morgan laws need no classical rule; Exercise 7.5 asks you to prove two of them.
Equality
refl, ?t = ?t, is (=I), and subst, ⟦?s = ?t; ?P ?s⟧ ⟹ ?P ?t, is (=E): if s = t and some property
holds of s, it holds of t. The property ?P is a schematic variable of function type, which unification
fills in with a function. Module 6 derived symmetry from these two rules (Section
6.8), with x = s as P x. Written as a rule, from s = t to t = s, the
derivation is:
Here (=E) uses the property “equal to s”: it holds of s, so it holds of t.
lemma "s = t ⟹ t = s"
apply (erule subst)proof (prove)
goal (1 subgoal):
1. s = serule unified the major premise ?s = ?t with the assumption s = t, and the conclusion ?P t with
t = s. For the second, Isabelle had to find a property ?P such that ?P t is t = s. The new subgoal shows
which one it chose: the property “equal to s”, since the remaining premise ?P s has become s = s.
refl proves it:
apply (rule refl)
doneIn everyday proofs you rarely use subst by hand, because the simplifier rewrites with equations
automatically (Module 9). But subst is what such rewriting means in natural deduction.
Equivalence
For ⟷, iffI turns one goal into two implications. Notice how Isabelle prints the goal:
lemma "A ∧ B ⟷ B ∧ A"proof (prove)
goal (1 subgoal):
1. (A ∧ B) = (B ∧ A)On formulas, ⟷ and = are the same, and Isabelle prints both as =. iffI gives the two directions:
apply (rule iffI)proof (prove)
goal (2 subgoals):
1. A ∧ B ⟹ B ∧ A
2. B ∧ A ⟹ A ∧ BEach subgoal is the swap lemma again, without the implication:
apply (erule conjE)
apply (rule conjI)
apply assumption
apply assumption
apply (erule conjE)
apply (rule conjI)
apply assumption
apply assumption
doneTo use an equivalence that you have, iffD1 and iffD2 act like mp in either direction.
When a step fails
Any step can fail, and Isabelle’s messages are short. This section collects the ones you will meet, with their causes and fixes. Isabelle marks the step that failed and shows the proof state it was given. The steps before it are not affected, so you can replace the failing step with another.
Failed to apply proof method
This is the most common message. It means that the method could do nothing with subgoal 1: for rule,
the conclusion of the rule does not unify with the conclusion of the subgoal; for erule, either that or
no assumption fits the rule’s major premise; for drule and frule, no assumption fits the major
premise; for assumption, no assumption unifies with the conclusion. Isabelle shows the proof state it
was given. Here is the early choice of a side that Module 6 warned about (Section 6.4), followed by a
hopeful assumption:
lemma "A ∨ ¬ A"
apply (rule disjI1)
apply assumption
doneFailed to apply proof method⌂:
goal (1 subgoal):
1. AdisjI1 left the subgoal A, which has no assumptions at all, so assumption has nothing to unify with.
Three other causes are common. Each gives the same message, followed by the proof state as it was before
the failing step.
Taking an assumption apart before it is one. In the goal A ∧ B ⟶ B ∧ A, the conjunction A ∧ B is
not an assumption; it is part of the implication, so erule conjE finds nothing to work on:
lemma "A ∧ B ⟶ B ∧ A"
apply (erule conjE)
doneFailed to apply proof method⌂:
goal (1 subgoal):
1. A ∧ B ⟶ B ∧ AApply impI first: it moves A ∧ B into the assumptions.
Expecting assumption to look inside a formula. After impI and conjI, subgoal 1 is A ∧ B ⟹ B. B
is part of the assumption, but it is not the assumption, so assumption fails:
lemma "A ∧ B ⟶ B ∧ A"
apply (rule impI)
apply (rule conjI)
apply assumption
doneFailed to apply proof method⌂:
goal (2 subgoals):
1. A ∧ B ⟹ B
2. A ∧ B ⟹ Aassumption only unifies whole formulas. Take the assumption apart first, with erule conjE.
Using a rule for the wrong connective. disjI1 concludes a disjunction, but the conclusion of the
subgoal A ∧ B ⟹ B ∧ A is a conjunction:
lemma "A ∧ B ⟶ B ∧ A"
apply (rule impI)
apply (rule disjI1)
doneFailed to apply proof method⌂:
goal (1 subgoal):
1. A ∧ B ⟹ B ∧ AWhen in doubt, look the rule up with thm: for rule, its conclusion must unify with the conclusion
of the subgoal. A fixed connective must match, but a schematic conclusion such as ?P can match
different shapes. The rule need not display the goal’s connective before instantiation.
Undefined fact
A misspelt rule name gives a different message. Many rule names end in a capital I, which looks much like a lower-case l:
lemma "A ∧ B ⟶ B ∧ A"
apply (rule impI)
apply (rule conjl)
doneUndefined fact: "conjl"⌂Failed to finish proof
done fails if subgoals remain, and lists them. Take the same early choice as above and write done
straight after it:
lemma "A ∨ ¬ A"
apply (rule disjI1)
doneFailed to finish proof:
goal (1 subgoal):
1. Adone never proves anything itself, not even a subgoal whose conclusion is one of its assumptions. Add
the missing steps or, if the subgoal left is unprovable, as here, go back and choose differently. (A
one-line proof by m, as in by blast, behaves a little differently: after the method m, it closes the
subgoals that are left by assumption, and reports Failed to finish proof only if something else
remains.)
Forgetting done
Without done, the proof is still open when the next command arrives, and the next lemma is refused:
lemma "A ⟶ A"
apply (rule impI)
apply assumption
lemma "B ⟶ B"Bad context for command "lemma"⌂A lemma cannot start inside a proof. Add done after the last apply. If the unfinished proof is the
last one in the theory, end is refused instead, with the message “Illegal application of proof command
in “prove” mode”.
A detour, not an error: rule instead of erule
Some mistakes produce no error at all, only a strange proof state. Applying an elimination rule with
rule instead of erule is the usual one:
lemma "A ∨ B ⟶ B ∨ A"
apply (rule impI)
apply (rule disjE)proof (prove)
goal (3 subgoals):
1. A ∨ B ⟹ ?P2 ∨ ?Q2
2. ⟦A ∨ B; ?P2⟧ ⟹ B ∨ A
3. ⟦A ∨ B; ?Q2⟧ ⟹ B ∨ Arule unified only the conclusion ?R of disjE with B ∨ A. The major premise became subgoal 1, so
Isabelle asks you to prove some disjunction it does not know yet, and the two cases speak of unknown
formulas. apply assumption would repair this by unifying the unknown disjunction with A ∨ B, and the
result would be the erule version with the assumption A ∨ B kept in both cases. Use erule from the
start.
oopsIf something went wrong
- Failed to apply proof method: the rule does not fit subgoal 1, or no assumption fits its major
premise. Check the main connective; use
impIbefore taking an assumption apart; read the rule withthm. - Undefined fact: a misspelt rule name, such as
conjlforconjI. - Failed to finish proof: subgoals remain at
done; they are listed. - Bad context for command “lemma”: the previous proof has no
done. - Inner syntax error … Failed to parse prop: a mistake in the statement itself, such as ⟹ inside a formula (Section 7.1).
- A subgoal that cannot be closed, with unknowns such as
?x4 y: a quantifier rule came too early. Fix variables before you create unknowns (Section 7.6).
Letting Isabelle search: blast and auto
Module 6 ended by letting blast prove its derivations (Section 6.9). You
have now done by hand what blast does automatically. blast belongs to Isabelle’s classical
reasoner, a family of proof methods built on natural-deduction rules. It applies introduction and
elimination rules like the ones in this module: the safe ones of Section 6.7 freely, the others as
choices. When a choice leads nowhere, it can go back and try another, within its search bounds.
It may find a complete proof, fail, or hit a resource limit. The examples below take a single call:
lemma "¬ (A ∧ B) ⟶ ¬ A ∨ ¬ B"
by blast
lemma "(∃x. ∀y. R x y) ⟶ (∀y. ∃x. R x y)"
by blast
lemma "⟦∀x. safe x ⟶ safe (step x); safe s⟧ ⟹ safe (step (step s))"
by blastblast found the instance step s that unification alone got wrong in Section 7.6: when one choice
fails, it tries another. And whatever blast finds, the theorem is built by Isabelle’s kernel from the
rules of the logic. As Module 1 explains, this guarantee concerns ordinary reconstructed proofs,
relative to the theory’s axioms and trusted infrastructure; admissions and oracle methods introduce
different evidence.
When the statement is not valid, blast fails, as Section 6.9 showed for the master key:
lemma "(∀y. ∃x. R x y) ⟶ (∃x. ∀y. R x y)"
by blastFailed to apply initial proof method⌂:
goal (1 subgoal):
1. (∀y. ∃x. R x y) ⟶ (∃x. ∀y. R x y)With by, Isabelle calls the method the initial proof method, so the message says only that blast
found no proof. It does not say whether the statement is false or too hard for blast; nitpick
(Modules 2 and 3) can look for a counterexample. auto behaves differently: it does what it can and
shows you what is left.
lemma "(∀y. ∃x. R x y) ⟶ (∃x. ∀y. R x y)"
apply autoproof (prove)
goal (1 subgoal):
1. ∀y. ∃x. R x y ⟹ ∃x. ∀y. R x y oopsauto turned the implication into an assumption and stopped there. auto combines classical reasoning
with the simplifier, and leaves the subgoals it cannot prove; Module 9 covers it in depth. blast does
not invoke the simplifier and knows little about equality, but Programming and Proving in Isabelle/HOL calls it “the
method of choice for complex logical goals”.
So which should you use? For routine logic, blast or auto. But automation fails often enough, on
goals that are too big or not quite true, and then the manual steps are how you find out why: apply a
few rules by hand, look at the subgoals, and call blast on the pieces, or discover that one of them
cannot be proved. That is why this module did everything by hand first.
A good routine when blast fails: apply the obvious introduction rules with intro (impI, allI,
conjI, …) and take apart the obvious assumptions with elim (conjE, exE, …). Then try blast on
each subgoal. A subgoal that looks false is a hint that the whole statement may be false; try nitpick
on the lemma.
What you learned
- Isabelle has two levels of logic: the meta-logic Pure, with ⟹, ⋀ and ≡, in which rules and goals are written, and the object logic HOL, with ¬ ∧ ∨ ⟶ ∀ ∃ and =, in which formulas are written.
- A rule is a theorem:
thm conjIshows⟦?P; ?Q⟧ ⟹ ?P ∧ ?Q. Schematic variables such as?Pcan be instantiated by terms of the appropriate type and permitted variable dependencies: by unification automatically, or by hand withofandrule_tac. - Each rule of Module 6 has an Isabelle name:
conjI,conjunct1,conjunct2,conjE,disjI1,disjI2,disjE,impI,mp,impE,notI,notE,FalseE,allI,spec,allE,exI,exE,ccontr,classical,reflandsubst. - A proof script builds the paper tree from the root:
rulematches a rule’s conclusion against the goal;erule,druleandfruleresolve rules against assumptions in different ways;assumptioncloses a branch;introandelimrepeat;donechecks that nothing is left. allIandexEcreate fixed variables (⋀x), which enforce the eigenvariable conditions;exI,allEandspeccreate unknowns. Fix first, guess later.- Classical proofs use
ccontr, which is (RAA), orclassical. - The common messages are Failed to apply proof method, Undefined fact, Failed to finish proof and Bad context for command.
blastsearches with the same rules and either succeeds or fails;autoshows what it could not prove.
Exercises
thm impE prints ⟦?P ⟶ ?Q; ?P; ?Q ⟹ ?R⟧ ⟹ ?R.
- Which premise is the major premise?
- Which premise has an assumption of its own, and what is it?
- Draw the rule as a paper rule, in the style of Module 6.
- With which method do you normally use
impE? What does it do to the subgoal ⟦A ⟶ B; A⟧ ⟹ C?
Show solution
-
?P ⟶ ?Q: it contains the connective that the rule eliminates. -
The third,
?Q ⟹ ?R: while proving ?R you may assume ?Q. -
As a paper rule, with the discharged assumption marked:
-
With
erule. It removes the assumption A ⟶ B and leaves two subgoals: prove A, and then prove C with B as an extra assumption.lemma "⟦A ⟶ B; A⟧ ⟹ C" apply (erule impE)proof (prove) goal (2 subgoals): 1. A ⟹ A 2. ⟦A; B⟧ ⟹ CThe first subgoal is closed by
assumption; the second cannot be proved, because C is unrelated to A and B, so abandon the attempt:oops
Write an apply script that follows this tree step by step. Say which command closes which leaf. Then check your script in Isabelle.
Show solution
Two impI steps for (⟶I¹) and (⟶I²), one conjI step for (∧I), and one assumption for each leaf:
lemma "A ⟶ B ⟶ A ∧ B"
apply (rule impI)
apply (rule impI)proof (prove)
goal (1 subgoal):
1. ⟦A; B⟧ ⟹ A ∧ B apply (rule conjI)
apply assumption
apply assumption
doneThe first assumption closes the leaf [A]¹ (subgoal 1 is A), the second closes [B]².
For each subgoal, name the first step you would take (method and rule), and say what is left after it. Then finish each proof in Isabelle.
⟦A; B⟧ ⟹ B ∧ AA ∧ B ⟹ B¬ A ⟹ A ⟶ B∀x. P x ⟹ P cP c ⟹ ∃x. P x
Show solution
rule conjIleaves B and A, each closed byassumption.erule conjEleaves ⟦A; B⟧ ⟹ B, closed byassumption.rule impIleaves ⟦¬ A; A⟧ ⟹ B. Thenerule notEturns the goal into A, closed byassumption.erule allEreplaces the assumption with an instance P t, where t is an unknown, andassumptionsets t to c. (drule specworks too.)rule exIleaves P t to prove, with an unknown witness t, andassumptionsets t to c.
lemma "⟦A; B⟧ ⟹ B ∧ A"
apply (rule conjI)
apply assumption
apply assumption
done
lemma "A ∧ B ⟹ B"
apply (erule conjE)
apply assumption
done
lemma "¬ A ⟹ A ⟶ B"
apply (rule impI)
apply (erule notE)
apply assumption
done
lemma "∀x. P x ⟹ P c"
apply (erule allE)
apply assumption
done
lemma "P c ⟹ ∃x. P x"
apply (rule exI)
apply assumption
doneExercise 6.4 derived these two formulas on paper. Prove them in Isabelle with rule, erule, drule and
assumption:
(A ⟶ B ⟶ C) ⟶ (A ∧ B ⟶ C)(A ∧ B ⟶ C) ⟶ (A ⟶ B ⟶ C)
Show solution
In the first, take the conjunction apart and use the nested implication twice, with drule mp:
lemma "(A ⟶ B ⟶ C) ⟶ (A ∧ B ⟶ C)"
apply (rule impI)
apply (rule impI)
apply (erule conjE)
apply (drule mp)
apply assumption
apply (drule mp)
apply assumption
apply assumption
doneIn the second, erule impE asks you to prove A ∧ B, which conjI splits:
lemma "(A ∧ B ⟶ C) ⟶ (A ⟶ B ⟶ C)"
apply (rule impI)
apply (rule impI)
apply (rule impI)
apply (erule impE)proof (prove)
goal (2 subgoals):
1. ⟦A; B⟧ ⟹ A ∧ B
2. ⟦A; B; C⟧ ⟹ C apply (rule conjI)
apply assumption
apply assumption
apply assumption
doneExercise 6.5 and Section 6.5 derived ¬ A ∨ ¬ B ⟶ ¬ (A ∧ B) and ¬ A ∧ ¬ B ⟶ ¬ (A ∨ B) on paper. Prove
both in Isabelle without ccontr or classical. In the second you will meet the pitfall of Section 7.5:
erule notE takes the first negated assumption. Name the one you want with erule_tac P = B in notE
(the variable of notE is called P).
Show solution
lemma "¬ A ∨ ¬ B ⟶ ¬ (A ∧ B)"
apply (rule impI)
apply (rule notI)
apply (erule conjE)
apply (erule disjE)
apply (erule notE)
apply assumption
apply (erule notE)
apply assumption
doneIn the second law, the case split leaves two subgoals with both ¬A and ¬B among the assumptions:
lemma "¬ A ∧ ¬ B ⟶ ¬ (A ∨ B)"
apply (rule impI)
apply (erule conjE)
apply (rule notI)
apply (erule disjE)proof (prove)
goal (2 subgoals):
1. ⟦¬ A; ¬ B; A⟧ ⟹ False
2. ⟦¬ A; ¬ B; B⟧ ⟹ FalseIn the first case, ¬A is the right one, and it comes first. In the second case, erule notE would take
¬A again and leave A to prove, which is impossible; choose ¬B instead:
apply (erule notE)
apply assumption
apply (erule_tac P = B in notE)proof (prove)
goal (1 subgoal):
1. ⟦¬ A; B⟧ ⟹ B apply assumption
doneIn an access-control policy, every administrator may write. Prove that whoever may not write is not an administrator:
(∀u. admin u ⟶ can_write u) ⟶ (∀u. ¬ can_write u ⟶ ¬ admin u)
Plan the order of the quantifier steps first: which rule fixes a variable, and which creates an unknown?
Show solution
allI fixes u in the conclusion, and allE creates an unknown instance of the assumption. Fix first:
lemma "(∀u. admin u ⟶ can_write u) ⟶ (∀u. ¬ can_write u ⟶ ¬ admin u)"
apply (rule impI)
apply (rule allI)
apply (rule impI)
apply (rule notI)proof (prove)
goal (1 subgoal):
1. ⋀u. ⟦∀u. admin u ⟶ can_write u; ¬ can_write u; admin u⟧ ⟹ False apply (erule allE)
apply (erule impE)
apply assumptionproof (prove)
goal (1 subgoal):
1. ⋀u. ⟦¬ can_write u; admin u; can_write u⟧ ⟹ Falseassumption instantiated the unknown with the fixed u, which is possible because u was fixed first.
apply (erule notE)
apply assumption
doneProve (∃x. P x ∧ Q x) ⟶ (∃x. P x) ∧ (∃x. Q x), which Exercise 6.6 derived on paper. Then explain in a
sentence or two, in terms of fixed variables and unknowns, why the converse,
(∃x. P x) ∧ (∃x. Q x) ⟶ (∃x. P x ∧ Q x), cannot be proved.
Show solution
lemma "(∃x. P x ∧ Q x) ⟶ (∃x. P x) ∧ (∃x. Q x)"
apply (rule impI)
apply (erule exE)
apply (erule conjE)
apply (rule conjI)proof (prove)
goal (2 subgoals):
1. ⋀x. ⟦P x; Q x⟧ ⟹ ∃x. P x
2. ⋀x. ⟦P x; Q x⟧ ⟹ ∃x. Q x apply (rule exI)
apply assumption
apply (rule exI)
apply assumption
doneThe converse is not valid: P could be “is even” and Q “is odd” on the natural numbers. Both have
witnesses, but no number is both. In a proof attempt, the two exE steps fix two different variables,
one with P and one with Q, and the single unknown witness of exI cannot become both: unification never
makes two different fixed variables equal. Different names do not assert different values; rather,
we have no equality that lets us treat these arbitrary witnesses as the same. This is the broken eigenvariable condition of Exercise 6.6 in
Isabelle’s form.
Exercise 6.8 derived Peirce’s law, ((A ⟶ B) ⟶ A) ⟶ A, on paper with (RAA). Turn that derivation into an
apply script with ccontr, following the tree step by step, and say which step does the work of (⊥E).
Then shorten the script with classical.
Show solution
At the bottom of the tree of Exercise 6.8 are (⟶I¹), (RAA²) and (¬E) with the premises [¬A]² and A. As in
Section 7.7, rule ccontr, rule notE and assumption take the last two steps and leave A to prove:
lemma "((A ⟶ B) ⟶ A) ⟶ A"
apply (rule impI)
apply (rule ccontr)
apply (rule notE)
apply assumptionproof (prove)
goal (1 subgoal):
1. ⟦(A ⟶ B) ⟶ A; ¬ A⟧ ⟹ AA comes from the assumption (A ⟶ B) ⟶ A by (⟶E), which needs A ⟶ B:
apply (erule impE)proof (prove)
goal (2 subgoals):
1. ¬ A ⟹ A ⟶ B
2. ⟦¬ A; A⟧ ⟹ ATo prove A ⟶ B, assume A (⟶I³). The goal is then B, and erule notE turns it into A, using ¬A:
apply (rule impI)
apply (erule notE)proof (prove)
goal (2 subgoals):
1. A ⟹ A
2. ⟦¬ A; A⟧ ⟹ AThis single erule notE does the work of both (¬E) and (⊥E) in the tree, because notE concludes any
formula, here B. Both subgoals left are assumptions:
apply assumption
apply assumption
doneWith classical, the three steps after impI become one:
lemma "((A ⟶ B) ⟶ A) ⟶ A"
apply (rule impI)
apply (rule classical)proof (prove)
goal (1 subgoal):
1. ⟦(A ⟶ B) ⟶ A; ¬ A⟧ ⟹ A apply (erule impE)
apply (rule impI)
apply (erule notE)
apply assumption
apply assumption
doneSection 6.7 showed that a backward search for (∀y. ∃x. R x y) ⟶ (∃x. ∀y. R x y) never closes. Watch it happen in Isabelle: apply the quantifier rules in the best order you can find, and show the state where you get stuck. Then explain, with fixed variables and unknowns, why no order can work.
Show solution
Direct introduction of the conclusion’s ∃x uses exI, and it creates the unknown
witness before anything is fixed:
lemma "(∀y. ∃x. R x y) ⟶ (∃x. ∀y. R x y)"
apply (rule impI)
apply (rule exI)
apply (rule allI)
apply (erule allE)
apply (erule exE)proof (prove)
goal (1 subgoal):
1. ⋀y x. R x (?y6 y) ⟹ R ?x2 y oopsTo close the subgoal, R x (?y6 y) and R ?x2 y must become identical. The instance ?y6 y can become y,
because allI fixed y before allE created ?y6. But the witness ?x2 would have to become x, which exE
fixed after exI created ?x2, and that is not allowed. Taking the assumption apart first only moves the
problem: erule allE and erule exE then fix x before the witness is created, so the witness can become
x, but the instance of ∀y is created before allI fixes y, so it cannot become y. One unknown is always
created too early. The y of the conclusion can only be fixed after the witness is created, since its ∀y
lies inside ∃x; and the x of the assumption can only be fixed after the instance is created, since its ∃x
lies inside ∀y.
This is the never-ending search of Section 6.7 in Isabelle’s terms: each new door needs a new key. The formula is not valid (Section 6.6 gives a countermodel), so no order could have worked; the conditions that make Isabelle refuse these unifications are what keep its proofs sound.
Check yourself
⟦A ⟶ B; A⟧ ⟹ B, what does ⟹ say?thm exI prints ?P ?x ⟹ ∃x. ?P x. What does the question mark in ?x mean?of or rule_tac; a later local variable cannot escape through an earlier unknown.A ∨ B ⟹ B ∨ A. Which step performs (∨E) on the assumption, leaving one subgoal per case?erule matches the major premise A ∨ B with the assumption and leaves the two cases. rule disjE leaves three subgoals with unknown formulas.apply (rule allI) the subgoal reads ⋀x. ∀x. P x ∧ Q x ⟹ P x. What is the x after ⋀?allI turns the HOL quantifier into Pure’s ⋀. The fixed variable is what Module 6 called the eigenvariable.⋀y x. R x (?y8 y x) ⟹ R (?x4 y) y, and apply assumption fails. Why?ex_all), but exI came before exE. Fix first, guess later.by blast reports “Failed to apply initial proof method”. What do you know?blast either finds a complete proof or fails. A failure says nothing about truth; use nitpick to look for a counterexample, or apply some rules by hand.