无法找到变量的实例

发布于 2024-12-27 02:26:19 字数 770 浏览 2 评论 0原文

背景:我正在软件基础中进行练习。

Theorem neg_move : forall x y : bool,
  x = negb y -> negb x = y.
Proof. Admitted.

Theorem evenb_n__oddb_Sn : forall n : nat,
  evenb n = negb (evenb (S n)).
Proof.
  intros n. induction n as [| n'].
  Case "n = 0".
    simpl. reflexivity.
  Case "n = S n'".
    rewrite -> neg_move.

在最后一行之前,我的子目标是这样的:

evenb (S n') = negb (evenb (S (S n')))

我想将其转换为:

negb (evenb (S n')) = evenb (S (S n'))

当我尝试单步执行 rewrite ->然而,neg_move 会产生以下错误:

错误:无法找到变量 y 的实例。

我确信这真的很简单,但是我做错了什么? (请不要为了解决evenb_n__oddb_Sn而放弃任何东西,除非我做得完全错误)。

Context: I'm working on exercises in Software Foundations.

Theorem neg_move : forall x y : bool,
  x = negb y -> negb x = y.
Proof. Admitted.

Theorem evenb_n__oddb_Sn : forall n : nat,
  evenb n = negb (evenb (S n)).
Proof.
  intros n. induction n as [| n'].
  Case "n = 0".
    simpl. reflexivity.
  Case "n = S n'".
    rewrite -> neg_move.

Before the last line, my subgoal is this:

evenb (S n') = negb (evenb (S (S n')))

And I want to transform it into this:

negb (evenb (S n')) = evenb (S (S n'))

When I try to step through rewrite -> neg_move, however, it produces this error:

Error: Unable to find an instance for the variable y.

I'm sure this is really simple, but what am I doing wrong? (Please don't give anything away for solving evenb_n__oddb_Sn, unless I'm doing it completely wrong).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

老子叫无熙 2025-01-03 02:26:19

正如 danportin 提到的,Coq 告诉您它不知道如何实例化 y。事实上,当你重写时 -> neg_move,你要求它用y替换一些negb x。现在,Coq 应该在这里使用什么y?它无法弄清楚。

一种选择是在重写时显式实例化y

rewrite -> neg_move with (y:=some_term)

这将执行重写并要求您证明前提,这里它将添加一个 x = negb some_term 形式的子目标。

另一种选择是在重写时专门化 neg_move

rewrite -> (neg_move _ _ H)

这里 H 必须是 some_x = negb some_y 类型的项。我为 neg_movexy 参数放置了两个通配符,因为 Coq 能够从 H 推断出它们分别为 some_xsome_y。然后,Coq 将尝试用 some_y 重写目标中出现的 negb some_x
但你首先需要在你的假设中得到这个 H 项,这可能会带来一些额外的负担......

(请注意,我给你的第一个选项应该相当于 rewrite -> ( neg_move _ some_term))

另一种选择是 erewrite -> negb_move,它将添加类似于 ?x?y 的未实例化变量,并尝试进行重写。然后你必须证明这个前提,它看起来像 (evenb (S (S n'))) = negb ?y,希望在解决这个子目标的过程中,Coq 会发现?y 从一开始就应该是什么(尽管有一些限制,并且可能会出现一些问题,因为 Coq 在没有弄清楚 ?y 必须是什么的情况下解决了目标)。


但是,对于您的特定问题,它相当容易:

==========
evenb (S n') = negb (evenb (S (S n')))

对称。

==========
negb (evenb (S (S n'))) = evenb (S n')

应用 neg_move。

==========
evenb (S (S n')) = negb (evenb (S n'))

这就是您想要的(向后,做另一个对称。如果你关心的话)。

As danportin mentioned, Coq is telling you that it does not know how to instantiate y. Indeed, when you do rewrite -> neg_move, you ask it to replace some negb x by a y. Now, what y is Coq supposed to use here? It cannot figure it out.

One option is to instantiate y explicitly upon rewriting:

rewrite -> neg_move with (y:=some_term)

This will perform the rewrite and ask you to prove the premises, here it will add a subgoal of the form x = negb some_term.

Another option is to specialize neg_move upon rewriting:

rewrite -> (neg_move _ _ H)

Here H must be a term of type some_x = negb some_y. I put two wildcards for the x and the y parameters of neg_move since Coq is able to infer them from H as being some_x and some_y respectively. Coq will then try to rewrite an occurence of negb some_x in your goal with some_y.
But you first need to get this H term in your hypotheses, which might be some additional burden...

(Note that the first option I gave you should be equivalent to rewrite -> (neg_move _ some_term))

Another option is erewrite -> negb_move, which will add uninstantiated variables that will look like ?x and ?y, and try to do the rewrite. You will then have to prove the premise, which will look like (evenb (S (S n'))) = negb ?y, and hopefully in the process of solving this subgoal, Coq will find out what ?y should have been from the start (there are some restrictions though, and some problems may arise is Coq solves the goal without figuring out what ?y must be).


However, for your particular problem, it is quite easier:

==========
evenb (S n') = negb (evenb (S (S n')))

symmetry.

==========
negb (evenb (S (S n'))) = evenb (S n')

apply neg_move.

==========
evenb (S (S n')) = negb (evenb (S n'))

And that's what you wanted (backwards, do another symmetry. if you care).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文