I'm working on a colleague's embedding of modal logic in Coq and I'm trying to define a custom notation for formulas of said logic, like presented here and also on Volume 2 of the book Software Foundations. So far I have this:
Declare Custom Entry modal.
Declare Scope modal_scope.
Notation "[! m !]" := m (at level 0, m custom modal at level 99) : modal_scope.
Notation " p -> q " := (Implies p q) (in custom modal at level 13, right associativity).
Open Scope modal_scope.
Definition test:
[! p -> q !].
However, the Definition gives this error:
Syntax error: [constr:modal level 99] expected after '[!' (in [constr:operconstr]).
And I can't figure out why. I found some questions on SO where the suggested solution is to change the precedence of the first symbol, p in this case, however that just throws another error. The Coq manual wasn't very helpful either.
What is causing this error and why do the other notations work ?
You declared your own syntactic category for your logic: The parser, after [!, expects only things that are in the entry modal. p is an identifier, and the parser does not expect arbitrary identifiers.
In the documentation on custom entries, you can find a hint on how to add identifiers to your entry:
Declare Custom Entry modal.
Declare Scope modal_scope.
Print Grammar constr.
Axiom Implies : Prop -> Prop -> Prop.
Notation "x" := x (in custom modal at level 0, x ident).
Notation "[! m !]" := m (at level 0, m custom modal at level 99) : modal_scope.
Notation "p '->' q" := (Implies p q) (in custom modal at level 13, right associativity).
Open Scope modal_scope.
Definition testp p q:
[! p -> q !] .
I found some questions on SO where the suggested solution is to change the precedence of the first symbol, p in this case, however that just throws another error. The Coq manual wasn't very helpful either.
This can be a solution if the left-most symbol of your notation is a terminal, not a variable.
Related
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.
Proof assistant Coq have compute command (and also check command for determination of the type) which returns the result of function application. Does Isabelle/HOL have similar command and how it is named?
Isabelle has a "value" command that performs evaluation.
value "rev [1::nat,2,3]"
Isabelle then responds with:
"[Suc (Suc (Suc 0)), Suc (Suc 0), Suc 0]"
:: "nat list"
(Quoted from https://lists.cam.ac.uk/pipermail/cl-isabelle-users/2007-October/msg00008.html)
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.
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.
How can I htmlfontify a code buffer in Emacs without losing the composed characters?
I have several modes that display certain ASCII sequences as unicode using compose-region. For example, I might write something like:
foo :: Num a => [a] -> a
foo = foldl (+) 0 . map (\ x -> x + f x - 10)
and the editor displays (without changing the buffer's actual contents):
foo ∷ Num a ⇒ [a] → a
foo = foldl (+) 0 ∘ map (λ x → x + f x - 10)
This is essentially another form of syntax highlighting, except with special characters instead of colors.
However, when I use M-x htmlfontify-buffer on a buffer that looks like my second example, all this information is lost and the html output looks like the first version. How can I avoid losing the character transformations?
I don't think htmlfontify supports this feature yet. But if you M-x report-emacs-bug to request the feature, you might find someone who can implement it fairly quickly (then again, maybe not).