The automation toolbox
Since Module 1 you have finished proofs with a single word: by simp, by auto, by blast. Each of these
words starts a program that searches for a proof. When it works, it saves you dozens of rule applications.
When it fails, it can leave you puzzled: the goal looked easy, and Isabelle only says that the method failed.
This module opens the toolbox. You will learn how the tools work, what each one is good at, how to steer
them, and what to do when none of them works.
First, a reminder of why it is safe to use tools whose inner workings you do not know in detail. In
Section 1.4 you met the LCF architecture: ordinary completed proofs are built from kernel inferences.
The proof methods here use that route. A search can fail or run for a long time, but its result becomes
a theorem only through checked inferences from the stated assumptions and axioms. Admissions and oracle
configurations bypass this guarantee. Search tools such as find_theorems, Quickcheck and Nitpick do
not themselves prove the goal. Sledgehammer’s reconstructed proofs are checked too, even though it
consults programs outside Isabelle; Section 9.8 shows how.
| Tool | What it does | Good for |
|---|---|---|
simp |
rewrites the goal with equations, from left to right | equations, definitions, functions on lists and numbers |
auto |
simp plus logical reasoning, on every subgoal |
many easy subgoals at once |
blast |
searches for a proof with the rules of logic | logic, sets and relations |
force, fastforce |
logic and rewriting together, on the first subgoal | quantifiers mixed with equations |
linarith, arith, presburger |
prove facts of linear arithmetic | inequalities; even and odd; div and mod by numbers |
find_theorems |
searches the library | finding the lemma you need |
quickcheck, nitpick |
search for counterexamples | testing a claim before you try to prove it |
sledgehammer |
asks external provers, returns a proof that Isabelle checks | goals that follow from a few library lemmas |
A running example: access control
So that every tool has real work to do, this module uses one example throughout. A document-sharing service decides who may do what with each document. For every document it keeps an access-control list (ACL): a list of entries, each of which gives one user one permission.
datatype perm = Read | Write | Admin
type_synonym 'u acl = "('u × perm) list"The datatype perm has three values. type_synonym gives a type a shorter name: 'u acl is the type
('u × perm) list, a list of pairs of a user and a permission. The type variable 'u is the type of
users. The examples below use strings such as ''ann''; Isabelle writes a string with two single quotes on
each side.
fun allows :: "'u acl ⇒ 'u ⇒ perm ⇒ bool" where
"allows [] u p = False"
| "allows (e # es) u p = (e = (u, p) ∨ allows es u p)"
definition grant :: "'u ⇒ perm ⇒ 'u acl ⇒ 'u acl" where
"grant u p es = (u, p) # es"
fun revoke :: "'u ⇒ 'u acl ⇒ 'u acl" where
"revoke u [] = []"
| "revoke u (e # es) = (if fst e = u then revoke u es else e # revoke u es)"allows es u p holds when the list es gives user u permission p, that is, when some entry is the
pair (u, p). grant u p es adds the entry (u, p) at the front. revoke u es removes every entry of
user u: fst e is the first component of the pair e, its user. Notice that grant is a definition
and the other two are defined with fun. The difference matters to the simplifier, as you will see in
Section 9.2. A quick test:
value "allows [(''ann'', Read), (''bob'', Write)] ''bob'' Write""True"
:: "bool"value "revoke ''ann'' (grant ''ann'' Admin [(''bob'', Write), (''ann'', Read)])""[(''bob'', Write)]"
:: "(char list × perm) list"The type in the second answer shows that a string is a list of characters, char list.
Rewriting with the simplifier
Rewriting on paper
The simplifier does one thing: it rewrites. Given an equation l = r, it looks for a part of the goal
that has the shape of l, and replaces that part with the corresponding instance of r. It repeats this
until no equation applies any more. If the goal has become True, it is proved.
Here is a worked example with four equations. The first two are the definition of grant and the second
equation of allows; the other two are laws of logic.
| No. | Equation |
|---|---|
| (1) | grant u p es = (u, p) # es |
| (2) | allows (e # es) u p = (e = (u, p) ∨ allows es u p) |
| (3) | (x = x) = True |
| (4) | (True ∨ P) = True |
Take the goal allows (grant u Read es) u Read: user u may read after being granted read access.
- The subterm
grant u Read eshas the shape of the left side of (1), withuforu,Readforpandesfores. Replace it: the goal becomesallows ((u, Read) # es) u Read. - The whole goal now has the shape of the left side of (2), with
(u, Read)fore. Replace it:(u, Read) = (u, Read) ∨ allows es u Read. - The subterm
(u, Read) = (u, Read)matches (3), with(u, Read)forx:True ∨ allows es u Read. - This matches (4): the goal is
True, and the proof is finished.
Equation (2) never rewrites allows es u Read, because es is not of the form e # es. That part of the
goal stays as it is, but after step 4 it no longer matters.
The variables in an equation are placeholders. In Isabelle’s display of theorems they carry a question
mark, ?u, like the schematic variables of Module 7. To use an equation, the simplifier finds terms for its
variables that make the left side identical to a part of the goal. This is matching. It is unification
from Module 7 in one direction only: the variables of the equation may be instantiated, those of the goal
may not.
A rewrite rule is an equation l = r that is used from left to right only. To rewrite a term with
a set of rules is to replace, again and again, a subterm that is an instance of some left side l by the
same instance of the right side r. A term that no rule can rewrite is in normal form. The simplifier
proves a goal by rewriting it to True.
In logic, l = r and r = l say the same. The simplifier still uses each equation in one direction only,
and that avoids searching both directions. Ordinary rewriting works from the inside out, as Figure 9.1
shows. Congruence rules can control which parts are simplified and under which assumptions: for
example, an if can have its condition simplified first and its branches simplified under that condition.
The simplifier at work on allows (grant u Read es) u Read. At each step the highlighted part is
rewritten with the rule named on the arrow. Inner parts are rewritten before the term around them.
Watching it in Isabelle
You can make Isabelle take the steps of the example one at a time. simp only: r₁ r₂ clears the ordinary
rewrite rules and uses r₁ r₂, together with assumptions and built-in support described in Section 9.2.4:
lemma "allows (grant u Read es) u Read"
apply (simp only: grant_def)proof (prove)
goal (1 subgoal):
1. allows ((u, Read) # es) u Readgrant_def is the theorem that the definition command created: grant ?u ?p ?es = (?u, ?p) # ?es. It
is rule (1). Rule (2) belongs to allows.simps, the equations that fun proved for allows:
apply (simp only: allows.simps)proof (prove)
goal (1 subgoal):
1. (u, Read) = (u, Read) ∨ allows es u ReadEven (u, Read) = (u, Read) is left untouched, because you allowed no rule that applies to it. Rules (3)
and (4) belong to simp_thms, a collection of basic laws of logic:
apply (simp only: simp_thms)
doneproof (prove)
goal:
No subgoals!Where simp rules come from
Plain simp does not take a list of rules. It uses the simp set, a large collection of rules that
grows as theories are loaded:
- the equations of every function defined with
funorprimrec, such asallows.simpsandrevoke.simps; - facts that
datatypeproves: the constructors are different (Read ≠ Write), and a constructor applied to different arguments gives different values, so(x # xs = y # ys) = (x = y ∧ xs = ys); - thousands of library lemmas that carry the attribute
[simp], such asrev (rev xs) = xs; - your own lemmas, when you give them
[simp].
A simp rule is a theorem that the simplifier uses without being told. The simp set is the
collection of all simp rules at a point of a theory. You make a lemma a simp rule by writing [simp] after
its name, or later with declare name [simp]; declare name [simp del] removes it again.
One thing is missing from the list: equations introduced by definition are not simp rules by default, so simp treats
grant as an unknown function:
lemma "allows (grant u Read es) u Read"
by simpFailed to apply initial proof method⌂:
goal (1 subgoal):
1. allows (grant u Read es) u ReadHere “Failed to apply initial proof method” means that simp made no progress on the goal: no applicable
rule unfolds grant or proves the surrounding claim. Tell simp to use the definition, with add::
lemma "allows (grant u Read es) u Read"
by (simp add: grant_def)Why are definitions not simp rules? A definition introduces a new idea, such as “grant a permission”. Once you have proved the properties of the idea that you need, later proofs should use those properties and not the definition. If you change the definition later, only the proofs of the properties have to change. So the usual style is to prove a few laws about a defined function, and make the laws simp rules:
lemma allows_grant [simp]:
"allows (grant u p es) v q = ((u, p) = (v, q) ∨ allows es v q)"
by (simp add: grant_def)From now on simp knows how allows and grant work together, without looking inside grant:
lemma "allows (grant u Read (grant v Write es)) v Write"
by simpTo the simplifier, u = v and v = u are different terms, and no rule in the simp set turns one into the
other. So the order in which you write an equation can decide whether simp succeeds. State
allows_grant with the sides of the equation swapped, and the same proof fails:
lemma "allows (grant u p es) v q = ((v, q) = (u, p) ∨ allows es v q)"
by (simp add: grant_def)Failed to finish proof⌂:
goal (1 subgoal):
1. (u = v ∧ p = q ∨ allows es v q) = (v = u ∧ q = p ∨ allows es v q)The simplifier rewrote both sides as far as it could and was left with u = v ∧ p = q on the left and
v = u ∧ q = p on the right. Write the lemma in the orientation that the definitions produce.
add:, del:, only: and simp_all
You have now seen most of the ways to change the rules that the simplifier uses. Here they are together.
| Method | Uses |
|---|---|
simp |
the simp set and the assumptions of the first subgoal |
simp add: a b |
the simp set, plus the theorems a and b |
simp del: a |
the simp set without a |
simp only: a b |
only a and b, plus the assumptions |
simp_all |
like simp, on every subgoal |
Even with only:, a few built-in helpers stay: the simplifier still closes a goal that has become
trivial, such as t = t, and it may still call linear arithmetic (Section 9.5) to finish a goal.
del: removes a rule for one call, for example a simp rule that rewrites a term into a form you do not
want. Without allows_grant the simplifier is back where it started:
lemma "allows (grant u Read (grant v Write es)) v Write"
by (simp del: allows_grant)Failed to apply initial proof method⌂:
goal (1 subgoal):
1. allows (grant u Read (grant v Write es)) v Writesimp works on the first subgoal only. After induction there are usually several subgoals, and
simp_all simplifies them all. Here is a law that later sections need:
lemma allows_append [simp]:
"allows (es @ fs) u p = (allows es u p ∨ allows fs u p)"
apply (induction es)proof (prove)
goal (2 subgoals):
1. allows ([] @ fs) u p = (allows [] u p ∨ allows fs u p)
2. ⋀a es.
allows (es @ fs) u p = (allows es u p ∨ allows fs u p) ⟹
allows ((a # es) @ fs) u p = (allows (a # es) u p ∨ allows fs u p) apply simp_all
doneIn the second subgoal the simplifier used the induction hypothesis, an assumption of that subgoal, as a rewrite rule. Section 9.3 explains how simp uses assumptions.
To understand the simplifier, start with the oriented rules in the simp set, what you add, and the
assumptions. Built-in solvers and case-splitting rules also contribute. When simp fails, ask which
equation or split it would have needed, and whether you supplied it.
If something went wrong
The two messages of a failed by mean different things:
- “Failed to apply initial proof method”: the method produced no successful initial result. For
simp, it usually means no progress. Often a definition is not unfolded, or a needed lemma is not a simp rule. - “Failed to finish proof”: the method made progress but did not prove the goal. The message shows what is left. Read it: it tells you what the simplifier could not do.
Steering the simplifier
Conditional rewrite rules
Many useful equations hold only under a condition. Revoking u’s entries does not change what another user
v may do, but only if v really is another user:
lemma revoke_other [simp]: "v ≠ u ⟹ allows (revoke u es) v p = allows es v p"
by (induction es) auto
lemma revoke_self [simp]: "allows (revoke u es) u p = False"
by (induction es) autoA conditional rewrite rule has the form H ⟹ l = r, or ⟦H₁; …; Hₙ⟧ ⟹ l = r with several
conditions. Before the simplifier replaces an instance of l by the same instance of r, it tries to prove
the same instance of each condition Hᵢ, by simplification. If it cannot, it does not use the rule.
Two concrete users are different, and the simplifier can prove it:
lemma "allows (revoke ''ann'' es) ''bob'' Read = allows es ''bob'' Read"
by simpTo use revoke_other here, the simplifier had to prove the condition ''bob'' ≠ ''ann''. It did, by
simplifying the condition to True: the two strings differ in their first character. With variables in
place of the names, the condition cannot be proved, and the rule is not used:
lemma "allows (revoke u es) v p = allows es v p"
by simpFailed to apply initial proof method⌂:
goal (1 subgoal):
1. allows (revoke u es) v p = allows es v pThe simplifier is right to stop: the claim is false when v = u.
The conditions of a rule must be simpler than its left side, or the simplifier can run in circles. The rule
Suc n < m ⟹ (n < m) = True is true, but as a simp rule it is useless: to rewrite n < m, the
simplifier must first prove Suc n < m, which the same rule rewrites if it can prove Suc (Suc n) < m,
and so on. The simplifier gives up only after 40 nested attempts, the default of its option
simp_depth_limit, and then leaves n < m as it was.
How simp uses assumptions
By default the simplifier uses the assumptions of a subgoal, the formulas before ⟹, as extra rewrite rules, and it simplifies the assumptions too. It turns each assumption into a rule:
- an equation
t = sis usually used to rewritettos; - a negation
¬ PbecomesP = False, sov ≠ ubecomes(v = u) = False; - any other formula
PbecomesP = True; ∀x. P x ⟶ Q xbecomes the conditional ruleP ?x ⟹ Q ?x = True.
So the false claim above becomes true, and provable by simp, once you add the assumption it needs:
lemma "v ≠ u ⟹ allows (revoke u es) v p = allows es v p"
by simpThe assumption gave the rule (v = u) = False, which proved the condition v ≠ u of revoke_other. The
last kind of assumption in the list is how simp uses a general fact about all users. Suppose that every
user who may write may also read, and that u may write:
lemma "⟦∀w. allows es w Write ⟶ allows es w Read; allows es u Write⟧
⟹ allows es u Read"
by simpThe first assumption became the conditional rule allows es ?w Write ⟹ allows es ?w Read = True. To
rewrite the goal allows es u Read with it, the simplifier had to prove allows es u Write, and the second
assumption, now the rule allows es u Write = True, did that.
Assumptions can also make the simplifier loop. An assumption such as ∀x. f x = g (f (g x)) becomes a
rule that rewrites f x to a term that contains f (g x), which the same rule rewrites again, and so on
for ever. (Isabelle notices simpler cases, such as ∀x. f x = g (f x), and turns them round, but not this
one.) If a goal has such an assumption that the proof does not need, simp (no_asm) ignores the
assumptions of the subgoal. Section 9.8 shows a goal whose own assumptions send the simplifier round in
circles.
Case splits
A goal containing if c then a else b can get stuck when the simplifier cannot determine c or reduce
both branches to the same term. It can then split the goal into two cases, one where c holds and one where it does not,
with this library rule:
thm if_split?P (if ?Q then ?x else ?y) = ((?Q ⟶ ?P ?x) ∧ (¬ ?Q ⟶ ?P ?y))Read ?P as “the rest of the goal around the if”. The simplifier splits ifs automatically. You can
watch it in the proof of a law about revoke, whose definition contains an if:
lemma allows_revoke: "allows (revoke u es) v p = (v ≠ u ∧ allows es v p)"
apply (induction es)
apply simp_allproof (prove)
goal (1 subgoal):
1. ⋀a es.
allows (revoke u es) v p = (v ≠ u ∧ allows es v p) ⟹
(fst a = u ⟶
(v ≠ u ∧ allows es v p) = (v ≠ u ∧ (a = (v, p) ∨ allows es v p))) ∧
(fst a ≠ u ⟶
(a = (v, p) ∨ v ≠ u ∧ allows es v p) =
(v ≠ u ∧ (a = (v, p) ∨ allows es v p)))The base case is proved. In the induction step the simplifier unfolded revoke u (a # es), split the if on
fst a = u into the two implications you see, and used the induction hypothesis. Then it got stuck. To go
on, it would have to conclude from a = (v, p) that fst a = v, and the simplifier does not look inside a
pair variable such as a. auto, which you meet in Section 9.4, first replaces a pair variable by a pair
of two variables, and then finishes:
apply auto
doneA case expression is different: the simplifier does not split it automatically, because for a recursive
datatype that could go on for ever. Here is a function with a case. The first entry with the permission
Admin names the owner of a document, and only the owner may delete it:
fun owner :: "'u acl ⇒ 'u option" where
"owner [] = None"
| "owner (e # es) = (if snd e = Admin then Some (fst e) else owner es)"
definition may_delete :: "'u ⇒ 'u acl ⇒ bool" where
"may_delete u es = (case owner es of None ⇒ False | Some v ⇒ v = u)"The type 'u option has the values None, for no result, and Some v, for the result v. snd e is the
second component of e, its permission. After unfolding the definition, the simplifier gets stuck at the
case:
lemma "may_delete u es = (owner es = Some u)"
apply (simp add: may_delete_def)proof (prove)
goal (1 subgoal):
1. (case owner es of None ⇒ False | Some v ⇒ v = u) = (owner es = Some u)The modifier split: names a rule that splits a case. For a datatype t the rule is called t.split,
so for option it is option.split:
thm option.split?P (case ?option of None ⇒ ?f1.0 | Some x ⇒ ?f2.0 x) =
((?option = None ⟶ ?P ?f1.0) ∧ (∀x2. ?option = Some x2 ⟶ ?P (?f2.0 x2)))The rule turns the case into two implications, one for each constructor, as if_split does for an
if. Read ?f1.0 as the schematic variable named f1 with index 0 (Module 7 explained indexes with
?P5): when a name ends in a digit, Isabelle puts a dot before the index, so that the two cannot run
together. With this rule, the simplifier finishes:
apply (simp split: option.split)
doneThe same works for lists with list.split and for natural numbers with nat.split. These rules split a
case in the conclusion of a goal. A case or an if in an assumption needs the variants option.splits
and if_splits, with an s at the end. With option.split, the case in the assumption stays:
lemma "may_delete u es ⟹ owner es = Some u"
by (simp add: may_delete_def split: option.split)Failed to finish proof⌂:
goal (1 subgoal):
1. case owner es of None ⇒ False | Some v ⇒ v = u ⟹ owner es = Some ulemma "may_delete u es ⟹ owner es = Some u"
by (simp add: may_delete_def split: option.splits)Rules that loop
Nothing guarantees that rewriting stops. The library has the simp rule append_assoc:
(xs @ ys) @ zs = xs @ (ys @ zs). Suppose you added its mirror image, xs @ (ys @ zs) = (xs @ ys) @ zs,
as a simp rule. Then a goal containing es @ (fs @ gs) would be rewritten like this:
The simplifier would never stop. In Isabelle/jEdit the proof keeps running and never finishes. Remove the rule from the text, and Isabelle checks the changed text again.
It is your job to keep the simp set terminating. A rule of thumb: the right side of a simp rule should be
simpler than its left side, and the conditions of a conditional rule simpler than its left side. Never add
both an equation and its mirror image. If you need a simp rule in the other direction for one call, write
simp flip: name: it removes the rule and adds its mirror image, for that call only.
Some useful equations look as if they must loop. Granting two permissions in either order gives the same set of entries, which is an instance of this library rule:
thm insert_commuteinsert ?x (insert ?y ?A) = insert ?y (insert ?x ?A)Used again and again, the rule would swap x and y back and forth. Isabelle recognises such
permutative rules, whose two sides are the same up to the order of the variables, and uses them only
when the result is smaller in a fixed order on terms. So the rule swaps two elements into order, and then
stops:
lemma "insert b (insert a A) = X"
apply (simp only: insert_commute)
oopsproof (prove)
goal (1 subgoal):
1. insert a (insert b A) = XThe goal insert a (insert b A) = X is already in order, so the rule does not apply to it again. Applied
to both sides of an equation, ordered rewriting brings both into the same order:
lemma "set (grant u p (grant v q es)) = set (grant v q (grant u p es))"
by (simp add: grant_def insert_commute)The same idea handles operators that are associative and commutative, such as +, *, ∪ and ∩. With
associativity oriented from left to right and two permutative rules, the simplifier sorts the operands into
a fixed order. For ∪ the three rules, plus one more, are collected under the name Un_ac:
thm Un_ac ?A ∪ ?B ∪ ?C = ?A ∪ (?B ∪ ?C)
?A ∪ (?A ∪ ?B) = ?A ∪ ?B
?A ∪ ?B = ?B ∪ ?A
?A ∪ (?B ∪ ?C) = ?B ∪ (?A ∪ ?C)lemma "C ∪ B ∪ A = X"
apply (simp only: Un_ac)
oopsproof (prove)
goal (1 subgoal):
1. A ∪ (B ∪ C) = XTwo unions with the same operands in any order and grouping reach the same normal form, so their equality
is proved by simp only: Un_ac. The name ac_simps collects such rules for many operators at once.
Tracing
When the simplifier does something unexpected, you can ask it to report every step. Put
using [[simp_trace]] before the method. The double brackets set a configuration option, here for this
proof only:
lemma "allows (grant u Read es) u Read"
using [[simp_trace]] by simpThe trace appears in the Output panel, below the proof state. The build that checks the outputs on these pages does not record traces, so this one was copied from a run of Isabelle2026. For this proof it reads:
[1]SIMPLIFIER INVOKED ON THE FOLLOWING TERM:
allows (grant u Read es) u Read
[1]Applying instance of rewrite rule "allows_grant":
allows (grant ?u1 ?p1 ?es1) ?v1 ?q1 ≡
(?u1, ?p1) = (?v1, ?q1) ∨ allows ?es1 ?v1 ?q1
[1]Rewriting:
allows (grant u Read es) u Read ≡ (u, Read) = (u, Read) ∨ allows es u Read
[1]Applying instance of rewrite rule "simp_thms(6)":
?x1 = ?x1 ≡ True
[1]Rewriting:
(u, Read) = (u, Read) ≡ True
[1]Applying instance of rewrite rule "simp_thms(30)":
True ∨ ?P1 ≡ True
[1]Rewriting:
True ∨ allows es u Read ≡ True
These are the steps of the example in Section 9.2, except that the simplifier used the lemma
allows_grant instead of unfolding grant. Each “Applying instance of rewrite rule” names a rule:
simp_thms(6) is the sixth law in simp_thms. The rule is written with ≡, the equality of Isabelle’s
meta-logic in which rewrite rules are stored, and with its variables numbered (?u1). Each “Rewriting:”
shows the instance that was used: which part of the goal, and what it became. The [1] is the depth.
When the simplifier calls itself to prove the condition of a conditional rule, those steps are marked
[2]; they are hidden unless you also raise the option simp_trace_depth_limit, whose default is 1, for
example with using [[simp_trace, simp_trace_depth_limit = 3]].
A trace can be long. Isabelle/jEdit shows at most 1000 trace messages for a command, then pauses with the
message “Tracing paused. Stop, or continue with next 100, 1000, 10000 messages?”. If that happens with a
small goal, suspect a rule that loops. Remove using [[simp_trace]] when you are done.
Logic and sets: blast, auto and friends
The simplifier rewrites. It never searches: it does not try a step, find that it leads nowhere, and go back
to try another. Many goals need such a search. Which assumption should be used? Which value should an
∃ get? Isabelle’s classical reasoner, which you met with blast in Module 7, answers these
questions by searching. It applies the introduction and elimination rules of natural deduction from
Modules 6 and 7, together with the rules declared for sets and relations, and it backtracks when a choice
fails.
A rule is safe if applying it to a provable goal always leaves provable subgoals, as conjI and impI
do: these are the safe steps of Section 6.7. A rule is unsafe if it might turn a provable goal into an
unprovable one: disjI1 reduces P ∨ Q to P, which may be the wrong choice, and allE must guess a
term for the variable. The classical reasoner applies safe rules freely and unsafe rules only with
backtracking.
To give the classical reasoner real work, extend the running example with roles. In a larger service,
permissions belong to roles and users have roles. Two relations, sets of pairs as in Module 4, describe
this. UR contains (u, r) when user u has role r; RP contains (r, p) when role r grants
permission p. A user has a permission when one of the user’s roles grants it. Isabelle writes this
composition of relations as UR O RP:
thm relcomp_unfold?r O ?s = {(x, z). ∃y. (x, y) ∈ ?r ∧ (y, z) ∈ ?s}blast
blast is a search procedure for first-order logic, the logic of ∀, ∃ and the connectives from
Module 3, with the rules for sets and relations built in. Here is a policy fact: if every role that grants
Write also grants Read, then every user who may write may read.
lemma "⟦∀r. (r, Write) ∈ RP ⟶ (r, Read) ∈ RP; (u, Write) ∈ UR O RP⟧
⟹ (u, Read) ∈ UR O RP"
by blastOn paper the proof needs a role r with (u, r) ∈ UR and (r, Write) ∈ RP, an instance of the ∀ for
that r, and the role r again as the witness for the ∃ hidden in O. blast found all three. Giving
users more roles never takes a permission away:
lemma "UR ⊆ UR' ⟹ UR O RP ⊆ UR' O RP"
by blastIn principle blast is a complete method for first-order logic: if its search had no limit, it would
find a proof of every valid first-order formula. In practice its search is bounded, as Section 6.9
described. It does not invoke the simplifier and has limited equality reasoning, so it often fails on goals that need
definitions unfolded, functions computed or arithmetic:
lemma "allows (grant u Read es) u Read"
by blastFailed to apply initial proof method⌂:
goal (1 subgoal):
1. allows (grant u Read es) u Readblast either proves the goal or fails with this message. It never leaves a partly proved goal behind, so
when it fails it gives you no hint why.
auto
auto combines the two worlds. It simplifies, applies safe rules, and tries a bounded search with unsafe
rules, on every subgoal. It proves the subgoals it can and leaves the rest, simplified, in the proof state.
That makes it good at goals with many easy parts, and at telling you what it could not do. Here is a false
claim about roles: removing the pair (r, p) from RP does not take permission p away from anyone.
lemma "(u, p) ∈ UR O RP ⟹ (u, p) ∈ UR O (RP - {(r, p)})"
apply auto
oopsproof (prove)
goal (1 subgoal):
1. ⋀y. ⟦(u, y) ∈ UR; (y, p) ∈ RP⟧ ⟹ (u, p) ∈ UR O (RP - {(r, p)})auto took the composition apart and left one subgoal, which you can read as a statement about roles. It
is not provable, because the role y that gives u the permission may be r itself. When auto leaves a
subgoal that you think should be easy, read it carefully: it may be false, as here, or it may need a lemma
that auto does not know. Section 9.7 shows how to tell the difference automatically.
force and fastforce
Some goals need search and rewriting at the same time. A storage service keeps every log twice in a row,
so every log in the set A is some list ys followed by itself. Then every log in A has even length:
lemma "⟦∀xs ∈ A. ∃ys. xs = ys @ ys; us ∈ A⟧ ⟹ ∃n. length us = n + n"
by autoFailed to apply initial proof method⌂:
goal (1 subgoal):
1. ⟦∀xs∈A. ∃ys. xs = ys @ ys; us ∈ A⟧ ⟹ ∃n. length us = n + nauto could do nothing with this goal, and blast fails too, because the proof needs the equation
length (ys @ ys) = length ys + length ys in the middle of the search. fastforce combines the search of
the classical reasoner with the simplifier at every step:
lemma "⟦∀xs ∈ A. ∃ys. xs = ys @ ys; us ∈ A⟧ ⟹ ∃n. length us = n + n"
by fastforceforce does the same with a more thorough search. It sometimes succeeds where fastforce fails, and
it can take much longer. Both work on the first subgoal only, and like blast they either prove it or
fail.
clarsimp
clarsimp applies safe rules and the simplifier. Unlike auto, it does not use logic to split a goal
into several subgoals, and it avoids unsafe search. It can finish a goal, but otherwise tidies it so
that you can see what remains. Simplifier splitters can still create multiple subgoals, particularly
when configured to split premises:
lemma "∀u. (u, Write) ∈ UR O RP ⟶ (u, Read) ∈ UR O RP"
apply clarsimp
oopsproof (prove)
goal (1 subgoal):
1. ⋀x y. ⟦(x, y) ∈ UR; (y, Write) ∈ RP⟧ ⟹ (x, Read) ∈ UR O RPclarsimp removed the ∀ and the ⟶, and took apart the assumption (x, Write) ∈ UR O RP into a role
y with two facts about it. What is left is the heart of the problem, and it is not provable: nothing
says that role y grants Read.
| Method | Works on | When it fails |
|---|---|---|
simp, simp_all |
first subgoal; all subgoals | leaves the simplified goal, or fails if nothing changed |
auto |
all subgoals | leaves what it could not prove, or fails if nothing changed |
blast |
first subgoal | fails, with no hint |
force, fastforce |
first subgoal | fails, with no hint |
clarsimp |
first subgoal | leaves a tidied goal (possibly split by simplification), or fails if nothing changed |
auto, force, fastforce and clarsimp accept the simplifier’s modifiers, written simp add: (or
simp: for short), simp del: and split:, because add: alone would be ambiguous. They also accept
rules for the classical reasoner: intro:, elim: and dest:, for introduction, elimination and
destruction rules as in Module 7. So
auto simp add: grant_def, or auto simp: grant_def as Module 4 wrote it, unfolds grant, and
blast intro: r lets blast use a rule r of your own.
Arithmetic
Arithmetic gets its own tools, because neither rewriting nor logical search handles it well. A formula of
linear arithmetic is built from variables, numbers, +, -, =, <, ≤ and the connectives, where
a variable may be multiplied by a number, as in 2 * x, but not by another variable. For such formulas
there are decision procedures: programs that decide, for every formula of the kind, whether it holds,
and prove it if it does.
A storage service gives each user a quota. A new file fits if its size is at most the free space:
lemma "⟦used ≤ quota; new ≤ quota - used⟧ ⟹ used + new ≤ (quota :: nat)"
by linarithlinarith proves goals of linear arithmetic over nat, int and real. Subtraction on nat is
tricky, because 3 - 5 = 0 for natural numbers, and linarith takes care of it by distinguishing the
cases used ≤ quota and quota < used. In fact simp proves this goal too: the simplifier calls a fast but
weaker version of the same procedure. Use linarith when simp and auto leave an arithmetic goal.
linarith combines inequalities by adding multiples of them, as you would to solve a system of
inequalities over the real numbers, plus one rule for whole numbers: from a < b it concludes
a + 1 ≤ b. That is enough for many goals about whole numbers, but not for all of them: for nat and
int, linarith is not a decision procedure. It does not know, for example, that an even number is never
odd. Suppose a load balancer sends requests with even numbers to one server and odd ones to another; no
request should go to both:
lemma "(2::int) * x ≠ 2 * y + 1"
by linarithFailed to apply initial proof method⌂:
goal (1 subgoal):
1. 2 * x ≠ 2 * y + 1presburger decides Presburger arithmetic: linear arithmetic over the integers and natural numbers,
including quantifiers, divisibility by fixed numbers, and div and mod by fixed numbers.
lemma "(2::int) * x ≠ 2 * y + 1"
by presburgerQuantifiers are no obstacle. A file system stores data in blocks of 3 and 5 kilobytes; every amount of at least 8 kilobytes can be made up exactly:
lemma "∀n ≥ 8. ∃a b. n = 3 * a + 5 * (b :: nat)"
by presburgerarith tries linarith first and presburger after it, so it proves all three goals above. Products of
variables are a different matter:
lemma "(x::nat) ≤ y ⟹ x * x ≤ y * y"
by linarithFailed to apply initial proof method⌂:
goal (1 subgoal):
1. x ≤ y ⟹ x * x ≤ y * yauto fails too. The fact is simple, but it lies outside linear arithmetic, and so outside what these
methods decide.
Presburger arithmetic, the first-order theory of the natural numbers with addition, is decidable (Mojżesz Presburger, 1929). With multiplication of variables it is not, not even for single equations: no algorithm decides, for every polynomial equation with integer coefficients, whether it has a solution in whole numbers (Yuri Matiyasevich, 1970, completing work of Martin Davis, Hilary Putnam and Julia Robinson). Over the real numbers, formulas with addition and multiplication are decidable again (Alfred Tarski), although decision procedures can be very expensive on difficult inputs.
A goal such as x ≤ y ⟹ x * x ≤ y * y is true exactly when the opposite, x ≤ y together with
y * y < x * x, has no solution. For whole numbers there is no decision procedure that always answers
every such question about polynomial arithmetic correctly. This does not prevent a proof method from
solving particular nonlinear goals, or a library from supplying useful theorems. Isabelle’s library
contains thousands of proved facts about multiplication. The
next section shows how to find the one you need, and Section 9.8 shows a tool that finds it for you.
Decision procedures need the right type. 2 * x ≠ 2 * y + 1 is false for real numbers (take
x = y + 1/2), so no method can prove it without knowing that x and y are integers. Annotate a type,
as in (2::int), whenever a number could belong to several types.
Searching the library
Even the library loaded by Main contains more than 20,000 theorems, and their names follow conventions
that take a while to learn. find_theorems searches them by shape and by name. Type it in a theory, or
use the Query panel of Isabelle/jEdit: its Find Theorems tab has a Find: field for the same
criteria and an Apply button. A pattern is a term in quotes, with _ for any term:
find_theorems "rev (rev _)"find_theorems
"rev (rev _)"
found 1 theorem(s):
List.rev_rev_ident: rev (rev ?xs) = ?xsThe answer gives the full name, List.rev_rev_ident: the theory and the theorem. You can use it as
rev_rev_ident. For the multiplication goal of Section 9.5, a pattern alone finds too much:
find_theorems (3) "_ * _ ≤ _ * _"find_theorems
"_ * _ ≤ _ * _"
found 31 theorem(s) (3 displayed):
Nat.mult_le_mono1: ?i ≤ ?j ⟹ ?i * ?k ≤ ?j * ?k
Nat.mult_le_mono2: ?i ≤ ?j ⟹ ?k * ?i ≤ ?k * ?j
Nat.Suc_mult_le_cancel1: (Suc ?k * ?m ≤ Suc ?k * ?n) = (?m ≤ ?n)The (3) limits the display to three of the matches. Narrow the search instead. Give the type, and add a
second criterion: monotonicity laws usually have mono in their name. Several criteria must all hold:
find_theorems "(_::nat) * _ ≤ _ * _" name: monofind_theorems
"_ * _ ≤ _ * _"
name: "mono"
found 3 theorem(s):
Nat.mult_le_mono1: ?i ≤ ?j ⟹ ?i * ?k ≤ ?j * ?k
Nat.mult_le_mono2: ?i ≤ ?j ⟹ ?k * ?i ≤ ?k * ?j
Nat.mult_le_mono: ⟦?i ≤ ?j; ?k ≤ ?l⟧ ⟹ ?i * ?k ≤ ?j * ?lmult_le_mono fits: with x ≤ y twice, it gives x * x ≤ y * y. The simplifier can use it as a
conditional rule, and proves both conditions from the assumption:
lemma "(x::nat) ≤ y ⟹ x * x ≤ y * y"
by (simp add: mult_le_mono)The criteria you will use most:
| Criterion | Finds theorems |
|---|---|
"pattern" |
that contain the pattern somewhere |
name: s |
whose name contains s |
simp: "term" |
that are equations whose left side matches the term, so that they could rewrite it |
intro, elim, dest |
that could be applied as such a rule to the current goal (inside a proof) |
- before a criterion |
that do not meet it |
The simp: criterion finds equations that could rewrite a term, including ones that are not currently
registered as simp rules:
find_theorems simp: "set (filter _ _)"find_theorems
simp: "set (filter _ _)"
found 1 theorem(s):
List.set_filter: set (filter ?P ?xs) = {x ∈ set ?xs. ?P x}find_consts finds functions by their type. Which functions turn a list into a set?
find_consts "'a list ⇒ 'a set"find_consts
"'a list ⇒ 'a set"
found 3 constant(s):
BNF_Greatest_Fixpoint.Succ :: "'a list set ⇒ 'a list ⇒ 'a set"
List.coset :: "'a list ⇒ 'a set"
List.list.set :: "'a list ⇒ 'a set"Besides set, the answer contains coset, and a function whose type contains 'a list ⇒ 'a set as a
part: find_consts also matches types inside larger ones.
Use _ in patterns, not variable names. In a pattern, xs is not a placeholder: it matches only the
variable xs itself, and library theorems are stated with variables of their own. Write "rev (rev _)",
not "rev (rev xs)". For an operator, give a whole term such as "_ * _", not the symbol * alone.
Counterexamples: Quickcheck and Nitpick
Trying to prove a false statement wastes time, and automation fails on false statements without saying that they are false. So test a claim before you try to prove it. Isabelle has two counterexample finders, Quickcheck (Module 1) and Nitpick (Modules 2 and 3). With the default settings, Isabelle/jEdit tries Quickcheck automatically on new goals; this background check can be disabled. The examples here call the tools explicitly, as you can too.
Quickcheck
Quickcheck turns the claim into a program and runs it on many values of its free variables. By default it tries all values up to a small size, systematically. Here is a claim that sounds reasonable: whoever may write may also read.
lemma "allows es u Write ⟹ allows es u Read"
quickcheck
oopsTesting conjecture with Quickcheck-exhaustive...
Quickcheck found a counterexample:
es = [(a1, Write)]
u = a1The counterexample is a list with a single entry. a₁ is a value of the user type 'u, about which
Quickcheck knows nothing else. A user who is granted only Write may write and not read. The claim is not a
law of ACLs: it is a property that some ACLs have and others lack. Exercise 9.8 turns it into an invariant.
Quickcheck takes options in square brackets:
| Option | Effect |
|---|---|
quickcheck [random] |
tests random values instead of all small ones |
quickcheck [exhaustive] |
tests all values up to the size bound (the default) |
quickcheck [size = 5] |
sets the size bound for the values tested |
quickcheck [timeout = 30] |
stops after 30 seconds |
quickcheck [expect = counterexample] |
reports an error unless a counterexample is found; also no_counterexample |
lemma "allows es u Write ⟹ allows es u Read"
quickcheck [random]
oopsTesting conjecture with Quickcheck-random...
Quickcheck found a counterexample:
es = [(a1, Write)]
u = a1When a claim involves a function’s result, Quickcheck also shows the values of the terms involved. Does revoking a user’s entries after a grant give back the original list?
lemma "revoke u (grant u p es) = es"
quickcheck
oopsTesting conjecture with Quickcheck-exhaustive...
Quickcheck found a counterexample:
u = a1
p = Read
es = [(a1, Read)]
Evaluated terms:
revoke u (grant u p es) = []The list already contained an entry of user a₁, and revoke removed that one too. On a true claim
Quickcheck reports that it found nothing:
lemma "allows (revoke u es) v p = (v ≠ u ∧ allows es v p)"
quickcheck
oopsTesting conjecture with Quickcheck-exhaustive...
Quickcheck found no counterexample.That is evidence, not proof: Quickcheck tried small values only.
Nitpick
Nitpick works differently. It looks for a finite model that makes the claim false: a small finite type for each type variable and values for the free variables. It translates the problem into propositional logic and hands it to a SAT solver. Because it reasons about sets, relations and quantifiers directly, it is good at the claims that Quickcheck finds hard to run.
A claim about roles: if role r grants Read, then after taking r away from user u, the user can no
longer read.
lemma "(r::'r, Read) ∈ RP ⟹ (u::'u, Read) ∉ (UR - {(u, r)}) O RP"
nitpick [card 'u = 1, card 'r = 2]
oopsNitpicking formula...
Nitpick found a counterexample for card 'r = 2 and card 'u = 1:
Free variables:
RP = {(r1, Read), (r2, Read)}
UR = {(u1, r1)}
r = r2
u = u1The option card 'r = 2 tells Nitpick to try a type 'r with exactly two elements. Without the option
it tries sizes 1 to 10 in parallel, and the size of the counterexample it reports can change from run to
run. Even with the option, your run may show a different counterexample. Nitpick names the elements of each
type after the type: u₁ is a user, r₁ and r₂ are roles. Read the counterexample: both roles grant
Read, and user u₁ has role r₁. The claim takes role r₂ away from u₁, but u₁ can still read
through r₁. The claim forgot that a user may get a permission from another role. Add the assumption that
no other role of u grants Read, and Nitpick finds nothing; blast then proves the claim:
lemma "⟦(r::'r, Read) ∈ RP; ∀r'. (u::'u, r') ∈ UR ∧ (r', Read) ∈ RP ⟶ r' = r⟧
⟹ (u, Read) ∉ (UR - {(u, r)}) O RP"
nitpick [card 'u = 1, card 'r = 2]Nitpicking goal:
⟦(r, Read) ∈ RP; ∀r'. (u, r') ∈ UR ∧ (r', Read) ∈ RP ⟶ r' = r⟧
⟹ (u, Read) ∉ (UR - {(u, r)}) O RP
Nitpick found no counterexample by blastA counterexample from Nitpick is genuine when Nitpick has checked that it really falsifies the claim.
For claims about infinite types such as nat, it may report a counterexample as potentially
spurious: the finite approximation may not correspond to any counterexample in the intended types.
Treat those as hints to investigate. “No counterexample” is not a
proof either: there may be a counterexample larger than the sizes Nitpick tried. On claims about
recursive functions on lists, Nitpick often runs out of time; Quickcheck is the better tool there.
| Quickcheck | Nitpick | |
|---|---|---|
| Method | runs the claim as a program on many values | searches for a finite model with a SAT solver |
| Strong on | functions on lists and numbers | sets, relations, quantifiers |
| Needs | executable definitions for the tested claim | supported encodings; infinite types and some constructs require approximations |
| Runs automatically in jEdit | yes | no (it can be turned on) |
| Main option | size |
card |
Sledgehammer
The goal x * x ≤ y * y from Section 9.5 needed the lemma mult_le_mono. Finding it with find_theorems
took some thought. Sledgehammer searches for you. It hands the goal, together with up to about a
thousand library facts that look relevant, to several automatic theorem provers that run outside
Isabelle. If one of them finds a proof, Sledgehammer turns it into a one-line Isabelle proof that you can
paste into your theory.
From a goal to a checked proof. Sledgehammer selects facts, translates the problem for external provers and reconstructs a proof from the facts that a prover used. Only the last step, checked by the kernel, makes a theorem.
The provers come with Isabelle (Module 1): E, Vampire, Zipperposition and SPASS are automatic theorem
provers for first-order and higher-order logic; cvc5, veriT and Z3 are SMT solvers, which also know
arithmetic. Isabelle2026 also runs some of its own proof methods, such as metis and auto, as further
“provers”. Nobody needs to trust the external programs or the translation, because their answers are only
used to construct a proof that the kernel checks:
metisis a proof method inside Isabelle that searches for a first-order proof from a short list of facts. Searching with three facts is far easier than with thousands, and every step goes through the kernel.smtsends the problem to an SMT solver and replays the solver’s proof, step by step, inside Isabelle.- When an ordinary method such as
simporautoworks with the facts found, Sledgehammer suggests it.
Write sledgehammer where the next proof step would go:
lemma "(x::nat) ≤ y ⟹ x * x ≤ y * y"
sledgehammerSledgehammering...
metis found a proof...
metis: Try this: by (metis mult_le_mono mult_le_mono1) (82 ms)
cvc5 found a proof...
cvc5: Try this: by (simp add: mult_le_mono) (1 ms)
vampire found a proof...
vampire: Try this: by (simp add: mult_mono') (4 ms)
spass found a proof...
verit found a proof...
verit: Duplicate proof
zipperposition found a proof...
e found a proof...
e: Duplicate proof
zipperposition: Try this: using mult_le_mono by blast (1 ms)
spass: Try this: using mult_le_mono by presburger (1 ms)
DoneRead the output from the top. “Sledgehammering...” means that the provers have started. Each
“… found a proof...” comes from one prover. That prover’s suggestion follows, at once or a few lines
later, as “prover: Try this: …”, with the time the suggested proof took to check in parentheses.
“Duplicate proof” means that a prover found a proof that was already suggested. “Done” means that all provers have finished. In Isabelle/jEdit you click a
suggestion to insert it. Choose a short and fast one, and replace the sledgehammer line with it. Here
cvc5’s suggestion is the proof you found by hand in Section 9.6:
by (simp add: mult_le_mono)Whichever suggestion you choose, the proof is carried out by an Isabelle method, simp here, and the kernel
checks every step. The sledgehammer command itself proves nothing: delete it once you have a proof.
Sledgehammer is at its best when a goal follows from a few library facts in a way that the other methods
miss. Two segments of a log that commute and have the same length are equal:
⟦es @ fs = fs @ es; length es = length fs⟧ ⟹ es = fs. blast fails on this goal, and simp and auto
do worse: they run until Isabelle runs out of memory. The simplifier rewrites the first assumption with
the library’s simp rule append_eq_append_conv, which says when two appended lists are equal, into
es = fs ∧ fs = es. Then it uses these two equations as rewrite rules, turning es into fs and fs
back into es, again and again. Sledgehammer uses the same library lemma as a fact rather than as a
rewrite rule, and suggests a proof such as this one:
lemma "⟦es @ fs = fs @ es; length es = length fs⟧ ⟹ es = fs"
by (metis append_eq_append_conv)You may not have thought of using the lemma in this way, but Sledgehammer found it.
Isabelle/jEdit also has a Sledgehammer panel at the bottom of the window. Put the cursor in a proof and click Apply: the provers run in the background while you go on working, and the results appear in the panel, where a click on a proof inserts it into the text. The Provers: field lists the provers to run, and Cancel stops them.
Sledgehammer works best on small, first-order goals. Simplify first with simp or auto and call
Sledgehammer on what is left. It does not do induction, so for a claim about all lists start the induction
yourself and call Sledgehammer on the cases. Options go in square brackets, for example
sledgehammer [timeout = 60] to give the provers 60 seconds instead of the default 30.
If something went wrong
- Windows: no prover runs, or a message says that a prover failed to start. Windows Defender can block Isabelle’s external provers, as Module 1 warned. Exclude the whole Isabelle folder in Virus & threat protection, as Isabelle’s installation page recommends, and run Sledgehammer again.
- No prover finds a proof. The goal may be false: check it with
quickcheckandnitpick. It may need induction, or a lemma that is not in the library: prove that lemma first. Or the provers need more time:sledgehammer [timeout = 120]. - The suggested
metiscall fails or runs for a long time. Try another suggestion from the list.
When automation fails
No algorithm always gives a terminating, correct yes-or-no answer for every logical goal: already first-order validity is undecidable (Module 3). Systematic proof search can still enumerate derivable theorems in principle; it need not terminate on goals with no derivation. In practice, bounded automation will fail on some goals that you can prove. Then work through these steps, roughly in this order.
- Is the claim true? Run
quickcheckandnitpick. If one finds a genuine counterexample, the statement needs fixing, not the proof. - Simplify and read.
apply auto(orapply simp) and read what is left. The remaining subgoals show what the tools could not do. - Unfold definitions. Defining equations are not simp rules by default: add them with
simp add: f_def. - Split cases. A
caseneedssplit: t.split; aniforcasein an assumption needssplit: if_splitsort.splits. - Use induction when the claim is about all values of a recursive type and involves a recursive function. Start it, then automate the cases.
- Find or prove a lemma. Search with
find_theorems. If the library has nothing, state the missing step as a lemma of its own and prove it first. - Try Sledgehammer on what is left.
- Choose a different method for the kind of goal (Figure 9.3).
Which method to try first, by the kind of goal. When the first choice fails, read what it leaves and go down the list of steps above.
Prove that the owner of a document may administer it: if owner es = Some v then
allows es v Admin.
Step 1: quickcheck finds no counterexample within its bounds; the intended meaning also suggests the
claim is true. Step 5: both owner and
allows are recursive functions on the list, so start an induction. Step 2: let auto do what it can.
lemma owner_admin: "owner es = Some v ⟹ allows es v Admin"
apply (induction es)
apply autoproof (prove)
goal (2 subgoals):
1. ⋀a b es.
⟦owner es = Some v ⟹ False;
(if b = Admin then Some (fst (a, b)) else owner es) = Some v;
¬ allows es v Admin⟧
⟹ a = v
2. ⋀a b es.
⟦owner es = Some v ⟹ False;
(if b = Admin then Some (fst (a, b)) else owner es) = Some v;
¬ allows es v Admin⟧
⟹ b = AdminThe base case is proved. Two subgoals of the induction step remain, and both have an if in an assumption:
auto split the pair a into a and b but not the if in the definition of owner. Step 4 says what
to do: an if in an assumption needs split: if_splits.
oops
lemma owner_admin: "owner es = Some v ⟹ allows es v Admin"
apply (induction es)
apply (auto split: if_splits)
doneThe lemma helps with the next claim at once. Only someone who may administer a document may delete it:
lemma "may_delete u es ⟹ allows es u Admin"
by (simp add: may_delete_def owner_admin split: option.splits)The proof uses steps 3, 4 and 6 together: it unfolds may_delete, splits the case in the assumption,
and uses the lemma proved above.
Automation fails for a reason, and the reason is usually visible: in the remaining subgoals, in a counterexample, or in a trace. Read before you try another method. The fix is most often a definition to unfold, a case to split, an induction to start, or a lemma to prove first.
What you learned
- The simplifier rewrites with oriented equations, ordinarily inner parts first, with congruence
rules controlling descent into terms;
a goal rewritten to
Trueis proved. It uses the simp set: equations offun, facts fromdatatype, and lemmas marked[simp]. Equations introduced bydefinitionare not registered by default. simp add:,simp del:andsimp only:change the rules for one call;simp_allworks on every subgoal;[simp]anddeclare … [simp]change the simp set.- A conditional rule is used only if the simplifier can prove its conditions. The assumptions of a subgoal become rewrite rules too.
ifis split automatically;caseneedssplit: t.split, and splits in assumptions needif_splitsort.splits.- Rewriting may loop; keep right sides simpler than left sides. Permutative rules such as commutativity
are safe, because Isabelle applies them only to sort terms.
using [[simp_trace]]shows every step. blastsearches first-order logic, sets and relations;autosimplifies and reasons on all subgoals and leaves what it cannot prove;forceandfastforcemix search and rewriting;clarsimptidies a goal.linarithproves linear arithmetic (onnatandint, not all of it);presburgerdecides linear arithmetic on whole numbers, with divisibility and quantifiers;arithtries both. Arithmetic on whole numbers with products of variables is undecidable; use library lemmas.find_theoremsandfind_constssearch the library; Quickcheck and Nitpick search for counterexamples.- Sledgehammer asks external provers for the facts that a proof needs and reconstructs a proof that the kernel checks.
- When automation fails: test the claim, read what is left, unfold, split, induct, find or prove a lemma, and try Sledgehammer.
Exercises
For each goal, name the method you would try first, and say why. Then check your answers in Isabelle.
rev (rev xs @ ys) = rev ys @ xs⟦A ⊆ B; B ∩ C ⊆ D⟧ ⟹ A ∩ C ⊆ D⟦(a::int) < b; b < c⟧ ⟹ a + 2 ≤ c(n::nat) mod 4 = 1 ⟹ n mod 2 = 1allows es u Admin ⟹ allows es u Write
Show solution
simp: an equation about the library functionrev, which the simp set knows well.blast: pure reasoning about sets.linarith: linear arithmetic. For integers,a < bmeansa + 1 ≤ b, andlinarithknows that.presburger:modby a number is Presburger arithmetic. The argument needs the fact that4 * q + 1is odd, which is beyondlinarith.quickcheck: an ACL that grants onlyAdminis a counterexample, so no method can prove it.
lemma "rev (rev xs @ ys) = rev ys @ xs"
by simp
lemma "⟦A ⊆ B; B ∩ C ⊆ D⟧ ⟹ A ∩ C ⊆ D"
by blast
lemma "⟦(a::int) < b; b < c⟧ ⟹ a + 2 ≤ c"
by linarith
lemma "(n::nat) mod 4 = 1 ⟹ n mod 2 = 1"
by presburger
lemma "allows es u Admin ⟹ allows es u Write"
quickcheck
oopsTesting conjecture with Quickcheck-exhaustive...
Quickcheck found a counterexample:
es = [(a1, Admin)]
u = a1Rewrite the term allows (revoke u [(u, Read)]) u Read to False by hand, using the equations of
revoke and allows and these laws: fst (a, b) = a, (x = x) = True and
(if True then s else t) = s. Write down each step and the rule it uses. Then confirm in Isabelle that
these rules suffice, with simp only:. The two laws about fst and if are called fst_conv and
if_True.
Show solution
Inner parts first:
revoke u [(u, Read)]matches the second equation ofrevoke, with(u, Read)foreand[]fores: it becomesif fst (u, Read) = u then revoke u [] else (u, Read) # revoke u [].- Now the parts of this new term. In the condition,
fst (u, Read)becomesubyfst_conv, and thenu = ubecomesTrueby(x = x) = True. In both branches,revoke u []becomes[]by the first equation ofrevoke. if True then [] else [(u, Read)]becomes[]byif_True.allows [] u ReadbecomesFalseby the first equation ofallows.
lemma "allows (revoke u [(u, Read)]) u Read = False"
by (simp only: revoke.simps allows.simps fst_conv simp_thms if_True)After step 4 the lemma reads False = False, which (x = x) = True from simp_thms turns into True.
(Rewriting in another order, for example resolving the if before simplifying its branches, reaches the
same result.)
These three lemmas are true, but by simp fails on each of them. Try each in Isabelle, read the message,
say why the proof fails, and fix it.
set (grant u p es) = insert (u, p) (set es)may_delete u es ⟹ owner es ≠ None, withby (simp add: may_delete_def)instead ofby simpx ∈ set (revoke u es) ⟹ fst x ≠ u
Show solution
- “Failed to apply initial proof method”: no rule applies.
grantis a definition, so the simplifier does not unfold it, and no simp rule says anything aboutset (grant u p es). (allows_grantis aboutallows, not aboutset.) Addgrant_def. - “Failed to finish proof”, and the remaining goal has a
caseonowner esin its assumption. Acasein an assumption is split only withsplit: option.splits. - “Failed to apply initial proof method”. The claim is about all lists and involves the recursive
function
revoke, so induction is a suitable next step. In the induction step theifofrevokeends up in an assumption, which needssplit: if_splits.
lemma "set (grant u p es) = insert (u, p) (set es)"
by (simp add: grant_def)
lemma "may_delete u es ⟹ owner es ≠ None"
by (simp add: may_delete_def split: option.splits)
lemma "x ∈ set (revoke u es) ⟹ fst x ≠ u"
by (induction es) (auto split: if_splits)Prove these three laws. Some of them need induction; choose simp or auto for the cases.
revoke u (grant u p es) = revoke u esrevoke u (revoke v es) = revoke v (revoke u es)length (revoke u es) ≤ length es
Show solution
The first needs no induction, only the definition of grant. For the second and third, induction on the
list supplies the facts needed about recursive calls; revoke contains an if, which the simplifier splits.
lemma "revoke u (grant u p es) = revoke u es"
by (simp add: grant_def)
lemma revoke_commute: "revoke u (revoke v es) = revoke v (revoke u es)"
by (induction es) auto
lemma "length (revoke u es) ≤ length es"
by (induction es) autoIn the third, after splitting the if, the induction step needs length (revoke u es) ≤ Suc (length es) from
the induction hypothesis length (revoke u es) ≤ length es: linear arithmetic, which auto does.
Define a function latest :: "'u acl ⇒ ('u × perm) option" that returns the first entry of a list, or
None for the empty list, using a case expression in a definition. Then prove:
latest (grant u p es) = Some (u, p)(latest es = None) = (es = [])
Show solution
definition latest :: "'u acl ⇒ ('u × perm) option" where
"latest es = (case es of [] ⇒ None | e # _ ⇒ Some e)"
lemma "latest (grant u p es) = Some (u, p)"
by (simp add: latest_def grant_def)
lemma "(latest es = None) = (es = [])"
by (simp add: latest_def split: list.split)In the first lemma the list is (u, p) # es, so the simplifier reduces the case without a split: the
datatype’s case equations are simp rules. In the second the list is the variable es, and the case
must be split with list.split.
Prove each goal with an arithmetic method, and say why the method fits. For the last one, find the lemma
you need with find_theorems.
⟦used ≤ quota; quota ≤ used + 5⟧ ⟹ quota - used ≤ (5::nat)(x::nat) ≤ y ⟹ 3 * x ≤ 3 * yeven (n::nat) ⟹ ¬ even (n + 1)(x::nat) ≤ y ⟹ x * z ≤ y * z
Show solution
linarith: linear, with subtraction onnat.linarith: multiplication by a number is linear.presburger:even nmeans that 2 dividesn, and divisibility by a number is Presburger arithmetic.- Products of variables: not linear.
find_theorems "(_::nat) * _ ≤ _ * _" name: mono(Section 9.6) listsmult_le_mono1: ?i ≤ ?j ⟹ ?i * ?k ≤ ?j * ?k, which is exactly the claim.
lemma "⟦used ≤ quota; quota ≤ used + 5⟧ ⟹ quota - used ≤ (5::nat)"
by linarith
lemma "(x::nat) ≤ y ⟹ 3 * x ≤ 3 * y"
by linarith
lemma "even (n::nat) ⟹ ¬ even (n + 1)"
by presburger
lemma "(x::nat) ≤ y ⟹ x * z ≤ y * z"
by (simp add: mult_le_mono1)A security review claims: “if a user has permission p, then after the permission p is removed from
role r, the user still has p”. In Isabelle:
(u, p) ∈ UR O RP ⟹ (u, p) ∈ UR O (RP - {(r, p)}). Find a counterexample with Nitpick, explain it, then
add an assumption that makes the claim true and prove it with blast.
Show solution
lemma "(u::'u, p::perm) ∈ UR O RP ⟹ (u, p) ∈ UR O (RP - {(r::'r, p)})"
nitpick [card 'u = 1, card 'r = 1]
oopsNitpicking formula...
Nitpick found a counterexample for card 'r = 1 and card 'u = 1:
Free variables:
RP = {(r1, p2)}
UR = {(u1, r1)}
p = p2
r = r1
u = u1Here p₂ is one of the three permissions. With a single role, the user gets p only through r; when r
loses p, so does the user. The claim holds if u has p through some role other than r:
lemma "⟦(u, r') ∈ UR; (r', p) ∈ RP; r' ≠ r⟧ ⟹ (u, p) ∈ UR O (RP - {(r, p)})"
by blastCall an ACL well formed if every user who may write may also read:
definition wf_acl :: "'u acl ⇒ bool" where
"wf_acl es = (∀u. allows es u Write ⟶ allows es u Read)"- Prove that
revokekeeps an ACL well formed:wf_acl es ⟹ wf_acl (revoke u es). - Show with Quickcheck that
grant u Writedoes not. - Prove that granting
Readtogether withWritekeeps it well formed:wf_acl es ⟹ wf_acl (grant u Read (grant u Write es)).
Show solution
lemma "wf_acl es ⟹ wf_acl (revoke u es)"
by (simp add: wf_acl_def allows_revoke)After unfolding, allows_revoke rewrites both occurrences of allows (revoke u es) w …, and the
assumption, a ∀ over ⟶, becomes a conditional rewrite rule that finishes the proof (Section 9.3).
lemma "wf_acl es ⟹ wf_acl (grant u Write es)"
quickcheck
oopsTesting conjecture with Quickcheck-exhaustive...
Quickcheck found a counterexample:
es = []
u = a1The empty list is well formed, but after granting Write alone the user may write and not read.
lemma "wf_acl es ⟹ wf_acl (grant u Read (grant u Write es))"
by (simp add: wf_acl_def)After unfolding, allows_grant compares each user w with the two new entries. For w = u both
Write and Read hold; for any other user the old list decides both, and the assumption, again a
conditional rule, finishes the proof.
- The lemma
rev_appendof the library is a simp rule:rev (xs @ ys) = rev ys @ rev xs. Explain what would happen if you also declaredrev ys @ rev xs = rev (xs @ ys)as a simp rule. - Prove
insert a (insert b (insert c A)) = insert c (insert a (insert b A))withsimp only:and a single library rule, and explain why the simplifier stops.
Show solution
- The two rules undo each other:
rev (xs @ ys)would be rewritten torev ys @ rev xsand back, for ever. Neither rule is permutative (their sides are different terms, not the same term with variables swapped), so ordered rewriting does not apply, and the simplifier would loop. insert_commuteis permutative. Isabelle applies it only when the result is smaller in its fixed order on terms, so it sorts the inserted elements, like bubble sort, and stops when they are in order. Both sides reach the same sorted form.
lemma "insert a (insert b (insert c A)) = insert c (insert a (insert b A))"
by (simp only: insert_commute)Check yourself
by simp fail on allows (grant u Read es) u Read while by (simp add: grant_def) succeeds?fun and many library lemmas are simp rules. A definition does not register its equation by default; supply or register its _def theorem when needed.v ≠ u ⟹ allows (revoke u es) v p = allows es v p. When does simp use it on allows (revoke a es) b Read?simp add: add.commute, adding commutativity x + y = y + x to the simp set. Why does simp not loop?blast searches first-order logic, with the rules for sets and relations built in.linarith fails on (x::nat) ≤ y ⟹ x * x ≤ y * y. What is the reason?mult_le_mono handles this nonlinear goal; undecidability rules out an algorithm that decides every nonlinear integer-arithmetic goal.by (metis …) that uses two library lemmas. Why can you trust the resulting theorem?metis and checked by the kernel, as for every other method.