联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> Java编程Java编程

日期:2023-10-01 10:38

? For questions involving answers in English or mathematics or a combination of the two, put your

answers to the question in an answer box like in the example below.

? For programming questions, please put your answers into a file called ps2-lastname-firstname.clj.

Be careful to follow the instructions exactly and be sure that all of your function definitions use the

precise names, number of inputs and input types, and output types as requested in each question.

For the code portion of the assignment, it is crucial to submit a standalone file that runs.

Before you submit ps2-lastname-firstname.clj, make sure that your code executes correctly without

any errors when run at the command line by typing clojure ps2-lastname-firtname.clj at a terminal

prompt. We cannot grade any code that does not run correctly as a standalone file, and if the preceding

command produces an error, the code portion of the assignment will receive a 0.

To do the computational problems, we recommend that you install Clojure on your local machine and

write and debug the answers to each problem in a local copy of ps2-lastname-firstname.clj. You can

find information about installing and using Clojure here https://clojure.org/.

Note there is a built-in function called reverse. Do not use the built-in function reverse in this

problem set! We remove reverse from the namespace when we grade, so using it anywhere will lead

to an error and a result in a 0.

Once you have entered your answers, please compile your copy of this LATEX file1

into a PDF and submit

(i) the compiled PDF renamed to ps2-lastname-firstname.pdf

(ii) the raw LATEX file renamed to ps2-lastname-firstname.tex and

(iii) your ps2-lastname-firstname.clj

to the Problem Set 2 folder under ‘Assignments’ on MyCourses.

Example Problem: This is an example question using some fake math like this L =

P∞

0

Gδx.

Example Answer: Put your answer in the box provided, like this:

Example answer is L =

P∞

0

Gδx.

1To compile a file file.tex to file.pdf, you can use the command pdflatex file.tex at the command line, or make use of an

online service such as https://overleaf.com. You can find more information about LATEX here https://www.latex-project.org/.

1

MAIN PROBLEM SET

Problem 1: Write a single-argument function called absval that, when passed a number, computes its

absolute value. It should do this by finding the square root of the square of the argument. (Note: you should

use the Math/sqrt function built in to Clojure (from Java), which returns the square root of a number.)

Answer 1: Please put your answer in ps2-lastname-firstname.clj.

Problem 2: In both of the following definitions, there are one or more errors of some kind. In each case,

explain what’s wrong and why, and fix it:

(defn take-square

(* x x))

(defn sum-of-squares [(take-square x) (take-square y)]

(+ (take-square x) (take-square y)))

Answer 2: Please put the fixed functions in ps2-lastname-firstname.clj and describe what is wrong

and why in the box below.

Problem 3: The expression (+ 11 2) evaluates to 13. Write four other different Clojure expressions which

also evaluate to the number 13 (either the integer 13 or the float 13.0). Using def, assign these expressions

to the symbols exp-13-1, exp-13-2, exp-13-3, and exp-13-4.

In each def statement, be sure to quote the expression (as below for our example), so it is not evaluated

before being assigned to the symbol.

(def exp-13-0 '(+ 11 2))

Answer 3: Please put your answer in ps2-lastname-firstname.clj.

Problem 4: Define a function called third, that selects the third element of a list. For example, given the

list '(4 5 6) as its argument, third should return the number 6.

Answer 4: Please put your answer in ps2-lastname-firstname.clj.

Problem 5: Define a function called compose, that takes two one-place functions f and g as arguments.

It should return a new function, the composition of its input functions, which computes f of g of x when

passed the argument x. For example, the function Math/sqrt (built in to Clojure from Java) takes the square

root of a number, and the function Math/abs (likewise) takes the absolute value of a number. If we use defn

to define functions sqrt and abs as

(defn sqrt [x] (Math/sqrt x))

(defn abs [x] (Math/abs x))

then ((compose sqrt abs) -36) should return 6, since the square root of the absolute value of -36 equals 6.

2

Answer 5: Please put your answer in ps2-lastname-firstname.clj.

Problem 6: Define a function called first-two that takes a list as its sole argument, and returns a

two-element list containing the first two elements of the argument. For example, given the list '(4 5 6),

first-two should return the list '(4 5).

You may assume that the list passed in has at least two elements.

Answer 6: Please put your answer in ps2-lastname-firstname.clj.

Problem 7: Define a function called remove-second that takes a list, and returns a new list that is the

same as the input list, but with the second value removed. For example, given '(3 1 4), remove-second

should return the list '(3 4).

Answer 7: Please put your answer in ps2-lastname-firstname.clj.

Problem 8: Define a function called add-to-end that takes in two arguments: a list lst and a value x. It

should return a new list which is the same as lst, except that it has x appended as its final element. For

example, (add-to-end (list 5 6 4) 0) should return the list '(5 6 4 0).

Answer 8: Please put your answer in ps2-lastname-firstname.clj.

Problem 9: Define a function called reverse-list, that takes in a list, and returns the reverse of the list.

For example, if it takes in the list '(a b c), it will output the list '(c b a).

Do not use the built-in function reverse (in this problem, nor anywhere in this problem set).

Answer 9: Please put your answer in ps2-lastname-firstname.clj.

Problem 10: Define a function called count-to-1, that takes a positive integer n, and returns a list of the

integers counting down from n to 1. For example, given input 3, it will return the list (list 3 2 1).

Answer 10: Please put your answer in ps2-lastname-firstname.clj.

Problem 11: Define a function called count-to-n, that takes a positive integer n, and returns a list of the

integers from 1 to n. For example, given input 3, it will return the value of (list 1 2 3).

Hint: Use the procedures reverse-list and count-to-1 that you wrote in the previous problems.

Answer 11: Please put your answer in ps2-lastname-firstname.clj.

3

Problem 12: Define a function called get-max, that takes a list of numbers, and returns the maximum

value. So, (get-max '(2 3 3)) should return 3.

Don’t use the built-in max function.

Answer 12: Please put your answer in ps2-lastname-firstname.clj.

Problem 13: Define a function called greater-than-five?, that takes a list of numbers, and returns a list

of equal length to the input list, but where each number is replaced with true if the number is greater than

5, and false otherwise. For example, given input (list 5 4 7), it will return the list '(false false true).

Hint: Use the built in function map.

Answer 13: Please put your answer in ps2-lastname-firstname.clj.

Problem 14: Define a function called concat-three, that takes three sequences (represented as lists), x,

y, and z, and returns the concatenation of the three sequences. For example, given the arguments (list 'a

'b), (list 'b 'c), and (list 'd 'e), the procedure should return the value of (list 'a 'b 'b 'c 'd 'e).

Don’t use the built-in concat function.

Answer 14: Please put your answer in ps2-lastname-firstname.clj.

Problem 15: Define a function called sequence-to-power, that takes a sequence (represented as a list) x,

and a nonnegative integer n, and returns the sequence x

n. For example, given the sequence (list 'a 'b) as

the first argument and the number 3 as the second, the procedure should return the value of (list 'a 'b

'a 'b 'a 'b).

You may use the built-in concat function for this problem.

Answer 15: Please put your answer in ps2-lastname-firstname.clj.

Problem 16: Define L as a language containing a single sequence, L = {a}.

In Clojure, we can represent the sequence a as the list '(a).

Define a function called in-L-star? that takes a sequence (represented as a list), and returns true if and

only if the sequence is a member of the language L

?

. For example, given a sequence such as '(a b), the

procedure should return false, because ab is not a member of L

?

.

Answer 16: Please put your answer in ps2-lastname-firstname.clj.

Problem 17: Let A and B be two distinct formal languages. We’ll use (A·B) to denote the concatenation

of A and B, in that order. Find an example of languages A and B such that (A · B) = (B · A).

4

Answer 17: Please put your answer in the box below.

Problem 18: Let A and B be languages. Find an example of languages A and B such that (A · B) does

not equal (B · A)

Answer 18: Please put your answer in the box below.

Problem 19: Find an example of a language L such that L = L

2

, i.e. L = (L · L).

Answer 19: Please put your answer in the box below.

Problem 20: Argue that the intersection of any two languages L and L

is always contained in L.

Answer 20: Please put your answer in the box below.

Problem 21: Let L1, L2, L3, and L4 be languages. Argue that the union of Cartesian products (L1 ×

L3) ∪ (L2 × L4) is always contained in the Cartesian product of unions (L1 ∪ L2) × (L3 ∪ L4).

Answer 21: Please put your answer in the box below.

Problem 22: Let L and L

′ be finite languages. Show that the number of elements in the Cartesian product

L × L

is always equal to the number of elements in L

′ × L.

Answer 22: Please put your answer in the box below.

Problem 23: Suppose L is a language, and that concatenation of L with itself is equal to itself: (L·L) = L.

Show that L is either the empty set, the set {?}, or an infinite language.

Answer 23: Please put your answer in the box below.

5

LONG FORM READING QUESTION:

(This section is optional for students in LING/COMP 445, but must be completed if taking

LING 645.)

You must answer this question on your own.

Andreas et al. (2022) lay out a framework for how to think about data collection and ML model design

when trying to study language representation. Though they use sperm whale communication as their driving

example, much of the points they make are applicable to any communication system, including humans.

What is the difference between supervised learning and self-supervised learning in ML models? What are

some of the benefits and downfalls of using self-supervision to train a model of language representation?

(give at least 2 benefits and 2 downfalls - your answer should be 1/2 a page to a page in length.)

Answer: Please put your answer in the box below.

6


相关文章

版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp