简体   繁体   English

了解有关Agda的实践考试

[英]Understanding practice exam about Agda

I am going through my practice exam for Programming language Foundations using agda and it has the following question: 我正在使用agda进行编程语言基础的实践考试,并且存在以下问题:

You are given the following Agda declaration: 您将获得以下Agda声明:

data Even : N → Set where
 ezero : Even 0
 esuc : { n : N }  → Even n  → Even (2+ n)

Assume that the standard library of natural numbers has been imported. 假设已导入标准自然数库。 Answer the following questions: 回答以下的问题:

a)What is the type of ezero ? a) ezero的类型是什么?

b)Are there any terms of type Even 1 ? b)是否有类型Even 1

c)How many terms are of type Even 2 ? c) Even 2类型有多少项? List them 列出他们

d)Describe one potential problem that might occur if we change the return type of esuc to be Even (n+2) instead of Even (2+n) . d)描述如果我们将esuc的返回类型更改为Even (n+2)而不是Even (2+n)可能发生的一个潜在问题。

We're not provided a solution manual. 我们没有提供解决方案手册。 The question seems pretty basic but I am not sure about any of these.I think the answer to the first three are: 这个问题似乎很基本,但我不确定其中任何一个,我认为前三个答案是:

a) Set 一套

b) No terms of type Even 1 b)甚至没有1个类型的项

c) One term of type Even 2 c)一类偶数2的项

d) don't know d)不知道

Answers to these questions along with a brief explanation would be highly appreciated. 这些问题的答案以及简短的解释将不胜感激。 Thanks 谢谢

What is the type of ezero ? ezero的类型是什么?

The type of the data constructor ezero can be read from the data declaration: ezero : Even 0 states that it has type Even 0 . 可以从数据声明中读取数据构造函数ezero的类型: ezero : Even 0表示其类型为Even 0

Are there any terms of type Even 1 ? 是否有类型Even 1

No there aren't any. 不,没有。 This can be seen by a case distinction: if there were a term then it'd start with either one of the two constructors. 这可以通过区分大小写来看出:如果有一个术语,则以两个构造函数之一开始。 And because these have specific return indices, they'd have to unify with 1 . 并且由于它们具有特定的回报指数,因此必须与1统一。

  • ezero would enforce 1 = 0 ezero将强制执行1 = 0
  • esuc would mean that there is an n such that 1 = 2+ n esuc表示存在一个n,使得1 = 2+ n

Both of these situations are impossible. 这两种情况都是不可能的。

How many terms are of type Even 2? 偶数2类型有多少个术语? List them 列出他们

There is exactly one: esuc ezero . 恰好有一个: esuc ezero With a reasoning similar to the one in the previous question, we can prove that ezero and esuc (esuc p) (for some p ) won't do. 随着一个类似于在上一个问题推理,我们可以证明ezeroesuc (esuc p)对于某些p )不会做。

Describe one potential problem that might occur if we change the return type of esuc to be Even (n+2) instead of Even (2+n) . 描述一下如果将esuc的返回类型更改为Even (n+2)而不是Even (2+n)可能发生的一个潜在问题。

Consider the proof plus-Even : {mn : N} → Even m → Even n → Even (m + n) . 考虑plus-Even : {mn : N} → Even m → Even n → Even (m + n)的证明plus-Even : {mn : N} → Even m → Even n → Even (m + n) Because (+) is defined by induction on its first argument, you won't be able to immediately apply esuc in the step case. 由于(+)是通过对第一个参数的归纳定义的,因此您将无法在单步情况下立即应用esuc You are going to need to use rewriting to reorganize the type of the goal from Even ((m +2) + n) (or Even (m + (n +2)) depending on which argument you perform induction on) to Even ((m + n) +2) beforehand. 您将需要使用重写将目标的类型从Even ((m +2) + n) (或Even (m + (n +2))取决于您对哪个参数进行归纳)重组为Even ((m + n) +2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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