I would like to understand the state machine of the Isar Virtual Machine.
Page 48 of Markus Wenzel's doctoral thesis gives a good overview but does not detail its messages in the Output panel. It might well be a later addendum to the system.
I have a simple Isar proof:
theory Propositional
imports Main
begin
lemma nj2: assumes p: P and q: Q shows "P ∧ (Q ∧ P)"
proof -
from q p have qp: "Q ∧ P" by (rule conjI)
from p qp show "P ∧ (Q ∧ P)" by (rule conjI)
qed
after the second by (rule conjI) the Output panel says
show (P::bool) /\ (Q::bool) /\ P
Successful attempt to solve goal by exported rule:
(P::bool) /\ (Q::bool) /\ P
proof (state): depth 0
this:
(P::bool) /\ (Q::bool) /\ P
goal:
No subgoals!
variables:
P, Q :: bool
so it explicitly recognizes the solution of the goal. However, at the first by (rule conjI) it says
have qp: (Q::bool) /\ (P::bool)
proof (state): depth 0
this:
(Q::bool) /\ (P::bool)
goal (1 subgoal):
1. P /\ Q /\ P
variables:
P, Q :: bool
I see no sign that the subgoal has been proved. Or, the fact that the have statement is the same as in the this register should remind me that it is proved?
Well, the subgoals in the output panel correspond to the subgoals of the context. In this case, the context is the one of the complete lemma, beginning with proof -. In this context, there is only one subgoal, which is the lemma to be proved.
When you state your intermediate property with have, the system doesn't verify anything with respect to the goals, and once it's proved, it just gives you access to this property (through the names this and qp) because you have proved it with by (rule conjI) and the fact that there is no error means that it is proved.
On the other hand, when you state a property with show, the system verifies that this property with the eventual assumptions you've made (with assume) actually corresponds to one of the subgoals, and fails otherwise.
When it arrives to the qed command, it finally verifies that all the subgoals of the context have been proved.
Another way to write this proof is like this (I didn't checked it worked, but it should...) :
theory Propositional
imports Main
begin
lemma nj2: assumes p: P and q: Q shows "P ∧ (Q ∧ P)"
proof (rule conjI)
from p show P by assumption
next
from q p show "Q ∧ P" by (rule conjI)
qed
In this case, proof (rule conjI) creates 2 subgoals P and Q ∧ P and the Output panel should confirm this.
Related
I sometimes find it hard to use Isabelle because I cannot have a "print command" like in normal programming.
For example, I want to see what ?thesis. The concrete semantics book says:
The unknown ?thesis is implicitly matched against any goal stated by lemma or show. Here is a typical example:
My silly sample FOL proof is:
lemma
assumes "(∃ x. ∀ y. x ≤ y)"
shows "(∀x. ∃ y. y ≤ x)"
proof (rule allI)
show ?thesis
but I get the error:
proof (state)
goal (1 subgoal):
1. ⋀x. ∃y. y ≤ x
Failed to refine any pending goal
Local statement fails to refine any pending goal
Failed attempt to solve goal by exported rule:
∀x. ∃y. y ≤ x
but I do know why.
I expected
?thesis === ⋀x. ∃y. y ≤ x
since my proof state is:
proof (state)
goal (1 subgoal):
1. ⋀x. ∃y. y ≤ x
Why can't I print ?thesis?
It's really annoying to have to write the statement I'm trying to proof if it's obvious. Perhaps it's meant to be explicit but in the examples in chapter 5 they get away with using ?thesis in:
lemma fixes a b :: int assumes "b dvd (a+b)" shows "b dvd a" proof −
have "∃k′. a = b∗k′" if asm: "a+b = b∗k" for k proof
show "a = b∗(k − 1)" using asm by(simp add: algebra_simps) qed
then show ?thesis using assms by(auto simp add: dvd_def ) qed
but whenever I try to use ?thesis I always fail.
Why is it?
Note that this does work:
lemma
assumes "(∃ x. ∀ y. x ≤ y)"
shows "(∀x. ∃ y. y ≤ x)"
proof (rule allI)
show "⋀x. ∃y. y ≤ x" proof -
but I thought ?thesis was there to avoid this.
Also, thm ?thesis didn't work either.
Another example is when I use:
let ?ys = take k1 xs
but I can't print ?ys value.
TODO:
why doesn't:
lemma "length(tl xs) = length xs - 1"
thm (cases xs)
show anything? (same if your replaces cases with induction).
You can find ?theorem and others in the print context window:
As for why ?thesis doesn't work, by applying the introduction rule proof (rule allI) you are changing the goal, so it no longer matches ?thesis. The example in the book uses proof- which prevents Isabelle from applying any introduction rule.
It seems I asked a very similar question worth pointing to: What is the best way to search through general definitions, theorems, functions, etc for Isabelle?
But here is a list of thing's I've learned so far:
thm: seems to work for definition, lemmas and functions. For definition do name_def for a definition with name name. For functions do thm f.simps for all definitions in the function. For a single one do thm f.simps(1) for the first one. For lemmas do thm lemma_name or thm impI or HOL.mp etc.
term: for terms do term term_name e.g. in isar term ?thesis or term this
print_theorems: if you place this after a definition or a function it shows all the theorems defined for those! It's amazing.
print... I just noticed in jedit if you let the auto complete show you the rest for print it has a bunch of options! Probably useful!
Search engine for Isabelle: https://search.isabelle.in.tum.de/
You can use Query (TODO: improve this)
TODO: how to find good way to display stuff about tactics.
I plan to update this as I learn all the ways to debug in Isabelle.
Let's assume we have such variant of Modus Ponens
lemma invDed: ‹(A-->B)==>(A==>B)›
apply(rule mp)
apply assumption
apply assumption
done
Can it be applied for proving the theorem? (I mean A:=A, B:=A, and A-->A we use as if it was previously proved)
lemma myid2: "A==>A"
If not, why? I know several other ways to prove this theorem("apply assumption" or 5-step proof from Frege's propositional calculus axioms.), but I interested in this nuance of proof mechanics.
i have one rule, now I want obtain an another [admissible] rule, what's problem?
Application with rule only applies to the formula after the rightmost meta implication (==>). So you would get something like the following, which is not very helpful:
lemma myid2: "A==>A"
proof (rule invDed[where A=A and B=A])
show "A ⟹ A ⟶ A"
by (rule imp_refl)
show "A ⟹ A"
by assumption
qed
If you rotate your premises (done below with the [rotated] modifier) to have A==>(A-->B)==>(B), then you can apply it with erule:
lemma myid2: "A==>A"
apply (erule invDed[rotated])
apply (rule imp_refl)
done
Is it possible to make the following example work?
inductive elems where
"x |∈| xs ⟹
elems xs x"
code_pred [show_modes] elems .
values "{x. elems {|1::nat,2,3|} x}"
The predicate compiler by default does not know anything about finite sets and the membership operator |∈|. However, if you add the following snippet, then it works.
lemma fmember_code_predI [code_pred_intro]:
"x |∈| xs" if "Predicate_Compile.contains (fset xs) x"
using that by(simp add: Predicate_Compile.contains_def fmember.rep_eq)
code_pred fmember
by(simp add: Predicate_Compile.contains_def fmember.rep_eq)
Here's why this works: The constant Predicate_Compile.contains implements enumeration for ordinary sets and the predicate compiler knows about it. The lemma with the attribute code_pred_intro tells the predicate compiler to treat membership on fset as if it was defined as an inductive predicate with the lemma statement as introduction rule. At the code_pred command itself, you then have to prove the corresponding elimination rule. These two rules (introduction and elimination rule) are enough for the predicate compiler to do the mode analysis and compile the equations and prove them correct.
You don't even need to define your own predicate elems. Membership on fset works directly:
values "{x. x |∈| {|1::nat,2,3|}}"
I'm attempting to formalize a series of proofs about topology from a book [1] in Isabelle.
I want to encode the idea that a topological space (X,T) consists of a set X of "points" (elements of some arbitrary type 'a), and a set of subsets of X, called T, such that:
A1. if an element p is in X, then there exists at least one set N in T that also contains p.
A2. if sets U and V are in T, and if p∈(U∩V), then there must exist at a set N in T where N⊆(U∩V) and x∈N. (If two sets intersect, then there must be a neighborhood that covers the intersection.).
Currently I have the following definition:
class topspace =
fixes X :: "'a set"
fixes T :: "('a set) set"
assumes A1: "p∈X ≡ ∃N∈T. p∈N"
assumes A2: "U∈T ∧ V∈T ∧ x∈(U∩V) ⟹ ∃N∈T. x∈N ∧ N⊆(U∩V)"
begin
(* ... *)
end
So far, so good. I'm able to add various definitions and prove various lemmas and theorems about hypothetical topspace instances.
But how do I actually create one? Unless I'm misinterpreting things, the examples I've seen so far for the instance and instantiate keywords all seem to be been about declaring that one particular abstract class (or type or locale) is an instance of another.
How do I tell Isabelle that a particular pair of sets (e.g. X={1::int, 2, 3}, T={X,{}}) form a topspace?
Likewise, how can I use my definition to prove that X={1::int, 2, 3}, T={} does not fit the requirements?
Finally, once I show that a particular concrete object X meets the definition of a topspace, how do I tell Isabelle to now make use of all the definitions and theorems I've proven about topspace when proving things about X?
BTW, I'm using class because I don't know any better. If it's not the right tool for the job, I'm happy to do something else.
[1]: A Bridge to Advanced Mathematics by Dennis Sentilles
I've made some progress here: a class is a special type of locale, but it isn't necessary for this sort of usage, and using the locale keyword directly simplifies the situation a bit. Every locale has an associated theorem that you can use to instantiate it:
locale topspace =
fixes X :: "'a set"
fixes T :: "('a set) set"
assumes A1 [simp]: "x∈X ≡ ∃N∈T. x∈N"
assumes A2 [simp]: "U∈T ∧ V∈T ∧ x∈(U∩V) ⟹ ∃N∈T. x∈N ∧ N⊆(U∩V)"
theorem
assumes "X⇩A={1,2,3::int}" and "T⇩A={{}, {1,2,3::int}}"
shows "topspace X⇩A T⇩A"
proof
show "⋀U V x. U∈T⇩A ∧ V∈T⇩A ∧ x∈U∩V ⟹ ∃N∈T⇩A. x∈N ∧ N⊆U∩V"
and "⋀x. x∈X⇩A ≡ ∃N∈T⇩A. x∈N" using assms by auto
qed
If we want to use definition for declarations, the proof goal becomes a bit more complex, and we need to use the unfolding keyword. (The locales.pdf that comes with isabelle covers this, but I'm not sure I'm not yet able to explain it in my own words). Anyway, this works:
experiment
begin
definition X⇩B where "X⇩B={1,2,3::int}"
definition T⇩B where "T⇩B={{}, {1,2,3::int}}"
lemma istop0: "topspace X⇩B T⇩B" proof
show "⋀U V x. U∈T⇩B ∧ V∈T⇩B ∧ x∈U∩V ⟹ ∃N∈T⇩B. x∈N ∧ N⊆U∩V"
and "⋀x. x∈X⇩B ≡ ∃N∈T⇩B. x∈N" unfolding X⇩B_def T⇩B_def by auto
qed
end
I believe it's also possible, and possibly preferable, to do all this work inside of a sub-locale, but I haven't quite worked out the syntax for this.
Although locales are implemented in the calculus itself and hence their predicates can be used in any regular proposition, this is usually not recommended. Instead, you should instantiate locales using e.g. interpretation, as in the following example.
locale topspace =
fixes X :: "'a set"
fixes T :: "('a set) set"
assumes A1 [simp]: "x∈X ⟷ (∃N∈T. x∈N)"
assumes A2 [simp]: "U∈T ∧ V∈T ∧ x∈(U∩V) ⟹ ∃N∈T. x∈N ∧ N⊆(U∩V)"
context
fixes X⇩A T⇩A
assumes X⇩A_eq: "X⇩A = {1, 2, 3 :: int}"
and T⇩A_eq: "T⇩A = {{}, {1, 2, 3 :: int}}"
begin
interpretation example: topspace X⇩A T⇩A
by standard (auto simp add: X⇩A_eq T⇩A_eq)
lemmas facts = example.A1 example.A2
end
thm facts
Whether this pattern really fits for your needs depends on your application; if you just want to have a predicate, it is better to define it directly without using locale at all.
Note: there is really need to the Pure equality »≡«; prefer HOL equality »=«, or its syntactic variant »⟷«.
I have another theorem that I am not being able to prove in Isabelle, involving identity and transitive closure.
It is the following:
lemma "r ⊆ Id ⟹ r^* = Id"
Update: Using apply-style I have the following:
lemma "r ⊆ Id ⟹r^* = Id"
apply (rule equalityI)
apply (rule subrelI)
apply (erule rtrancl_induct)
apply (blast+)
done
How can the same be done in Isar?
It seems that your question is more about transforming apply-style proofs into proper Isar. For the specific example you have this can be done as follows. As you mentioned yourself in
lemma "r ⊆ Id ⟹ r^* = Id"
there are difficulties to refer to the assumption r ⊆ Id. The canonical Isar way of structuring this proof is as follows. We start a proof via
proof -
where the - indicates that no initial rule should be used. This just serves the purpose to be able to state assumptions explicitly.
assume *: "r ⊆ Id"
show "r^* = Id"
In addition we give the name * to the assumption. Alternatively we could have stated the whole lemma differently as
lemma
assumes *: "r ⊆ Id"
shows "r^* = Id"
which saves one level of nesting. Anyway, having this, as you said, equality of sets is again canonical, namely:
proof
show "r^* ⊆ Id"
proof (rule subrelI)
fix x y
assume "(x, y) ∈ r^*"
then show "(x, y) ∈ Id"
using * by (induct) blast+
The above line is where we use the assumption (alternatively, we could refer to the assumption literally via ‹r ⊆ Id› or via the implicit name assms that is introduced for the facts following assumes). And we finish by:
qed
next
show "Id ⊆ r^*" by blast
qed