[英]Agda - Building proofs interactively - How to use the hole syntax?
Sorry for the strange title, I have no idea how these concepts are actually named.对不起,奇怪的标题,我不知道这些概念实际上是如何命名的。
I'm following an Agda
tutorial and there's a section explaining how to build proofs inductively:https://plfa.github.io/Induction/#building-proofs-interactively我正在关注Agda
教程,其中有一节解释了如何以归纳方式构建证明:https://plfa.github.io/Induction/#building-proofs-interactively
It's pretty cool that you can expand your proof step by step and have the hole (this { }0
) update its contents to tell you what's going on.您可以逐步扩展您的证明并让孔(此{ }0
)更新其内容以告诉您发生了什么,这非常酷。 However, it is only explained how to do that when using the rewrite
syntax.但是,仅说明了在使用rewrite
语法时如何执行此操作。
How does this work when I want to "manually" do the proof within a begin
block, for example:当我想“手动”在begin
块中进行证明时,这是如何工作的,例如:
+-assoc : ∀ (m n p : ℕ) → (m + n) + p ≡ m + (n + p)
+-assoc zero n p =
begin
(zero + n) + p
≡⟨⟩ n + p
≡⟨⟩ zero + (n + p)
∎
+-assoc (suc m) n p =
begin
(suc m + n) + p
≡⟨⟩ suc (m + n) + p
≡⟨⟩ suc ((m + n) + p)
≡⟨ cong suc (+-assoc m n p) ⟩
suc (m + (n + p))
≡⟨⟩ suc m + (n + p)
∎
The problem is the following.问题如下。 Let's start with the proposition and start of the evidence:让我们从命题和证据开始:
+-assoc : ∀ (m n p : ℕ) → (m + n) + p ≡ m + (n + p)
+-assoc m n p = ?
This evaluates to:这评估为:
+-assoc : ∀ (m n p : ℕ) → (m + n) + p ≡ m + (n + p)
+-assoc m n p = { }0
In this case, I want to do a proof by induction, so I split these using Cc Cc
using the variable m
:在这种情况下,我想通过归纳来证明,所以我使用Cc Cc
使用变量m
拆分这些:
+-assoc : ∀ (m n p : ℕ) → (m + n) + p ≡ m + (n + p)
+-assoc zero n p = { }0
+-assoc (suc m) n p = { }1
The base case is trivial and is replaced with refl
after resolving it using Cc Cr
.基本情况是微不足道的,在使用Cc Cr
解决后被refl
替换。 However, the inductive case (hole 1) needs some work.但是,感应案例(孔 1)需要一些工作。 How can I turn this { }1
hole into the following structure to do the proof:我怎样才能把这个{ }1
洞变成下面的结构来做证明:
begin
-- my proof
∎
My editor (spacemacs) says { }1
is read-only.我的编辑器(spacemacs)说{ }1
是只读的。 I cannot delete it, only insert stuff between the braces.我不能删除它,只能在大括号之间插入东西。 I can force-delete it but that's clearly not intended.我可以强制删除它,但这显然不是故意的。
What are you supposed to do to expand the hole into a begin
block?你应该怎么做才能把洞扩大成一个begin
块? Something like this像这样的东西
{ begin }1
does not work and leads to an error message不起作用并导致错误消息
Thanks!谢谢!
EDIT:编辑:
Okay, so the following seems to work:好的,所以以下似乎有效:
{ begin ? }1
This turns it into this:这变成了这样:
+-assoc : ∀ (m n p : ℕ) → (m + n) + p ≡ m + (n + p)
+-assoc zero n p = refl
+-assoc (suc m) n p = begin { }0
That's a progress:D.这是一个进步:D。 But now I can't figure out where to put the actual steps of the proof:但现在我不知道在哪里放置证明的实际步骤:
...
+-assoc (suc m) n p = begin (suc m + n) + p { }0
-- or
+-assoc (suc m) n p = begin { (suc m + n) + p }0
Neither seems to be working似乎都没有工作
{ }1
is read-only{ }1
是只读的
This message is shown in two cases:此消息在两种情况下显示:
A rule of thumb is that you always refine a hole with Cc C-SPC
with an expression of the type that is equal to the goal.一条经验法则是,您始终使用Cc C-SPC
用等于目标类型的表达式来细化一个洞。 In your case this means starting with begin?
在您的情况下,这意味着从begin?
, then giving (suc m + n) + p ≡⟨⟩?
,然后给出(suc m + n) + p ≡⟨⟩?
and so on.等等。
There are two ways to refine a hole:有两种方法可以细化孔:
Cc Cr
: creates new holes for you when given a function. Cc Cr
:当给定 function 时为您创建新孔。 Eg with this setup:例如,使用此设置:
test: Bool test = {!!}
if you type not
in the hole如果你not
洞里打字
test: Bool test = {!not!}
and refine, you'll get并精炼,你会得到
test: Bool test = not {!!}
ie the new hole is created automatically for the argument.即为参数自动创建新孔。
With this way or refining a hole Agda also reformats your code the way it prefers, which I don't like, so I usually don't use it.通过这种方式或改进一个洞,Agda 也会按照它喜欢的方式重新格式化你的代码,我不喜欢这种方式,所以我通常不使用它。
Cc C-SPC
: doesn't create new holes for arguments and doesn't reformat your code Cc C-SPC
:不会为 arguments 创建新的孔,也不会重新格式化您的代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.