Are Coq tacticals right associative or left associative? - coq

I was going through software foundations and got the example:
repeat (try (left; reflexivity); right).
and was confused what this meant. For example do we get:
try [ (left; reflexivity); right ]
or
[try (left; reflexivity);] right
second or first?
in particular I was trying to understand:
Theorem In10 : In 10 [1;2;3;4;5;6;7;8;9;10].
Proof.
repeat (try (left; reflexivity); right).
Qed.

A good way of solving those problems on your own is to use tactics like idtac (always succeeds) and fail (always fails) to disambiguate:
try (idtac; idtac); fail. (* FAILS *)
try ((idtac; idtac); fail). (* SUCCEEDS *)
(try (idtac; idtac)); fail. (* FAILS *)
So indeed, the application of try binds tighter than the semicolon:
try (idtac; idtac); fail. is the same as (try (idtac; idtac)); fail.

Related

How to run SearchAbout snippet in company-coq-tutorial

Running M-x company-coq-tutorial, I'm getting stuck at the following instruction in the tutorial:
(* Run the following snippet, then try typing ‘plus’ *)
SearchAbout eq.
I'm assuming it's supposed to be Search eq. in newer versions of Coq.
How do I "run" this snippet? Does the tutorial want me to go to the line below Search eq. and press C-c C-RET, or is there something else I'm supposed to do?

Avoid printing notation in Coq with Proof General

In lecture 6 of the DeepSpec 2018, the lecturer Checks the definition of
string_dec
obtaining:
string_dec
: forall s1 s2 : string, {s1 = s2} + {s1 <> s2}
Then he goes on to see the definition of +, but before, he disables in CoqIde the printing of notation. So that sumbool is printed. This last symbol can be checked.
How can I do the same thing with Proof General?
You can use the menu, Coq > OPTIONS > Set Printing All.
You can also issue the command directly, typing Set Printing All. and evaluating it in your buffer before running the Check command. This also gives you access to Unset Printing Notations to only disable printing notations (which is something you can do with the menu in CoqIDE). When you're done you can just delete this command, which will undo its effect.
Finally, you can also directly use Coq > OTHER QUERIES > Check (show all) on string_dec.

Conditional Proof Tactic in Coq

I believe the title is pretty self explanatory : https://en.wikipedia.org/wiki/Conditional_proof
I would like to have a tactic where I assume a proposition and proceed to find another one, if succeeded, then I have found that the first proposition implies the second one and this is put as an hypothesis in the context.
So for example Ltac cp P Q creates a subgoal Qand puts Pin the context. If I can indeed reach the subgoal Q, then the subgoal is discharged and P->Q is added to the context. How can I achieve this ?
Edit: It is clear that while proving
assert (P->Q).
intro.
does the job, but I cannot combine them into a Ltac tactic, it gives an error of No focused proof (No proof-editing in progress).
To define new tactics, you need to compose them with ;.
Ltac cp P Q := assert (P -> Q); [ intro | ].
(* Use intro in the first subgoal of assert *)
There is already such a tactic, it's called enough, as "it is enough to show that P". It assumes P and you now get to finish your proof using P. When you're done, you have to prove P.
If it is easy to finish, you can use by (in the same as for assert). I often do enough (bla bla) by (subst; auto). or something similar, which leaves me with the goal bla bla.
You may also find this tactic useful, i.e. if you don't want to type the entire complicated antecedent into the enough statement:
Ltac postpone_antecedent H :=
match type of H with ?A -> _ =>
let Q := fresh in enough A as Q ; [specialize (H Q) | ]
end.

How to get coq to print out new goal and hypotheses after applying tactic

sometimes I find coq gets into a state where when I apply a tactic, the new goal and hypotheses don't automatically get printed out. How do I set it to print these out after each tactic invocation.
This is coq 8.7.2, using coqtop
I believe when this happens it's a bug in Proof General, which is supposed to display the proof context whenever you're in the middle of a proof. Li-yao Xia's solution of hitting C-c C-p should work.

XXX "is bound to a notation that does not denote a reference" during unfold in Coq?

I am working on an example given here:
Notation step_normal_form := (normal_form step).
Definition stuck (t:tm) : Prop :=
step_normal_form t /\ ~ value t.
Example some_term_is_stuck :
exists t, stuck t.
and I am having trouble unfold-ing the definition step_normal_form at step 1 (Coq 8.4pl6). I can Check its contents in CoqIDE:
normal_form
: relation ?23 -> ?23 -> Prop
value
: tm -> Prop
But when I unfold step_normal_form:
Example some_term_is_stuck :
exists t, stuck t.
Proof.
unfold stuck. unfold step_normal_form.
I get an error:
Error: step_normal_form is bound to a notation that does not denote a reference.
Does anyone know why this happens and how to fix it?
BTW, I tried to work around this by doing the unfold manually and redefining:
Definition stuck' (t:tm) : Prop :=
normal_form step t /\ ~ value t.
and use stuck' instead. But Coq seems to automatically fold the content of stuck' into step_normal_form and then refuse to unfold it, giving the same error.
Since step_normal_form is just notation for (normal_form step) you could just do unfold normal_form.
Sometimes notations and pretty-printing hides what's really there. Use Set Printing All. to make Coq print the term in clear.