简体   繁体   中英

Why can't Coq unify goal and hypothesis?

After some work on an exercise, I've reached the following proof state:

(tail1 is a nat list pattern generator, lng is generalized)

1 subgoal
n' : nat
IH_n' : forall lng : nat, lng > n' -> nth n' (update (tail1 lng) 0 1) 9 = 1
lng : nat
H : S lng > S n'
______________________________________(1/1)
nth (S n') (update (tail1 (S lng)) 0 1) 9 = 1

Using apply IH_n' fails with the following error:

Unable to unify "nth n' (update (tail1?M1305) 0 1) 9 = 1" with "nth (S n') (update (tail1 (S lng)) 0 1) 9 = 1".

  • Is it the ?M1305 - (S lng) pair that can't be unified?
  • What is ?M1305 exactly?
  • Is it possible to move forward from here?

The problem here is that you are trying to apply an hypothesis on n' for S n' , whereas n' is not quantified in IH_n'.

It would only work if your hypothesis was:

IH_n' : forall n' lng : nat, lng > n' -> nth n' (update (tail1 lng) 0 1) 9 = 1

To answer your other question, ?_ is the existential variable which would be replaced if your hypothesis was applicable, because the variable lng is quantified in the hypothesis.

If you want some help on how to prove this goal, could you share the code please? (even though I think you should do unfold nth, update; simpl to see if you can apply your hypothesis somewhere.

Hypothesis IH_n' is universally quantified by lng:nat . To apply it to the goal, Coq needs to instantiate it. ?M1305 is the name it gives to the value of lng it has yet to find.

The error message does not necessarily mean that ?M1305 and (S lng) cannot be unified. The issue might come from elsewhere. For example, your goal starts with nth (S n') , while the hypothesis starts with nth n' . Obviously, (S n') and n' cannot be unified.

Your first step, assuming the goal is provable, is to make sure it starts with nth n' . To do so, you need the second argument of nth to be of the form (cons foo bar) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM