2

I noticed notations can be treated differently. For example < is just notation for a regular definition and unfold "<" does work as in the following example:

Theorem a : 4 < 5.
Proof.
    unfold "<".

However, <= is notation associated with the type le and for some reason unfold "<=" doesn't work, as in the following example:

Theorem a : 4 <= 5
Proof.
   unfold "<=".

which fails with Unable to interpret "<=" as a reference.

Can I convert 4 <= 5 into le 4 5 with some ltac command?

Mei Zhang
  • 1,434
  • 13
  • 29

2 Answers2

1

This happens because < is interpreted as lt which is a definition (here):

Definition lt (n m:nat) := S n <= m.

You can achieve the same effect with unfold lt.

In the same manner <= means le, but you cannot unfold le, because it is a type constructor. The manual says that you can unfold only a defined transparent constant or local definition.

The upshot here is that you don't unfold notations, you unfold the definitions those notations refer to.

Anton Trunov
  • 15,074
  • 2
  • 23
  • 43
  • Makes sense, unfold works only on definitions. However, if I wanted `a <= b` to be displayed as `le a b` in the proof view, is there a tactic or something I can execute in the middle of the proof to do it? – Mei Zhang Feb 03 '18 at 11:20
  • There is `Unset Printing Notations.` command, but it unfolds them *all*. There is no way to do it selectively as of now. Here is a [related question](https://stackoverflow.com/q/30248144/2747511). And here are related issues: [#5591](https://github.com/coq/coq/issues/5591) and [#703](https://github.com/coq/coq/pull/703). – Anton Trunov Feb 03 '18 at 11:27
1

Adding to Anton's answer: If you already know how the notation is defined and only want to make it visible in the goal, you could do something like

Definition make_visible {X} (f : X) := f.

Notation "` f" := (make_visible f) (at level 5, format "` f").

Tactic Notation "unfold" "notation" constr(f) :=
  change f with (`f).
Tactic Notation "fold" "notation" constr(f) :=
  unfold make_visible.

Theorem a : 4 <= 5.
Proof.
  unfold notation le.
  fold notation le.

(Edit: My first solution was Definition make_visible {X} (f : X) := (fun _ => f) tt., but, as Anton pointed out, this is easier.)

  • 1
    Nice! I've noticed that a simple wrapper also works: `Definition make_visible {X} (f : X) := f.` Is there a case when it fails? – Anton Trunov Feb 07 '18 at 10:25
  • Ah, no, I think that's even better. When playing around I first didn't introduce a definition and defined the notation directly, thus the strange detour. I'll change the answer! – Yannick Forster Feb 08 '18 at 11:54