Why structured proofs
In Module 7 you built proofs from apply steps, one rule at a time, and in Module 9 you let automation
prove whole goals at once. Both work, and both have a weakness that shows once a proof grows beyond a few
lines. Here is a proof in the style of Module 7. Read it, and ask yourself what is true after the fourth
step.
The statement is about access control: if every administrator is a member of staff, and there is an
administrator, then there is a member of staff. ∀u. admin u ⟶ staff u reads “for every user u, if u
is an administrator then u is staff”.
lemma "(∀u. admin u ⟶ staff u) ⟶ (∃u. admin u) ⟶ (∃u. staff u)"
apply (rule impI)
apply (rule impI)
apply (erule exE)
apply (rule exI)
apply (erule allE)
apply (erule mp)
apply assumption
doneIsabelle accepts the script. But it records what Isabelle should do, not what is true. Which user
does exI choose? Which assumption does erule allE take apart? The answers are in the proof states,
and the proof states are not in the text: to understand the script you have to replay it in Isabelle and
read the state after every line. The same holds for whoever maintains the proof later. If a change in
the library makes one step leave its subgoals in a different order, a later step fails, far from the
cause, and the script gives no hint of what was intended.
Here is the same theorem proved in Isar:
lemma "(∀u. admin u ⟶ staff u) ⟶ (∃u. admin u) ⟶ (∃u. staff u)"
proof (intro impI)
assume all: "∀u. admin u ⟶ staff u"
assume "∃u. admin u"
then obtain a where "admin a" by blast
with all have "staff a" by blast
then show "∃u. staff u" by blast
qedYou have not met these keywords yet, and you can probably read the proof all the same, because it says what holds at each step. It is the paper proof, line for line: assume that every administrator is staff, and that there is an administrator. Call one of them a. By the first assumption, a is staff. So there is a member of staff.
Isar is Isabelle’s language for such structured proofs; the name stands for Intelligible
semi-automated reasoning. An Isar proof is a text made of statements. Each step claims a fact, and
Isabelle checks that the claim follows, usually with a short call to automation such as by blast.
Three things follow from this design.
- You can read the proof without running it. The facts are in the text, not hidden in proof states.
- A failing step is marked where it fails. Its statement tells you what was meant, so you know what to repair.
- It matches paper proofs. The natural-deduction proofs of Module 6 and the induction proofs of Module 5 turn into Isar almost line for line (Section 10.7).
Isabelle’s own tutorial, Programming and Proving in Isabelle/HOL, recommends Isar for larger proofs,
and the rest of this series writes its longer proofs in it. Apply scripts stay useful for exploring a
goal step by step, and short proofs stay by simp or by auto.
| Apply script | Isar proof | |
|---|---|---|
| Each line says | which method to apply next | which fact holds next |
| To follow it you need | Isabelle, to see each state | the text |
| Its shape | a list of steps | nested blocks, like a program |
An apply script tells Isabelle what to do to the goal. An Isar proof tells the reader what is true at each step, and Isabelle checks every claim.
The shape of an Isar proof
An Isar proof is built from a handful of commands. This section introduces them on small examples from logic, so that you can concentrate on the structure, and then on a first function from programming.
Proof blocks
You know two ways to finish a lemma: a single step by method, and an apply script that ends with
done. Isar adds a third, the proof block:
lemma "statement"
proof method
steps
qedThe method after proof makes the first move on the goal, as apply would. The steps between proof
and qed then prove what is left, and qed closes the block.
A proof block proof m … qed proves the goal stated directly before it. The initial method m turns
the goal into pending goals. The steps inside the block establish facts and solve the pending goals;
qed closes the block once all of them are solved. Every claim inside the block needs a proof of its
own, which is again either a single step by m or a proof block, so blocks nest.
Take the formula you proved by hand in Module 6 and with apply in Module 7: A ∧ B ⟶ B ∧ A. State it:
lemma "A ∧ B ⟶ B ∧ A"proof (prove)
goal (1 subgoal):
1. A ∧ B ⟶ B ∧ AStart the block with the rule for implication from Module 7:
proof (rule impI)proof (state)
goal (1 subgoal):
1. A ∧ B ⟹ B ∧ AThe goal now says: assuming A ∧ B, show B ∧ A. The arrow ⟹ is Isabelle’s own implication, which you met in Module 7. In a paper proof you would now write “Assume A ∧ B”. In Isar too:
assume ab: "A ∧ B"proof (state)
this:
A ∧ B
goal (1 subgoal):
1. A ∧ B ⟹ B ∧ Aassume adds the assumption to the proof and calls it ab. The state lists it under this:, the most
recent fact. The goal has not changed: an assumption proves nothing by itself, it is something you may
use. Now claim the conclusion:
show "B ∧ A"proof (prove)
goal (1 subgoal):
1. B ∧ Ashow states a claim that solves a pending goal. Like a lemma, the claim needs a proof, and the state
shows it as a goal of its own. Prove it with blast, giving it the assumption, and close the block:
using ab by blast
qedusing ab hands the fact ab to blast; Section 10.3.3 explains why you have to. When the proof of
the show succeeds, Isabelle uses the shown fact to solve the pending goal, and qed finds nothing
left to do. This works because ab is the premise A ∧ B of the goal. An assume must match a premise
of the goal: assume something else, and the show at the end fails (Section 10.8).
The first line of every proof state names the mode Isabelle is in, which tells you what may come
next. proof (prove): a claim (lemma, have, show) has been stated, and its proof comes next.
proof (state): you are inside a block and may assume, claim or close it. proof (chain): facts have
been picked up for the next claim (Section 10.3).
Steps on the way: have
A paper proof rarely jumps to its conclusion: it reaches it through intermediate facts. have states
such a fact, with its own proof, and adds it to the proof for later steps. Unlike show, have does not
touch the pending goals.
lemma "A ∧ B ⟶ B ∧ A"
proof (rule impI)
assume ab: "A ∧ B"
have b: "B" using ab by blast
have a: "A" using ab by blast
show "B ∧ A" using b a by blast
qedEach have gets a name, b and a, and the show uses both. The proof reads as on paper: from A ∧ B
we get B, and we get A, so B ∧ A.
Nested blocks and next
The proof of a have or a show can itself be a block. Here the conclusion B ∧ A is proved with the
rule for conjunction, which leaves two goals:
lemma "A ∧ B ⟶ B ∧ A"
proof (rule impI)
assume ab: "A ∧ B"
show "B ∧ A"
proof (rule conjI)proof (state)
goal (2 subgoals):
1. B
2. AEach of the two goals gets its own show:
show "B" using ab by blast
next
show "A" using ab by blast
qed
qedA show may solve any pending goal of its block, not only the first: Isabelle looks for a goal that the
shown fact solves. next separates the proofs of different goals. It closes the current part of the
block and opens a fresh one, so that whatever you assume for one goal is not available for the next.
Here nothing is assumed inside the inner block, so next could be left out. In the case analysis and
induction patterns below (Sections 10.5 and 10.6), use it to separate the case contexts. Figure 10.1
shows the structure of this proof.
The block structure of the nested proof. Each proof … qed opens a block with its own pending goals,
and each show solves one of them. The fact ab, assumed in the outer block, can be used in every block
nested inside it.
Arbitrary values: fix
To prove a statement for all x, a paper proof says “let x be arbitrary” and proves the statement for
that x. This is the rule (∀I) of Module 6. Isar says fix x:
lemma "∀u. admin u ⟶ admin u ∨ staff u"
proofproof (state)
goal (1 subgoal):
1. ⋀u. admin u ⟶ admin u ∨ staff uproof without a method applied the rule for ∀ (Section 10.2.6 lists what it does for each
connective). The goal starts with ⋀u, Isabelle’s own “for every u” from Module 7. Fix such a u and
prove the statement for it:
fix u
show "admin u ⟶ admin u ∨ staff u"
proof
assume a: "admin u"
show "admin u ∨ staff u" using a by blast
qed
qedfix x introduces a fixed variable x, like the variables bound by ⋀ in Module 7: a name for an
arbitrary value, about which the proof knows nothing except its type and the available assumptions.
On leaving the block, Isabelle generalises x and discharges local assumptions: proving P x under
A x establishes ⋀x. A x ⟹ P x, not an unconditional ⋀x. P x.
Lemmas with assumptions: assumes, shows and ?thesis
Statements about programs usually have conditions. Here is a function that every programmer has written
in some form: clamp lo hi x keeps a value x inside the range from lo to hi, as a volume control or a
sensor reading does.
fun clamp :: "int ⇒ int ⇒ int ⇒ int" where
"clamp lo hi x = (if x < lo then lo else if hi < x then hi else x)"consts
clamp :: "int ⇒ int ⇒ int ⇒ int"
Found termination order: "{}"value "clamp 0 100 150"
value "clamp 0 100 (-5)"
value "clamp 0 100 42""100"
:: "int"
"0"
:: "int"
"42"
:: "int"The result is never below lo, provided the range is not empty. A lemma can state the condition
separately, with assumes, and the claim with shows:
lemma clamp_lower:
assumes "lo ≤ hi"
shows "lo ≤ clamp lo hi x"proof (prove)
goal (1 subgoal):
1. lo ≤ clamp lo hi xThe goal shows only the claim. The assumption is available as a fact called assms, the list of all
assumptions of the lemma:
proof -
show ?thesis using assms by simp
qedTwo new things appear here. proof - starts a block without changing the goal: the hyphen is the
method that does nothing. And ?thesis, read “the thesis”, is an abbreviation that Isabelle defines for
every claim: it stands for the statement after shows (or after lemma, have or show), here
lo ≤ clamp lo hi x. It saves you from copying long statements. You can also name each assumption,
assumes order: "lo ≤ hi", or refer to the i-th one as assms(i). The result of the lemma is the
implication lo ≤ hi ⟹ lo ≤ clamp lo hi x, which later proofs use under the name clamp_lower.
A one-step proof works too: using assms by simp directly after the statement. The block form pays off
when the proof needs several steps.
How a block starts
The initial method decides which pending goals the block has to prove. Three forms cover most proofs:
proof (rule r)applies the rule r backwards, asapply (rule r)does, for examplerule impI.proofwith no method applies one standard rule chosen by the main connective of the goal (or, when facts are passed to it, an elimination rule for them; Section 10.5.3).proof -leaves the goal as it is.
For the standard rule, the block then follows the patterns of natural deduction:
| Goal | proof applies |
Inside the block |
|---|---|---|
A ⟶ B |
impI |
assume "A" … show "B" |
A ∧ B |
conjI |
show "A" … next … show "B" |
A ⟷ B |
iffI |
assume "A" … show "B" next assume "B" … show "A" |
¬ A |
notI |
assume "A" … show False |
∀x. P x |
allI |
fix x … show "P x" |
∃x. P x |
exI |
show "P t" for a witness t of your choice |
proof on its own fails when no standard rule fits the goal, for example when the goal is False or an
equation between numbers:
lemma
assumes "A" and "¬ A"
shows False
proof
show False using assms by blast
qedFailed to apply initial proof method:
goal (1 subgoal):
1. FalseThe fix is proof -, which starts the block without applying any rule:
lemma
assumes "A" and "¬ A"
shows False
proof -
show False using assms by blast
qedPassing facts along
The proofs so far handed facts to methods with using. Isar has several ways to pass facts from one
step to the next. They make the flow of a proof visible, as words like “hence” and “from this” do on
paper.
Chaining facts with then
A fact is a proved statement available in a proof: an assumption, the result of have or show, or
a lemma from the library or from your theory. After each step, the fact it produced is called
this. Forward chaining passes facts to the next claim, whose proof method receives them, as
using does.
then chains this into the next claim. A proof in which every step uses the result of the step before
reads like a pipeline:
lemma "A ∧ (A ⟶ B) ⟶ B ∨ C"
proof (rule impI)
assume "A ∧ (A ⟶ B)"
then have "B"proof (chain)
picking this:
A ∧ (A ⟶ B)
proof (prove)
using this:
A ∧ (A ⟶ B)
goal (1 subgoal):
1. BIsabelle prints two states for the last line, one for each command. After then the mode is
proof (chain), and picking this shows the fact being passed. After have "B" the new goal appears,
with the fact it will use listed under using this. In Isabelle/jEdit you see the state of the command
under the cursor. Finish the pipeline:
by blast
then show "B ∨ C" by blast
qedNames, from, with, using and note
A pipeline breaks as soon as a step needs an older fact. from names the facts to pass, so then is
the same as from this. Facts can be referred to by name, or by their statement between the quotes
‹ and ›: ‹A› reads “the fact A” and refers to the fact of the proof whose statement is A.
lemma "A ∧ B ⟶ B ∧ A"
proof (rule impI)
assume ab: "A ∧ B"
from ab have "A" by blast
from ab have "B" by blast
with ‹A› show "B ∧ A" by blast
qedwith ‹A› is short for from ‹A› this: it passes the named fact and the current one, here B.
To type ‹ and › in Isabelle/jEdit, type a back-quote (`) and accept the first completion,
which inserts ‹› with the cursor between the two quotes.
note puts facts into this without proving anything, and can give the group a name:
lemma "A ∧ B ⟶ B ∧ A"
proof (rule impI)
assume ab: "A ∧ B"
from ab have a: "A" by blast
from ab have b: "B" by blast
note both = b aproof (state)
this:
B
A
goal (1 subgoal):
1. A ∧ B ⟹ B ∧ A from both show "B ∧ A" by (rule conjI)
qedThe order of the facts matters here: rule conjI uses the first fact for the left conjunct and the
second for the right one. blast, simp and auto do not assign these positional roles to the facts.
Their search or rewriting can still depend on fact order; there is no general promise that reordering
facts leaves automation’s behaviour unchanged.
| You write | It means |
|---|---|
then |
from this |
with a |
from a this |
have "P" using a |
from a have "P" |
hence |
then have |
thus |
then show |
You will meet hence and thus in older proofs, including the Isabelle tutorial. Isabelle2026 still
accepts them, but its reference manual calls them left-overs from the early history of Isar and
recommends the longer forms, which this series uses.
Passing local facts to methods
In Section 10.2.5 the proof of clamp_lower said using assms. Leave it out:
lemma
assumes "lo ≤ hi"
shows "lo ≤ clamp lo hi x"
by simpFailed to finish proof⌂:
goal (1 subgoal):
1. hi < x ⟶ ¬ x < lo ⟶ lo ≤ hiThe simplifier unfolded clamp and split the ifs, and what remains is the one case that needs the
assumption: when x is above the range, clamp returns hi, and lo ≤ hi is exactly what simp did not
know. The assumption was available as a local fact, but these methods do not automatically use every
local fact. They receive the goal and facts passed with then, from, with or using, and consult
their configured context rules (for simp, the simp rules, including the equation of clamp). A fact
registered with [simp] can therefore be used without being passed explicitly. Premises already inside
the subgoal are also available. Explicit fact passing makes the dependencies of these proofs visible.
Local assumptions and proved facts are available to pass to a method; availability alone does not add them to its input or rule collections. When a step fails, first check that it receives the facts it needs.
Using an existential: obtain
The rule (∃E) of Module 6 says: from ∃x. P x you may introduce a new name a with P a, provided the
conclusion does not mention a. In Isar this is obtain. Look again at the Isar proof of Section 10.1:
assume all: …andassume "∃u. admin u"take the two premises thatproof (intro impI)left.then obtain a where "admin a" by blastintroduces a new fixed variableaand the factadmin a. The proof,by blast, shows that such anaexists, using the chained fact ∃u. admin u.with all have "staff a"passesallandadmin atoblast.then show "∃u. staff u"usesstaff a:ais the witness.
Forget to chain the existential, and obtain cannot be proved:
lemma "(∃u. admin u) ⟶ (∃u. admin u ∨ staff u)"
proof
assume "∃u. admin u"
obtain a where "admin a" by blast
then show "∃u. admin u ∨ staff u" by blast
qedFailed to apply initial proof method⌂:
goal (1 subgoal):
1. (⋀a. admin a ⟹ thesis) ⟹ thesisThe goal in the message is what obtain has to prove: whatever you want to show (thesis), if it
follows from admin a for an arbitrary a, then it holds. blast cannot prove that without the fact
∃u. admin u. Write then obtain, or name the fact and write obtain a where "admin a" using ex by blast
with using after the clause.
Collecting facts: moreover and ultimately
Sometimes a step needs several facts that are proved one after another. Instead of naming each one, you
can collect them: moreover adds the most recent fact, this, to a collection, and ultimately adds
the last one and passes the whole collection to the next claim.
lemma clamp_in_range:
assumes "lo ≤ hi"
shows "lo ≤ clamp lo hi x ∧ clamp lo hi x ≤ hi"
proof -
have "lo ≤ clamp lo hi x" using assms by simp
moreover have "clamp lo hi x ≤ hi" using assms by simp
ultimately show ?thesis by blast
qedThe proof says what a reviewer wants to see: the result is at least lo, it is at most hi, so it lies in the range.
Calculations
Much of mathematics, and much reasoning about programs, is calculation: a chain of equations or inequalities in which each step follows from the one before.
Chains of equations
On paper, you multiply out (a + b)(a + b) like this:
and conclude that the first term equals the last. Isar writes the same chain:
lemma "(a + b) * (a + b) = a * a + 2 * a * b + b * (b :: int)"
proof -
have "(a + b) * (a + b) = a * (a + b) + b * (a + b)" by (rule distrib_right)
also have "… = a * a + a * b + (b * a + b * b)" by (simp add: distrib_left)
also have "… = a * a + 2 * a * b + b * b" by (simp add: algebra_simps)
finally show ?thesis .
qed…reads “the right-hand side of the previous step”. To type it, type three dots...: Isabelle/jEdit offers the symbol …, and the three dots work as well.alsoadds the new step to the chain. Isabelle composes the steps by transitivity: from a = b and b = c it derives a = c.finallycomposes the last step and passes the result, first term = last term, to the next claim..(a single dot) directly uses the passed fact when it matches the claim, without deriving a weaker consequence by logical search. Here the claim is?thesis, the statement of the lemma.
Each step has its own justification: distrib_right is the law (a + b)c = ac + bc, distrib_left the
law a(b + c) = ab + ac, and algebra_simps a collection of laws such as commutativity, which simp
uses to rearrange terms.
A calculation is a chain of steps t₁ R t₂, t₂ R t₃, …, each with its own proof, from which Isabelle
derives t₁ R tₙ by transitivity: a R b and b R c give a R c. In Isar, also extends the chain and
finally ends it; … stands for the right-hand side of the previous step.
Inequalities
Chains may mix =, ≤ and <. The result has the strictest relation of the chain: one < anywhere
makes the whole chain <.
A binary heap is often stored in an array: the node at index i has its left child at index 2i + 1. If i is one of the first n indices, is the child within the first 2n?
lemma heap_child:
fixes i n :: nat
assumes "i < n"
shows "2 * i + 1 < 2 * n"
proof -
have "2 * i + 1 < 2 * i + 2" by simp
also have "… = 2 * (i + 1)" by simp
also have "… ≤ 2 * n" using assms by simp
finally show ?thesis .
qedfixes i n :: nat declares the lemma’s variables with their type, for the whole statement; without
it, Isabelle would not know which kind of numbers i and n are. The chain is < then = then ≤, so the
result is 2 * i + 1 < 2 * n. Only the last step needs the assumption, and only that step is given it.
For these numeric chains, finally produces the strictest relation, and . directly uses that fact.
It does not automatically weaken < to ≤. A weaker claim fails,
even though it follows:
lemma
fixes x y z :: nat
assumes "x < y" and "y ≤ z"
shows "x ≤ z"
proof -
have "x < y" using assms by simp
also have "… ≤ z" using assms by simp
finally show "x ≤ z" .
qedFailed to apply initial proof method:
using this:
x < z
goal (1 subgoal):
1. x ≤ zThe message shows the fact the chain produced (using this: x < z) and the claim. Either claim
x < z, or replace . by a method that can weaken it, here by simp.
Chains with ≥ and > do not work as you might expect. Isabelle reads a ≥ b as b ≤ a, so … stands for
a, not b, and the steps no longer fit together:
lemma
fixes a b c :: nat
assumes "a ≥ b" and "b ≥ c"
shows "a ≥ c"
proof -
have "a ≥ b" using assms by simp
also have "… ≥ c" using assms by simp
finally show "a ≥ c" .
qedVacuous calculation result: (⋀x y. x ≤ y ⟹ a ≤ a) ⟹ b ≤ a
derived as projection (1) from:
b ≤ a
c ≤ aWrite chains from the small end to the big end, with ≤ and <.
Case analysis
Many proofs about programs split into cases: the list is empty or not, the condition of an if holds or
not, the input is below, inside or above a range. In Isar each case gets its own part of the block,
separated by next.
Two cases: true or false
clamp lo hi x should agree with the mathematical description “the maximum of lo and the minimum of hi
and x”. Prove it by cases on the first test of clamp:
lemma clamp_max_min:
assumes "lo ≤ hi"
shows "clamp lo hi x = max lo (min hi x)"
proof (cases "x < lo")proof (state)
goal (2 subgoals):
1. x < lo ⟹ clamp lo hi x = max lo (min hi x)
2. ¬ x < lo ⟹ clamp lo hi x = max lo (min hi x)proof (cases "x < lo") splits the goal into the case where x < lo holds and the case where it does
not. The command case True enters the first case:
case Trueproof (state)
this:
x < lo
goal (2 subgoals):
1. x < lo ⟹ clamp lo hi x = max lo (min hi x)
2. ¬ x < lo ⟹ clamp lo hi x = max lo (min hi x)case True assumes the condition of the case, which the state lists under this:. The state still
lists both pending goals, and the claim to prove is still ?thesis, the statement of the lemma. Shown
under the assumption x < lo, it solves the first goal:
then show ?thesis using assms by simp
next
case False
then show ?thesis using assms by simp
qedWhen you write proof (cases …) or proof (induction …), Isabelle/jEdit also shows a message that
begins Proof outline with cases:, with the skeleton of the rest of the proof. For this lemma it is
Proof outline with cases:
case True
then show ?thesis sorry
next
case False
then show ?thesis sorry
qed
Click on the skeleton and Isabelle/jEdit inserts it into your text. Each sorry marks a proof still to
be written: Isabelle/jEdit accepts it in place of a proof while you work, but a theory that contains
sorry is not proved. Replace every one.
Cases of a datatype
For a list, the cases are the two ways of building one: the empty list [], called Nil, and y # ys,
called Cons. Take a function that returns the first element of a list, or a default value d for the
empty list:
fun first_or :: "'a ⇒ 'a list ⇒ 'a" where
"first_or d [] = d"
| "first_or d (y # ys) = y"The first element of xs @ ys is the first element of xs, unless xs is empty; then it is the first
element of ys:
lemma first_or_append: "first_or d (xs @ ys) = first_or (first_or d ys) xs"
proof (cases xs)proof (state)
goal (2 subgoals):
1. xs = [] ⟹ first_or d (xs @ ys) = first_or (first_or d ys) xs
2. ⋀a list.
xs = a # list ⟹ first_or d (xs @ ys) = first_or (first_or d ys) xs case Nil
then show ?thesis by simp
next
case (Cons z zs)proof (state)
this:
xs = z # zs
goal (1 subgoal):
1. ⋀a list.
xs = a # list ⟹ first_or d (xs @ ys) = first_or (first_or d ys) xscase (Cons z zs) gives names to the head and tail of xs: the state shows the assumption xs = z # zs,
while the goal still uses Isabelle’s own names for them, a and list. Choose names that the lemma does
not use already. case (Cons y ys) would create a second ys, which hides the lemma’s own ys for the
rest of the case, although Isabelle prints both as ys. Finish the case:
then show ?thesis by simp
qedWithout next, the assumption of the first case stays in force in the second:
lemma "first_or d (xs @ ys) = first_or (first_or d ys) xs"
proof (cases xs)
case Nil
then show ?thesis by simp
case (Cons z zs)
then show ?thesis by simp
qedFailed to refine any pending goalThe second show proves its claim under both xs = [] and xs = z # zs, and no pending goal has both
assumptions, so the shown fact solves none of them. Put next between the cases.
Cases from a disjunction
The rule (∨E) of Module 6 proves C from A ∨ B by proving C once from A and once from B. In Isar, pass the
disjunction to proof and give each case its assume. Here a user may read a file if they own it, or if
they are an administrator:
lemma
assumes who: "owner u ∨ admin u"
and owners: "∀v. owner v ⟶ may_read v"
and admins: "∀v. admin v ⟶ may_read v"
shows "may_read u"
using who
proof
assume "owner u"
with owners show ?thesis by blast
next
assume "admin u"
with admins show ?thesis by blast
qedusing who before proof passes the disjunction to the initial method, so proof applies the
elimination rule for ∨ instead of an introduction rule. In both cases ?thesis is the claim of the
lemma, may_read u.
Your own cases: consider
Sometimes the natural cases are neither a datatype nor a single condition. clamp distinguishes three:
x below the range, inside it, or above it. consider states such a split, with a name for each case, and
proves that the cases cover every possibility:
lemma
assumes "lo ≤ hi"
shows "lo ≤ clamp lo hi x ∧ clamp lo hi x ≤ hi"
proof -
consider (below) "x < lo" | (inside) "lo ≤ x" "x ≤ hi" | (above) "hi < x"
by linarith
then show ?thesis
proof cases
case below
then show ?thesis using assms by simp
next
case inside
then show ?thesis by simp
next
case above
then show ?thesis using assms by simp
qed
qedThe proof of consider, here linarith from Module 9, shows that every x falls into one of the three
cases. then show ?thesis proof cases then splits the proof along them, and case inside assumes both
facts of that case. A lemma can state such a split for later use, with obtains in place of shows; in
a proof, consider is the local form.
Induction with named cases
In Module 5 you proved properties of recursive functions with apply (induction xs) and read the base
case and the induction step off the proof state. In Isar, each case of the induction becomes a named part of
the block, and the induction hypothesis becomes a named fact.
The skeleton of an induction
Here is the total of a list of amounts, such as the items of a bill:
fun mysum :: "nat list ⇒ nat" where
"mysum [] = 0"
| "mysum (x # xs) = x + mysum xs"consts
mysum :: "nat list ⇒ nat"
Found termination order: "size_list size <*mlex*> {}"The total of two bills put together is the sum of their totals. Start an induction on xs:
lemma mysum_append: "mysum (xs @ ys) = mysum xs + mysum ys"
proof (induction xs)proof (state)
goal (2 subgoals):
1. mysum ([] @ ys) = mysum [] + mysum ys
2. ⋀a xs.
mysum (xs @ ys) = mysum xs + mysum ys ⟹
mysum ((a # xs) @ ys) = mysum (a # xs) + mysum ysThese are the base case and the induction step of Module 5. The proof outline that Isabelle/jEdit shows names the two cases after the constructors of lists:
Proof outline with cases:
case Nil
then show ?case sorry
next
case (Cons a xs)
then show ?case sorry
qed
Prove the base case, then enter the induction step with names of your choice for the head and the tail:
case Nil
show ?case by simp
next
case (Cons x xs)proof (state)
this:
mysum (xs @ ys) = mysum xs + mysum ys
goal (1 subgoal):
1. ⋀a xs.
mysum (xs @ ys) = mysum xs + mysum ys ⟹
mysum ((a # xs) @ ys) = mysum (a # xs) + mysum yscase (Cons x xs) does three things. It fixes x and xs, your names for the variables the goal calls
a and xs. It assumes the induction hypothesis, which the state shows under this:. And it sets
?case, read “the case”, to the claim of this case:
mysum ((x # xs) @ ys) = mysum (x # xs) + mysum ys. Pass the hypothesis to simp with then:
then show ?case by simp
qedIn a proof by cases or induction, case c enters the case named c, and case (c x y …) also
gives names to its variables. The case assumes its facts, available together under the name c. In an
induction, case also sets ?case to the claim of the case, c.IH is the induction hypothesis
and c.prems are the premises of the claim (Section 10.6.2). In a proof by cases, every case proves
the same claim, ?thesis.
For natural numbers the cases are called 0 and Suc: case 0, then case (Suc n) with the
hypothesis Suc.IH. For a datatype of your own they are named after its constructors.
The induction hypothesis, premises and ?case
A paper proof of the induction step is a calculation that uses the induction hypothesis once. The Isar proof
can say exactly that, with the hypothesis named Cons.IH:
lemma "mysum (xs @ ys) = mysum xs + mysum ys"
proof (induction xs)
case Nil
show ?case by simp
next
case (Cons x xs)
have "mysum ((x # xs) @ ys) = x + mysum (xs @ ys)" by simp
also have "… = x + (mysum xs + mysum ys)" using Cons.IH by simp
also have "… = mysum (x # xs) + mysum ys" by simp
finally show ?case .
qedWhen the claim has a premise, the induction keeps it apart from the hypothesis.
If every item of a bill costs at most m, the total is at most m times the number of items. set xs is
the set of the elements of xs, so ∀x ∈ set xs. x ≤ m says that every item is at most m.
lemma mysum_bound: "(∀x ∈ set xs. x ≤ m) ⟹ mysum xs ≤ length xs * m"
proof (induction xs)
print_casescases:
Nil:
let "?case" = "mysum [] ≤ length [] * m"
assume prems : "∀x∈set []. x ≤ m"
Cons:
fix a_ xs_
let "?case" = "mysum (a_ # xs_) ≤ length (a_ # xs_) * m"
assume IH : "∀x∈set xs_. x ≤ m ⟹ mysum xs_ ≤ length xs_ * m" and
prems : "∀x∈set (a_ # xs_). x ≤ m"print_cases lists the cases with everything they provide: the fixed variables, ?case, the
induction hypothesis under IH and the premise of the claim under prems. The names a_ and xs_,
with a trailing underscore, are hidden: the proof cannot refer to them until case (Cons a xs) gives
them names. Each case receives the premise for its own list, and the hypothesis is the whole
implication for the shorter list xs.
case Nil
then show ?case by simp
next
case (Cons a xs)
have "mysum (a # xs) = a + mysum xs" by simp
also have "… ≤ m + mysum xs" using Cons.prems by simp
also have "… ≤ m + length xs * m" using Cons.IH Cons.prems by simp
also have "… = length (a # xs) * m" by simp
finally show ?case .
qedThe second step needs only the premise: a ≤ m, because a is in the list. The third step needs the
hypothesis, and the hypothesis needs its own premise, that every item of xs is at most m, which again
follows from Cons.prems. So both are passed.
If something went wrong
-
show ?thesisinstead ofshow ?case. In an induction,?thesisis the whole lemma for the original xs, not the claim of the case:lemma "mysum (xs @ ys) = mysum xs + mysum ys" proof (induction xs) case Nil show ?thesis by simp next case (Cons x xs) then show ?case by simp qedFailed to apply initial proof method⌂: goal (1 subgoal): 1. mysum (xs @ ys) = mysum xs + mysum yssimpcannot prove the lemma about an unknown list, so the step fails. Write?case. -
A case name that does not exist. The names come from the constructors, here
NilandCons:lemma "mysum (xs @ ys) = mysum xs + mysum ys" proof (induction xs) case Empty show ?case by simp next case (Cons x xs) then show ?case by simp qedUndefined case: "Empty"⌂The proof outline and
print_casesshow the right names. -
The hypothesis is not passed. Without
then(orusing Cons.IH),simpdoes not see it:lemma "mysum (xs @ ys) = mysum xs + mysum ys" proof (induction xs) case Nil show ?case by simp next case (Cons x xs) show ?case by simp qedFailed to finish proof⌂: goal (1 subgoal): 1. mysum (xs @ ys) = mysum xs + mysum ysThe remaining goal is the induction hypothesis itself: a sure sign that it was not passed.
From paper and apply scripts to Isar
You have now seen the core Isar forms used in this series. This section puts them side by side with the proofs of Modules 5, 6 and 7, so that you can translate in both directions.
A natural-deduction proof
In Module 6 you proved A ∧ B ⟶ B ∧ A with this tree:
In Module 7 you replayed it with apply:
lemma "A ∧ B ⟶ B ∧ A"
apply (rule impI)
apply (erule conjE)
apply (rule conjI)
apply assumption
apply assumption
doneThe Isar proof follows the tree rule by rule. It needs (∧E₁) and (∧E₂) in the form the tree uses them,
from A ∧ B to A and to B: the destruction rules conjunct1 and conjunct2 of Module 7.
thm conjunct1 conjunct2 ?P ∧ ?Q ⟹ ?P
?P ∧ ?Q ⟹ ?Qlemma "A ∧ B ⟶ B ∧ A"
proof (rule impI)
assume ab: "A ∧ B"
from ab have b: "B" by (rule conjunct2)
from ab have a: "A" by (rule conjunct1)
from b a show "B ∧ A" by (rule conjI)
qedEach rule of the tree is one line of the proof (Figure 10.2). The assumption [A ∧ B]¹, which the tree
discharges with (⟶I), is the assume inside the block that rule impI opened. The tree is read from
the leaves down, the Isar text from the top down, and both contain the same steps. The apply script, in
contrast, works backwards from the goal and never states B or A at all.
The natural-deduction tree of Module 6 and its Isar proof. Each rule of the tree, in its colour, is one
step of the Isar text; the discharged assumption [A ∧ B]¹ is the assume.
Writing the rule names is useful for learning. In practice you let Isabelle choose the rule: ..
(two dots) is a proof by one standard rule step, so from ab have "B" .. works as well, and by blast
proves such steps too.
Rule by rule
Every rule of natural deduction has an Isar counterpart. In the table, A, B and C are formulas, and
ab, imp, a, b, na, all, pa and ex are the names of facts A ∧ B, A ⟶ B, A, B, ¬ A,
∀x. P x, P a and ∃x. P x.
| Rule (Module 6) | Apply step (Module 7) | Isar |
|---|---|---|
| (⟶I) | rule impI |
assume "A" … show "B" |
| (⟶E) | erule impE |
from imp a have "B" by (rule mp) |
| (∧I) | rule conjI |
from a b have "A ∧ B" by (rule conjI) |
| (∧E₁), (∧E₂) | erule conjE |
from ab have "A" by (rule conjunct1) |
| (∨I₁) | rule disjI1 |
from a have "A ∨ B" by (rule disjI1) |
| (∨E) | erule disjE |
from ‹A ∨ B› show "C" proof … next … qed |
| (¬I) | rule notI |
assume "A" … show False |
| (¬E) | erule notE |
from na a show False by (rule notE) |
| (∀I) | rule allI |
fix x … show "P x" |
| (∀E) | erule allE |
from all have "P a" by (rule spec) |
| (∃I) | rule exI |
from pa have "∃x. P x" by (rule exI) |
| (∃E) | erule exE |
from ex obtain a where "P a" by blast |
| (RAA) | rule ccontr |
proof (rule ccontr) assume "¬ A" … show False |
spec is the destruction rule for (∀E) (Module 7): from ∀x. P x it gives P x for any x.
An induction
Module 5 proved the sum formula twice: on paper, in the example The sum formula, and in Isabelle, with an apply script. Here are the definition and the script again:
fun sum_upto :: "nat ⇒ nat" where
"sum_upto 0 = 0"
| "sum_upto (Suc n) = sum_upto n + Suc n"lemma "2 * sum_upto n = n * (n + 1)"
apply (induction n)
apply simp
apply simp
doneThe script does not say what the two cases are, or how the step uses the induction hypothesis. The paper proof does: its step is a chain of four equations. The Isar proof repeats that chain line for line:
lemma sum_formula: "2 * sum_upto n = n * (n + 1)"
proof (induction n)
case 0
show ?case by simp
next
case (Suc n)
have "2 * sum_upto (Suc n) = 2 * (sum_upto n + Suc n)" by simp
also have "… = 2 * sum_upto n + 2 * Suc n" by simp
also have "… = n * (n + 1) + 2 * Suc n" using Suc.IH by simp
also have "… = Suc n * (Suc n + 1)" by simp
finally show ?case .
qed| On paper (Module 5) | In Isar |
|---|---|
| Proof by induction on . | proof (induction n) |
| Base case . | case 0, show ?case by simp |
| Let be any number, and assume the IH. | next, case (Suc n) |
| , by sum_upto.2 | have "2 * sum_upto (Suc n) = …" by simp |
| , arithmetic | also have "… = …" by simp |
| , by the IH | also have "… = …" using Suc.IH by simp |
| , arithmetic | also have "… = …" by simp |
| By induction, holds for every . | finally show ?case ., qed |
Isabelle writes n + 1 as Suc n, as in the subgoals of Module 5. Each step is checked on its own, so
the proof shows exactly where the hypothesis is used.
From an apply script to Isar: a recipe
To turn an apply script into Isar, run the script in Isabelle/jEdit and read the proof state after each line. Then write down what the states say, not what the methods do:
- The first steps usually only introduce:
rule impI,rule allI,intro impI. They becomeproof (intro …)orproof, followed byassumefor each premise andfixfor each ⋀-variable that the state then shows. - A step that derives a new fact, such as
drule mporerule conjE, becomes ahavewith that fact as its statement. - The step that finishes the goal becomes
show. - Prove each step with the rule of the apply step, or with automation.
Here is a script in the style of Module 7, for the transitivity of implication:
lemma "(A ⟶ B) ⟶ (B ⟶ C) ⟶ A ⟶ C"
apply (intro impI)
apply (erule mp)
apply (erule mp)
apply assumption
doneAfter intro impI the state has the premises A ⟶ B, B ⟶ C and A and the conclusion C. The first
erule mp works backwards from C to B, the second from B to A. Written forwards, as a reader thinks:
lemma "(A ⟶ B) ⟶ (B ⟶ C) ⟶ A ⟶ C"
proof (intro impI)
assume ab: "A ⟶ B" and bc: "B ⟶ C" and a: "A"
from ab a have b: "B" by (rule mp)
from bc b show "C" by (rule mp)
qedWhen an Isar proof fails
Because every step of an Isar proof is a statement, Isabelle can tell you which step failed and what remained of it. These are the messages you will meet most often; you have seen most of them in this module already.
| Message | Meaning | What to do |
|---|---|---|
Failed to finish proof, or Failed to apply initial proof method, at a by |
The method could not prove this step from the facts it was given. The message shows what remained. | Pass the missing facts (then, using); add a lemma (simp add:); split the step; try sledgehammer (Module 9). |
Failed to apply initial proof method, at proof |
The initial method cannot start, for example no standard rule fits the goal. | Use proof -, or name the rule. |
| Failed to refine any pending goal | The shown fact, under the assumptions of its block, solves no pending goal. | Compare the claim with the goal in the state; check ?case and ?thesis, next, and assumptions that are not premises of the goal. |
| Illegal application of proof command in “prove” mode | A claim has no proof, so the next command comes too early. | Give the claim a proof, by … or proof … qed. |
| Undefined case, Undefined fact | A case or fact name is wrong. | Use the proof outline or print_cases. |
| Vacuous calculation result | The steps of a chain do not fit together. | Write chains with =, ≤ and <. |
The fourth message appears, for example, when a have has no proof:
lemma "A ∧ B ⟶ B ∧ A"
proof (rule impI)
assume ab: "A ∧ B"
have "B"
show "B ∧ A" using ab by blast
qedIllegal application of proof command in "prove" modeAfter have "B" Isabelle is in prove mode and expects a proof; show is not one.
“Failed to refine any pending goal” deserves a closer look, because the step itself succeeded: the claim
was proved, but it does not fit the goal. Isabelle/jEdit warns about this before the proof of the
show has finished, with the message “Local statement fails to refine any pending goal”. Here is the
typical case, a claim that is not the goal:
lemma "A ∧ B ⟶ B ∧ A"
proof (rule impI)
assume "A ∧ B"
then show "A ∧ B" by blast
qedFailed to refine any pending goalTo find out what is wrong, change show into have: if the step is then accepted, the claim is right
and the mismatch is between the claim and the goal. Look at the goal in the state and compare.
A few habits make Isar proofs easier to write and to keep working:
- Write the skeleton first. State the lemma, write
proof …, theassume,fixandshowlines andqed, and let the proof outline fill in cases. Then prove the steps, one at a time. - One idea per step. If a
byneeds a long list of facts or a clever method, put an intermediatehavein between. - Chain what you need and nothing else. Pass a fact where it is used, with
then,withorusing; name it only if it is used further away. - Let automation do the small steps.
simp,blast,autoandlinarithprove the steps; Isar provides the structure that a person reads.
What you learned
- Isar writes proofs as structured text: each step states what is true, and Isabelle checks it. Such proofs can be read without Isabelle, and a failing step is marked where it fails.
- A proof block
proof m … qedstarts with an initial method:proof (rule r),proof(a standard rule for the goal) orproof -(nothing). Inside it,assumetakes a premise,fixan arbitrary value,haveproves an intermediate fact andshowsolves a pending goal.nextseparates the proofs of different goals. - Facts flow from step to step:
thenpassesthis,from apasses named facts,with apasses both,using acomes after the claim,notecollects facts, andmoreover … ultimatelycollects several before using them.henceandthusare old forms ofthen haveandthen show. A method receives the passed facts and can also use its configured context rules and the subgoal’s premises. obtain x where …uses an existential fact, as the rule (∃E) does.- Calculations chain steps with
alsoand end them withfinally;…stands for the previous right-hand side, and.directly uses the fact that the chain produced. For numeric chains mixing=,≤and<, the result has the strictest relation of the chain. - Case analysis uses
proof (cases …)withcase True/case Falseor the constructors of a datatype,considerfor cases of your own, andproofwith a disjunction passed to it. - Induction uses
proof (induction x)withcase Nil,case (Cons x xs),case 0,case (Suc n); inside a case,?caseis its claim,c.IHthe induction hypothesis andc.premsthe premises. - Natural-deduction proofs and apply scripts translate into Isar step by step, and Isabelle’s messages (Failed to finish proof, Failed to refine any pending goal, Undefined case, …) point to the step to repair.
Exercises
Here is a proof about a login check: a user who is not locked out and enters a valid password may log in.
lemma
assumes valid: "valid pw"
and fresh: "¬ locked u"
and policy: "∀p v. valid p ∧ ¬ locked v ⟶ login v p"
shows "login u pw ∧ valid pw"
proof -
from valid fresh have "valid pw ∧ ¬ locked u" by blast
with policy have "login u pw" by blast
then show ?thesis using valid by blast
qed- What is
thisafter the firsthave? - Which facts does
blastreceive in the second step? - What does
?thesisstand for? - Rewrite the second step with
frominstead ofwith.
Show solution
valid pw ∧ ¬ locked u, the fact that this step proved.policyandthis, that is ∀p v. valid p ∧ ¬ locked v ⟶ login v p and valid pw ∧ ¬ locked u:with policyis short forfrom policy this.- The statement after
shows:login u pw ∧ valid pw. from policy ‹valid pw ∧ ¬ locked u› have "login u pw" by blast.
Rewrite this proof without hence, thus and with: use only from with names. Check your version in
Isabelle.
lemma "(A ⟶ B) ∧ A ⟶ B ∨ C"
proof
assume prem: "(A ⟶ B) ∧ A"
hence "A ⟶ B" by blast
with prem have "B" by blast
thus "B ∨ C" by blast
qedShow solution
hence is then have, that is from this have; with prem is from prem this; thus is
from this show. With names for the intermediate facts:
lemma "(A ⟶ B) ∧ A ⟶ B ∨ C"
proof
assume prem: "(A ⟶ B) ∧ A"
from prem have ab: "A ⟶ B" by blast
from prem ab have b: "B" by blast
from b show "B ∨ C" by blast
qedEach of these proofs fails. Say which message Isabelle gives, why, and how to repair the proof.
lemma "A ∧ B ⟶ A"
proof
assume "A ∧ B"
then show "A ∧ B" by blast
qedlemma "(∃x. P x ∧ Q x) ⟶ (∃x. P x)"
proof
assume "∃x. P x ∧ Q x"
obtain a where "P a ∧ Q a" by blast
then show "∃x. P x" by blast
qedlemma "clamp lo hi x ≤ max lo x"
proof (cases "x < lo")
case True
then show ?thesis by simp
case False
then show ?thesis by simp
qedShow solution
- Failed to refine any pending goal. The proof of
A ∧ Bsucceeds, but the pending goal is A (under the assumption A ∧ B). Claim the goal:then show "A" by blast. - Failed to apply initial proof method, at the proof of
obtain, with the goal(⋀a. P a ∧ Q a ⟹ thesis) ⟹ thesis. The existential is not passed toblast. Writethen obtain. - Failed to refine any pending goal, at the second
show: withoutnext, the second case still has the assumption x < lo of the first, so its result fits no pending goal. Insertnextbeforecase False.
lemma "A ∧ B ⟶ A"
proof
assume "A ∧ B"
then show "A" by blast
qed
lemma "(∃x. P x ∧ Q x) ⟶ (∃x. P x)"
proof
assume "∃x. P x ∧ Q x"
then obtain a where "P a ∧ Q a" by blast
then show "∃x. P x" by blast
qed
lemma "clamp lo hi x ≤ max lo x"
proof (cases "x < lo")
case True
then show ?thesis by simp
next
case False
then show ?thesis by simp
qedModule 7 proved A ∨ B ⟶ B ∨ A with erule disjE. Prove it in Isar, with a case split on the assumed
disjunction as in Section 10.5.3. Use blast only for the steps inside the cases.
Show solution
lemma "A ∨ B ⟶ B ∨ A"
proof
assume "A ∨ B"
then show "B ∨ A"
proof
assume "A"
then show "B ∨ A" by blast
next
assume "B"
then show "B ∨ A" by blast
qed
qedThe outer proof applies impI. The inner proof receives the disjunction through then, so it
applies the elimination rule disjE and leaves two goals, one for each case. The steps inside the
cases are (∨I₂) and (∨I₁); by (rule disjI2) and by (rule disjI1) work as well.
Prove (∃x. ∀y. R x y) ⟶ (∀y. ∃x. R x y) in Isar with obtain and fix. Read the formula in words
first: if one x is related to every y, then every y has some x related to it.
Show solution
lemma "(∃x. ∀y. R x y) ⟶ (∀y. ∃x. R x y)"
proof
assume "∃x. ∀y. R x y"
then obtain a where a: "∀y. R a y" by blast
show "∀y. ∃x. R x y"
proof
fix b
from a have "R a b" by (rule spec)
then show "∃x. R x b" by (rule exI)
qed
qedThe proof uses (∃E), (∀I), (∀E) and (∃I) in this order. The same x, here a, works for every y. The converse does not hold: each y may need a different x.
Prove (a + b) * (a - b) = a * a - b * b for integers a and b with a chain of equations, one law per
step, as in Section 10.4.1.
Show solution
lemma
fixes a b :: int
shows "(a + b) * (a - b) = a * a - b * b"
proof -
have "(a + b) * (a - b) = a * (a - b) + b * (a - b)" by (rule distrib_right)
also have "… = (a * a - a * b) + (b * a - b * b)" by (simp add: right_diff_distrib)
also have "… = a * a - b * b" by (simp add: algebra_simps)
finally show ?thesis .
qedright_diff_distrib is the law a(b − c) = ab − ac. The last step uses commutativity, b · a = a · b, so
that the middle terms cancel.
Prove mysum (rev xs) = mysum xs by induction with named cases. Use the lemma mysum_append of
Section 10.6.1 in the induction step, inside a calculation.
Show solution
lemma "mysum (rev xs) = mysum xs"
proof (induction xs)
case Nil
show ?case by simp
next
case (Cons x xs)
have "mysum (rev (x # xs)) = mysum (rev xs @ [x])" by simp
also have "… = mysum (rev xs) + mysum [x]" by (rule mysum_append)
also have "… = mysum xs + x" using Cons.IH by simp
also have "… = mysum (x # xs)" by simp
finally show ?case .
qedThe second step is an instance of mysum_append, with rev xs for xs and [x] for ys; rule finds
the instance. Without the lemma, simp would get stuck at mysum (rev xs @ [x]).
Module 5 defined binary trees and the function mirror, and proved on paper, in the example Mirroring
twice, that mirroring a tree twice gives the tree back. Here are the definitions again:
datatype 'a tree2 = Tip | Node "'a tree2" 'a "'a tree2"
fun mirror :: "'a tree2 ⇒ 'a tree2" where
"mirror Tip = Tip"
| "mirror (Node l x r) = Node (mirror r) x (mirror l)"Prove mirror (mirror t) = t in Isar by induction on t, with named cases. Write the induction step as
a calculation with the three steps of the paper proof. How many induction hypotheses does the induction
step have, and how do you refer to each one?
Show solution
lemma "mirror (mirror t) = t"
proof (induction t)
case Tip
show ?case by simp
next
case (Node l x r)
have "mirror (mirror (Node l x r)) = mirror (Node (mirror r) x (mirror l))" by simp
also have "… = Node (mirror (mirror l)) x (mirror (mirror r))" by simp
also have "… = Node l x r" using Node.IH by simp
finally show ?case .
qedThe cases are named after the constructors, Tip and Node. A node has two subtrees, so the induction
step has two induction hypotheses, one for l and one for r. Node.IH is the list of both; Node.IH(1) is
the one for l and Node.IH(2) the one for r. The first two steps use the second equation of mirror,
the third uses both hypotheses.
filter P xs keeps the elements of xs that satisfy P. Prove length (filter P xs) ≤ length xs by
induction on xs. In the induction step, split on whether P x holds, with a nested proof (cases "P x"),
and use a calculation in the case where it does not.
Show solution
lemma "length (filter P xs) ≤ length xs"
proof (induction xs)
case Nil
show ?case by simp
next
case (Cons x xs)
show ?case
proof (cases "P x")
case True
then show ?thesis using Cons.IH by simp
next
case False
then have "length (filter P (x # xs)) = length (filter P xs)" by simp
also have "… ≤ length xs" by (rule Cons.IH)
also have "… ≤ length (x # xs)" by simp
finally show ?thesis .
qed
qedInside the nested block, ?thesis is the claim of the show it proves, which is the claim of the case.
In the case where P x holds, filter keeps x, and both sides grow by one; the hypothesis does the rest.
Check yourself
then have "B" by blast, what does then do?then is short for from this: the fact produced by the previous step is passed to the method that proves the next claim.have only adds a fact. show claims a statement and, once its proof is finished, uses it to solve a pending goal.also have "… = x + 1", what does … stand for?… abbreviates the right-hand side of the previous fact, so the chain continues from where it stopped.proof fails on the goal False, while proof - works. Why?proof applies a standard introduction rule chosen by the goal. proof - applies no rule, so the steps inside the block have to prove the goal.case (Cons x xs) of a proof by induction xs, what is Cons.IH?Cons.prems holds the premises, and ?case the claim to prove.show. What is the most likely cause?next, ?case and the assumptions.