The order of premises - isabelle

How to change the order of premises in a rule?
For instance, in Isabelle's natural deduction rule:
mp: ?P ⟶ ?Q ⟹ ?P ⟹ ?Q
Can we change the order to:
?P ⟹ ?P ⟶ ?Q ⟹ ?Q
I can use rev_mp or define a new lemma, but what I am looking for is whether there is a theorem modifier that changes the order of premises.

The premises of a theorem can be rotated with the attribute rotated. You can also specify the number of premises to rotate, e.g., mp[rotated 1]. AFAIK there's no attribute for arbitrarily permuting the premises.

Related

Meta symbol for existential quantification in Isabelle

There are meta symbols for implication and universal quantification in Isabelle/Pure (⟹ and ⋀), which behave differently from its HOL counterparts (∀ and →).
Is there a meta symbol for existential quantification? If not, is there a specific reason for this decision?
Pure is based on intuistionistic logic and there is no existential quantifier in this logic.
The rough equivalent is obtains:
lemma
assumes "P"
obtains x where "Q x"
The generated lemma is P ⟹ (⋀x. Q x ⟹ thesis) ⟹ thesis. It does not contain an existential quantifier, but only an implication. However it plays a similar rule: by instantiation of thesis with any other goal, you can exhibit the existence of an x such that Q x.

An inductive predicate enumerating set elements

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|}}"

Curry-Howard for term synthesis in Isabelle

Say I have proven some basic proposition of intuitionistic propositional logic in Isabelle/HOL:
theorem ‹(A ⟶ B) ⟶ ((B ⟶ C) ⟶ (A ⟶ C))›
proof -
{
assume ‹A ⟶ B›
{
assume ‹B ⟶ C›
{
assume ‹A›
with ‹A ⟶ B› have ‹B› by (rule mp)
with ‹B ⟶ C› have ‹C› by (rule mp)
}
hence ‹A ⟶ C› by (rule impI)
}
hence ‹(B ⟶ C) ⟶ (A ⟶ C)› by (rule impI)
}
thus ?thesis by (rule impI)
qed
I know from the Curry-Howard correspondence that the proposition corresponds to some type (a -> b) -> ((b -> c) -> (a -> c)), and the proof to some term, all inside some type theory (say, in the simply-typed λ-calculus). From the structure of the proof, I know the corresponding simply-typed λ-term is λf:a→b. λg:b→c. λx:a. f(g(x)).
Is there a way to get Isabelle to construct this for me?
I have looked up program extraction in Isabelle, and from what I can tell it largely refers to something else: where you write functional programs in Isabelle, prove things about them and then it provides some kind of translation to Haskell or ML.
I also know that HOL is not the same thing as dependent type theory, which I'm given to understand has a stronger Curry-Howard flavour to it. I know that HOL itself is conceptually somewhat like polymorphic λ-calculus, and I found some brief notes about how HOL is a shallow encoding of logic in type theory, but some more context would be greatly appreciated. I've barely been able to piece together how all these different proof assistants and their associated foundations relate together, and perhaps some more historical context would help too. Unfortunately, the documentation around Isabelle, Coq, etc. all seems a bit all over the place; for Isabelle in particular, I seem to regularly find information that is 20 years out of date.

Instantiating a class from a concrete object?

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 »⟷«.

Recognising that a subgoal is proved

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.

Resources