CS 350 Homework 1 solution

$24.99

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (5 votes)

1.1. Take
Write an Oz function Take which takes two arguments, a list
.B Xs and a number N and evaluates to the first N
elements of the list if N is a positive number less
than the list length, to nil if N is either 0 or negative, and evaluates to the whole list if the list is
shorter than N
[10 points]
1.2. Last
Write an Oz function Last which takes two arguments, a list Xs and a number N and evaluates to
the last N elements of the list if N is a positive
number at most the list length, to nil if N is either
0 or neg ative, and evaluates to the whole list if N
is longer than the list.
[10 points]
1.3. Merge
Write an Oz function Merge which takes two
sorted lists of integers as arguments, and evaluates
to a merged list in sorted order. The two lists need
not be of equal length.
[10 points]
2. Higher-Order Programming
2.1. ZipWith
Write an Oz function ZipWith which takes 3
arguments – the first, a 2-argument function
BinOp followed by two lists, Xs and Ys , and
outputs the list whose i
th position is got by evaluating BinOp on the i
th elements in Xs and Ys.
[15points]
2.2. Map Using FoldR
Rewrite Map using FoldR
[15points]
2.3. FoldL
Write an Oz function FoldL which folds a binary
operation from the left. For example,
{FoldL Sum [1 2 3] 0}
should evaluate to
{Sum {Sum {Sum 0 1} 2} 3}.
[10 points]
3.
3.1.
Write a lazy Oz function to generate the Taylor
series for sin(x). Write the function to produce a
list of successive terms in the Taylor series.
[10 points]
3.2.
Write a function {Approximate S Epsilon}
which takes a Taylor series S and evaluates it until
the point where successive terms differ from each
other by at most Epsilon. It should then return
the sum of the terms taken until then. The series S
may have infinitely many terms.
[10 points]
4. Suppose a square matrix
a11
a21
a31
a12
a22
a32
a13
a23
a33
is represented in row-major manner as
15 September 2020
-2-
[[a11 a12 a13]
[a21 a22 a23]
[a31 a32 a33]].
Write an Oz function {IsDiagonal M} which
takes a square matrix represented in row-major
manner, and returns true if it is a diagonal matrix,
and false otherwise. You can assume that M is
always a square matrix, but it need not be a 3 × 3
matrix.
[15 points]