COQ-将表达式分配给变量

发布于 2025-02-06 04:11:51 字数 752 浏览 2 评论 0原文

首先,我还不熟悉Coq Lingo,因此我将宽松地使用EG'expression'和``变量''之类的术语,但是它们可能不是正确的COQ术语。

我正在尝试证明定理的以下子缘。

1 goal
b : bag
v, b' : nat
b'' : natlist
B : b = b' :: b''
IHb'' : b = b'' -> count v (add v b'') = count v b'' + 1
______________________________________(1/1)
S match v =? b' with
  | true => S (count v b'')
  | false => count v b''
  end = match v =? b' with
        | true => S (count v b'')
        | false => count v b''
        end + 1

您可以忽略s+ 1,我基本上正在寻找一种分配

match v =? b' with
  | true => S (count v b'')
  | false => count v b''
  end

给类型nat的 方法方程式的侧面。 我该怎么做?或者我需要进行销毁vb'并分别证明所有情况吗?

First and foremost, I'm not yet very familiar with Coq lingo, so I will use terms like e.g. 'expression' and 'variable' loosely, but they are probably not the correct Coq terms.

I'm trying to prove the following subgoal of a Theorem.

1 goal
b : bag
v, b' : nat
b'' : natlist
B : b = b' :: b''
IHb'' : b = b'' -> count v (add v b'') = count v b'' + 1
______________________________________(1/1)
S match v =? b' with
  | true => S (count v b'')
  | false => count v b''
  end = match v =? b' with
        | true => S (count v b'')
        | false => count v b''
        end + 1

You can ignore S and + 1, I'm basically looking for a way to assign

match v =? b' with
  | true => S (count v b'')
  | false => count v b''
  end

to a variable of type nat because it occurs on both sides of the equation.
How can I do this? Or do I need to go through destroying v and b' and proving all cases separately?

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

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

发布评论

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

评论(2

挽容 2025-02-13 04:11:54

这是两种可能性。可能会有更好的。

您可以使用 为一个术语命名。该术语的所有出现都被变量所取代。

set (x := match v =? b' with
          | true => S (count v b'')
          | false => count v b''
          end).

有时,您需要隐藏变量的定义,并且只能记住它是根据需要调用的平等。为此,使用 记住

您可以使用 上下文 匹配目标 ,并为该模式中的任何内容命名。

match goal with |- context [S ?_x = ?_x + 1] => set (x := _x) end.

如果这是您的真正目标,而不是简化的例子,那么这是一个简单的算术语句#COQ:tacn.lia“ rel =” nofollow noreferrer“> lia ,让Coq弄清楚。

Require Import Lia.

…
lia.

Here are two possibilities. There may well be better ones.

You can use set to give a name to a term. All the occurrences of that term are replaced by the variable.

set (x := match v =? b' with
          | true => S (count v b'')
          | false => count v b''
          end).

Sometimes you need to hide the definition of the variable, and only remember it as an equality that you invoke on demand. For that, use remember.

You can match the goal against a pattern using the context form of match goal and give a name to whatever's inside that pattern.

match goal with |- context [S ?_x = ?_x + 1] => set (x := _x) end.

If this is your real goal and not a simplified example, it's a simple arithmetic statement and you can just call lia and let Coq figure it out.

Require Import Lia.

…
lia.
不疑不惑不回忆 2025-02-13 04:11:54

除了吉尔斯的建议外,您还可以使用代码> 为了实现这一目标,至少以两种方式说明了此处:

Require Import Arith ssreflect.

Variables v b' b'' : nat.
Variable count : nat -> nat -> nat.

Goal
 S match v =? b' with
   | true => S (count v b'')
   | false => count v b''
   end
 = match v =? b' with
   | true => S (count v b'')
   | false => count v b''
   end + 1.
Proof.
  set t := (X in S X = X + _).
  Undo.
  set t := match _ with true => _ | false => _ end.
Abort.

后者也可以与常规set ,但需要括号:

  set (t := match _ with true => _ | false => _ end).

Besides Gilles's suggestions you can use the ssreflect set to achieve this, in at least two ways illustrated here:

Require Import Arith ssreflect.

Variables v b' b'' : nat.
Variable count : nat -> nat -> nat.

Goal
 S match v =? b' with
   | true => S (count v b'')
   | false => count v b''
   end
 = match v =? b' with
   | true => S (count v b'')
   | false => count v b''
   end + 1.
Proof.
  set t := (X in S X = X + _).
  Undo.
  set t := match _ with true => _ | false => _ end.
Abort.

The latter one also works with the regular set but it needs brackets:

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