0

I'm trying to figure out the source of the following error with the apply (list2map_not_in_default [(k, v)] i) in H2. command.

Here is the list2map_not_in_default type:

list2map_not_in_default
     : forall (al : list (key * V)) (i : key),
       ~ (exists v : V, In (i, v) al) -> list2map al i = default

And the error:

Error:
Unable to apply lemma of type
 "~ (exists v0 : V, In (i, v0) [(k, v)]) -> list2map [(k, v)] i = default"
on hypothesis of type "~ (exists v : V, In (i, v) [(k, v)])".

Alternatively apply (list2map_not_in_default [(k, v)] i) in H2. , can be seen as the following error, whereby you can see my context fully.

Error:
In environment
V : Type
default : V
lo : key
l : tree
k : key
v : V
r : tree
hi : key
H0_ : SearchTree' lo l k
H0_0 : SearchTree' (S k) r hi
i : nat
Hleft : ~ (exists v : V, In (i, v) (slow_elements l))
H : i < k
H0 : k <> i
H1 : list2map (slow_elements l) i = default
H2 : ~ (exists v : V, In (i, v) [(k, v)])
The term "H2" has type "~ (exists v : V, In (i, v) [(k, v)])"
while it is expected to have type "~ (exists v0 : V, In (?i, v0) ?al)".

Earlier in the proof I use the exact same lemma specialize (list2map_not_in_default _ _ Hleft). with no problems.

This applied in the following context

  V : Type
  default : V
  lo : key
  l : tree
  k : key
  v : V
  r : tree
  hi : key
  H0_ : SearchTree' lo l k
  H0_0 : SearchTree' (S k) r hi
  i : nat
  Hleft : ~ (exists v : V, In (i, v) (slow_elements l))
  H : i < k
  H0 : k <> i
  ============================
  list2map (slow_elements l ++ [(k, v)] ++ slow_elements r) i =
  list2map (slow_elements l) i

yields a goal with the desired application.

  list2map (slow_elements l) i = default ->
  list2map (slow_elements l ++ [(k, v)] ++ slow_elements r) i =
  list2map (slow_elements l) i

What is happening here? Any suggestions on how I can fix it?

1 Answers1

1

The unification algorithm used by apply in is exceedingly weak. There is nothing you can do about it (except opening bug reports and hoping someone fixes it). Just use some other tactic. As you already noticed, specialize works better, since you are explicitly writing a lambda-term. Another similar tactic is assert (H3 := list2map_not_in_default _ _ Hleft). Or you can go to the most expressive tactic of all: (simple) refine (let H3 := list2map_not_in_default _ _ Hleft in _).

Guillaume Melquiond
  • 1,243
  • 4
  • 11