本次英国统计代写主要是R语言的统计数据建模

CMPSC 461: Programming Language Concepts Assignment 7. Due: Monday, Mar, 15th, 11:59PM

对于此作业,所有提交的作品必须是您自己的作品。将书面部分以pdf或图像形式提交给hw7,并提交hw7.rkt及其以下对hw7-code要求的功能的定义。

问题1 [6分]适用于以下术语:

(λx。λy。y x)(λz。y)

a)计算其自由变量FV()并用线将所有绑定的变量连接到其定义。为了

例如,该项的绑定变量λx。 x x y应该是λx。 x x y。

b)对项进行减法,直到不再有β减法的可能性为止。显示每个步骤。

问题2 [8pt]在hw6中,您在纸上的教堂数字上定义了一些功能。请在可用于教堂数字的hw7.rkt文件中实现ISZERO,PRED和MINUS函数。我们已经实现了一些帮助程序功能,以帮助您开始实施。您的实现只能使用(lambda …),形式为(a b c)的函数应用程序以及预定义的常量/构造,例如TRUE,FALSE,IF,PAIR,LEFT,RIGHT,SUCC,PLUS和ZERO。

ENCODE和DECODE功能严格用于测试。您的实现不应涉及这两个功能中的任何一个。

a)(2pt)定义一个函数ISZERO,以便在给定教堂数字n的情况下,如果n = 0,则返回TRUE(true的编码);如果n = 0,则为FALSE(假编码)。

>(零零)
#<过程:TRUE>
>(ISZERO(编码100))
#<procedure:FALSE>

b)(4pt)定义一个函数PRED,以便在给定教堂编号n的情况下,该函数返回其前任(假设0的前任为0)。

PAIR􏰁λxyf.fxy

>(解码(预零))
0
>(解码(PRED(编码461)))
460

左􏰁λp.pλxy.x

右􏰁λp.pλxy.y

c)(2pt)使用PRED的编码定义减法函数MINUS,以便当n1≥n2时MINUS n1 n2返回n1-n2,否则返回0。

>(解码(减号(编码461)(编码311)))
150
>(解码(减号(编码131)(编码461)))
0

1/2

问题3 [6pt]在hw7.rkt中实现了两个操纵球拍的球拍功能。

a)(4分)编写一个函数序列,该函数序列包含3个参数low,high和fac,均假定为正整数。进一步假设因子大于1。序列产生一个从低到高(包括低和可能高)的几何序列,其中该序列在每两个数字之间具有fac因子。如果低大于高,则序列应为空列表。

>(序列1100 2)
’(1 2 4 8 16 32 64)
>(序列20 19 2)
’()

>(序列20 1000 3)
’(20 60 180 540)

b)(2分)编写一个函数总和,该函数总和返回列表中所有数字的总和。如果列表为空,则返回0。

>(总和((1 2 3))
6
>(总和(())
0

>(总和((1.1 2.2 3.3 4.4 5.5 100))
116.5
>

作业7,CMPSC461 2/2

For this assignment, All submitted work must be your own work. Submit written part as pdf or images to hw7 and submit hw7.rkt with definitions of functions required below to hw7-code.

Problem 1 [6pt] For the following term:

(λx. λy. y x) (λz. y)

  1. a)  Calculate its free variables FV() and connect all bound variables to their definitions with lines. For

    example, the bound variables for this term, λx. x x y should be λ x. x x y.

  2. b)  Do reduction on the term until no more β-reduction is possible. Show every steps.

Problem 2 [8pt] In hw6, you have defined a few functions on church numerals on paper. Please implement ISZERO, PRED and MINUS functions in hw7.rkt file that works on church numerals. We have already implemented some helper functions to help you get started with your implementation. Your implementation can only use (lambda …), function application of the form (a b c) and predefined constants/constructs such as TRUE, FALSE, IF, PAIR, LEFT, RIGHT, SUCC, PLUS and ZERO.

The ENCODE and DECODE functions are strictly for testing. Your implementation should not involve either of these two functions.

  1. a)  (2pt) Define a function ISZERO so that given a church numeral n, it returns TRUE (the encoding of true) if n = 0; FALSE (the encoding of false) if n ̸= 0.
      > (ISZERO ZERO)
      #<procedure:TRUE>
      > (ISZERO (ENCODE 100))
      #<procedure:FALSE>
    
  2. b)  (4pt) Define a function PRED so that given a church numeral n, the function returns its predecessor, assuming the predecessor of 0 is 0.

PAIR􏰁λxyf.f xy

> (DECODE (PRED ZERO))
0
> (DECODE (PRED (ENCODE 461)))
460

LEFT􏰁λp.pλxy.x

RIGHT􏰁λp.pλxy.y

c) (2pt) Use your encoding of PRED to define a subtraction function MINUS, so that MINUS n1 n2 returns n1 n2 when n1 n2, and 0 otherwise.

  > (DECODE (MINUS (ENCODE 461) (ENCODE 311)))
  150
  > (DECODE (MINUS (ENCODE 131) (ENCODE 461)))
  0

1/2

Problem 3 [6pt] Implement two racket functions in hw7.rkt that manipulate lists.

a) (4pts) Write a function sequence that takes 3 arguments low, high, and fac, all assumed to be positive integers. Further assume factor is greater than 1. sequence produces a geometric sequence from low to high (including low and possibly high) where the sequence has a factor of fac between each two numbers. If low is greater than high, the sequence should be an empty list.

  > (sequence 1 100 2)
  ’(1 2 4 8 16 32 64)
  > (sequence 20 19 2)
  ’()
  > (sequence 20 1000 3)
  ’(20 60 180 540)

b) (2pts) Write a function sum that returns the sum of all numbers of a list. It returns 0 if the list is empty.

  > (sum ’(1 2 3))
  6
  > (sum ’())
  0
  > (sum ’(1.1 2.2 3.3 4.4 5.5 100))
  116.5
  >

Assignment 7, CMPSC461 2/2