How to enable "Tracing" in Isabelle/jEdit - isabelle

I'm a vim fan, but only emacs has this Isabelle/HOL environment. jEdit is great, but I cannot use
using [[simp_trace=true]]
like in emacs.
How to enable "Tracing" in jEdit?

You can indeed use simp_trace in the middle of a proof in Isabelle/jEdit, like so:
lemma "(2 :: nat) + 2 = 4"
using [[simp_trace]]
apply simp
done
Alternatively, you can declare it globally, like so:
declare [[simp_trace]]
lemma "(2 :: nat) + 2 = 4"
apply simp
done
Both give you the simplifier's trace in the "Output" window when your cursor is just after the apply simp statement in jEdit.

If you need a trace depth deeper than 1 (default), you fine-tune it by
declare [[simp_trace_depth_limit=4]]
This example then gives a trace depth of 4.

As others have pointed out, you can use simp_trace. However, you can also use simp_trace_new combined with the "Simplifier Trace" window. This provides improved output over simp_trace:
lemma "rev (rev xs) = xs"
using [[simp_trace_new]]
apply(induction xs)
apply(auto)
done
To view the trace, position the cursor over "apply(auto)" then click on "See simplifier trace". The "Simplifier Trace" window(tab) should open. Click on "Show Trace" and a new window should appear showing a trace for each subgoal.
The Isabelle/Isar reference provides more details:
simp_trace_new controls Simplifier tracing within Isabelle/PIDE applications, notably Isabelle/jEdit.
This provides a hierarchical representation of the rewriting steps performed by the Simplifier.
Users can configure the behaviour by specifying breakpoints, verbosity
and enabling or disabling the interactive mode.
In normal verbosity (the default), only rule applications matching a breakpoint will be
shown to the user. In full verbosity, all rule applications will be logged.
Interactive mode interrupts the normal flow of the Simplifier and defers
the decision how to continue to the user via some GUI dialog.
Alternatively you can specify "using [[simp_trace_new mode=full]]" link here
To see all steps taken by the simplifier.
NOTE: in the previous example, showing the trace of "apply(induction xs)" yields no output.

Related

Print the name of a fact in a document antiquotation

Can I somehow refer to the name of a lemma (or theorem or corollary) inside Isabelle text?
For example:
theory Scratch
imports Main
begin
lemma lemma_name: "stuff = stuff" by simp
text‹As we have proven in fact #{thm lemma_name}, stuff is stuff.›
end
When compiling this to pdf, I see
As we have proven in fact stuff=stuff, stuff is stuff.
I would like to see
As we have proven in fact lemma_name, stuff is stuff.
Is there some document antiqotation which just prints the name of a lemma?
I could just type the lemma name verbatim, but this neither gives me control-click in the IDE nor does it make sure the text still refers to a true fact, even if I rename lemmas.
The output of antiquotations can be changed by options explained in 4.2.1 and 4.2.2 of the Isabelle/Isar Reference Manual. One (rather hidden) option [source=true] sets the output to print what you have entered as argument to the antiquotation instead of its output.
text ‹As we have proven in fact #{thm [source] lemma_name}, stuff is stuff.
...will thus result in the document output:
As we have proven in fact lemma_name, stuff is stuff.
The checking of the validity of the reference will still take place during document preparation.

Access a definition from a locale

Specific example: Let's say I have demonstrated that I have a graph in the sense of https://www.isa-afp.org/theories/category3/#FreeCategory.html :
lemma i_have_a_graph: shows "graph Obj Arr Dom Cod"
sorry
where the symbols Obj, Arr, Dom, and Cod were defined earlier in the file. This gives me access to the lemmas and theorems stated within the graph locale.
How do I use the symbol path defined within the graph locale?
Related question with no answers: Access definitions from sublocale
You don't do it using a lemma but by the interpretation command:
interpretation MyGraph: graph Obj Are Dom Cod <proof>
Of course, the <proof> could use your lemma, but you don't need to prove such a lemma separately.
Now MyGraph.path refers to the path component of this instance.
See https://www.cl.cam.ac.uk/research/hvg/Isabelle/dist/Isabelle/doc/locales.pdf

Isabelle/HOL: access interpretation in another locale

There's an Isabelle/HOL library that I want to build on with new definitions and proofs. The library defines locale2, which I'd like to build upon. Inside locale2, there's an interpretation of locale1.
To extend locale2 in a separate theory, I define locale3 = locale2. Inside locale3, however, I can't figure out how to access locale2's interpretation of locale1. How can I do that? (Am I even going about this in the right way at all?)
Below is an MWE. This is the library theory with the locale I want to extend:
theory ExistingLibrary
imports Main
begin
(* this is the locale with the function I want *)
locale locale1 = assumes True
begin
fun inc :: "nat ⇒ nat"
where "inc n = n + 1"
end
(* this is the locale that interprets the locale I want *)
locale locale2 = assumes True
begin
interpretation I: locale1
by unfold_locales auto
end
end
This is my extension theory. My attempt is at the bottom, causing an error:
theory MyExtension
imports ExistingLibrary
begin
locale locale3 = locale2
begin
definition x :: nat
where "x = I.inc 7" (* Undefined constant: "I.inc" *)
end
end
Interpretations inside a context last only until the end of the context. When the context is entered again, you have to repeat the interpretation to make the definitions and theorems available:
locale 3 = locale2 begin
interpretation I: locale1 <proof>
For this reason, I recommend to split the first interpretation step into two:
A lemma with a name that proves the goal of the interpretation step.
The interpretation command itself which can be proved by(rulelemma)
If you want the interpretation to take place whenever you open the locale and whenever you interpret the locale, then sublocale instead of interpretation might be better.

Isabelle class obligation prove blue

in Isabelle I have the following file
theory Scratch
imports Main
begin
class named =
fixes getName :: "'a ⇒ string"
class node = named
datatype Node = node string
fun getName_Node :: "Node ⇒ string" where
"getName_Node (node str) = str"
instantiation Node :: node
begin
instance proof
qed
end
end
the part 'instance' is underlined with a blue line. When I hover the curses over the info provided:
Auto solve_direct: The current goal can be solved directly with
Scratch.class.Scratch.node.of_class.intro: OFCLASS(?'a, node_class)
What can I do to prevent 'instance' to be underlined?
This is merely a hint by the system and can be safely ignored. Usually it's helpful to see that the proposition you're about to prove already exists somewhere.
Nonetheless, to disable, go to jEdit's "Plugins" menu, and choose "Plugin Options". There, go to the "Isabelle / General" item in the tree. You'll see a bunch of options. In the section "Automatically tried tools", disable "Auto Solve Direct".

Isabelle: run try command without try0

Occasionally there is a lemma, where try0 crashes Isabelle/JEdit. Only kill -9 on the process id works then.
When I then call try in the same situation, Isabelle/JEdit crashes again.
Is it possible to invoke in this situation everything from try without running try0 (or otherwise omit all the proves try0 would call)?
(I did some google searches but could not find anything relevant.)
From isar-ref.pdf, page 267, it gives the following notes on try0 and try:
try0 attempts to prove a subgoal using a combination of standard proof methods (auto, simp, blast, etc.). Additional facts supplied via simp:, intro:, elim:, and dest: are passed to the appropriate proof methods.
try attempts to prove or disprove a subgoal using a combination of provers and disprovers (solve_direct, quickcheck, try0, sledgehammer, nitpick).
So if the description is complete in the Isar Reference manual, then try is try0 plus two provers, solve_direct and sledgehammer, and two counterexample finders, quickcheck and nitpick.
To not run the provers of try0, as far as I know, you would have to run solve_direct and sledgehammer individually.
If try0 is hanging the PIDE, then it's mostly likely going into a bad loop of some kind, where enabling Auto Methods in Plugin Options / Isabelle can also cause these loops, since it does something similar to try0.
There are two kind of loops that I've experienced, where I can only remember the 2nd one listed next as hanging the PIDE:
simp rule loops caused by simp or methods that call simp, such as auto, force, fastforce, slowsimp, and bestsimp. To stop an infinite loop, I just have to delete the command.
blast loops caused by auto calling blast. For these kind, it either happens immediately, or after I've let the command run for 5 seconds or so.
You can try to narrow down which automatic proof method is causing try0 and try to hang the PIDE.
You can get a list of the try0 methods used like this (I don't know if the list of provers it shows is complete):
lemma "False"
try0
(*Trying "simp", "auto", "fast", "fastforce", "force", "blast", "metis",
"linarith", and "presburger"...*)
oops
From that list, if apply(simp) is looping, you know there's a simp rule loop (or simp rules that take a long time to complete), which would make auto, fastforce and force loop, since they call simp.
If auto is looping, then it could be simp or blast, since auto can call each of those, so you can try apply(blast) to see if blast is the problem.
With Isabelle2013-2, for me, the hanging of the PIDE has been because of auto, because it calls blast. Supposedly, that has been fixed for the next release.
I put this as a second answer, since it's different enough.
I was browsing through the repository changes, and that led me to the following Isabelle2013-2 ML files related to try and try0 (but don't get locked in completely, because I list other files to show things are changing):
src/Tools/try.ML
src/HOL/Tools/try0.ML
src/HOL/Tools/Sledgehammer/sledgehammer_try0.ML
The file try.ML gives this line of source:
val get_tools : theory -> tool list
I suppose, using ML, a person could get a list of the tools used by try, but if so, then it would probably correspond with the description given in the other answer from isar-ref.pdf.
Basically, there is try which calls other tools, sledgehammer which does its own special thing, where the use of try0 is part of its arsenal, solve_direct, and then fully automatic proof methods used by try0, which are listed in try0.ML.
The majority of automatic proof methods which are listed in try0.ML are referenced in isar-ref.pdf sections
9.3 The Simplifier [187]
9.4.4 Fully automated methods [211],
12.7 Model Elimination and Resolution [263], and
12.8 Algebraic reasoning via Gröbner bases [263].
Now for some changes that are coming down the pipe, taken from the latest files or changesets:
src/HOL/Tools/try0.ML
Changeset: got rid of 'try0' step that is now redundant
Changeset: implemented new 'try0_isar' semantics
From the latest repository try0.ML, it gives the list of proof methods that try0 will try. If you look at the Isabelle2013-2 try0.ML above, you'll see that the list given in that file is the same list of methods shown in the other answer when trying to prove False.
Here, there are extra automatic proof methods that aren't currently being tried with Isabelle2013-2.
val full_attrs = (SOME "simp", SOME "intro", SOME "elim", SOME "dest");
val clas_attrs = (NONE, SOME "intro", SOME "elim", SOME "dest");
val simp_attrs = (SOME "add", NONE, NONE, NONE);
val metis_attrs = (SOME "", SOME "", SOME "", SOME "");
val no_attrs = (NONE, NONE, NONE, NONE);
(* name * ((all_goals, run_if_auto_try), (simp, intro, elim, dest) *)
val named_methods =
[("simp", ((false, true), simp_attrs)),
("auto", ((true, true), full_attrs)),
("blast", ((false, true), clas_attrs)),
("metis", ((false, true), metis_attrs)),
("linarith", ((false, true), no_attrs)),
("presburger", ((false, true), no_attrs)),
("algebra", ((false, true), no_attrs)),
("fast", ((false, false), clas_attrs)),
("fastforce", ((false, false), full_attrs)),
("force", ((false, false), full_attrs)),
("meson", ((false, false), metis_attrs))]

Resources